From f664b001a2e3c2fd56deb1c37222a80425f939d0 Mon Sep 17 00:00:00 2001 From: Anthony Calosa Date: Wed, 22 Feb 2023 06:38:01 +0800 Subject: [PATCH] update SpellSmithScene selectbox --- .../src/forge/adventure/scene/SpellSmithScene.java | 9 ++++++++- .../src/forge/adventure/util/Controls.java | 11 +++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/forge-gui-mobile/src/forge/adventure/scene/SpellSmithScene.java b/forge-gui-mobile/src/forge/adventure/scene/SpellSmithScene.java index f94739f9312..47495508232 100644 --- a/forge-gui-mobile/src/forge/adventure/scene/SpellSmithScene.java +++ b/forge-gui-mobile/src/forge/adventure/scene/SpellSmithScene.java @@ -117,6 +117,7 @@ public class SpellSmithScene extends UIScene { ui.onButtonPress("BResetEdition", () -> { editionList.setColor(Color.WHITE); edition = ""; + editionList.setUserObject(edition); filterResults(); }); } @@ -267,7 +268,6 @@ public class SpellSmithScene extends UIScene { loadEditions(); //just to be safe since it's preloaded, if somehow edition is null, then reload it editionList.clearListeners(); editionList.clearItems(); - editionList.showScrollPane(); editionList.setItems(editions.toArray(new CardEdition[editions.size()])); editionList.addListener(new ChangeListener() { @Override @@ -278,6 +278,12 @@ public class SpellSmithScene extends UIScene { filterResults(); } }); + editionList.addListener(new ClickListener() { + @Override + public void clicked(InputEvent event, float x, float y) { + editionList.showScrollPane(); + } + }); editionList.setColor(Color.WHITE); filterResults(); super.enter(); @@ -357,6 +363,7 @@ public class SpellSmithScene extends UIScene { pullUsingShards.setText("Pull: " + currentShardPrice + "[+shards]"); pullUsingGold.setDisabled(!(cardPool.size() > 0) || Current.player().getGold() < totalCost); pullUsingShards.setDisabled(!(cardPool.size() > 0) || Current.player().getShards() < currentShardPrice); + editionList.setUserObject(edition); } public void pullCard(boolean usingShards) { diff --git a/forge-gui-mobile/src/forge/adventure/util/Controls.java b/forge-gui-mobile/src/forge/adventure/util/Controls.java index c3f612fca6a..617f92a5775 100644 --- a/forge-gui-mobile/src/forge/adventure/util/Controls.java +++ b/forge-gui-mobile/src/forge/adventure/util/Controls.java @@ -2,7 +2,9 @@ package forge.adventure.util; import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.graphics.Color; +import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.g2d.BitmapFont; +import com.badlogic.gdx.graphics.g2d.GlyphLayout; import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.math.Interpolation; import com.badlogic.gdx.math.Rectangle; @@ -148,6 +150,15 @@ public class Controls { return (this.isOver() || hasKeyboardFocus()) && this.getStyle().backgroundOver != null ? this.getStyle().backgroundOver : this.getStyle().background; } } + + @Override + protected GlyphLayout drawItem(Batch batch, BitmapFont font, T item, float x, float y, float width) { + if (getUserObject() != null && getUserObject() instanceof String) { //currently this is used on spellsmith... + if (((String) getUserObject()).isEmpty()) + return super.drawItem(batch, font, (T) Forge.getLocalizer().getMessage("lblSelectingFilter"), x, y, width); + } + return super.drawItem(batch, font, item, x, y, width); + } }; } static public SelectBox newComboBox(Float[] text, float item, Function func) {