From 573345760223269c62e23d0cd034bcf7e043d5e5 Mon Sep 17 00:00:00 2001 From: lodici Date: Fri, 14 Oct 2016 19:50:32 +0100 Subject: [PATCH] new layout icon; plumbing added for switching between different keywords screens. --- resources/magic/data/icons/ui/w_layout32D.png | Bin 0 -> 522 bytes src/magic/data/GeneralConfig.java | 17 ++++++- src/magic/data/MagicIcon.java | 2 +- .../ui/screen/keywords/KeywordsScreen.java | 25 +++++++++- .../ui/screen/keywords/ScreenLayout.java | 46 ++++++++++++++++++ src/magic/ui/screen/widget/MenuButton.java | 9 ++++ src/magic/ui/widget/button/LayoutButton.java | 29 +++++++++++ 7 files changed, 124 insertions(+), 4 deletions(-) create mode 100644 resources/magic/data/icons/ui/w_layout32D.png create mode 100644 src/magic/ui/screen/keywords/ScreenLayout.java create mode 100644 src/magic/ui/widget/button/LayoutButton.java diff --git a/resources/magic/data/icons/ui/w_layout32D.png b/resources/magic/data/icons/ui/w_layout32D.png new file mode 100644 index 0000000000000000000000000000000000000000..45b4c098dc3b64b647f29ba0272f40cced8374c1 GIT binary patch literal 522 zcmV+l0`>igP)a1G$jFzz{ki-bVn#Bm(B zuA4HNGV_f|bfwg3dg1kY?elm%4gsu^|A)qPPn2SO*X#Aq^yb~9Npvm5eUM~p3jrXo{8Usd)c^nh M07*qoM6N<$g4V#?Z2$lO literal 0 HcmV?d00001 diff --git a/src/magic/data/GeneralConfig.java b/src/magic/data/GeneralConfig.java index 2fdee84636..316dbccb39 100644 --- a/src/magic/data/GeneralConfig.java +++ b/src/magic/data/GeneralConfig.java @@ -176,6 +176,9 @@ public class GeneralConfig { private static final String CUSTOM_SCROLLBAR = "customScrollBar"; private boolean isCustomScrollBar = true; + private static final String KEYWORDS_SCREEN = "keywordsScreen"; + private String keywordsScreen; + private boolean isStatsVisible = true; private GeneralConfig() { } @@ -585,6 +588,7 @@ public class GeneralConfig { gameVolume = Integer.parseInt(properties.getProperty(GAME_VOLUME, "" + gameVolume)); imagesOnDemand = Boolean.parseBoolean(properties.getProperty(IMAGES_ON_DEMAND, "" + imagesOnDemand)); isCustomScrollBar = Boolean.parseBoolean(properties.getProperty(CUSTOM_SCROLLBAR, "" + isCustomScrollBar)); + keywordsScreen = properties.getProperty(KEYWORDS_SCREEN, ""); } public void load() { @@ -638,12 +642,13 @@ public class GeneralConfig { properties.setProperty(GAME_VOLUME, String.valueOf(gameVolume)); properties.setProperty(IMAGES_ON_DEMAND, String.valueOf(imagesOnDemand)); properties.setProperty(CUSTOM_SCROLLBAR, String.valueOf(isCustomScrollBar)); + properties.setProperty(KEYWORDS_SCREEN, keywordsScreen); } public void save() { - final Properties properties=new SortedProperties(); + final Properties properties = new SortedProperties(); save(properties); - try { //save config + try { FileIO.toFile(getConfigFile(), properties, "General configuration"); } catch (final IOException ex) { System.err.println("ERROR! Unable to save general config"); @@ -724,4 +729,12 @@ public class GeneralConfig { return isCustomScrollBar; } + public void setKeywordsSettings(String text) { + keywordsScreen = text; + } + + public String getKeywordsSettings() { + return keywordsScreen; + } + } diff --git a/src/magic/data/MagicIcon.java b/src/magic/data/MagicIcon.java index 9a328c0bb9..ca5d8073d6 100644 --- a/src/magic/data/MagicIcon.java +++ b/src/magic/data/MagicIcon.java @@ -30,7 +30,7 @@ public enum MagicIcon { INSTANTS("ui/w_instants.png"), KEY("ui/w_key16.png"), LANDS("ui/w_lands.png"), - LAYOUT("ui/w-layout.png"), + LAYOUT("ui/w_layout32D.png"), LEGAL("ui/card_legal.png"), LIFE("ui/w_life.png"), LOG_FILE("ui/w_log16.png"), diff --git a/src/magic/ui/screen/keywords/KeywordsScreen.java b/src/magic/ui/screen/keywords/KeywordsScreen.java index f9915451c5..f74ba0ceb8 100644 --- a/src/magic/ui/screen/keywords/KeywordsScreen.java +++ b/src/magic/ui/screen/keywords/KeywordsScreen.java @@ -1,10 +1,12 @@ package magic.ui.screen.keywords; import java.awt.event.KeyEvent; +import magic.data.GeneralConfig; import magic.translate.UiString; import magic.ui.ScreenController; import magic.ui.helpers.KeyEventAction; import magic.ui.screen.HeaderFooterScreen; +import magic.ui.screen.widget.MenuButton; @SuppressWarnings("serial") public class KeywordsScreen extends HeaderFooterScreen { @@ -15,7 +17,28 @@ public class KeywordsScreen extends HeaderFooterScreen { public KeywordsScreen() { super(UiString.get(_S1)); setDefaultProperties(); - setMainContent(new KeywordsContentPanel()); + setContent(); + } + + private void doSaveSettings() { + final GeneralConfig config = GeneralConfig.getInstance(); + config.setKeywordsSettings(ScreenLayout.getLayout().name()); + + } + + private void setContent() { + setMainContent(ScreenLayout.getLayout() == ScreenLayout.Layout1 + ? new KeywordsContentPanel() + : new KeywordsContentPanel() + ); + clearFooterButtons(); + addToFooter(MenuButton.buildLayoutButton(this::doChangeLayout)); + doSaveSettings(); + } + + private void doChangeLayout() { + ScreenLayout.setNextLayout(); + setContent(); } private void setDefaultProperties() { diff --git a/src/magic/ui/screen/keywords/ScreenLayout.java b/src/magic/ui/screen/keywords/ScreenLayout.java new file mode 100644 index 0000000000..5ac83ba121 --- /dev/null +++ b/src/magic/ui/screen/keywords/ScreenLayout.java @@ -0,0 +1,46 @@ +package magic.ui.screen.keywords; + +import magic.data.GeneralConfig; + +enum ScreenLayout { + + /** + * Original two column text only on light background. + */ + Layout1, + + /** + * Multi-column list of keywords on dark translucent background. + * Can show sample card image for selected keyword. + */ + Layout2A, + + /** + * Multi-column list of keywords on dark translucent background. + * Can multiple sample card thumbnail images for selected keyword. + */ + Layout2B; + + private static ScreenLayout layout; + static { + try { + final String setting = GeneralConfig.getInstance().getKeywordsSettings(); + layout = setting.isEmpty() ? Layout1 : valueOf(setting); + } catch (Exception ex) { + System.err.println(ex); + layout = Layout1; + } + } + + private ScreenLayout next() { + return values()[(this.ordinal()+1) % values().length]; + } + + static void setNextLayout() { + layout = layout.next(); + } + + static ScreenLayout getLayout() { + return layout; + } +} diff --git a/src/magic/ui/screen/widget/MenuButton.java b/src/magic/ui/screen/widget/MenuButton.java index 09d0693744..5bf987cc6e 100644 --- a/src/magic/ui/screen/widget/MenuButton.java +++ b/src/magic/ui/screen/widget/MenuButton.java @@ -18,6 +18,7 @@ import magic.ui.ScreenController; import magic.ui.helpers.ImageHelper; import magic.ui.utility.MagicStyle; import magic.ui.FontsAndBorders; +import magic.ui.widget.button.LayoutButton; @SuppressWarnings("serial") public class MenuButton extends JButton { @@ -232,4 +233,12 @@ public class MenuButton extends JButton { } }); } + + /** + * Action bar button used to change screen layout. + */ + public static MenuButton buildLayoutButton(final Runnable action) { + return new LayoutButton(action); + } + } diff --git a/src/magic/ui/widget/button/LayoutButton.java b/src/magic/ui/widget/button/LayoutButton.java new file mode 100644 index 0000000000..3b4a99de51 --- /dev/null +++ b/src/magic/ui/widget/button/LayoutButton.java @@ -0,0 +1,29 @@ +package magic.ui.widget.button; + +import java.awt.event.ActionEvent; +import javax.swing.AbstractAction; +import magic.data.MagicIcon; +import magic.ui.MagicImages; +import magic.ui.screen.widget.ActionBarButton; + +/** + * Action bar button used to change screen layout. + */ +@SuppressWarnings("serial") +public class LayoutButton extends ActionBarButton { + + private static final String _S7 = "Screen layout"; + private static final String _S8 = "Cycles through different screen layouts."; + + public LayoutButton(final Runnable action) { + super(MagicImages.getIcon(MagicIcon.LAYOUT), _S7, _S8, + new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + action.run(); + } + } + ); + } + +}