-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5118 from kwvanderlinde/feature/5080-wall-directi…
…onality Add directionality to walls
- Loading branch information
Showing
28 changed files
with
1,546 additions
and
440 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
src/main/java/net/rptools/maptool/client/swing/walls/WallConfigurationController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
* This software Copyright by the RPTools.net development team, and | ||
* licensed under the Affero GPL Version 3 or, at your option, any later | ||
* version. | ||
* | ||
* MapTool Source Code is distributed in the hope that it will be | ||
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty | ||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* | ||
* You should have received a copy of the GNU Affero General Public | ||
* License * along with this source Code. If not, please visit | ||
* <http://www.gnu.org/licenses/> and specifically the Affero license | ||
* text at <http://www.gnu.org/licenses/agpl.html>. | ||
*/ | ||
package net.rptools.maptool.client.swing.walls; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
import javax.swing.JComboBox; | ||
import net.rptools.maptool.client.MapTool; | ||
import net.rptools.maptool.model.Zone; | ||
import net.rptools.maptool.model.topology.VisibilityType; | ||
import net.rptools.maptool.model.topology.Wall; | ||
|
||
public class WallConfigurationController { | ||
private final WallConfigurationView view; | ||
private @Nullable Zone modelZone; | ||
private @Nonnull Wall model; | ||
|
||
public WallConfigurationController() { | ||
this.view = new WallConfigurationView(); | ||
|
||
this.modelZone = null; | ||
this.model = new Wall(); | ||
|
||
var directionSelect = view.getDirectionSelect(); | ||
directionSelect.addActionListener( | ||
e -> { | ||
var direction = directionSelect.getItemAt(directionSelect.getSelectedIndex()); | ||
if (direction != null && !direction.equals(this.model.direction())) { | ||
this.model.direction(direction); | ||
wallUpdated(); | ||
} | ||
}); | ||
|
||
var movementModifierSelect = view.getMovementModifier(); | ||
movementModifierSelect.addActionListener( | ||
e -> { | ||
var modifier = | ||
movementModifierSelect.getItemAt(movementModifierSelect.getSelectedIndex()); | ||
if (modifier != null && !modifier.equals(this.model.movementModifier())) { | ||
this.model.movementModifier(modifier); | ||
wallUpdated(); | ||
} | ||
}); | ||
|
||
for (var visibilityType : VisibilityType.values()) { | ||
final var input = getModifierInput(visibilityType); | ||
input.addActionListener( | ||
e -> { | ||
var modifier = input.getItemAt(input.getSelectedIndex()); | ||
if (modifier != null | ||
&& !modifier.equals(this.model.directionModifier(visibilityType))) { | ||
this.model.directionModifier(visibilityType, modifier); | ||
wallUpdated(); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
public WallConfigurationView getView() { | ||
return view; | ||
} | ||
|
||
private JComboBox<Wall.DirectionModifier> getModifierInput(VisibilityType visibilityType) { | ||
return switch (visibilityType) { | ||
case Sight -> view.getSightModifier(); | ||
case Light -> view.getLightModifier(); | ||
case Aura -> view.getAuraModifier(); | ||
}; | ||
} | ||
|
||
private void wallUpdated() { | ||
if (modelZone != null) { | ||
MapTool.serverCommand().updateWall(modelZone, this.model); | ||
} | ||
} | ||
|
||
public void unbind() { | ||
// Preserve the current settings in a new prototype wall. | ||
var prototype = new Wall(); | ||
prototype.copyDataFrom(model); | ||
bind(null, prototype); | ||
} | ||
|
||
public void bind(@Nullable Zone zone, @Nonnull Wall model) { | ||
// Avoid events firing during binding. | ||
this.modelZone = null; | ||
this.model = new Wall(); | ||
|
||
this.view.getDirectionSelect().setSelectedItem(model.direction()); | ||
this.view.getMovementModifier().setSelectedItem(model.movementModifier()); | ||
for (var visibilityType : VisibilityType.values()) { | ||
getModifierInput(visibilityType).setSelectedItem(model.directionModifier(visibilityType)); | ||
} | ||
|
||
// Now that the state is set, remember which wall we're bound to. | ||
this.modelZone = zone; | ||
this.model = model; | ||
} | ||
|
||
public @Nonnull Wall getModel() { | ||
return model; | ||
} | ||
} |
106 changes: 106 additions & 0 deletions
106
src/main/java/net/rptools/maptool/client/swing/walls/WallConfigurationView.form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="net.rptools.maptool.client.swing.walls.WallConfigurationView"> | ||
<grid id="c3ea9" binding="mainPanel" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="1"> | ||
<constraints> | ||
<xy x="10" y="10" width="242" height="278"/> | ||
</constraints> | ||
<properties/> | ||
<border type="none"/> | ||
<children> | ||
<grid id="ec22d" layout-manager="GridLayoutManager" row-count="6" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> | ||
<margin top="0" left="0" bottom="0" right="0"/> | ||
<constraints/> | ||
<properties/> | ||
<border type="none"/> | ||
<children> | ||
<component id="7bc67" class="javax.swing.JLabel"> | ||
<constraints> | ||
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties> | ||
<labelFor value="67709"/> | ||
<text resource-bundle="net/rptools/maptool/language/i18n" key="WallConfigurationView.label.aura"/> | ||
</properties> | ||
</component> | ||
<component id="3f303" class="javax.swing.JLabel"> | ||
<constraints> | ||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties> | ||
<labelFor value="3b108"/> | ||
<text resource-bundle="net/rptools/maptool/language/i18n" key="WallConfigurationView.label.light"/> | ||
</properties> | ||
</component> | ||
<component id="720b3" class="javax.swing.JLabel"> | ||
<constraints> | ||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties> | ||
<labelFor value="84818"/> | ||
<text resource-bundle="net/rptools/maptool/language/i18n" key="WallConfigurationView.label.sight"/> | ||
</properties> | ||
</component> | ||
<component id="67709" class="javax.swing.JComboBox" binding="auraModifier"> | ||
<constraints> | ||
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties/> | ||
</component> | ||
<component id="3b108" class="javax.swing.JComboBox" binding="lightModifier"> | ||
<constraints> | ||
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties> | ||
<model/> | ||
</properties> | ||
</component> | ||
<component id="84818" class="javax.swing.JComboBox" binding="sightModifier"> | ||
<constraints> | ||
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties/> | ||
</component> | ||
<component id="f0996" class="javax.swing.JSeparator"> | ||
<constraints> | ||
<grid row="1" column="0" row-span="1" col-span="2" vsize-policy="6" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties/> | ||
</component> | ||
<component id="9b0e4" class="javax.swing.JLabel"> | ||
<constraints> | ||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties> | ||
<labelFor value="b6a66"/> | ||
<text resource-bundle="net/rptools/maptool/language/i18n" key="WallConfigurationView.label.direction"/> | ||
</properties> | ||
</component> | ||
<component id="b6a66" class="javax.swing.JComboBox" binding="direction"> | ||
<constraints> | ||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties> | ||
<editable value="false"/> | ||
<model/> | ||
</properties> | ||
</component> | ||
<component id="fd64d" class="javax.swing.JLabel"> | ||
<constraints> | ||
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties> | ||
<labelFor value="eddfc"/> | ||
<text resource-bundle="net/rptools/maptool/language/i18n" key="WallConfigurationView.label.movement"/> | ||
</properties> | ||
</component> | ||
<component id="eddfc" class="javax.swing.JComboBox" binding="movementModifier"> | ||
<constraints> | ||
<grid row="5" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties/> | ||
</component> | ||
</children> | ||
</grid> | ||
</children> | ||
</grid> | ||
</form> |
61 changes: 61 additions & 0 deletions
61
src/main/java/net/rptools/maptool/client/swing/walls/WallConfigurationView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* This software Copyright by the RPTools.net development team, and | ||
* licensed under the Affero GPL Version 3 or, at your option, any later | ||
* version. | ||
* | ||
* MapTool Source Code is distributed in the hope that it will be | ||
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty | ||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* | ||
* You should have received a copy of the GNU Affero General Public | ||
* License * along with this source Code. If not, please visit | ||
* <http://www.gnu.org/licenses/> and specifically the Affero license | ||
* text at <http://www.gnu.org/licenses/agpl.html>. | ||
*/ | ||
package net.rptools.maptool.client.swing.walls; | ||
|
||
import javax.swing.DefaultComboBoxModel; | ||
import javax.swing.JComboBox; | ||
import javax.swing.JPanel; | ||
import net.rptools.maptool.model.topology.Wall; | ||
|
||
public class WallConfigurationView { | ||
private JPanel mainPanel; | ||
private JComboBox<Wall.Direction> direction; | ||
private JComboBox<Wall.DirectionModifier> sightModifier; | ||
private JComboBox<Wall.DirectionModifier> lightModifier; | ||
private JComboBox<Wall.DirectionModifier> auraModifier; | ||
private JComboBox<Wall.MovementDirectionModifier> movementModifier; | ||
|
||
public WallConfigurationView() { | ||
direction.setModel(new DefaultComboBoxModel<>(Wall.Direction.values())); | ||
sightModifier.setModel(new DefaultComboBoxModel<>(Wall.DirectionModifier.values())); | ||
lightModifier.setModel(new DefaultComboBoxModel<>(Wall.DirectionModifier.values())); | ||
auraModifier.setModel(new DefaultComboBoxModel<>(Wall.DirectionModifier.values())); | ||
movementModifier.setModel(new DefaultComboBoxModel<>(Wall.MovementDirectionModifier.values())); | ||
} | ||
|
||
public JPanel getRootComponent() { | ||
return mainPanel; | ||
} | ||
|
||
public JComboBox<Wall.Direction> getDirectionSelect() { | ||
return direction; | ||
} | ||
|
||
public JComboBox<Wall.DirectionModifier> getSightModifier() { | ||
return sightModifier; | ||
} | ||
|
||
public JComboBox<Wall.DirectionModifier> getLightModifier() { | ||
return lightModifier; | ||
} | ||
|
||
public JComboBox<Wall.DirectionModifier> getAuraModifier() { | ||
return auraModifier; | ||
} | ||
|
||
public JComboBox<Wall.MovementDirectionModifier> getMovementModifier() { | ||
return movementModifier; | ||
} | ||
} |
Oops, something went wrong.