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

add deployment options #4922

Merged
merged 24 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a560f8c
add team and player0 deployemnt options
kuronekochomusuke Nov 24, 2023
9640b11
typo
kuronekochomusuke Nov 24, 2023
2d419e1
code cleanup
kuronekochomusuke Nov 24, 2023
c4cd96c
handle overlapping start positions and player display
kuronekochomusuke Nov 24, 2023
cf4f166
allow limiting Any deployment to a smaller square area
kuronekochomusuke Nov 24, 2023
688dc50
code cleanup
kuronekochomusuke Nov 24, 2023
11a8d30
show player deployments on map preview
kuronekochomusuke Nov 25, 2023
ec89204
if blind drop hid player deployment zones from non gm player
kuronekochomusuke Nov 25, 2023
262b730
code cleanup
kuronekochomusuke Nov 25, 2023
b3150d6
allow gm to see and edit all units on any team hidden or not in lobby
kuronekochomusuke Nov 25, 2023
1cfebff
correct issue
kuronekochomusuke Nov 25, 2023
86a483f
save and load from mul
kuronekochomusuke Nov 26, 2023
9195c91
add ruler to map preview
kuronekochomusuke Nov 26, 2023
a106899
insure ruler is always on top of the map preview
kuronekochomusuke Nov 26, 2023
ab56dc6
apply ruler coords for deployment Any corners
kuronekochomusuke Nov 26, 2023
966f32d
update button to apply any deployment changes
kuronekochomusuke Nov 26, 2023
5163750
correct issue
kuronekochomusuke Nov 27, 2023
65cf65d
update message
kuronekochomusuke Nov 27, 2023
c2fe464
use 2 buttons
kuronekochomusuke Nov 27, 2023
3c6518d
correct gm edit issue
kuronekochomusuke Nov 27, 2023
1fad826
while in lobby and there is a gm, if player disconnects transfer the …
kuronekochomusuke Nov 27, 2023
c913302
code cleanup
kuronekochomusuke Nov 28, 2023
6df8b2f
code cleanup
kuronekochomusuke Dec 4, 2023
a1efa21
text cleanup
kuronekochomusuke Dec 19, 2023
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
9 changes: 9 additions & 0 deletions megamek/i18n/megamek/client/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ BoardSelectionDialog.UpdateSize=Update Size
BoardSelectionDialog.Updating=Updating...
BoardSelectionDialog.ViewGameBoard=Preview Game Map... *
BoardSelectionDialog.ViewGameBoardTooltip=Shows a preview of the game's map.<br> * Note: For generated maps and surprise maps the preview is only a sample<br> and will not be the same as the actual map used.
BoardSelectionDialog.ViewGameBoardButton=Refresh Preview

