mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 10:18:01 +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 javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
@@ -23,6 +24,7 @@ import forge.control.RestartUtil;
|
||||
import forge.game.ai.AiProfileUtil;
|
||||
import forge.gui.framework.ICDoc;
|
||||
import forge.gui.framework.SLayoutIO;
|
||||
import forge.gui.toolbox.FComboBoxPanel;
|
||||
import forge.gui.toolbox.FSkin;
|
||||
import forge.properties.ForgePreferences;
|
||||
import forge.properties.ForgePreferences.FPref;
|
||||
@@ -39,7 +41,9 @@ public enum CSubmenuPreferences implements ICDoc {
|
||||
/** */
|
||||
SINGLETON_INSTANCE;
|
||||
|
||||
|
||||
private VSubmenuPreferences view;
|
||||
private ForgePreferences prefs;
|
||||
|
||||
private final List<Pair<JCheckBox, FPref>> lstControls = new ArrayList<Pair<JCheckBox,FPref>>();
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -48,8 +52,9 @@ public enum CSubmenuPreferences implements ICDoc {
|
||||
@SuppressWarnings("serial")
|
||||
@Override
|
||||
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() {
|
||||
@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.add(Pair.of(view.getCbCompactMainMenu(), FPref.UI_COMPACT_MAIN_MENU));
|
||||
@@ -135,7 +132,10 @@ public enum CSubmenuPreferences implements ICDoc {
|
||||
public void run() {
|
||||
CSubmenuPreferences.this.resetMatchScreenLayout();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
initializeGameLogVerbosityComboBox();
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -143,13 +143,12 @@ public enum CSubmenuPreferences implements ICDoc {
|
||||
*/
|
||||
@Override
|
||||
public void update() {
|
||||
final VSubmenuPreferences view = VSubmenuPreferences.SINGLETON_INSTANCE;
|
||||
final ForgePreferences prefs = Singletons.getModel().getPreferences();
|
||||
this.view = VSubmenuPreferences.SINGLETON_INSTANCE;
|
||||
this.prefs = Singletons.getModel().getPreferences();
|
||||
updateSkinNames();
|
||||
updateAIProfiles();
|
||||
|
||||
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) {
|
||||
kv.getKey().setSelected(prefs.getPrefBoolean(kv.getValue()));
|
||||
@@ -174,6 +173,7 @@ public enum CSubmenuPreferences implements ICDoc {
|
||||
RestartUtil.restartApplication(null);
|
||||
}
|
||||
}
|
||||
|
||||
private void resetDeckEditorLayout() {
|
||||
String userPrompt =
|
||||
"This will reset the Deck Editor screen layout.\n" +
|
||||
@@ -205,6 +205,32 @@ public enum CSubmenuPreferences implements ICDoc {
|
||||
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() {
|
||||
final VSubmenuPreferences view = VSubmenuPreferences.SINGLETON_INSTANCE;
|
||||
final String[] uglyNames = FSkin.getSkins().toArray(ArrayUtils.EMPTY_STRING_ARRAY);
|
||||
@@ -253,7 +279,7 @@ public enum CSubmenuPreferences implements ICDoc {
|
||||
prefs.setPref(FPref.UI_SKIN, name);
|
||||
prefs.save();
|
||||
}
|
||||
|
||||
|
||||
private void updateAIProfile() {
|
||||
final VSubmenuPreferences view = VSubmenuPreferences.SINGLETON_INSTANCE;
|
||||
final String name = view.getLstChooseAIProfile().getSelectedValue().toString();
|
||||
@@ -262,7 +288,8 @@ public enum CSubmenuPreferences implements ICDoc {
|
||||
|
||||
prefs.setPref(FPref.UI_CURRENT_AI_PROFILE, name);
|
||||
prefs.save();
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.gui.framework.ICDoc#getCommandOnSelect()
|
||||
*/
|
||||
|
||||
@@ -13,7 +13,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JList;
|
||||
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 cbManaBurn = new OptionsCheckBox("Mana Burn");
|
||||
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 cbCloneImgSource = new OptionsCheckBox("Clones use original card art");
|
||||
private final JCheckBox cbOverlayCardName = new OptionsCheckBox("Card Name");
|
||||
@@ -110,18 +107,21 @@ public enum VSubmenuPreferences implements IVSubmenu<CSubmenuPreferences> {
|
||||
|
||||
private final Map<FPref, KeyboardShortcutField> shortcutFields = new HashMap<FPref, KeyboardShortcutField>();
|
||||
|
||||
private final FComboBoxPanel<GameLogEntryType> cbpGameLogEntryType =
|
||||
new FComboBoxPanel<GameLogEntryType>("Game Log Verbosity:");
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
private VSubmenuPreferences() {
|
||||
|
||||
pnlPrefs.setOpaque(false);
|
||||
pnlPrefs.setLayout(new MigLayout("insets 0, gap 0, wrap 2"));
|
||||
|
||||
// Spacing between components is defined here.
|
||||
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";
|
||||
|
||||
|
||||
|
||||
// Troubleshooting
|
||||
pnlPrefs.add(new SectionLabel("Troubleshooting"), sectionConstraints);
|
||||
|
||||
@@ -167,24 +167,26 @@ public enum VSubmenuPreferences implements IVSubmenu<CSubmenuPreferences> {
|
||||
pnlPrefs.add(cbManaBurn, 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(new NoteLabel("Enforces deck legality relevant to each environment (minimum deck sizes, max card count etc)"), 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);
|
||||
|
||||
// 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
|
||||
pnlPrefs.add(new SectionLabel("AI Options"), sectionConstraints);
|
||||
pnlPrefs.add(new SectionLabel("AI Options"), sectionConstraints + ", gaptop 2%");
|
||||
|
||||
pnlPrefs.add(lblTitleAIProfile, regularConstraints);
|
||||
pnlPrefs.add(lblChooseAIProfile, regularConstraints);
|
||||
pnlPrefs.add(lblTitleAIProfile, regularConstraints);
|
||||
pnlPrefs.add(lblChooseAIProfile, regularConstraints);
|
||||
pnlPrefs.add(scrChooseAIProfile, "h 200px!, w 200px!, gap 10% 0 0 2%, wrap");
|
||||
|
||||
// Graphic Options
|
||||
@@ -504,11 +506,6 @@ public enum VSubmenuPreferences implements IVSubmenu<CSubmenuPreferences> {
|
||||
return cbDevMode;
|
||||
}
|
||||
|
||||
/** @return {@link javax.swing.JComboBox} */
|
||||
public JComboBox<GameLogEntryType> getCboLogEntryType() {
|
||||
return cbpLogEntryType.getJComboBox();
|
||||
}
|
||||
|
||||
/** @return {@link javax.swing.JCheckBox} */
|
||||
public JCheckBox getCbEnforceDeckLegality() {
|
||||
return cbEnforceDeckLegality;
|
||||
@@ -537,7 +534,11 @@ public enum VSubmenuPreferences implements IVSubmenu<CSubmenuPreferences> {
|
||||
public FLabel getBtnReset() {
|
||||
return btnReset;
|
||||
}
|
||||
|
||||
|
||||
public FComboBoxPanel<GameLogEntryType> getGameLogVerbosityComboBoxPanel() {
|
||||
return cbpGameLogEntryType;
|
||||
}
|
||||
|
||||
//========== Overridden from IVDoc
|
||||
|
||||
public final FLabel getBtnDeleteMatchUI() {
|
||||
|
||||
@@ -18,26 +18,42 @@ import javax.swing.border.EmptyBorder;
|
||||
public class FComboBoxPanel<E> extends JPanel {
|
||||
|
||||
private String comboBoxCaption = "";
|
||||
private final JComboBox<E> comboBox;
|
||||
|
||||
public FComboBoxPanel(E[] comboBoxItems, String comboBoxCaption) {
|
||||
private JComboBox<E> comboBox = null;
|
||||
|
||||
public FComboBoxPanel(String comboBoxCaption) {
|
||||
super();
|
||||
this.comboBox = new JComboBox<E>(comboBoxItems);
|
||||
this.comboBoxCaption = comboBoxCaption;
|
||||
applyLayoutAndSkin();
|
||||
applyLayoutAndSkin();
|
||||
}
|
||||
|
||||
public final JComboBox<E> getJComboBox() {
|
||||
return this.comboBox;
|
||||
|
||||
public void setComboBox(JComboBox<E> comboBox, E selectedItem) {
|
||||
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() {
|
||||
|
||||
setPanelLayout();
|
||||
setLabelLayout();
|
||||
setComboBoxLayout();
|
||||
}
|
||||
|
||||
private void setPanelLayout() {
|
||||
FlowLayout panelLayout = new FlowLayout(FlowLayout.LEFT);
|
||||
panelLayout.setVgap(0);
|
||||
this.setLayout(panelLayout);
|
||||
this.setOpaque(false);
|
||||
|
||||
this.setOpaque(false);
|
||||
}
|
||||
|
||||
private void setLabelLayout() {
|
||||
if (this.comboBoxCaption != "") {
|
||||
JLabel comboLabel;
|
||||
comboLabel = new JLabel(this.comboBoxCaption);
|
||||
@@ -45,16 +61,19 @@ public class FComboBoxPanel<E> extends JPanel {
|
||||
comboLabel.setFont(FSkin.getBoldFont(12));
|
||||
this.add(comboLabel);
|
||||
}
|
||||
|
||||
this.comboBox.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2));
|
||||
this.comboBox.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT));
|
||||
this.comboBox.setFont(FSkin.getFont(12));
|
||||
this.comboBox.setEditable(false);
|
||||
this.comboBox.setFocusable(true);
|
||||
this.comboBox.setOpaque(true);
|
||||
this.comboBox.setRenderer(new ComplexCellRenderer<E>());
|
||||
this.add(this.comboBox);
|
||||
|
||||
}
|
||||
|
||||
private void setComboBoxLayout() {
|
||||
if (this.comboBox != null) {
|
||||
this.comboBox.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2));
|
||||
this.comboBox.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT));
|
||||
this.comboBox.setFont(FSkin.getFont(12));
|
||||
this.comboBox.setEditable(false);
|
||||
this.comboBox.setFocusable(true);
|
||||
this.comboBox.setOpaque(true);
|
||||
this.comboBox.setRenderer(new ComplexCellRenderer<E>());
|
||||
this.add(this.comboBox);
|
||||
}
|
||||
}
|
||||
|
||||
private class ComplexCellRenderer<E1> implements ListCellRenderer<E1> {
|
||||
|
||||
Reference in New Issue
Block a user