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