update GameHUD

add NPE prevention on buttons
update adventure skin
This commit is contained in:
Anthony Calosa
2022-11-18 07:32:32 +08:00
parent 6c0a339019
commit 441b2ec2fd
4 changed files with 147 additions and 143 deletions

View File

@@ -181,8 +181,7 @@ public class GameHUD extends Stage {
}
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button)
{
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
Vector2 c = new Vector2();
Vector2 touch = new Vector2();
screenToStageCoordinates(touch.set(screenX, screenY));
@@ -248,6 +247,7 @@ public class GameHUD extends Stage {
Texture miniMapTexture;
Texture miniMapToolTipTexture;
Pixmap miniMapToolTipPixmap;
public void enter() {
if (miniMapTexture != null)
miniMapTexture.dispose();
@@ -277,36 +277,42 @@ public class GameHUD extends Stage {
WorldSave.getCurrentSave().header.createPreview();
Forge.switchScene(InventoryScene.instance());
}
private void menu() {
gameStage.openMenu();
}
public void showHideMap(boolean visible) {
miniMap.setVisible(visible);
mapborder.setVisible(visible);
openMapActor.setVisible(visible);
miniMapPlayer.setVisible(visible);
gamehud.setVisible(visible);
lifePoints.setVisible(visible);
mana.setVisible(visible);
money.setVisible(visible);
blank.setVisible(visible);
if (visible) {
avatarborder.getColor().a = 1f;
avatar.getColor().a = 1f;
deckActor.getColor().a = 1f;
menuActor.getColor().a = 1f;
statsActor.getColor().a = 1f;
inventoryActor.getColor().a = 1f;
opacity = 1f;
} else {
avatarborder.getColor().a = 0.4f;
avatar.getColor().a = 0.4f;
deckActor.getColor().a = 0.4f;
menuActor.getColor().a = 0.4f;
statsActor.getColor().a = 0.4f;
inventoryActor.getColor().a = 0.4f;
opacity = 0.4f;
public void setVisibility(Actor actor, boolean visible) {
if (actor != null)
actor.setVisible(visible);
}
public void setAlpha(Actor actor, boolean visible) {
if (actor != null) {
if (visible)
actor.getColor().a = 1f;
else
actor.getColor().a = 0.4f;
}
}
public void showHideMap(boolean visible) {
setVisibility(miniMap, visible);
setVisibility(mapborder, visible);
setVisibility(openMapActor, visible);
setVisibility(miniMapPlayer, visible);
setVisibility(gamehud, visible);
setVisibility(lifePoints, visible);
setVisibility(mana, visible);
setVisibility(money, visible);
setVisibility(blank, visible);
setAlpha(avatarborder, visible);
setAlpha(avatar, visible);
setAlpha(deckActor, visible);
setAlpha(menuActor, visible);
setAlpha(statsActor, visible);
setAlpha(inventoryActor, visible);
opacity = visible ? 1f : 0.4f;
}
@Override
@@ -314,6 +320,7 @@ public class GameHUD extends Stage {
ui.pressUp(keycode);
return super.keyUp(keycode);
}
@Override
public boolean keyDown(int keycode) {
ui.pressDown(keycode);
@@ -334,12 +341,12 @@ public class GameHUD extends Stage {
if (console.isVisible())
return true;
Button pressedButton = ui.buttonPressed(keycode);
if(pressedButton!=null)
{
if (pressedButton != null) {
performTouch(pressedButton);
}
return super.keyDown(keycode);
}
public void performTouch(Actor actor) {
if (actor == null)
return;
@@ -351,6 +358,7 @@ public class GameHUD extends Stage {
}
}, 0.10f);
}
public void hideButtons() {
if (isShowing)
return;
@@ -363,6 +371,7 @@ public class GameHUD extends Stage {
menuActor.addAction(Actions.sequence(Actions.fadeOut(0.25f), Actions.hide(), Actions.moveTo(menuActor.getX() + menuActor.getWidth(), menuActor.getY())));
FThreads.delayInEDT(300, () -> isHiding = false);
}
public void showButtons() {
if (console.isVisible())
return;
@@ -386,12 +395,14 @@ public class GameHUD extends Stage {
public ConsoleToggleListener() {
getGestureDetector().setLongPressSeconds(0.6f);
}
@Override
public boolean longPress(Actor actor, float x, float y) {
hideButtons();
console.toggle();
return super.longPress(actor, x, y);
}
@Override
public void tap(InputEvent event, float x, float y, int count, int button) {
super.tap(event, x, y, count, button);

View File

@@ -121,13 +121,10 @@ public class UIActor extends Group {
newActor.setY(data.yDown ? data.height - yValue - newActor.getHeight() : yValue);
break;
case "yOffset":
if(data.yDown)
{
if (data.yDown) {
yValue = (Float) property.value + ((lastActor != null ? (data.height - lastActor.getY()) : 0f));
newActor.setY(data.height - yValue - newActor.getHeight());
}
else
{
} else {
yValue = (Float) property.value + ((lastActor != null ? (lastActor.getY()) : 0f));
newActor.setY(yValue);
@@ -147,12 +144,9 @@ public class UIActor extends Group {
}
public Button buttonPressed(int key)
{
for(Map.Entry<KeyBinding, Button> entry:keyMap.entrySet())
{
if(entry.getKey().isPressed(key))
{
public Button buttonPressed(int key) {
for (Map.Entry<KeyBinding, Button> entry : keyMap.entrySet()) {
if (entry.getKey().isPressed(key)) {
return entry.getValue();
}
}
@@ -196,8 +190,7 @@ public class UIActor extends Group {
public static String localize(String str) {
Pattern regex = Pattern.compile("tr\\([^\\)]*\\)");
for(int i=0;i<100;i++)
{
for (int i = 0; i < 100; i++) {
Matcher matcher = regex.matcher(str);
if (!matcher.find())
return str;
@@ -305,12 +298,11 @@ public class UIActor extends Group {
public void onButtonPress(String name, Runnable func) {
Actor button = findActor(name);
assert button != null;
if (button != null) {
button.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
if(button instanceof Button)
{
if (button instanceof Button) {
if (((Button) button).isDisabled())
return;
}
@@ -318,29 +310,28 @@ public class UIActor extends Group {
}
});
}
}
public void controllerDisconnected() {
for(KeyHintLabel label:keyLabels)
{
for (KeyHintLabel label : keyLabels) {
label.disconnected();
}
}
public void controllerConnected() {
for(KeyHintLabel label:keyLabels)
{
for (KeyHintLabel label : keyLabels) {
label.connected();
}
}
public void pressUp(int code) {
for(KeyHintLabel label:keyLabels)
{
for (KeyHintLabel label : keyLabels) {
label.buttonUp(code);
}
}
public void pressDown(int code) {
for(KeyHintLabel label:keyLabels)
{
for (KeyHintLabel label : keyLabels) {
label.buttonDown(code);
}
}
@@ -351,7 +342,9 @@ public class UIActor extends Group {
super(keyBinding.getLabelText(false), Controls.getKeysFont());
this.keyBinding = keyBinding;
}
KeyBinding keyBinding;
public void connected() {
updateText();
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 121 KiB

After

Width:  |  Height:  |  Size: 128 KiB