diff --git a/forge-gui-mobile/src/forge/adventure/scene/RewardScene.java b/forge-gui-mobile/src/forge/adventure/scene/RewardScene.java index 6a40d5ca7d6..ee0f69af36d 100644 --- a/forge-gui-mobile/src/forge/adventure/scene/RewardScene.java +++ b/forge-gui-mobile/src/forge/adventure/scene/RewardScene.java @@ -41,12 +41,13 @@ public class RewardScene extends UIScene { private PointOfInterestChanges changes; public static RewardScene instance() { - if(object==null) - object=new RewardScene(); + if (object == null) + object = new RewardScene(); return object; } private boolean showTooltips = false; + public enum Type { Shop, Loot, @@ -55,7 +56,7 @@ public class RewardScene extends UIScene { Type type; Array generated = new Array<>(); - static public final float CARD_WIDTH = 550f ; + static public final float CARD_WIDTH = 550f; static public final float CARD_HEIGHT = 400f; static public final float CARD_WIDTH_TO_HEIGHT = CARD_WIDTH / CARD_HEIGHT; ItemPool collectionPool = null; @@ -65,7 +66,7 @@ public class RewardScene extends UIScene { super(Forge.isLandscapeMode() ? "ui/items.json" : "ui/items_portrait.json"); playerGold = Controls.newAccountingLabel(ui.findActor("playerGold"), false); - playerShards = Controls.newAccountingLabel(ui.findActor("playerShards"),true); + playerShards = Controls.newAccountingLabel(ui.findActor("playerShards"), true); shopNameLabel = ui.findActor("shopName"); ui.onButtonPress("done", this::done); ui.onButtonPress("detail", this::toggleToolTip); @@ -87,6 +88,7 @@ public class RewardScene extends UIScene { super.disconnected(controller); updateDetailButton(); } + private void updateDetailButton() { detailButton.setVisible(Controllers.getCurrent() != null); detailButton.layout(); @@ -94,29 +96,21 @@ public class RewardScene extends UIScene { private void toggleToolTip() { - Selectable selectable=getSelected(); - if(selectable==null) + Selectable selectable = getSelected(); + if (selectable == null) return; RewardActor actor; - if(selectable.actor instanceof BuyButton) - { - actor= ((BuyButton) selectable.actor).reward; - } - else if (selectable.actor instanceof RewardActor) - { - actor= (RewardActor) selectable.actor; - } - else - { + if (selectable.actor instanceof BuyButton) { + actor = ((BuyButton) selectable.actor).rewardActor; + } else if (selectable.actor instanceof RewardActor) { + actor = (RewardActor) selectable.actor; + } else { return; } - if(actor.toolTipIsVisible()) - { + if (actor.toolTipIsVisible()) { actor.hideTooltip(); - } - else - { - if(!actor.isFlipped()) + } else { + if (!actor.isFlipped()) actor.showTooltip(); } @@ -128,8 +122,8 @@ public class RewardScene extends UIScene { public void quitScene() { //There were reports of memory leaks after using the shop many times, so remove() everything on exit to be sure. - for(Actor A: new Array.ArrayIterator<>(generated)) { - if(A instanceof RewardActor){ + for (Actor A : new Array.ArrayIterator<>(generated)) { + if (A instanceof RewardActor) { ((RewardActor) A).removeTooltip(); ((RewardActor) A).dispose(); A.remove(); @@ -144,13 +138,16 @@ public class RewardScene extends UIScene { } Forge.switchToLast(); } + public void reactivateInputs() { Gdx.input.setInputProcessor(stage); doneButton.toFront(); } + public boolean done() { return done(false); } + boolean done(boolean skipShowLoot) { GameHUD.getInstance().getTouchpad().setVisible(false); if (!skipShowLoot) { @@ -158,22 +155,23 @@ public class RewardScene extends UIScene { showLootOrDone(); return true; } - if (type != null) { - switch (type) { - case Shop: - doneButton.setText("[+OK]"); - break; - case QuestReward: - case Loot: - doneButton.setText("[+OK]"); - break; - } + if (type != null) { + switch (type) { + case Shop: + doneButton.setText("[+OK]"); + break; + case QuestReward: + case Loot: + doneButton.setText("[+OK]"); + break; + } } shown = false; clearGenerated(); quitScene(); return true; } + void clearGenerated() { for (Actor actor : new Array.ArrayIterator<>(generated)) { if (!(actor instanceof RewardActor)) { @@ -187,7 +185,8 @@ public class RewardScene extends UIScene { reward.clearHoldToolTip(); try { stage.getActors().removeValue(reward, true); - } catch (Exception e) {} + } catch (Exception e) { + } } } @@ -252,7 +251,7 @@ public class RewardScene extends UIScene { } } - void updateRestockButton(){ + void updateRestockButton() { if (!shopActor.canRestock()) return; int price = shopActor.getRestockPrice(); @@ -260,11 +259,11 @@ public class RewardScene extends UIScene { restockButton.setDisabled(WorldSave.getCurrentSave().getPlayer().getShards() < price); } - void restockShop(){ + void restockShop() { if (!shopActor.canRestock()) return; int price = shopActor.getRestockPrice(); - if(changes!=null) + if (changes != null) changes.generateNewShopSeed(shopActor.getObjectId()); Current.player().takeShards(price); @@ -273,7 +272,7 @@ public class RewardScene extends UIScene { SoundSystem.instance.play(SoundEffectType.Shuffle, false); updateBuyButtons(); - if(changes==null) + if (changes == null) return; clearGenerated(); @@ -287,28 +286,36 @@ public class RewardScene extends UIScene { ret.addAll(rdata.generate(false, false)); } shopActor.setRewardData(ret); - loadRewards(ret, RewardScene.Type.Shop,shopActor); + loadRewards(ret, RewardScene.Type.Shop, shopActor); } - public void loadRewards(Deck deck, Type type, ShopActor shopActor, boolean noSell){ + public void loadRewards(Deck deck, Type type, ShopActor shopActor, boolean noSell) { Array rewards = new Array<>(); - for (PaperCard card : deck.getAllCardsInASinglePool().toFlatList()){ + for (PaperCard card : deck.getAllCardsInASinglePool().toFlatList()) { rewards.add(new Reward(card, noSell)); } loadRewards(rewards, type, shopActor); } + void updateCollectionPool() { + if (Type.Shop != this.type) + return; + if (this.collectionPool == null) + this.collectionPool = new ItemPool<>(PaperCard.class); + else + this.collectionPool.clear(); + + this.collectionPool.addAllFlat(AdventurePlayer.current().getCollectionCards(true).toFlatList()); + } + public void loadRewards(Array newRewards, Type type, ShopActor shopActor) { clearSelectable(); - this.type = type; + this.type = type; doneClicked = false; - if (type==Type.Shop) { + updateCollectionPool(); + if (type == Type.Shop) { this.shopActor = shopActor; this.changes = shopActor.getMapStage().getChanges(); - if (this.collectionPool == null) { - this.collectionPool = new ItemPool<>(PaperCard.class); - this.collectionPool.addAllFlat(AdventurePlayer.current().getCollectionCards(true).toFlatList()); - } } for (Actor actor : new Array.ArrayIterator<>(generated)) { actor.remove(); @@ -319,25 +326,23 @@ public class RewardScene extends UIScene { generated.clear(); Actor card = ui.findActor("cards"); - if(type==Type.Shop) { + if (type == Type.Shop) { String shopName = shopActor.getDescription(); if (shopName != null && !shopName.isEmpty()) { shopNameLabel.setVisible(true); shopNameLabel.setText("[%?SHINY]{GRADIENT}" + shopName + "{ENDGRADIENT}"); shopNameLabel.skipToTheEnd(); - } - else - { + } else { shopNameLabel.setVisible(false); } Actor background = ui.findActor("market_background"); - if(background!=null) + if (background != null) background.setVisible(true); } else { shopNameLabel.setVisible(false); shopNameLabel.setText(""); Actor background = ui.findActor("market_background"); - if(background!=null) + if (background != null) background.setVisible(false); } @@ -367,8 +372,7 @@ public class RewardScene extends UIScene { if (shopActor.canRestock()) { restockButton.setVisible(true); - } - else{ + } else { restockButton.setVisible(false); restockButton.setDisabled(true); } @@ -399,22 +403,22 @@ public class RewardScene extends UIScene { bestCardHeight = h; } } - float AR = 480f/270f; + float AR = 480f / 270f; int x = Forge.getDeviceAdapter().getRealScreenSize(false).getLeft(); int y = Forge.getDeviceAdapter().getRealScreenSize(false).getRight(); int realX = Forge.getDeviceAdapter().getRealScreenSize(true).getLeft(); int realY = Forge.getDeviceAdapter().getRealScreenSize(true).getRight(); float fW = Math.max(x, y); float fH = Math.min(x, y); - float mul = fW/fH < AR ? AR/(fW/fH) : (fW/fH)/AR; - if (fW/fH >= 2f) {//tall display - mul = (fW/fH) - ((fW/fH)/AR); - if ((fW/fH) >= 2.1f && (fW/fH) < 2.2f) + float mul = fW / fH < AR ? AR / (fW / fH) : (fW / fH) / AR; + if (fW / fH >= 2f) {//tall display + mul = (fW / fH) - ((fW / fH) / AR); + if ((fW / fH) >= 2.1f && (fW / fH) < 2.2f) mul *= 0.9f; - else if ((fW/fH) > 2.2f) //ultrawide 21:9 Galaxy Fold, Huawei X2, Xperia 1 + else if ((fW / fH) > 2.2f) //ultrawide 21:9 Galaxy Fold, Huawei X2, Xperia 1 mul *= 0.8f; } - cardHeight = bestCardHeight * 0.90f ; + cardHeight = bestCardHeight * 0.90f; Float custom = Forge.isLandscapeMode() ? Config.instance().getSettingData().rewardCardAdjLandscape : Config.instance().getSettingData().rewardCardAdj; if (custom != null && custom != 1f) { mul *= custom; @@ -423,16 +427,16 @@ public class RewardScene extends UIScene { mul *= Forge.isLandscapeMode() ? 0.95f : 1.05f; } else { //immersive | no navigation and/or showing cutout cam - if (fW/fH > 2.2f) + if (fW / fH > 2.2f) mul *= Forge.isLandscapeMode() ? 1.1f : 1.6f; - else if (fW/fH >= 2.1f) + else if (fW / fH >= 2.1f) mul *= Forge.isLandscapeMode() ? 1.05f : 1.5f; - else if (fW/fH >= 2f) + else if (fW / fH >= 2f) mul *= Forge.isLandscapeMode() ? 1f : 1.4f; } } - cardWidth = (cardHeight / CARD_WIDTH_TO_HEIGHT)*mul; + cardWidth = (cardHeight / CARD_WIDTH_TO_HEIGHT) * mul; yOff += (targetHeight - (cardHeight * numberOfRows)) / 2f; xOff += (targetWidth - (cardWidth * numberOfColumns)) / 2f; @@ -456,7 +460,7 @@ public class RewardScene extends UIScene { lastRowXAdjust = ((numberOfColumns * cardWidth) - (lastRowCount * cardWidth)) / 2; } - RewardActor actor = new RewardActor(reward, type == Type.Loot || type == Type.QuestReward,type); + RewardActor actor = new RewardActor(reward, type == Type.Loot || type == Type.QuestReward, type); actor.setBounds(lastRowXAdjust + xOff + cardWidth * (i % numberOfColumns) + spacing, yOff + cardHeight * currentRow + spacing, cardWidth - spacing * 2, cardHeight - spacing * 2); @@ -464,21 +468,12 @@ public class RewardScene extends UIScene { if (currentRow != ((i + 1) / numberOfColumns)) yOff += doneButton.getHeight(); - BuyButton buyCardButton = new BuyButton(shopActor.getObjectId(), i, actor, doneButton, shopActor.getPriceModifier()); + BuyButton buyCardButton = new BuyButton(shopActor.getObjectId(), i, actor, reward, doneButton, shopActor.getPriceModifier()); generated.add(buyCardButton); if (!skipCard) { stage.addActor(buyCardButton); addToSelectable(buyCardButton); } - if (this.collectionPool != null && Reward.Type.Card.equals(reward.getType())) { - int count = collectionPool.count(reward.getCard()); - String text = buyCardButton.getTextraLabel().storedText; - buyCardButton.setText("[%75]" + text + "\n" + Forge.getLocalizer().getMessage("lblOwned") + ": " + count); - } else if (Reward.Type.Item.equals(reward.getType())) { - int count = AdventurePlayer.current().countItem(reward.getItem().name); - String text = buyCardButton.getTextraLabel().storedText; - buyCardButton.setText("[%75]" + text + "\n" + Forge.getLocalizer().getMessage("lblOwned") + ": " + count); - } } else { addToSelectable(actor); } @@ -502,21 +497,37 @@ public class RewardScene extends UIScene { } } } + private class BuyButton extends TextraButton { private final int objectID; private final int index; - public RewardActor reward; + public RewardActor rewardActor; + private Reward reward; int price; void update() { setDisabled(WorldSave.getCurrentSave().getPlayer().getGold() < price); + updateOwned(); } - public BuyButton(int id, int i, RewardActor actor, TextraButton style, float shopModifier) { - super("", style.getStyle(),Controls.getTextraFont()); + void updateOwned() { + if (Type.Shop != type) + return; + if (collectionPool != null && Reward.Type.Card.equals(reward.getType())) { + int count = collectionPool.count(reward.getCard()); + setText("[%75]" + price + " [+Gold]\n" + Forge.getLocalizer().getMessage("lblOwned") + ": " + count); + } else if (Reward.Type.Item.equals(reward.getType())) { + int count = AdventurePlayer.current().countItem(reward.getItem().name); + setText("[%75]" + price + " [+Gold]\n" + Forge.getLocalizer().getMessage("lblOwned") + ": " + count); + } + } + + public BuyButton(int id, int i, RewardActor actor, Reward reward, TextraButton style, float shopModifier) { + super("", style.getStyle(), Controls.getTextraFont()); this.objectID = id; this.index = i; - reward = actor; + rewardActor = actor; + this.reward = reward; setHeight(style.getHeight()); setWidth(actor.getWidth()); setX(actor.getX()); @@ -524,29 +535,31 @@ public class RewardScene extends UIScene { price = CardUtil.getRewardPrice(actor.getReward()); price *= Current.player().goldModifier(); price *= shopModifier; - setText(price+" [+Gold]"); + setText(price + " [+Gold]"); + updateOwned(); addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { - if (Current.player().getGold() >= price) { - if(!shopActor.isUnlimited()) - changes.buyCard(objectID, index); + if (Current.player().getGold() >= price) { + if (!shopActor.isUnlimited()) + changes.buyCard(objectID, index); - Current.player().takeGold(price); - Current.player().addReward(reward.getReward()); + Current.player().takeGold(price); + Current.player().addReward(rewardActor.getReward()); - Gdx.input.vibrate(5); - SoundSystem.instance.play(SoundEffectType.FlipCoin, false); + Gdx.input.vibrate(5); + SoundSystem.instance.play(SoundEffectType.FlipCoin, false); - updateBuyButtons(); - if(changes==null) - return; - setDisabled(true); - reward.sold(); - getColor().a = 0.5f; - setText("SOLD"); - removeListener(this); - } + if (changes == null) + return; + setDisabled(true); + rewardActor.sold(); + getColor().a = 0.5f; + updateCollectionPool(); + updateBuyButtons(); + setText("SOLD"); + removeListener(this); + } } }); }