update format filters for Adventure Deck Editor

use FormatFilter to filter Collections, AutoSell and NoSell cards
This commit is contained in:
Anthony Calosa
2024-11-05 22:56:47 +08:00
parent 46c502942b
commit a242f1fe04
2 changed files with 81 additions and 68 deletions

View File

@@ -419,6 +419,42 @@ public class AdventureDeckEditor extends TabPageScreen<AdventureDeckEditor> {
}
}
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<AdventureDeckEditor> {
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<AdventureDeckEditor> {
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<AdventureDeckEditor> {
Map<ColumnDef, ItemColumn> 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<AdventureDeckEditor> {
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();

View File

@@ -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<T extends InventoryItem> extends ItemFilter<T
private String selectedFormat;
private boolean preventHandling = false;
private FComboBox<Object> cbxFormats = new FComboBox<>();
private FComboBox<Object> catalogDisplay = new FComboBox<>();
public FormatFilter(ItemManager<? super T> itemManager0) {
super(itemManager0);
@@ -46,20 +49,31 @@ public abstract class FormatFilter<T extends InventoryItem> extends ItemFilter<T
cbxFormats.addItem(Forge.getLocalizer().getMessage("lblOtherFormats"));
cbxFormats.addItem(Forge.getLocalizer().getMessage("lblChooseSets"));
cbxFormats.setEnabled(!Forge.isMobileAdventureMode);
cbxFormats.setVisible(!Forge.isMobileAdventureMode);
catalogDisplay.setFont(FSkinFont.get(12));
catalogDisplay.addItem(Forge.getLocalizer().getMessage("lblShowCollection")
+ " | " + Forge.getLocalizer().getMessage("lblShowNoSell"));
catalogDisplay.addItem(Forge.getLocalizer().getMessage("lblShowCollection"));
catalogDisplay.addItem(Forge.getLocalizer().getMessage("lblShowAutoSell"));
catalogDisplay.addItem(Forge.getLocalizer().getMessage("lblShowNoSell"));
catalogDisplay.setEnabled(Forge.isMobileAdventureMode);
catalogDisplay.setVisible(Forge.isMobileAdventureMode);
selectedFormat = cbxFormats.getText();
cbxFormats.setChangedHandler(e -> {
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<T extends InventoryItem> extends ItemFilter<T
applyChange();
});
Forge.openScreen(archivedFormatSelect);
}
else if (index == cbxFormats.getItemCount() - 1) {
} else if (index == cbxFormats.getItemCount() - 1) {
preventHandling = true;
cbxFormats.setText(selectedFormat); //restore previous selection by default
preventHandling = false;
Forge.openScreen(new MultiSetSelect());
}
else {
} else {
format = (GameFormat) cbxFormats.getSelectedItem();
applyChange();
}
});
catalogDisplay.setChangedHandler(e -> {
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<T extends InventoryItem> extends ItemFilter<T
public void reset() {
preventHandling = true;
cbxFormats.setSelectedIndex(0);
catalogDisplay.setSelectedIndex(0);
preventHandling = false;
format = null;
}
@Override
public FDisplayObject getMainComponent() {
if (Forge.isMobileAdventureMode)
return catalogDisplay;
return cbxFormats;
}
@@ -110,11 +139,12 @@ public abstract class FormatFilter<T extends InventoryItem> extends ItemFilter<T
@Override
protected void buildWidget(Widget widget) {
widget.add(cbxFormats);
widget.add(Forge.isMobileAdventureMode ? catalogDisplay : cbxFormats);
}
@Override
protected void doWidgetLayout(float width, float height) {
catalogDisplay.setSize(width, height);
cbxFormats.setSize(width, height);
}
@@ -139,7 +169,6 @@ public abstract class FormatFilter<T extends InventoryItem> extends ItemFilter<T
lstSets.addGroup("Draft Innovation Sets");
lstSets.addGroup("Commander Sets");
lstSets.addGroup("Multiplayer Sets");
lstSets.addGroup("Other Supplemental Sets");
@@ -233,12 +262,10 @@ public abstract class FormatFilter<T extends InventoryItem> extends ItemFilter<T
if (selectedSets.contains(value)) {
if (count == 2) {
Forge.back(); //support double tap to confirm selection without unselecting double tapped item
}
else {
} else {
selectedSets.remove(value);
}
}
else {
} else {
selectedSets.add(value);
if (count == 2) {
Forge.back(); //support double tap to confirm selection after selecting double tapped item