diff --git a/forge-gui-mobile/src/forge/adventure/stage/Console.java b/forge-gui-mobile/src/forge/adventure/stage/Console.java index 5bc67052d157..03823d7d364a 100644 --- a/forge-gui-mobile/src/forge/adventure/stage/Console.java +++ b/forge-gui-mobile/src/forge/adventure/stage/Console.java @@ -18,11 +18,13 @@ public class Console extends Window { public void toggle() { if (isVisible()) { + Forge.advFreezePlayerControls = false; setVisible(false); getStage().unfocus(input); Gdx.input.setOnscreenKeyboardVisible(false); } else { if (!Forge.advFreezePlayerControls) { + Forge.advFreezePlayerControls = true; setVisible(true); getStage().setKeyboardFocus(input); } @@ -58,7 +60,6 @@ public boolean keyUp(InputEvent event, int keycode) { textField.setCursorPosition(Integer.MAX_VALUE); } else { index = 0; - textField.setText(commands.get(index)); textField.setCursorPosition(Integer.MAX_VALUE); } } else if (!commands.isEmpty()) { @@ -78,7 +79,7 @@ public boolean keyUp(InputEvent event, int keycode) { textField.setCursorPosition(Integer.MAX_VALUE); } else { index = commands.size - 1; - textField.setText(commands.get(index)); + textField.setText(""); textField.setCursorPosition(Integer.MAX_VALUE); } } else if (!commands.isEmpty()) { diff --git a/forge-gui-mobile/src/forge/adventure/stage/GameStage.java b/forge-gui-mobile/src/forge/adventure/stage/GameStage.java index 4944c9822a4e..4556094c3469 100644 --- a/forge-gui-mobile/src/forge/adventure/stage/GameStage.java +++ b/forge-gui-mobile/src/forge/adventure/stage/GameStage.java @@ -75,6 +75,9 @@ public abstract class GameStage extends Stage { private float animationTimeout = 0; public static float maximumScrollDistance = 1.5f; public static float minimumScrollDistance = 0.3f; + private final Vector2 keyboardInput = new Vector2(); + private final Vector2 controllerInput = new Vector2(); + private final Vector2 touchInput = new Vector2(); private String extraAnnouncement = ""; @@ -248,16 +251,11 @@ public void showDeckAwardDialog(String message, Deck deck, Runnable runnable) { showDialog(); } - public boolean axisMoved(Controller controller, int axisIndex, float value) { if (MapStage.getInstance().isDialogOnlyInput() || isPaused()) { return true; } - player.getMovementDirection().x = controller.getAxis(0); - player.getMovementDirection().y = -controller.getAxis(1); - if (player.getMovementDirection().len() < 0.2) { - player.stop(); - } + controllerInput.set(controller.getAxis(0), -controller.getAxis(1)); return true; } @@ -268,7 +266,6 @@ enum PlayerModification { } - HashMap currentModifications = new HashMap<>(); public void modifyPlayer(PlayerModification mod, float value) { @@ -360,6 +357,7 @@ public final void act(float delta) { animationTimeout -= delta; return; } + Array modsToRemove = new Array<>(); for (Map.Entry mod : currentModifications.entrySet()) { mod.setValue(mod.getValue() - delta); @@ -371,28 +369,66 @@ public final void act(float delta) { onRemoveEffect(mod); } - if (isPaused()) { - return; - } - - if (onEndAction != null) { - onEndAction.run(); onEndAction = null; } - if (touchX >= 0) { - Vector2 target = this.screenToStageCoordinates(new Vector2(touchX, touchY)); - target.x -= player.getWidth() / 2f; - Vector2 diff = target.sub(player.pos()); + if (isPaused() || isDialogOnlyInput() || Forge.advFreezePlayerControls) { + keyboardInput.setZero(); + controllerInput.setZero(); + touchInput.setZero(); + player.getMovementDirection().setZero(); + player.stop(); + } else { + keyboardInput.setZero(); + if (KeyBinding.Left.isPressed()) { + keyboardInput.x -= 1; + } + + if (KeyBinding.Right.isPressed()) { + keyboardInput.x += 1; + } + + if (KeyBinding.Up.isPressed()) { + keyboardInput.y += 1; + } + + if (KeyBinding.Down.isPressed()) { + keyboardInput.y -= 1; + } + + // Input priority: touch > controller > keyboard + Vector2 dir = new Vector2(); + if (touchX >= 0 && touchInput.len() > 0.2f) { + dir.set(touchInput); + + } else if (controllerInput.len() > 0.2f) { + dir.set(controllerInput); - if (diff.len() < 2) { - diff.setZero(); + } else { + dir.set(keyboardInput); + } + if (dir.len() < 0.01f) { player.stop(); + } else { + player.getMovementDirection().set(dir); + } + + if (touchX >= 0) { + Vector2 target = this.screenToStageCoordinates(new Vector2(touchX, touchY)); + target.x -= player.getWidth() / 2f; + Vector2 diff = target.sub(player.pos()); + + if (diff.len() < 2) { + touchInput.setZero(); + player.stop(); + } else { + touchInput.set(diff); + } } - player.setMovementDirection(diff); } + camera.position.x = Math.min(Math.max(Scene.getIntendedWidth() / 2f, player.pos().x), getViewport().getWorldWidth() - Scene.getIntendedWidth() / 2f); camera.position.y = Math.min(Math.max(Scene.getIntendedHeight() / 2f, player.pos().y), getViewport().getWorldHeight() - Scene.getIntendedHeight() / 2f); @@ -415,23 +451,22 @@ private void onRemoveEffect(PlayerModification mod) { abstract protected void onActing(float delta); - @Override public boolean keyDown(int keycode) { super.keyDown(keycode); if (isPaused()) return true; if (KeyBinding.Left.isPressed(keycode)) { - player.getMovementDirection().x = -1; + keyboardInput.x = -1; } if (KeyBinding.Right.isPressed(keycode)) { - player.getMovementDirection().x = +1; + keyboardInput.x = +1; } if (KeyBinding.Up.isPressed(keycode)) { - player.getMovementDirection().y = +1; + keyboardInput.y = +1; } if (KeyBinding.Down.isPressed(keycode)) { - player.getMovementDirection().y = -1; + keyboardInput.y = -1; } if (keycode == Input.Keys.F5)//todo config { @@ -542,6 +577,9 @@ public boolean touchDown(int screenX, int screenY, int pointer, int button) { public void stop() { WorldStage.getInstance().getPlayerSprite().setMovementDirection(Vector2.Zero); MapStage.getInstance().getPlayerSprite().setMovementDirection(Vector2.Zero); + touchInput.setZero(); + keyboardInput.setZero(); + controllerInput.setZero(); touchX = -1; touchY = -1; player.stop(); diff --git a/forge-gui-mobile/src/forge/adventure/stage/WorldStage.java b/forge-gui-mobile/src/forge/adventure/stage/WorldStage.java index a843e4b434ae..043005647efa 100644 --- a/forge-gui-mobile/src/forge/adventure/stage/WorldStage.java +++ b/forge-gui-mobile/src/forge/adventure/stage/WorldStage.java @@ -230,8 +230,8 @@ public boolean handlePointsOfInterestCollision() { public void loadPOI(PointOfInterest poi) { try { - TileMapScene.instance().load(poi); stop(); + TileMapScene.instance().load(poi); TileMapScene.instance().setFromWorldMap(true); Forge.switchScene(TileMapScene.instance()); } catch (Exception e) { @@ -266,7 +266,7 @@ private void handleMonsterSpawn(float delta) { } World world = WorldSave.getCurrentSave().getWorld(); - int currentBiome = World.highestBiome(world.getBiome((int) player.getX() / world.getTileSize(), (int) player.getY() / world.getTileSize())); + int currentBiome = World.highestBiome(world.getBiome((int) ((player.getX() + player.getWidth() / 2f) / world.getTileSize()), (int) (player.getY() / world.getTileSize()))); List biomeData = WorldSave.getCurrentSave().getWorld().getData().GetBiomes(); float sprintingMod = currentModifications.containsKey(PlayerModification.Sprint) ? 2 : 1; if (biomeData.size() <= currentBiome) {// "if isOnRoad diff --git a/forge-gui-mobile/src/forge/adventure/util/KeyBinding.java b/forge-gui-mobile/src/forge/adventure/util/KeyBinding.java index cb103c6b8a9b..d929dd6efafd 100644 --- a/forge-gui-mobile/src/forge/adventure/util/KeyBinding.java +++ b/forge-gui-mobile/src/forge/adventure/util/KeyBinding.java @@ -1,5 +1,6 @@ package forge.adventure.util; +import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input; import com.badlogic.gdx.controllers.Controller; import com.badlogic.gdx.controllers.ControllerMapping; @@ -34,6 +35,15 @@ public enum KeyBinding { this.bindings = bindings; } + public boolean isPressed() { + for (int key : bindings) { + if (Gdx.input.isKeyPressed(key)) { + return true; + } + } + return false; + } + public boolean isPressed(int key) { return isPressed(key, null); }