mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2025-10-30 08:11:25 +00:00
keyboard/gameepad input for menu
This commit is contained in:
parent
68ce996c4c
commit
0e33a33270
21 changed files with 92 additions and 16 deletions
|
|
@ -1,5 +1,6 @@
|
|||
package gui;
|
||||
|
||||
import hxd.Key;
|
||||
import src.MarbleGame;
|
||||
import hxd.res.BitmapFont;
|
||||
import h3d.Vector;
|
||||
|
|
@ -108,6 +109,7 @@ class AboutMenuOptionsGui extends GuiImage {
|
|||
backButton.vertSizing = Bottom;
|
||||
backButton.horizSizing = Right;
|
||||
backButton.gamepadAccelerator = ["B"];
|
||||
backButton.accelerators = [Key.ESCAPE, Key.BACKSPACE];
|
||||
if (pauseGui)
|
||||
backButton.pressedAction = (e) -> {
|
||||
MarbleGame.canvas.popDialog(this);
|
||||
|
|
|
|||
|
|
@ -116,6 +116,7 @@ class AchievementsGui extends GuiImage {
|
|||
backButton.vertSizing = Bottom;
|
||||
backButton.horizSizing = Right;
|
||||
backButton.gamepadAccelerator = ["B"];
|
||||
backButton.accelerators = [hxd.Key.ESCAPE, hxd.Key.BACKSPACE];
|
||||
if (isPause)
|
||||
backButton.pressedAction = (e) -> {
|
||||
MarbleGame.canvas.popDialog(this);
|
||||
|
|
@ -129,6 +130,8 @@ class AchievementsGui extends GuiImage {
|
|||
nextButton.position = new Vector(960, 0);
|
||||
nextButton.vertSizing = Bottom;
|
||||
nextButton.horizSizing = Right;
|
||||
nextButton.accelerators = [hxd.Key.ENTER];
|
||||
nextButton.gamepadAccelerator = ["X"];
|
||||
nextButton.pressedAction = (e) -> {
|
||||
var desc = "Select an achievement from the list.";
|
||||
var selection = curSelection;
|
||||
|
|
|
|||
|
|
@ -84,6 +84,7 @@ class DifficultySelectGui extends GuiImage {
|
|||
backButton.vertSizing = Bottom;
|
||||
backButton.horizSizing = Right;
|
||||
backButton.gamepadAccelerator = ["B"];
|
||||
backButton.accelerators = [hxd.Key.ESCAPE, hxd.Key.BACKSPACE];
|
||||
backButton.pressedAction = (e) -> MarbleGame.canvas.setContent(new MainMenuGui());
|
||||
bottomBar.addChild(backButton);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -153,6 +153,7 @@ class EndGameGui extends GuiImage {
|
|||
retryButton.vertSizing = Bottom;
|
||||
retryButton.horizSizing = Right;
|
||||
retryButton.gamepadAccelerator = ["B"];
|
||||
retryButton.accelerators = [hxd.Key.ESCAPE, hxd.Key.BACKSPACE];
|
||||
retryButton.pressedAction = (e) -> restartFunc(retryButton);
|
||||
bottomBar.addChild(retryButton);
|
||||
|
||||
|
|
@ -166,6 +167,8 @@ class EndGameGui extends GuiImage {
|
|||
nextButton.position = new Vector(960, 0);
|
||||
nextButton.vertSizing = Bottom;
|
||||
nextButton.horizSizing = Right;
|
||||
nextButton.gamepadAccelerator = ["A"];
|
||||
nextButton.accelerators = [hxd.Key.ENTER];
|
||||
nextButton.pressedAction = (e) -> continueFunc(nextButton);
|
||||
bottomBar.addChild(nextButton);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ class GuiXboxButton extends GuiControl {
|
|||
|
||||
public var buttonSounds:Bool = true;
|
||||
|
||||
public var accelerator:Int = 0;
|
||||
public var accelerators:Array<Int> = [];
|
||||
public var gamepadAccelerator:Array<String> = [];
|
||||
public var acceleratorWasPressed = false;
|
||||
|
||||
|
|
@ -116,16 +116,21 @@ class GuiXboxButton extends GuiControl {
|
|||
pressed = false;
|
||||
}
|
||||
if (!disabled) {
|
||||
if (acceleratorWasPressed && (accelerator != 0 && hxd.Key.isReleased(accelerator)) || Gamepad.isReleased(gamepadAccelerator)) {
|
||||
if (acceleratorWasPressed
|
||||
&& (accelerators.length != 0 && accelerators.map(x -> hxd.Key.isReleased(x)).contains(true))
|
||||
|| Gamepad.isReleased(gamepadAccelerator)) {
|
||||
if (this.pressedAction != null) {
|
||||
this.pressedAction(new GuiEvent(this));
|
||||
}
|
||||
} else if ((accelerator != 0 && hxd.Key.isPressed(accelerator)) || Gamepad.isPressed(gamepadAccelerator)) {
|
||||
} else if (accelerators.length != 0
|
||||
&& accelerators.map(x -> hxd.Key.isPressed(x)).contains(true)
|
||||
|| Gamepad.isPressed(gamepadAccelerator)) {
|
||||
acceleratorWasPressed = true;
|
||||
}
|
||||
}
|
||||
if (acceleratorWasPressed) {
|
||||
if ((accelerator != 0 && hxd.Key.isReleased(accelerator)) || Gamepad.isReleased(gamepadAccelerator))
|
||||
if ((accelerators.length != 0 && accelerators.map(x -> hxd.Key.isReleased(x)).contains(true))
|
||||
|| Gamepad.isReleased(gamepadAccelerator))
|
||||
acceleratorWasPressed = false;
|
||||
}
|
||||
super.update(dt, mouseState);
|
||||
|
|
|
|||
|
|
@ -1,9 +1,15 @@
|
|||
package gui;
|
||||
|
||||
import src.Gamepad;
|
||||
import hxd.Key;
|
||||
import gui.GuiControl.MouseState;
|
||||
import h3d.Vector;
|
||||
|
||||
class GuiXboxList extends GuiControl {
|
||||
var currentOffset:Float = 0;
|
||||
var selected:Int = 0;
|
||||
|
||||
var buttons:Array<GuiXboxListButton> = [];
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
|
|
@ -14,8 +20,30 @@ class GuiXboxList extends GuiControl {
|
|||
btn.position = new Vector(0, currentOffset + addOffset);
|
||||
btn.extent = new Vector(502, 94);
|
||||
btn.pressedAction = func;
|
||||
btn.list = this;
|
||||
this.addChild(btn);
|
||||
buttons.push(btn);
|
||||
currentOffset += 60 + addOffset;
|
||||
return btn;
|
||||
}
|
||||
|
||||
override function update(dt:Float, mouseState:MouseState) {
|
||||
super.update(dt, mouseState);
|
||||
|
||||
var prevSelected = selected;
|
||||
if (Key.isPressed(Key.DOWN) || Gamepad.isPressed(["dpadDown"]))
|
||||
selected++;
|
||||
if (Key.isPressed(Key.UP) || Gamepad.isPressed(["dpadUp"]))
|
||||
selected--;
|
||||
if (selected < 0)
|
||||
selected = buttons.length - 1;
|
||||
if (selected >= buttons.length)
|
||||
selected = 0;
|
||||
if (prevSelected != selected) {
|
||||
buttons[prevSelected].selected = false;
|
||||
buttons[selected].selected = true;
|
||||
}
|
||||
if (Key.isPressed(Key.ENTER) || Gamepad.isPressed(["A"]))
|
||||
buttons[selected].pressedAction(new GuiEvent(buttons[selected]));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,12 +20,16 @@ class GuiXboxListButton extends GuiControl {
|
|||
public var disabled:Bool = false;
|
||||
|
||||
public var pressed:Bool = false;
|
||||
public var selected:Bool = false;
|
||||
|
||||
public var buttonSounds:Bool = true;
|
||||
|
||||
public var accelerator:Int = 0;
|
||||
public var gamepadAccelerator:Array<String> = [];
|
||||
public var acceleratorWasPressed = false;
|
||||
public var list:GuiXboxList;
|
||||
|
||||
var _prevMousePos:Vector;
|
||||
|
||||
public function new(icon:Int, text:String) {
|
||||
super();
|
||||
|
|
@ -76,7 +80,20 @@ class GuiXboxListButton extends GuiControl {
|
|||
AudioManager.playSound(ResourceLoader.getResource("data/sound/buttonpress.wav", ResourceLoader.getAudio, this.soundResources));
|
||||
}
|
||||
}
|
||||
if (renderRect.inRect(mouseState.position) && !disabled) {
|
||||
if (_prevMousePos == null || !_prevMousePos.equals(mouseState.position)) {
|
||||
if (renderRect.inRect(mouseState.position) && !selected) {
|
||||
if (list != null) {
|
||||
list.buttons[list.selected].selected = false;
|
||||
list.selected = list.buttons.indexOf(this);
|
||||
}
|
||||
this.selected = true;
|
||||
}
|
||||
if (!renderRect.inRect(mouseState.position) && selected) {
|
||||
this.selected = false;
|
||||
}
|
||||
_prevMousePos = mouseState.position.clone();
|
||||
}
|
||||
if (selected && !disabled) {
|
||||
if (Key.isDown(Key.MOUSE_LEFT)) {
|
||||
this.button.anim.currentFrame = 1;
|
||||
this.buttonIcon.anim.currentFrame = 1;
|
||||
|
|
|
|||
|
|
@ -142,7 +142,8 @@ class HelpCreditsGui extends GuiImage {
|
|||
backButton.position = new Vector(960, 0);
|
||||
backButton.vertSizing = Bottom;
|
||||
backButton.horizSizing = Right;
|
||||
backButton.gamepadAccelerator = ["OK"];
|
||||
backButton.gamepadAccelerator = ["A"];
|
||||
backButton.accelerators = [hxd.Key.ENTER];
|
||||
if (pauseGui)
|
||||
if (index == 5)
|
||||
backButton.pressedAction = (e) -> {
|
||||
|
|
|
|||
|
|
@ -143,7 +143,8 @@ class InputOptionsGui extends GuiImage {
|
|||
backButton.position = new Vector(960, 0);
|
||||
backButton.vertSizing = Bottom;
|
||||
backButton.horizSizing = Right;
|
||||
backButton.gamepadAccelerator = ["OK"];
|
||||
backButton.gamepadAccelerator = ["A"];
|
||||
backButton.accelerators = [hxd.Key.ENTER];
|
||||
if (pauseGui)
|
||||
backButton.pressedAction = (e) -> {
|
||||
Settings.applySettings();
|
||||
|
|
|
|||
|
|
@ -181,6 +181,7 @@ class KeyBindingsGui extends GuiImage {
|
|||
backButton.vertSizing = Bottom;
|
||||
backButton.horizSizing = Right;
|
||||
backButton.gamepadAccelerator = ["B"];
|
||||
backButton.accelerators = [hxd.Key.ESCAPE, hxd.Key.BACKSPACE];
|
||||
if (pauseGui)
|
||||
backButton.pressedAction = (e) -> {
|
||||
MarbleGame.canvas.popDialog(this);
|
||||
|
|
|
|||
|
|
@ -136,6 +136,7 @@ class LevelSelectGui extends GuiImage {
|
|||
backButton.vertSizing = Bottom;
|
||||
backButton.horizSizing = Right;
|
||||
backButton.gamepadAccelerator = ["B"];
|
||||
backButton.accelerators = [hxd.Key.ESCAPE, hxd.Key.BACKSPACE];
|
||||
backButton.pressedAction = (e) -> MarbleGame.canvas.setContent(new DifficultySelectGui());
|
||||
bottomBar.addChild(backButton);
|
||||
|
||||
|
|
@ -143,6 +144,7 @@ class LevelSelectGui extends GuiImage {
|
|||
recordButton.position = new Vector(560, 0);
|
||||
recordButton.vertSizing = Bottom;
|
||||
recordButton.horizSizing = Right;
|
||||
backButton.gamepadAccelerator = ["X"];
|
||||
recordButton.pressedAction = (e) -> {
|
||||
MarbleGame.instance.toRecord = true;
|
||||
MarbleGame.canvas.pushDialog(new MessageBoxOkDlg("The next mission you play will be recorded."));
|
||||
|
|
@ -159,6 +161,8 @@ class LevelSelectGui extends GuiImage {
|
|||
nextButton.position = new Vector(960, 0);
|
||||
nextButton.vertSizing = Bottom;
|
||||
nextButton.horizSizing = Right;
|
||||
nextButton.gamepadAccelerator = ["A"];
|
||||
nextButton.accelerators = [hxd.Key.ENTER];
|
||||
nextButton.pressedAction = (e) -> {
|
||||
MarbleGame.instance.playMission(curMission);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -330,7 +330,8 @@ class MarblePickerGui extends GuiImage {
|
|||
backButton.position = new Vector(960, 0);
|
||||
backButton.vertSizing = Bottom;
|
||||
backButton.horizSizing = Right;
|
||||
backButton.gamepadAccelerator = ["OK"];
|
||||
backButton.gamepadAccelerator = ["A"];
|
||||
backButton.accelerators = [hxd.Key.ENTER];
|
||||
backButton.pressedAction = (e) -> {
|
||||
this.bmp.visible = true;
|
||||
MarbleGame.instance.setPreviewMission(prevPreview, () -> {
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ class MessageBoxOkDlg extends GuiImage {
|
|||
okButton.position = new Vector(211, 248);
|
||||
okButton.extent = new Vector(120, 94);
|
||||
okButton.vertSizing = Top;
|
||||
okButton.accelerator = hxd.Key.ENTER;
|
||||
okButton.accelerators = [hxd.Key.ENTER];
|
||||
okButton.gamepadAccelerator = ["A"];
|
||||
okButton.pressedAction = (sender) -> {
|
||||
MarbleGame.canvas.popDialog(this);
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ class MessageBoxYesNoDlg extends GuiImage {
|
|||
okButton.position = new Vector(211, 248);
|
||||
okButton.extent = new Vector(120, 94);
|
||||
okButton.vertSizing = Top;
|
||||
okButton.accelerator = hxd.Key.ENTER;
|
||||
okButton.accelerators = [hxd.Key.ENTER];
|
||||
okButton.gamepadAccelerator = ["A"];
|
||||
okButton.pressedAction = (sender) -> {
|
||||
MarbleGame.canvas.popDialog(this);
|
||||
|
|
@ -50,7 +50,7 @@ class MessageBoxYesNoDlg extends GuiImage {
|
|||
cancelButton.position = new Vector(321, 248);
|
||||
cancelButton.extent = new Vector(120, 94);
|
||||
cancelButton.vertSizing = Top;
|
||||
cancelButton.accelerator = hxd.Key.ENTER;
|
||||
cancelButton.accelerators = [hxd.Key.ESCAPE, hxd.Key.BACKSPACE];
|
||||
cancelButton.gamepadAccelerator = ["A"];
|
||||
cancelButton.pressedAction = (sender) -> {
|
||||
MarbleGame.canvas.popDialog(this);
|
||||
|
|
|
|||
|
|
@ -102,7 +102,8 @@ class MiscOptionsGui extends GuiImage {
|
|||
backButton.position = new Vector(960, 0);
|
||||
backButton.vertSizing = Bottom;
|
||||
backButton.horizSizing = Right;
|
||||
backButton.gamepadAccelerator = ["OK"];
|
||||
backButton.gamepadAccelerator = ["A"];
|
||||
backButton.accelerators = [hxd.Key.ENTER];
|
||||
if (pauseGui)
|
||||
backButton.pressedAction = (e) -> {
|
||||
Settings.applySettings();
|
||||
|
|
|
|||
|
|
@ -103,6 +103,7 @@ class OptionsListGui extends GuiImage {
|
|||
backButton.vertSizing = Bottom;
|
||||
backButton.horizSizing = Right;
|
||||
backButton.gamepadAccelerator = ["B"];
|
||||
backButton.accelerators = [hxd.Key.ESCAPE, hxd.Key.BACKSPACE];
|
||||
if (pauseGui)
|
||||
backButton.pressedAction = (e) -> {
|
||||
MarbleGame.canvas.popDialog(this);
|
||||
|
|
|
|||
|
|
@ -131,6 +131,7 @@ class ReplayCenterGui extends GuiImage {
|
|||
backButton.vertSizing = Bottom;
|
||||
backButton.horizSizing = Right;
|
||||
backButton.gamepadAccelerator = ["B"];
|
||||
backButton.accelerators = [hxd.Key.ESCAPE, hxd.Key.BACKSPACE];
|
||||
backButton.pressedAction = (e) -> MarbleGame.canvas.setContent(new MainMenuGui());
|
||||
bottomBar.addChild(backButton);
|
||||
|
||||
|
|
@ -138,6 +139,8 @@ class ReplayCenterGui extends GuiImage {
|
|||
nextButton.position = new Vector(960, 0);
|
||||
nextButton.vertSizing = Bottom;
|
||||
nextButton.horizSizing = Right;
|
||||
nextButton.gamepadAccelerator = ["A"];
|
||||
nextButton.accelerators = [hxd.Key.ENTER];
|
||||
nextButton.pressedAction = (e) -> {
|
||||
if (selectedIdx != -1) {
|
||||
var repl = replayList[selectedIdx];
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ class ReplayNameDlg extends GuiImage {
|
|||
okButton.position = new Vector(211, 248);
|
||||
okButton.extent = new Vector(120, 94);
|
||||
okButton.vertSizing = Top;
|
||||
okButton.accelerator = hxd.Key.ENTER;
|
||||
okButton.accelerators = [hxd.Key.ENTER];
|
||||
okButton.gamepadAccelerator = ["A"];
|
||||
okButton.pressedAction = (sender) -> {
|
||||
if (StringTools.trim(textInput.text.text) != "") {
|
||||
|
|
@ -79,7 +79,7 @@ class ReplayNameDlg extends GuiImage {
|
|||
cancelButton.position = new Vector(321, 248);
|
||||
cancelButton.extent = new Vector(120, 94);
|
||||
cancelButton.vertSizing = Top;
|
||||
cancelButton.accelerator = hxd.Key.ENTER;
|
||||
cancelButton.accelerators = [hxd.Key.ENTER];
|
||||
cancelButton.gamepadAccelerator = ["A"];
|
||||
cancelButton.pressedAction = (sender) -> {
|
||||
MarbleGame.canvas.popDialog(this);
|
||||
|
|
|
|||
|
|
@ -60,6 +60,8 @@ class TouchCtrlsEditGui extends GuiImage {
|
|||
nextButton.position = new Vector(960, 100);
|
||||
nextButton.vertSizing = Bottom;
|
||||
nextButton.horizSizing = Right;
|
||||
nextButton.gamepadAccelerator = ["A"];
|
||||
nextButton.accelerators = [hxd.Key.ENTER];
|
||||
nextButton.pressedAction = (e) -> {
|
||||
if (paused) {
|
||||
MarbleGame.canvas.popDialog(this);
|
||||
|
|
|
|||
|
|
@ -72,7 +72,8 @@ class VersionGui extends GuiImage {
|
|||
backButton.position = new Vector(960, 0);
|
||||
backButton.vertSizing = Bottom;
|
||||
backButton.horizSizing = Right;
|
||||
backButton.gamepadAccelerator = ["OK"];
|
||||
backButton.gamepadAccelerator = ["A"];
|
||||
backButton.accelerators = [hxd.Key.ENTER];
|
||||
backButton.pressedAction = (e) -> MarbleGame.canvas.setContent(new MainMenuGui());
|
||||
bottomBar.addChild(backButton);
|
||||
|
||||
|
|
|
|||
|
|
@ -217,7 +217,8 @@ class VideoOptionsGui extends GuiImage {
|
|||
backButton.position = new Vector(960, 0);
|
||||
backButton.vertSizing = Bottom;
|
||||
backButton.horizSizing = Right;
|
||||
backButton.gamepadAccelerator = ["OK"];
|
||||
backButton.gamepadAccelerator = ["A"];
|
||||
backButton.accelerators = [hxd.Key.ENTER];
|
||||
if (pauseGui)
|
||||
backButton.pressedAction = (e) -> {
|
||||
Settings.applySettings();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue