fix buttons

This commit is contained in:
Anthony Calosa
2023-04-14 07:52:55 +08:00
parent 10ac2bf139
commit 93b8fc79b7
2 changed files with 37 additions and 12 deletions

View File

@@ -154,12 +154,14 @@ public class GameHUD extends Stage {
} }
private void openMap() { private void openMap() {
if (console.isVisible())
return;
Forge.switchScene(MapViewScene.instance()); Forge.switchScene(MapViewScene.instance());
} }
private void logbook() { private void logbook() {
if (console.isVisible()) if (console.isVisible())
console.toggle(); return;
Forge.switchScene(QuestLogScene.instance(Forge.getCurrentScene())); Forge.switchScene(QuestLogScene.instance(Forge.getCurrentScene()));
} }
@@ -227,6 +229,7 @@ public class GameHUD extends Stage {
&& !(Controls.actorContainsVector(logbookActor, touch)) //not inside stats button && !(Controls.actorContainsVector(logbookActor, touch)) //not inside stats button
&& !(Controls.actorContainsVector(inventoryActor, touch)) //not inside inventory button && !(Controls.actorContainsVector(inventoryActor, touch)) //not inside inventory button
&& !(Controls.actorContainsVector(exitToWorldMapActor, touch)) //not inside exit button && !(Controls.actorContainsVector(exitToWorldMapActor, touch)) //not inside exit button
&& !(Controls.actorContainsVector(abilityButtonMap, touch)) //not inside abilityButtonMap
&& (Controls.actorContainsVector(ui, touch)) //inside display bounds && (Controls.actorContainsVector(ui, touch)) //inside display bounds
&& pointer < 1) { //not more than 1 pointer && pointer < 1) { //not more than 1 pointer
touchpad.setBounds(touch.x - TOUCHPAD_SCALE / 2, touch.y - TOUCHPAD_SCALE / 2, TOUCHPAD_SCALE, TOUCHPAD_SCALE); touchpad.setBounds(touch.x - TOUCHPAD_SCALE / 2, touch.y - TOUCHPAD_SCALE / 2, TOUCHPAD_SCALE, TOUCHPAD_SCALE);
@@ -349,14 +352,16 @@ public class GameHUD extends Stage {
button.getColor().a = opacity; button.getColor().a = opacity;
button.setSize(w, h); button.setSize(w, h);
button.setPosition(x, y); button.setPosition(x, y);
y += h + 10f; y += h + 15f;
addActor(button); addActor(button);
} }
} }
void setAbilityButton(ItemData data) { void setAbilityButton(ItemData data) {
if (data != null) { if (data != null) {
TextraButton button = Controls.newTextButton("[%120][+" + data.iconName + "][+Shards]" + data.shardsNeeded, () -> { TextraButton button = Controls.newTextButton("[%90][+" + data.iconName + "][+Shards][BLACK]" + data.shardsNeeded, () -> {
if (console.isVisible())
return;
boolean isInPoi = MapStage.getInstance().isInMap(); boolean isInPoi = MapStage.getInstance().isInMap();
if (!(isInPoi && data.usableInPoi || !isInPoi && data.usableOnWorldMap)) if (!(isInPoi && data.usableInPoi || !isInPoi && data.usableOnWorldMap))
return; return;
@@ -365,6 +370,7 @@ public class GameHUD extends Stage {
Current.player().addShards(-data.shardsNeeded); Current.player().addShards(-data.shardsNeeded);
ConsoleCommandInterpreter.getInstance().command(data.commandOnUse); ConsoleCommandInterpreter.getInstance().command(data.commandOnUse);
}); });
button.setStyle(Controls.getSkin().get("menu", TextButton.TextButtonStyle.class));
abilityButtonMap.add(button); abilityButtonMap.add(button);
} }
} }
@@ -473,20 +479,20 @@ public class GameHUD extends Stage {
private void openDeck() { private void openDeck() {
if (console.isVisible()) if (console.isVisible())
console.toggle(); return;
Forge.switchScene(DeckSelectScene.instance()); Forge.switchScene(DeckSelectScene.instance());
} }
private void openInventory() { private void openInventory() {
if (console.isVisible()) if (console.isVisible())
console.toggle(); return;
WorldSave.getCurrentSave().header.createPreview(); WorldSave.getCurrentSave().header.createPreview();
Forge.switchScene(InventoryScene.instance()); Forge.switchScene(InventoryScene.instance());
} }
private void exitToWorldMap() { private void exitToWorldMap() {
if (console.isVisible()) if (console.isVisible())
console.toggle(); return;
if (!GameScene.instance().isNotInWorldMap()) //prevent showing this dialog to WorldMap if (!GameScene.instance().isNotInWorldMap()) //prevent showing this dialog to WorldMap
return; return;
dialog.getButtonTable().clear(); dialog.getButtonTable().clear();
@@ -514,7 +520,7 @@ public class GameHUD extends Stage {
private void menu() { private void menu() {
if (console.isVisible()) if (console.isVisible())
console.toggle(); return;
gameStage.openMenu(); gameStage.openMenu();
} }
@@ -523,9 +529,11 @@ public class GameHUD extends Stage {
actor.setVisible(visible); actor.setVisible(visible);
} }
private void setDisabled(Actor actor, boolean enable) { private void setDisabled(Actor actor, boolean enable, String enabled, String disabled) {
if (actor != null && actor instanceof Button) if (actor instanceof TextraButton) {
((Button) actor).setDisabled(enable); ((TextraButton) actor).setDisabled(enable);
((TextraButton) actor).setText(((TextraButton) actor).isDisabled() ? disabled : enabled);
}
} }
private void setAlpha(Actor actor, boolean visible) { private void setAlpha(Actor actor, boolean visible) {
@@ -547,7 +555,7 @@ public class GameHUD extends Stage {
setVisibility(shards, visible); setVisibility(shards, visible);
setVisibility(money, visible); setVisibility(money, visible);
setVisibility(blank, visible); setVisibility(blank, visible);
setDisabled(exitToWorldMapActor, !GameScene.instance().isNotInWorldMap()); setDisabled(exitToWorldMapActor, !GameScene.instance().isNotInWorldMap(), "[%120][+ExitToWorldMap]", "---");
setAlpha(avatarborder, visible); setAlpha(avatarborder, visible);
setAlpha(avatar, visible); setAlpha(avatar, visible);
setAlpha(deckActor, visible); setAlpha(deckActor, visible);
@@ -641,7 +649,7 @@ public class GameHUD extends Stage {
public boolean act(float v) { public boolean act(float v) {
if (exitDungeon) { if (exitDungeon) {
MapStage.getInstance().exitDungeon(); MapStage.getInstance().exitDungeon();
setDisabled(exitToWorldMapActor, true); setDisabled(exitToWorldMapActor, true, "[%120][+ExitToWorldMap]", "---");
} }
return true; return true;
} }

View File

@@ -104,6 +104,23 @@ public class Controls {
return getBoundingRect(actor).contains(point); return getBoundingRect(actor).contains(point);
} }
static public boolean actorContainsVector(Array<TextraButton> buttons, Vector2 point) {
boolean value = false;
if (buttons == null)
return false;
if (buttons.isEmpty())
return false;
for (Actor actor : buttons) {
if (actor == null)
return false;
if (!actor.isVisible())
return false;
if (getBoundingRect(actor).contains(point))
value = true;
}
return value;
}
static public SelectBox<String> newComboBox(String[] text, String item, Function<Object, Void> func) { static public SelectBox<String> newComboBox(String[] text, String item, Function<Object, Void> func) {
SelectBox<String> ret = newComboBox(); SelectBox<String> ret = newComboBox();
ret.getStyle().listStyle.selection.setTopHeight(4); ret.getStyle().listStyle.selection.setTopHeight(4);