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

@@ -36,7 +36,7 @@ import forge.gui.GuiBase;
/** /**
* Stage to handle everything rendered in the HUD * Stage to handle everything rendered in the HUD
*/ */
public class GameHUD extends Stage { public class GameHUD extends Stage {
static public GameHUD instance; static public GameHUD instance;
private final GameStage gameStage; private final GameStage gameStage;
@@ -77,7 +77,7 @@ public class GameHUD extends Stage {
avatarborder = ui.findActor("avatarborder"); avatarborder = ui.findActor("avatarborder");
deckActor = ui.findActor("deck"); deckActor = ui.findActor("deck");
openMapActor = ui.findActor("openmap"); openMapActor = ui.findActor("openmap");
ui.onButtonPress("openmap", ()-> GameHUD.this.openMap()); ui.onButtonPress("openmap", () -> GameHUD.this.openMap());
menuActor = ui.findActor("menu"); menuActor = ui.findActor("menu");
referenceX = menuActor.getX(); referenceX = menuActor.getX();
statsActor = ui.findActor("statistic"); statsActor = ui.findActor("statistic");
@@ -92,11 +92,11 @@ public class GameHUD extends Stage {
@Override @Override
public void changed(ChangeEvent changeEvent, Actor actor) { public void changed(ChangeEvent changeEvent, Actor actor) {
if (MapStage.getInstance().isInMap()) { if (MapStage.getInstance().isInMap()) {
MapStage.getInstance().getPlayerSprite().getMovementDirection().x+=((Touchpad) actor).getKnobPercentX(); MapStage.getInstance().getPlayerSprite().getMovementDirection().x += ((Touchpad) actor).getKnobPercentX();
MapStage.getInstance().getPlayerSprite().getMovementDirection().y+=((Touchpad) actor).getKnobPercentY(); MapStage.getInstance().getPlayerSprite().getMovementDirection().y += ((Touchpad) actor).getKnobPercentY();
} else { } else {
WorldStage.getInstance().getPlayerSprite().getMovementDirection().x+=((Touchpad) actor).getKnobPercentX(); WorldStage.getInstance().getPlayerSprite().getMovementDirection().x += ((Touchpad) actor).getKnobPercentX();
WorldStage.getInstance().getPlayerSprite().getMovementDirection().y+=((Touchpad) actor).getKnobPercentY(); WorldStage.getInstance().getPlayerSprite().getMovementDirection().y += ((Touchpad) actor).getKnobPercentY();
} }
} }
}); });
@@ -116,11 +116,11 @@ public class GameHUD extends Stage {
AdventurePlayer.current().onLifeChange(() -> lifePoints.setText(AdventurePlayer.current().getLife() + "/" + AdventurePlayer.current().getMaxLife())); AdventurePlayer.current().onLifeChange(() -> lifePoints.setText(AdventurePlayer.current().getLife() + "/" + AdventurePlayer.current().getMaxLife()));
AdventurePlayer.current().onManaChange(() -> mana.setText(AdventurePlayer.current().getMana() + "/" + AdventurePlayer.current().getMaxMana())); AdventurePlayer.current().onManaChange(() -> mana.setText(AdventurePlayer.current().getMana() + "/" + AdventurePlayer.current().getMaxMana()));
WorldSave.getCurrentSave().getPlayer().onGoldChange(() -> money.setText(String.valueOf(AdventurePlayer.current().getGold()))) ; WorldSave.getCurrentSave().getPlayer().onGoldChange(() -> money.setText(String.valueOf(AdventurePlayer.current().getGold())));
addActor(ui); addActor(ui);
addActor(miniMapPlayer); addActor(miniMapPlayer);
console=new Console(); console = new Console();
console.setBounds(0, GuiBase.isAndroid() ? getHeight() : 0, getWidth(),getHeight()/2); console.setBounds(0, GuiBase.isAndroid() ? getHeight() : 0, getWidth(), getHeight() / 2);
console.setVisible(false); console.setVisible(false);
ui.addActor(console); ui.addActor(console);
if (GuiBase.isAndroid()) { if (GuiBase.isAndroid()) {
@@ -137,7 +137,7 @@ public class GameHUD extends Stage {
eventTouchUp.setType(InputEvent.Type.touchUp); eventTouchUp.setType(InputEvent.Type.touchUp);
} }
private void openMap() { private void openMap() {
Forge.switchScene(MapViewScene.instance()); Forge.switchScene(MapViewScene.instance());
} }
@@ -163,17 +163,17 @@ public class GameHUD extends Stage {
@Override @Override
public boolean touchDragged(int screenX, int screenY, int pointer) { public boolean touchDragged(int screenX, int screenY, int pointer) {
Vector2 c=new Vector2(); Vector2 c = new Vector2();
screenToStageCoordinates(c.set(screenX, screenY)); screenToStageCoordinates(c.set(screenX, screenY));
float x=(c.x-miniMap.getX())/miniMap.getWidth(); float x = (c.x - miniMap.getX()) / miniMap.getWidth();
float y=(c.y-miniMap.getY())/miniMap.getHeight(); float y = (c.y - miniMap.getY()) / miniMap.getHeight();
//map bounds //map bounds
if (Controls.actorContainsVector(miniMap,c)) { if (Controls.actorContainsVector(miniMap, c)) {
touchpad.setVisible(false); touchpad.setVisible(false);
if(debugMap) if (debugMap)
WorldStage.getInstance().getPlayerSprite().setPosition(x*WorldSave.getCurrentSave().getWorld().getWidthInPixels(),y*WorldSave.getCurrentSave().getWorld().getHeightInPixels()); WorldStage.getInstance().getPlayerSprite().setPosition(x * WorldSave.getCurrentSave().getWorld().getWidthInPixels(), y * WorldSave.getCurrentSave().getWorld().getHeightInPixels());
return true; return true;
} }
@@ -181,37 +181,36 @@ public class GameHUD extends Stage {
} }
@Override @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 c=new Vector2(); Vector2 touch = new Vector2();
Vector2 touch =new Vector2();
screenToStageCoordinates(touch.set(screenX, screenY)); screenToStageCoordinates(touch.set(screenX, screenY));
screenToStageCoordinates(c.set(screenX, screenY)); screenToStageCoordinates(c.set(screenX, screenY));
float x=(c.x-miniMap.getX())/miniMap.getWidth(); float x = (c.x - miniMap.getX()) / miniMap.getWidth();
float y=(c.y-miniMap.getY())/miniMap.getHeight(); float y = (c.y - miniMap.getY()) / miniMap.getHeight();
if (Controls.actorContainsVector(gamehud,c)) { if (Controls.actorContainsVector(gamehud, c)) {
super.touchDown(screenX, screenY, pointer, button); super.touchDown(screenX, screenY, pointer, button);
return true; return true;
} }
if (Controls.actorContainsVector(miniMap,c)) { if (Controls.actorContainsVector(miniMap, c)) {
if(debugMap) if (debugMap)
WorldStage.getInstance().getPlayerSprite().setPosition(x*WorldSave.getCurrentSave().getWorld().getWidthInPixels(),y*WorldSave.getCurrentSave().getWorld().getHeightInPixels()); WorldStage.getInstance().getPlayerSprite().setPosition(x * WorldSave.getCurrentSave().getWorld().getWidthInPixels(), y * WorldSave.getCurrentSave().getWorld().getHeightInPixels());
return true; return true;
} }
//auto follow touchpad //auto follow touchpad
if (GuiBase.isAndroid() && !MapStage.getInstance().getDialogOnlyInput() && !console.isVisible()) { if (GuiBase.isAndroid() && !MapStage.getInstance().getDialogOnlyInput() && !console.isVisible()) {
if (!(Controls.actorContainsVector(avatar,touch)) // not inside avatar bounds if (!(Controls.actorContainsVector(avatar, touch)) // not inside avatar bounds
&& !(Controls.actorContainsVector(miniMap,touch)) // not inside map bounds && !(Controls.actorContainsVector(miniMap, touch)) // not inside map bounds
&& !(Controls.actorContainsVector(gamehud,touch)) //not inside gamehud bounds && !(Controls.actorContainsVector(gamehud, touch)) //not inside gamehud bounds
&& !(Controls.actorContainsVector(menuActor,touch)) //not inside menu button && !(Controls.actorContainsVector(menuActor, touch)) //not inside menu button
&& !(Controls.actorContainsVector(deckActor,touch)) //not inside deck button && !(Controls.actorContainsVector(deckActor, touch)) //not inside deck button
&& !(Controls.actorContainsVector(openMapActor,touch)) //not inside openmap button && !(Controls.actorContainsVector(openMapActor, touch)) //not inside openmap button
&& !(Controls.actorContainsVector(statsActor,touch)) //not inside stats button && !(Controls.actorContainsVector(statsActor, touch)) //not inside stats button
&& !(Controls.actorContainsVector(inventoryActor,touch)) //not inside inventory button && !(Controls.actorContainsVector(inventoryActor, touch)) //not inside inventory button
&& (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);
touchpad.setVisible(true); touchpad.setVisible(true);
touchpad.setResetOnTouchUp(true); touchpad.setResetOnTouchUp(true);
hideButtons(); hideButtons();
@@ -230,9 +229,9 @@ public class GameHUD extends Stage {
super.draw(); //draw the Hud super.draw(); //draw the Hud
int xPosMini = (int) (((float) xPos / (float) WorldSave.getCurrentSave().getWorld().getTileSize() / (float) WorldSave.getCurrentSave().getWorld().getWidthInTiles()) * miniMap.getWidth()); int xPosMini = (int) (((float) xPos / (float) WorldSave.getCurrentSave().getWorld().getTileSize() / (float) WorldSave.getCurrentSave().getWorld().getWidthInTiles()) * miniMap.getWidth());
int yPosMini = (int) (((float) yPos / (float) WorldSave.getCurrentSave().getWorld().getTileSize() / (float) WorldSave.getCurrentSave().getWorld().getHeightInTiles()) * miniMap.getHeight()); int yPosMini = (int) (((float) yPos / (float) WorldSave.getCurrentSave().getWorld().getTileSize() / (float) WorldSave.getCurrentSave().getWorld().getHeightInTiles()) * miniMap.getHeight());
miniMapPlayer.setPosition(miniMap.getX() + xPosMini - miniMapPlayer.getWidth()/2, miniMap.getY() + yPosMini - miniMapPlayer.getHeight()/2); miniMapPlayer.setPosition(miniMap.getX() + xPosMini - miniMapPlayer.getWidth() / 2, miniMap.getY() + yPosMini - miniMapPlayer.getHeight() / 2);
if (GuiBase.isAndroid()) // prevent drawing on top of console if (GuiBase.isAndroid()) // prevent drawing on top of console
miniMapPlayer.setVisible(!console.isVisible()&&miniMap.isVisible()); miniMapPlayer.setVisible(!console.isVisible() && miniMap.isVisible());
//colored lifepoints //colored lifepoints
if (Current.player().getLife() >= Current.player().getMaxLife()) { if (Current.player().getLife() >= Current.player().getMaxLife()) {
//color green if max life //color green if max life
@@ -248,17 +247,18 @@ public class GameHUD extends Stage {
Texture miniMapTexture; Texture miniMapTexture;
Texture miniMapToolTipTexture; Texture miniMapToolTipTexture;
Pixmap miniMapToolTipPixmap; Pixmap miniMapToolTipPixmap;
public void enter() { public void enter() {
if(miniMapTexture!=null) if (miniMapTexture != null)
miniMapTexture.dispose(); miniMapTexture.dispose();
miniMapTexture=new Texture(WorldSave.getCurrentSave().getWorld().getBiomeImage()); miniMapTexture = new Texture(WorldSave.getCurrentSave().getWorld().getBiomeImage());
if(miniMapToolTipTexture!=null) if (miniMapToolTipTexture != null)
miniMapToolTipTexture.dispose(); miniMapToolTipTexture.dispose();
if(miniMapToolTipPixmap!=null) if (miniMapToolTipPixmap != null)
miniMapToolTipPixmap.dispose(); miniMapToolTipPixmap.dispose();
miniMapToolTipPixmap=new Pixmap((int) (miniMap.getWidth()*3), (int) (miniMap.getHeight()*3), Pixmap.Format.RGBA8888); miniMapToolTipPixmap = new Pixmap((int) (miniMap.getWidth() * 3), (int) (miniMap.getHeight() * 3), Pixmap.Format.RGBA8888);
miniMapToolTipPixmap.drawPixmap(WorldSave.getCurrentSave().getWorld().getBiomeImage(),0,0,WorldSave.getCurrentSave().getWorld().getBiomeImage().getWidth(),WorldSave.getCurrentSave().getWorld().getBiomeImage().getHeight(),0,0,miniMapToolTipPixmap.getWidth(),miniMapToolTipPixmap.getHeight()); miniMapToolTipPixmap.drawPixmap(WorldSave.getCurrentSave().getWorld().getBiomeImage(), 0, 0, WorldSave.getCurrentSave().getWorld().getBiomeImage().getWidth(), WorldSave.getCurrentSave().getWorld().getBiomeImage().getHeight(), 0, 0, miniMapToolTipPixmap.getWidth(), miniMapToolTipPixmap.getHeight());
miniMapToolTipTexture=new Texture(miniMapToolTipPixmap); miniMapToolTipTexture = new Texture(miniMapToolTipPixmap);
miniMap.setDrawable(new TextureRegionDrawable(miniMapTexture)); miniMap.setDrawable(new TextureRegionDrawable(miniMapTexture));
avatar.setDrawable(new TextureRegionDrawable(Current.player().avatar())); avatar.setDrawable(new TextureRegionDrawable(Current.player().avatar()));
Deck deck = AdventurePlayer.current().getSelectedDeck(); Deck deck = AdventurePlayer.current().getSelectedDeck();
@@ -277,43 +277,50 @@ public class GameHUD extends Stage {
WorldSave.getCurrentSave().header.createPreview(); WorldSave.getCurrentSave().header.createPreview();
Forge.switchScene(InventoryScene.instance()); Forge.switchScene(InventoryScene.instance());
} }
private void menu() { private void menu() {
gameStage.openMenu(); gameStage.openMenu();
} }
public void showHideMap(boolean visible) {
miniMap.setVisible(visible); public void setVisibility(Actor actor, boolean visible) {
mapborder.setVisible(visible); if (actor != null)
openMapActor.setVisible(visible); actor.setVisible(visible);
miniMapPlayer.setVisible(visible); }
gamehud.setVisible(visible);
lifePoints.setVisible(visible); public void setAlpha(Actor actor, boolean visible) {
mana.setVisible(visible); if (actor != null) {
money.setVisible(visible); if (visible)
blank.setVisible(visible); actor.getColor().a = 1f;
if (visible) { else
avatarborder.getColor().a = 1f; actor.getColor().a = 0.4f;
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 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 @Override
public boolean keyUp(int keycode) { public boolean keyUp(int keycode) {
ui.pressUp(keycode); ui.pressUp(keycode);
return super.keyUp(keycode); return super.keyUp(keycode);
} }
@Override @Override
public boolean keyDown(int keycode) { public boolean keyDown(int keycode) {
ui.pressDown(keycode); ui.pressDown(keycode);
@@ -333,13 +340,13 @@ public class GameHUD extends Stage {
} }
if (console.isVisible()) if (console.isVisible())
return true; return true;
Button pressedButton=ui.buttonPressed(keycode); Button pressedButton = ui.buttonPressed(keycode);
if(pressedButton!=null) if (pressedButton != null) {
{
performTouch(pressedButton); performTouch(pressedButton);
} }
return super.keyDown(keycode); return super.keyDown(keycode);
} }
public void performTouch(Actor actor) { public void performTouch(Actor actor) {
if (actor == null) if (actor == null)
return; return;
@@ -351,18 +358,20 @@ public class GameHUD extends Stage {
} }
}, 0.10f); }, 0.10f);
} }
public void hideButtons() { public void hideButtons() {
if (isShowing) if (isShowing)
return; return;
if (isHiding) if (isHiding)
return; return;
isHiding = true; isHiding = true;
deckActor.addAction(Actions.sequence(Actions.fadeOut(0.10f), Actions.hide(), Actions.moveTo(deckActor.getX()+deckActor.getWidth(), deckActor.getY()))); deckActor.addAction(Actions.sequence(Actions.fadeOut(0.10f), Actions.hide(), Actions.moveTo(deckActor.getX() + deckActor.getWidth(), deckActor.getY())));
inventoryActor.addAction(Actions.sequence(Actions.fadeOut(0.15f), Actions.hide(), Actions.moveTo(inventoryActor.getX()+inventoryActor.getWidth(), inventoryActor.getY()))); inventoryActor.addAction(Actions.sequence(Actions.fadeOut(0.15f), Actions.hide(), Actions.moveTo(inventoryActor.getX() + inventoryActor.getWidth(), inventoryActor.getY())));
statsActor.addAction(Actions.sequence(Actions.fadeOut(0.20f), Actions.hide(), Actions.moveTo(statsActor.getX()+statsActor.getWidth(), statsActor.getY()))); statsActor.addAction(Actions.sequence(Actions.fadeOut(0.20f), Actions.hide(), Actions.moveTo(statsActor.getX() + statsActor.getWidth(), statsActor.getY())));
menuActor.addAction(Actions.sequence(Actions.fadeOut(0.25f), Actions.hide(), Actions.moveTo(menuActor.getX() + menuActor.getWidth(), menuActor.getY()))); menuActor.addAction(Actions.sequence(Actions.fadeOut(0.25f), Actions.hide(), Actions.moveTo(menuActor.getX() + menuActor.getWidth(), menuActor.getY())));
FThreads.delayInEDT(300, () -> isHiding = false); FThreads.delayInEDT(300, () -> isHiding = false);
} }
public void showButtons() { public void showButtons() {
if (console.isVisible()) if (console.isVisible())
return; return;
@@ -371,27 +380,29 @@ public class GameHUD extends Stage {
if (isShowing) if (isShowing)
return; return;
isShowing = true; isShowing = true;
menuActor.addAction(Actions.sequence(Actions.delay(0.1f), Actions.parallel(Actions.show(), Actions.alpha(opacity,0.1f), Actions.moveTo(referenceX, menuActor.getY(), 0.25f)))); menuActor.addAction(Actions.sequence(Actions.delay(0.1f), Actions.parallel(Actions.show(), Actions.alpha(opacity, 0.1f), Actions.moveTo(referenceX, menuActor.getY(), 0.25f))));
statsActor.addAction(Actions.sequence(Actions.delay(0.15f), Actions.parallel(Actions.show(), Actions.alpha(opacity,0.1f), Actions.moveTo(referenceX, statsActor.getY(), 0.25f)))); statsActor.addAction(Actions.sequence(Actions.delay(0.15f), Actions.parallel(Actions.show(), Actions.alpha(opacity, 0.1f), Actions.moveTo(referenceX, statsActor.getY(), 0.25f))));
inventoryActor.addAction(Actions.sequence(Actions.delay(0.2f), Actions.parallel(Actions.show(), Actions.alpha(opacity,0.1f), Actions.moveTo(referenceX, inventoryActor.getY(), 0.25f)))); inventoryActor.addAction(Actions.sequence(Actions.delay(0.2f), Actions.parallel(Actions.show(), Actions.alpha(opacity, 0.1f), Actions.moveTo(referenceX, inventoryActor.getY(), 0.25f))));
deckActor.addAction(Actions.sequence(Actions.delay(0.25f), Actions.parallel(Actions.show(), Actions.alpha(opacity,0.1f), Actions.moveTo(referenceX, deckActor.getY(), 0.25f)))); deckActor.addAction(Actions.sequence(Actions.delay(0.25f), Actions.parallel(Actions.show(), Actions.alpha(opacity, 0.1f), Actions.moveTo(referenceX, deckActor.getY(), 0.25f))));
FThreads.delayInEDT(300, () -> isShowing = false); FThreads.delayInEDT(300, () -> isShowing = false);
} }
public void setDebug(boolean b) { public void setDebug(boolean b) {
debugMap=b; debugMap = b;
} }
class ConsoleToggleListener extends ActorGestureListener { class ConsoleToggleListener extends ActorGestureListener {
public ConsoleToggleListener() { public ConsoleToggleListener() {
getGestureDetector().setLongPressSeconds(0.6f); getGestureDetector().setLongPressSeconds(0.6f);
} }
@Override @Override
public boolean longPress(Actor actor, float x, float y) { public boolean longPress(Actor actor, float x, float y) {
hideButtons(); hideButtons();
console.toggle(); console.toggle();
return super.longPress(actor, x, y); return super.longPress(actor, x, y);
} }
@Override @Override
public void tap(InputEvent event, float x, float y, int count, int button) { public void tap(InputEvent event, float x, float y, int count, int button) {
super.tap(event, x, y, count, button); super.tap(event, x, y, count, button);

View File

@@ -30,10 +30,10 @@ import java.util.regex.Pattern;
*/ */
public class UIActor extends Group { public class UIActor extends Group {
UIData data; UIData data;
Actor lastActor=null; Actor lastActor = null;
public Array<UIScene.Selectable> selectActors=new Array<>(); public Array<UIScene.Selectable> selectActors = new Array<>();
private HashMap<KeyBinding,Button> keyMap=new HashMap<>(); private HashMap<KeyBinding, Button> keyMap = new HashMap<>();
public Array<KeyHintLabel> keyLabels=new Array<>(); public Array<KeyHintLabel> keyLabels = new Array<>();
public UIActor(FileHandle handle) { public UIActor(FileHandle handle) {
data = (new Json()).fromJson(UIData.class, handle); data = (new Json()).fromJson(UIData.class, handle);
@@ -89,7 +89,7 @@ public class UIActor extends Group {
readCheckBoxProperties((CheckBox) newActor, new OrderedMap.OrderedMapEntries<>(element)); readCheckBoxProperties((CheckBox) newActor, new OrderedMap.OrderedMapEntries<>(element));
break; break;
case "SelectBox": case "SelectBox":
newActor =Controls.newComboBox(); newActor = Controls.newComboBox();
break; break;
default: default:
throw new IllegalStateException("Unexpected value: " + type); throw new IllegalStateException("Unexpected value: " + type);
@@ -121,38 +121,32 @@ public class UIActor extends Group {
newActor.setY(data.yDown ? data.height - yValue - newActor.getHeight() : yValue); newActor.setY(data.yDown ? data.height - yValue - newActor.getHeight() : yValue);
break; break;
case "yOffset": case "yOffset":
if(data.yDown) if (data.yDown) {
{ yValue = (Float) property.value + ((lastActor != null ? (data.height - lastActor.getY()) : 0f));
yValue = (Float)property.value+((lastActor!=null?(data.height-lastActor.getY()):0f)); newActor.setY(data.height - yValue - newActor.getHeight());
newActor.setY( data.height - yValue - newActor.getHeight() ); } else {
}
else
{
yValue = (Float)property.value+((lastActor!=null?(lastActor.getY()):0f)); yValue = (Float) property.value + ((lastActor != null ? (lastActor.getY()) : 0f));
newActor.setY(yValue); newActor.setY(yValue);
} }
break; break;
case "xOffset": case "xOffset":
newActor.setX((Float)property.value+((lastActor!=null?lastActor.getX():0f))); newActor.setX((Float) property.value + ((lastActor != null ? lastActor.getX() : 0f)));
break; break;
case "name": case "name":
newActor.setName((String) property.value); newActor.setName((String) property.value);
break; break;
} }
} }
lastActor=newActor; lastActor = newActor;
addActor(newActor); addActor(newActor);
} }
} }
public Button buttonPressed(int key) public Button buttonPressed(int key) {
{ for (Map.Entry<KeyBinding, Button> entry : keyMap.entrySet()) {
for(Map.Entry<KeyBinding, Button> entry:keyMap.entrySet()) if (entry.getKey().isPressed(key)) {
{
if(entry.getKey().isPressed(key))
{
return entry.getValue(); return entry.getValue();
} }
} }
@@ -195,13 +189,12 @@ public class UIActor extends Group {
} }
public static String localize(String str) { public static String localize(String str) {
Pattern regex=Pattern.compile("tr\\([^\\)]*\\)"); Pattern regex = Pattern.compile("tr\\([^\\)]*\\)");
for(int i=0;i<100;i++) for (int i = 0; i < 100; i++) {
{ Matcher matcher = regex.matcher(str);
Matcher matcher= regex.matcher(str); if (!matcher.find())
if(!matcher.find()) return str;
return str; str = matcher.replaceFirst(Forge.getLocalizer().getMessage(matcher.group().substring(3, matcher.group().length() - 1)));
str=matcher.replaceFirst(Forge.getLocalizer().getMessage(matcher.group().substring(3,matcher.group().length()-1)));
} }
return str; return str;
} }
@@ -213,7 +206,7 @@ public class UIActor extends Group {
newActor.setStyle(Controls.getSkin().get(property.value.toString(), ImageButton.ImageButtonStyle.class)); newActor.setStyle(Controls.getSkin().get(property.value.toString(), ImageButton.ImageButtonStyle.class));
break; break;
case "binding": case "binding":
keyMap.put(KeyBinding.valueOf(property.value.toString()),newActor); keyMap.put(KeyBinding.valueOf(property.value.toString()), newActor);
break; break;
} }
} }
@@ -227,11 +220,11 @@ public class UIActor extends Group {
break; break;
case "font": case "font":
case "fontName": case "fontName":
if(!property.value.toString().equals("default")) if (!property.value.toString().equals("default"))
newActor.setFont(Controls.getTextraFont(property.value.toString())); newActor.setFont(Controls.getTextraFont(property.value.toString()));
break; break;
case "style": case "style":
newActor.style=(Controls.getSkin().get(property.value.toString(), Label.LabelStyle.class)); newActor.style = (Controls.getSkin().get(property.value.toString(), Label.LabelStyle.class));
break; break;
case "color": case "color":
case "fontColor": case "fontColor":
@@ -280,8 +273,8 @@ public class UIActor extends Group {
newActor.setStyle(Controls.getSkin().get(property.value.toString(), TextButton.TextButtonStyle.class)); newActor.setStyle(Controls.getSkin().get(property.value.toString(), TextButton.TextButtonStyle.class));
break; break;
case "binding": case "binding":
keyMap.put(KeyBinding.valueOf(property.value.toString()),newActor); keyMap.put(KeyBinding.valueOf(property.value.toString()), newActor);
KeyHintLabel label=new KeyHintLabel(KeyBinding.valueOf(property.value.toString())); KeyHintLabel label = new KeyHintLabel(KeyBinding.valueOf(property.value.toString()));
keyLabels.add(label); keyLabels.add(label);
newActor.add(label); newActor.add(label);
break; break;
@@ -305,42 +298,40 @@ public class UIActor extends Group {
public void onButtonPress(String name, Runnable func) { public void onButtonPress(String name, Runnable func) {
Actor button = findActor(name); Actor button = findActor(name);
assert button != null; if (button != null) {
button.addListener(new ClickListener() { button.addListener(new ClickListener() {
@Override @Override
public void clicked(InputEvent event, float x, float y) { public void clicked(InputEvent event, float x, float y) {
if(button instanceof Button) if (button instanceof Button) {
{ if (((Button) button).isDisabled())
if(((Button)button).isDisabled()) return;
return; }
func.run();
} }
func.run(); });
} }
});
} }
public void controllerDisconnected( ) { public void controllerDisconnected() {
for(KeyHintLabel label:keyLabels) for (KeyHintLabel label : keyLabels) {
{
label.disconnected(); label.disconnected();
} }
} }
public void controllerConnected( ) {
for(KeyHintLabel label:keyLabels) public void controllerConnected() {
{ for (KeyHintLabel label : keyLabels) {
label.connected(); label.connected();
} }
} }
public void pressUp(int code) { public void pressUp(int code) {
for(KeyHintLabel label:keyLabels) for (KeyHintLabel label : keyLabels) {
{
label.buttonUp(code); label.buttonUp(code);
} }
} }
public void pressDown(int code) { public void pressDown(int code) {
for(KeyHintLabel label:keyLabels) for (KeyHintLabel label : keyLabels) {
{
label.buttonDown(code); label.buttonDown(code);
} }
} }
@@ -348,11 +339,13 @@ public class UIActor extends Group {
private class KeyHintLabel extends TextraLabel { private class KeyHintLabel extends TextraLabel {
public KeyHintLabel(KeyBinding keyBinding) { public KeyHintLabel(KeyBinding keyBinding) {
super(keyBinding.getLabelText(false),Controls.getKeysFont()); super(keyBinding.getLabelText(false), Controls.getKeysFont());
this.keyBinding=keyBinding; this.keyBinding = keyBinding;
} }
KeyBinding keyBinding; KeyBinding keyBinding;
public void connected( ) {
public void connected() {
updateText(); updateText();
} }
@@ -366,14 +359,14 @@ public class UIActor extends Group {
} }
public boolean buttonDown(int i) { public boolean buttonDown(int i) {
if(keyBinding.isPressed(i)) if (keyBinding.isPressed(i))
setText(keyBinding.getLabelText(true)); setText(keyBinding.getLabelText(true));
layout(); layout();
return false; return false;
} }
public boolean buttonUp( int i) { public boolean buttonUp(int i) {
if(keyBinding.isPressed(i)) if (keyBinding.isPressed(i))
updateText(); updateText();
return false; return false;
} }

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