From 8331e8662425b59c5f0129c99a2d17c4a6c15c11 Mon Sep 17 00:00:00 2001 From: spr Date: Thu, 11 Jul 2013 23:00:01 +0000 Subject: [PATCH] - Modified setting. "Text/Mana Overlay" replaced with individual toggle setting for Card Name, P/T and Mana Cost overlays. --- .../home/settings/CSubmenuPreferences.java | 446 +++---- .../home/settings/VSubmenuPreferences.java | 1132 +++++++++-------- .../forge/properties/ForgePreferences.java | 4 +- .../java/forge/view/arcane/CardPanel.java | 78 +- 4 files changed, 843 insertions(+), 817 deletions(-) diff --git a/src/main/java/forge/gui/home/settings/CSubmenuPreferences.java b/src/main/java/forge/gui/home/settings/CSubmenuPreferences.java index d44a5cd1c37..4e06a5255b8 100644 --- a/src/main/java/forge/gui/home/settings/CSubmenuPreferences.java +++ b/src/main/java/forge/gui/home/settings/CSubmenuPreferences.java @@ -1,222 +1,224 @@ -package forge.gui.home.settings; - -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.io.File; - -import javax.swing.JCheckBox; -import javax.swing.SwingUtilities; - -import org.apache.commons.lang.ArrayUtils; -import org.apache.commons.lang3.text.WordUtils; -import org.apache.commons.lang3.tuple.Pair; - -import forge.Command; -import forge.Constant.Preferences; -import forge.Singletons; -import forge.control.FControl.Screens; -import forge.control.RestartUtil; -import forge.game.ai.AiProfileUtil; -import forge.gui.framework.ICDoc; -import forge.gui.framework.SLayoutIO; -import forge.gui.toolbox.FSkin; -import forge.properties.ForgePreferences; -import forge.properties.ForgePreferences.FPref; -import java.util.ArrayList; -import java.util.List; - -/** - * Controls the preferences submenu in the home UI. - * - *

(C at beginning of class name denotes a control class.) - * - */ -public enum CSubmenuPreferences implements ICDoc { - /** */ - SINGLETON_INSTANCE; - - - private final List> lstControls = new ArrayList>(); - - /* (non-Javadoc) - * @see forge.control.home.IControlSubmenu#update() - */ - @SuppressWarnings("serial") - @Override - public void initialize() { - final VSubmenuPreferences view = VSubmenuPreferences.SINGLETON_INSTANCE; - final ForgePreferences prefs = Singletons.getModel().getPreferences(); - - view.getLstChooseSkin().addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(final MouseEvent e) { - updateSkin(); - } - }); - - view.getLstChooseAIProfile().addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(final MouseEvent e) { - updateAIProfile(); - } - }); - - // This updates variable right now and is not standard - view.getCbDevMode().addItemListener(new ItemListener() { - @Override - public void itemStateChanged(final ItemEvent arg0) { - final boolean toggle = view.getCbDevMode().isSelected(); - prefs.setPref(FPref.DEV_MODE_ENABLED, String.valueOf(toggle)); - Preferences.DEV_MODE = toggle; - prefs.save(); - } - }); - - lstControls.clear(); // just in case - lstControls.add(Pair.of(view.getCbCompactMainMenu(), FPref.UI_COMPACT_MAIN_MENU)); - lstControls.add(Pair.of(view.getCbAnte(), FPref.UI_ANTE)); - lstControls.add(Pair.of(view.getCbManaBurn(), FPref.UI_MANABURN)); - lstControls.add(Pair.of(view.getCbScaleLarger(), FPref.UI_SCALE_LARGER)); - lstControls.add(Pair.of(view.getCbEnforceDeckLegality(), FPref.ENFORCE_DECK_LEGALITY)); - lstControls.add(Pair.of(view.getCbCloneImgSource(), FPref.UI_CLONE_MODE_SOURCE)); - lstControls.add(Pair.of(view.getCbRemoveSmall(), FPref.DECKGEN_NOSMALL)); - lstControls.add(Pair.of(view.getCbRemoveArtifacts(), FPref.DECKGEN_ARTIFACTS)); - lstControls.add(Pair.of(view.getCbSingletons(), FPref.DECKGEN_SINGLETONS)); - lstControls.add(Pair.of(view.getCbUploadDraft(), FPref.UI_UPLOAD_DRAFT)); - lstControls.add(Pair.of(view.getCbStackLand(), FPref.UI_SMOOTH_LAND)); - lstControls.add(Pair.of(view.getCbRandomFoil(), FPref.UI_RANDOM_FOIL)); - lstControls.add(Pair.of(view.getCbTextMana(), FPref.UI_CARD_OVERLAY)); - lstControls.add(Pair.of(view.getCbRandomizeArt(), FPref.UI_RANDOM_CARD_ART)); - lstControls.add(Pair.of(view.getCbEnableSounds(), FPref.UI_ENABLE_SOUNDS)); - lstControls.add(Pair.of(view.getCbAltSoundSystem(), FPref.UI_ALT_SOUND_SYSTEM)); - lstControls.add(Pair.of(view.getCbUiForTouchScreen(), FPref.UI_FOR_TOUCHSCREN)); - - for(final Pair kv : lstControls) { - kv.getKey().addItemListener(new ItemListener() { - @Override - public void itemStateChanged(final ItemEvent arg0) { - prefs.setPref(kv.getValue(), String.valueOf(kv.getKey().isSelected())); - prefs.save(); - } - }); - } - - view.getBtnReset().setCommand(new Command() { - @Override - public void run() { - ForgePreferences prefs = Singletons.getModel().getPreferences(); - prefs.reset(); - prefs.save(); - update(); - } - }); - - view.getBtnDeleteEditorUI().setCommand(new Command() { - @Override - public void run() { - String fd = SLayoutIO.getFilePreferred(Screens.DECK_EDITOR_CONSTRUCTED); - File f = new File(fd); - f.delete(); - } - }); - - view.getBtnDeleteMatchUI().setCommand(new Command() { - @Override - public void run() { - String fd = SLayoutIO.getFilePreferred(Screens.MATCH_SCREEN); - File f = new File(fd); - f.delete(); - } - }); - } - - /* (non-Javadoc) - * @see forge.control.home.IControlSubmenu#update() - */ - @Override - public void update() { - final VSubmenuPreferences view = VSubmenuPreferences.SINGLETON_INSTANCE; - final ForgePreferences prefs = Singletons.getModel().getPreferences(); - updateSkinNames(); - updateAIProfiles(); - - view.getCbDevMode().setSelected(prefs.getPrefBoolean(FPref.DEV_MODE_ENABLED)); - - for(Pair kv: lstControls) { - kv.getKey().setSelected(prefs.getPrefBoolean(kv.getValue())); - } - view.reloadShortcuts(); - - SwingUtilities.invokeLater(new Runnable() { - @Override public void run() { view.getCbRemoveSmall().requestFocusInWindow(); } - }); - } - - private void updateSkinNames() { - final VSubmenuPreferences view = VSubmenuPreferences.SINGLETON_INSTANCE; - final String[] uglyNames = FSkin.getSkins().toArray(ArrayUtils.EMPTY_STRING_ARRAY); - final String[] prettyNames = new String[uglyNames.length]; - final String currentName = Singletons.getModel().getPreferences().getPref(FPref.UI_SKIN); - int currentIndex = 0; - - for (int i = 0; i < uglyNames.length; i++) { - prettyNames[i] = WordUtils.capitalize(uglyNames[i].replace('_', ' ')); - if (currentName.equalsIgnoreCase(prettyNames[i])) { currentIndex = i; } - } - - view.getLstChooseSkin().setListData(prettyNames); - view.getLstChooseSkin().setSelectedIndex(currentIndex); - view.getLstChooseSkin().ensureIndexIsVisible(view.getLstChooseSkin().getSelectedIndex()); - } - - private void updateAIProfiles() { - final VSubmenuPreferences view = VSubmenuPreferences.SINGLETON_INSTANCE; - final List profileNames = AiProfileUtil.getProfilesDisplayList(); - final String currentName = Singletons.getModel().getPreferences().getPref(FPref.UI_CURRENT_AI_PROFILE); - int currentIndex = 0; - - for (int i = 0; i < profileNames.size(); i++) { - if (currentName.equalsIgnoreCase(profileNames.get(i))) { currentIndex = i; } - } - - view.getLstChooseAIProfile().setListData(profileNames.toArray(ArrayUtils.EMPTY_STRING_ARRAY)); - view.getLstChooseAIProfile().setSelectedIndex(currentIndex); - view.getLstChooseAIProfile().ensureIndexIsVisible(view.getLstChooseAIProfile().getSelectedIndex()); - } - - @SuppressWarnings("serial") - private void updateSkin() { - final VSubmenuPreferences view = VSubmenuPreferences.SINGLETON_INSTANCE; - final String name = view.getLstChooseSkin().getSelectedValue().toString(); - final ForgePreferences prefs = Singletons.getModel().getPreferences(); - if (name.equals(prefs.getPref(FPref.UI_SKIN))) { return; } - - view.getScrChooseSkin().setVisible(false); - view.getLblChooseSkin().setText("Please restart Forge (click here to close)."); - view.getLblChooseSkin().setHoverable(true); - view.getLblChooseSkin().setCommand(new Command() { @Override - public void run() { RestartUtil.restartApplication(null); } }); - - prefs.setPref(FPref.UI_SKIN, name); - prefs.save(); - } - - private void updateAIProfile() { - final VSubmenuPreferences view = VSubmenuPreferences.SINGLETON_INSTANCE; - final String name = view.getLstChooseAIProfile().getSelectedValue().toString(); - final ForgePreferences prefs = Singletons.getModel().getPreferences(); - if (name.equals(prefs.getPref(FPref.UI_CURRENT_AI_PROFILE))) { return; } - - prefs.setPref(FPref.UI_CURRENT_AI_PROFILE, name); - prefs.save(); - } - /* (non-Javadoc) - * @see forge.gui.framework.ICDoc#getCommandOnSelect() - */ - @Override - public Command getCommandOnSelect() { - return null; - } -} +package forge.gui.home.settings; + +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.io.File; + +import javax.swing.JCheckBox; +import javax.swing.SwingUtilities; + +import org.apache.commons.lang.ArrayUtils; +import org.apache.commons.lang3.text.WordUtils; +import org.apache.commons.lang3.tuple.Pair; + +import forge.Command; +import forge.Constant.Preferences; +import forge.Singletons; +import forge.control.FControl.Screens; +import forge.control.RestartUtil; +import forge.game.ai.AiProfileUtil; +import forge.gui.framework.ICDoc; +import forge.gui.framework.SLayoutIO; +import forge.gui.toolbox.FSkin; +import forge.properties.ForgePreferences; +import forge.properties.ForgePreferences.FPref; +import java.util.ArrayList; +import java.util.List; + +/** + * Controls the preferences submenu in the home UI. + * + *

