Skip to content

Commit 67c3955

Browse files
authored
Merge pull request Card-Forge#11602 from Card-Forge/revert-11168-feature/archipelago/revamped-input-system
Revert "Feature/11167: Revamped input handling + better road detection"
2 parents a264116 + c89f003 commit 67c3955

4 files changed

Lines changed: 29 additions & 78 deletions

File tree

forge-gui-mobile/src/forge/adventure/stage/Console.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,11 @@ public class Console extends Window {
1818

1919
public void toggle() {
2020
if (isVisible()) {
21-
Forge.advFreezePlayerControls = false;
2221
setVisible(false);
2322
getStage().unfocus(input);
2423
Gdx.input.setOnscreenKeyboardVisible(false);
2524
} else {
2625
if (!Forge.advFreezePlayerControls) {
27-
Forge.advFreezePlayerControls = true;
2826
setVisible(true);
2927
getStage().setKeyboardFocus(input);
3028
}
@@ -60,6 +58,7 @@ public boolean keyUp(InputEvent event, int keycode) {
6058
textField.setCursorPosition(Integer.MAX_VALUE);
6159
} else {
6260
index = 0;
61+
textField.setText(commands.get(index));
6362
textField.setCursorPosition(Integer.MAX_VALUE);
6463
}
6564
} else if (!commands.isEmpty()) {
@@ -79,7 +78,7 @@ public boolean keyUp(InputEvent event, int keycode) {
7978
textField.setCursorPosition(Integer.MAX_VALUE);
8079
} else {
8180
index = commands.size - 1;
82-
textField.setText("");
81+
textField.setText(commands.get(index));
8382
textField.setCursorPosition(Integer.MAX_VALUE);
8483
}
8584
} else if (!commands.isEmpty()) {

forge-gui-mobile/src/forge/adventure/stage/GameStage.java

Lines changed: 25 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,6 @@ public abstract class GameStage extends Stage {
7575
private float animationTimeout = 0;
7676
public static float maximumScrollDistance = 1.5f;
7777
public static float minimumScrollDistance = 0.3f;
78-
private final Vector2 keyboardInput = new Vector2();
79-
private final Vector2 controllerInput = new Vector2();
80-
private final Vector2 touchInput = new Vector2();
8178

8279
private String extraAnnouncement = "";
8380

@@ -251,11 +248,16 @@ public void showDeckAwardDialog(String message, Deck deck, Runnable runnable) {
251248
showDialog();
252249
}
253250

251+
254252
public boolean axisMoved(Controller controller, int axisIndex, float value) {
255253
if (MapStage.getInstance().isDialogOnlyInput() || isPaused()) {
256254
return true;
257255
}
258-
controllerInput.set(controller.getAxis(0), -controller.getAxis(1));
256+
player.getMovementDirection().x = controller.getAxis(0);
257+
player.getMovementDirection().y = -controller.getAxis(1);
258+
if (player.getMovementDirection().len() < 0.2) {
259+
player.stop();
260+
}
259261
return true;
260262
}
261263

@@ -266,6 +268,7 @@ enum PlayerModification {
266268

267269
}
268270

271+
269272
HashMap<PlayerModification, Float> currentModifications = new HashMap<>();
270273

271274
public void modifyPlayer(PlayerModification mod, float value) {
@@ -357,7 +360,6 @@ public final void act(float delta) {
357360
animationTimeout -= delta;
358361
return;
359362
}
360-
361363
Array<PlayerModification> modsToRemove = new Array<>();
362364
for (Map.Entry<PlayerModification, Float> mod : currentModifications.entrySet()) {
363365
mod.setValue(mod.getValue() - delta);
@@ -369,66 +371,28 @@ public final void act(float delta) {
369371
onRemoveEffect(mod);
370372
}
371373

372-
if (onEndAction != null) {
373-
onEndAction.run();
374-
onEndAction = null;
374+
if (isPaused()) {
375+
return;
375376
}
376377

377-
if (isPaused() || isDialogOnlyInput() || Forge.advFreezePlayerControls) {
378-
keyboardInput.setZero();
379-
controllerInput.setZero();
380-
touchInput.setZero();
381-
player.getMovementDirection().setZero();
382-
player.stop();
383-
} else {
384-
keyboardInput.setZero();
385-
if (KeyBinding.Left.isPressed()) {
386-
keyboardInput.x -= 1;
387-
}
388-
389-
if (KeyBinding.Right.isPressed()) {
390-
keyboardInput.x += 1;
391-
}
392-
393-
if (KeyBinding.Up.isPressed()) {
394-
keyboardInput.y += 1;
395-
}
396378

397-
if (KeyBinding.Down.isPressed()) {
398-
keyboardInput.y -= 1;
399-
}
379+
if (onEndAction != null) {
400380

401-
// Input priority: touch > controller > keyboard
402-
Vector2 dir = new Vector2();
403-
if (touchX >= 0 && touchInput.len() > 0.2f) {
404-
dir.set(touchInput);
381+
onEndAction.run();
382+
onEndAction = null;
383+
}
405384

406-
} else if (controllerInput.len() > 0.2f) {
407-
dir.set(controllerInput);
385+
if (touchX >= 0) {
386+
Vector2 target = this.screenToStageCoordinates(new Vector2(touchX, touchY));
387+
target.x -= player.getWidth() / 2f;
388+
Vector2 diff = target.sub(player.pos());
408389

409-
} else {
410-
dir.set(keyboardInput);
411-
}
412-
if (dir.len() < 0.01f) {
390+
if (diff.len() < 2) {
391+
diff.setZero();
413392
player.stop();
414-
} else {
415-
player.getMovementDirection().set(dir);
416-
}
417-
418-
if (touchX >= 0) {
419-
Vector2 target = this.screenToStageCoordinates(new Vector2(touchX, touchY));
420-
target.x -= player.getWidth() / 2f;
421-
Vector2 diff = target.sub(player.pos());
422-
423-
if (diff.len() < 2) {
424-
touchInput.setZero();
425-
player.stop();
426-
} else {
427-
touchInput.set(diff);
428-
}
429393
}
394+
player.setMovementDirection(diff);
430395
}
431-
432396
camera.position.x = Math.min(Math.max(Scene.getIntendedWidth() / 2f, player.pos().x), getViewport().getWorldWidth() - Scene.getIntendedWidth() / 2f);
433397
camera.position.y = Math.min(Math.max(Scene.getIntendedHeight() / 2f, player.pos().y), getViewport().getWorldHeight() - Scene.getIntendedHeight() / 2f);
434398

@@ -451,22 +415,23 @@ private void onRemoveEffect(PlayerModification mod) {
451415

452416
abstract protected void onActing(float delta);
453417

418+
454419
@Override
455420
public boolean keyDown(int keycode) {
456421
super.keyDown(keycode);
457422
if (isPaused())
458423
return true;
459424
if (KeyBinding.Left.isPressed(keycode)) {
460-
keyboardInput.x = -1;
425+
player.getMovementDirection().x = -1;
461426
}
462427
if (KeyBinding.Right.isPressed(keycode)) {
463-
keyboardInput.x = +1;
428+
player.getMovementDirection().x = +1;
464429
}
465430
if (KeyBinding.Up.isPressed(keycode)) {
466-
keyboardInput.y = +1;
431+
player.getMovementDirection().y = +1;
467432
}
468433
if (KeyBinding.Down.isPressed(keycode)) {
469-
keyboardInput.y = -1;
434+
player.getMovementDirection().y = -1;
470435
}
471436
if (keycode == Input.Keys.F5)//todo config
472437
{
@@ -577,9 +542,6 @@ public boolean touchDown(int screenX, int screenY, int pointer, int button) {
577542
public void stop() {
578543
WorldStage.getInstance().getPlayerSprite().setMovementDirection(Vector2.Zero);
579544
MapStage.getInstance().getPlayerSprite().setMovementDirection(Vector2.Zero);
580-
touchInput.setZero();
581-
keyboardInput.setZero();
582-
controllerInput.setZero();
583545
touchX = -1;
584546
touchY = -1;
585547
player.stop();

forge-gui-mobile/src/forge/adventure/stage/WorldStage.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,8 @@ public boolean handlePointsOfInterestCollision() {
230230

231231
public void loadPOI(PointOfInterest poi) {
232232
try {
233-
stop();
234233
TileMapScene.instance().load(poi);
234+
stop();
235235
TileMapScene.instance().setFromWorldMap(true);
236236
Forge.switchScene(TileMapScene.instance());
237237
} catch (Exception e) {
@@ -266,7 +266,7 @@ private void handleMonsterSpawn(float delta) {
266266
}
267267

268268
World world = WorldSave.getCurrentSave().getWorld();
269-
int currentBiome = World.highestBiome(world.getBiome((int) ((player.getX() + player.getWidth() / 2f) / world.getTileSize()), (int) (player.getY() / world.getTileSize())));
269+
int currentBiome = World.highestBiome(world.getBiome((int) player.getX() / world.getTileSize(), (int) player.getY() / world.getTileSize()));
270270
List<BiomeData> biomeData = WorldSave.getCurrentSave().getWorld().getData().GetBiomes();
271271
float sprintingMod = currentModifications.containsKey(PlayerModification.Sprint) ? 2 : 1;
272272
if (biomeData.size() <= currentBiome) {// "if isOnRoad

forge-gui-mobile/src/forge/adventure/util/KeyBinding.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package forge.adventure.util;
22

3-
import com.badlogic.gdx.Gdx;
43
import com.badlogic.gdx.Input;
54
import com.badlogic.gdx.controllers.Controller;
65
import com.badlogic.gdx.controllers.ControllerMapping;
@@ -35,15 +34,6 @@ public enum KeyBinding {
3534
this.bindings = bindings;
3635
}
3736

38-
public boolean isPressed() {
39-
for (int key : bindings) {
40-
if (Gdx.input.isKeyPressed(key)) {
41-
return true;
42-
}
43-
}
44-
return false;
45-
}
46-
4737
public boolean isPressed(int key) {
4838
return isPressed(key, null);
4939
}

0 commit comments

Comments
 (0)