preserve leaderboards view state on exit

attempt fix case sensitivity issue (web)
add controller bindings ui
This commit is contained in:
RandomityGuy 2025-06-17 22:12:30 +05:30
parent 364cee017f
commit bc635bb77f
34 changed files with 517 additions and 60 deletions

View file

@ -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<String>;
var blast:Array<String>;
var rewind:Array<String>;
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

View file

@ -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

View file

@ -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) -> {

View file

@ -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;

View file

@ -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}"!<br/>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);
}
}

View file

@ -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, () -> {

View file

@ -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);

View file

@ -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) {

View file

@ -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());
}

View file

@ -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();

View file

@ -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)

View file

@ -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) -> {

108
src/gui/InputSelectGui.hx Normal file
View file

@ -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);
}
}

View file

@ -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);

View file

@ -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);
}

View file

@ -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) -> {

View file

@ -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);

View file

@ -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;

View file

@ -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;

View file

@ -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);
}

View file

@ -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();

View file

@ -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) -> {

View file

@ -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);

View file

@ -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);

View file

@ -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();

View file

@ -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) -> {

View file

@ -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;

View file

@ -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);
}
}
}
}

View file

@ -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) {

View file

@ -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();

View file

@ -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) {

View file

@ -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));
}

View file

@ -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);

View file

@ -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) -> {