(C at beginning of class name denotes a control class.) + * + */ +public enum CSubmenuPreferences implements ICDoc { + /** */ + SINGLETON_INSTANCE; + + + private final List> lstControls = new ArrayList>(); + + /* (non-Javadoc) + * @see forge.control.home.IControlSubmenu#update() + */ + @SuppressWarnings("serial") + @Override + public void initialize() { + final VSubmenuPreferences view = VSubmenuPreferences.SINGLETON_INSTANCE; + final ForgePreferences prefs = Singletons.getModel().getPreferences(); + + view.getLstChooseSkin().addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(final MouseEvent e) { + updateSkin(); + } + }); + + view.getLstChooseAIProfile().addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(final MouseEvent e) { + updateAIProfile(); + } + }); + + // This updates variable right now and is not standard + view.getCbDevMode().addItemListener(new ItemListener() { + @Override + public void itemStateChanged(final ItemEvent arg0) { + final boolean toggle = view.getCbDevMode().isSelected(); + prefs.setPref(FPref.DEV_MODE_ENABLED, String.valueOf(toggle)); + Preferences.DEV_MODE = toggle; + prefs.save(); + } + }); + + lstControls.clear(); // just in case + lstControls.add(Pair.of(view.getCbCompactMainMenu(), FPref.UI_COMPACT_MAIN_MENU)); + lstControls.add(Pair.of(view.getCbAnte(), FPref.UI_ANTE)); + lstControls.add(Pair.of(view.getCbManaBurn(), FPref.UI_MANABURN)); + lstControls.add(Pair.of(view.getCbScaleLarger(), FPref.UI_SCALE_LARGER)); + lstControls.add(Pair.of(view.getCbEnforceDeckLegality(), FPref.ENFORCE_DECK_LEGALITY)); + lstControls.add(Pair.of(view.getCbCloneImgSource(), FPref.UI_CLONE_MODE_SOURCE)); + lstControls.add(Pair.of(view.getCbRemoveSmall(), FPref.DECKGEN_NOSMALL)); + lstControls.add(Pair.of(view.getCbRemoveArtifacts(), FPref.DECKGEN_ARTIFACTS)); + lstControls.add(Pair.of(view.getCbSingletons(), FPref.DECKGEN_SINGLETONS)); + lstControls.add(Pair.of(view.getCbUploadDraft(), FPref.UI_UPLOAD_DRAFT)); + lstControls.add(Pair.of(view.getCbStackLand(), FPref.UI_SMOOTH_LAND)); + lstControls.add(Pair.of(view.getCbRandomFoil(), FPref.UI_RANDOM_FOIL)); + lstControls.add(Pair.of(view.getCbOverlayCardName(), FPref.UI_OVERLAY_CARD_NAME)); + lstControls.add(Pair.of(view.getCbOverlayCardPower(), FPref.UI_OVERLAY_CARD_POWER)); + lstControls.add(Pair.of(view.getCbOverlayCardManaCost(), FPref.UI_OVERLAY_CARD_MANA_COST)); + lstControls.add(Pair.of(view.getCbRandomizeArt(), FPref.UI_RANDOM_CARD_ART)); + lstControls.add(Pair.of(view.getCbEnableSounds(), FPref.UI_ENABLE_SOUNDS)); + lstControls.add(Pair.of(view.getCbAltSoundSystem(), FPref.UI_ALT_SOUND_SYSTEM)); + lstControls.add(Pair.of(view.getCbUiForTouchScreen(), FPref.UI_FOR_TOUCHSCREN)); + + for(final Pair kv : lstControls) { + kv.getKey().addItemListener(new ItemListener() { + @Override + public void itemStateChanged(final ItemEvent arg0) { + prefs.setPref(kv.getValue(), String.valueOf(kv.getKey().isSelected())); + prefs.save(); + } + }); + } + + view.getBtnReset().setCommand(new Command() { + @Override + public void run() { + ForgePreferences prefs = Singletons.getModel().getPreferences(); + prefs.reset(); + prefs.save(); + update(); + } + }); + + view.getBtnDeleteEditorUI().setCommand(new Command() { + @Override + public void run() { + String fd = SLayoutIO.getFilePreferred(Screens.DECK_EDITOR_CONSTRUCTED); + File f = new File(fd); + f.delete(); + } + }); + + view.getBtnDeleteMatchUI().setCommand(new Command() { + @Override + public void run() { + String fd = SLayoutIO.getFilePreferred(Screens.MATCH_SCREEN); + File f = new File(fd); + f.delete(); + } + }); + } + + /* (non-Javadoc) + * @see forge.control.home.IControlSubmenu#update() + */ + @Override + public void update() { + final VSubmenuPreferences view = VSubmenuPreferences.SINGLETON_INSTANCE; + final ForgePreferences prefs = Singletons.getModel().getPreferences(); + updateSkinNames(); + updateAIProfiles(); + + view.getCbDevMode().setSelected(prefs.getPrefBoolean(FPref.DEV_MODE_ENABLED)); + + for(Pair kv: lstControls) { + kv.getKey().setSelected(prefs.getPrefBoolean(kv.getValue())); + } + view.reloadShortcuts(); + + SwingUtilities.invokeLater(new Runnable() { + @Override public void run() { view.getCbRemoveSmall().requestFocusInWindow(); } + }); + } + + private void updateSkinNames() { + final VSubmenuPreferences view = VSubmenuPreferences.SINGLETON_INSTANCE; + final String[] uglyNames = FSkin.getSkins().toArray(ArrayUtils.EMPTY_STRING_ARRAY); + final String[] prettyNames = new String[uglyNames.length]; + final String currentName = Singletons.getModel().getPreferences().getPref(FPref.UI_SKIN); + int currentIndex = 0; + + for (int i = 0; i < uglyNames.length; i++) { + prettyNames[i] = WordUtils.capitalize(uglyNames[i].replace('_', ' ')); + if (currentName.equalsIgnoreCase(prettyNames[i])) { currentIndex = i; } + } + + view.getLstChooseSkin().setListData(prettyNames); + view.getLstChooseSkin().setSelectedIndex(currentIndex); + view.getLstChooseSkin().ensureIndexIsVisible(view.getLstChooseSkin().getSelectedIndex()); + } + + private void updateAIProfiles() { + final VSubmenuPreferences view = VSubmenuPreferences.SINGLETON_INSTANCE; + final List profileNames = AiProfileUtil.getProfilesDisplayList(); + final String currentName = Singletons.getModel().getPreferences().getPref(FPref.UI_CURRENT_AI_PROFILE); + int currentIndex = 0; + + for (int i = 0; i < profileNames.size(); i++) { + if (currentName.equalsIgnoreCase(profileNames.get(i))) { currentIndex = i; } + } + + view.getLstChooseAIProfile().setListData(profileNames.toArray(ArrayUtils.EMPTY_STRING_ARRAY)); + view.getLstChooseAIProfile().setSelectedIndex(currentIndex); + view.getLstChooseAIProfile().ensureIndexIsVisible(view.getLstChooseAIProfile().getSelectedIndex()); + } + + @SuppressWarnings("serial") + private void updateSkin() { + final VSubmenuPreferences view = VSubmenuPreferences.SINGLETON_INSTANCE; + final String name = view.getLstChooseSkin().getSelectedValue().toString(); + final ForgePreferences prefs = Singletons.getModel().getPreferences(); + if (name.equals(prefs.getPref(FPref.UI_SKIN))) { return; } + + view.getScrChooseSkin().setVisible(false); + view.getLblChooseSkin().setText("Please restart Forge (click here to close)."); + view.getLblChooseSkin().setHoverable(true); + view.getLblChooseSkin().setCommand(new Command() { @Override + public void run() { RestartUtil.restartApplication(null); } }); + + prefs.setPref(FPref.UI_SKIN, name); + prefs.save(); + } + + private void updateAIProfile() { + final VSubmenuPreferences view = VSubmenuPreferences.SINGLETON_INSTANCE; + final String name = view.getLstChooseAIProfile().getSelectedValue().toString(); + final ForgePreferences prefs = Singletons.getModel().getPreferences(); + if (name.equals(prefs.getPref(FPref.UI_CURRENT_AI_PROFILE))) { return; } + + prefs.setPref(FPref.UI_CURRENT_AI_PROFILE, name); + prefs.save(); + } + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#getCommandOnSelect() + */ + @Override + public Command getCommandOnSelect() { + return null; + } +} diff --git a/src/main/java/forge/gui/home/settings/VSubmenuPreferences.java b/src/main/java/forge/gui/home/settings/VSubmenuPreferences.java index 5cea709433d..4fd7b698d48 100644 --- a/src/main/java/forge/gui/home/settings/VSubmenuPreferences.java +++ b/src/main/java/forge/gui/home/settings/VSubmenuPreferences.java @@ -1,558 +1,574 @@ -package forge.gui.home.settings; - -import java.awt.Color; -import java.awt.Font; -import java.awt.event.FocusAdapter; -import java.awt.event.FocusEvent; -import java.awt.event.KeyAdapter; -import java.awt.event.KeyEvent; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.swing.JCheckBox; -import javax.swing.JLabel; -import javax.swing.JList; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JTextField; -import javax.swing.ScrollPaneConstants; -import javax.swing.SwingConstants; -import javax.swing.border.MatteBorder; - -import net.miginfocom.swing.MigLayout; - -import org.apache.commons.lang3.StringUtils; - -import forge.Singletons; -import forge.control.KeyboardShortcuts; -import forge.control.KeyboardShortcuts.Shortcut; -import forge.gui.framework.DragCell; -import forge.gui.framework.DragTab; -import forge.gui.framework.EDocID; -import forge.gui.home.EMenuGroup; -import forge.gui.home.IVSubmenu; -import forge.gui.home.VHomeUI; -import forge.gui.toolbox.FCheckBox; -import forge.gui.toolbox.FLabel; -import forge.gui.toolbox.FList; -import forge.gui.toolbox.FScrollPane; -import forge.gui.toolbox.FSkin; -import forge.properties.ForgePreferences.FPref; - -/** - * Assembles Swing components of preferences submenu singleton. - * - *

