mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 12:48:00 +00:00
Implement Back and Menu key support
This commit is contained in:
@@ -96,6 +96,8 @@ public class Forge implements ApplicationListener {
|
||||
FSkin.loadFull(splashScreen);
|
||||
|
||||
Gdx.input.setInputProcessor(new MainInputProcessor());
|
||||
Gdx.input.setCatchBackKey(true);
|
||||
Gdx.input.setCatchMenuKey(true);
|
||||
openScreen(new HomeScreen());
|
||||
splashScreen = null;
|
||||
}
|
||||
@@ -106,6 +108,7 @@ public class Forge implements ApplicationListener {
|
||||
|
||||
public static void showMenu() {
|
||||
if (currentScreen == null) { return; }
|
||||
endKeyInput(); //end key input before menu shown
|
||||
currentScreen.showMenu();
|
||||
}
|
||||
|
||||
@@ -233,13 +236,14 @@ public class Forge implements ApplicationListener {
|
||||
Gdx.input.setOnscreenKeyboardVisible(true);
|
||||
}
|
||||
|
||||
public static void endKeyInput() {
|
||||
if (keyInputAdapter == null) { return; }
|
||||
public static boolean endKeyInput() {
|
||||
if (keyInputAdapter == null) { return false; }
|
||||
keyInputAdapter.onInputEnd();
|
||||
keyInputAdapter = null;
|
||||
MainInputProcessor.keyTyped = false;
|
||||
MainInputProcessor.lastKeyTyped = '\0';
|
||||
Gdx.input.setOnscreenKeyboardVisible(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static abstract class KeyInputAdapter {
|
||||
@@ -270,6 +274,10 @@ public class Forge implements ApplicationListener {
|
||||
|
||||
@Override
|
||||
public boolean keyDown(int keyCode) {
|
||||
if (keyCode == Keys.MENU) {
|
||||
showMenu();
|
||||
return true;
|
||||
}
|
||||
if (keyInputAdapter == null) {
|
||||
//if no active key input adapter, give current screen or overlay a chance to handle key
|
||||
FContainer container = FOverlay.getTopOverlay();
|
||||
|
||||
@@ -150,7 +150,9 @@ public abstract class FScreen extends FContainer {
|
||||
|
||||
@Override
|
||||
public boolean keyDown(int keyCode) {
|
||||
if (keyCode == Keys.ESCAPE) {
|
||||
if (keyCode == Keys.ESCAPE || keyCode == Keys.BACK) {
|
||||
if (Forge.endKeyInput()) { return true; }
|
||||
|
||||
Forge.back(); //go back on escape by default
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -181,6 +181,9 @@ public class MatchScreen extends FScreen {
|
||||
return prompt.getBtnCancel().trigger(); //trigger Cancel if can't trigger OK
|
||||
case Keys.ESCAPE:
|
||||
return prompt.getBtnCancel().trigger(); //otherwise trigger Cancel
|
||||
case Keys.BACK:
|
||||
FControl.undoLastAction(); //let back trigger undo instead of going back a screen
|
||||
return true;
|
||||
case Keys.A: //alpha strike on Ctrl+A
|
||||
if (KeyInputAdapter.isCtrlKeyDown()) {
|
||||
FControl.alphaStrike();
|
||||
|
||||
@@ -270,8 +270,11 @@ public class FOptionPane extends FDialog {
|
||||
}
|
||||
return true;
|
||||
case Keys.ESCAPE:
|
||||
case Keys.BACK:
|
||||
if (Forge.endKeyInput()) { return true; }
|
||||
|
||||
if (isButtonEnabled(buttons.length - 1)) {
|
||||
setResult(buttons.length - 1); //set result to final option on Escape
|
||||
setResult(buttons.length - 1); //set result to final option on Escape or Back
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.util.Stack;
|
||||
import com.badlogic.gdx.Input.Keys;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
|
||||
import forge.Forge;
|
||||
import forge.Forge.Graphics;
|
||||
import forge.assets.FSkinColor;
|
||||
import forge.assets.FSkinColor.Colors;
|
||||
@@ -108,7 +109,9 @@ public abstract class FOverlay extends FContainer {
|
||||
|
||||
@Override
|
||||
public boolean keyDown(int keyCode) {
|
||||
if (keyCode == Keys.ESCAPE) {
|
||||
if (keyCode == Keys.ESCAPE || keyCode == Keys.BACK) {
|
||||
if (Forge.endKeyInput()) { return true; }
|
||||
|
||||
hide(); //hide on escape by default
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user