Skip to content

Commit

Permalink
Merge pull request #4123 from kuronekochomusuke/saveSettings
Browse files Browse the repository at this point in the history
saveSettings updates
  • Loading branch information
Windchild292 authored Feb 4, 2023
2 parents 7381d8f + 2044591 commit dbd312a
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,18 @@ public void windowClosing(WindowEvent evt) {
}
//endregion Constructors

public void saveSettings() {
GUIP.setMiniReportSizeWidth(getSize().width);
GUIP.setMiniReportSizeHeight(getSize().height);
GUIP.setMiniReportPosX(getLocation().x);
GUIP.setMiniReportPosY(getLocation().y);
}

@Override
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if ((e.getID() == WindowEvent.WINDOW_DEACTIVATED) || (e.getID() == WindowEvent.WINDOW_CLOSING)) {
GUIP.setMiniReportSizeWidth(getSize().width);
GUIP.setMiniReportSizeHeight(getSize().height);
GUIP.setMiniReportPosX(getLocation().x);
GUIP.setMiniReportPosY(getLocation().y);
saveSettings();
}
}

Expand Down
32 changes: 18 additions & 14 deletions megamek/src/megamek/client/ui/dialogs/UnitDisplayDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,28 @@ public void windowClosing(WindowEvent evt) {
}
//endregion Constructors

public void saveSettings() {
if ((getSize().width * getSize().height) > 0) {
if (GUIP.getUnitDisplayStartTabbed()) {
GUIP.setUnitDisplayPosX(getLocation().x);
GUIP.setUnitDisplayPosY(getLocation().y);
GUIP.setUnitDisplaySizeWidth(getSize().width);
GUIP.setUnitDisplaySizeHeight(getSize().height);
} else {
GUIP.setUnitDisplayNontabbedPosX(getLocation().x);
GUIP.setUnitDisplayNontabbedPosY(getLocation().y);
GUIP.setUnitDisplayNonTabbedSizeWidth(getSize().width);
GUIP.setUnitDisplayNonTabbedSizeHeight(getSize().height);
clientGUI.getUnitDisplay().saveSplitterLoc();
}
}
}

@Override
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if ((e.getID() == WindowEvent.WINDOW_DEACTIVATED) || (e.getID() == WindowEvent.WINDOW_CLOSING)) {
if ((getSize().width * getSize().height) > 0) {
if (GUIP.getUnitDisplayStartTabbed()) {
GUIP.setUnitDisplayPosX(getLocation().x);
GUIP.setUnitDisplayPosY(getLocation().y);
GUIP.setUnitDisplaySizeWidth(getSize().width);
GUIP.setUnitDisplaySizeHeight(getSize().height);
} else {
GUIP.setUnitDisplayNontabbedPosX(getLocation().x);
GUIP.setUnitDisplayNontabbedPosY(getLocation().y);
GUIP.setUnitDisplayNonTabbedSizeWidth(getSize().width);
GUIP.setUnitDisplayNonTabbedSizeHeight(getSize().height);
clientGUI.getUnitDisplay().saveSplitterLoc();
}
}
saveSettings();
}
}

Expand Down
104 changes: 64 additions & 40 deletions megamek/src/megamek/client/ui/swing/ClientGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,14 @@ public void setUnitDisplayDialog(final UnitDisplayDialog unitDisplayDialog) {
this.unitDisplayDialog = unitDisplayDialog;
}

public JDialog getMiniMapDialog() {
return minimapW;
}

public void setMiniMapDialog(final JDialog miniMapDialog) {
this.minimapW = miniMapDialog;
}

public MiniReportDisplay getMiniReportDisplay() {
return miniReportDisplay;
}
Expand All @@ -379,12 +387,16 @@ public MiniReportDisplayDialog getMiniReportDisplayDialog() {
return miniReportDisplayDialog;
}

public void setMiniReportDisplayDialog(final MiniReportDisplayDialog miniReportDisplayDialog) {
this.miniReportDisplayDialog = miniReportDisplayDialog;
}