(V at beginning of class name denotes a view class.) - */ -public enum VSubmenuPreferences implements IVSubmenu { - /** */ - SINGLETON_INSTANCE; - - // Fields used with interface IVDoc - private DragCell parentCell; - private final DragTab tab = new DragTab("Preferences"); - - /** */ - private final JPanel pnlPrefs = new JPanel(); - private final FScrollPane scrContent = new FScrollPane(pnlPrefs, - ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); - - private final FLabel btnReset = new FLabel.Builder().opaque(true).hoverable(true).text("Reset to defaults").build(); - - private final FLabel btnDeleteMatchUI = new FLabel.Builder().opaque(true).hoverable(true).text("Reset Match Layout").build(); - private final FLabel btnDeleteEditorUI = new FLabel.Builder().opaque(true).hoverable(true).text("Reset Editor Layout").build(); - - private final FLabel lblTitleSkin = new FLabel.Builder() - .text("Choose Skin").fontStyle(Font.BOLD).fontSize(14).build(); - - private final JList lstChooseSkin = new FList(); - private final FLabel lblChooseSkin = new FLabel.Builder().fontSize(12).fontStyle(Font.ITALIC) - .text("Various user-created themes for Forge backgrounds, fonts, and colors.") - .fontAlign(SwingConstants.LEFT).build(); - private final JScrollPane scrChooseSkin = new FScrollPane(lstChooseSkin); - - private final FLabel lblTitleAIProfile = new FLabel.Builder() - .text("Choose AI Personality").fontStyle(Font.BOLD).fontSize(14).build(); - - private final JList lstChooseAIProfile = new FList(); - private final FLabel lblChooseAIProfile = new FLabel.Builder().fontSize(12).fontStyle(Font.ITALIC) - .text("AI Opponent Personality.") - .fontAlign(SwingConstants.LEFT).build(); - private final JScrollPane scrChooseAIProfile = new FScrollPane(lstChooseAIProfile); - - private final JCheckBox cbCompactMainMenu = new OptionsCheckBox("Use Compact Main Sidebar Menu"); - private final JCheckBox cbRemoveSmall = new OptionsCheckBox("Remove Small Creatures"); - private final JCheckBox cbSingletons = new OptionsCheckBox("Singleton Mode"); - private final JCheckBox cbRemoveArtifacts = new OptionsCheckBox("Remove Artifacts"); - private final JCheckBox cbAnte = new OptionsCheckBox("Play for Ante"); - private final JCheckBox cbUploadDraft = new OptionsCheckBox("Upload Draft Picks"); - 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 JCheckBox cbEnforceDeckLegality = new OptionsCheckBox("Deck Conformance"); - private final JCheckBox cbCloneImgSource = new OptionsCheckBox("Clones use original card art"); - private final JCheckBox cbTextMana = new OptionsCheckBox("Text / Mana Overlay"); - private final JCheckBox cbScaleLarger = new OptionsCheckBox("Scale Image Larger"); - private final JCheckBox cbRandomFoil = new OptionsCheckBox("Random Foil"); - private final JCheckBox cbRandomizeArt = new OptionsCheckBox("Randomize Card Art"); - private final JCheckBox cbEnableSounds = new OptionsCheckBox("Enable Sounds"); - private final JCheckBox cbAltSoundSystem = new OptionsCheckBox("Use Alternate Sound System"); - private final JCheckBox cbUiForTouchScreen = new OptionsCheckBox("Enchance UI for touchscreens"); - - private final Map shortcutFields = new HashMap(); - - /** - * 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"; - - // ======== General Configuration Options ======== - pnlPrefs.add(new SectionLabel("General Configuration"), sectionConstraints + ", gaptop 2%"); - - pnlPrefs.add(cbCompactMainMenu, regularConstraints); - pnlPrefs.add(new NoteLabel("Enable for a space efficient sidebar that displays only one menu group at a time (RESTART REQUIRED)."), regularConstraints); - - // Deck building options - pnlPrefs.add(new SectionLabel("Random Deck Generation Options"), sectionConstraints + ", gaptop 2%"); - - pnlPrefs.add(cbRemoveSmall, regularConstraints); - pnlPrefs.add(new NoteLabel("Disables 1/1 and 0/X creatures in generated decks."), regularConstraints); - - pnlPrefs.add(cbSingletons, regularConstraints); - pnlPrefs.add(new NoteLabel("Disables non-land duplicates in generated decks."), regularConstraints); - - pnlPrefs.add(cbRemoveArtifacts, regularConstraints); - pnlPrefs.add(new NoteLabel("Disables artifact cards in generated decks."), regularConstraints); - - // Gameplay Options - pnlPrefs.add(new SectionLabel("Gameplay Options"), sectionConstraints); - - pnlPrefs.add(cbAnte, regularConstraints); - pnlPrefs.add(new NoteLabel("Determines whether or not the game is played for ante."), regularConstraints); - - pnlPrefs.add(cbUploadDraft, regularConstraints); - pnlPrefs.add(new NoteLabel("Sends draft picks to Forge servers for analysis, to improve draft AI."), regularConstraints); - - pnlPrefs.add(cbStackLand, regularConstraints); - pnlPrefs.add(new NoteLabel("Minimizes mana lock in AI hands, giving a slight advantage to computer."), regularConstraints); - - 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(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); - - // Troubleshooting - pnlPrefs.add(new SectionLabel("Troubleshooting"), sectionConstraints); - final String twoButtonConstraints = "w 38%!, h 30px!, gap 10% 0 0 10px"; - pnlPrefs.add(btnDeleteMatchUI, twoButtonConstraints); - pnlPrefs.add(btnDeleteEditorUI, "w 38%!, h 30px!, gap 0 0 0 10px"); - - // AI Personality Profile Options - pnlPrefs.add(new SectionLabel("AI Options"), sectionConstraints); - - pnlPrefs.add(lblTitleAIProfile, regularConstraints); - pnlPrefs.add(lblChooseAIProfile, regularConstraints); - pnlPrefs.add(scrChooseAIProfile, "h 200px!, w 200px!, gap 10% 0 0 2%, wrap"); - - // Graphic Options - pnlPrefs.add(new SectionLabel("Graphic Options"), sectionConstraints); - - pnlPrefs.add(lblTitleSkin, regularConstraints); - pnlPrefs.add(lblChooseSkin, regularConstraints); - pnlPrefs.add(scrChooseSkin, "h 200px!, w 200px!, gap 10% 0 0 2%, wrap"); - - pnlPrefs.add(cbRandomFoil, regularConstraints); - pnlPrefs.add(new NoteLabel("Adds foiled effects to random cards."), regularConstraints); - - pnlPrefs.add(cbRandomizeArt, regularConstraints); - pnlPrefs.add(new NoteLabel("Randomize the card art for cards in the human's deck"), regularConstraints); - - pnlPrefs.add(cbScaleLarger, regularConstraints); - pnlPrefs.add(new NoteLabel("Allows card pictures to be expanded larger than their original size."), regularConstraints); - - pnlPrefs.add(cbUiForTouchScreen, regularConstraints); - pnlPrefs.add(new NoteLabel("Increases some UI elements to provide a better experience on touchscreen devices. (Needs restart)"), regularConstraints); - - pnlPrefs.add(cbTextMana, regularConstraints); - pnlPrefs.add(new NoteLabel("Overlays each card with basic card-specific information."), regularConstraints); - - // Sound options - pnlPrefs.add(new SectionLabel("Sound Options"), sectionConstraints); - - pnlPrefs.add(cbEnableSounds, regularConstraints); - pnlPrefs.add(new NoteLabel("Enable sound effects during the game."), regularConstraints); - - pnlPrefs.add(cbAltSoundSystem, regularConstraints); - pnlPrefs.add(new NoteLabel("Use the alternate sound system (only use in case your have issues with sound not playing or disappearing)"), regularConstraints); - - // Keyboard shortcuts - final JLabel lblShortcuts = new SectionLabel("Keyboard Shortcuts"); - pnlPrefs.add(lblShortcuts, sectionConstraints); - - final List shortcuts = Singletons.getControl().getShortcuts(); - - for (final Shortcut s : shortcuts) { - pnlPrefs.add(new FLabel.Builder().text(s.getDescription()) - .fontAlign(SwingConstants.RIGHT).build(), "w 50%!, h 22px!, gap 0 2% 0 1%"); - KeyboardShortcutField field = new KeyboardShortcutField(s); - pnlPrefs.add(field, "w 25%!"); - shortcutFields.put(s.getPrefKey(), field); - } - - // Reset button - pnlPrefs.add(new SectionLabel(" "), sectionConstraints); - pnlPrefs.add(btnReset, sectionConstraints); - - scrContent.setBorder(null); - } - - public void reloadShortcuts() { - for (Map.Entry e : shortcutFields.entrySet()) { - e.getValue().reload(e.getKey()); - } - } - - /* (non-Javadoc) - * @see forge.view.home.IViewSubmenu#populate() - */ - @Override - public void populate() { - VHomeUI.SINGLETON_INSTANCE.getPnlDisplay().removeAll(); - - VHomeUI.SINGLETON_INSTANCE.getPnlDisplay().setLayout(new MigLayout("insets 0, gap 0")); - VHomeUI.SINGLETON_INSTANCE.getPnlDisplay().add(scrContent, "w 98%!, h 98%!, gap 1% 0 1% 0"); - - VHomeUI.SINGLETON_INSTANCE.getPnlDisplay().repaintSelf(); - VHomeUI.SINGLETON_INSTANCE.getPnlDisplay().revalidate(); - } - - /* (non-Javadoc) - * @see forge.view.home.IViewSubmenu#getGroup() - */ - @Override - public EMenuGroup getGroupEnum() { - return EMenuGroup.SETTINGS; - } - - /* (non-Javadoc) - * @see forge.gui.home.IVSubmenu#getMenuTitle() - */ - @Override - public String getMenuTitle() { - return "Preferences"; - } - - /* (non-Javadoc) - * @see forge.gui.home.IVSubmenu#getItemEnum() - */ - @Override - public EDocID getItemEnum() { - return EDocID.HOME_PREFERENCES; - } - - /** Consolidates checkbox styling in one place. */ - @SuppressWarnings("serial") - private class OptionsCheckBox extends FCheckBox { - public OptionsCheckBox(final String txt0) { - super(txt0); - setFont(FSkin.getBoldFont(12)); - } - } - - /** Consolidates section title label styling in one place. */ - @SuppressWarnings("serial") - private class SectionLabel extends JLabel { - public SectionLabel(final String txt0) { - super(txt0); - setBorder(new MatteBorder(0, 0, 1, 0, FSkin.getColor(FSkin.Colors.CLR_BORDERS))); - setHorizontalAlignment(SwingConstants.CENTER); - setFont(FSkin.getBoldFont(16)); - setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); - } - } - - /** Consolidates notation label styling in one place. */ - @SuppressWarnings("serial") - private class NoteLabel extends JLabel { - public NoteLabel(final String txt0) { - super(txt0); - setFont(FSkin.getItalicFont(12)); - setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); - } - } - - /** - * A JTextField plus a "codeString" property, that stores keycodes for the - * shortcut. Also, an action listener that handles translation of keycodes - * into characters and (dis)assembly of keycode stack. - */ - @SuppressWarnings("serial") - public class KeyboardShortcutField extends JTextField { - private String codeString; - - /** - * A JTextField plus a "codeString" property, that stores keycodes for - * the shortcut. Also, an action listener that handles translation of - * keycodes into characters and (dis)assembly of keycode stack. - * - * @param shortcut0   Shortcut object - */ - public KeyboardShortcutField(final Shortcut shortcut0) { - super(); - this.setEditable(false); - this.setFont(FSkin.getFont(14)); - final FPref prefKey = shortcut0.getPrefKey(); - reload(prefKey); - - this.addKeyListener(new KeyAdapter() { - @Override - public void keyPressed(final KeyEvent evt) { - KeyboardShortcuts.addKeyCode(evt); - } - }); - - this.addFocusListener(new FocusAdapter() { - @Override - public void focusGained(final FocusEvent evt) { - KeyboardShortcutField.this.setBackground(FSkin.getColor(FSkin.Colors.CLR_ACTIVE)); - } - - @Override - public void focusLost(final FocusEvent evt) { - Singletons.getModel().getPreferences().setPref(prefKey, getCodeString()); - Singletons.getModel().getPreferences().save(); - shortcut0.attach(); - KeyboardShortcutField.this.setBackground(Color.white); - } - }); - } - - public void reload(FPref prefKey) { - this.setCodeString(Singletons.getModel().getPreferences().getPref(prefKey)); - } - - /** - * Gets the code string. - * - * @return String - */ - public final String getCodeString() { - return this.codeString; - } - - /** - * Sets the code string. - * - * @param str0 - *   The new code string (space delimited) - */ - public final void setCodeString(final String str0) { - if ("null".equals(str0)) { - return; - } - - this.codeString = str0.trim(); - - final List codes = new ArrayList(Arrays.asList(this.codeString.split(" "))); - final List displayText = new ArrayList(); - - for (final String s : codes) { - if (!s.isEmpty()) { - displayText.add(KeyEvent.getKeyText(Integer.valueOf(s))); - } - } - - this.setText(StringUtils.join(displayText, ' ')); - } - } - - /** @return {@link javax.swing.JList} */ - public final JList getLstChooseSkin() { - return lstChooseSkin; - } - - /** @return {@link forge.gui.toolbox.FLabel} */ - public final FLabel getLblChooseSkin() { - return lblChooseSkin; - } - - /** @return {@link javax.swing.JScrollPane} */ - public final JScrollPane getScrChooseSkin() { - return scrChooseSkin; - } - - /** @return {@link javax.swing.JList} */ - public final JList getLstChooseAIProfile() { - return lstChooseAIProfile; - } - - /** @return {@link forge.gui.toolbox.FLabel} */ - public final FLabel getLblChooseAIProfile() { - return lblChooseAIProfile; - } - - /** @return {@link javax.swing.JScrollPane} */ - public final JScrollPane getScrChooseAIProfile() { - return scrChooseAIProfile; - } - - /** @return {@link javax.swing.JCheckBox} */ - public final JCheckBox getCbCompactMainMenu() { - return cbCompactMainMenu; - } - - /** @return {@link javax.swing.JCheckBox} */ - public final JCheckBox getCbRemoveSmall() { - return cbRemoveSmall; - } - - /** @return {@link javax.swing.JCheckBox} */ - public final JCheckBox getCbSingletons() { - return cbSingletons; - } - - /** @return {@link javax.swing.JCheckBox} */ - public JCheckBox getCbRemoveArtifacts() { - return cbRemoveArtifacts; - } - - /** @return {@link javax.swing.JCheckBox} */ - public JCheckBox getCbUploadDraft() { - return cbUploadDraft; - } - - /** @return {@link javax.swing.JCheckBox} */ - public JCheckBox getCbStackLand() { - return cbStackLand; - } - - /** @return {@link javax.swing.JCheckBox} */ - public JCheckBox getCbTextMana() { - return cbTextMana; - } - - /** @return {@link javax.swing.JCheckBox} */ - public JCheckBox getCbRandomFoil() { - return cbRandomFoil; - } - - /** @return {@link javax.swing.JCheckBox} */ - public JCheckBox getCbRandomizeArt() { - return cbRandomizeArt; - } - - /** @return {@link javax.swing.JCheckBox} */ - public JCheckBox getCbAnte() { - return cbAnte; - } - - /** @return {@link javax.swing.JCheckBox} */ - public JCheckBox getCbManaBurn() { - return cbManaBurn; - } - - /** @return {@link javax.swing.JCheckBox} */ - public JCheckBox getCbScaleLarger() { - return cbScaleLarger; - } - - /** @return {@link javax.swing.JCheckBox} */ - public JCheckBox getCbDevMode() { - return cbDevMode; - } - - /** @return {@link javax.swing.JCheckBox} */ - public JCheckBox getCbEnforceDeckLegality() { - return cbEnforceDeckLegality; - } - - /** @return {@link javax.swing.JCheckBox} */ - public JCheckBox getCbCloneImgSource() { - return cbCloneImgSource; - } - - /** @return {@link javax.swing.JCheckBox} */ - public JCheckBox getCbEnableSounds() { - return cbEnableSounds; - } - - /** @return {@link javax.swing.JCheckBox} */ - public JCheckBox getCbAltSoundSystem() { - return cbAltSoundSystem; - } - - public final JCheckBox getCbUiForTouchScreen() { - return cbUiForTouchScreen; - } - - /** @return {@link forge.gui.toolbox.FLabel} */ - public FLabel getBtnReset() { - return btnReset; - } - - //========== Overridden from IVDoc - - public final FLabel getBtnDeleteMatchUI() { - return btnDeleteMatchUI; - } - - public final FLabel getBtnDeleteEditorUI() { - return btnDeleteEditorUI; - } - - /* (non-Javadoc) - * @see forge.gui.framework.IVDoc#getDocumentID() - */ - @Override - public EDocID getDocumentID() { - return EDocID.HOME_PREFERENCES; - } - - /* (non-Javadoc) - * @see forge.gui.framework.IVDoc#getTabLabel() - */ - @Override - public DragTab getTabLabel() { - return tab; - } - - /* (non-Javadoc) - * @see forge.gui.framework.IVDoc#getLayoutControl() - */ - @Override - public CSubmenuPreferences getLayoutControl() { - return CSubmenuPreferences.SINGLETON_INSTANCE; - } - - /* (non-Javadoc) - * @see forge.gui.framework.IVDoc#setParentCell(forge.gui.framework.DragCell) - */ - @Override - public void setParentCell(DragCell cell0) { - this.parentCell = cell0; - } - - /* (non-Javadoc) - * @see forge.gui.framework.IVDoc#getParentCell() - */ - @Override - public DragCell getParentCell() { - return parentCell; - } -} +package forge.gui.home.settings; + +import java.awt.Color; +import java.awt.Font; +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.swing.JCheckBox; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextField; +import javax.swing.ScrollPaneConstants; +import javax.swing.SwingConstants; +import javax.swing.border.MatteBorder; + +import net.miginfocom.swing.MigLayout; + +import org.apache.commons.lang3.StringUtils; + +import forge.Singletons; +import forge.control.KeyboardShortcuts; +import forge.control.KeyboardShortcuts.Shortcut; +import forge.gui.framework.DragCell; +import forge.gui.framework.DragTab; +import forge.gui.framework.EDocID; +import forge.gui.home.EMenuGroup; +import forge.gui.home.IVSubmenu; +import forge.gui.home.VHomeUI; +import forge.gui.toolbox.FCheckBox; +import forge.gui.toolbox.FLabel; +import forge.gui.toolbox.FList; +import forge.gui.toolbox.FScrollPane; +import forge.gui.toolbox.FSkin; +import forge.properties.ForgePreferences.FPref; + +/** + * Assembles Swing components of preferences submenu singleton. + * + *

(V at beginning of class name denotes a view class.) + */ +public enum VSubmenuPreferences implements IVSubmenu { + /** */ + SINGLETON_INSTANCE; + + // Fields used with interface IVDoc + private DragCell parentCell; + private final DragTab tab = new DragTab("Preferences"); + + /** */ + private final JPanel pnlPrefs = new JPanel(); + private final FScrollPane scrContent = new FScrollPane(pnlPrefs, + ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); + + private final FLabel btnReset = new FLabel.Builder().opaque(true).hoverable(true).text("Reset to defaults").build(); + + private final FLabel btnDeleteMatchUI = new FLabel.Builder().opaque(true).hoverable(true).text("Reset Match Layout").build(); + private final FLabel btnDeleteEditorUI = new FLabel.Builder().opaque(true).hoverable(true).text("Reset Editor Layout").build(); + + private final FLabel lblTitleSkin = new FLabel.Builder() + .text("Choose Skin").fontStyle(Font.BOLD).fontSize(14).build(); + + private final JList lstChooseSkin = new FList(); + private final FLabel lblChooseSkin = new FLabel.Builder().fontSize(12).fontStyle(Font.ITALIC) + .text("Various user-created themes for Forge backgrounds, fonts, and colors.") + .fontAlign(SwingConstants.LEFT).build(); + private final JScrollPane scrChooseSkin = new FScrollPane(lstChooseSkin); + + private final FLabel lblTitleAIProfile = new FLabel.Builder() + .text("Choose AI Personality").fontStyle(Font.BOLD).fontSize(14).build(); + + private final JList lstChooseAIProfile = new FList(); + private final FLabel lblChooseAIProfile = new FLabel.Builder().fontSize(12).fontStyle(Font.ITALIC) + .text("AI Opponent Personality.") + .fontAlign(SwingConstants.LEFT).build(); + private final JScrollPane scrChooseAIProfile = new FScrollPane(lstChooseAIProfile); + + private final JCheckBox cbCompactMainMenu = new OptionsCheckBox("Use Compact Main Sidebar Menu"); + private final JCheckBox cbRemoveSmall = new OptionsCheckBox("Remove Small Creatures"); + private final JCheckBox cbSingletons = new OptionsCheckBox("Singleton Mode"); + private final JCheckBox cbRemoveArtifacts = new OptionsCheckBox("Remove Artifacts"); + private final JCheckBox cbAnte = new OptionsCheckBox("Play for Ante"); + private final JCheckBox cbUploadDraft = new OptionsCheckBox("Upload Draft Picks"); + 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 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"); + private final JCheckBox cbOverlayCardPower = new OptionsCheckBox("Power/Toughness"); + private final JCheckBox cbOverlayCardManaCost = new OptionsCheckBox("Mana Cost"); + private final JCheckBox cbScaleLarger = new OptionsCheckBox("Scale Image Larger"); + private final JCheckBox cbRandomFoil = new OptionsCheckBox("Random Foil"); + private final JCheckBox cbRandomizeArt = new OptionsCheckBox("Randomize Card Art"); + private final JCheckBox cbEnableSounds = new OptionsCheckBox("Enable Sounds"); + private final JCheckBox cbAltSoundSystem = new OptionsCheckBox("Use Alternate Sound System"); + private final JCheckBox cbUiForTouchScreen = new OptionsCheckBox("Enchance UI for touchscreens"); + + private final Map shortcutFields = new HashMap(); + + /** + * 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"; + + // ======== General Configuration Options ======== + pnlPrefs.add(new SectionLabel("General Configuration"), sectionConstraints + ", gaptop 2%"); + + pnlPrefs.add(cbCompactMainMenu, regularConstraints); + pnlPrefs.add(new NoteLabel("Enable for a space efficient sidebar that displays only one menu group at a time (RESTART REQUIRED)."), regularConstraints); + + // Deck building options + pnlPrefs.add(new SectionLabel("Random Deck Generation Options"), sectionConstraints + ", gaptop 2%"); + + pnlPrefs.add(cbRemoveSmall, regularConstraints); + pnlPrefs.add(new NoteLabel("Disables 1/1 and 0/X creatures in generated decks."), regularConstraints); + + pnlPrefs.add(cbSingletons, regularConstraints); + pnlPrefs.add(new NoteLabel("Disables non-land duplicates in generated decks."), regularConstraints); + + pnlPrefs.add(cbRemoveArtifacts, regularConstraints); + pnlPrefs.add(new NoteLabel("Disables artifact cards in generated decks."), regularConstraints); + + // Gameplay Options + pnlPrefs.add(new SectionLabel("Gameplay Options"), sectionConstraints); + + pnlPrefs.add(cbAnte, regularConstraints); + pnlPrefs.add(new NoteLabel("Determines whether or not the game is played for ante."), regularConstraints); + + pnlPrefs.add(cbUploadDraft, regularConstraints); + pnlPrefs.add(new NoteLabel("Sends draft picks to Forge servers for analysis, to improve draft AI."), regularConstraints); + + pnlPrefs.add(cbStackLand, regularConstraints); + pnlPrefs.add(new NoteLabel("Minimizes mana lock in AI hands, giving a slight advantage to computer."), regularConstraints); + + 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(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); + + // Troubleshooting + pnlPrefs.add(new SectionLabel("Troubleshooting"), sectionConstraints); + final String twoButtonConstraints = "w 38%!, h 30px!, gap 10% 0 0 10px"; + pnlPrefs.add(btnDeleteMatchUI, twoButtonConstraints); + pnlPrefs.add(btnDeleteEditorUI, "w 38%!, h 30px!, gap 0 0 0 10px"); + + // AI Personality Profile Options + pnlPrefs.add(new SectionLabel("AI Options"), sectionConstraints); + + pnlPrefs.add(lblTitleAIProfile, regularConstraints); + pnlPrefs.add(lblChooseAIProfile, regularConstraints); + pnlPrefs.add(scrChooseAIProfile, "h 200px!, w 200px!, gap 10% 0 0 2%, wrap"); + + // Graphic Options + pnlPrefs.add(new SectionLabel("Graphic Options"), sectionConstraints); + + pnlPrefs.add(lblTitleSkin, regularConstraints); + pnlPrefs.add(lblChooseSkin, regularConstraints); + pnlPrefs.add(scrChooseSkin, "h 200px!, w 200px!, gap 10% 0 0 2%, wrap"); + + pnlPrefs.add(cbRandomFoil, regularConstraints); + pnlPrefs.add(new NoteLabel("Adds foiled effects to random cards."), regularConstraints); + + pnlPrefs.add(cbRandomizeArt, regularConstraints); + pnlPrefs.add(new NoteLabel("Randomize the card art for cards in the human's deck"), regularConstraints); + + pnlPrefs.add(cbScaleLarger, regularConstraints); + pnlPrefs.add(new NoteLabel("Allows card pictures to be expanded larger than their original size."), regularConstraints); + + pnlPrefs.add(cbUiForTouchScreen, regularConstraints); + pnlPrefs.add(new NoteLabel("Increases some UI elements to provide a better experience on touchscreen devices. (Needs restart)"), regularConstraints); + + // Overlay options + pnlPrefs.add(new SectionLabel("Card Overlay Options"), sectionConstraints); + pnlPrefs.add(new NoteLabel("Show text overlays which are easier to read when cards are reduced in size to fit the play area."), regularConstraints); + pnlPrefs.add(cbOverlayCardName, regularConstraints); + pnlPrefs.add(cbOverlayCardPower, regularConstraints); + pnlPrefs.add(cbOverlayCardManaCost, regularConstraints); + + // Sound options + pnlPrefs.add(new SectionLabel("Sound Options"), sectionConstraints); + + pnlPrefs.add(cbEnableSounds, regularConstraints); + pnlPrefs.add(new NoteLabel("Enable sound effects during the game."), regularConstraints); + + pnlPrefs.add(cbAltSoundSystem, regularConstraints); + pnlPrefs.add(new NoteLabel("Use the alternate sound system (only use in case your have issues with sound not playing or disappearing)"), regularConstraints); + + // Keyboard shortcuts + final JLabel lblShortcuts = new SectionLabel("Keyboard Shortcuts"); + pnlPrefs.add(lblShortcuts, sectionConstraints); + + final List shortcuts = Singletons.getControl().getShortcuts(); + + for (final Shortcut s : shortcuts) { + pnlPrefs.add(new FLabel.Builder().text(s.getDescription()) + .fontAlign(SwingConstants.RIGHT).build(), "w 50%!, h 22px!, gap 0 2% 0 1%"); + KeyboardShortcutField field = new KeyboardShortcutField(s); + pnlPrefs.add(field, "w 25%!"); + shortcutFields.put(s.getPrefKey(), field); + } + + // Reset button + pnlPrefs.add(new SectionLabel(" "), sectionConstraints); + pnlPrefs.add(btnReset, sectionConstraints); + + scrContent.setBorder(null); + } + + public void reloadShortcuts() { + for (Map.Entry e : shortcutFields.entrySet()) { + e.getValue().reload(e.getKey()); + } + } + + /* (non-Javadoc) + * @see forge.view.home.IViewSubmenu#populate() + */ + @Override + public void populate() { + VHomeUI.SINGLETON_INSTANCE.getPnlDisplay().removeAll(); + + VHomeUI.SINGLETON_INSTANCE.getPnlDisplay().setLayout(new MigLayout("insets 0, gap 0")); + VHomeUI.SINGLETON_INSTANCE.getPnlDisplay().add(scrContent, "w 98%!, h 98%!, gap 1% 0 1% 0"); + + VHomeUI.SINGLETON_INSTANCE.getPnlDisplay().repaintSelf(); + VHomeUI.SINGLETON_INSTANCE.getPnlDisplay().revalidate(); + } + + /* (non-Javadoc) + * @see forge.view.home.IViewSubmenu#getGroup() + */ + @Override + public EMenuGroup getGroupEnum() { + return EMenuGroup.SETTINGS; + } + + /* (non-Javadoc) + * @see forge.gui.home.IVSubmenu#getMenuTitle() + */ + @Override + public String getMenuTitle() { + return "Preferences"; + } + + /* (non-Javadoc) + * @see forge.gui.home.IVSubmenu#getItemEnum() + */ + @Override + public EDocID getItemEnum() { + return EDocID.HOME_PREFERENCES; + } + + /** Consolidates checkbox styling in one place. */ + @SuppressWarnings("serial") + private class OptionsCheckBox extends FCheckBox { + public OptionsCheckBox(final String txt0) { + super(txt0); + setFont(FSkin.getBoldFont(12)); + } + } + + /** Consolidates section title label styling in one place. */ + @SuppressWarnings("serial") + private class SectionLabel extends JLabel { + public SectionLabel(final String txt0) { + super(txt0); + setBorder(new MatteBorder(0, 0, 1, 0, FSkin.getColor(FSkin.Colors.CLR_BORDERS))); + setHorizontalAlignment(SwingConstants.CENTER); + setFont(FSkin.getBoldFont(16)); + setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + } + } + + /** Consolidates notation label styling in one place. */ + @SuppressWarnings("serial") + private class NoteLabel extends JLabel { + public NoteLabel(final String txt0) { + super(txt0); + setFont(FSkin.getItalicFont(12)); + setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + } + } + + /** + * A JTextField plus a "codeString" property, that stores keycodes for the + * shortcut. Also, an action listener that handles translation of keycodes + * into characters and (dis)assembly of keycode stack. + */ + @SuppressWarnings("serial") + public class KeyboardShortcutField extends JTextField { + private String codeString; + + /** + * A JTextField plus a "codeString" property, that stores keycodes for + * the shortcut. Also, an action listener that handles translation of + * keycodes into characters and (dis)assembly of keycode stack. + * + * @param shortcut0   Shortcut object + */ + public KeyboardShortcutField(final Shortcut shortcut0) { + super(); + this.setEditable(false); + this.setFont(FSkin.getFont(14)); + final FPref prefKey = shortcut0.getPrefKey(); + reload(prefKey); + + this.addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(final KeyEvent evt) { + KeyboardShortcuts.addKeyCode(evt); + } + }); + + this.addFocusListener(new FocusAdapter() { + @Override + public void focusGained(final FocusEvent evt) { + KeyboardShortcutField.this.setBackground(FSkin.getColor(FSkin.Colors.CLR_ACTIVE)); + } + + @Override + public void focusLost(final FocusEvent evt) { + Singletons.getModel().getPreferences().setPref(prefKey, getCodeString()); + Singletons.getModel().getPreferences().save(); + shortcut0.attach(); + KeyboardShortcutField.this.setBackground(Color.white); + } + }); + } + + public void reload(FPref prefKey) { + this.setCodeString(Singletons.getModel().getPreferences().getPref(prefKey)); + } + + /** + * Gets the code string. + * + * @return String + */ + public final String getCodeString() { + return this.codeString; + } + + /** + * Sets the code string. + * + * @param str0 + *   The new code string (space delimited) + */ + public final void setCodeString(final String str0) { + if ("null".equals(str0)) { + return; + } + + this.codeString = str0.trim(); + + final List codes = new ArrayList(Arrays.asList(this.codeString.split(" "))); + final List displayText = new ArrayList(); + + for (final String s : codes) { + if (!s.isEmpty()) { + displayText.add(KeyEvent.getKeyText(Integer.valueOf(s))); + } + } + + this.setText(StringUtils.join(displayText, ' ')); + } + } + + /** @return {@link javax.swing.JList} */ + public final JList getLstChooseSkin() { + return lstChooseSkin; + } + + /** @return {@link forge.gui.toolbox.FLabel} */ + public final FLabel getLblChooseSkin() { + return lblChooseSkin; + } + + /** @return {@link javax.swing.JScrollPane} */ + public final JScrollPane getScrChooseSkin() { + return scrChooseSkin; + } + + /** @return {@link javax.swing.JList} */ + public final JList getLstChooseAIProfile() { + return lstChooseAIProfile; + } + + /** @return {@link forge.gui.toolbox.FLabel} */ + public final FLabel getLblChooseAIProfile() { + return lblChooseAIProfile; + } + + /** @return {@link javax.swing.JScrollPane} */ + public final JScrollPane getScrChooseAIProfile() { + return scrChooseAIProfile; + } + + /** @return {@link javax.swing.JCheckBox} */ + public final JCheckBox getCbCompactMainMenu() { + return cbCompactMainMenu; + } + + /** @return {@link javax.swing.JCheckBox} */ + public final JCheckBox getCbRemoveSmall() { + return cbRemoveSmall; + } + + /** @return {@link javax.swing.JCheckBox} */ + public final JCheckBox getCbSingletons() { + return cbSingletons; + } + + /** @return {@link javax.swing.JCheckBox} */ + public JCheckBox getCbRemoveArtifacts() { + return cbRemoveArtifacts; + } + + /** @return {@link javax.swing.JCheckBox} */ + public JCheckBox getCbUploadDraft() { + return cbUploadDraft; + } + + /** @return {@link javax.swing.JCheckBox} */ + public JCheckBox getCbStackLand() { + return cbStackLand; + } + + /** @return {@link javax.swing.JCheckBox} */ + public JCheckBox getCbOverlayCardName() { + return cbOverlayCardName; + } + + /** @return {@link javax.swing.JCheckBox} */ + public JCheckBox getCbOverlayCardPower() { + return cbOverlayCardPower; + } + + /** @return {@link javax.swing.JCheckBox} */ + public JCheckBox getCbOverlayCardManaCost() { + return cbOverlayCardManaCost; + } + + /** @return {@link javax.swing.JCheckBox} */ + public JCheckBox getCbRandomFoil() { + return cbRandomFoil; + } + + /** @return {@link javax.swing.JCheckBox} */ + public JCheckBox getCbRandomizeArt() { + return cbRandomizeArt; + } + + /** @return {@link javax.swing.JCheckBox} */ + public JCheckBox getCbAnte() { + return cbAnte; + } + + /** @return {@link javax.swing.JCheckBox} */ + public JCheckBox getCbManaBurn() { + return cbManaBurn; + } + + /** @return {@link javax.swing.JCheckBox} */ + public JCheckBox getCbScaleLarger() { + return cbScaleLarger; + } + + /** @return {@link javax.swing.JCheckBox} */ + public JCheckBox getCbDevMode() { + return cbDevMode; + } + + /** @return {@link javax.swing.JCheckBox} */ + public JCheckBox getCbEnforceDeckLegality() { + return cbEnforceDeckLegality; + } + + /** @return {@link javax.swing.JCheckBox} */ + public JCheckBox getCbCloneImgSource() { + return cbCloneImgSource; + } + + /** @return {@link javax.swing.JCheckBox} */ + public JCheckBox getCbEnableSounds() { + return cbEnableSounds; + } + + /** @return {@link javax.swing.JCheckBox} */ + public JCheckBox getCbAltSoundSystem() { + return cbAltSoundSystem; + } + + public final JCheckBox getCbUiForTouchScreen() { + return cbUiForTouchScreen; + } + + /** @return {@link forge.gui.toolbox.FLabel} */ + public FLabel getBtnReset() { + return btnReset; + } + + //========== Overridden from IVDoc + + public final FLabel getBtnDeleteMatchUI() { + return btnDeleteMatchUI; + } + + public final FLabel getBtnDeleteEditorUI() { + return btnDeleteEditorUI; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getDocumentID() + */ + @Override + public EDocID getDocumentID() { + return EDocID.HOME_PREFERENCES; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getTabLabel() + */ + @Override + public DragTab getTabLabel() { + return tab; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getLayoutControl() + */ + @Override + public CSubmenuPreferences getLayoutControl() { + return CSubmenuPreferences.SINGLETON_INSTANCE; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#setParentCell(forge.gui.framework.DragCell) + */ + @Override + public void setParentCell(DragCell cell0) { + this.parentCell = cell0; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getParentCell() + */ + @Override + public DragCell getParentCell() { + return parentCell; + } +} diff --git a/src/main/java/forge/properties/ForgePreferences.java b/src/main/java/forge/properties/ForgePreferences.java index b7a95601b96..7328ccedc92 100644 --- a/src/main/java/forge/properties/ForgePreferences.java +++ b/src/main/java/forge/properties/ForgePreferences.java @@ -38,7 +38,9 @@ public class ForgePreferences extends PreferencesStore { UI_RANDOM_FOIL ("false"), UI_SMOOTH_LAND ("false"), UI_AVATARS ("0,1"), - UI_CARD_OVERLAY ("true"), + UI_OVERLAY_CARD_NAME ("true"), + UI_OVERLAY_CARD_POWER ("true"), + UI_OVERLAY_CARD_MANA_COST ("true"), UI_UPLOAD_DRAFT ("false"), UI_SCALE_LARGER ("true"), UI_MAX_STACK ("3"), diff --git a/src/main/java/forge/view/arcane/CardPanel.java b/src/main/java/forge/view/arcane/CardPanel.java index 4ab36a9f3d0..c8e64be51bf 100644 --- a/src/main/java/forge/view/arcane/CardPanel.java +++ b/src/main/java/forge/view/arcane/CardPanel.java @@ -125,7 +125,6 @@ public class CardPanel extends JPanel implements CardContainer { private boolean isAnimationPanel; private int cardXOffset, cardYOffset, cardWidth, cardHeight; private boolean isSelected; - private boolean showCastingCost; /** *

@@ -281,18 +280,6 @@ public class CardPanel extends JPanel implements CardContainer { return this.isSelected; } - /** - *

- * Setter for the field showCastingCost. - *

- * - * @param showCastingCost - * a boolean. - */ - public final void setShowCastingCost(final boolean showCastingCost) { - this.showCastingCost = showCastingCost; - } - /** {@inheritDoc} */ @Override public final void paint(final Graphics g) { @@ -361,7 +348,7 @@ public class CardPanel extends JPanel implements CardContainer { int height = CardFaceSymbols.getHeight(); CardFaceSymbols.draw(g, cost, (this.cardXOffset + (this.cardWidth / 2)) - (width / 2), deltaY + this.cardYOffset + (this.cardHeight / 2) - height/2); } - + /** {@inheritDoc} */ @Override protected final void paintChildren(final Graphics g) { @@ -371,7 +358,7 @@ public class CardPanel extends JPanel implements CardContainer { return; } - if (this.showCastingCost && this.cardWidth < 200) { + if (showCardManaCostOverlay() && this.cardWidth < 200) { Card gameCard = this.getGameCard(); boolean showSplitMana = gameCard.isSplitCard() && gameCard.getCurState() == CardCharacteristicName.Original; if ( !showSplitMana ) { @@ -593,34 +580,37 @@ public class CardPanel extends JPanel implements CardContainer { * a {@link forge.Card} object. */ public final void setText(final Card card) { - if ((card == null) || !Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_CARD_OVERLAY)) { + + if ((card == null)) { return; } - + if (card.isFaceDown()) { this.titleText.setText(""); - this.showCastingCost = false; } else { - this.titleText.setText(card.getName()); - this.showCastingCost = true; + if (showCardNameOverlay()) { + this.titleText.setText(card.getName()); + } + } + + if (showCardPowerOverlay()) { + String sPt = ""; + if (card.isCreature() && card.isPlaneswalker()) { + sPt = String.format("%d/%d (%d)", card.getNetAttack(), card.getNetDefense(), card.getCounters(CounterType.LOYALTY)); + } else if (card.isCreature()) { + sPt = String.format("%d/%d", card.getNetAttack(), card.getNetDefense()); + } else if (card.isPlaneswalker()) { + int loyalty = card.getCounters(CounterType.LOYALTY); + sPt = String.valueOf(loyalty == 0 ? card.getBaseLoyalty() : loyalty); + } + this.ptText.setText(sPt); } - String sPt = ""; - if (card.isCreature() && card.isPlaneswalker()) { - sPt = String.format("%d/%d (%d)", card.getNetAttack(), card.getNetDefense(), card.getCounters(CounterType.LOYALTY)); - } else if (card.isCreature()) { - sPt = String.format("%d/%d", card.getNetAttack(), card.getNetDefense()); - } else if (card.isPlaneswalker()) { - int loyalty = card.getCounters(CounterType.LOYALTY); - sPt = String.valueOf(loyalty == 0 ? card.getBaseLoyalty() : loyalty); - } - this.ptText.setText(sPt); - int damage = card.getDamage(); this.damageText.setText(damage > 0 ? "\u00BB " + String.valueOf(damage) + " \u00AB" : ""); } - + /** *

* getCard. @@ -646,13 +636,11 @@ public class CardPanel extends JPanel implements CardContainer { } final BufferedImage image = card == null ? null : ImageCache.getImage(card, imagePanel.getWidth(), imagePanel.getHeight()); - if ((this.getGameCard() != null) && Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_CARD_OVERLAY)) { - this.setText(this.getGameCard()); - } + this.setText(this.getGameCard()); this.setImage(image); } - + /** * Gets the game card. * @@ -775,4 +763,22 @@ public class CardPanel extends JPanel implements CardContainer { public static final float getBorderSize() { return BLACK_BORDER_SIZE; } + + private boolean isPreferenceEnabled(FPref preferenceName) { + return Singletons.getModel().getPreferences().getPrefBoolean(preferenceName); + } + + private boolean showCardNameOverlay() { + return isPreferenceEnabled(FPref.UI_OVERLAY_CARD_NAME); + } + + private boolean showCardPowerOverlay() { + return isPreferenceEnabled(FPref.UI_OVERLAY_CARD_POWER); + } + + private boolean showCardManaCostOverlay() { + return isPreferenceEnabled(FPref.UI_OVERLAY_CARD_MANA_COST) && !this.getCard().isFaceDown(); + } + + }