Skip to content

Commit

Permalink
Merge pull request #4985 from kuronekochomusuke/forceDisplay
Browse files Browse the repository at this point in the history
add in game force display dialog
  • Loading branch information
HammerGS authored Jan 15, 2024
2 parents 4683996 + fc20c63 commit 3608486
Show file tree
Hide file tree
Showing 16 changed files with 1,367 additions and 105 deletions.
7 changes: 7 additions & 0 deletions megamek/i18n/megamek/client/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ BoardView1.Tooltip.Clan=(C)
BoardView1.Tooltip.ClanBrackets=[Clan]
BoardView1.Tooltip.ClanParens=(Clan)
BoardView1.Tooltip.Crippled=CRIPPLED
BoardView1.Tooltip.Destroyed=DESTROYED
BoardView1.Tooltip.C3=C3
BoardView1.Tooltip.C3CC=C3CC
BoardView1.Tooltip.C3i=C3i
Expand Down Expand Up @@ -876,6 +877,7 @@ ClientGUI.FatalError.title=Fatal Error
ClientGUI.FileSaveDialog.title=Select file to save to...
ClientGUI.FileSaveServerDialog.title=Select file to save to...
ClientGUI.FileSaveServerDialog.message=Please enter the filename under which the game will be saved to in the server's savegames directory.
ClientGUI.ForceDisplay=Force Display
ClientGUI.gameSaveDialogMessage=Do you want to save the game before quitting MegaMek?
ClientGUI.gameSaveFirst=Save First?
ClientGUI.Hide=Hide
Expand Down Expand Up @@ -1074,6 +1076,7 @@ CommonMenuBar.viewPlayerSettings=Player Settings
CommonMenuBar.viewClientSettings=Client Settings
CommonMenuBar.viewGameOptions=Game Options...
CommonMenuBar.viewLOSSetting=LOS Setting
CommonMenuBar.viewForceDisplay=Force Display
CommonMenuBar.viewMekDisplay=Unit Display
CommonMenuBar.viewAccessibilityWindow=Accessibility Window
CommonMenuBar.viewIncGUIScale=Increase GUI Scale
Expand Down Expand Up @@ -1201,6 +1204,9 @@ CommonSettingsDialog.colors.UnitTooltipWeaponColor=Weapon Color
CommonSettingsDialog.colors.UnitTooltipQuirkColor=Quirk Color
CommonSettingsDialog.colors.VisualRangeColor=Visual Range Color
CommonSettingsDialog.colors.warningColor=Warning Color
CommonSettingsDialog.colors.myUnitColor=My Unit Color
CommonSettingsDialog.colors.allyUnitColor=Ally Unit Color
CommonSettingsDialog.colors.enemyUnitColor=Enemy Unit Color
CommonSettingsDialog.darkenMapAtNight=Darken Map At Night
CommonSettingsDialog.defaultAutoejectDisabled=Disable automatic ejection by default for units added in the lobby.
CommonSettingsDialog.defaultWeaponSortOrder.tooltip=<html>Sets the default weapon sort order for chassis/models without a specified default. <br>Changing this setting won't affect games already in progress.</html>
Expand Down Expand Up @@ -1862,6 +1868,7 @@ KeyBinds.cmdNames.toggleMinimap=Toggle Minimap
KeyBinds.cmdDesc.toggleMinimap=Turns the Minimap on and off
KeyBinds.cmdNames.viewLosSetting=LOS Settings
KeyBinds.cmdDesc.viewLosSetting=Shows the LOS settings dialog
KeyBinds.cmdNames.toggleForceDisplay=Toggle Force Display
KeyBinds.cmdNames.toggleUnitDisplay=Toggle Unit Display
KeyBinds.cmdDesc.toggleUnitDisplay=Turns the unit display window on and off
KeyBinds.cmdNames.toggleUnitOverview=Toggle Unit Overview
Expand Down
11 changes: 9 additions & 2 deletions megamek/mmconf/defaultKeyBinds.xml
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,15 @@
</KeyBind>

