mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 11:48:02 +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.world.WorldSave;
|
||||
import forge.assets.ImageCache;
|
||||
import forge.gui.GuiBase;
|
||||
|
||||
/**
|
||||
* Displays the rewards of a fight or a treasure
|
||||
*/
|
||||
public class RewardScene extends UIScene {
|
||||
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");
|
||||
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(GuiBase.isAndroid() ? "ui/items_mobile.json" : "ui/items.json");
|
||||
}
|
||||
|
||||
boolean doneClicked=false;
|
||||
float flipCountDown=1.0f;
|
||||
public boolean done()
|
||||
{
|
||||
boolean doneClicked = false;
|
||||
float flipCountDown = 1.0f;
|
||||
|
||||
public boolean done() {
|
||||
GameHUD.getInstance().getTouchpad().setVisible(false);
|
||||
if(doneClicked)
|
||||
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))
|
||||
{
|
||||
boolean wait = false;
|
||||
for (Actor actor : new Array.ArrayIterator<>(generated)) {
|
||||
if (!(actor instanceof RewardActor)) {
|
||||
continue;
|
||||
}
|
||||
RewardActor reward=(RewardActor) actor;
|
||||
RewardActor reward = (RewardActor) actor;
|
||||
AdventurePlayer.current().addReward(reward.getReward());
|
||||
if(!reward.isFlipped())
|
||||
{
|
||||
if (!reward.isFlipped()) {
|
||||
wait = true;
|
||||
reward.flip();
|
||||
}
|
||||
}
|
||||
if(wait)
|
||||
{
|
||||
flipCountDown=3.0f;
|
||||
doneClicked=true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (wait) {
|
||||
flipCountDown = 3.0f;
|
||||
doneClicked = true;
|
||||
} else {
|
||||
Forge.switchToLast();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
Forge.switchToLast();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void act(float delta) {
|
||||
|
||||
stage.act(delta);
|
||||
ImageCache.allowSingleLoad();
|
||||
if(doneClicked)
|
||||
{
|
||||
if(type==Type.Loot)
|
||||
flipCountDown-=Gdx.graphics.getDeltaTime();
|
||||
if(flipCountDown<=0)
|
||||
{
|
||||
if (doneClicked) {
|
||||
if (type == Type.Loot)
|
||||
flipCountDown -= Gdx.graphics.getDeltaTime();
|
||||
if (flipCountDown <= 0) {
|
||||
Forge.switchToLast();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resLoaded() {
|
||||
super.resLoaded();
|
||||
@@ -108,56 +99,49 @@ public class RewardScene extends UIScene {
|
||||
RewardScene.this.done();
|
||||
}
|
||||
});
|
||||
doneButton=ui.findActor("done");
|
||||
doneButton = ui.findActor("done");
|
||||
}
|
||||
|
||||
@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)
|
||||
{
|
||||
this.type=type;
|
||||
doneClicked=false;
|
||||
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)
|
||||
{
|
||||
((RewardActor)actor).dispose();
|
||||
if (actor instanceof RewardActor) {
|
||||
((RewardActor) actor).dispose();
|
||||
}
|
||||
}
|
||||
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 xOff = card.getX();
|
||||
float xOff = card.getX();
|
||||
float yOff = card.getY();
|
||||
|
||||
int numberOfRows=0;
|
||||
float cardWidth=0;
|
||||
float cardHeight=0;
|
||||
float bestCardHeight=0;
|
||||
int numberOfColumns=0;
|
||||
float targetArea=targetHeight*targetWidth;
|
||||
float oldCardArea=0;
|
||||
float newArea=0;
|
||||
int numberOfRows = 0;
|
||||
float cardWidth = 0;
|
||||
float cardHeight = 0;
|
||||
float bestCardHeight = 0;
|
||||
int numberOfColumns = 0;
|
||||
float targetArea = targetHeight * targetWidth;
|
||||
float oldCardArea = 0;
|
||||
float newArea = 0;
|
||||
|
||||
switch (type) {
|
||||
case Shop:
|
||||
@@ -167,89 +151,74 @@ public class RewardScene extends UIScene {
|
||||
doneButton.setText("Take all");
|
||||
break;
|
||||
}
|
||||
for(int h=1;h<targetHeight;h++)
|
||||
{
|
||||
cardHeight=h;
|
||||
if(type==Type.Shop)
|
||||
{
|
||||
cardHeight+=doneButton.getHeight();
|
||||
for (int h = 1; h < targetHeight; h++) {
|
||||
cardHeight = h;
|
||||
if (type == Type.Shop) {
|
||||
cardHeight += doneButton.getHeight();
|
||||
}
|
||||
//cardHeight=targetHeight/i;
|
||||
cardWidth=h/ CARD_WIDTH_TO_HEIGHT;
|
||||
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)
|
||||
{
|
||||
oldCardArea=newArea;
|
||||
numberOfRows= rows;
|
||||
numberOfColumns =cols;
|
||||
bestCardHeight=h;
|
||||
cardWidth = h / CARD_WIDTH_TO_HEIGHT;
|
||||
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) {
|
||||
oldCardArea = newArea;
|
||||
numberOfRows = rows;
|
||||
numberOfColumns = cols;
|
||||
bestCardHeight = h;
|
||||
}
|
||||
}
|
||||
|
||||
cardHeight=bestCardHeight;
|
||||
cardWidth=bestCardHeight/ CARD_WIDTH_TO_HEIGHT;
|
||||
cardHeight = bestCardHeight;
|
||||
cardWidth = bestCardHeight / CARD_WIDTH_TO_HEIGHT;
|
||||
|
||||
yOff+=(targetHeight-(cardHeight*numberOfRows))/2f;
|
||||
xOff+=(targetWidth-(cardWidth*numberOfColumns))/2f;
|
||||
float spacing=2;
|
||||
int i=0;
|
||||
for(Reward reward:new Array.ArrayIterator<>(newRewards))
|
||||
{
|
||||
boolean skipCard=false;
|
||||
if(type==Type.Shop)
|
||||
{
|
||||
if(shopActor.getMapStage().getChanges().wasCardBought(shopActor.getObjectID(),i))
|
||||
{
|
||||
skipCard=true;
|
||||
yOff += (targetHeight - (cardHeight * numberOfRows)) / 2f;
|
||||
xOff += (targetWidth - (cardWidth * numberOfColumns)) / 2f;
|
||||
float spacing = 2;
|
||||
int i = 0;
|
||||
for (Reward reward : new Array.ArrayIterator<>(newRewards)) {
|
||||
boolean skipCard = false;
|
||||
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)
|
||||
{
|
||||
int lastRowCount=newRewards.size%numberOfColumns;
|
||||
if(lastRowCount!=0)
|
||||
lastRowXAdjust=((numberOfColumns*cardWidth)-(lastRowCount*cardWidth))/2;
|
||||
int currentRow = (i / numberOfColumns);
|
||||
float lastRowXAdjust = 0;
|
||||
if (currentRow == numberOfRows - 1) {
|
||||
int lastRowCount = newRewards.size % numberOfColumns;
|
||||
if (lastRowCount != 0)
|
||||
lastRowXAdjust = ((numberOfColumns * cardWidth) - (lastRowCount * cardWidth)) / 2;
|
||||
}
|
||||
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);
|
||||
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(currentRow!=((i+1)/numberOfColumns))
|
||||
yOff+=doneButton.getHeight();
|
||||
if (type == Type.Shop) {
|
||||
if (currentRow != ((i + 1) / numberOfColumns))
|
||||
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);
|
||||
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)
|
||||
{
|
||||
((BuyButton)actor).update();
|
||||
for (Actor actor : new Array.ArrayIterator<>(generated)) {
|
||||
if (actor instanceof BuyButton) {
|
||||
((BuyButton) actor).update();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -260,28 +229,28 @@ public class RewardScene extends UIScene {
|
||||
private final PointOfInterestChanges changes;
|
||||
RewardActor reward;
|
||||
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) {
|
||||
super("",style.getStyle());
|
||||
super("", style.getStyle());
|
||||
this.objectID = id;
|
||||
this.index = i;
|
||||
this.changes = ch;
|
||||
reward=actor;
|
||||
reward = actor;
|
||||
setHeight(style.getHeight());
|
||||
setWidth(actor.getWidth());
|
||||
setX(actor.getX());
|
||||
setY(actor.getY()-getHeight());
|
||||
price= CardUtil.getCardPrice(actor.getReward().getCard());
|
||||
setText("Buy for "+price);
|
||||
addListener(new ClickListener(){
|
||||
|
||||
setY(actor.getY() - getHeight());
|
||||
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)
|
||||
{
|
||||
changes.buyCard(objectID,index);
|
||||
public void clicked(InputEvent event, float x, float y) {
|
||||
if (Current.player().getGold() >= price) {
|
||||
changes.buyCard(objectID, index);
|
||||
Current.player().takeGold(price);
|
||||
Current.player().addReward(reward.getReward());
|
||||
setDisabled(true);
|
||||
@@ -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