public PlayerListDialog getPlayerListDialog() {
return playerListDialog;
}

public void setMiniReportDisplayDialog(final MiniReportDisplayDialog miniReportDisplayDialog) {
this.miniReportDisplayDialog = miniReportDisplayDialog;
public void setPlayerListDialog(final PlayerListDialog playerListDialog) {
this.playerListDialog = playerListDialog;
}

/**
Expand Down Expand Up @@ -570,7 +582,7 @@ public void windowClosing(WindowEvent e) {
setMiniReportDisplayDialog(new MiniReportDisplayDialog(getFrame(), this));
getMiniReportDisplayDialog().setVisible(false);

playerListDialog = new PlayerListDialog(frame, client, false);
setPlayerListDialog(new PlayerListDialog(frame, client, false));

Ruler.color1 = GUIP.getRulerColor1();
Ruler.color2 = GUIP.getRulerColor2();
Expand All @@ -579,7 +591,7 @@ public void windowClosing(WindowEvent e) {
ruler.setSize(GUIP.getRulerSizeHeight(), GUIP.getRulerSizeWidth());
UIUtil.updateWindowBounds(ruler);

minimapW = Minimap.createMinimap(frame, getBoardView(), getClient().getGame(), this);
setMiniMapDialog(Minimap.createMinimap(frame, getBoardView(), getClient().getGame(), this));
cb = new ChatterBox(this);
cb.setChatterBox2(cb2);
cb2.setChatterBox(cb);
Expand Down Expand Up @@ -683,16 +695,16 @@ public void customizePlayer() {
* Called when the user selects the "View->Player List" menu item.
*/
public void showPlayerList() {
if (playerListDialog == null) {
playerListDialog = new PlayerListDialog(frame, client, false);
if (getPlayerListDialog() == null) {
setPlayerListDialog(new PlayerListDialog(frame, client, false));
}
playerListDialog.setVisible(true);
getPlayerListDialog().setVisible(true);
}

public void miniReportDisplayAddReportPages() {
ignoreHotKeys = true;
if (miniReportDisplay != null) {
miniReportDisplay.addReportPages();
if (getMiniReportDisplay() != null) {
getMiniReportDisplay().addReportPages();
}
ignoreHotKeys = false;
}
Expand All @@ -711,18 +723,34 @@ public void reportDisplayResetRerollInitiative() {
}
}

private boolean resetMiniMapZoom(Container c) {
for (Component comp : c.getComponents()) {
if (comp instanceof Minimap) {
Minimap mm = (Minimap) comp;
mm.resetZoom();
return true;
} else {
if (resetMiniMapZoom((Container) comp)) {
return true;
}
}
}
return false;
}

public void resetWindowPositions() {
if (minimapW != null) {
minimapW.setBounds(0, 0, minimapW.getWidth(), minimapW.getHeight());
if (getMiniMapDialog() != null) {
getMiniMapDialog().setBounds(0, 0, getMiniMapDialog().getWidth(), getMiniMapDialog().getHeight());
resetMiniMapZoom(getMiniMapDialog());
}
if (getUnitDisplayDialog() != null) {
getUnitDisplayDialog().setBounds(0, 0, getUnitDisplay().getWidth(), getUnitDisplay().getHeight());
}
if (miniReportDisplayDialog!= null) {
miniReportDisplayDialog.setBounds(0, 0, miniReportDisplayDialog.getWidth(), miniReportDisplayDialog.getHeight());
if (getMiniReportDisplayDialog() != null) {
getMiniReportDisplayDialog().setBounds(0, 0, getMiniReportDisplayDialog().getWidth(), getMiniReportDisplayDialog().getHeight());
}
if (playerListDialog != null) {
playerListDialog.setBounds(0, 0, playerListDialog.getWidth(), playerListDialog.getHeight());
if (getPlayerListDialog() != null) {
getPlayerListDialog().setBounds(0, 0, getPlayerListDialog().getWidth(), getPlayerListDialog().getHeight());
}
if (gameOptionsDialog!= null) {
gameOptionsDialog.setBounds(0, 0, gameOptionsDialog.getWidth(), gameOptionsDialog.getHeight());
Expand Down Expand Up @@ -998,32 +1026,28 @@ void saveSettings() {
GUIP.setWindowSizeWidth(frame.getSize().width);
GUIP.setWindowSizeHeight(frame.getSize().height);

// Minimap
if ((minimapW != null) && ((minimapW.getSize().width * minimapW.getSize().height) > 0)) {
GUIP.setMinimapPosX(minimapW.getLocation().x);
GUIP.setMinimapPosY(minimapW.getLocation().y);
// Minimap Dialog
if ((getMiniMapDialog() != null) && ((getMiniMapDialog().getSize().width * getMiniMapDialog().getSize().height) > 0)) {
GUIP.setMinimapPosX(getMiniMapDialog().getLocation().x);
GUIP.setMinimapPosY(getMiniMapDialog().getLocation().y);
}

// Mek display
if ((getUnitDisplayDialog() != null)
&& ((getUnitDisplayDialog().getSize().width * getUnitDisplayDialog().getSize().height) > 0)) {
if (GUIP.getUnitDisplayStartTabbed()) {
GUIP.setUnitDisplayPosX(getUnitDisplayDialog().getLocation().x);
GUIP.setUnitDisplayPosY(getUnitDisplayDialog().getLocation().y);
GUIP.setUnitDisplaySizeWidth(getUnitDisplayDialog().getSize().width);
GUIP.setUnitDisplaySizeHeight(getUnitDisplayDialog().getSize().height);
}
else {
GUIP.setUnitDisplayNontabbedPosX(getUnitDisplayDialog().getLocation().x);
GUIP.setUnitDisplayNontabbedPosY(getUnitDisplayDialog().getLocation().y);
GUIP.setUnitDisplayNonTabbedSizeWidth(getUnitDisplayDialog().getSize().width);
GUIP.setUnitDisplayNonTabbedSizeHeight(getUnitDisplayDialog().getSize().height);
unitDisplay.saveSplitterLoc();
}

// Unit Display Dialog
if (getUnitDisplayDialog() != null) {
getUnitDisplayDialog().saveSettings();
saveSplitPaneLocations();
}

// Mini Report Dialog
if (getMiniReportDisplayDialog() != null) {
getMiniReportDisplayDialog().saveSettings();
}

// Player List Dialog
if (getPlayerListDialog() != null) {
getPlayerListDialog().saveSettings();
}

// Ruler display
if ((ruler != null) && (ruler.getSize().width != 0) && (ruler.getSize().height != 0)) {
GUIP.setRulerPosX(ruler.getLocation().x);
Expand Down Expand Up @@ -1497,8 +1521,8 @@ private void maybeShowPlayerList() {
* Does not change the menu setting.
*/
void setMapVisible(boolean visible) {
if (minimapW != null) {
minimapW.setVisible(visible);
if (getMiniMapDialog() != null) {
getMiniMapDialog().setVisible(visible);
}
}

Expand All @@ -1512,8 +1536,8 @@ void setPlayerListVisible(boolean visible) {
if (visible) {
showPlayerList();
} else {
if (playerListDialog != null) {
playerListDialog.setVisible(visible);
if (getPlayerListDialog() != null) {
getPlayerListDialog().setVisible(visible);
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions megamek/src/megamek/client/ui/swing/GUIPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ public class GUIPreferences extends PreferenceStoreProxy {
public static final String MINI_MAP_POS_X = "MinimapPosX";
public static final String MINI_MAP_POS_Y = "MinimapPosY";
public static final String MINI_MAP_ZOOM = "MinimapZoom";
public static final String MINI_MAP_HEIGHT_DISPLAY_MODE = "MinimapHeightDisplayMode";
public static final String MINI_MAP_AUTO_DISPLAY_REPORT_PHASE = "MinimapAutoDiplayReportPhase";
public static final String MINI_MAP_AUTO_DISPLAY_NONREPORT_PHASE = "MinimapAutoDiplayNonReportPhase";
public static final String MINIMUM_SIZE_HEIGHT = "MinimumSizeHeight";
Expand Down Expand Up @@ -947,6 +948,10 @@ public int getMinimapZoom() {
return store.getInt(MINI_MAP_ZOOM);
}

public int getMinimapHeightDisplayMode() {
return store.getInt(MINI_MAP_HEIGHT_DISPLAY_MODE);
}

public boolean getMiniReportEnabled() {
return store.getBoolean(MINI_REPORT_ENABLED);
}
Expand Down Expand Up @@ -1538,6 +1543,10 @@ public void setMinimapZoom(int zoom) {
store.setValue(MINI_MAP_ZOOM, zoom);
}

public void setMinimapHeightDisplayMode(int zoom) {
store.setValue(MINI_MAP_HEIGHT_DISPLAY_MODE, zoom);
}

public void setMinimapAutoDisplayReportPhase(int i) {
store.setValue(MINI_MAP_AUTO_DISPLAY_REPORT_PHASE, i);
}
Expand Down
8 changes: 6 additions & 2 deletions megamek/src/megamek/client/ui/swing/PlayerListDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,17 @@ public void actionPerformed(ActionEvent ae) {
}
}

public void saveSettings() {
GUIP.setPlayerListPosX(getLocation().x);
GUIP.setPlayerListPosY(getLocation().y);
}

@Override
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if ((e.getID() == WindowEvent.WINDOW_DEACTIVATED) || (e.getID() == WindowEvent.WINDOW_CLOSING)) {
if (!modal) {
GUIP.setPlayerListPosX(getLocation().x);
GUIP.setPlayerListPosY(getLocation().y);
saveSettings();
}
}
}
Expand Down
10 changes: 9 additions & 1 deletion megamek/src/megamek/client/ui/swing/minimap/Minimap.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public final class Minimap extends JPanel implements IPreferenceChangeListener {
private static final int[] HALF_ROAD_WIDTH = {0, 0, 0, 1, 2, 3, 3};
private static final int[] UNIT_SIZES = {4, 5, 6, 7, 8, 9, 10};
private static final int[] UNIT_SCALE = {7, 8, 9, 11, 12, 14, 16};
private static final int MIM_ZOOM = 0;
private static final int MAX_ZOOM = HEX_SIDE.length - 1;

private static final int SHOW_NO_HEIGHT = 0;
Expand Down Expand Up @@ -125,7 +126,7 @@ public final class Minimap extends JPanel implements IPreferenceChangeListener {
/** A list of information on hexes with roads or bridges. */
private final List<int[]> roadHexes = new ArrayList<>();
private int zoom = GUIP.getMinimapZoom();
private int heightDisplayMode = SHOW_NO_HEIGHT;
private int heightDisplayMode = GUIP.getMinimapHeightDisplayMode();

private Coords firstLOS;
private Coords secondLOS;
Expand Down Expand Up @@ -1272,6 +1273,12 @@ private void zoomIn() {
}
}

public void resetZoom() {
zoom = MIM_ZOOM;
initializeMap();
GUIP.setMinimapZoom(zoom);
}

private void processMouseRelease(int x, int y, int modifiers) {
if (!new Rectangle(getSize()).contains(x, y)) {
return;
Expand All @@ -1297,6 +1304,7 @@ private void processMouseRelease(int x, int y, int modifiers) {
zoomOut();
} else if ((x < 2 * BUTTON_HEIGHT) && (zoom > 3)) {
heightDisplayMode = ((++heightDisplayMode) > NBR_MODES) ? 0 : heightDisplayMode;
GUIP.setMinimapHeightDisplayMode(heightDisplayMode);
initializeMap();
} else if (x > (getSize().width - BUTTON_HEIGHT)) {
zoomIn();
Expand Down

0 comments on commit dbd312a

Please sign in to comment.