From c13e379908222258360e34edd740054b5c76f4d8 Mon Sep 17 00:00:00 2001 From: Bug Hunter Date: Sun, 2 May 2021 14:25:35 +0000 Subject: [PATCH] Add preference how to display alternate card states in deck views --- .../forge/itemmanager/views/ImageView.java | 59 +++++++++++-------- .../home/settings/CSubmenuPreferences.java | 10 ++++ .../home/settings/VSubmenuPreferences.java | 8 +++ .../match/controllers/CDetailPicture.java | 10 +++- forge-gui/res/languages/de-DE.properties | 2 + forge-gui/res/languages/en-US.properties | 2 + forge-gui/res/languages/es-ES.properties | 2 + forge-gui/res/languages/it-IT.properties | 2 + forge-gui/res/languages/ja-JP.properties | 2 + forge-gui/res/languages/zh-CN.properties | 2 + .../properties/ForgeConstants.java | 9 ++- .../properties/ForgePreferences.java | 1 + 12 files changed, 80 insertions(+), 29 deletions(-) diff --git a/forge-gui-desktop/src/main/java/forge/itemmanager/views/ImageView.java b/forge-gui-desktop/src/main/java/forge/itemmanager/views/ImageView.java index c47e40893ad..9c89dfec2c7 100644 --- a/forge-gui-desktop/src/main/java/forge/itemmanager/views/ImageView.java +++ b/forge-gui-desktop/src/main/java/forge/itemmanager/views/ImageView.java @@ -46,7 +46,9 @@ import forge.itemmanager.ItemManager; import forge.itemmanager.ItemManagerConfig; import forge.itemmanager.ItemManagerModel; import forge.itemmanager.SItemManagerUtil; +import forge.localinstance.properties.ForgeConstants; import forge.localinstance.properties.ForgePreferences; +import forge.localinstance.properties.ForgePreferences.FPref; import forge.localinstance.skin.FSkinProp; import forge.model.FModel; import forge.screens.deckeditor.CDeckEditorUI; @@ -796,6 +798,10 @@ public class ImageView extends ItemView { if (hoveredItem == item) { return false; } hoveredItem = item; if (item != null) { + final CDetailPicture cDetailPicture = itemManager.getCDetailPicture(); + if (cDetailPicture != null) { + cDetailPicture.displayAlt(item.alt); + } showHoveredItem(item.item); } return true; @@ -999,6 +1005,7 @@ public class ImageView extends ItemView { private final T item; private int index; private boolean selected; + private boolean alt; private ItemInfo(T item0) { item = item0; @@ -1115,6 +1122,7 @@ public class ImageView extends ItemView { if (pile.getTop() >= visibleBottom) { break; } + for (ItemInfo itemInfo : pile.items) { if (itemInfo.getBottom() < visibleTop) { continue; @@ -1122,6 +1130,28 @@ public class ImageView extends ItemView { if (itemInfo.getTop() >= visibleBottom) { break; } + + InventoryItem item = itemInfo.item; + itemInfo.alt = false; + if (!FModel.getPreferences().getPref(FPref.UI_SWITCH_STATES_DECKVIEW).equals(ForgeConstants.SWITCH_CARDSTATES_DECK_NEVER)) { + if ((hoveredItem == null || !hoveredItem.item.equals(item)) || (FModel.getPreferences().getPref(FPref.UI_SWITCH_STATES_DECKVIEW).equals(ForgeConstants.SWITCH_CARDSTATES_DECK_ALWAYS))) { + if (item instanceof PaperCard) { + if (ImageUtil.hasBackFacePicture(((PaperCard)item))) { + if (item.equals(lastAltCard)) { + itemInfo.alt = true; + lastAltCard = null; + } + else { + lastAltCard = item; + } + } + else { + lastAltCard = null; + } + } + } + } + if (itemInfo != hoveredItem) { //save hovered item for last drawItemImage(g2d, itemInfo); } @@ -1149,12 +1179,13 @@ public class ImageView extends ItemView { Rectangle bounds = itemInfo.getBounds(); final int itemWidth = bounds.width; final int selBorderSize = 1; - boolean deckSelectMode = itemInfo.item instanceof DeckProxy; + InventoryItem item = itemInfo.item; + boolean deckSelectMode = item instanceof DeckProxy; // Determine whether to render border from properties boolean noBorder = !isPreferenceEnabled(ForgePreferences.FPref.UI_RENDER_BLACK_BORDERS); - if (itemInfo.item instanceof IPaperCard) { - CardView cv = CardView.getCardForUi((IPaperCard) itemInfo.item); + if (item instanceof IPaperCard) { + CardView cv = CardView.getCardForUi((IPaperCard) item); // Amonkhet Invocations noBorder |= cv.getCurrentState().getSetCode().equalsIgnoreCase("MPS_AKH"); // Unstable basic lands @@ -1174,27 +1205,7 @@ public class ImageView extends ItemView { g.setColor(Color.black); g.fillRoundRect(bounds.x, bounds.y, bounds.width, bounds.height, cornerSize, cornerSize); - InventoryItem item = itemInfo.item; - - boolean tryAltState = false; - if (hoveredItem == null || hoveredItem.item != item) { - if (item instanceof PaperCard) { - if (ImageUtil.hasBackFacePicture(((PaperCard)item))) { - if (item.equals(lastAltCard)) { - tryAltState = true; - lastAltCard = null; - } - else { - lastAltCard = item; - } - } - else { - lastAltCard = null; - } - } - } - - BufferedImage img = ImageCache.getImage(item, bounds.width - 2 * borderSize, bounds.height - 2 * borderSize, tryAltState); + BufferedImage img = ImageCache.getImage(item, bounds.width - 2 * borderSize, bounds.height - 2 * borderSize, itemInfo.alt); if (img != null) { g.drawImage(img, null, bounds.x + borderSize, bounds.y + borderSize); diff --git a/forge-gui-desktop/src/main/java/forge/screens/home/settings/CSubmenuPreferences.java b/forge-gui-desktop/src/main/java/forge/screens/home/settings/CSubmenuPreferences.java index 5db97522d48..08a3f485aee 100644 --- a/forge-gui-desktop/src/main/java/forge/screens/home/settings/CSubmenuPreferences.java +++ b/forge-gui-desktop/src/main/java/forge/screens/home/settings/CSubmenuPreferences.java @@ -257,6 +257,7 @@ public enum CSubmenuPreferences implements ICDoc { initializeStackAdditionsComboBox(); initializeLandPlayedComboBox(); initializeColorIdentityCombobox(); + initializeSwitchStatesCombobox(); initializeAutoYieldModeComboBox(); initializeCounterDisplayTypeComboBox(); initializeCounterDisplayLocationComboBox(); @@ -480,6 +481,15 @@ public enum CSubmenuPreferences implements ICDoc { panel.setComboBox(comboBox, selectedItem); } + private void initializeSwitchStatesCombobox() { + final String[] elems = {ForgeConstants.SWITCH_CARDSTATES_DECK_NEVER, ForgeConstants.SWITCH_CARDSTATES_DECK_HOVER, ForgeConstants.SWITCH_CARDSTATES_DECK_ALWAYS}; + final FPref userSetting = FPref.UI_SWITCH_STATES_DECKVIEW; + final FComboBoxPanel panel = this.view.getSwitchStates(); + final FComboBox comboBox = createComboBox(elems, userSetting); + final String selectedItem = this.prefs.getPref(userSetting); + panel.setComboBox(comboBox, selectedItem); + } + private void initializeAutoYieldModeComboBox() { final String[] elems = {ForgeConstants.AUTO_YIELD_PER_ABILITY, ForgeConstants.AUTO_YIELD_PER_CARD}; final FPref userSetting = FPref.UI_AUTO_YIELD_MODE; diff --git a/forge-gui-desktop/src/main/java/forge/screens/home/settings/VSubmenuPreferences.java b/forge-gui-desktop/src/main/java/forge/screens/home/settings/VSubmenuPreferences.java index 250ffd4b4c3..88607bcf411 100644 --- a/forge-gui-desktop/src/main/java/forge/screens/home/settings/VSubmenuPreferences.java +++ b/forge-gui-desktop/src/main/java/forge/screens/home/settings/VSubmenuPreferences.java @@ -143,6 +143,7 @@ public enum VSubmenuPreferences implements IVSubmenu { private final FComboBoxPanel cbpGraveyardOrdering = new FComboBoxPanel<>(localizer.getMessage("cbpGraveyardOrdering")+":"); private final FComboBoxPanel cbpDefaultLanguage = new FComboBoxPanel<>(localizer.getMessage("cbpSelectLanguage")+":"); private final FComboBoxPanel cbpAutoUpdater = new FComboBoxPanel<>(localizer.getMessage("cbpAutoUpdater")+":"); + private final FComboBoxPanel cbpSwitchStates = new FComboBoxPanel<>(localizer.getMessage("cbpSwitchStates")+":"); /** * Constructor. @@ -384,6 +385,9 @@ public enum VSubmenuPreferences implements IVSubmenu { pnlPrefs.add(cbpDisplayCurrentCardColors, comboBoxConstraints); pnlPrefs.add(new NoteLabel(localizer.getMessage("nlDisplayCurrentCardColors")), descriptionConstraints); + pnlPrefs.add(cbpSwitchStates, comboBoxConstraints); + pnlPrefs.add(new NoteLabel(localizer.getMessage("nlSwitchStates")), descriptionConstraints); + // Sound options pnlPrefs.add(new SectionLabel(localizer.getMessage("SoundOptions")), sectionConstraints + ", gaptop 2%"); @@ -732,6 +736,10 @@ public enum VSubmenuPreferences implements IVSubmenu { return cbpDisplayCurrentCardColors; } + public FComboBoxPanel getSwitchStates() { + return cbpSwitchStates; + } + public FComboBoxPanel getCloseActionComboBoxPanel() { return cbpCloseAction; } diff --git a/forge-gui-desktop/src/main/java/forge/screens/match/controllers/CDetailPicture.java b/forge-gui-desktop/src/main/java/forge/screens/match/controllers/CDetailPicture.java index f2b82899bee..ac0ebd099cf 100644 --- a/forge-gui-desktop/src/main/java/forge/screens/match/controllers/CDetailPicture.java +++ b/forge-gui-desktop/src/main/java/forge/screens/match/controllers/CDetailPicture.java @@ -39,11 +39,15 @@ public class CDetailPicture { return cPicture; } + public void displayAlt(final boolean showAlt) { + isDisplayAlt = showAlt; + } + public void showCard(final CardView c, final boolean showAlt) { currentView = c; - final boolean mayView = mayView(), mayFlip = mayView && mayFlip(); + final boolean mayFlip = mayView() && mayFlip(); isDisplayAlt = mayFlip && showAlt; - alwaysDisplayAlt = mayView && mayFlip && c.isFaceDown(); + alwaysDisplayAlt = mayFlip && c.isFaceDown(); update(); } @@ -65,7 +69,7 @@ public class CDetailPicture { c.getCurrentState().setFoilIndexOverride(1); } } - showCard(c, false); + showCard(c, isDisplayAlt); } else { currentView = null; isDisplayAlt = false; diff --git a/forge-gui/res/languages/de-DE.properties b/forge-gui/res/languages/de-DE.properties index 5bfa301d34b..d81fee9ec5d 100644 --- a/forge-gui/res/languages/de-DE.properties +++ b/forge-gui/res/languages/de-DE.properties @@ -193,6 +193,8 @@ nlSrOptimize=Setze verschiedene Optionen, um Forge besser für Screenreader lesb KeyboardShortcuts=Tastenkombinationen cbpLandPlayed=Land-kommt-ins-Spiel-Benachrichtigung nlpLandPlayed=Wenn ein Land auf das Spielfeld kommt, wann möchtest du eine Benachrichtigung bekommen: Niemals, immer oder nur bei Aktionen der KI? +cbpSwitchStates=Switch card states +nlSwitchStates=Display alternate state for every second copy in deck viewers. #VSubmenuAchievements.java lblAchievements=Errungenschaften #VSubmenuDownloaders.java diff --git a/forge-gui/res/languages/en-US.properties b/forge-gui/res/languages/en-US.properties index 8704ce0a225..ee3f6e5eb4c 100644 --- a/forge-gui/res/languages/en-US.properties +++ b/forge-gui/res/languages/en-US.properties @@ -193,6 +193,8 @@ nlSrOptimize=Set various options to make FOrge work better with screen readers KeyboardShortcuts=Keyboard Shortcuts cbpLandPlayed=Land entering battlefield notifications nlpLandPlayed=Choose when you want to get visual notifications for a land entering the battlefield: Never, always, or only for the lands entering a battlefield because of an action of a AI player +cbpSwitchStates=Switch card states +nlSwitchStates=Display alternate state for every second copy in deck viewers. #VSubmenuAchievements.java lblAchievements=Achievements #VSubmenuDownloaders.java diff --git a/forge-gui/res/languages/es-ES.properties b/forge-gui/res/languages/es-ES.properties index 96d8c97c0e4..b38f78cda0d 100644 --- a/forge-gui/res/languages/es-ES.properties +++ b/forge-gui/res/languages/es-ES.properties @@ -193,6 +193,8 @@ nlSrOptimize=Establecer varias opciones para que Forge funcione mejor con los le KeyboardShortcuts=Atajos de teclado cbpLandPlayed=Notificación al entrar una tierra en juego nlpLandPlayed=Elige cuando quieras recibir notificaciones visuales de una tierra que entra en el campo de batalla: Nunca, siempre o sólo para las tierras que entran en el campo de batalla por una acción de un jugador IA. +cbpSwitchStates=Switch card states +nlSwitchStates=Display alternate state for every second copy in deck viewers. #VSubmenuAchievements.java lblAchievements=Trofeos #VSubmenuDownloaders.java diff --git a/forge-gui/res/languages/it-IT.properties b/forge-gui/res/languages/it-IT.properties index f90f2ee3d06..91bbe2c49a4 100644 --- a/forge-gui/res/languages/it-IT.properties +++ b/forge-gui/res/languages/it-IT.properties @@ -193,6 +193,8 @@ nlSrOptimize=Set various options to make FOrge work better with screen readers KeyboardShortcuts=Tasti rapidi cbpLandPlayed=Land entering battlefield notifications nlpLandPlayed=Choose when you want to get visual notifications for a land entering the battlefield: Never, always, or only for the lands entering a battlefield because of an action of a AI player +cbpSwitchStates=Switch card states +nlSwitchStates=Display alternate state for every second copy in deck viewers. #VSubmenuAchievements.java lblAchievements=realizzazioni #VSubmenuDownloaders.java diff --git a/forge-gui/res/languages/ja-JP.properties b/forge-gui/res/languages/ja-JP.properties index c7103db035c..9df88803379 100644 --- a/forge-gui/res/languages/ja-JP.properties +++ b/forge-gui/res/languages/ja-JP.properties @@ -193,6 +193,8 @@ nlSrOptimize=Forge とスクリーンリーダーを上手く連動できるよ KeyboardShortcuts=キーボードショートカット cbpLandPlayed=土地が戦場に出るときの通知 nlpLandPlayed=土地が戦場に出た時いつに通知を受けたい:Never[しない]、Always[常時]、またはAIプレイヤーの行動によるの時だけ。 +cbpSwitchStates=Switch card states +nlSwitchStates=Display alternate state for every second copy in deck viewers. #VSubmenuAchievements.java lblAchievements=実績 #VSubmenuDownloaders.java diff --git a/forge-gui/res/languages/zh-CN.properties b/forge-gui/res/languages/zh-CN.properties index ac77731a3f3..114c7cd39ee 100644 --- a/forge-gui/res/languages/zh-CN.properties +++ b/forge-gui/res/languages/zh-CN.properties @@ -193,6 +193,8 @@ nlSrOptimize=使屏幕阅读器能更好的在forge上使用 KeyboardShortcuts=键盘快捷键 cbpLandPlayed=当地牌进入战场发出通知 nlpLandPlayed=选择你是否想收到地牌进入战场的视觉通知:从不(Never),总是(always), 或者只有当地牌是因AI玩家的动作而进入战场 +cbpSwitchStates=Switch card states +nlSwitchStates=Display alternate state for every second copy in deck viewers. #VSubmenuAchievements.java lblAchievements=成就 #VSubmenuDownloaders.java diff --git a/forge-gui/src/main/java/forge/localinstance/properties/ForgeConstants.java b/forge-gui/src/main/java/forge/localinstance/properties/ForgeConstants.java index 2319a427c82..d58d06a3090 100644 --- a/forge-gui/src/main/java/forge/localinstance/properties/ForgeConstants.java +++ b/forge-gui/src/main/java/forge/localinstance/properties/ForgeConstants.java @@ -338,13 +338,18 @@ public final class ForgeConstants { public static final String STACK_EFFECT_NOTIFICATION_ALWAYS = "Always"; public static final String STACK_EFFECT_NOTIFICATION_AI_AND_TRIGGERED = "AI cast/activated, or triggered by any player"; - // Constants for LAnd played notification policy + // Constants for Land played notification policy public static final String LAND_PLAYED_NOTIFICATION_NEVER = "Never"; public static final String LAND_PLAYED_NOTIFICATION_ALWAYS = "Always"; public static final String LAND_PLAYED_NOTIFICATION_ALWAYS_FOR_NONBASIC_LANDS = "Always, but only for nonbasic lands"; public static final String LAND_PLAYED_NOTIFICATION_AI = "Lands entering a battlefield because of an action of a AI player"; public static final String LAND_PLAYED_NOTIFICATION_AI_FOR_NONBASIC_LANDS = "Nonbasic lands entering a battlefield because of an action of a AI player"; - + + // Constants for Land played notification policy + public static final String SWITCH_CARDSTATES_DECK_NEVER = "Never"; + public static final String SWITCH_CARDSTATES_DECK_ALWAYS = "Always"; + public static final String SWITCH_CARDSTATES_DECK_HOVER = "Switch back on hover"; + // Set boolean constant for landscape mode for gdx port public static final boolean isGdxPortLandscape = FileUtil.doesFileExist(ASSETS_DIR + "switch_orientation.ini"); diff --git a/forge-gui/src/main/java/forge/localinstance/properties/ForgePreferences.java b/forge-gui/src/main/java/forge/localinstance/properties/ForgePreferences.java index 033357e4d60..73caaab43bc 100644 --- a/forge-gui/src/main/java/forge/localinstance/properties/ForgePreferences.java +++ b/forge-gui/src/main/java/forge/localinstance/properties/ForgePreferences.java @@ -157,6 +157,7 @@ public class ForgePreferences extends PreferencesStore { UI_DEFAULT_FONT_SIZE("12"), UI_SELECT_FROM_CARD_DISPLAYS("true"), UI_FOR_TOUCHSCREN("false"), + UI_SWITCH_STATES_DECKVIEW("Always"), UI_VIBRATE_ON_LIFE_LOSS("true"), UI_VIBRATE_ON_LONG_PRESS("true"),