Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions forge-gui-mobile/src/forge/adventure/stage/Console.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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()) {
Expand All @@ -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()) {
Expand Down
88 changes: 63 additions & 25 deletions forge-gui-mobile/src/forge/adventure/stage/GameStage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";

Expand Down Expand Up @@ -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;
}

Expand All @@ -268,7 +266,6 @@ enum PlayerModification {

}


HashMap<PlayerModification, Float> currentModifications = new HashMap<>();

public void modifyPlayer(PlayerModification mod, float value) {
Expand Down Expand Up @@ -360,6 +357,7 @@ public final void act(float delta) {
animationTimeout -= delta;
return;
}

Array<PlayerModification> modsToRemove = new Array<>();
for (Map.Entry<PlayerModification, Float> mod : currentModifications.entrySet()) {
mod.setValue(mod.getValue() - delta);
Expand All @@ -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);

Expand All @@ -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
{
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions forge-gui-mobile/src/forge/adventure/stage/WorldStage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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> biomeData = WorldSave.getCurrentSave().getWorld().getData().GetBiomes();
float sprintingMod = currentModifications.containsKey(PlayerModification.Sprint) ? 2 : 1;
if (biomeData.size() <= currentBiome) {// "if isOnRoad
Expand Down
10 changes: 10 additions & 0 deletions forge-gui-mobile/src/forge/adventure/util/KeyBinding.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
Loading