* GUI: fixed that deck editor doesn't restore settings after games (cards list hides after draft/sideboarding, see #4350);

This commit is contained in:
Oleg Agafonov 2020-07-25 13:29:51 +04:00
parent 5585e1d878
commit e07dd273f2
3 changed files with 713 additions and 697 deletions

View file

@ -31,7 +31,6 @@ public class DeckArea extends javax.swing.JPanel {
private BigCard lastBigCard = null; private BigCard lastBigCard = null;
private int dividerLocationNormal = 0; private int dividerLocationNormal = 0;
private int dividerLocationLimited = 0; private int dividerLocationLimited = 0;
private static final boolean isLimitedBuildingOrientation = false;
public DeckCardLayout getCardLayout() { public DeckCardLayout getCardLayout() {
return deckList.getCardLayout(); return deckList.getCardLayout();
@ -163,7 +162,7 @@ public class DeckArea extends javax.swing.JPanel {
}); });
} }
public Settings saveSettings() { public Settings saveSettings(boolean isLimitedBuildingOrientation) {
Settings settings = new Settings(); Settings settings = new Settings();
settings.maindeckSettings = deckList.saveSettings(); settings.maindeckSettings = deckList.saveSettings();
settings.sideboardSetings = sideboardList.saveSettings(); settings.sideboardSetings = sideboardList.saveSettings();
@ -177,7 +176,7 @@ public class DeckArea extends javax.swing.JPanel {
return settings; return settings;
} }
public void loadSettings(Settings s) { public void loadSettings(Settings s, boolean isLimitedBuildingOrientation) {
if (s != null) { if (s != null) {
deckList.loadSettings(s.maindeckSettings); deckList.loadSettings(s.maindeckSettings);
sideboardList.loadSettings(s.sideboardSetings); sideboardList.loadSettings(s.sideboardSetings);
@ -208,8 +207,8 @@ public class DeckArea extends javax.swing.JPanel {
private void setGUISize() { private void setGUISize() {
} }
public void setOrientation(boolean limitedBuildingOrientation) { public void setOrientation(boolean isLimitedBuildingOrientation) {
if (limitedBuildingOrientation) { if (isLimitedBuildingOrientation) {
deckAreaSplitPane.setOrientation(JSplitPane.VERTICAL_SPLIT); deckAreaSplitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
if (dividerLocationLimited != 0) { if (dividerLocationLimited != 0) {
deckAreaSplitPane.setDividerLocation(dividerLocationLimited); deckAreaSplitPane.setDividerLocation(dividerLocationLimited);

View file

@ -78,7 +78,6 @@ public class DeckEditorPanel extends javax.swing.JPanel {
deckArea.setOpaque(false); deckArea.setOpaque(false);
panelLeft.setOpaque(false); panelLeft.setOpaque(false);
panelRight.setOpaque(false); panelRight.setOpaque(false);
restoreDividerLocationsAndDeckAreaSettings();
countdown = new javax.swing.Timer(1000, countdown = new javax.swing.Timer(1000,
e -> { e -> {
if (--timeout > 0) { if (--timeout > 0) {
@ -93,13 +92,18 @@ public class DeckEditorPanel extends javax.swing.JPanel {
} }
}); });
// Set up tracking to save the deck editor settings when the deck editor is hidden. // save editor settings dynamicly on hides (e.g. app close)
addHierarchyListener((HierarchyEvent e) -> { addHierarchyListener((HierarchyEvent e) -> {
if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0) { if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0) {
if (!isShowing()) { if (!isShowing()) {
// It's bugged and called on sideboarding creates too (before load). So:
// * for free mode - save here
// * for draft/sideboarding - save on cleanup call
if (mode == DeckEditorMode.FREE_BUILDING) {
saveDividerLocationsAndDeckAreaSettings(); saveDividerLocationsAndDeckAreaSettings();
} }
} }
}
}); });
} }
@ -127,21 +131,32 @@ public class DeckEditorPanel extends javax.swing.JPanel {
} }
private void saveDividerLocationsAndDeckAreaSettings() { private void saveDividerLocationsAndDeckAreaSettings() {
PreferencesDialog.saveValue(PreferencesDialog.KEY_EDITOR_HORIZONTAL_DIVIDER_LOCATION, Integer.toString(panelRight.getDividerLocation())); boolean isLimitedBuildingOrientation = (mode != DeckEditorMode.FREE_BUILDING);
PreferencesDialog.saveValue(PreferencesDialog.KEY_EDITOR_DECKAREA_SETTINGS, this.deckArea.saveSettings().toString()); if (isLimitedBuildingOrientation) {
PreferencesDialog.saveValue(PreferencesDialog.KEY_EDITOR_HORIZONTAL_DIVIDER_LOCATION_LIMITED, Integer.toString(panelRight.getDividerLocation()));
} else {
PreferencesDialog.saveValue(PreferencesDialog.KEY_EDITOR_HORIZONTAL_DIVIDER_LOCATION_NORMAL, Integer.toString(panelRight.getDividerLocation()));
}
PreferencesDialog.saveValue(PreferencesDialog.KEY_EDITOR_DECKAREA_SETTINGS, this.deckArea.saveSettings(isLimitedBuildingOrientation).toString());
} }
private void restoreDividerLocationsAndDeckAreaSettings() { private void restoreDividerLocationsAndDeckAreaSettings() {
// Load horizontal split position setting String dividerLocation = "";
String dividerLocation = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_EDITOR_HORIZONTAL_DIVIDER_LOCATION, ""); boolean isLimitedBuildingOrientation = (mode != DeckEditorMode.FREE_BUILDING);
if (isLimitedBuildingOrientation) {
dividerLocation = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_EDITOR_HORIZONTAL_DIVIDER_LOCATION_LIMITED, "");
} else {
dividerLocation = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_EDITOR_HORIZONTAL_DIVIDER_LOCATION_NORMAL, "");
}
if (!dividerLocation.isEmpty()) { if (!dividerLocation.isEmpty()) {
panelRight.setDividerLocation(Integer.parseInt(dividerLocation)); panelRight.setDividerLocation(Integer.parseInt(dividerLocation));
} }
// Load deck area settings // Load deck area settings
this.deckArea.loadSettings( this.deckArea.loadSettings(
DeckArea.Settings.parse( DeckArea.Settings.parse(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_EDITOR_DECKAREA_SETTINGS, "")),
PreferencesDialog.getCachedValue(PreferencesDialog.KEY_EDITOR_DECKAREA_SETTINGS, ""))); isLimitedBuildingOrientation);
} }
public void changeGUISize() { public void changeGUISize() {
@ -157,11 +172,12 @@ public class DeckEditorPanel extends javax.swing.JPanel {
this.mode = mode; this.mode = mode;
this.btnAddLand.setVisible(false); this.btnAddLand.setVisible(false);
restoreDividerLocationsAndDeckAreaSettings();
switch (mode) { switch (mode) {
case LIMITED_BUILDING: case LIMITED_BUILDING:
this.btnAddLand.setVisible(true); this.btnAddLand.setVisible(true);
this.txtTimeRemaining.setVisible(true); this.txtTimeRemaining.setVisible(true);
// Fall through to sideboarding // Fall through to sideboarding (no break)
case SIDEBOARDING: case SIDEBOARDING:
this.btnSubmit.setVisible(true); this.btnSubmit.setVisible(true);
this.btnSubmitTimer.setVisible(true); this.btnSubmitTimer.setVisible(true);

View file

@ -3,6 +3,7 @@ package mage.client.dialog;
import mage.client.MageFrame; import mage.client.MageFrame;
import mage.client.SessionHandler; import mage.client.SessionHandler;
import mage.client.components.KeyBindButton; import mage.client.components.KeyBindButton;
import mage.client.themes.ThemeType;
import mage.client.util.CardLanguage; import mage.client.util.CardLanguage;
import mage.client.util.ClientDefaultSettings; import mage.client.util.ClientDefaultSettings;
import mage.client.util.GUISizeHelper; import mage.client.util.GUISizeHelper;
@ -15,7 +16,6 @@ import mage.remote.Connection;
import mage.remote.Connection.ProxyType; import mage.remote.Connection.ProxyType;
import mage.view.UserRequestMessage; import mage.view.UserRequestMessage;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import mage.client.themes.ThemeType;
import javax.swing.*; import javax.swing.*;
import javax.swing.border.Border; import javax.swing.border.Border;
@ -160,7 +160,8 @@ public class PreferencesDialog extends javax.swing.JDialog {
public static final String KEY_TABLES_DIVIDER_LOCATION_4 = "tablePanelDividerLocation4"; public static final String KEY_TABLES_DIVIDER_LOCATION_4 = "tablePanelDividerLocation4";
// Positions of deck editor divider bars // Positions of deck editor divider bars
public static final String KEY_EDITOR_HORIZONTAL_DIVIDER_LOCATION = "editorHorizontalDividerLocation"; public static final String KEY_EDITOR_HORIZONTAL_DIVIDER_LOCATION_NORMAL = "editorHorizontalDividerLocationNormal";
public static final String KEY_EDITOR_HORIZONTAL_DIVIDER_LOCATION_LIMITED = "editorHorizontalDividerLocationLimited";
public static final String KEY_EDITOR_DECKAREA_SETTINGS = "editorDeckAreaSettings"; public static final String KEY_EDITOR_DECKAREA_SETTINGS = "editorDeckAreaSettings";
// user list // user list