mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 19:58:00 +00:00
update RewardScene
This commit is contained in:
@@ -18,6 +18,7 @@ import forge.adventure.util.Reward;
|
||||
import forge.adventure.util.RewardActor;
|
||||
import forge.adventure.world.WorldSave;
|
||||
import forge.assets.ImageCache;
|
||||
import forge.gui.GuiBase;
|
||||
|
||||
/**
|
||||
* Displays the rewards of a fight or a treasure
|
||||
@@ -26,79 +27,69 @@ public class RewardScene extends UIScene {
|
||||
|
||||
private TextButton doneButton;
|
||||
|
||||
public enum Type
|
||||
{
|
||||
public enum Type {
|
||||
Shop,
|
||||
Loot
|
||||
|
||||
}
|
||||
|
||||
Type type;
|
||||
Array<Actor> generated = new Array<>();
|
||||
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;
|
||||
public RewardScene()
|
||||
{
|
||||
super("ui/items.json");
|
||||
|
||||
public RewardScene() {
|
||||
super(GuiBase.isAndroid() ? "ui/items_mobile.json" : "ui/items.json");
|
||||
}
|
||||
|
||||
boolean doneClicked = false;
|
||||
float flipCountDown = 1.0f;
|
||||
public boolean done()
|
||||
{
|
||||
|
||||
public boolean done() {
|
||||
GameHUD.getInstance().getTouchpad().setVisible(false);
|
||||
if (doneClicked)
|
||||
return true;
|
||||
|
||||
if(type==Type.Loot)
|
||||
{
|
||||
if (type == Type.Loot) {
|
||||
|
||||
boolean wait = false;
|
||||
for(Actor actor: new Array.ArrayIterator<>(generated))
|
||||
{
|
||||
if(!(actor instanceof RewardActor))
|
||||
{
|
||||
for (Actor actor : new Array.ArrayIterator<>(generated)) {
|
||||
if (!(actor instanceof RewardActor)) {
|
||||
continue;
|
||||
}
|
||||
RewardActor reward = (RewardActor) actor;
|
||||
AdventurePlayer.current().addReward(reward.getReward());
|
||||
if(!reward.isFlipped())
|
||||
{
|
||||
if (!reward.isFlipped()) {
|
||||
wait = true;
|
||||
reward.flip();
|
||||
}
|
||||
}
|
||||
if(wait)
|
||||
{
|
||||
if (wait) {
|
||||
flipCountDown = 3.0f;
|
||||
doneClicked = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
Forge.switchToLast();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
Forge.switchToLast();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void act(float delta) {
|
||||
|
||||
stage.act(delta);
|
||||
ImageCache.allowSingleLoad();
|
||||
if(doneClicked)
|
||||
{
|
||||
if (doneClicked) {
|
||||
if (type == Type.Loot)
|
||||
flipCountDown -= Gdx.graphics.getDeltaTime();
|
||||
if(flipCountDown<=0)
|
||||
{
|
||||
if (flipCountDown <= 0) {
|
||||
Forge.switchToLast();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resLoaded() {
|
||||
super.resLoaded();
|
||||
@@ -112,29 +103,22 @@ public class RewardScene extends UIScene {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyPressed(int keycode)
|
||||
{
|
||||
if (keycode == Input.Keys.ESCAPE)
|
||||
{
|
||||
public boolean keyPressed(int keycode) {
|
||||
if (keycode == Input.Keys.ESCAPE) {
|
||||
done();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public void loadRewards(Array<Reward> newRewards, Type type, ShopActor shopActor)
|
||||
{
|
||||
public void loadRewards(Array<Reward> newRewards, Type type, ShopActor shopActor) {
|
||||
this.type = type;
|
||||
doneClicked = false;
|
||||
|
||||
|
||||
|
||||
|
||||
for(Actor actor: new Array.ArrayIterator<>(generated))
|
||||
{
|
||||
for (Actor actor : new Array.ArrayIterator<>(generated)) {
|
||||
actor.remove();
|
||||
if(actor instanceof RewardActor)
|
||||
{
|
||||
if (actor instanceof RewardActor) {
|
||||
((RewardActor) actor).dispose();
|
||||
}
|
||||
}
|
||||
@@ -167,11 +151,9 @@ public class RewardScene extends UIScene {
|
||||
doneButton.setText("Take all");
|
||||
break;
|
||||
}
|
||||
for(int h=1;h<targetHeight;h++)
|
||||
{
|
||||
for (int h = 1; h < targetHeight; h++) {
|
||||
cardHeight = h;
|
||||
if(type==Type.Shop)
|
||||
{
|
||||
if (type == Type.Shop) {
|
||||
cardHeight += doneButton.getHeight();
|
||||
}
|
||||
//cardHeight=targetHeight/i;
|
||||
@@ -179,8 +161,7 @@ public class RewardScene extends UIScene {
|
||||
newArea = newRewards.size * cardWidth * cardHeight;
|
||||
int rows = (int) (targetHeight / cardHeight);
|
||||
int cols = (int) Math.ceil(newRewards.size / (double) rows);
|
||||
if(newArea>oldCardArea&&newArea<=targetArea&&rows*cardHeight<targetHeight&&cols*cardWidth<targetWidth)
|
||||
{
|
||||
if (newArea > oldCardArea && newArea <= targetArea && rows * cardHeight < targetHeight && cols * cardWidth < targetWidth) {
|
||||
oldCardArea = newArea;
|
||||
numberOfRows = rows;
|
||||
numberOfColumns = cols;
|
||||
@@ -195,23 +176,18 @@ public class RewardScene extends UIScene {
|
||||
xOff += (targetWidth - (cardWidth * numberOfColumns)) / 2f;
|
||||
float spacing = 2;
|
||||
int i = 0;
|
||||
for(Reward reward:new Array.ArrayIterator<>(newRewards))
|
||||
{
|
||||
for (Reward reward : new Array.ArrayIterator<>(newRewards)) {
|
||||
boolean skipCard = false;
|
||||
if(type==Type.Shop)
|
||||
{
|
||||
if(shopActor.getMapStage().getChanges().wasCardBought(shopActor.getObjectID(),i))
|
||||
{
|
||||
if (type == Type.Shop) {
|
||||
if (shopActor.getMapStage().getChanges().wasCardBought(shopActor.getObjectID(), i)) {
|
||||
skipCard = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int currentRow = (i / numberOfColumns);
|
||||
float lastRowXAdjust = 0;
|
||||
if(currentRow==numberOfRows-1)
|
||||
{
|
||||
if (currentRow == numberOfRows - 1) {
|
||||
int lastRowCount = newRewards.size % numberOfColumns;
|
||||
if (lastRowCount != 0)
|
||||
lastRowXAdjust = ((numberOfColumns * cardWidth) - (lastRowCount * cardWidth)) / 2;
|
||||
@@ -219,36 +195,29 @@ public class RewardScene extends UIScene {
|
||||
RewardActor actor = new RewardActor(reward, type == Type.Loot);
|
||||
actor.setBounds(lastRowXAdjust + xOff + cardWidth * (i % numberOfColumns) + spacing, yOff + cardHeight * currentRow + spacing, cardWidth - spacing * 2, cardHeight - spacing * 2);
|
||||
|
||||
if(type==Type.Shop)
|
||||
{
|
||||
if (type == Type.Shop) {
|
||||
if (currentRow != ((i + 1) / numberOfColumns))
|
||||
yOff += doneButton.getHeight();
|
||||
|
||||
TextButton buyCardButton = new BuyButton(shopActor.getObjectID(), i, shopActor.getMapStage().getChanges(), actor, doneButton);
|
||||
|
||||
generated.add(buyCardButton);
|
||||
if(!skipCard)
|
||||
{
|
||||
if (!skipCard) {
|
||||
stage.addActor(buyCardButton);
|
||||
}
|
||||
}
|
||||
generated.add(actor);
|
||||
if(!skipCard)
|
||||
{
|
||||
if (!skipCard) {
|
||||
stage.addActor(actor);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
updateBuyButtons();
|
||||
|
||||
}
|
||||
|
||||
private void updateBuyButtons() {
|
||||
|
||||
for(Actor actor: new Array.ArrayIterator<>(generated))
|
||||
{
|
||||
if(actor instanceof BuyButton)
|
||||
{
|
||||
for (Actor actor : new Array.ArrayIterator<>(generated)) {
|
||||
if (actor instanceof BuyButton) {
|
||||
((BuyButton) actor).update();
|
||||
}
|
||||
}
|
||||
@@ -260,9 +229,11 @@ public class RewardScene extends UIScene {
|
||||
private final PointOfInterestChanges changes;
|
||||
RewardActor reward;
|
||||
int price;
|
||||
|
||||
void update() {
|
||||
setDisabled(WorldSave.getCurrentSave().getPlayer().getGold() < price);
|
||||
}
|
||||
|
||||
public BuyButton(int id, int i, PointOfInterestChanges ch, RewardActor actor, TextButton style) {
|
||||
super("", style.getStyle());
|
||||
this.objectID = id;
|
||||
@@ -276,11 +247,9 @@ public class RewardScene extends UIScene {
|
||||
price = CardUtil.getCardPrice(actor.getReward().getCard());
|
||||
setText("Buy for " + price);
|
||||
addListener(new ClickListener() {
|
||||
|
||||
@Override
|
||||
public void clicked(InputEvent event, float x, float y) {
|
||||
if(Current.player().getGold()>= price)
|
||||
{
|
||||
if (Current.player().getGold() >= price) {
|
||||
changes.buyCard(objectID, index);
|
||||
Current.player().takeGold(price);
|
||||
Current.player().addReward(reward.getReward());
|
||||
@@ -289,7 +258,6 @@ public class RewardScene extends UIScene {
|
||||
remove();
|
||||
updateBuyButtons();
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
29
forge-gui/res/adventure/Shandalar/ui/items_mobile.json
Normal file
29
forge-gui/res/adventure/Shandalar/ui/items_mobile.json
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"width": 480,
|
||||
"height": 270,
|
||||
"yDown": true,
|
||||
"elements": [
|
||||
{
|
||||
"type": "Image",
|
||||
"name": "lastScreen",
|
||||
"width": 480,
|
||||
"height": 270
|
||||
},
|
||||
{
|
||||
"name": "cards",
|
||||
"x": 5,
|
||||
"y": 5,
|
||||
"width": 405,
|
||||
"height": 265
|
||||
},
|
||||
{
|
||||
"type": "TextButton",
|
||||
"name": "done",
|
||||
"text": "Take all",
|
||||
"width": 48,
|
||||
"height": 30,
|
||||
"x": 420,
|
||||
"y": 120
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user