Skip to content

Commit

Permalink
Merge pull request #5924 from NickAragua/custom_deployment_zones
Browse files Browse the repository at this point in the history
custom deployment zones
  • Loading branch information
NickAragua authored Sep 9, 2024
2 parents 66af4bd + 76782c9 commit a1ff343
Show file tree
Hide file tree
Showing 27 changed files with 525 additions and 168 deletions.
1 change: 1 addition & 0 deletions megamek/data/images/hexes/atmospheric.tileset
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,4 @@ base 2 "tundra:1" "" "tundra/tundra_2.gif"
base 3 "tundra:1" "" "tundra/tundra_3.gif"

base * "impassable:1" "" "boring/solidrock.gif"
super * "deployment_zone:*" "" "saxarba/misc/blank.png"
1 change: 1 addition & 0 deletions megamek/data/images/hexes/bw_atmospheric.tileset
Original file line number Diff line number Diff line change
Expand Up @@ -321,3 +321,4 @@ base 2 "tundra:1" "" "tundra/tundra_2.gif"
base 3 "tundra:1" "" "tundra/tundra_3.gif"

base * "impassable:1" "" "largeTextures/BigRock.jpg"
super * "deployment_zone:*" "" "saxarba/misc/blank.png"
2 changes: 2 additions & 0 deletions megamek/data/images/hexes/classic.tileset
Original file line number Diff line number Diff line change
Expand Up @@ -538,3 +538,5 @@ base -3 "" "volcano" "volcano/volcano_sinkhole_3.gif"
base -4 "" "volcano" "volcano/volcano_sinkhole_4.gif"

#------------------- END volcano theme

super * "deployment_zone:*" "" "saxarba/misc/blank.png"
1 change: 1 addition & 0 deletions megamek/data/images/hexes/hq_atmospheric.tileset
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,4 @@ base 2 "tundra:1" "" "tundra/tundra_2.gif"
base 3 "tundra:1" "" "tundra/tundra_3.gif"

base * "impassable:1" "" "boring/solidrock.gif"
super * "deployment_zone:*" "" "saxarba/misc/blank.png"
1 change: 1 addition & 0 deletions megamek/data/images/hexes/hq_isometric.tileset
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,4 @@ base 2 "tundra:1" "" "tundra/tundra_2.gif"
base 3 "tundra:1" "" "tundra/tundra_3.gif"

base * "impassable:1" "" "boring/solidrock.gif"
super * "deployment_zone:*" "" "saxarba/misc/blank.png"
3 changes: 2 additions & 1 deletion megamek/data/images/hexes/hq_saxarba.tileset
Original file line number Diff line number Diff line change
Expand Up @@ -659,4 +659,5 @@ super * "water_fluff:*" "" "saxarba/misc/blank.png"
super * "bldg_fluff:*" "" "saxarba/misc/blank.png"

super * "bldg_class:0" "" "saxarba/misc/blank.png"
super * "fluff:1000:1000" "grass" "saxarba/misc/blank.png"
super * "fluff:1000:1000" "grass" "saxarba/misc/blank.png"
super * "deployment_zone:*" "" "saxarba/misc/blank.png"
1 change: 1 addition & 0 deletions megamek/data/images/hexes/isometric.tileset
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,4 @@ base 2 "tundra:1" "" "tundra/tundra_2.gif"
base 3 "tundra:1" "" "tundra/tundra_3.gif"

