Skip to content

Commit

Permalink
Merge pull request #5118 from kwvanderlinde/feature/5080-wall-directi…
Browse files Browse the repository at this point in the history
…onality

Add directionality to walls
  • Loading branch information
cwisniew authored Jan 19, 2025
2 parents b11ff77 + d306f20 commit a97b8e3
Show file tree
Hide file tree
Showing 28 changed files with 1,546 additions and 440 deletions.
3 changes: 2 additions & 1 deletion src/main/java/net/rptools/maptool/client/AppStyle.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public class AppStyle {
public static Color resizeBoxFill = Color.yellow;
public static Color wallTopologyColor = new Color(255, 182, 0, 255);
public static Color wallTopologyOutlineColor = Color.black;
public static Color selectedWallTopologyColor = new Color(255, 136, 0, 255);
public static Color highlightedWallTopologyColor = new Color(255, 136, 0, 255);
public static Color selectedWallOutlineColor = new Color(255, 255, 255, 255);
public static Color topologyColor = new Color(0, 0, 255, 128);
public static Color topologyAddColor = new Color(255, 0, 0, 128);
public static Color topologyRemoveColor = new Color(255, 255, 255, 128);
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/net/rptools/maptool/client/ClientMessageHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import net.rptools.maptool.model.library.addon.AddOnLibraryImporter;
import net.rptools.maptool.model.library.addon.TransferableAddOnLibrary;
import net.rptools.maptool.model.player.Player;
import net.rptools.maptool.model.topology.Wall;
import net.rptools.maptool.model.topology.WallTopology;
import net.rptools.maptool.model.zones.TokensAdded;
import net.rptools.maptool.model.zones.TokensRemoved;
Expand Down Expand Up @@ -171,6 +172,7 @@ public void handleMessage(String id, byte[] message) {
case UPDATE_TOKEN_MOVE_MSG -> handle(msg.getUpdateTokenMoveMsg());
case UPDATE_PLAYER_STATUS_MSG -> handle(msg.getUpdatePlayerStatusMsg());
case SET_WALL_TOPOLOGY_MSG -> handle(msg.getSetWallTopologyMsg());
case UPDATE_WALL_DATA_MSG -> handle(msg.getUpdateWallDataMsg());
default -> log.warn(msgType + "not handled.");
}
log.debug(id + " handled: " + msgType);
Expand Down Expand Up @@ -1068,8 +1070,28 @@ private void handle(SetWallTopologyMsg setWallTopologyMsg) {
() -> {
var zoneId = new GUID(setWallTopologyMsg.getZoneGuid());
var zone = client.getCampaign().getZone(zoneId);
if (zone == null) {
log.warn("Failed to find zone with id {}", zoneId);
return;
}
var topology = WallTopology.fromDto(setWallTopologyMsg.getTopology());

zone.replaceWalls(topology);
});
}

private void handle(UpdateWallDataMsg updateWallDataMsg) {
EventQueue.invokeLater(
() -> {
var zoneId = new GUID(updateWallDataMsg.getZoneGuid());
var zone = client.getCampaign().getZone(zoneId);
if (zone == null) {
log.warn("Failed to find zone with id {}", zoneId);
return;
}
var wall = Wall.fromDto(updateWallDataMsg.getWall());

zone.updateWall(wall);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import net.rptools.maptool.model.gamedata.proto.GameDataValueDto;
import net.rptools.maptool.model.library.addon.TransferableAddOnLibrary;
import net.rptools.maptool.model.player.Player;
import net.rptools.maptool.model.topology.Wall;
import net.rptools.maptool.model.topology.WallTopology;
import net.rptools.maptool.server.Mapper;
import net.rptools.maptool.server.ServerCommand;
Expand Down Expand Up @@ -424,6 +425,14 @@ public void replaceWalls(Zone zone, WallTopology walls) {
makeServerCall(Message.newBuilder().setSetWallTopologyMsg(msg).build());
}

public void updateWall(Zone zone, Wall wall) {
var msg =
UpdateWallDataMsg.newBuilder().setZoneGuid(zone.getId().toString()).setWall(wall.toDto());

zone.updateWall(wall);
makeServerCall(Message.newBuilder().setUpdateWallDataMsg(msg).build());
}

@Override
public void updateMaskTopology(
Zone zone, Area area, boolean erase, Zone.TopologyType topologyType) {
Expand Down
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;
}
}
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>
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;
}
}
Loading

0 comments on commit a97b8e3

Please sign in to comment.