Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename TopologyMode to TopologyTypeSet #3156

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 17 additions & 18 deletions src/main/java/net/rptools/maptool/client/AppPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ public class AppPreferences {
// When hill VBL was introduced, older versions of MapTool were unable to read the new topology
// modes. So we use a different preference key than in the past so older versions would not
// unexpectedly break.
private static final String KEY_TOPOLOGY_DRAWING_MODE = "topologyMode";
private static final String KEY_TOPOLOGY_TYPES = "topologyTypes";
private static final String KEY_OLD_TOPOLOGY_DRAWING_MODE = "topologyDrawingMode";
private static final String DEFAULT_TOPOLOGY_DRAWING_MODE = "VBL";
private static final String DEFAULT_TOPOLOGY_TYPE = "VBL";

private static final String KEY_WEB_END_POINT_PORT = "webEndPointPort";
private static final int DEFAULT_WEB_END_POINT = 654555;
Expand Down Expand Up @@ -1258,25 +1258,24 @@ public static void setDefaultMacroEditorTheme(String type) {
prefs.put(MACRO_EDITOR_THEME, type);
}

public static Zone.TopologyMode getTopologyDrawingMode() {
public static Zone.TopologyTypeSet getTopologyTypes() {
try {
String drawingMode = prefs.get(KEY_TOPOLOGY_DRAWING_MODE, "");
if ("".equals(drawingMode)) {
String typeNames = prefs.get(KEY_TOPOLOGY_TYPES, "");
if ("".equals(typeNames)) {
// Fallback to the key used prior to the introduction of various VBL types.
String oldDrawingMode =
prefs.get(KEY_OLD_TOPOLOGY_DRAWING_MODE, DEFAULT_TOPOLOGY_DRAWING_MODE);
String oldDrawingMode = prefs.get(KEY_OLD_TOPOLOGY_DRAWING_MODE, DEFAULT_TOPOLOGY_TYPE);
return switch (oldDrawingMode) {
default -> new Zone.TopologyMode(Zone.TopologyType.WALL_VBL);
case "VBL" -> new Zone.TopologyMode(Zone.TopologyType.WALL_VBL);
case "MBL" -> new Zone.TopologyMode(Zone.TopologyType.MBL);
case "COMBINED" -> new Zone.TopologyMode(
default -> new Zone.TopologyTypeSet(Zone.TopologyType.WALL_VBL);
case "VBL" -> new Zone.TopologyTypeSet(Zone.TopologyType.WALL_VBL);
case "MBL" -> new Zone.TopologyTypeSet(Zone.TopologyType.MBL);
case "COMBINED" -> new Zone.TopologyTypeSet(
Zone.TopologyType.WALL_VBL, Zone.TopologyType.MBL);
};
} else {
return Zone.TopologyMode.valueOf(drawingMode);
return Zone.TopologyTypeSet.valueOf(typeNames);
}
} catch (Exception exc) {
return new Zone.TopologyMode(Zone.TopologyType.WALL_VBL);
return new Zone.TopologyTypeSet(Zone.TopologyType.WALL_VBL);
}
}

Expand Down Expand Up @@ -1309,13 +1308,13 @@ public String toString() {
/**
* Sets the topology mode preference.
*
* @param mode the mode. A value of null resets to default.
* @param types the topology types. A value of null resets to default.
*/
public static void setTopologyDrawingMode(Zone.TopologyMode mode) {
if (mode == null) {
prefs.remove(KEY_TOPOLOGY_DRAWING_MODE);
public static void setTopologyTypes(Zone.TopologyTypeSet types) {
if (types == null) {
prefs.remove(KEY_TOPOLOGY_TYPES);
} else {
prefs.put(KEY_TOPOLOGY_DRAWING_MODE, mode.toString());
prefs.put(KEY_TOPOLOGY_TYPES, types.toString());
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/net/rptools/maptool/client/MapTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -1366,7 +1366,7 @@ private static void postInitialize() {
MapTool.getFrame()
.getCurrentZoneRenderer()
.getZone()
.setTopologyMode(AppPreferences.getTopologyDrawingMode());
.setTopologyTypes(AppPreferences.getTopologyTypes());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,27 +51,27 @@ public TopologyModeSelectionPanel() {
modeButtons = new EnumMap<>(Zone.TopologyType.class);

try {
var initialMode = AppPreferences.getTopologyDrawingMode();
var initiallySelectedTypes = AppPreferences.getTopologyTypes();
createAndAddModeButton(
Zone.TopologyType.WALL_VBL,
"net/rptools/maptool/client/image/tool/wall-vbl-only.png",
"tools.topology_mode_selection.vbl.tooltip",
initialMode);
initiallySelectedTypes);
createAndAddModeButton(
Zone.TopologyType.HILL_VBL,
"net/rptools/maptool/client/image/tool/hill-vbl-only.png",
"tools.topology_mode_selection.hill_vbl.tooltip",
initialMode);
initiallySelectedTypes);
createAndAddModeButton(
Zone.TopologyType.PIT_VBL,
"net/rptools/maptool/client/image/tool/pit-vbl-only.png",
"tools.topology_mode_selection.pit_vbl.tooltip",
initialMode);
initiallySelectedTypes);
createAndAddModeButton(
Zone.TopologyType.MBL,
"net/rptools/maptool/client/image/tool/mbl-only.png",
"tools.topology_mode_selection.mbl.tooltip",
initialMode);
initiallySelectedTypes);
} catch (IOException ioe) {
ioe.printStackTrace();
}
Expand All @@ -80,11 +80,14 @@ public TopologyModeSelectionPanel() {
}

private void createAndAddModeButton(
Zone.TopologyType type, String imageFile, String toolTipKey, Zone.TopologyMode initialMode)
Zone.TopologyType type,
String imageFile,
String toolTipKey,
Zone.TopologyTypeSet initiallySelectedTypes)
throws IOException {
final var button = new JToggleButton(new ImageIcon(ImageUtil.getImage(imageFile)));
button.setToolTipText(I18N.getText(toolTipKey));
button.setSelected(initialMode.contains(type));
button.setSelected(initiallySelectedTypes.contains(type));
this.add(button);
modeButtons.put(type, button);
button.addChangeListener(
Expand All @@ -94,7 +97,7 @@ public void stateChanged(ChangeEvent e) {
ZoneRenderer zr = MapTool.getFrame().getCurrentZoneRenderer();
if (zr != null) {
var zone = zr.getZone();
var mode = zone.getTopologyMode();
var mode = zone.getTopologyTypes();
if (button.isSelected()) {
mode = mode.with(type);
} else {
Expand All @@ -107,24 +110,24 @@ public void stateChanged(ChangeEvent e) {
});
}

public void setMode(Zone.TopologyMode topologyMode) {
AppPreferences.setTopologyDrawingMode(topologyMode);
if (topologyMode == null) {
topologyMode = AppPreferences.getTopologyDrawingMode();
public void setMode(Zone.TopologyTypeSet topologyTypes) {
AppPreferences.setTopologyTypes(topologyTypes);
if (topologyTypes == null) {
topologyTypes = AppPreferences.getTopologyTypes();
}

for (final var entry : modeButtons.entrySet()) {
final var topologyType = entry.getKey();
final var button = entry.getValue();

button.setSelected(topologyMode.contains(topologyType));
button.setSelected(topologyTypes.contains(topologyType));
}

// Since setting selection also triggers change listeners, we need this work even early on.
ZoneRenderer zr = MapTool.getFrame().getCurrentZoneRenderer();
// Check if there is a map. Fix #1605
if (zr != null) {
zr.getZone().setTopologyMode(topologyMode);
zr.getZone().setTopologyTypes(topologyTypes);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,11 @@ public void mousePressed(MouseEvent e) {
if (isEraser(e)) {
getZone().removeTopology(area);
MapTool.serverCommand()
.removeTopology(getZone().getId(), area, getZone().getTopologyMode());
.removeTopology(getZone().getId(), area, getZone().getTopologyTypes());
} else {
getZone().addTopology(area);
MapTool.serverCommand().addTopology(getZone().getId(), area, getZone().getTopologyMode());
MapTool.serverCommand()
.addTopology(getZone().getId(), area, getZone().getTopologyTypes());
}
renderer.repaint();
// TODO: send this to the server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,11 @@ public void mousePressed(MouseEvent e) {
if (isEraser(e)) {
getZone().removeTopology(area);
MapTool.serverCommand()
.removeTopology(getZone().getId(), area, getZone().getTopologyMode());
.removeTopology(getZone().getId(), area, getZone().getTopologyTypes());
} else {
getZone().addTopology(area);
MapTool.serverCommand().addTopology(getZone().getId(), area, getZone().getTopologyMode());
MapTool.serverCommand()
.addTopology(getZone().getId(), area, getZone().getTopologyTypes());
}
renderer.repaint();
// TODO: send this to the server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,11 @@ public void mousePressed(MouseEvent e) {
if (isEraser(e)) {
getZone().removeTopology(area);
MapTool.serverCommand()
.removeTopology(getZone().getId(), area, getZone().getTopologyMode());
.removeTopology(getZone().getId(), area, getZone().getTopologyTypes());
} else {
getZone().addTopology(area);
MapTool.serverCommand().addTopology(getZone().getId(), area, getZone().getTopologyMode());
MapTool.serverCommand()
.addTopology(getZone().getId(), area, getZone().getTopologyTypes());
}
renderer.repaint();
// TODO: send this to the server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,11 @@ public void mousePressed(MouseEvent e) {
if (isEraser(e)) {
getZone().removeTopology(area);
MapTool.serverCommand()
.removeTopology(getZone().getId(), area, getZone().getTopologyMode());
.removeTopology(getZone().getId(), area, getZone().getTopologyTypes());
} else {
getZone().addTopology(area);
MapTool.serverCommand().addTopology(getZone().getId(), area, getZone().getTopologyMode());
MapTool.serverCommand()
.addTopology(getZone().getId(), area, getZone().getTopologyTypes());
}
renderer.repaint();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,11 @@ public void mousePressed(MouseEvent e) {
if (isEraser(e)) {
getZone().removeTopology(area);
MapTool.serverCommand()
.removeTopology(getZone().getId(), area, getZone().getTopologyMode());
.removeTopology(getZone().getId(), area, getZone().getTopologyTypes());
} else {
getZone().addTopology(area);
MapTool.serverCommand().addTopology(getZone().getId(), area, getZone().getTopologyMode());
MapTool.serverCommand()
.addTopology(getZone().getId(), area, getZone().getTopologyTypes());
}
renderer.repaint();
// TODO: send this to the server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,11 @@ public void mousePressed(MouseEvent e) {
if (isEraser(e)) {
getZone().removeTopology(area);
MapTool.serverCommand()
.removeTopology(getZone().getId(), area, getZone().getTopologyMode());
.removeTopology(getZone().getId(), area, getZone().getTopologyTypes());
} else {
getZone().addTopology(area);
MapTool.serverCommand().addTopology(getZone().getId(), area, getZone().getTopologyMode());
MapTool.serverCommand()
.addTopology(getZone().getId(), area, getZone().getTopologyTypes());
}
renderer.repaint();
oval = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ protected void completeDrawable(GUID zoneGUID, Pen pen, Drawable drawable) {
}
if (pen.isEraser()) {
getZone().removeTopology(area);
MapTool.serverCommand().removeTopology(getZone().getId(), area, getZone().getTopologyMode());
MapTool.serverCommand().removeTopology(getZone().getId(), area, getZone().getTopologyTypes());
} else {
getZone().addTopology(area);
MapTool.serverCommand().addTopology(getZone().getId(), area, getZone().getTopologyMode());
MapTool.serverCommand().addTopology(getZone().getId(), area, getZone().getTopologyTypes());
}
renderer.repaint();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,11 @@ public void mousePressed(MouseEvent e) {
if (isEraser(e)) {
getZone().removeTopology(area);
MapTool.serverCommand()
.removeTopology(getZone().getId(), area, getZone().getTopologyMode());
.removeTopology(getZone().getId(), area, getZone().getTopologyTypes());
} else {
getZone().addTopology(area);
MapTool.serverCommand().addTopology(getZone().getId(), area, getZone().getTopologyMode());
MapTool.serverCommand()
.addTopology(getZone().getId(), area, getZone().getTopologyTypes());
}
renderer.repaint();
// TODO: send this to the server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1579,7 +1579,7 @@ public void setCurrentZoneRenderer(ZoneRenderer renderer) {
.fireEvent(MapTool.ZoneEvent.Activated, this, oldZone, renderer.getZone());
renderer.requestFocusInWindow();
// Updates the VBL/MBL button. Fixes #1642.
TopologyModeSelectionPanel.getInstance().setMode(renderer.getZone().getTopologyMode());
TopologyModeSelectionPanel.getInstance().setMode(renderer.getZone().getTopologyTypes());
}
AppActions.updateActions();
repaint();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -588,11 +588,11 @@ private void VblTool(Drawable drawable, boolean pathOnly, boolean isEraser) {
if (isEraser) {
renderer.getZone().removeTopology(area);
MapTool.serverCommand()
.removeTopology(renderer.getZone().getId(), area, renderer.getZone().getTopologyMode());
.removeTopology(renderer.getZone().getId(), area, renderer.getZone().getTopologyTypes());
} else {
renderer.getZone().addTopology(area);
MapTool.serverCommand()
.addTopology(renderer.getZone().getId(), area, renderer.getZone().getTopologyMode());
.addTopology(renderer.getZone().getId(), area, renderer.getZone().getTopologyTypes());
}
renderer.repaint();
}
Expand Down
Loading