base * "impassable:1" "" "boring/solidrock.gif"
super * "deployment_zone:*" "" "saxarba/misc/blank.png"
1 change: 1 addition & 0 deletions megamek/data/images/hexes/largeTextures.tileset
Original file line number Diff line number Diff line change
Expand Up @@ -761,3 +761,4 @@ base 10 "bldg_basement_type:*" "" "Ahne/iLarge_Textures_pavement/grey_pavement_0
base -1 "bldg_basement_type:*" "" "Ahne/iLarge_Textures_pavement/grey_pavement_6.gif"
base -2 "bldg_basement_type:*" "" "Ahne/iLarge_Textures_pavement/grey_pavement_7.gif"
base -3 "bldg_basement_type:*" "" "Ahne/iLarge_Textures_pavement/grey_pavement_8.gif"
super * "deployment_zone:*" "" "saxarba/misc/blank.png"
1 change: 1 addition & 0 deletions megamek/data/images/hexes/saxarba.tileset
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,7 @@ base 10 "" "lunar" "saxarba/theme_lunar/base_lunar_10.png;saxarba/theme_lunar/ba
base * "sky:1" "" "atmospheric_map/sky.png"

# To avoid errors
super * "deployment_zone:*" "" "saxarba/misc/blank.png"
super * "fluff:*" "" "saxarba/misc/blank.png"
super * "road_fluff:*" "" "saxarba/misc/blank.png"
super * "ground_fluff:*" "" "saxarba/misc/blank.png"
Expand Down
4 changes: 4 additions & 0 deletions megamek/i18n/megamek/client/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ BoardEditor.waitDialog.message=Saving board as image...
BoardEditor.waitDialog.title=Please wait...
BoardEditor.helpText=<HTML><U>General Info:</U> <FONT COLOR=BLUE><I> - Click to hide -</I></FONT><BR>Click the map to paint the terrain <I>without</I> elevation<BR>CTRL-Click the map to paint the terrain <I>with</I> elevation<BR>SHIFT-Click the map to <I>add</I> terrain<BR>ALT-Click the map to retrieve its terrain (eyedropper tool)</HTML>
BoardEditor.helpText2=<HTML><U>Info for the terrain buttons:</U><BR>Click to select a terrain type<BR>SHIFT-click to add terrain type<BR><FONT COLOR=RED>Additional info in the button tooltips!</FONT></HTML>
BoardEditor.deploymentZoneIDs=Zone IDs
BoardEditor.deploymentZoneSelectorName=Select Deployment Zone IDs
BoardEditor.deploymentZoneSelectorTitle=Select Deployment Zone IDs
BoardEditor.deploymentZoneSelectorDescription=Select Deployment Zone IDs from the list below
#Below are assigned dynamically, and are actually used. It just does not appear so because of how they are used
BoardEditor.ButtonLWTT=<HTML>Woods<BR>Mouse Wheel on the button to change between Light, Heavy and Ultra</HTML>
BoardEditor.ButtonLJTT=<HTML>Jungle<BR>Mouse Wheel on the button to change between Light, Heavy and Ultra</HTML>
Expand Down
2 changes: 2 additions & 0 deletions megamek/i18n/megamek/common/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ Terrains.editorName.incline_bottom=Incline Bottom
Terrains.editorName.incline_high_top=High Incline Top
Terrains.editorName.incline_high_bottom=High Incline Bottom
Terrains.editorName.cliff_bottom=Cliff Bottom
Terrains.editorName.deployment_zone=Deployment Zone

