From bc635bb77fbb5d6871de527b869caa959a5b75cd Mon Sep 17 00:00:00 2001 From: RandomityGuy <31925790+RandomityGuy@users.noreply.github.com> Date: Tue, 17 Jun 2025 22:12:30 +0530 Subject: [PATCH] preserve leaderboards view state on exit attempt fix case sensitivity issue (web) add controller bindings ui --- src/Settings.hx | 26 ++- src/fs/ManifestFileSystem.hx | 10 + src/gui/AboutMenuOptionsGui.hx | 2 +- src/gui/AchievementsGui.hx | 4 +- src/gui/ControllerBindingsGui.hx | 275 +++++++++++++++++++++++++++ src/gui/CreateMatchGui.hx | 4 +- src/gui/DifficultySelectGui.hx | 2 +- src/gui/EndGameGui.hx | 10 +- src/gui/EnterNameDlg.hx | 4 +- src/gui/EnterNamePopupDlg.hx | 2 +- src/gui/HelpCreditsGui.hx | 2 +- src/gui/InputOptionsGui.hx | 2 +- src/gui/InputSelectGui.hx | 108 +++++++++++ src/gui/JoinServerGui.hx | 4 +- src/gui/KeyBindingsGui.hx | 6 +- src/gui/LeaderboardsGui.hx | 9 +- src/gui/LevelSelectGui.hx | 8 +- src/gui/MPServerListGui.hx | 4 +- src/gui/MarblePickerGui.hx | 2 +- src/gui/MessageBoxOkDlg.hx | 2 +- src/gui/MessageBoxYesNoDlg.hx | 4 +- src/gui/MiscOptionsGui.hx | 2 +- src/gui/MultiplayerGui.hx | 2 +- src/gui/MultiplayerLevelSelectGui.hx | 8 +- src/gui/MultiplayerLoadingGui.hx | 2 +- src/gui/OptionsListGui.hx | 4 +- src/gui/PlayMissionGui.hx | 4 +- src/gui/RemapDlg.hx | 47 ++++- src/gui/ReplayCenterGui.hx | 4 +- src/gui/ReplayNameDlg.hx | 4 +- src/gui/TouchCtrlsEditGui.hx | 2 +- src/gui/TouchOptionsGui.hx | 4 +- src/gui/VersionGui.hx | 2 +- src/gui/VideoOptionsGui.hx | 2 +- 34 files changed, 517 insertions(+), 60 deletions(-) create mode 100644 src/gui/ControllerBindingsGui.hx create mode 100644 src/gui/InputSelectGui.hx diff --git a/src/Settings.hx b/src/Settings.hx index 5859ad6a..05855d18 100644 --- a/src/Settings.hx +++ b/src/Settings.hx @@ -50,6 +50,7 @@ typedef OptionsSettings = { var maxPixelRatio:Float; var huntRandom:Bool; var fastLoad:Bool; + var currentView:Int; } typedef ControlsSettings = { @@ -107,6 +108,10 @@ typedef GamepadSettings = { var respawn:Array; var blast:Array; var rewind:Array; + var ok:String; + var back:String; + var alt1:String; + var alt2:String; } typedef PlayStatistics = { @@ -144,7 +149,8 @@ class Settings { maxPixelRatio: 1, vsync: false, huntRandom: false, - fastLoad: false + fastLoad: false, + currentView: 0 }; public static var controlsSettings:ControlsSettings = { @@ -202,6 +208,10 @@ class Settings { respawn: ["back"], blast: ["X", "LB", "RB"], rewind: ["Y"], + ok: "A", + back: "B", + alt1: "X", + alt2: "Y" } public static var playStatistics:PlayStatistics = { @@ -390,6 +400,8 @@ class Settings { optionsSettings.huntRandom = false; if (optionsSettings.fastLoad == null) optionsSettings.fastLoad = false; + if (optionsSettings.currentView == null) + optionsSettings.currentView = 0; #end if (optionsSettings.maxPixelRatio == 0 #if js || optionsSettings.maxPixelRatio == null #end) optionsSettings.maxPixelRatio = 1; @@ -437,6 +449,18 @@ class Settings { if (gamepadSettings.rewind == null) { gamepadSettings.rewind = ["Y"]; } + if (gamepadSettings.ok == null) { + gamepadSettings.ok = "A"; + } + if (gamepadSettings.back == null) { + gamepadSettings.back = "B"; + } + if (gamepadSettings.alt1 == null) { + gamepadSettings.alt1 = "X"; + } + if (gamepadSettings.alt2 == null) { + gamepadSettings.alt2 = "Y"; + } if (json.stats != null) { playStatistics = json.stats; #if js diff --git a/src/fs/ManifestFileSystem.hx b/src/fs/ManifestFileSystem.hx index 6c11d878..91731951 100644 --- a/src/fs/ManifestFileSystem.hx +++ b/src/fs/ManifestFileSystem.hx @@ -137,6 +137,16 @@ class ManifestEntry extends FileEntry { bytes = Bytes.ofData(buf); if (onReady != null) onReady(); + }).catchError((e) -> { + // Try the original file path + js.Browser.window.fetch('data/' + originalFile).then((res:js.html.Response) -> { + return res.arrayBuffer(); + }).then((buf:js.lib.ArrayBuffer) -> { + loaded = true; + bytes = Bytes.ofData(buf); + if (onReady != null) + onReady(); + }); }); } #else diff --git a/src/gui/AboutMenuOptionsGui.hx b/src/gui/AboutMenuOptionsGui.hx index 78c743e8..97b0fe84 100644 --- a/src/gui/AboutMenuOptionsGui.hx +++ b/src/gui/AboutMenuOptionsGui.hx @@ -113,7 +113,7 @@ class AboutMenuOptionsGui extends GuiImage { backButton.position = new Vector(400, 0); backButton.vertSizing = Bottom; backButton.horizSizing = Right; - backButton.gamepadAccelerator = ["B"]; + backButton.gamepadAccelerator = [Settings.gamepadSettings.back]; backButton.accelerators = [Key.ESCAPE, Key.BACKSPACE]; if (pauseGui) backButton.pressedAction = (e) -> { diff --git a/src/gui/AchievementsGui.hx b/src/gui/AchievementsGui.hx index cb2ab7bb..7a4b26f1 100644 --- a/src/gui/AchievementsGui.hx +++ b/src/gui/AchievementsGui.hx @@ -143,7 +143,7 @@ class AchievementsGui extends GuiImage { backButton.position = new Vector(400, 0); backButton.vertSizing = Bottom; backButton.horizSizing = Right; - backButton.gamepadAccelerator = ["B"]; + backButton.gamepadAccelerator = [Settings.gamepadSettings.back]; backButton.accelerators = [hxd.Key.ESCAPE, hxd.Key.BACKSPACE]; if (isPause) backButton.pressedAction = (e) -> { @@ -159,7 +159,7 @@ class AchievementsGui extends GuiImage { nextButton.vertSizing = Bottom; nextButton.horizSizing = Right; nextButton.accelerators = [hxd.Key.ENTER]; - nextButton.gamepadAccelerator = ["X"]; + nextButton.gamepadAccelerator = [Settings.gamepadSettings.alt1]; nextButton.pressedAction = (e) -> { var desc = "Select an achievement from the list."; var selection = curSelection; diff --git a/src/gui/ControllerBindingsGui.hx b/src/gui/ControllerBindingsGui.hx new file mode 100644 index 00000000..4bdc8672 --- /dev/null +++ b/src/gui/ControllerBindingsGui.hx @@ -0,0 +1,275 @@ +package gui; + +import src.Gamepad; +import gui.GuiControl.MouseState; +import hxd.Key; +import src.MarbleGame; +import hxd.res.BitmapFont; +import h3d.Vector; +import src.ResourceLoader; +import src.Settings; +import src.Util; + +class ControllerBindingsGui extends GuiImage { + var innerCtrl:GuiControl; + var btnListLeft:GuiXboxList; + var btnListRight:GuiXboxList; + + var selectedColumn = 0; + var _prevMousePosition:Vector; + + 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:String) { + // For menu bindings, it's independent of the game stuff + if (["Menu OK", "Menu Back", "Menu Alt 1", "Menu Alt 2"].indexOf(bindingName) != -1) { + if (Settings.gamepadSettings.ok == key && bindingName != "Menu OK") + return "Menu OK"; + if (Settings.gamepadSettings.back == key && bindingName != "Menu Back") + return "Menu Back"; + if (Settings.gamepadSettings.alt1 == key && bindingName != "Menu Alt 1") + return "Menu Alt 1"; + if (Settings.gamepadSettings.alt2 == key && bindingName != "Menu Alt 2") + return "Menu Alt 2"; + } else { + if (Settings.gamepadSettings.jump[0] == key && bindingName != "Jump") + return "Jump"; + if (Settings.gamepadSettings.jump[1] == key && bindingName != "Jump") + return "Jump"; + if (Settings.gamepadSettings.blast[0] == key && bindingName != "Blast") + return "Blast"; + if (Settings.gamepadSettings.blast[1] == key && bindingName != "Blast") + return "Blast"; + if (Settings.gamepadSettings.powerup[0] == key && bindingName != "Use Powerup") + return "Use Powerup"; + if (Settings.gamepadSettings.powerup[1] == key && bindingName != "Use Powerup") + return "Use Powerup"; + if (Settings.gamepadSettings.rewind[0] == key && bindingName != "Rewind") + return "Rewind"; + if (Settings.gamepadSettings.rewind[1] == key && bindingName != "Rewind") + return "Rewind"; + } + + return null; + } + + function remapFunc(bindingName:String, bindingFunc:String->Void, ctrl:GuiXboxListButton) { + var remapDlg = new RemapDlg(bindingName, true); + MarbleGame.canvas.pushDialog(remapDlg); + remapDlg.controllerRemapCallback = (key) -> { + MarbleGame.canvas.popDialog(remapDlg); + + if (key == "escape") + return; + + var conflicting = getConflictingBinding(bindingName, key); + if (conflicting == null) { + ctrl.buttonText.text.text = '${bindingName}: ${key}'; + bindingFunc(key); + } else { + var yesNoDlg = new MessageBoxYesNoDlg('"${key}" is already bound to "${conflicting}"!
Do you want to undo this mapping?', () -> { + ctrl.buttonText.text.text = '${bindingName}: ${key}'; + bindingFunc(key); + }, () -> {}); + MarbleGame.canvas.pushDialog(yesNoDlg); + } + } + } + + #if hl + var scene2d = hxd.Window.getInstance(); + #end + #if js + var scene2d = MarbleGame.instance.scene2d; + #end + + 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 = "CONTROLLER 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); + btnListLeft.active = false; + 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, 'Menu OK: ${Settings.gamepadSettings.ok}', (e) -> {}); + b1.pressedAction = (e) -> { + remapFunc("Menu OK", (key) -> Settings.gamepadSettings.ok = key, b1); + }; + + var b2 = btnListLeft.addButton(0, 'Menu Back: ${Settings.gamepadSettings.back}', (e) -> {}); + b2.pressedAction = (e) -> { + remapFunc("Menu Back", (key) -> Settings.gamepadSettings.back = key, b2); + }; + var b3 = btnListRight.addButton(0, 'Menu Alt 1: ${Settings.gamepadSettings.alt1}', (e) -> {}); + b3.pressedAction = (e) -> { + remapFunc("Menu Alt 1", (key) -> Settings.gamepadSettings.alt1 = key, b3); + }; + var b4 = btnListLeft.addButton(0, 'Menu Alt 2: ${Settings.gamepadSettings.alt2}', (e) -> {}); + b4.pressedAction = (e) -> { + remapFunc("Move Right", (key) -> Settings.gamepadSettings.alt2 = key, b4); + } + var b5 = btnListRight.addButton(0, 'Jump: ${Settings.gamepadSettings.jump[0]}', (e) -> {}); + b5.pressedAction = (e) -> { + remapFunc("Jump", (key) -> Settings.gamepadSettings.jump[0] = key, b5); + }; + var b5 = btnListLeft.addButton(0, 'Jump: ${Settings.gamepadSettings.jump[1]}', (e) -> {}); + b5.pressedAction = (e) -> { + remapFunc("Jump", (key) -> Settings.gamepadSettings.jump[1] = key, b5); + }; + var b6 = btnListRight.addButton(0, 'Blast: ${Settings.gamepadSettings.blast[0]}', (e) -> {}); + b6.pressedAction = (e) -> { + remapFunc("Blast", (key) -> Settings.gamepadSettings.blast[0] = key, b6); + } + var b6 = btnListLeft.addButton(0, 'Blast: ${Settings.gamepadSettings.blast[1]}', (e) -> {}); + b6.pressedAction = (e) -> { + remapFunc("Blast", (key) -> Settings.gamepadSettings.blast[1] = key, b6); + } + var b11 = btnListRight.addButton(0, 'Use Powerup: ${Settings.gamepadSettings.powerup[0]}', (e) -> {}); + b11.pressedAction = (e) -> { + remapFunc("Use Powerup", (key) -> Settings.gamepadSettings.powerup[0] = key, b11); + } + var b11 = btnListLeft.addButton(0, 'Use Powerup: ${Settings.gamepadSettings.powerup[1]}', (e) -> {}); + b11.pressedAction = (e) -> { + remapFunc("Use Powerup", (key) -> Settings.gamepadSettings.powerup[1] = key, b11); + } + var b12 = btnListRight.addButton(0, 'Rewind: ${Settings.gamepadSettings.rewind[0]}', (e) -> {}); + b12.pressedAction = (e) -> { + remapFunc("Rewind", (key) -> Settings.gamepadSettings.rewind[0] = 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"]; + backButton.accelerators = [hxd.Key.ESCAPE, hxd.Key.BACKSPACE]; + if (pauseGui) + backButton.pressedAction = (e) -> { + MarbleGame.canvas.popDialog(this); + MarbleGame.canvas.pushDialog(new InputSelectGui(true)); + } + else + backButton.pressedAction = (e) -> MarbleGame.canvas.setContent(new InputSelectGui()); + bottomBar.addChild(backButton); + } + + override function update(dt:Float, mouseState:MouseState) { + super.update(dt, mouseState); + var prevSelected = selectedColumn; + if (Key.isPressed(Key.RIGHT) || Gamepad.isPressed(["dpadRight"])) + selectedColumn++; + if (Key.isPressed(Key.LEFT) || Gamepad.isPressed(["dpadLeft"])) + selectedColumn++; + if (selectedColumn < 0) + selectedColumn = 1; + if (selectedColumn > 1) + selectedColumn = 0; + if (selectedColumn == 1) { + btnListLeft.active = true; + btnListRight.active = false; + } else { + btnListLeft.active = false; + btnListRight.active = true; + } + if (prevSelected == 0 && selectedColumn == 1) { + btnListLeft.selected = btnListRight.selected; + } + if (prevSelected == 1 && selectedColumn == 0) { + btnListRight.selected = btnListLeft.selected; + if (btnListRight.selected > btnListRight.buttons.length - 1) + btnListRight.selected = btnListRight.buttons.length - 1; + } + if (_prevMousePosition == null || !_prevMousePosition.equals(mouseState.position)) { + for (i in 0...btnListLeft.buttons.length) { + var btn = btnListLeft.buttons[i]; + var renderRect = btn.getHitTestRect(); + renderRect.position = renderRect.position.add(new Vector(24, 20)); // Offset + renderRect.extent.set(439, 53); + if (renderRect.inRect(mouseState.position)) { + selectedColumn = 1; + btnListLeft.selected = i; + btnListLeft.active = true; + btnListRight.active = false; + break; + } + } + for (i in 0...btnListRight.buttons.length) { + var btn = btnListRight.buttons[i]; + var renderRect = btn.getHitTestRect(); + renderRect.position = renderRect.position.add(new Vector(24, 20)); // Offset + renderRect.extent.set(439, 53); + if (renderRect.inRect(mouseState.position)) { + selectedColumn = 0; + btnListRight.selected = i; + btnListRight.active = true; + btnListLeft.active = false; + break; + } + } + _prevMousePosition = mouseState.position.clone(); + } + } + + 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/CreateMatchGui.hx b/src/gui/CreateMatchGui.hx index fe869c02..7f8b2fe1 100644 --- a/src/gui/CreateMatchGui.hx +++ b/src/gui/CreateMatchGui.hx @@ -108,7 +108,7 @@ class CreateMatchGui extends GuiImage { backButton.position = new Vector(400, 0); backButton.vertSizing = Bottom; backButton.horizSizing = Right; - backButton.gamepadAccelerator = ["B"]; + backButton.gamepadAccelerator = [Settings.gamepadSettings.back]; backButton.accelerators = [hxd.Key.ESCAPE, hxd.Key.BACKSPACE]; backButton.pressedAction = (e) -> MarbleGame.canvas.setContent(new MultiplayerGui()); bottomBar.addChild(backButton); @@ -117,7 +117,7 @@ class CreateMatchGui extends GuiImage { nextButton.position = new Vector(960, 0); nextButton.vertSizing = Bottom; nextButton.horizSizing = Right; - nextButton.gamepadAccelerator = ["A"]; + nextButton.gamepadAccelerator = [Settings.gamepadSettings.ok]; nextButton.accelerators = [hxd.Key.ENTER]; nextButton.pressedAction = (e) -> { Net.hostServer('${Settings.highscoreName}\'s Server', maxPlayers, privateSlots, privateGame, () -> { diff --git a/src/gui/DifficultySelectGui.hx b/src/gui/DifficultySelectGui.hx index d20aa96e..b83831db 100644 --- a/src/gui/DifficultySelectGui.hx +++ b/src/gui/DifficultySelectGui.hx @@ -88,7 +88,7 @@ class DifficultySelectGui extends GuiImage { backButton.position = new Vector(400, 0); backButton.vertSizing = Bottom; backButton.horizSizing = Right; - backButton.gamepadAccelerator = ["B"]; + backButton.gamepadAccelerator = [Settings.gamepadSettings.back]; backButton.accelerators = [hxd.Key.ESCAPE, hxd.Key.BACKSPACE]; backButton.pressedAction = (e) -> MarbleGame.canvas.setContent(new MainMenuGui()); bottomBar.addChild(backButton); diff --git a/src/gui/EndGameGui.hx b/src/gui/EndGameGui.hx index 95448d52..10c7ad8b 100644 --- a/src/gui/EndGameGui.hx +++ b/src/gui/EndGameGui.hx @@ -167,7 +167,7 @@ class EndGameGui extends GuiImage { retryButton.position = new Vector(400, 0); retryButton.vertSizing = Bottom; retryButton.horizSizing = Right; - retryButton.gamepadAccelerator = ["B"]; + retryButton.gamepadAccelerator = [Settings.gamepadSettings.back]; retryButton.accelerators = [hxd.Key.ESCAPE, hxd.Key.BACKSPACE]; retryButton.pressedAction = (e) -> { if (MarbleGame.canvas.children.length == 1) @@ -187,7 +187,7 @@ class EndGameGui extends GuiImage { nextButton.position = new Vector(960, 0); nextButton.vertSizing = Bottom; nextButton.horizSizing = Right; - nextButton.gamepadAccelerator = ["A"]; + nextButton.gamepadAccelerator = [Settings.gamepadSettings.ok]; nextButton.accelerators = [hxd.Key.ENTER]; nextButton.pressedAction = (e) -> { if (MarbleGame.canvas.children.length == 1) @@ -216,7 +216,11 @@ class EndGameGui extends GuiImage { submitScore(); } } else { - Leaderboards.getScores(mission.path, All, lbscores -> { + Leaderboards.getScores(mission.path, rewindUsed ? Rewind : NoRewind, lbscores -> { + // Score submission criteria + // If it is better than our non-rewind score, or better than the top non-rewind score, and we are non rewind, submit it + // If it is better than our rewind score, or better than the top rewind score, and we are rewind, submit it + var foundScore = false; var foundLBScore:Float = 0; for (lb in lbscores) { diff --git a/src/gui/EnterNameDlg.hx b/src/gui/EnterNameDlg.hx index 7b19e9c2..c6009377 100644 --- a/src/gui/EnterNameDlg.hx +++ b/src/gui/EnterNameDlg.hx @@ -63,7 +63,7 @@ class EnterNameDlg extends GuiImage { okButton.extent = new Vector(120, 94); okButton.vertSizing = Top; okButton.accelerators = [hxd.Key.ENTER]; - okButton.gamepadAccelerator = ["A"]; + okButton.gamepadAccelerator = [Settings.gamepadSettings.ok]; okButton.pressedAction = (sender) -> { Settings.highscoreName = textInput.text.text.substr(0, 15); // Max 15 pls Settings.save(); @@ -76,7 +76,7 @@ class EnterNameDlg extends GuiImage { cancelButton.extent = new Vector(120, 94); cancelButton.vertSizing = Top; cancelButton.accelerators = [hxd.Key.ENTER]; - cancelButton.gamepadAccelerator = ["A"]; + cancelButton.gamepadAccelerator = [Settings.gamepadSettings.ok]; cancelButton.pressedAction = (sender) -> { MarbleGame.canvas.setContent(new MultiplayerGui()); } diff --git a/src/gui/EnterNamePopupDlg.hx b/src/gui/EnterNamePopupDlg.hx index 368d4873..2f4d0cd5 100644 --- a/src/gui/EnterNamePopupDlg.hx +++ b/src/gui/EnterNamePopupDlg.hx @@ -63,7 +63,7 @@ class EnterNamePopupDlg extends GuiImage { okButton.extent = new Vector(120, 94); okButton.vertSizing = Top; okButton.accelerators = [hxd.Key.ENTER]; - okButton.gamepadAccelerator = ["A"]; + okButton.gamepadAccelerator = [Settings.gamepadSettings.ok]; okButton.pressedAction = (sender) -> { Settings.highscoreName = textInput.text.text.substr(0, 15); // Max 15 pls Settings.save(); diff --git a/src/gui/HelpCreditsGui.hx b/src/gui/HelpCreditsGui.hx index b567f92b..77c26137 100644 --- a/src/gui/HelpCreditsGui.hx +++ b/src/gui/HelpCreditsGui.hx @@ -147,7 +147,7 @@ class HelpCreditsGui extends GuiImage { backButton.position = new Vector(960, 0); backButton.vertSizing = Bottom; backButton.horizSizing = Right; - backButton.gamepadAccelerator = ["A"]; + backButton.gamepadAccelerator = [Settings.gamepadSettings.ok]; backButton.accelerators = [hxd.Key.ENTER]; if (pauseGui) if (index == 5) diff --git a/src/gui/InputOptionsGui.hx b/src/gui/InputOptionsGui.hx index 7f290755..90e8dbc8 100644 --- a/src/gui/InputOptionsGui.hx +++ b/src/gui/InputOptionsGui.hx @@ -124,7 +124,7 @@ class InputOptionsGui extends GuiImage { backButton.position = new Vector(960, 0); backButton.vertSizing = Bottom; backButton.horizSizing = Right; - backButton.gamepadAccelerator = ["A"]; + backButton.gamepadAccelerator = [Settings.gamepadSettings.ok]; backButton.accelerators = [hxd.Key.ENTER]; if (pauseGui) backButton.pressedAction = (e) -> { diff --git a/src/gui/InputSelectGui.hx b/src/gui/InputSelectGui.hx new file mode 100644 index 00000000..00c5ca93 --- /dev/null +++ b/src/gui/InputSelectGui.hx @@ -0,0 +1,108 @@ +package gui; + +import h2d.filter.DropShadow; +import src.MarbleGame; +import gui.GuiControl.MouseState; +import hxd.res.BitmapFont; +import h3d.Vector; +import src.ResourceLoader; +import src.Settings; + +class InputSelectGui extends GuiImage { + var innerCtrl:GuiControl; + var btnList: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); + + #if hl + var scene2d = hxd.Window.getInstance(); + #end + #if js + var scene2d = MarbleGame.instance.scene2d; + #end + + 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 = "SELECT CONTROLS"; + rootTitle.text.alpha = 0.5; + innerCtrl.addChild(rootTitle); + + btnList = new GuiXboxList(); + btnList.position = new Vector(70 - offsetX, 165); + btnList.horizSizing = Left; + btnList.extent = new Vector(502, 500); + innerCtrl.addChild(btnList); + + btnList.addButton(0, 'Keyboard Controls', (e) -> { + MarbleGame.canvas.setContent(new KeyBindingsGui(pauseGui)); + }); + btnList.addButton(0, 'Gamepad Controls', (e) -> { + MarbleGame.canvas.setContent(new ControllerBindingsGui(pauseGui)); + }); + 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 = [Settings.gamepadSettings.back]; + backButton.accelerators = [hxd.Key.ESCAPE, hxd.Key.BACKSPACE]; + if (pauseGui) + backButton.pressedAction = (e) -> { + MarbleGame.canvas.popDialog(this); + MarbleGame.canvas.pushDialog(new OptionsListGui(pauseGui)); + } + else + backButton.pressedAction = (e) -> MarbleGame.canvas.setContent(new OptionsListGui(pauseGui)); + 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); + btnList.position = new Vector(70 - offsetX, 165); + + super.onResize(width, height); + } +} diff --git a/src/gui/JoinServerGui.hx b/src/gui/JoinServerGui.hx index 3d61cd27..98014679 100644 --- a/src/gui/JoinServerGui.hx +++ b/src/gui/JoinServerGui.hx @@ -196,7 +196,7 @@ class JoinServerGui extends GuiImage { backButton.position = new Vector(400, 0); backButton.vertSizing = Bottom; backButton.horizSizing = Right; - backButton.gamepadAccelerator = ["B"]; + backButton.gamepadAccelerator = [Settings.gamepadSettings.back]; backButton.accelerators = [hxd.Key.ESCAPE, hxd.Key.BACKSPACE]; backButton.pressedAction = (e) -> { MarbleGame.canvas.setContent(new MultiplayerGui()); @@ -207,7 +207,7 @@ class JoinServerGui extends GuiImage { goButton.position = new Vector(960, 0); goButton.vertSizing = Bottom; goButton.horizSizing = Right; - goButton.gamepadAccelerator = ["A"]; + goButton.gamepadAccelerator = [Settings.gamepadSettings.ok]; goButton.accelerators = [hxd.Key.ENTER]; goButton.pressedAction = (e) -> joinFunc(); bottomBar.addChild(goButton); diff --git a/src/gui/KeyBindingsGui.hx b/src/gui/KeyBindingsGui.hx index 273b88f1..a97e9713 100644 --- a/src/gui/KeyBindingsGui.hx +++ b/src/gui/KeyBindingsGui.hx @@ -197,15 +197,15 @@ class KeyBindingsGui extends GuiImage { backButton.position = new Vector(400, 0); backButton.vertSizing = Bottom; backButton.horizSizing = Right; - backButton.gamepadAccelerator = ["B"]; + backButton.gamepadAccelerator = [Settings.gamepadSettings.back]; backButton.accelerators = [hxd.Key.ESCAPE, hxd.Key.BACKSPACE]; if (pauseGui) backButton.pressedAction = (e) -> { MarbleGame.canvas.popDialog(this); - MarbleGame.canvas.pushDialog(new OptionsListGui(true)); + MarbleGame.canvas.pushDialog(new InputSelectGui(true)); } else - backButton.pressedAction = (e) -> MarbleGame.canvas.setContent(new OptionsListGui()); + backButton.pressedAction = (e) -> MarbleGame.canvas.setContent(new InputSelectGui()); bottomBar.addChild(backButton); } diff --git a/src/gui/LeaderboardsGui.hx b/src/gui/LeaderboardsGui.hx index e084fcce..fb786a79 100644 --- a/src/gui/LeaderboardsGui.hx +++ b/src/gui/LeaderboardsGui.hx @@ -157,7 +157,7 @@ class LeaderboardsGui extends GuiImage { var levelNames = allMissions.map(x -> x.title); var scoreCategories = ["Overall", "Rewind", "Non-Rewind"]; - var scoreView:LeaderboardsKind = All; + var scoreView:LeaderboardsKind = cast Settings.optionsSettings.currentView; var currentMission = allMissions[actualIndex]; @@ -218,7 +218,7 @@ class LeaderboardsGui extends GuiImage { backButton.position = new Vector(400, 0); backButton.vertSizing = Bottom; backButton.horizSizing = Right; - backButton.gamepadAccelerator = ["B"]; + backButton.gamepadAccelerator = [Settings.gamepadSettings.back]; backButton.accelerators = [hxd.Key.ESCAPE, hxd.Key.BACKSPACE]; if (levelSelectGui) backButton.pressedAction = (e) -> MarbleGame.canvas.setContent(new LevelSelectGui(levelSelectDifficulty)); @@ -231,9 +231,10 @@ class LeaderboardsGui extends GuiImage { changeViewButton.position = new Vector(560, 0); changeViewButton.vertSizing = Bottom; changeViewButton.horizSizing = Right; - changeViewButton.gamepadAccelerator = ["X"]; + changeViewButton.gamepadAccelerator = [Settings.gamepadSettings.alt1]; changeViewButton.pressedAction = (e) -> { scoreView = scoreView == All ? Rewind : (scoreView == Rewind ? NoRewind : All); + Settings.optionsSettings.currentView = cast scoreView; levelSelectOpts.labelText.text.text = scoreCategories[cast(scoreView, Int)]; fetchScores(); } @@ -242,7 +243,7 @@ class LeaderboardsGui extends GuiImage { var replayButton = new GuiXboxButton("Watch Replay", 220); replayButton.position = new Vector(750, 0); replayButton.vertSizing = Bottom; - replayButton.gamepadAccelerator = ["Y"]; + replayButton.gamepadAccelerator = [Settings.gamepadSettings.alt2]; replayButton.horizSizing = Right; replayButton.pressedAction = (e) -> { Leaderboards.watchTopReplay(currentMission.path, scoreView, (b) -> { diff --git a/src/gui/LevelSelectGui.hx b/src/gui/LevelSelectGui.hx index 55fb406e..65c60c8e 100644 --- a/src/gui/LevelSelectGui.hx +++ b/src/gui/LevelSelectGui.hx @@ -144,7 +144,7 @@ class LevelSelectGui extends GuiImage { backButton.position = new Vector(400, 0); backButton.vertSizing = Bottom; backButton.horizSizing = Right; - backButton.gamepadAccelerator = ["B"]; + backButton.gamepadAccelerator = [Settings.gamepadSettings.back]; backButton.accelerators = [hxd.Key.ESCAPE, hxd.Key.BACKSPACE]; backButton.pressedAction = (e) -> MarbleGame.canvas.setContent(new DifficultySelectGui()); bottomBar.addChild(backButton); @@ -153,7 +153,7 @@ class LevelSelectGui extends GuiImage { recordButton.position = new Vector(560, 0); recordButton.vertSizing = Bottom; recordButton.horizSizing = Right; - recordButton.gamepadAccelerator = ["X"]; + recordButton.gamepadAccelerator = [Settings.gamepadSettings.alt1]; recordButton.pressedAction = (e) -> { MarbleGame.instance.toRecord = true; MarbleGame.canvas.pushDialog(new MessageBoxOkDlg("The next mission you play will be recorded.")); @@ -164,7 +164,7 @@ class LevelSelectGui extends GuiImage { var lbButton = new GuiXboxButton("Leaderboard", 220); lbButton.position = new Vector(750, 0); lbButton.vertSizing = Bottom; - lbButton.gamepadAccelerator = ["Y"]; + lbButton.gamepadAccelerator = [Settings.gamepadSettings.alt2]; lbButton.horizSizing = Right; lbButton.pressedAction = (e) -> MarbleGame.canvas.setContent(new LeaderboardsGui(currentSelectionStatic, currentDifficultyStatic, true)); bottomBar.addChild(lbButton); @@ -174,7 +174,7 @@ class LevelSelectGui extends GuiImage { nextButton.position = new Vector(960, 0); nextButton.vertSizing = Bottom; nextButton.horizSizing = Right; - nextButton.gamepadAccelerator = ["A"]; + nextButton.gamepadAccelerator = [Settings.gamepadSettings.ok]; nextButton.accelerators = [hxd.Key.ENTER]; nextButton.pressedAction = (e) -> { MarbleGame.instance.playMission(curMission); diff --git a/src/gui/MPServerListGui.hx b/src/gui/MPServerListGui.hx index 09d9f12f..1b61b52a 100644 --- a/src/gui/MPServerListGui.hx +++ b/src/gui/MPServerListGui.hx @@ -140,7 +140,7 @@ class MPServerListGui extends GuiImage { backButton.position = new Vector(400, 0); backButton.vertSizing = Bottom; backButton.horizSizing = Right; - backButton.gamepadAccelerator = ["B"]; + backButton.gamepadAccelerator = [Settings.gamepadSettings.back]; backButton.accelerators = [hxd.Key.ESCAPE, hxd.Key.BACKSPACE]; backButton.pressedAction = (e) -> MarbleGame.canvas.setContent(new MainMenuGui()); bottomBar.addChild(backButton); @@ -183,7 +183,7 @@ class MPServerListGui extends GuiImage { nextButton.vertSizing = Bottom; nextButton.horizSizing = Right; nextButton.accelerators = [hxd.Key.ENTER]; - nextButton.gamepadAccelerator = ["X"]; + nextButton.gamepadAccelerator = [Settings.gamepadSettings.alt1]; nextButton.pressedAction = (e) -> { if (curSelection != -1) { var selectedServerVersion = ourServerList[curSelection].version; diff --git a/src/gui/MarblePickerGui.hx b/src/gui/MarblePickerGui.hx index d04c4a1e..4408e2ab 100644 --- a/src/gui/MarblePickerGui.hx +++ b/src/gui/MarblePickerGui.hx @@ -344,7 +344,7 @@ class MarblePickerGui extends GuiImage { backButton.position = new Vector(960, 0); backButton.vertSizing = Bottom; backButton.horizSizing = Right; - backButton.gamepadAccelerator = ["A"]; + backButton.gamepadAccelerator = [Settings.gamepadSettings.ok]; backButton.accelerators = [hxd.Key.ENTER]; backButton.pressedAction = (e) -> { this.bmp.visible = true; diff --git a/src/gui/MessageBoxOkDlg.hx b/src/gui/MessageBoxOkDlg.hx index ffbfd96c..e5b56a24 100644 --- a/src/gui/MessageBoxOkDlg.hx +++ b/src/gui/MessageBoxOkDlg.hx @@ -39,7 +39,7 @@ class MessageBoxOkDlg extends GuiImage { okButton.extent = new Vector(120, 94); okButton.vertSizing = Top; okButton.accelerators = [hxd.Key.ENTER]; - okButton.gamepadAccelerator = ["A"]; + okButton.gamepadAccelerator = [Settings.gamepadSettings.ok]; okButton.pressedAction = (sender) -> { MarbleGame.canvas.popDialog(this); } diff --git a/src/gui/MessageBoxYesNoDlg.hx b/src/gui/MessageBoxYesNoDlg.hx index ce510f1d..bf89a358 100644 --- a/src/gui/MessageBoxYesNoDlg.hx +++ b/src/gui/MessageBoxYesNoDlg.hx @@ -39,7 +39,7 @@ class MessageBoxYesNoDlg extends GuiImage { okButton.extent = new Vector(120, 94); okButton.vertSizing = Top; okButton.accelerators = [hxd.Key.ENTER]; - okButton.gamepadAccelerator = ["A"]; + okButton.gamepadAccelerator = [Settings.gamepadSettings.ok]; okButton.pressedAction = (sender) -> { MarbleGame.canvas.popDialog(this); yesFunc(); @@ -51,7 +51,7 @@ class MessageBoxYesNoDlg extends GuiImage { cancelButton.extent = new Vector(120, 94); cancelButton.vertSizing = Top; cancelButton.accelerators = [hxd.Key.ESCAPE, hxd.Key.BACKSPACE]; - cancelButton.gamepadAccelerator = ["B"]; + cancelButton.gamepadAccelerator = [Settings.gamepadSettings.back]; cancelButton.pressedAction = (sender) -> { MarbleGame.canvas.popDialog(this); noFunc(); diff --git a/src/gui/MiscOptionsGui.hx b/src/gui/MiscOptionsGui.hx index a5a7bbc0..06352b16 100644 --- a/src/gui/MiscOptionsGui.hx +++ b/src/gui/MiscOptionsGui.hx @@ -119,7 +119,7 @@ class MiscOptionsGui extends GuiImage { backButton.position = new Vector(960, 0); backButton.vertSizing = Bottom; backButton.horizSizing = Right; - backButton.gamepadAccelerator = ["A"]; + backButton.gamepadAccelerator = [Settings.gamepadSettings.ok]; backButton.accelerators = [hxd.Key.ENTER]; if (pauseGui) backButton.pressedAction = (e) -> { diff --git a/src/gui/MultiplayerGui.hx b/src/gui/MultiplayerGui.hx index d3c8dd2f..1361e68d 100644 --- a/src/gui/MultiplayerGui.hx +++ b/src/gui/MultiplayerGui.hx @@ -108,7 +108,7 @@ class MultiplayerGui extends GuiImage { backButton.position = new Vector(400, 0); backButton.vertSizing = Bottom; backButton.horizSizing = Right; - backButton.gamepadAccelerator = ["B"]; + backButton.gamepadAccelerator = [Settings.gamepadSettings.back]; backButton.accelerators = [hxd.Key.ESCAPE, hxd.Key.BACKSPACE]; backButton.pressedAction = (e) -> MarbleGame.canvas.setContent(new MainMenuGui()); bottomBar.addChild(backButton); diff --git a/src/gui/MultiplayerLevelSelectGui.hx b/src/gui/MultiplayerLevelSelectGui.hx index 78679810..a4dee1dd 100644 --- a/src/gui/MultiplayerLevelSelectGui.hx +++ b/src/gui/MultiplayerLevelSelectGui.hx @@ -271,7 +271,7 @@ class MultiplayerLevelSelectGui extends GuiImage { backButton.position = new Vector(400, 0); backButton.vertSizing = Bottom; backButton.horizSizing = Right; - backButton.gamepadAccelerator = ["B"]; + backButton.gamepadAccelerator = [Settings.gamepadSettings.back]; backButton.accelerators = [hxd.Key.ESCAPE, hxd.Key.BACKSPACE]; backButton.pressedAction = (e) -> { Net.disconnect(); @@ -288,7 +288,7 @@ class MultiplayerLevelSelectGui extends GuiImage { customsButton.position = new Vector(560, 0); customsButton.vertSizing = Bottom; customsButton.horizSizing = Right; - customsButton.gamepadAccelerator = ["X"]; + customsButton.gamepadAccelerator = [Settings.gamepadSettings.alt1]; customsButton.pressedAction = (e) -> { showingCustoms = !showingCustoms; if (showingCustoms) { @@ -307,7 +307,7 @@ class MultiplayerLevelSelectGui extends GuiImage { inviteButton.position = new Vector(750, 0); inviteButton.vertSizing = Bottom; inviteButton.horizSizing = Right; - inviteButton.gamepadAccelerator = ["Y"]; + inviteButton.gamepadAccelerator = [Settings.gamepadSettings.alt2]; inviteButton.pressedAction = (e) -> { inviteVisibility = !inviteVisibility; updateLobbyNames(); @@ -319,7 +319,7 @@ class MultiplayerLevelSelectGui extends GuiImage { nextButton.position = new Vector(960, 0); nextButton.vertSizing = Bottom; nextButton.horizSizing = Right; - nextButton.gamepadAccelerator = ["A"]; + nextButton.gamepadAccelerator = [Settings.gamepadSettings.ok]; nextButton.accelerators = [hxd.Key.ENTER]; nextButton.pressedAction = (e) -> { NetCommands.toggleReadiness(Net.isClient ? Net.clientId : 0); diff --git a/src/gui/MultiplayerLoadingGui.hx b/src/gui/MultiplayerLoadingGui.hx index 75f4b6e2..78af3e2d 100644 --- a/src/gui/MultiplayerLoadingGui.hx +++ b/src/gui/MultiplayerLoadingGui.hx @@ -94,7 +94,7 @@ class MultiplayerLoadingGui extends GuiImage { backButton.position = new Vector(960, 0); backButton.vertSizing = Bottom; backButton.horizSizing = Right; - backButton.gamepadAccelerator = ["A"]; + backButton.gamepadAccelerator = [Settings.gamepadSettings.ok]; backButton.accelerators = [hxd.Key.ENTER]; backButton.pressedAction = (e) -> { Net.disconnect(); diff --git a/src/gui/OptionsListGui.hx b/src/gui/OptionsListGui.hx index 9b4b4d39..c507a493 100644 --- a/src/gui/OptionsListGui.hx +++ b/src/gui/OptionsListGui.hx @@ -78,7 +78,7 @@ class OptionsListGui extends GuiImage { } } else { btnList.addButton(3, 'Key Bindings', (e) -> { - MarbleGame.canvas.setContent(new KeyBindingsGui(pauseGui)); + MarbleGame.canvas.setContent(new InputSelectGui(pauseGui)); }); } btnList.addButton(3, 'Video Options', (e) -> { @@ -107,7 +107,7 @@ class OptionsListGui extends GuiImage { backButton.position = new Vector(400, 0); backButton.vertSizing = Bottom; backButton.horizSizing = Right; - backButton.gamepadAccelerator = ["B"]; + backButton.gamepadAccelerator = [Settings.gamepadSettings.back]; backButton.accelerators = [hxd.Key.ESCAPE, hxd.Key.BACKSPACE]; if (pauseGui) backButton.pressedAction = (e) -> { diff --git a/src/gui/PlayMissionGui.hx b/src/gui/PlayMissionGui.hx index 037208bb..a88cf5c3 100644 --- a/src/gui/PlayMissionGui.hx +++ b/src/gui/PlayMissionGui.hx @@ -181,7 +181,7 @@ class PlayMissionGui extends GuiImage { pmMenuButton.position = new Vector(119, 325); pmMenuButton.extent = new Vector(92, 43); pmMenuButton.accelerator = hxd.Key.ESCAPE; - pmMenuButton.gamepadAccelerator = ["B"]; + pmMenuButton.gamepadAccelerator = [Settings.gamepadSettings.back]; pmMenuButton.pressedAction = (sender) -> { cast(this.parent, Canvas).setContent(new MainMenuGui()); }; @@ -217,7 +217,7 @@ class PlayMissionGui extends GuiImage { var pmPlay = new GuiButton(loadButtonImages("data/ui/play/play")); pmPlay.position = new Vector(510, 325); pmPlay.extent = new Vector(92, 43); - pmPlay.gamepadAccelerator = ["A"]; + pmPlay.gamepadAccelerator = [Settings.gamepadSettings.ok]; pmPlay.pressedAction = (sender) -> { // Wacky hacks currentList[currentSelection].index = currentSelection; diff --git a/src/gui/RemapDlg.hx b/src/gui/RemapDlg.hx index 8311f7a3..54314d1e 100644 --- a/src/gui/RemapDlg.hx +++ b/src/gui/RemapDlg.hx @@ -6,13 +6,18 @@ import hxd.res.BitmapFont; import h3d.Vector; import src.ResourceLoader; import src.Settings; +import src.Gamepad; class RemapDlg extends GuiImage { var remapCallback:Int->Void; + var controllerRemapCallback:String->Void; + var controller:Bool; - public function new(bindingName:String) { + public function new(bindingName:String, controller:Bool = false) { var res = ResourceLoader.getImage("data/ui/xbox/roundedBG.png").resource.toTile(); super(res); + this.controller = controller; + this.horizSizing = Width; this.vertSizing = Height; this.position = new Vector(); @@ -40,11 +45,41 @@ class RemapDlg extends GuiImage { public override function update(dt:Float, mouseState:MouseState) { super.update(dt, mouseState); - for (i in 0...1024) { - if (i == Key.MOUSE_WHEEL_DOWN || i == Key.MOUSE_WHEEL_UP) - continue; - if (Key.isPressed(i)) { - remapCallback(i); + if (controller) { + var controllerKeys = [ + "A", + "B", + "X", + "Y", + "LB", + "RB", + "LT", + "RT", + "start", + "back", + "analogClick", + "ranalogClick", + "dpadUp", + "dpadDown", + "dpadLeft", + "dpadRight" + ]; + + for (key in controllerKeys) { + if (Gamepad.isPressed([key])) { + controllerRemapCallback(key); + return; + } + } + if (Key.isPressed(Key.ESCAPE)) + controllerRemapCallback("escape"); + } else { + for (i in 0...1024) { + if (i == Key.MOUSE_WHEEL_DOWN || i == Key.MOUSE_WHEEL_UP) + continue; + if (Key.isPressed(i)) { + remapCallback(i); + } } } } diff --git a/src/gui/ReplayCenterGui.hx b/src/gui/ReplayCenterGui.hx index d258b6cb..1dc93651 100644 --- a/src/gui/ReplayCenterGui.hx +++ b/src/gui/ReplayCenterGui.hx @@ -121,7 +121,7 @@ class ReplayCenterGui extends GuiImage { backButton.position = new Vector(400, 0); backButton.vertSizing = Bottom; backButton.horizSizing = Right; - backButton.gamepadAccelerator = ["B"]; + backButton.gamepadAccelerator = [Settings.gamepadSettings.back]; backButton.accelerators = [hxd.Key.ESCAPE, hxd.Key.BACKSPACE]; backButton.pressedAction = (e) -> MarbleGame.canvas.setContent(new MainMenuGui()); bottomBar.addChild(backButton); @@ -130,7 +130,7 @@ class ReplayCenterGui extends GuiImage { nextButton.position = new Vector(960, 0); nextButton.vertSizing = Bottom; nextButton.horizSizing = Right; - nextButton.gamepadAccelerator = ["A"]; + nextButton.gamepadAccelerator = [Settings.gamepadSettings.ok]; nextButton.accelerators = [hxd.Key.ENTER]; nextButton.pressedAction = (e) -> { if (selectedIdx != -1) { diff --git a/src/gui/ReplayNameDlg.hx b/src/gui/ReplayNameDlg.hx index c4ea3276..dc035647 100644 --- a/src/gui/ReplayNameDlg.hx +++ b/src/gui/ReplayNameDlg.hx @@ -65,7 +65,7 @@ class ReplayNameDlg extends GuiImage { okButton.extent = new Vector(120, 94); okButton.vertSizing = Top; okButton.accelerators = [hxd.Key.ENTER]; - okButton.gamepadAccelerator = ["A"]; + okButton.gamepadAccelerator = [Settings.gamepadSettings.ok]; okButton.pressedAction = (sender) -> { if (StringTools.trim(textInput.text.text) != "") { MarbleGame.instance.recordingName = textInput.text.text; @@ -81,7 +81,7 @@ class ReplayNameDlg extends GuiImage { cancelButton.extent = new Vector(120, 94); cancelButton.vertSizing = Top; cancelButton.accelerators = [hxd.Key.ENTER]; - cancelButton.gamepadAccelerator = ["A"]; + cancelButton.gamepadAccelerator = [Settings.gamepadSettings.ok]; cancelButton.pressedAction = (sender) -> { MarbleGame.canvas.popDialog(this); callback(); diff --git a/src/gui/TouchCtrlsEditGui.hx b/src/gui/TouchCtrlsEditGui.hx index f64165f1..63df44aa 100644 --- a/src/gui/TouchCtrlsEditGui.hx +++ b/src/gui/TouchCtrlsEditGui.hx @@ -65,7 +65,7 @@ class TouchCtrlsEditGui extends GuiImage { nextButton.position = new Vector(960, 100); nextButton.vertSizing = Bottom; nextButton.horizSizing = Right; - nextButton.gamepadAccelerator = ["A"]; + nextButton.gamepadAccelerator = [Settings.gamepadSettings.ok]; nextButton.accelerators = [hxd.Key.ENTER]; nextButton.pressedAction = (e) -> { if (paused) { diff --git a/src/gui/TouchOptionsGui.hx b/src/gui/TouchOptionsGui.hx index 30230a44..1ca9db99 100644 --- a/src/gui/TouchOptionsGui.hx +++ b/src/gui/TouchOptionsGui.hx @@ -98,7 +98,7 @@ class TouchOptionsGui extends GuiImage { backButton.position = new Vector(960, 0); backButton.vertSizing = Bottom; backButton.horizSizing = Right; - backButton.gamepadAccelerator = ["A"]; + backButton.gamepadAccelerator = [Settings.gamepadSettings.ok]; backButton.accelerators = [hxd.Key.ENTER]; if (pauseGui) backButton.pressedAction = (e) -> { @@ -118,7 +118,7 @@ class TouchOptionsGui extends GuiImage { ctrlButton.position = new Vector(750, 0); ctrlButton.vertSizing = Bottom; ctrlButton.horizSizing = Right; - ctrlButton.gamepadAccelerator = ["Y"]; + ctrlButton.gamepadAccelerator = [Settings.gamepadSettings.alt2]; ctrlButton.pressedAction = (e) -> { MarbleGame.canvas.setContent(new TouchCtrlsEditGui(pauseGui)); } diff --git a/src/gui/VersionGui.hx b/src/gui/VersionGui.hx index 1abc38bc..83eaf64a 100644 --- a/src/gui/VersionGui.hx +++ b/src/gui/VersionGui.hx @@ -77,7 +77,7 @@ class VersionGui extends GuiImage { backButton.position = new Vector(960, 0); backButton.vertSizing = Bottom; backButton.horizSizing = Right; - backButton.gamepadAccelerator = ["A"]; + backButton.gamepadAccelerator = [Settings.gamepadSettings.ok]; backButton.accelerators = [hxd.Key.ENTER]; backButton.pressedAction = (e) -> MarbleGame.canvas.setContent(new MainMenuGui()); bottomBar.addChild(backButton); diff --git a/src/gui/VideoOptionsGui.hx b/src/gui/VideoOptionsGui.hx index 2667c377..a97dbb55 100644 --- a/src/gui/VideoOptionsGui.hx +++ b/src/gui/VideoOptionsGui.hx @@ -179,7 +179,7 @@ class VideoOptionsGui extends GuiImage { backButton.position = new Vector(960, 0); backButton.vertSizing = Bottom; backButton.horizSizing = Right; - backButton.gamepadAccelerator = ["A"]; + backButton.gamepadAccelerator = [Settings.gamepadSettings.ok]; backButton.accelerators = [hxd.Key.ENTER]; if (pauseGui) backButton.pressedAction = (e) -> {