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,87 +18,78 @@ import forge.adventure.util.Reward;
|
|||||||
import forge.adventure.util.RewardActor;
|
import forge.adventure.util.RewardActor;
|
||||||
import forge.adventure.world.WorldSave;
|
import forge.adventure.world.WorldSave;
|
||||||
import forge.assets.ImageCache;
|
import forge.assets.ImageCache;
|
||||||
|
import forge.gui.GuiBase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Displays the rewards of a fight or a treasure
|
* Displays the rewards of a fight or a treasure
|
||||||
*/
|
*/
|
||||||
public class RewardScene extends UIScene {
|
public class RewardScene extends UIScene {
|
||||||
|
|
||||||
private TextButton doneButton;
|
private TextButton doneButton;
|
||||||
|
|
||||||
public enum Type
|
public enum Type {
|
||||||
{
|
|
||||||
Shop,
|
Shop,
|
||||||
Loot
|
Loot
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Type type;
|
Type type;
|
||||||
Array<Actor> generated =new Array<>();
|
Array<Actor> 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_HEIGHT = 400f;
|
||||||
static public final float CARD_WIDTH_TO_HEIGHT =CARD_WIDTH/CARD_HEIGHT;
|
static public final float CARD_WIDTH_TO_HEIGHT = CARD_WIDTH / CARD_HEIGHT;
|
||||||
public RewardScene()
|
|
||||||
{
|
public RewardScene() {
|
||||||
super("ui/items.json");
|
super(GuiBase.isAndroid() ? "ui/items_mobile.json" : "ui/items.json");
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean doneClicked=false;
|
boolean doneClicked = false;
|
||||||
float flipCountDown=1.0f;
|
float flipCountDown = 1.0f;
|
||||||
public boolean done()
|
|
||||||
{
|
public boolean done() {
|
||||||
GameHUD.getInstance().getTouchpad().setVisible(false);
|
GameHUD.getInstance().getTouchpad().setVisible(false);
|
||||||
if(doneClicked)
|
if (doneClicked)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if(type==Type.Loot)
|
if (type == Type.Loot) {
|
||||||
{
|
|
||||||
|
|
||||||
boolean wait=false;
|
boolean wait = false;
|
||||||
for(Actor actor: new Array.ArrayIterator<>(generated))
|
for (Actor actor : new Array.ArrayIterator<>(generated)) {
|
||||||
{
|
if (!(actor instanceof RewardActor)) {
|
||||||
if(!(actor instanceof RewardActor))
|
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
RewardActor reward=(RewardActor) actor;
|
RewardActor reward = (RewardActor) actor;
|
||||||
AdventurePlayer.current().addReward(reward.getReward());
|
AdventurePlayer.current().addReward(reward.getReward());
|
||||||
if(!reward.isFlipped())
|
if (!reward.isFlipped()) {
|
||||||
{
|
|
||||||
wait = true;
|
wait = true;
|
||||||
reward.flip();
|
reward.flip();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(wait)
|
if (wait) {
|
||||||
{
|
flipCountDown = 3.0f;
|
||||||
flipCountDown=3.0f;
|
doneClicked = true;
|
||||||
doneClicked=true;
|
} else {
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Forge.switchToLast();
|
Forge.switchToLast();
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
Forge.switchToLast();
|
Forge.switchToLast();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void act(float delta) {
|
public void act(float delta) {
|
||||||
|
|
||||||
stage.act(delta);
|
stage.act(delta);
|
||||||
ImageCache.allowSingleLoad();
|
ImageCache.allowSingleLoad();
|
||||||
if(doneClicked)
|
if (doneClicked) {
|
||||||
{
|
if (type == Type.Loot)
|
||||||
if(type==Type.Loot)
|
flipCountDown -= Gdx.graphics.getDeltaTime();
|
||||||
flipCountDown-=Gdx.graphics.getDeltaTime();
|
if (flipCountDown <= 0) {
|
||||||
if(flipCountDown<=0)
|
|
||||||
{
|
|
||||||
Forge.switchToLast();
|
Forge.switchToLast();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void resLoaded() {
|
public void resLoaded() {
|
||||||
super.resLoaded();
|
super.resLoaded();
|
||||||
@@ -108,56 +99,49 @@ public class RewardScene extends UIScene {
|
|||||||
RewardScene.this.done();
|
RewardScene.this.done();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
doneButton=ui.findActor("done");
|
doneButton = ui.findActor("done");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean keyPressed(int keycode)
|
public boolean keyPressed(int keycode) {
|
||||||
{
|
if (keycode == Input.Keys.ESCAPE) {
|
||||||
if (keycode == Input.Keys.ESCAPE)
|
|
||||||
{
|
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
return true;
|
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;
|
||||||
this.type=type;
|
doneClicked = false;
|
||||||
doneClicked=false;
|
|
||||||
|
|
||||||
|
|
||||||
|
for (Actor actor : new Array.ArrayIterator<>(generated)) {
|
||||||
|
|
||||||
for(Actor actor: new Array.ArrayIterator<>(generated))
|
|
||||||
{
|
|
||||||
actor.remove();
|
actor.remove();
|
||||||
if(actor instanceof RewardActor)
|
if (actor instanceof RewardActor) {
|
||||||
{
|
((RewardActor) actor).dispose();
|
||||||
((RewardActor)actor).dispose();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
generated.clear();
|
generated.clear();
|
||||||
|
|
||||||
|
|
||||||
Actor card=ui.findActor("cards");
|
Actor card = ui.findActor("cards");
|
||||||
|
|
||||||
// card.setDrawable(new TextureRegionDrawable(new Texture(Res.CurrentRes.GetFile("ui/transition.png"))));
|
// card.setDrawable(new TextureRegionDrawable(new Texture(Res.CurrentRes.GetFile("ui/transition.png"))));
|
||||||
|
|
||||||
float targetWidth = card.getWidth();
|
float targetWidth = card.getWidth();
|
||||||
float targetHeight = card.getHeight();
|
float targetHeight = card.getHeight();
|
||||||
float xOff = card.getX();
|
float xOff = card.getX();
|
||||||
float yOff = card.getY();
|
float yOff = card.getY();
|
||||||
|
|
||||||
int numberOfRows=0;
|
int numberOfRows = 0;
|
||||||
float cardWidth=0;
|
float cardWidth = 0;
|
||||||
float cardHeight=0;
|
float cardHeight = 0;
|
||||||
float bestCardHeight=0;
|
float bestCardHeight = 0;
|
||||||
int numberOfColumns=0;
|
int numberOfColumns = 0;
|
||||||
float targetArea=targetHeight*targetWidth;
|
float targetArea = targetHeight * targetWidth;
|
||||||
float oldCardArea=0;
|
float oldCardArea = 0;
|
||||||
float newArea=0;
|
float newArea = 0;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case Shop:
|
case Shop:
|
||||||
@@ -167,89 +151,74 @@ public class RewardScene extends UIScene {
|
|||||||
doneButton.setText("Take all");
|
doneButton.setText("Take all");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
for(int h=1;h<targetHeight;h++)
|
for (int h = 1; h < targetHeight; h++) {
|
||||||
{
|
cardHeight = h;
|
||||||
cardHeight=h;
|
if (type == Type.Shop) {
|
||||||
if(type==Type.Shop)
|
cardHeight += doneButton.getHeight();
|
||||||
{
|
|
||||||
cardHeight+=doneButton.getHeight();
|
|
||||||
}
|
}
|
||||||
//cardHeight=targetHeight/i;
|
//cardHeight=targetHeight/i;
|
||||||
cardWidth=h/ CARD_WIDTH_TO_HEIGHT;
|
cardWidth = h / CARD_WIDTH_TO_HEIGHT;
|
||||||
newArea=newRewards.size*cardWidth*cardHeight;
|
newArea = newRewards.size * cardWidth * cardHeight;
|
||||||
int rows=(int) (targetHeight/cardHeight);
|
int rows = (int) (targetHeight / cardHeight);
|
||||||
int cols =(int)Math.ceil(newRewards.size/(double)rows);
|
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;
|
||||||
oldCardArea=newArea;
|
numberOfRows = rows;
|
||||||
numberOfRows= rows;
|
numberOfColumns = cols;
|
||||||
numberOfColumns =cols;
|
bestCardHeight = h;
|
||||||
bestCardHeight=h;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cardHeight=bestCardHeight;
|
cardHeight = bestCardHeight;
|
||||||
cardWidth=bestCardHeight/ CARD_WIDTH_TO_HEIGHT;
|
cardWidth = bestCardHeight / CARD_WIDTH_TO_HEIGHT;
|
||||||
|
|
||||||
yOff+=(targetHeight-(cardHeight*numberOfRows))/2f;
|
yOff += (targetHeight - (cardHeight * numberOfRows)) / 2f;
|
||||||
xOff+=(targetWidth-(cardWidth*numberOfColumns))/2f;
|
xOff += (targetWidth - (cardWidth * numberOfColumns)) / 2f;
|
||||||
float spacing=2;
|
float spacing = 2;
|
||||||
int i=0;
|
int i = 0;
|
||||||
for(Reward reward:new Array.ArrayIterator<>(newRewards))
|
for (Reward reward : new Array.ArrayIterator<>(newRewards)) {
|
||||||
{
|
boolean skipCard = false;
|
||||||
boolean skipCard=false;
|
if (type == Type.Shop) {
|
||||||
if(type==Type.Shop)
|
if (shopActor.getMapStage().getChanges().wasCardBought(shopActor.getObjectID(), i)) {
|
||||||
{
|
skipCard = true;
|
||||||
if(shopActor.getMapStage().getChanges().wasCardBought(shopActor.getObjectID(),i))
|
|
||||||
{
|
|
||||||
skipCard=true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int currentRow = (i / numberOfColumns);
|
||||||
int currentRow=(i/numberOfColumns);
|
float lastRowXAdjust = 0;
|
||||||
float lastRowXAdjust=0;
|
if (currentRow == numberOfRows - 1) {
|
||||||
if(currentRow==numberOfRows-1)
|
int lastRowCount = newRewards.size % numberOfColumns;
|
||||||
{
|
if (lastRowCount != 0)
|
||||||
int lastRowCount=newRewards.size%numberOfColumns;
|
lastRowXAdjust = ((numberOfColumns * cardWidth) - (lastRowCount * cardWidth)) / 2;
|
||||||
if(lastRowCount!=0)
|
|
||||||
lastRowXAdjust=((numberOfColumns*cardWidth)-(lastRowCount*cardWidth))/2;
|
|
||||||
}
|
}
|
||||||
RewardActor actor=new RewardActor(reward,type==Type.Loot);
|
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);
|
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))
|
||||||
if(currentRow!=((i+1)/numberOfColumns))
|
yOff += doneButton.getHeight();
|
||||||
yOff+=doneButton.getHeight();
|
|
||||||
|
|
||||||
TextButton buyCardButton=new BuyButton(shopActor.getObjectID(),i,shopActor.getMapStage().getChanges(),actor,doneButton);
|
TextButton buyCardButton = new BuyButton(shopActor.getObjectID(), i, shopActor.getMapStage().getChanges(), actor, doneButton);
|
||||||
|
|
||||||
generated.add(buyCardButton);
|
generated.add(buyCardButton);
|
||||||
if(!skipCard)
|
if (!skipCard) {
|
||||||
{
|
|
||||||
stage.addActor(buyCardButton);
|
stage.addActor(buyCardButton);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
generated.add(actor);
|
generated.add(actor);
|
||||||
if(!skipCard)
|
if (!skipCard) {
|
||||||
{
|
|
||||||
stage.addActor(actor);
|
stage.addActor(actor);
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
updateBuyButtons();
|
updateBuyButtons();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateBuyButtons() {
|
private void updateBuyButtons() {
|
||||||
|
for (Actor actor : new Array.ArrayIterator<>(generated)) {
|
||||||
for(Actor actor: new Array.ArrayIterator<>(generated))
|
if (actor instanceof BuyButton) {
|
||||||
{
|
((BuyButton) actor).update();
|
||||||
if(actor instanceof BuyButton)
|
|
||||||
{
|
|
||||||
((BuyButton)actor).update();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -260,28 +229,28 @@ public class RewardScene extends UIScene {
|
|||||||
private final PointOfInterestChanges changes;
|
private final PointOfInterestChanges changes;
|
||||||
RewardActor reward;
|
RewardActor reward;
|
||||||
int price;
|
int price;
|
||||||
void update(){
|
|
||||||
setDisabled(WorldSave.getCurrentSave().getPlayer().getGold()< price);
|
void update() {
|
||||||
|
setDisabled(WorldSave.getCurrentSave().getPlayer().getGold() < price);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BuyButton(int id, int i, PointOfInterestChanges ch, RewardActor actor, TextButton style) {
|
public BuyButton(int id, int i, PointOfInterestChanges ch, RewardActor actor, TextButton style) {
|
||||||
super("",style.getStyle());
|
super("", style.getStyle());
|
||||||
this.objectID = id;
|
this.objectID = id;
|
||||||
this.index = i;
|
this.index = i;
|
||||||
this.changes = ch;
|
this.changes = ch;
|
||||||
reward=actor;
|
reward = actor;
|
||||||
setHeight(style.getHeight());
|
setHeight(style.getHeight());
|
||||||
setWidth(actor.getWidth());
|
setWidth(actor.getWidth());
|
||||||
setX(actor.getX());
|
setX(actor.getX());
|
||||||
setY(actor.getY()-getHeight());
|
setY(actor.getY() - getHeight());
|
||||||
price= CardUtil.getCardPrice(actor.getReward().getCard());
|
price = CardUtil.getCardPrice(actor.getReward().getCard());
|
||||||
setText("Buy for "+price);
|
setText("Buy for " + price);
|
||||||
addListener(new ClickListener(){
|
addListener(new ClickListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clicked (InputEvent event, float x, float y) {
|
public void clicked(InputEvent event, float x, float y) {
|
||||||
if(Current.player().getGold()>= price)
|
if (Current.player().getGold() >= price) {
|
||||||
{
|
changes.buyCard(objectID, index);
|
||||||
changes.buyCard(objectID,index);
|
|
||||||
Current.player().takeGold(price);
|
Current.player().takeGold(price);
|
||||||
Current.player().addReward(reward.getReward());
|
Current.player().addReward(reward.getReward());
|
||||||
setDisabled(true);
|
setDisabled(true);
|
||||||
@@ -289,7 +258,6 @@ public class RewardScene extends UIScene {
|
|||||||
remove();
|
remove();
|
||||||
updateBuyButtons();
|
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