mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 18:28:00 +00:00
- Refactoring. Moved Dev Mode and Log Verbosity into Advanced Settings section. Refactored FComboBoxPanel.
This commit is contained in:
@@ -7,6 +7,7 @@ import java.awt.event.MouseEvent;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
import javax.swing.JCheckBox;
|
import javax.swing.JCheckBox;
|
||||||
|
import javax.swing.JComboBox;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
|
|
||||||
@@ -23,6 +24,7 @@ import forge.control.RestartUtil;
|
|||||||
import forge.game.ai.AiProfileUtil;
|
import forge.game.ai.AiProfileUtil;
|
||||||
import forge.gui.framework.ICDoc;
|
import forge.gui.framework.ICDoc;
|
||||||
import forge.gui.framework.SLayoutIO;
|
import forge.gui.framework.SLayoutIO;
|
||||||
|
import forge.gui.toolbox.FComboBoxPanel;
|
||||||
import forge.gui.toolbox.FSkin;
|
import forge.gui.toolbox.FSkin;
|
||||||
import forge.properties.ForgePreferences;
|
import forge.properties.ForgePreferences;
|
||||||
import forge.properties.ForgePreferences.FPref;
|
import forge.properties.ForgePreferences.FPref;
|
||||||
@@ -39,6 +41,8 @@ public enum CSubmenuPreferences implements ICDoc {
|
|||||||
/** */
|
/** */
|
||||||
SINGLETON_INSTANCE;
|
SINGLETON_INSTANCE;
|
||||||
|
|
||||||
|
private VSubmenuPreferences view;
|
||||||
|
private ForgePreferences prefs;
|
||||||
|
|
||||||
private final List<Pair<JCheckBox, FPref>> lstControls = new ArrayList<Pair<JCheckBox,FPref>>();
|
private final List<Pair<JCheckBox, FPref>> lstControls = new ArrayList<Pair<JCheckBox,FPref>>();
|
||||||
|
|
||||||
@@ -48,8 +52,9 @@ public enum CSubmenuPreferences implements ICDoc {
|
|||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
@Override
|
@Override
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
final VSubmenuPreferences view = VSubmenuPreferences.SINGLETON_INSTANCE;
|
|
||||||
final ForgePreferences prefs = Singletons.getModel().getPreferences();
|
this.view = VSubmenuPreferences.SINGLETON_INSTANCE;
|
||||||
|
this.prefs = Singletons.getModel().getPreferences();
|
||||||
|
|
||||||
view.getLstChooseSkin().addMouseListener(new MouseAdapter() {
|
view.getLstChooseSkin().addMouseListener(new MouseAdapter() {
|
||||||
@Override
|
@Override
|
||||||
@@ -76,14 +81,6 @@ public enum CSubmenuPreferences implements ICDoc {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
view.getCboLogEntryType().addItemListener(new ItemListener() {
|
|
||||||
@Override
|
|
||||||
public void itemStateChanged(final ItemEvent e) {
|
|
||||||
GameLogEntryType selectedType = (GameLogEntryType) view.getCboLogEntryType().getSelectedItem();
|
|
||||||
prefs.setPref(FPref.DEV_LOG_ENTRY_TYPE, selectedType.toString());
|
|
||||||
prefs.save();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
lstControls.clear(); // just in case
|
lstControls.clear(); // just in case
|
||||||
lstControls.add(Pair.of(view.getCbCompactMainMenu(), FPref.UI_COMPACT_MAIN_MENU));
|
lstControls.add(Pair.of(view.getCbCompactMainMenu(), FPref.UI_COMPACT_MAIN_MENU));
|
||||||
@@ -136,6 +133,9 @@ public enum CSubmenuPreferences implements ICDoc {
|
|||||||
CSubmenuPreferences.this.resetMatchScreenLayout();
|
CSubmenuPreferences.this.resetMatchScreenLayout();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
initializeGameLogVerbosityComboBox();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
@@ -143,13 +143,12 @@ public enum CSubmenuPreferences implements ICDoc {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void update() {
|
public void update() {
|
||||||
final VSubmenuPreferences view = VSubmenuPreferences.SINGLETON_INSTANCE;
|
this.view = VSubmenuPreferences.SINGLETON_INSTANCE;
|
||||||
final ForgePreferences prefs = Singletons.getModel().getPreferences();
|
this.prefs = Singletons.getModel().getPreferences();
|
||||||
updateSkinNames();
|
updateSkinNames();
|
||||||
updateAIProfiles();
|
updateAIProfiles();
|
||||||
|
|
||||||
view.getCbDevMode().setSelected(prefs.getPrefBoolean(FPref.DEV_MODE_ENABLED));
|
view.getCbDevMode().setSelected(prefs.getPrefBoolean(FPref.DEV_MODE_ENABLED));
|
||||||
view.getCboLogEntryType().setSelectedItem(GameLogEntryType.valueOf(prefs.getPref(FPref.DEV_LOG_ENTRY_TYPE)));
|
|
||||||
|
|
||||||
for(Pair<JCheckBox, FPref> kv: lstControls) {
|
for(Pair<JCheckBox, FPref> kv: lstControls) {
|
||||||
kv.getKey().setSelected(prefs.getPrefBoolean(kv.getValue()));
|
kv.getKey().setSelected(prefs.getPrefBoolean(kv.getValue()));
|
||||||
@@ -174,6 +173,7 @@ public enum CSubmenuPreferences implements ICDoc {
|
|||||||
RestartUtil.restartApplication(null);
|
RestartUtil.restartApplication(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resetDeckEditorLayout() {
|
private void resetDeckEditorLayout() {
|
||||||
String userPrompt =
|
String userPrompt =
|
||||||
"This will reset the Deck Editor screen layout.\n" +
|
"This will reset the Deck Editor screen layout.\n" +
|
||||||
@@ -205,6 +205,32 @@ public enum CSubmenuPreferences implements ICDoc {
|
|||||||
f.delete();
|
f.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void initializeGameLogVerbosityComboBox() {
|
||||||
|
FPref userSetting = FPref.DEV_LOG_ENTRY_TYPE;
|
||||||
|
FComboBoxPanel<GameLogEntryType> panel = this.view.getGameLogVerbosityComboBoxPanel();
|
||||||
|
JComboBox<GameLogEntryType> comboBox = createComboBox(GameLogEntryType.values(), userSetting);
|
||||||
|
GameLogEntryType selectedItem = GameLogEntryType.valueOf(this.prefs.getPref(userSetting));
|
||||||
|
panel.setComboBox(comboBox, selectedItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
private <E> JComboBox<E> createComboBox(E[] items, final ForgePreferences.FPref setting) {
|
||||||
|
final JComboBox<E> comboBox = new JComboBox<E>(items);
|
||||||
|
addComboBoxListener(comboBox, setting);
|
||||||
|
return comboBox;
|
||||||
|
}
|
||||||
|
|
||||||
|
private <E> void addComboBoxListener(final JComboBox<E> comboBox, final ForgePreferences.FPref setting) {
|
||||||
|
comboBox.addItemListener(new ItemListener() {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public void itemStateChanged(final ItemEvent e) {
|
||||||
|
E selectedType = (E) comboBox.getSelectedItem();
|
||||||
|
CSubmenuPreferences.this.prefs.setPref(setting, selectedType.toString());
|
||||||
|
CSubmenuPreferences.this.prefs.save();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private void updateSkinNames() {
|
private void updateSkinNames() {
|
||||||
final VSubmenuPreferences view = VSubmenuPreferences.SINGLETON_INSTANCE;
|
final VSubmenuPreferences view = VSubmenuPreferences.SINGLETON_INSTANCE;
|
||||||
final String[] uglyNames = FSkin.getSkins().toArray(ArrayUtils.EMPTY_STRING_ARRAY);
|
final String[] uglyNames = FSkin.getSkins().toArray(ArrayUtils.EMPTY_STRING_ARRAY);
|
||||||
@@ -263,6 +289,7 @@ public enum CSubmenuPreferences implements ICDoc {
|
|||||||
prefs.setPref(FPref.UI_CURRENT_AI_PROFILE, name);
|
prefs.setPref(FPref.UI_CURRENT_AI_PROFILE, name);
|
||||||
prefs.save();
|
prefs.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see forge.gui.framework.ICDoc#getCommandOnSelect()
|
* @see forge.gui.framework.ICDoc#getCommandOnSelect()
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.swing.JCheckBox;
|
import javax.swing.JCheckBox;
|
||||||
import javax.swing.JComboBox;
|
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JList;
|
import javax.swing.JList;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
@@ -94,8 +93,6 @@ public enum VSubmenuPreferences implements IVSubmenu<CSubmenuPreferences> {
|
|||||||
private final JCheckBox cbStackLand = new OptionsCheckBox("Stack AI Land");
|
private final JCheckBox cbStackLand = new OptionsCheckBox("Stack AI Land");
|
||||||
private final JCheckBox cbManaBurn = new OptionsCheckBox("Mana Burn");
|
private final JCheckBox cbManaBurn = new OptionsCheckBox("Mana Burn");
|
||||||
private final JCheckBox cbDevMode = new OptionsCheckBox("Developer Mode");
|
private final JCheckBox cbDevMode = new OptionsCheckBox("Developer Mode");
|
||||||
private final FComboBoxPanel<GameLogEntryType> cbpLogEntryType =
|
|
||||||
new FComboBoxPanel<GameLogEntryType>(GameLogEntryType.values(), "Game Log Verbosity:");
|
|
||||||
private final JCheckBox cbEnforceDeckLegality = new OptionsCheckBox("Deck Conformance");
|
private final JCheckBox cbEnforceDeckLegality = new OptionsCheckBox("Deck Conformance");
|
||||||
private final JCheckBox cbCloneImgSource = new OptionsCheckBox("Clones use original card art");
|
private final JCheckBox cbCloneImgSource = new OptionsCheckBox("Clones use original card art");
|
||||||
private final JCheckBox cbOverlayCardName = new OptionsCheckBox("Card Name");
|
private final JCheckBox cbOverlayCardName = new OptionsCheckBox("Card Name");
|
||||||
@@ -110,10 +107,14 @@ public enum VSubmenuPreferences implements IVSubmenu<CSubmenuPreferences> {
|
|||||||
|
|
||||||
private final Map<FPref, KeyboardShortcutField> shortcutFields = new HashMap<FPref, KeyboardShortcutField>();
|
private final Map<FPref, KeyboardShortcutField> shortcutFields = new HashMap<FPref, KeyboardShortcutField>();
|
||||||
|
|
||||||
|
private final FComboBoxPanel<GameLogEntryType> cbpGameLogEntryType =
|
||||||
|
new FComboBoxPanel<GameLogEntryType>("Game Log Verbosity:");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
private VSubmenuPreferences() {
|
private VSubmenuPreferences() {
|
||||||
|
|
||||||
pnlPrefs.setOpaque(false);
|
pnlPrefs.setOpaque(false);
|
||||||
pnlPrefs.setLayout(new MigLayout("insets 0, gap 0, wrap 2"));
|
pnlPrefs.setLayout(new MigLayout("insets 0, gap 0, wrap 2"));
|
||||||
|
|
||||||
@@ -121,7 +122,6 @@ public enum VSubmenuPreferences implements IVSubmenu<CSubmenuPreferences> {
|
|||||||
final String sectionConstraints = "w 80%!, h 42px!, gap 10% 0 10px 10px, span 2 1";
|
final String sectionConstraints = "w 80%!, h 42px!, gap 10% 0 10px 10px, span 2 1";
|
||||||
final String regularConstraints = "w 80%!, h 22px!, gap 10% 0 0 10px, span 2 1";
|
final String regularConstraints = "w 80%!, h 22px!, gap 10% 0 0 10px, span 2 1";
|
||||||
|
|
||||||
|
|
||||||
// Troubleshooting
|
// Troubleshooting
|
||||||
pnlPrefs.add(new SectionLabel("Troubleshooting"), sectionConstraints);
|
pnlPrefs.add(new SectionLabel("Troubleshooting"), sectionConstraints);
|
||||||
|
|
||||||
@@ -167,24 +167,26 @@ public enum VSubmenuPreferences implements IVSubmenu<CSubmenuPreferences> {
|
|||||||
pnlPrefs.add(cbManaBurn, regularConstraints);
|
pnlPrefs.add(cbManaBurn, regularConstraints);
|
||||||
pnlPrefs.add(new NoteLabel("Play with mana burn (from pre-Magic 2010 rules)."), regularConstraints);
|
pnlPrefs.add(new NoteLabel("Play with mana burn (from pre-Magic 2010 rules)."), regularConstraints);
|
||||||
|
|
||||||
pnlPrefs.add(cbDevMode, regularConstraints);
|
|
||||||
pnlPrefs.add(new NoteLabel("Enables menu with functions for testing during development."), regularConstraints);
|
|
||||||
|
|
||||||
pnlPrefs.add(cbpLogEntryType, "w 80%!, gap 10% 0 0 10px, span 2 1");
|
|
||||||
pnlPrefs.add(new NoteLabel("Changes how much information is displayed in the game log. Sorted by least to most verbose."), regularConstraints);
|
|
||||||
|
|
||||||
pnlPrefs.add(cbEnforceDeckLegality, regularConstraints);
|
pnlPrefs.add(cbEnforceDeckLegality, regularConstraints);
|
||||||
pnlPrefs.add(new NoteLabel("Enforces deck legality relevant to each environment (minimum deck sizes, max card count etc)"), regularConstraints);
|
pnlPrefs.add(new NoteLabel("Enforces deck legality relevant to each environment (minimum deck sizes, max card count etc)"), regularConstraints);
|
||||||
|
|
||||||
pnlPrefs.add(cbCloneImgSource, regularConstraints);
|
pnlPrefs.add(cbCloneImgSource, regularConstraints);
|
||||||
pnlPrefs.add(new NoteLabel("When enabled clones will use their original art instead of the cloned card's art"), regularConstraints);
|
pnlPrefs.add(new NoteLabel("When enabled clones will use their original art instead of the cloned card's art"), regularConstraints);
|
||||||
|
|
||||||
|
// Advanced
|
||||||
|
pnlPrefs.add(new SectionLabel("Advanced Settings"), sectionConstraints);
|
||||||
|
|
||||||
|
pnlPrefs.add(cbDevMode, regularConstraints);
|
||||||
|
pnlPrefs.add(new NoteLabel("Enables menu with functions for testing during development."), regularConstraints);
|
||||||
|
|
||||||
|
pnlPrefs.add(cbpGameLogEntryType, "w 80%!, gap 10% 0 0 10px, span 2 1");
|
||||||
|
pnlPrefs.add(new NoteLabel("Changes how much information is displayed in the game log. Sorted by least to most verbose."), regularConstraints);
|
||||||
|
|
||||||
// AI Personality Profile Options
|
// AI Personality Profile Options
|
||||||
pnlPrefs.add(new SectionLabel("AI Options"), sectionConstraints);
|
pnlPrefs.add(new SectionLabel("AI Options"), sectionConstraints + ", gaptop 2%");
|
||||||
|
|
||||||
pnlPrefs.add(lblTitleAIProfile, regularConstraints);
|
pnlPrefs.add(lblTitleAIProfile, regularConstraints);
|
||||||
pnlPrefs.add(lblChooseAIProfile, regularConstraints);
|
pnlPrefs.add(lblChooseAIProfile, regularConstraints);
|
||||||
pnlPrefs.add(scrChooseAIProfile, "h 200px!, w 200px!, gap 10% 0 0 2%, wrap");
|
pnlPrefs.add(scrChooseAIProfile, "h 200px!, w 200px!, gap 10% 0 0 2%, wrap");
|
||||||
|
|
||||||
// Graphic Options
|
// Graphic Options
|
||||||
@@ -504,11 +506,6 @@ public enum VSubmenuPreferences implements IVSubmenu<CSubmenuPreferences> {
|
|||||||
return cbDevMode;
|
return cbDevMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return {@link javax.swing.JComboBox} */
|
|
||||||
public JComboBox<GameLogEntryType> getCboLogEntryType() {
|
|
||||||
return cbpLogEntryType.getJComboBox();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @return {@link javax.swing.JCheckBox} */
|
/** @return {@link javax.swing.JCheckBox} */
|
||||||
public JCheckBox getCbEnforceDeckLegality() {
|
public JCheckBox getCbEnforceDeckLegality() {
|
||||||
return cbEnforceDeckLegality;
|
return cbEnforceDeckLegality;
|
||||||
@@ -538,6 +535,10 @@ public enum VSubmenuPreferences implements IVSubmenu<CSubmenuPreferences> {
|
|||||||
return btnReset;
|
return btnReset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public FComboBoxPanel<GameLogEntryType> getGameLogVerbosityComboBoxPanel() {
|
||||||
|
return cbpGameLogEntryType;
|
||||||
|
}
|
||||||
|
|
||||||
//========== Overridden from IVDoc
|
//========== Overridden from IVDoc
|
||||||
|
|
||||||
public final FLabel getBtnDeleteMatchUI() {
|
public final FLabel getBtnDeleteMatchUI() {
|
||||||
|
|||||||
@@ -18,26 +18,42 @@ import javax.swing.border.EmptyBorder;
|
|||||||
public class FComboBoxPanel<E> extends JPanel {
|
public class FComboBoxPanel<E> extends JPanel {
|
||||||
|
|
||||||
private String comboBoxCaption = "";
|
private String comboBoxCaption = "";
|
||||||
private final JComboBox<E> comboBox;
|
private JComboBox<E> comboBox = null;
|
||||||
|
|
||||||
public FComboBoxPanel(E[] comboBoxItems, String comboBoxCaption) {
|
public FComboBoxPanel(String comboBoxCaption) {
|
||||||
super();
|
super();
|
||||||
this.comboBox = new JComboBox<E>(comboBoxItems);
|
|
||||||
this.comboBoxCaption = comboBoxCaption;
|
this.comboBoxCaption = comboBoxCaption;
|
||||||
applyLayoutAndSkin();
|
applyLayoutAndSkin();
|
||||||
}
|
}
|
||||||
|
|
||||||
public final JComboBox<E> getJComboBox() {
|
public void setComboBox(JComboBox<E> comboBox, E selectedItem) {
|
||||||
return this.comboBox;
|
removeExistingComboBox();
|
||||||
|
this.comboBox = comboBox;
|
||||||
|
this.comboBox.setSelectedItem(selectedItem);
|
||||||
|
setComboBoxLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removeExistingComboBox() {
|
||||||
|
if (this.comboBox != null) {
|
||||||
|
this.remove(this.comboBox);
|
||||||
|
this.comboBox = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyLayoutAndSkin() {
|
private void applyLayoutAndSkin() {
|
||||||
|
setPanelLayout();
|
||||||
|
setLabelLayout();
|
||||||
|
setComboBoxLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setPanelLayout() {
|
||||||
FlowLayout panelLayout = new FlowLayout(FlowLayout.LEFT);
|
FlowLayout panelLayout = new FlowLayout(FlowLayout.LEFT);
|
||||||
panelLayout.setVgap(0);
|
panelLayout.setVgap(0);
|
||||||
this.setLayout(panelLayout);
|
this.setLayout(panelLayout);
|
||||||
this.setOpaque(false);
|
this.setOpaque(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setLabelLayout() {
|
||||||
if (this.comboBoxCaption != "") {
|
if (this.comboBoxCaption != "") {
|
||||||
JLabel comboLabel;
|
JLabel comboLabel;
|
||||||
comboLabel = new JLabel(this.comboBoxCaption);
|
comboLabel = new JLabel(this.comboBoxCaption);
|
||||||
@@ -45,16 +61,19 @@ public class FComboBoxPanel<E> extends JPanel {
|
|||||||
comboLabel.setFont(FSkin.getBoldFont(12));
|
comboLabel.setFont(FSkin.getBoldFont(12));
|
||||||
this.add(comboLabel);
|
this.add(comboLabel);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.comboBox.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2));
|
private void setComboBoxLayout() {
|
||||||
this.comboBox.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT));
|
if (this.comboBox != null) {
|
||||||
this.comboBox.setFont(FSkin.getFont(12));
|
this.comboBox.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2));
|
||||||
this.comboBox.setEditable(false);
|
this.comboBox.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT));
|
||||||
this.comboBox.setFocusable(true);
|
this.comboBox.setFont(FSkin.getFont(12));
|
||||||
this.comboBox.setOpaque(true);
|
this.comboBox.setEditable(false);
|
||||||
this.comboBox.setRenderer(new ComplexCellRenderer<E>());
|
this.comboBox.setFocusable(true);
|
||||||
this.add(this.comboBox);
|
this.comboBox.setOpaque(true);
|
||||||
|
this.comboBox.setRenderer(new ComplexCellRenderer<E>());
|
||||||
|
this.add(this.comboBox);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ComplexCellRenderer<E1> implements ListCellRenderer<E1> {
|
private class ComplexCellRenderer<E1> implements ListCellRenderer<E1> {
|
||||||
|
|||||||
Reference in New Issue
Block a user