<KeyBind>
<command>undoIllegalSteps</command> <!-- Ctrl+BackSpace -->
<keyCode>8</keyCode>
<command>undoIllegalSteps</command> <!-- Ctrl+BackSpace -->
<keyCode>8</keyCode>
<modifier>128</modifier>
<isRepeatable>false</isRepeatable>
</KeyBind>

<KeyBind>
<command>toggleForceDisplay</command> <!-- Ctrl-F -->
<keyCode>70</keyCode>
<modifier>128</modifier>
<isRepeatable>false</isRepeatable>
</KeyBind>
Expand Down
73 changes: 73 additions & 0 deletions megamek/src/megamek/client/ui/swing/ClientGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import megamek.client.ui.swing.boardview.BoardView;
import megamek.client.ui.swing.dialog.AbstractUnitSelectorDialog;
import megamek.client.ui.swing.dialog.MegaMekUnitSelectorDialog;
import megamek.client.ui.swing.forceDisplay.ForceDisplayDialog;
import megamek.client.ui.swing.forceDisplay.ForceDisplayPanel;
import megamek.client.ui.swing.lobby.ChatLounge;
import megamek.client.ui.swing.lobby.PlayerSettingsDialog;
import megamek.client.ui.swing.minimap.Minimap;
Expand Down Expand Up @@ -146,6 +148,7 @@ public class ClientGUI extends JPanel implements BoardViewListener,
// region view menu
public static final String VIEW_INCGUISCALE = "viewIncGUIScale";
public static final String VIEW_DECGUISCALE = "viewDecGUIScale";
public static final String VIEW_FORCE_DISPLAY = "viewForceDisplay";
public static final String VIEW_UNIT_DISPLAY = "viewMekDisplay";
public static final String VIEW_ACCESSIBILITY_WINDOW = "viewAccessibilityWindow";
public static final String VIEW_KEYBINDS_OVERLAY = "viewKeyboardShortcuts";
Expand Down Expand Up @@ -242,6 +245,10 @@ public class ClientGUI extends JPanel implements BoardViewListener,

public UnitDisplay unitDisplay;
private UnitDisplayDialog unitDisplayDialog;

public ForceDisplayPanel forceDisplayPanel;
private ForceDisplayDialog forceDisplayDialog;

public JDialog minimapW;
private MapMenu popup;
private UnitOverview uo;
Expand Down Expand Up @@ -373,6 +380,22 @@ public void setUnitDisplayDialog(final UnitDisplayDialog unitDisplayDialog) {
this.unitDisplayDialog = unitDisplayDialog;
}

public ForceDisplayPanel getForceDisplayPanel() {
return forceDisplayPanel;
}

public void setForceDisplayPanel(final ForceDisplayPanel forceDisplayPanel) {
this.forceDisplayPanel = forceDisplayPanel;
}

public ForceDisplayDialog getForceDisplayDialog() {
return forceDisplayDialog;
}

public void setForceDisplayDialog(final ForceDisplayDialog forceDisplayDialog) {
this.forceDisplayDialog = forceDisplayDialog;
}

