[Mobile] update Adventure inventory

This commit is contained in:
Anthony Calosa
2022-04-03 10:27:09 +08:00
parent e4487de90f
commit a7d3d83287
7 changed files with 82 additions and 30 deletions

View File

@@ -73,7 +73,7 @@ public class InventoryScene extends UIScene {
equipButton = ui.findActor("equip");
deleteButton = ui.findActor("delete");
itemDescription = ui.findActor("item_description");
leave.getLabel().setText(Forge.getLocalizer().getMessage("lblLeave"));
leave.getLabel().setText(Forge.getLocalizer().getMessage("lblBack"));
inventoryButtons=new Array<>();
equipmentSlots=new HashMap<>();
@@ -132,7 +132,7 @@ public class InventoryScene extends UIScene {
columns-=1;
if(columns<=0)columns=1;
scrollPane.setActor(inventory);
confirm = new Dialog("\n Delete item", Controls.GetSkin())
confirm = new Dialog("\n "+Forge.getLocalizer().getMessage("lblDelete"), Controls.GetSkin())
{
protected void result(Object object)
{
@@ -142,11 +142,26 @@ public class InventoryScene extends UIScene {
};
};
confirm.button("Yes", true);
confirm.button("No", false);
confirm.button(Forge.getLocalizer().getMessage("lblYes"), true);
confirm.button(Forge.getLocalizer().getMessage("lblNo"), false);
ui.addActor(confirm);
confirm.hide();
itemDescription.setWrap(true);
//makes confirm dialog hidden immediately when you open inventory first time..
confirm.getColor().a = 0;
float bw = scrollPane.getWidth() / 3;
deleteButton.setX(scrollPane.getX());
deleteButton.setWidth(bw);
equipButton.setX(scrollPane.getX()+bw);
equipButton.setWidth(bw);
leave.setX(equipButton.getX()+bw);
leave.setWidth(bw);
if (!Forge.isLandscapeMode()) {
confirm.getTitleLabel().setFontScaleX(2);
itemDescription.setFontScaleX(2);
}
this.init = true;
}

View File

@@ -160,6 +160,13 @@ public class RewardScene extends UIScene {
case Shop:
doneButton.setText(Forge.getLocalizer().getMessage("lblLeave"));
goldLabel.setText("Gold:"+Current.player().getGold());
float w = 480 - (goldLabel.getPrefWidth() + 10);
goldLabel.setPosition(w, 250);
if (!Forge.isLandscapeMode()) {
goldLabel.setFontScaleX(2);
w = 480/2 - goldLabel.getPrefWidth();
goldLabel.setPosition(w, 250);
}
break;
case Loot:
goldLabel.setText("");
@@ -185,7 +192,7 @@ public class RewardScene extends UIScene {
}
}
cardHeight = Forge.isLandscapeMode() ? bestCardHeight : bestCardHeight * 0.65f;
cardHeight = Forge.isLandscapeMode() ? bestCardHeight * 0.90f : bestCardHeight * 0.65f;
cardWidth = bestCardHeight / CARD_WIDTH_TO_HEIGHT;
yOff += (targetHeight - (cardHeight * numberOfRows)) / 2f;

View File

@@ -45,6 +45,7 @@ public class GameHUD extends Stage {
private boolean deckPressed = false;
private boolean menuPressed = false;
private boolean statsPressed = false;
private boolean inventoryPressed = false;
private UIActor ui;
private Touchpad touchpad;
private TouchpadStyle touchpadStyle;
@@ -72,7 +73,7 @@ public class GameHUD extends Stage {
statsActor = ui.findActor("statistic");
statsActor.getLabel().setText(Forge.getLocalizer().getMessage("lblStatus"));
inventoryActor = ui.findActor("inventory");
//todo translate inventoryActor
inventoryActor.getLabel().setText(Forge.getLocalizer().getMessage("lblItem"));
gamehud = ui.findActor("gamehud");
miniMapPlayer = new Image(new Texture(Config.instance().getFile("ui/minimap_player.png")));
@@ -160,10 +161,14 @@ public class GameHUD extends Stage {
statsActor.setWidth(80);
statsActor.setX(400);
statsActor.setY(menuActor.getY() + 35);
inventoryActor.setHeight(20);
inventoryActor.setWidth(80);
inventoryActor.setX(400);
inventoryActor.setY(statsActor.getY() + 35);
deckActor.setHeight(20);
deckActor.setWidth(80);
deckActor.setX(400);
deckActor.setY(statsActor.getY() + 35);
deckActor.setY(inventoryActor.getY() + 35);
}
addActor(ui);
addActor(miniMapPlayer);
@@ -196,9 +201,11 @@ public class GameHUD extends Stage {
checkButtonState(deckActor, pointer);
checkButtonState(menuActor, pointer);
checkButtonState(statsActor, pointer);
checkButtonState(inventoryActor, pointer);
deckPressed = false;
menuPressed = false;
statsPressed = false;
inventoryPressed = false;
return super.touchUp(screenX, screenY, pointer, button);
}
@@ -252,6 +259,18 @@ public class GameHUD extends Stage {
return true;
}
float inventoryX = inventoryActor.getX();
float inventoryY = inventoryActor.getY();
float inventoryR = inventoryActor.getRight();
float inventoryT = inventoryActor.getTop();
float inventoryOriginX = inventoryActor.getOriginX();
//inventory button bounds
if (c.x>=inventoryX&&c.x<=inventoryR&&c.y>=inventoryY&&c.y<=inventoryT) {
if (pointer < 1)
inventoryPressed = true;
return true;
}
float menuX = menuActor.getX();
float menuY = menuActor.getY();
float menuR = menuActor.getRight();
@@ -351,6 +370,7 @@ public class GameHUD extends Stage {
updateVisualState(statsActor, statsPressed);
updateVisualState(menuActor, menuPressed);
updateVisualState(deckActor, deckPressed);
updateVisualState(inventoryActor, inventoryPressed);
}
Texture miniMapTexture;

View File

@@ -5,6 +5,7 @@ import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.TextureData;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import forge.util.TextUtil;
/*
Class to draw directly on a pixmap
@@ -24,24 +25,31 @@ public abstract class DrawOnPixmap {
}
public static void drawText(Pixmap drawingMap, String text, int x, int y, float width) {
public static void drawText(Pixmap drawingMap, String itemText, int x, int y, float width, boolean bigText) {
//used for big numbers on Gold/Life for reward...
BitmapFont font = Controls.getBitmapFont("MiKrollFantasyBig");
BitmapFont font = bigText ? Controls.getBitmapFont("MiKrollFantasyBig") : Controls.getBitmapFont("default");
BitmapFont.BitmapFontData data = font.getData();
Pixmap source = new Pixmap(Gdx.files.absolute(data.getImagePath(0)));
float totalLength =0;
for (char c : text.toCharArray()) {
totalLength += data.getGlyph(c).width;
}
float xOffset = (width - totalLength) / 2;
xOffset += x;
for (char c : text.toCharArray()) {
drawingMap.drawPixmap(source, (int) xOffset, y,
data.getGlyph(c).srcX, data.getGlyph(c).srcY, data.getGlyph(c).width, data.getGlyph(c).height);
xOffset += data.getGlyph(c).width + 1;
String[] split = TextUtil.split(itemText, ' ');
for (int i = 0; i < split.length; i++) {
String text = split[i];
float totalLength =0;
for (char c : text.toCharArray()) {
totalLength += data.getGlyph(c).width;
}
float xOffset = (width - totalLength) / 2;
float yOffset = y;
xOffset += x;
for (char c : text.toCharArray()) {
drawingMap.drawPixmap(source, (int) xOffset, (int) yOffset*(i+1),
data.getGlyph(c).srcX, data.getGlyph(c).srcY, data.getGlyph(c).width, data.getGlyph(c).height);
xOffset += data.getGlyph(c).width + 1;
}
if (!bigText) {
yOffset += data.getGlyph(' ').height + 1;
}
}
source.dispose();

View File

@@ -91,7 +91,8 @@ public class RewardActor extends Actor implements Disposable, ImageFetcher.Callb
DrawOnPixmap.draw(drawingMap, backSprite);
Sprite item = reward.getItem().sprite();
DrawOnPixmap.draw(drawingMap, (int) ((backSprite.getWidth() / 2f) - item.getWidth() / 2f), (int) ((backSprite.getHeight() / 4f) * 1f), item);
DrawOnPixmap.draw(drawingMap, (int) ((backSprite.getWidth() / 2f) - item.getWidth() / 2f), (int) ((backSprite.getHeight() / 4f) * 1.7f), item);
DrawOnPixmap.drawText(drawingMap, String.valueOf(reward.getItem().name), 0, (int) ((backSprite.getHeight() / 8f) * 1f), backSprite.getWidth(), false);
image=new Texture(drawingMap);
drawingMap.dispose();
@@ -106,7 +107,7 @@ public class RewardActor extends Actor implements Disposable, ImageFetcher.Callb
DrawOnPixmap.draw(drawingMap, backSprite);
Sprite gold = atlas.createSprite("Gold");
DrawOnPixmap.draw(drawingMap, (int) ((backSprite.getWidth() / 2f) - gold.getWidth() / 2f), (int) ((backSprite.getHeight() / 4f) * 1f), gold);
DrawOnPixmap.drawText(drawingMap, String.valueOf(reward.getCount()), 0, (int) ((backSprite.getHeight() / 4f) * 2f), backSprite.getWidth());
DrawOnPixmap.drawText(drawingMap, String.valueOf(reward.getCount()), 0, (int) ((backSprite.getHeight() / 4f) * 2f), backSprite.getWidth(), true);
image=new Texture(drawingMap);
drawingMap.dispose();
@@ -121,7 +122,7 @@ public class RewardActor extends Actor implements Disposable, ImageFetcher.Callb
DrawOnPixmap.draw(drawingMap, backSprite);
Sprite gold = atlas.createSprite("Life");
DrawOnPixmap.draw(drawingMap, (int) ((backSprite.getWidth() / 2f) - gold.getWidth() / 2f), (int) ((backSprite.getHeight() / 4f) * 1f), gold);
DrawOnPixmap.drawText(drawingMap, String.valueOf(reward.getCount()), 0, (int) ((backSprite.getHeight() / 4f) * 2f), backSprite.getWidth());
DrawOnPixmap.drawText(drawingMap, String.valueOf(reward.getCount()), 0, (int) ((backSprite.getHeight() / 4f) * 2f), backSprite.getWidth(), true);
image = new Texture(drawingMap);
drawingMap.dispose();

View File

@@ -71,8 +71,13 @@ public class WorldSave {
SaveFileData mainData=(SaveFileData)oos.readObject();
currentSave.player.load(mainData.readSubData("player"));
GamePlayerUtil.getGuiPlayer().setName(currentSave.player.getName());
currentSave.world.load(mainData.readSubData("world"));
WorldStage.getInstance().load(mainData.readSubData("worldStage"));
try {
currentSave.world.load(mainData.readSubData("world"));
WorldStage.getInstance().load(mainData.readSubData("worldStage"));
} catch (Exception e) {
System.err.println("Generating New World");
currentSave.world.generateNew(0);
}
currentSave.onLoadList.emit();
@@ -128,6 +133,7 @@ public class WorldSave {
return currentSave;
//return currentSave = ret;
}
public boolean autoSave() {
return save("auto save",AUTO_SAVE_SLOT);
}

View File

@@ -395,11 +395,6 @@
"selection": "select"
}
},
"com.badlogic.gdx.scenes.scene2d.ui.TextTooltip$TextTooltipStyle": {
"default": {
"label": "default"
}
},
"com.badlogic.gdx.scenes.scene2d.ui.Touchpad$TouchpadStyle": {
"default": {
"background": "thinwindow",