Terrains.editorTooltip.woods=Woods
Terrains.editorTooltip.water=Water
Expand Down Expand Up @@ -469,6 +470,7 @@ Terrains.editorTooltip.road_fluff=Special road images
Terrains.editorTooltip.ground_fluff=Special ground images
Terrains.editorTooltip.water_fluff=Special water images
Terrains.editorTooltip.foliage_elev=Defines how tall the woods/jungle is (required)
Terrains.editorTooltip.deployment_zone=A custom deployment zone (level is group #)

WeaponType.DirectFire=Direct fire
WeaponType.BallisticCluster=Ballistic Cluster
Expand Down
2 changes: 2 additions & 0 deletions megamek/src/megamek/MMConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,6 @@ private MMConstants() {
public static final int TSEMP_EFFECT_INTERFERENCE = 1;
public static final int TSEMP_EFFECT_SHUTDOWN = 2;
// endregion Magic Numbers That Should Be Enums

public static final String CL_KEY_FILEEXTENTION_BOARD = ".board";
}
9 changes: 5 additions & 4 deletions megamek/src/megamek/client/ui/dialogs/BotConfigDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@
import megamek.client.ui.swing.util.UIUtil.*;
import megamek.common.*;
import megamek.common.annotations.Nullable;
import megamek.server.ServerBoardHelper;

import org.apache.logging.log4j.LogManager;

import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import javax.swing.border.TitledBorder;
import javax.swing.event.ChangeEvent;
Expand Down Expand Up @@ -211,7 +212,7 @@ private String getFreePrincessName() {
String name = baseName;
if (client != null) {
int counter = 0;
Set<String> playerNames = client.getGame().getPlayersVector().stream().map(Player::getName).collect(Collectors.toSet());
Set<String> playerNames = client.getGame().getPlayersList().stream().map(Player::getName).collect(Collectors.toSet());
while (playerNames.contains(name) && counter < 1000) {
counter++;
name = baseName + counter;
Expand Down Expand Up @@ -495,7 +496,7 @@ protected void okButtonActionPerformed(ActionEvent evt) {
// adding ".2" when necessary. But it has to be unique among local bots as otherwise
// the connection between the client.bots stored name and the server-given name
// gets lost. It doesn't hurt to check against all players though.
boolean playerNameTaken = (client != null) && client.getGame().getPlayersVector().stream()
boolean playerNameTaken = (client != null) && client.getGame().getPlayersList().stream()
.anyMatch(p -> p.getName().equals(nameField.getText()));
if (isNewBot && playerNameTaken) {
JOptionPane.showMessageDialog(getFrame(), Messages.getString("ChatLounge.AlertExistsBot.message"));
Expand Down Expand Up @@ -806,7 +807,7 @@ public Component getListCellRendererComponent(JList<?> list, Object value, int i
if (client != null) {
Board board = client.getBoard();
if (client.getGame().getPhase().isLounge()) {
board = clientGui.chatlounge.getPossibleGameBoard(true);
board = ServerBoardHelper.getPossibleGameBoard(clientGui.getClient().getMapSettings(), true);
}
if (board == null) {
content += Messages.getString("BotConfigDialog.hexListNoMp");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import megamek.common.Coords;
import megamek.common.Hex;
import megamek.common.annotations.Nullable;
import megamek.server.ServerBoardHelper;

import javax.swing.*;
import java.awt.*;
Expand Down Expand Up @@ -58,7 +59,7 @@ protected BotConfigTargetHexDialog(JFrame frame, @Nullable ClientGUI cg) {
clientGui = cg;
if (clientGui != null) {
if (clientGui.getClient().getGame().getPhase().isLounge()) {
board = clientGui.chatlounge.getPossibleGameBoard(true);
board = ServerBoardHelper.getPossibleGameBoard(clientGui.getClient().getMapSettings(), true);
} else {
board = clientGui.getClient().getBoard();
}
Expand Down
50 changes: 43 additions & 7 deletions megamek/src/megamek/client/ui/swing/BoardEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import megamek.client.ui.swing.dialog.FloodDialog;
import megamek.client.ui.swing.dialog.LevelChangeDialog;
import megamek.client.ui.swing.dialog.MMConfirmDialog;
import megamek.client.ui.swing.dialog.MultiIntSelectorDialog;
import megamek.client.ui.swing.minimap.Minimap;
import megamek.client.ui.swing.tileset.HexTileset;
import megamek.client.ui.swing.tileset.TilesetManager;
Expand Down Expand Up @@ -202,6 +203,7 @@ public void setTerrainTypes(List<TerrainTypeHelper> terrainTypes) {

private static final int BASE_TERRAINBUTTON_ICON_WIDTH = 70;
private static final int BASE_ARROWBUTTON_ICON_WIDTH = 25;
private static final String CMD_EDIT_DEPLOYMENT_ZONES = "CMD_EDIT_DEPLOYMENT_ZONES";

// Components
private final JFrame frame = new JFrame();
Expand Down Expand Up @@ -914,6 +916,27 @@ private void setupEditorPanel() {
choTerrainType.addActionListener(e -> {
if (!terrListBlocker) {
lisTerrain.clearSelection();

// if we've selected DEPLOYMENT ZONE, disable the "exits" buttons
// and make the "exits" popup point to a multi-select list that lets
// the user choose which deployment zones will be flagged here

// otherwise, re-enable all the buttons and reset the "exits" popup to its normal behavior
if (((TerrainHelper) choTerrainType.getSelectedItem()).getTerrainType() == Terrains.DEPLOYMENT_ZONE) {
butExitUp.setEnabled(false);
butExitDown.setEnabled(false);
texTerrExits.setEnabled(false);
cheTerrExitSpecified.setEnabled(false);
cheTerrExitSpecified.setText("Zones");//Messages.getString("BoardEditor.deploymentZoneIDs"));
butTerrExits.setActionCommand(CMD_EDIT_DEPLOYMENT_ZONES);
} else {
butExitUp.setEnabled(true);
butExitDown.setEnabled(true);
texTerrExits.setEnabled(true);
cheTerrExitSpecified.setEnabled(true);
cheTerrExitSpecified.setText(Messages.getString("BoardEditor.cheTerrExitSpecified"));
butTerrExits.setActionCommand("");
}
}
});
choTerrainType.setFont(fontComboTerr);
Expand Down Expand Up @@ -1255,8 +1278,10 @@ private void addSetTerrain() {
Messages.getString("BoardEditor.invalidTerrainTitle"),
JOptionPane.ERROR_MESSAGE);
return;
}
}

curHex.addTerrain(toAdd);

noTextFieldUpdate = true;
refreshTerrainList();
repaintWorkingHex();
Expand Down Expand Up @@ -1878,12 +1903,23 @@ public void actionPerformed(ActionEvent ae) {
}
updateWhenSelected();
} else if (ae.getSource().equals(butTerrExits)) {
ExitsDialog ed = new ExitsDialog(frame);
int exitsVal = texTerrExits.getNumber();
ed.setExits(exitsVal);
ed.setVisible(true);
exitsVal = ed.getExits();
texTerrExits.setNumber(exitsVal);
int exitsVal = 0;

if (ae.getActionCommand().equals(CMD_EDIT_DEPLOYMENT_ZONES)) {
var dlg = new MultiIntSelectorDialog(frame, "BoardEditor.deploymentZoneSelectorName",
"BoardEditor.deploymentZoneSelectorTitle", "BoardEditor.deploymentZoneSelectorDescription",
Board.MAX_DEPLOYMENT_ZONE_NUMBER, Board.exitsAsIntList(texTerrExits.getNumber()));
dlg.setVisible(true);
exitsVal = Board.IntListAsExits(dlg.getSelectedItems());
texTerrExits.setNumber(exitsVal);
} else {
ExitsDialog ed = new ExitsDialog(frame);
exitsVal = texTerrExits.getNumber();
ed.setExits(exitsVal);
ed.setVisible(true);
exitsVal = ed.getExits();
texTerrExits.setNumber(exitsVal);
}
setExitsState(exitsVal != 0);
updateWhenSelected();
} else if (ae.getSource().equals(cheTerrExitSpecified)) {
Expand Down
29 changes: 25 additions & 4 deletions megamek/src/megamek/client/ui/swing/CustomMechDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import megamek.common.verifier.TestEntity;
import megamek.common.weapons.bayweapons.ArtilleryBayWeapon;
import megamek.common.weapons.bayweapons.CapitalMissileBayWeapon;
import megamek.server.ServerBoardHelper;

import javax.swing.*;
import javax.swing.text.DefaultFormatterFactory;
Expand Down Expand Up @@ -482,8 +483,19 @@ private void refreshDeployment() {
choDeploymentZone.addItem(Messages.getString("CustomMechDialog.deployW"));
choDeploymentZone.addItem(Messages.getString("CustomMechDialog.deployEdge"));
choDeploymentZone.addItem(Messages.getString("CustomMechDialog.deployCenter"));

for (int zoneID : ServerBoardHelper.getPossibleGameBoard(clientgui.getClient().getMapSettings(), true)
.getCustomDeploymentZones()) {
choDeploymentZone.addItem("Zone " + zoneID);
}

choDeploymentZone.setSelectedIndex(entity.getStartingPos(false) + 1);
int startingPos = entity.getStartingPos(false);

if (entity.getStartingPos(false) < Board.NUM_ZONES) {
choDeploymentZone.setSelectedIndex(startingPos + 1);
} else {
choDeploymentZone.setSelectedItem("Zone " + startingPos);
}

choDeploymentZone.addItemListener(this);

Expand All @@ -503,7 +515,8 @@ private void refreshDeployment() {
y = Math.min(entity.getStartingAnySEy(false) + 1, bh);
spinStartingAnySEy.setValue(y);

boolean enableDeploymentZoneControls = choDeploymentZone.isEnabled() && (choDeploymentZone.getSelectedIndex() > 0);
boolean enableDeploymentZoneControls = choDeploymentZone.isEnabled() && (choDeploymentZone.getSelectedIndex() > 0)
&& (choDeploymentZone.getSelectedIndex() < Board.NUM_ZONES);
txtDeploymentOffset.setEnabled(enableDeploymentZoneControls);
txtDeploymentWidth.setEnabled(enableDeploymentZoneControls);

Expand Down Expand Up @@ -913,7 +926,14 @@ protected void okAction() {
}

// Set the entity's deployment position and round.
entity.setStartingPos(choDeploymentZone.getSelectedIndex() - 1);
// parse the non-standard deployment zones
int zoneID = choDeploymentZone.getSelectedIndex() - 1;
if (zoneID >= Board.NUM_ZONES) {
zoneID = Integer.parseInt(choDeploymentZone.getSelectedItem().toString().substring(5));
zoneID = Board.encodeCustomDeploymentZoneID(zoneID);
}

entity.setStartingPos(zoneID);
entity.setDeployRound(choDeploymentRound.getSelectedIndex());
entity.setStartingOffset(Integer.parseInt(txtDeploymentOffset.getText()));
entity.setStartingWidth(Integer.parseInt(txtDeploymentWidth.getText()));
Expand Down Expand Up @@ -975,7 +995,8 @@ public void itemStateChanged(ItemEvent itemEvent) {
}

if (itemEvent.getSource().equals(choDeploymentZone)) {
boolean enableDeploymentZoneControls = choDeploymentZone.isEnabled() && (choDeploymentZone.getSelectedIndex() > 0);
boolean enableDeploymentZoneControls = choDeploymentZone.isEnabled() && (choDeploymentZone.getSelectedIndex() > 0) &&
choDeploymentZone.getSelectedIndex() < Board.NUM_ZONES;
txtDeploymentOffset.setEnabled(enableDeploymentZoneControls);
txtDeploymentWidth.setEnabled(enableDeploymentZoneControls);
}
Expand Down
6 changes: 6 additions & 0 deletions megamek/src/megamek/client/ui/swing/boardview/BoardView.java
Original file line number Diff line number Diff line change
Expand Up @@ -2013,6 +2013,12 @@ private void drawHex(Coords c, Graphics boardGraph, boolean saveBoardImage) {
}
}
}

if (hex.containsTerrain(Terrains.DEPLOYMENT_ZONE) && (game.getPhase().isUnknown())) {
drawHexBorder(g, Color.yellow, 5, 5);
drawCenteredString("DZ " + Board.exitsAsIntList(hex.getTerrain(Terrains.DEPLOYMENT_ZONE).getExits()),
0, (int) (50 * scale), font_note, g);
}

// Set the text color according to Preferences or Light Gray in space
g.setColor(GUIP.getBoardTextColor());
Expand Down
Loading

0 comments on commit a1ff343

Please sign in to comment.