v2.0.0: added ability to toggle fullscreen on desktop with alt+enter
This commit is contained in:
@@ -181,10 +181,16 @@ public class SPDAction extends GameAction {
|
||||
return new LinkedHashMap<>(defaultControllerBindings);
|
||||
}
|
||||
|
||||
//hard bindings for android devices
|
||||
static {
|
||||
//hard bindings for android devices
|
||||
KeyBindings.addHardBinding( Input.Keys.BACK, SPDAction.BACK );
|
||||
KeyBindings.addHardBinding( Input.Keys.MENU, SPDAction.INVENTORY );
|
||||
|
||||
//hard bindings for desktop fullscreen toggle
|
||||
//not bound to specific game actions, see PixelScene
|
||||
//Note that user-entered bindings can override these individually, and that's fine.
|
||||
KeyBindings.addHardBinding( Input.Keys.ALT_RIGHT, SPDAction.NONE );
|
||||
KeyBindings.addHardBinding( Input.Keys.ENTER, SPDAction.NONE );
|
||||
}
|
||||
|
||||
//we only save/loads keys which differ from the default configuration.
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
package com.shatteredpixel.shatteredpixeldungeon.scenes;
|
||||
|
||||
import com.badlogic.gdx.Input;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.Assets;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.Badges;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.SPDSettings;
|
||||
@@ -33,6 +34,7 @@ import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
|
||||
import com.watabou.gltextures.TextureCache;
|
||||
import com.watabou.glwrap.Blending;
|
||||
import com.watabou.input.ControllerHandler;
|
||||
import com.watabou.input.KeyEvent;
|
||||
import com.watabou.input.PointerEvent;
|
||||
import com.watabou.noosa.BitmapText;
|
||||
import com.watabou.noosa.BitmapText.Font;
|
||||
@@ -46,9 +48,11 @@ import com.watabou.noosa.Visual;
|
||||
import com.watabou.noosa.ui.Component;
|
||||
import com.watabou.noosa.ui.Cursor;
|
||||
import com.watabou.utils.Callback;
|
||||
import com.watabou.utils.DeviceCompat;
|
||||
import com.watabou.utils.GameMath;
|
||||
import com.watabou.utils.PointF;
|
||||
import com.watabou.utils.Reflection;
|
||||
import com.watabou.utils.Signal;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -82,6 +86,8 @@ public class PixelScene extends Scene {
|
||||
|
||||
protected boolean inGameScene = false;
|
||||
|
||||
private Signal.Listener<KeyEvent> fullscreenListener;
|
||||
|
||||
@Override
|
||||
public void create() {
|
||||
|
||||
@@ -162,6 +168,34 @@ public class PixelScene extends Scene {
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
//we create this here so that it is last in the scene
|
||||
if (DeviceCompat.isDesktop() && fullscreenListener == null){
|
||||
KeyEvent.addKeyListener(fullscreenListener = new Signal.Listener<KeyEvent>() {
|
||||
|
||||
private boolean alt;
|
||||
private boolean enter;
|
||||
|
||||
@Override
|
||||
public boolean onSignal(KeyEvent keyEvent) {
|
||||
|
||||
//we don't use keybindings for these as we want the user to be able to
|
||||
// bind these keys to other actions when pressed individually
|
||||
if (keyEvent.code == Input.Keys.ALT_RIGHT){
|
||||
alt = keyEvent.pressed;
|
||||
} else if (keyEvent.code == Input.Keys.ENTER){
|
||||
enter = keyEvent.pressed;
|
||||
}
|
||||
|
||||
if (alt && enter){
|
||||
SPDSettings.fullscreen(!SPDSettings.fullscreen());
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
super.update();
|
||||
//20% deadzone
|
||||
if (!Cursor.isCursorCaptured()) {
|
||||
@@ -266,6 +300,9 @@ public class PixelScene extends Scene {
|
||||
public void destroy() {
|
||||
super.destroy();
|
||||
PointerEvent.clearListeners();
|
||||
if (fullscreenListener != null){
|
||||
KeyEvent.removeKeyListener(fullscreenListener);
|
||||
}
|
||||
if (cursor != null){
|
||||
cursor.destroy();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user