#Game board tooltips
BoardView1.ACTIVATING=ACTIVATING
Expand Down Expand Up @@ -772,6 +773,8 @@ ChatLounge.notDone=Not Done
ChatLounge.PartialRepairs=Partial Repairs
ChatLounge.Player=Player
ChatLounge.Players=Players
ChatLounge.Player0=Player0
ChatLounge.Blind=Blind
ChatLounge.quickView=Unit Quick View
ChatLounge.OverlapDeploy.title=Must choose exclusive deployment zone
ChatLounge.OverlapDeploy.msg=When using double blind, each player needs to have an exclusive deployment zone.
Expand Down Expand Up @@ -1430,6 +1433,12 @@ CustomMechDialog.labDeploymentOffset=Deployment Zone Offset:
CustomMechDialog.labDeploymentOffsetTip=Deployment Zone Offset, in hexes from corresponding map edge
CustomMechDialog.labDeploymentWidth=Deployment Zone Width:
CustomMechDialog.labDeploymentWidthTip=Deployment Zone width, in hexes
CustomMechDialog.labDeploymentAnyNW=Deployment Any NW corner:
CustomMechDialog.labDeploymentAnySE=Deployment Any SE corner:
CustomMechDialog.BtnDeploymentUseRuler=Use ruler coords
CustomMechDialog.BtnDeploymentUseRulerTip=Set the Any NW and SE corners based on the corners of the NW and SE corners the square defined by the map preview ruler
CustomMechDialog.BtnDeploymentApply=Apply
CustomMechDialog.BtnDeploymentApplyTip=Apply player setting
CustomMechDialog.labDeployShutdown=Shutdown
CustomMechDialog.labDeployProne=Prone
CustomMechDialog.labDeployHullDown=Hull Down
Expand Down
4 changes: 4 additions & 0 deletions megamek/i18n/megamek/common/options/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ GameOptionsInfo.option.dumping_from_round.displayableName=first round for ammo d
GameOptionsInfo.option.dumping_from_round.description=Number of the round that has to be at least reached before allowing ammo dumps.
GameOptionsInfo.option.set_arty_player_homeedge.displayableName=Automatically set artillery home edge
GameOptionsInfo.option.set_arty_player_homeedge.description=If checked, all of the players' artillery units will have their home edge set to the deployment edge of the player, NW and NE are North, SW and SE are South. \nUnchecked by default.
GameOptionsInfo.option.set_default_team_1.displayableName=Default non-bot players to team 1, useful in coop games
GameOptionsInfo.option.set_default_team_1.description=When this option is unchecked each player is assigned new team
GameOptionsInfo.option.set_player_deployment_to_player0.displayableName=Non-bot player entities with \"Use Owners*\" deployment set, use Player 0\'s settings, instead of current player\'s settings
GameOptionsInfo.option.set_player_deployment_to_player0.description=When this option is unchecked use the standard player deployments settings
GameOptionsInfo.option.restrict_game_commands.displayableName=Restrict sensitive commands to non-Observers
GameOptionsInfo.option.restrict_game_commands.description=If checked, commands such as /reset and /kick cannot be used by Observers while others are playing. \nUnchecked by default.
GameOptionsInfo.option.disable_local_save.displayableName=Disable local saves when using double blind
Expand Down
4 changes: 2 additions & 2 deletions megamek/src/megamek/client/ui/swing/ClientGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ public void windowClosing(WindowEvent e) {

Ruler.color1 = GUIP.getRulerColor1();
Ruler.color2 = GUIP.getRulerColor2();
ruler = new Ruler(frame, client, bv);
ruler = new Ruler(frame, client, bv, client.getGame());
ruler.setLocation(GUIP.getRulerPosX(), GUIP.getRulerPosY());
ruler.setSize(GUIP.getRulerSizeHeight(), GUIP.getRulerSizeWidth());
UIUtil.updateWindowBounds(ruler);
Expand Down Expand Up @@ -680,7 +680,7 @@ private void showOptions() {
}

public void customizePlayer() {
PlayerSettingsDialog psd = new PlayerSettingsDialog(this, client);
PlayerSettingsDialog psd = new PlayerSettingsDialog(this, client, bv);
psd.setVisible(true);
}

Expand Down
51 changes: 51 additions & 0 deletions megamek/src/megamek/client/ui/swing/CustomMechDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ public class CustomMechDialog extends AbstractButtonDialog implements ActionList
private final JFormattedTextField txtDeploymentOffset = new JFormattedTextField(formatterFactory);
private final JFormattedTextField txtDeploymentWidth = new JFormattedTextField(formatterFactory);

private JSpinner spinStartingAnyNWx;
private JSpinner spinStartingAnyNWy;
private JSpinner spinStartingAnySEx;
private JSpinner spinStartingAnySEy;

private final JLabel labDeployShutdown = new JLabel(
Messages.getString("CustomMechDialog.labDeployShutdown"), SwingConstants.RIGHT);
private final JCheckBox chDeployShutdown = new JCheckBox();
Expand Down Expand Up @@ -473,6 +478,17 @@ private void refreshDeployment() {
txtDeploymentOffset.setText(Integer.toString(entity.getStartingOffset(false)));
txtDeploymentWidth.setText(Integer.toString(entity.getStartingWidth(false)));

int bh = clientgui.getClient().getMapSettings().getBoardHeight();
int bw = clientgui.getClient().getMapSettings().getBoardWidth();
int x = Math.min(entity.getStartingAnyNWx(false) + 1, bw);
spinStartingAnyNWx.setValue(x);
int y = Math.min(entity.getStartingAnyNWy(false) + 1, bh);
spinStartingAnyNWy.setValue(y);
x = Math.min(entity.getStartingAnySEx(false) + 1, bw);
spinStartingAnySEy.setValue(x);
y = Math.min(entity.getStartingAnySEy(false) + 1, bh);
spinStartingAnySEy.setValue(y);

boolean enableDeploymentZoneControls = choDeploymentZone.isEnabled() && (choDeploymentZone.getSelectedIndex() > 0);
txtDeploymentOffset.setEnabled(enableDeploymentZoneControls);
txtDeploymentWidth.setEnabled(enableDeploymentZoneControls);
Expand Down Expand Up @@ -881,6 +897,15 @@ protected void okAction() {
entity.setStartingOffset(Integer.parseInt(txtDeploymentOffset.getText()));
entity.setStartingWidth(Integer.parseInt(txtDeploymentWidth.getText()));

int x = Math.min((Integer) spinStartingAnyNWx.getValue(), (Integer) spinStartingAnySEx.getValue());
int y = Math.min((Integer) spinStartingAnyNWy.getValue(), (Integer) spinStartingAnySEy.getValue());
entity.setStartingAnyNWx(x - 1);
entity.setStartingAnyNWy(y - 1);
x = Math.max((Integer) spinStartingAnyNWx.getValue(), (Integer) spinStartingAnySEx.getValue());
y = Math.max((Integer) spinStartingAnyNWy.getValue(), (Integer) spinStartingAnySEy.getValue());
entity.setStartingAnySEx(x - 1);
entity.setStartingAnySEy(y - 1);

// Should the entity begin the game shutdown?
if (chDeployShutdown.isSelected() && gameOptions().booleanOption(OptionsConstants.RPG_BEGIN_SHUTDOWN)) {
entity.performManualShutdown();
Expand Down Expand Up @@ -1200,6 +1225,32 @@ protected Container createCenterPane() {
panDeploy.add(labDeploymentWidth, GBC.std());
panDeploy.add(txtDeploymentWidth, GBC.eol());

int bh = clientgui.getClient().getMapSettings().getBoardHeight();
int bw = clientgui.getClient().getMapSettings().getBoardWidth();

panDeploy.add(new JLabel(Messages.getString("CustomMechDialog.labDeploymentAnyNW")), GBC.std());
int x = Math.min(entity.getStartingAnyNWx(false) + 1, bw);
SpinnerNumberModel mStartingAnyNWx = new SpinnerNumberModel(x, 0,bw, 1);
spinStartingAnyNWx = new JSpinner(mStartingAnyNWx);
spinStartingAnyNWx.setValue(x);
panDeploy.add(spinStartingAnyNWx, GBC.std());
int y = Math.min(entity.getStartingAnyNWy(false) + 1, bh);
SpinnerNumberModel mStartingAnyNWy = new SpinnerNumberModel(y, 0, bh, 1);
spinStartingAnyNWy = new JSpinner(mStartingAnyNWy);
spinStartingAnyNWy.setValue(y);
panDeploy.add(spinStartingAnyNWy, GBC.eol());
panDeploy.add(new JLabel(Messages.getString("CustomMechDialog.labDeploymentAnySE")), GBC.std());
x = Math.min(entity.getStartingAnySEx(false) + 1, bw);
SpinnerNumberModel mStartingAnySEx = new SpinnerNumberModel(x, 0, bw, 1);
spinStartingAnySEx = new JSpinner(mStartingAnySEx);
spinStartingAnySEx.setValue(x);
panDeploy.add(spinStartingAnySEx, GBC.std());
y = Math.min(entity.getStartingAnySEy(false) + 1, bh);
SpinnerNumberModel mStartingAnySEy = new SpinnerNumberModel(y, -0, bh, 1);
spinStartingAnySEy = new JSpinner(mStartingAnySEy);
spinStartingAnySEy.setValue(y);
panDeploy.add(spinStartingAnySEy, GBC.eol());

numFormatter.setMinimum(0);
numFormatter.setCommitsOnValidEdit(true);

Expand Down
28 changes: 15 additions & 13 deletions megamek/src/megamek/client/ui/swing/Ruler.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class Ruler extends JDialog implements BoardViewListener, IPreferenceChan
private int distance;
private Client client;
private BoardView bv;
private Game game;
private boolean flip;

private JPanel buttonPanel;
Expand All @@ -69,7 +70,7 @@ public class Ruler extends JDialog implements BoardViewListener, IPreferenceChan
private JCheckBox cboIsMech2 =
new JCheckBox(Messages.getString("Ruler.isMech"));

public Ruler(JFrame f, Client c, BoardView b) {
public Ruler(JFrame f, Client c, BoardView b, Game g) {
super(f, Messages.getString("Ruler.title"), false);
enableEvents(AWTEvent.WINDOW_EVENT_MASK);

Expand All @@ -81,6 +82,7 @@ public Ruler(JFrame f, Client c, BoardView b) {

bv = b;
client = c;
game = g;
b.addBoardViewListener(this);

try {
Expand Down Expand Up @@ -273,7 +275,7 @@ private void addPoint(Coords c) {
int absHeight = Integer.MIN_VALUE;
boolean isMech = false;
boolean entFound = false;
for (Entity ent : client.getGame().getEntitiesVector(c)) {
for (Entity ent : game.getEntitiesVector(c)) {
int trAbsheight = ent.relHeight();
if (trAbsheight > absHeight) {
absHeight = trAbsheight;
Expand Down Expand Up @@ -316,34 +318,34 @@ private void setText() {
// leave at default value
}

if (!client.getGame().getBoard().contains(start) || !client.getGame().getBoard().contains(end)) {
if (!game.getBoard().contains(start) || !game.getBoard().contains(end)) {
return;
}

String toHit1 = "", toHit2 = "";
ToHitData thd;
if (flip) {
thd = LosEffects.calculateLos(client.getGame(),
thd = LosEffects.calculateLos(game,
buildAttackInfo(start, end, h1, h2, cboIsMech1.isSelected(),
cboIsMech2.isSelected())).losModifiers(client.getGame());
cboIsMech2.isSelected())).losModifiers(game);
} else {
thd = LosEffects.calculateLos(client.getGame(),
thd = LosEffects.calculateLos(game,
buildAttackInfo(end, start, h2, h1, cboIsMech2.isSelected(),
cboIsMech1.isSelected())).losModifiers(client.getGame());
cboIsMech1.isSelected())).losModifiers(game);
}
if (thd.getValue() != TargetRoll.IMPOSSIBLE) {
toHit1 = thd.getValue() + " = ";
}
toHit1 += thd.getDesc();

if (flip) {
thd = LosEffects.calculateLos(client.getGame(),
thd = LosEffects.calculateLos(game,
buildAttackInfo(end, start, h2, h1, cboIsMech2.isSelected(),
cboIsMech1.isSelected())).losModifiers(client.getGame());
cboIsMech1.isSelected())).losModifiers(game);
} else {
thd = LosEffects.calculateLos(client.getGame(),
thd = LosEffects.calculateLos(game,
buildAttackInfo(start, end, h1, h2, cboIsMech1.isSelected(),
cboIsMech2.isSelected())).losModifiers(client.getGame());
cboIsMech2.isSelected())).losModifiers(game);
}
if (thd.getValue() != TargetRoll.IMPOSSIBLE) {
toHit2 = thd.getValue() + " = ";
Expand Down Expand Up @@ -377,8 +379,8 @@ private LosEffects.AttackInfo buildAttackInfo(Coords c1, Coords c2, int h1,
ai.targetHeight = h2;
ai.attackerIsMech = attackerIsMech;
ai.targetIsMech = targetIsMech;
ai.attackAbsHeight = client.getGame().getBoard().getHex(c1).floor() + h1;
ai.targetAbsHeight = client.getGame().getBoard().getHex(c2).floor() + h2;
ai.attackAbsHeight = game.getBoard().getHex(c1).floor() + h1;
ai.targetAbsHeight = game.getBoard().getHex(c2).floor() + h2;
return ai;
}

Expand Down
33 changes: 26 additions & 7 deletions megamek/src/megamek/client/ui/swing/boardview/BoardView.java
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,8 @@ public synchronized void paintComponent(Graphics g) {
drawDeployment(g);
}

if (game.getPhase().isSetArtilleryAutohitHexes() && showAllDeployment) {
if ((game.getPhase().isSetArtilleryAutohitHexes() && showAllDeployment)
|| (game.getPhase().isLounge())) {
drawAllDeployment(g);
}

Expand Down Expand Up @@ -1850,20 +1851,30 @@ private void drawAllDeployment(Graphics g) {
int drawWidth = (view.width / (int) (HEX_WC * scale)) + 3;
int drawHeight = (view.height / (int) (HEX_H * scale)) + 3;

List<Player> players = game.getPlayersList();
final GameOptions gOpts = game.getOptions();

if (gOpts.booleanOption(OptionsConstants.BASE_SET_PLAYER_DEPLOYMENT_TO_PLAYER0)) {
players = players.stream().filter(p -> p.isBot() || p.getId() == 0).collect(Collectors.toList());
}

if (game.getPhase().isLounge() && !localPlayer.isGameMaster()
&& (gOpts.booleanOption(OptionsConstants.BASE_BLIND_DROP)
|| gOpts.booleanOption(OptionsConstants.BASE_REAL_BLIND_DROP)) ) {
players = players.stream().filter(p -> !p.isEnemyOf(localPlayer)).collect(Collectors.toList());
}

Board board = game.getBoard();
// loop through the hexes
for (int i = 0; i < drawHeight; i++) {
for (int j = 0; j < drawWidth; j++) {
Coords c = new Coords(j + drawX, i + drawY);
Enumeration<Player> allP = game.getPlayers();
Player cp;
int pCount = 0;
int bThickness = 1 + 10 / game.getNoOfPlayers();
// loop through all players
while (allP.hasMoreElements()) {
cp = allP.nextElement();
if (board.isLegalDeployment(c, cp)) {
Color bC = cp.getColour().getColour();
for (Player player : players) {
if (board.isLegalDeployment(c, player)) {
Color bC = player.getColour().getColour();
drawHexBorder(g, getHexLocation(c), bC, (bThickness + 2) * pCount, bThickness);
pCount++;
}
Expand Down Expand Up @@ -3147,6 +3158,14 @@ public void drawRuler(Coords s, Coords e, Color sc, Color ec) {
repaint();
}

public Coords getRulerStart() {
return rulerStart;
}

public Coords getRulerEnd() {
return rulerEnd;
}

/**
* @return the coords at the specified point
*/
Expand Down
Loading