public JDialog getMiniMapDialog() {
return minimapW;
}
Expand Down Expand Up @@ -578,6 +601,11 @@ public void windowClosing(WindowEvent e) {
setUnitDisplayDialog(new UnitDisplayDialog(getFrame(), this));
getUnitDisplayDialog().setVisible(false);

setForceDisplayPanel(new ForceDisplayPanel(this));
setForceDisplayDialog(new ForceDisplayDialog(getFrame(), this));
getForceDisplayDialog().add(getForceDisplayPanel(), BorderLayout.CENTER);
getForceDisplayDialog().setVisible(false);

setMiniReportDisplay(new MiniReportDisplay(this));
setMiniReportDisplayDialog(new MiniReportDisplayDialog(getFrame(), this));
getMiniReportDisplayDialog().setVisible(false);
Expand Down Expand Up @@ -740,6 +768,9 @@ public void resetWindowPositions() {
if (getUnitDisplayDialog() != null) {
getUnitDisplayDialog().setBounds(0, 0, getUnitDisplay().getWidth(), getUnitDisplay().getHeight());
}
if (getForceDisplayDialog() != null) {
getForceDisplayDialog().setBounds(0, 0, getForceDisplayPanel().getWidth(), getForceDisplayPanel().getHeight());
}
if (getMiniReportDisplayDialog() != null) {
getMiniReportDisplayDialog().setBounds(0, 0, getMiniReportDisplayDialog().getWidth(),
getMiniReportDisplayDialog().getHeight());
Expand Down Expand Up @@ -856,6 +887,9 @@ public void actionPerformed(ActionEvent event) {
case VIEW_UNIT_DISPLAY:
GUIP.toggleUnitDisplay();
break;
case VIEW_FORCE_DISPLAY:
GUIP.toggleForceDisplay();
break;
case VIEW_MINI_MAP:
GUIP.toggleMinimapEnabled();
break;
Expand Down Expand Up @@ -1037,6 +1071,11 @@ void saveSettings() {
saveSplitPaneLocations();
}

// Force Display Dialog
if (getForceDisplayDialog() != null) {
getForceDisplayDialog().saveSettings();
}

// Mini Report Dialog
if (getMiniReportDisplayDialog() != null) {
getMiniReportDisplayDialog().saveSettings();
Expand Down Expand Up @@ -1186,6 +1225,7 @@ void switchPanel(GamePhase phase) {

maybeShowMinimap();
maybeShowUnitDisplay();
maybeShowForceDisplay();
maybeShowMiniReport();
maybeShowPlayerList();

Expand Down Expand Up @@ -1572,6 +1612,29 @@ public void maybeShowUnitDisplay() {
}
}

/** Shows or hides the Unit Display based on the current menu setting. */
public void maybeShowForceDisplay() {
GamePhase phase = getClient().getGame().getPhase();

if (phase.isReport()) {
int action = GUIP.getForceDisplayAutoDisplayReportPhase();
if (action == GUIPreferences.SHOW) {
GUIP.setForceDisplayEnabled(true);
} else if (action == GUIPreferences.HIDE) {
GUIP.setForceDisplayEnabled(false);
}
} else if (phase.isOnMap()) {
int action = GUIP.getForceDisplayAutoDisplayNonReportPhase();
if (action == GUIPreferences.SHOW) {
GUIP.setForceDisplayEnabled(true);
} else if (action == GUIPreferences.HIDE) {
GUIP.setForceDisplayEnabled(false);
}
} else {
GUIP.setForceDisplayEnabled(false);
}
}

/**
* Shows or hides the Unit Display based on the given visible. This works
* independently
Expand Down Expand Up @@ -1608,6 +1671,13 @@ private void setsetDividerLocations() {
splitPaneA.setDividerLocation(GUIP.getSplitPaneADividerLocaton());
}


public void setForceDisplayVisible(boolean visible) {
if (getForceDisplayDialog() != null) {
getForceDisplayDialog().setVisible(visible);
}
}

private void hideEmptyPanel(JPanel p, JSplitPane sp, Double d) {
boolean b = false;

Expand Down Expand Up @@ -2228,6 +2298,7 @@ public void gamePhaseChange(GamePhaseChangeEvent e) {
}

menuBar.setPhase(phase);

validate();
cb.moveToEnd();
}
Expand Down Expand Up @@ -2879,6 +2950,8 @@ public void preferenceChange(PreferenceChangeEvent e) {
setPlayerListVisible(GUIP.getPlayerListEnabled());
} else if (e.getName().equals(GUIPreferences.UNIT_DISPLAY_ENABLED)) {
setUnitDisplayVisible(GUIP.getUnitDisplayEnabled());
} else if (e.getName().equals(GUIPreferences.FORCE_DISPLAY_ENABLED)) {
setForceDisplayVisible(GUIP.getForceDisplayEnabled());
} else if (e.getName().equals(GUIPreferences.UNIT_DISPLAY_LOCATION)) {
setUnitDisplayVisible(GUIP.getUnitDisplayEnabled());
} else if (e.getName().equals(GUIPreferences.MINI_REPORT_ENABLED)) {
Expand Down
8 changes: 8 additions & 0 deletions megamek/src/megamek/client/ui/swing/CommonMenuBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public class CommonMenuBar extends JMenuBar implements ActionListener, IPreferen
// The View menu
private JCheckBoxMenuItem viewMinimap = new JCheckBoxMenuItem(getString("CommonMenuBar.viewMinimap"));
private JCheckBoxMenuItem viewMekDisplay = new JCheckBoxMenuItem(getString("CommonMenuBar.viewMekDisplay"));
private JCheckBoxMenuItem viewForceDisplay = new JCheckBoxMenuItem(getString("CommonMenuBar.viewForceDisplay"));
private JMenuItem viewAccessibilityWindow = new JMenuItem(getString("CommonMenuBar.viewAccessibilityWindow"));
private JCheckBoxMenuItem viewKeybindsOverlay = new JCheckBoxMenuItem(getString("CommonMenuBar.viewKeyboardShortcuts"));
private JCheckBoxMenuItem viewPlanetaryConditionsOverlay = new JCheckBoxMenuItem(getString("CommonMenuBar.viewPlanetaryConditions"));
Expand Down Expand Up @@ -260,6 +261,9 @@ public CommonMenuBar() {
initMenuItem(gamePlayerList, menu, VIEW_PLAYER_LIST);
GUIP.setPlayerListEnabled(false);
gamePlayerList.setSelected(false);
initMenuItem(viewForceDisplay, menu, VIEW_FORCE_DISPLAY);
GUIP.setForceDisplayEnabled(false);
viewForceDisplay.setSelected(false);
menu.addSeparator();

initMenuItem(viewKeybindsOverlay, menu, VIEW_KEYBINDS_OVERLAY);
Expand Down Expand Up @@ -341,6 +345,7 @@ private void setKeyBinds() {
viewKeybindsOverlay.setAccelerator(KeyCommandBind.keyStroke(KeyCommandBind.KEY_BINDS));
viewPlanetaryConditionsOverlay.setAccelerator(KeyCommandBind.keyStroke(KeyCommandBind.PLANETARY_CONDITIONS));
viewTurnDetailsOverlay.setAccelerator(KeyCommandBind.keyStroke(KeyCommandBind.TURN_DETAILS));
viewForceDisplay.setAccelerator(KeyCommandBind.keyStroke(KeyCommandBind.FORCE_DISPLAY));
viewMekDisplay.setAccelerator(KeyCommandBind.keyStroke(KeyCommandBind.UNIT_DISPLAY));
viewUnitOverview.setAccelerator(KeyCommandBind.keyStroke(KeyCommandBind.UNIT_OVERVIEW));
viewLOSSetting.setAccelerator(KeyCommandBind.keyStroke(KeyCommandBind.LOS_SETTING));
Expand Down Expand Up @@ -490,6 +495,7 @@ private synchronized void updateEnabledStates() {
viewMovModEnvelope.setEnabled(isInGameBoardView);
gameRoundReport.setEnabled((isInGame));
viewMekDisplay.setEnabled(isInGameBoardView);
viewForceDisplay.setEnabled(isInGameBoardView);
fireSaveWeaponOrder.setEnabled(isInGameBoardView);
}

Expand Down Expand Up @@ -538,6 +544,8 @@ public void preferenceChange(PreferenceChangeEvent e) {
setKeyBinds();
} else if (e.getName().equals(GUIPreferences.UNIT_DISPLAY_ENABLED)) {
viewMekDisplay.setSelected(GUIP.getUnitDisplayEnabled());
} else if (e.getName().equals(GUIPreferences.FORCE_DISPLAY_ENABLED)) {
viewForceDisplay.setSelected(GUIP.getForceDisplayEnabled());
} else if (e.getName().equals(GUIPreferences.MINI_REPORT_ENABLED)) {
gameRoundReport.setSelected(GUIP.getMiniReportEnabled());
} else if (e.getName().equals(GUIPreferences.PLAYER_LIST_ENABLED)) {
Expand Down
Loading

0 comments on commit 3608486

Please sign in to comment.