From aeb90f55c67d5ed8ab827666cbf8832a679e3cf6 Mon Sep 17 00:00:00 2001 From: Anthony Calosa Date: Sun, 20 Feb 2022 06:53:02 +0800 Subject: [PATCH] fix gamehud touch --- .../src/forge/adventure/stage/GameHUD.java | 47 +++++++++++++++++-- .../src/forge/adventure/world/WorldSave.java | 2 +- forge-gui/res/adventure/Shandalar/ui/hud.json | 3 +- .../adventure/Shandalar/ui/hud_mobile.json | 3 +- 4 files changed, 49 insertions(+), 6 deletions(-) diff --git a/forge-gui-mobile/src/forge/adventure/stage/GameHUD.java b/forge-gui-mobile/src/forge/adventure/stage/GameHUD.java index 3007ed14837..7591ca273ea 100644 --- a/forge-gui-mobile/src/forge/adventure/stage/GameHUD.java +++ b/forge-gui-mobile/src/forge/adventure/stage/GameHUD.java @@ -30,13 +30,14 @@ public class GameHUD extends Stage { private final Label lifePoints; private final Label money; private Image miniMap; + UIActor ui; private GameHUD(GameStage gameStage) { super(new FitViewport(Scene.GetIntendedWidth(), Scene.GetIntendedHeight()), gameStage.getBatch()); instance = this; this.gameStage = gameStage; - UIActor ui = new UIActor(Config.instance().getFile(GuiBase.isAndroid() ? "ui/hud_mobile.json" : "ui/hud.json")); + ui = new UIActor(Config.instance().getFile(GuiBase.isAndroid() ? "ui/hud_mobile.json" : "ui/hud.json")); miniMap = ui.findActor("map"); @@ -90,7 +91,7 @@ public class GameHUD extends Stage { } private void statistic() { - + Forge.switchScene(SceneType.PlayerStatisticScene.instance); } public static GameHUD getInstance() { @@ -105,10 +106,50 @@ public class GameHUD extends Stage { float x=(c.x-miniMap.getX())/miniMap.getWidth(); float y=(c.y-miniMap.getY())/miniMap.getHeight(); + + float deckX = ui.findActor("deck").getX(); + float deckY = ui.findActor("deck").getY(); + float deckR = ui.findActor("deck").getRight(); + float deckT = ui.findActor("deck").getTop(); + //deck button bounds + if (c.x>=deckX&&c.x<=deckR&&c.y>=deckY&&c.y<=deckT) { + instance.openDeck(); + return true; + } + + float menuX = ui.findActor("menu").getX(); + float menuY = ui.findActor("menu").getY(); + float menuR = ui.findActor("menu").getRight(); + float menuT = ui.findActor("menu").getTop(); + //menu button bounds + if (c.x>=menuX&&c.x<=menuR&&c.y>=menuY&&c.y<=menuT) { + instance.menu(); + return true; + } + + float statsX = ui.findActor("statistic").getX(); + float statsY = ui.findActor("statistic").getY(); + float statsR = ui.findActor("statistic").getRight(); + float statsT = ui.findActor("statistic").getTop(); + //stats button bounds + if (c.x>=statsX&&c.x<=statsR&&c.y>=statsY&&c.y<=statsT) { + instance.statistic(); + return true; + } + + float uiX = ui.findActor("gamehud").getX(); + float uiY = ui.findActor("gamehud").getY(); + float uiTop = ui.findActor("gamehud").getTop(); + float uiRight = ui.findActor("gamehud").getRight(); + //gamehud bounds + if (c.x>=uiX&&c.x<=uiRight&&c.y>=uiY&&c.y<=uiTop) { + return true; + } + + //move player except touching the gamehud bounds and buttons if(x>=0&&x<=1.0&&y>=0&&y<=1.0) { WorldStage.getInstance().GetPlayer().setPosition(x*WorldSave.getCurrentSave().getWorld().getWidthInPixels(),y*WorldSave.getCurrentSave().getWorld().getHeightInPixels()); - return true; } return super.touchDown(screenX,screenY, pointer,button); } diff --git a/forge-gui-mobile/src/forge/adventure/world/WorldSave.java b/forge-gui-mobile/src/forge/adventure/world/WorldSave.java index 4d0b781b484..8392b869883 100644 --- a/forge-gui-mobile/src/forge/adventure/world/WorldSave.java +++ b/forge-gui-mobile/src/forge/adventure/world/WorldSave.java @@ -75,7 +75,7 @@ public class WorldSave { currentSave.onLoadList.emit(); } - } catch (ClassNotFoundException | IOException e) { + } catch (Exception e) { e.printStackTrace(); return false; } finally { diff --git a/forge-gui/res/adventure/Shandalar/ui/hud.json b/forge-gui/res/adventure/Shandalar/ui/hud.json index c14e03e70d2..c205ac9c566 100644 --- a/forge-gui/res/adventure/Shandalar/ui/hud.json +++ b/forge-gui/res/adventure/Shandalar/ui/hud.json @@ -4,7 +4,8 @@ "yDown": true, "elements":[ { - "type" : "Image", + "type" : "Image", + "name" : "gamehud", "width": 64, "height": 206, "image":"ui/hud.png", diff --git a/forge-gui/res/adventure/Shandalar/ui/hud_mobile.json b/forge-gui/res/adventure/Shandalar/ui/hud_mobile.json index 2a149f2b426..5b6bd6891fa 100644 --- a/forge-gui/res/adventure/Shandalar/ui/hud_mobile.json +++ b/forge-gui/res/adventure/Shandalar/ui/hud_mobile.json @@ -4,7 +4,8 @@ "yDown": true, "elements":[ { - "type" : "Image", + "type" : "Image", + "name" : "gamehud", "width": 64, "height": 206, "image":"ui/hud.png",