From 68ce996c4cde551b6048a1966040c696a0c5193c Mon Sep 17 00:00:00 2001
From: RandomityGuy <31925790+RandomityGuy@users.noreply.github.com>
Date: Tue, 4 Jul 2023 23:26:45 +0530
Subject: [PATCH] add key rebinding ui
---
src/MarbleWorld.hx | 32 +++---
src/gui/GuiXboxList.hx | 1 +
src/gui/KeyBindingsGui.hx | 207 +++++++++++++++++++++++++++++++++++
src/gui/OptionsListGui.hx | 12 ++
src/gui/RemapDlg.hx | 32 +++---
src/gui/TouchCtrlsEditGui.hx | 100 ++++++++++-------
6 files changed, 313 insertions(+), 71 deletions(-)
create mode 100644 src/gui/KeyBindingsGui.hx
diff --git a/src/MarbleWorld.hx b/src/MarbleWorld.hx
index 0a9858f7..0688daea 100644
--- a/src/MarbleWorld.hx
+++ b/src/MarbleWorld.hx
@@ -998,23 +998,23 @@ class MarbleWorld extends Scheduler {
ProfilerUI.measure("updateTimer");
this.updateTimer(dt);
- if ((Key.isPressed(Settings.controlsSettings.respawn) || Gamepad.isPressed(Settings.gamepadSettings.respawn))
- && this.finishTime == null) {
- performRestart();
- return;
- }
+ // if ((Key.isPressed(Settings.controlsSettings.respawn) || Gamepad.isPressed(Settings.gamepadSettings.respawn))
+ // && this.finishTime == null) {
+ // performRestart();
+ // return;
+ // }
- if ((Key.isDown(Settings.controlsSettings.respawn)
- || MarbleGame.instance.touchInput.restartButton.pressed
- || Gamepad.isDown(Settings.gamepadSettings.respawn))
- && !this.isWatching
- && this.finishTime == null) {
- if (timeState.timeSinceLoad - this.respawnPressedTime > 1.5) {
- this.restart(true);
- this.respawnPressedTime = Math.POSITIVE_INFINITY;
- return;
- }
- }
+ // if ((Key.isDown(Settings.controlsSettings.respawn)
+ // || MarbleGame.instance.touchInput.restartButton.pressed
+ // || Gamepad.isDown(Settings.gamepadSettings.respawn))
+ // && !this.isWatching
+ // && this.finishTime == null) {
+ // if (timeState.timeSinceLoad - this.respawnPressedTime > 1.5) {
+ // this.restart(true);
+ // this.respawnPressedTime = Math.POSITIVE_INFINITY;
+ // return;
+ // }
+ // }
this.tickSchedule(timeState.currentAttemptTime);
diff --git a/src/gui/GuiXboxList.hx b/src/gui/GuiXboxList.hx
index fa173b3c..b69053ca 100644
--- a/src/gui/GuiXboxList.hx
+++ b/src/gui/GuiXboxList.hx
@@ -16,5 +16,6 @@ class GuiXboxList extends GuiControl {
btn.pressedAction = func;
this.addChild(btn);
currentOffset += 60 + addOffset;
+ return btn;
}
}
diff --git a/src/gui/KeyBindingsGui.hx b/src/gui/KeyBindingsGui.hx
new file mode 100644
index 00000000..20a05a0f
--- /dev/null
+++ b/src/gui/KeyBindingsGui.hx
@@ -0,0 +1,207 @@
+package gui;
+
+import hxd.Key;
+import src.MarbleGame;
+import hxd.res.BitmapFont;
+import h3d.Vector;
+import src.ResourceLoader;
+import src.Settings;
+import src.Util;
+
+class KeyBindingsGui extends GuiImage {
+ var innerCtrl:GuiControl;
+ var btnListLeft:GuiXboxList;
+ var btnListRight:GuiXboxList;
+
+ public function new(pauseGui:Bool = false) {
+ var res = ResourceLoader.getImage("data/ui/xbox/BG_fadeOutSoftEdge.png").resource.toTile();
+ super(res);
+ var domcasual32fontdata = ResourceLoader.getFileEntry("data/font/DomCasualD.fnt");
+ var domcasual32b = new BitmapFont(domcasual32fontdata.entry);
+ @:privateAccess domcasual32b.loader = ResourceLoader.loader;
+ var domcasual32 = domcasual32b.toSdfFont(cast 42 * Settings.uiScale, MultiChannel);
+
+ this.horizSizing = Width;
+ this.vertSizing = Height;
+ this.position = new Vector();
+ this.extent = new Vector(640, 480);
+
+ function getConflictingBinding(bindingName:String, key:Int) {
+ if (Settings.controlsSettings.forward == key && bindingName != "Move Forward")
+ return "Move Forward";
+ if (Settings.controlsSettings.backward == key && bindingName != "Move Backward")
+ return "Move Backward";
+ if (Settings.controlsSettings.left == key && bindingName != "Move Left")
+ return "Move Left";
+ if (Settings.controlsSettings.right == key && bindingName != "Move Right")
+ return "Move Right";
+ if (Settings.controlsSettings.camForward == key && bindingName != "Rotate Camera Up")
+ return "Rotate Camera Up";
+ if (Settings.controlsSettings.camBackward == key && bindingName != "Rotate Camera Down")
+ return "Rotate Camera Down";
+ if (Settings.controlsSettings.camLeft == key && bindingName != "Rotate Camera Left")
+ return "Rotate Camera Left";
+ if (Settings.controlsSettings.camRight == key && bindingName != "Rotate Camera Right")
+ return "Rotate Camera Right";
+ if (Settings.controlsSettings.jump == key && bindingName != "Jump")
+ return "Jump";
+ if (Settings.controlsSettings.powerup == key && bindingName != "Use PowerUp")
+ return "Use PowerUp";
+ if (Settings.controlsSettings.freelook == key && bindingName != "Free Look")
+ return "Free Look";
+ if (Settings.controlsSettings.rewind == key && bindingName != "Rewind")
+ return "Rewind";
+
+ return null;
+ }
+
+ function remapFunc(bindingName:String, bindingFunc:Int->Void, ctrl:GuiXboxListButton) {
+ var remapDlg = new RemapDlg(bindingName);
+ MarbleGame.canvas.pushDialog(remapDlg);
+ remapDlg.remapCallback = (key) -> {
+ MarbleGame.canvas.popDialog(remapDlg);
+
+ if (key == Key.ESCAPE)
+ return;
+
+ var conflicting = getConflictingBinding(bindingName, key);
+ if (conflicting == null) {
+ ctrl.buttonText.text.text = '${bindingName}: ${Util.getKeyForButton2(key)}';
+ bindingFunc(key);
+ } else {
+ var yesNoDlg = new MessageBoxYesNoDlg('"${Util.getKeyForButton2(key)}" is already bound to "${conflicting}"!
Do you want to undo this mapping?',
+ () -> {
+ ctrl.buttonText.text.text = '${bindingName}: ${Util.getKeyForButton2(key)}';
+ bindingFunc(key);
+ }, () -> {});
+ MarbleGame.canvas.pushDialog(yesNoDlg);
+ }
+ }
+ }
+
+ var scene2d = MarbleGame.canvas.scene2d;
+
+ var offsetX = (scene2d.width - 1280) / 2;
+ var offsetY = (scene2d.height - 720) / 2;
+
+ var subX = 640 - (scene2d.width - offsetX) * 640 / scene2d.width;
+ var subY = 480 - (scene2d.height - offsetY) * 480 / scene2d.height;
+
+ innerCtrl = new GuiControl();
+ innerCtrl.position = new Vector(offsetX, offsetY);
+ innerCtrl.extent = new Vector(640 - subX, 480 - subY);
+ innerCtrl.horizSizing = Width;
+ innerCtrl.vertSizing = Height;
+ this.addChild(innerCtrl);
+
+ var coliseumfontdata = ResourceLoader.getFileEntry("data/font/ColiseumRR.fnt");
+ var coliseumb = new BitmapFont(coliseumfontdata.entry);
+ @:privateAccess coliseumb.loader = ResourceLoader.loader;
+ var coliseum = coliseumb.toSdfFont(cast 44 * Settings.uiScale, MultiChannel);
+
+ var rootTitle = new GuiText(coliseum);
+ rootTitle.position = new Vector(100, 30);
+ rootTitle.extent = new Vector(1120, 80);
+ rootTitle.text.textColor = 0xFFFFFF;
+ rootTitle.text.text = "KEY BINDINGS";
+ rootTitle.text.alpha = 0.5;
+ innerCtrl.addChild(rootTitle);
+
+ btnListLeft = new GuiXboxList();
+ btnListLeft.position = new Vector(70 - offsetX, 135);
+ btnListLeft.horizSizing = Left;
+ btnListLeft.extent = new Vector(502, 500);
+ innerCtrl.addChild(btnListLeft);
+
+ btnListRight = new GuiXboxList();
+ btnListRight.position = new Vector(-400 - offsetX, 135);
+ btnListRight.horizSizing = Left;
+ btnListRight.extent = new Vector(502, 500);
+ innerCtrl.addChild(btnListRight);
+
+ var b1 = btnListRight.addButton(0, 'Move Forward: ${Util.getKeyForButton2(Settings.controlsSettings.forward)}', (e) -> {});
+ b1.pressedAction = (e) -> {
+ remapFunc("Move Forward", (key) -> Settings.controlsSettings.forward = key, b1);
+ };
+
+ var b2 = btnListRight.addButton(0, 'Move Backward: ${Util.getKeyForButton2(Settings.controlsSettings.backward)}', (e) -> {});
+ b2.pressedAction = (e) -> {
+ remapFunc("Move Backward", (key) -> Settings.controlsSettings.backward = key, b2);
+ };
+ var b3 = btnListRight.addButton(0, 'Move Left: ${Util.getKeyForButton2(Settings.controlsSettings.left)}', (e) -> {});
+ b3.pressedAction = (e) -> {
+ remapFunc("Move Left", (key) -> Settings.controlsSettings.left = key, b3);
+ };
+ var b4 = btnListRight.addButton(0, 'Move Right: ${Util.getKeyForButton2(Settings.controlsSettings.right)}', (e) -> {});
+ b4.pressedAction = (e) -> {
+ remapFunc("Move Right", (key) -> Settings.controlsSettings.right = key, b4);
+ }
+ var b5 = btnListRight.addButton(0, 'Jump: ${Util.getKeyForButton2(Settings.controlsSettings.jump)}', (e) -> {});
+ b5.pressedAction = (e) -> {
+ remapFunc("Jump", (key) -> Settings.controlsSettings.jump = key, b5);
+ };
+ var b6 = btnListRight.addButton(0, 'Blast: ${Util.getKeyForButton2(Settings.controlsSettings.blast)}', (e) -> {});
+ b6.pressedAction = (e) -> {
+ remapFunc("Blast", (key) -> Settings.controlsSettings.blast = key, b6);
+ }
+ var b7 = btnListLeft.addButton(0, 'Look Up: ${Util.getKeyForButton2(Settings.controlsSettings.camForward)}', (e) -> {});
+ b7.pressedAction = (e) -> {
+ remapFunc("Look Up", (key) -> Settings.controlsSettings.camForward = key, b7);
+ }
+ var b8 = btnListLeft.addButton(0, 'Look Down: ${Util.getKeyForButton2(Settings.controlsSettings.camBackward)}', (e) -> {});
+ b8.pressedAction = (e) -> {
+ remapFunc("Look Down", (key) -> Settings.controlsSettings.camBackward = key, b8);
+ }
+ var b9 = btnListLeft.addButton(0, 'Look Left: ${Util.getKeyForButton2(Settings.controlsSettings.camLeft)}', (e) -> {});
+ b9.pressedAction = (e) -> {
+ remapFunc("Look Left", (key) -> Settings.controlsSettings.camLeft = key, b9);
+ }
+ var b10 = btnListLeft.addButton(0, 'Look Right: ${Util.getKeyForButton2(Settings.controlsSettings.camRight)}', (e) -> {});
+ b10.pressedAction = (e) -> {
+ remapFunc("Look Right", (key) -> Settings.controlsSettings.camRight = key, b10);
+ }
+ var b11 = btnListLeft.addButton(0, 'Use Powerup: ${Util.getKeyForButton2(Settings.controlsSettings.powerup)}', (e) -> {});
+ b11.pressedAction = (e) -> {
+ remapFunc("Use Powerup", (key) -> Settings.controlsSettings.powerup = key, b11);
+ }
+ var b12 = btnListLeft.addButton(0, 'Rewind: ${Util.getKeyForButton2(Settings.controlsSettings.rewind)}', (e) -> {});
+ b12.pressedAction = (e) -> {
+ remapFunc("Rewind", (key) -> Settings.controlsSettings.rewind = key, b12);
+ }
+
+ var bottomBar = new GuiControl();
+ bottomBar.position = new Vector(0, 590);
+ bottomBar.extent = new Vector(640, 200);
+ bottomBar.horizSizing = Width;
+ bottomBar.vertSizing = Bottom;
+ innerCtrl.addChild(bottomBar);
+
+ var backButton = new GuiXboxButton("Back", 160);
+ backButton.position = new Vector(400, 0);
+ backButton.vertSizing = Bottom;
+ backButton.horizSizing = Right;
+ backButton.gamepadAccelerator = ["B"];
+ if (pauseGui)
+ backButton.pressedAction = (e) -> {
+ MarbleGame.canvas.popDialog(this);
+ MarbleGame.canvas.pushDialog(new OptionsListGui(true));
+ }
+ else
+ backButton.pressedAction = (e) -> MarbleGame.canvas.setContent(new OptionsListGui());
+ bottomBar.addChild(backButton);
+ }
+
+ override function onResize(width:Int, height:Int) {
+ var offsetX = (width - 1280) / 2;
+ var offsetY = (height - 720) / 2;
+
+ var subX = 640 - (width - offsetX) * 640 / width;
+ var subY = 480 - (height - offsetY) * 480 / height;
+ innerCtrl.position = new Vector(offsetX, offsetY);
+ innerCtrl.extent = new Vector(640 - subX, 480 - subY);
+ btnListLeft.position = new Vector(70 - offsetX, 135);
+ btnListLeft.position = new Vector(-400 - offsetX, 135);
+
+ super.onResize(width, height);
+ }
+}
diff --git a/src/gui/OptionsListGui.hx b/src/gui/OptionsListGui.hx
index efb945e7..8c607f8a 100644
--- a/src/gui/OptionsListGui.hx
+++ b/src/gui/OptionsListGui.hx
@@ -5,6 +5,7 @@ import hxd.res.BitmapFont;
import h3d.Vector;
import src.ResourceLoader;
import src.Settings;
+import src.Util;
class OptionsListGui extends GuiImage {
var innerCtrl:GuiControl;
@@ -64,6 +65,17 @@ class OptionsListGui extends GuiImage {
btnList.addButton(3, 'Input and Sound Options', (e) -> {
MarbleGame.canvas.setContent(new InputOptionsGui(pauseGui));
});
+ if (Util.isTouchDevice()) {
+ if (!pauseGui) {
+ btnList.addButton(3, 'Touch Controls', (e) -> {
+ MarbleGame.canvas.setContent(new TouchCtrlsEditGui(pauseGui));
+ });
+ }
+ } else {
+ btnList.addButton(3, 'Key Bindings', (e) -> {
+ MarbleGame.canvas.setContent(new KeyBindingsGui(pauseGui));
+ });
+ }
btnList.addButton(3, 'Video Options', (e) -> {
MarbleGame.canvas.setContent(new VideoOptionsGui(pauseGui));
});
diff --git a/src/gui/RemapDlg.hx b/src/gui/RemapDlg.hx
index 4484fd9f..8311f7a3 100644
--- a/src/gui/RemapDlg.hx
+++ b/src/gui/RemapDlg.hx
@@ -7,35 +7,33 @@ import h3d.Vector;
import src.ResourceLoader;
import src.Settings;
-class RemapDlg extends GuiControl {
+class RemapDlg extends GuiImage {
var remapCallback:Int->Void;
public function new(bindingName:String) {
- super();
+ var res = ResourceLoader.getImage("data/ui/xbox/roundedBG.png").resource.toTile();
+ super(res);
this.horizSizing = Width;
this.vertSizing = Height;
this.position = new Vector();
this.extent = new Vector(640, 480);
- var remapDlg = new GuiImage(ResourceLoader.getResource("data/ui/common/dialog.png", ResourceLoader.getImage, this.imageResources).toTile());
+ var arial14fontdata = ResourceLoader.getFileEntry("data/font/Arial Bold.fnt");
+ var arial14b = new BitmapFont(arial14fontdata.entry);
+ @:privateAccess arial14b.loader = ResourceLoader.loader;
+ var arial14 = arial14b.toSdfFont(cast 21 * Settings.uiScale, h2d.Font.SDFChannel.MultiChannel);
+
+ var remapDlg = new GuiImage(ResourceLoader.getResource("data/ui/xbox/popupGUI.png", ResourceLoader.getImage, this.imageResources).toTile());
remapDlg.horizSizing = Center;
remapDlg.vertSizing = Center;
- remapDlg.position = new Vector(170, 159);
- remapDlg.extent = new Vector(300, 161);
+ remapDlg.position = new Vector(70, 30);
+ remapDlg.extent = new Vector(512, 400);
this.addChild(remapDlg);
- var domcasual24fontdata = ResourceLoader.getFileEntry("data/font/DomCasualD.fnt");
- var domcasual24b = new BitmapFont(domcasual24fontdata.entry);
- @:privateAccess domcasual24b.loader = ResourceLoader.loader;
-
- var domcasual24 = domcasual24b.toSdfFont(cast 20 * Settings.uiScale, MultiChannel);
-
- var remapText = new GuiMLText(domcasual24, null);
- remapText.horizSizing = Center;
- remapText.vertSizing = Bottom;
- remapText.position = new Vector(46, 60);
- remapText.extent = new Vector(213, 23);
- remapText.text.textColor = 0;
+ var remapText = new GuiMLText(arial14, null);
+ remapText.position = new Vector(103, 85);
+ remapText.extent = new Vector(313, 186);
+ remapText.text.textColor = 0xEBEBEB;
remapText.text.text = '
Press a new key or button for
"${bindingName}"