From a242f1fe04e7170d7d6f7e4fcdf142a9d6cc9dfc Mon Sep 17 00:00:00 2001 From: Anthony Calosa Date: Tue, 5 Nov 2024 22:56:47 +0800 Subject: [PATCH] update format filters for Adventure Deck Editor use FormatFilter to filter Collections, AutoSell and NoSell cards --- .../adventure/scene/AdventureDeckEditor.java | 88 ++++++++----------- .../itemmanager/filters/FormatFilter.java | 61 +++++++++---- 2 files changed, 81 insertions(+), 68 deletions(-) diff --git a/forge-gui-mobile/src/forge/adventure/scene/AdventureDeckEditor.java b/forge-gui-mobile/src/forge/adventure/scene/AdventureDeckEditor.java index 28d812a139e..5b2d43c072c 100644 --- a/forge-gui-mobile/src/forge/adventure/scene/AdventureDeckEditor.java +++ b/forge-gui-mobile/src/forge/adventure/scene/AdventureDeckEditor.java @@ -419,6 +419,42 @@ public class AdventureDeckEditor extends TabPageScreen { } } + public void showDefault() { + if (catalogPage == null) + return; + catalogPage.showCollectionCards = true; + catalogPage.showAutoSellCards = false; + catalogPage.showNoSellCards = true; + catalogPage.refresh(); + } + + public void showCollection() { + if (catalogPage == null) + return; + catalogPage.showCollectionCards = true; + catalogPage.showAutoSellCards = false; + catalogPage.showNoSellCards = false; + catalogPage.refresh(); + } + + public void showAutoSell() { + if (catalogPage == null) + return; + catalogPage.showCollectionCards = false; + catalogPage.showAutoSellCards = true; + catalogPage.showNoSellCards = false; + catalogPage.refresh(); + } + + public void showNoSell() { + if (catalogPage == null) + return; + catalogPage.showCollectionCards = false; + catalogPage.showAutoSellCards = false; + catalogPage.showNoSellCards = true; + catalogPage.refresh(); + } + private static DeckEditorPage[] getPages(boolean isShop) { if (isShop) { return new DeckEditorPage[]{ @@ -543,32 +579,6 @@ public class AdventureDeckEditor extends TabPageScreen { FMenuItem addBasic = new FMenuItem(Forge.getLocalizer().getMessage("lblAddBasicLands"), FSkinImage.LANDLOGO, e1 -> launchBasicLandDialog()); addItem(addBasic); } - if (!isShop && catalogPage != null && !(catalogPage instanceof ContentPreviewPage)) { - if (catalogPage.showNoSellCards) { - FMenuItem hideNoSell = new FMenuItem(Forge.getLocalizer().getMessage("lblHideNoSell"), Forge.hdbuttons ? FSkinImage.HDMINUS : FSkinImage.MINUS, e1 -> catalogPage.toggleNoSellCards(false)); - addItem(hideNoSell); - hideNoSell.setEnabled(catalogPage.showAutoSellCards || catalogPage.showCollectionCards); - } else { - addItem(new FMenuItem(Forge.getLocalizer().getMessage("lblShowNoSell"), Forge.hdbuttons ? FSkinImage.HDPLUS : FSkinImage.PLUS, e1 -> catalogPage.toggleNoSellCards(true))); - } - if (catalogPage.showAutoSellCards) { - FMenuItem hideAutoSell = new FMenuItem(Forge.getLocalizer().getMessage("lblHideAutoSell"), Forge.hdbuttons ? FSkinImage.HDMINUS : FSkinImage.MINUS, e1 -> catalogPage.toggleAutoSellCards(false)); - addItem(hideAutoSell); - hideAutoSell.setEnabled(catalogPage.showCollectionCards || catalogPage.showNoSellCards); - } else { - addItem(new FMenuItem(Forge.getLocalizer().getMessage("lblShowAutoSell"), Forge.hdbuttons ? FSkinImage.HDPLUS : FSkinImage.PLUS, e1 -> catalogPage.toggleAutoSellCards(true))); - } - if (catalogPage.showCollectionCards) { - FMenuItem hideCollection = new FMenuItem(Forge.getLocalizer().getMessage("lblHideCollection"), Forge.hdbuttons ? FSkinImage.HDMINUS : FSkinImage.MINUS, e1 -> catalogPage.toggleCollectionCards(false)); - addItem(hideCollection); - hideCollection.setEnabled(catalogPage.showAutoSellCards || catalogPage.showNoSellCards); - } else { - addItem(new FMenuItem(Forge.getLocalizer().getMessage("lblShowCollection"), Forge.hdbuttons ? FSkinImage.HDPLUS : FSkinImage.PLUS, e1 -> catalogPage.toggleCollectionCards(true))); - } - if (!catalogPage.showNoSellCards || !catalogPage.showAutoSellCards || !catalogPage.showCollectionCards) { - addItem(new FMenuItem(Forge.getLocalizer().getMessage("lblShowAll"), Forge.hdbuttons ? FSkinImage.HDPLUS : FSkinImage.PLUS, e1 -> catalogPage.showAllCards())); - } - } ((DeckEditorPage) getSelectedPage()).buildDeckMenu(this); } }; @@ -589,8 +599,7 @@ public class AdventureDeckEditor extends TabPageScreen { availableEditionCodes.add(FModel.getMagicDb().getEditions().get(p.getEdition())); } defaultLandSet = CardEdition.Predicates.getRandomSetWithAllBasicLands(availableEditionCodes); - } - else { + } else { defaultLandSet = FModel.getMagicDb().getEditions().get("JMP"); } @@ -751,7 +760,6 @@ public class AdventureDeckEditor extends TabPageScreen { Map colOverrides = new HashMap<>(); ItemColumn.addColOverride(config, colOverrides, ColumnDef.NEW, fnNewCompare, fnNewGet); ItemColumn.addColOverride(config, colOverrides, ColumnDef.DECKS, fnDeckCompare, fnDeckGet); - cardManager.setup(config, colOverrides); } @@ -991,28 +999,6 @@ public class AdventureDeckEditor extends TabPageScreen { boolean showCollectionCards = true, showAutoSellCards = false, showNoSellCards = true; - public void showAllCards() { - showCollectionCards = true; - showAutoSellCards = true; - showNoSellCards = true; - refresh(); - } - - public void toggleCollectionCards(boolean show) { - showCollectionCards = show; - refresh(); - } - - public void toggleAutoSellCards(boolean show) { - showAutoSellCards = show; - refresh(); - } - - public void toggleNoSellCards(boolean show) { - showNoSellCards = show; - refresh(); - } - protected CatalogPage(ItemManagerConfig config, String caption0, FImage icon0) { super(config, caption0, icon0); refresh(); diff --git a/forge-gui-mobile/src/forge/itemmanager/filters/FormatFilter.java b/forge-gui-mobile/src/forge/itemmanager/filters/FormatFilter.java index 460f066fb3c..116acab5a34 100644 --- a/forge-gui-mobile/src/forge/itemmanager/filters/FormatFilter.java +++ b/forge-gui-mobile/src/forge/itemmanager/filters/FormatFilter.java @@ -10,6 +10,8 @@ import com.badlogic.gdx.utils.Align; import forge.Forge; import forge.Graphics; +import forge.adventure.scene.AdventureDeckEditor; +import forge.adventure.scene.DeckEditScene; import forge.assets.FSkinColor; import forge.assets.FSkinFont; import forge.card.CardEdition; @@ -34,6 +36,7 @@ public abstract class FormatFilter extends ItemFilter cbxFormats = new FComboBox<>(); + private FComboBox catalogDisplay = new FComboBox<>(); public FormatFilter(ItemManager itemManager0) { super(itemManager0); @@ -46,20 +49,31 @@ public abstract class FormatFilter extends ItemFilter { - if (preventHandling) { return; } + if (preventHandling) { + return; + } int index = cbxFormats.getSelectedIndex(); if (index == -1) { //Do nothing when index set to -1 - } - else if (index == 0) { + } else if (index == 0) { format = null; applyChange(); - } - else if (index == cbxFormats.getItemCount() - 2) { + } else if (index == cbxFormats.getItemCount() - 2) { preventHandling = true; cbxFormats.setText(selectedFormat); //restore previous selection by default preventHandling = false; @@ -70,18 +84,30 @@ public abstract class FormatFilter extends ItemFilter { + if (preventHandling) + return; + int index = catalogDisplay.getSelectedIndex(); + if (index == -1) { + //Do nothing when index set to -1 + } + switch (index) { + case 0 -> ((AdventureDeckEditor) DeckEditScene.getInstance().getScreen()).showDefault(); + case 1 -> ((AdventureDeckEditor) DeckEditScene.getInstance().getScreen()).showCollection(); + case 2 -> ((AdventureDeckEditor) DeckEditScene.getInstance().getScreen()).showAutoSell(); + case 3 -> ((AdventureDeckEditor) DeckEditScene.getInstance().getScreen()).showNoSell(); + } + }); } @Override @@ -94,12 +120,15 @@ public abstract class FormatFilter extends ItemFilter extends ItemFilter extends ItemFilter extends ItemFilter extends ItemFilter