From 1204e5a8f4c9d560d8268add568bf1e9a501adb0 Mon Sep 17 00:00:00 2001 From: RandomityGuy <31925790+RandomityGuy@users.noreply.github.com> Date: Tue, 11 Jun 2024 20:06:51 +0530 Subject: [PATCH] add entire section for touch settings --- src/Settings.hx | 9 +- src/gui/MultiplayerLevelSelectGui.hx | 1 + src/gui/OptionsListGui.hx | 2 +- src/gui/TouchCtrlsEditGui.hx | 4 +- src/gui/TouchOptionsGui.hx | 128 +++++++++++++++++++++++++++ src/touch/MovementInput.hx | 1 + src/touch/TouchInput.hx | 23 +++++ 7 files changed, 164 insertions(+), 4 deletions(-) create mode 100644 src/gui/TouchOptionsGui.hx diff --git a/src/Settings.hx b/src/Settings.hx index bd31a086..d00a0bbc 100644 --- a/src/Settings.hx +++ b/src/Settings.hx @@ -84,6 +84,7 @@ typedef TouchSettings = { var rewindButtonPos:Array; var rewindButtonSize:Float; var buttonJoystickMultiplier:Float; + var hideControls:Bool; } typedef GamepadSettings = { @@ -172,7 +173,8 @@ class Settings { blastButtonSize: 60, rewindButtonPos: [300, 100], rewindButtonSize: 60, - buttonJoystickMultiplier: 2.5 + buttonJoystickMultiplier: 2.5, + hideControls: false } public static var gamepadSettings:GamepadSettings = { @@ -391,6 +393,11 @@ class Settings { touchSettings.rewindButtonPos = [300, 100]; touchSettings.rewindButtonSize = 60; } + #if js + if (touchSettings.hideControls == null) { + touchSettings.hideControls = false; + } + #end if (json.gamepad != null) { gamepadSettings = json.gamepad; } diff --git a/src/gui/MultiplayerLevelSelectGui.hx b/src/gui/MultiplayerLevelSelectGui.hx index 135eced7..f0136d1e 100644 --- a/src/gui/MultiplayerLevelSelectGui.hx +++ b/src/gui/MultiplayerLevelSelectGui.hx @@ -300,6 +300,7 @@ class MultiplayerLevelSelectGui extends GuiImage { inviteButton.position = new Vector(750, 0); inviteButton.vertSizing = Bottom; inviteButton.horizSizing = Right; + inviteButton.gamepadAccelerator = ["Y"]; inviteButton.pressedAction = (e) -> { inviteVisibility = !inviteVisibility; updateLobbyNames(); diff --git a/src/gui/OptionsListGui.hx b/src/gui/OptionsListGui.hx index 7bc1a7a6..9b4b4d39 100644 --- a/src/gui/OptionsListGui.hx +++ b/src/gui/OptionsListGui.hx @@ -73,7 +73,7 @@ class OptionsListGui extends GuiImage { if (Util.isTouchDevice()) { if (!pauseGui) { btnList.addButton(3, 'Touch Controls', (e) -> { - MarbleGame.canvas.setContent(new TouchCtrlsEditGui(pauseGui)); + MarbleGame.canvas.setContent(new TouchOptionsGui(pauseGui)); }); } } else { diff --git a/src/gui/TouchCtrlsEditGui.hx b/src/gui/TouchCtrlsEditGui.hx index 5502119a..f64165f1 100644 --- a/src/gui/TouchCtrlsEditGui.hx +++ b/src/gui/TouchCtrlsEditGui.hx @@ -70,9 +70,9 @@ class TouchCtrlsEditGui extends GuiImage { nextButton.pressedAction = (e) -> { if (paused) { MarbleGame.canvas.popDialog(this); - MarbleGame.canvas.pushDialog(new OptionsListGui(true)); + MarbleGame.canvas.pushDialog(new TouchOptionsGui(true)); } else { - MarbleGame.canvas.setContent(new OptionsListGui()); + MarbleGame.canvas.setContent(new TouchOptionsGui()); } }; innerCtrl.addChild(nextButton); diff --git a/src/gui/TouchOptionsGui.hx b/src/gui/TouchOptionsGui.hx new file mode 100644 index 00000000..0a3f946d --- /dev/null +++ b/src/gui/TouchOptionsGui.hx @@ -0,0 +1,128 @@ +package gui; + +import src.MarbleGame; +import hxd.res.BitmapFont; +import h3d.Vector; +import src.ResourceLoader; +import src.Settings; +import src.Util; +import src.AudioManager; + +class TouchOptionsGui extends GuiImage { + var innerCtrl:GuiControl; + + 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 = "TOUCH OPTIONS"; + rootTitle.text.alpha = 0.5; + innerCtrl.addChild(rootTitle); + + var optionCollection = new GuiXboxOptionsListCollection(); + optionCollection.position = new Vector(380, 160); + optionCollection.extent = new Vector(815, 500); + innerCtrl.addChild(optionCollection); + + var cameraMultiplier = optionCollection.addOption(1, "Button-Camera Factor", ["0.5", "1", "1.5", "2", "2.5", "3", "3.5"], (idx) -> { + Settings.touchSettings.buttonJoystickMultiplier = 0.5 + (idx * 0.5); + return true; + }, 0.5, 118); + cameraMultiplier.setCurrentOption(Std.int(Util.clamp((Settings.touchSettings.buttonJoystickMultiplier - 0.5) / 0.5, 0, 6))); + + var hideCtrls = optionCollection.addOption(1, "Hide Controls", ["No", "Yes"], (idx) -> { + Settings.touchSettings.hideControls = idx == 1; + return true; + }, 0.5, 118); + + hideCtrls.setCurrentOption(Settings.touchSettings.hideControls ? 1 : 0); + + 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("Ok", 160); + backButton.position = new Vector(960, 0); + backButton.vertSizing = Bottom; + backButton.horizSizing = Right; + backButton.gamepadAccelerator = ["A"]; + backButton.accelerators = [hxd.Key.ENTER]; + if (pauseGui) + backButton.pressedAction = (e) -> { + Settings.applySettings(); + MarbleGame.canvas.popDialog(this); + MarbleGame.canvas.pushDialog(new OptionsListGui(true)); + } + else + backButton.pressedAction = (e) -> { + Settings.applySettings(); + MarbleGame.canvas.setContent(new OptionsListGui()); + }; + bottomBar.addChild(backButton); + + if (!pauseGui) { + var ctrlButton = new GuiXboxButton("Edit Controls", 220); + ctrlButton.position = new Vector(750, 0); + ctrlButton.vertSizing = Bottom; + ctrlButton.horizSizing = Right; + ctrlButton.gamepadAccelerator = ["Y"]; + ctrlButton.pressedAction = (e) -> { + MarbleGame.canvas.setContent(new TouchCtrlsEditGui(pauseGui)); + } + bottomBar.addChild(ctrlButton); + } + } + + 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); + + super.onResize(width, height); + } +} diff --git a/src/touch/MovementInput.hx b/src/touch/MovementInput.hx index 2e07fb34..38bd39c8 100644 --- a/src/touch/MovementInput.hx +++ b/src/touch/MovementInput.hx @@ -115,6 +115,7 @@ class MovementInput { public function setVisible(enabled:Bool) { this.area.graphics.visible = enabled; + this.joystick.graphics.visible = enabled; } public function dispose() { diff --git a/src/touch/TouchInput.hx b/src/touch/TouchInput.hx index c19244a7..fafbab7e 100644 --- a/src/touch/TouchInput.hx +++ b/src/touch/TouchInput.hx @@ -138,6 +138,19 @@ class TouchInput { movementInput.add(parentGui); cameraInput.add(parentGui); cameraInput.enabled = true; + + if (Settings.touchSettings.hideControls) { + this.jumpButton.setVisible(false); + this.powerupButton.setVisible(false); + if (this.blastbutton != null) + this.blastbutton.setVisible(false); + this.movementInput.setVisible(false); + this.pauseButton.setVisible(false); + if (this.restartButton != null) + this.restartButton.setVisible(false); + if (this.rewindButton != null) + this.rewindButton.setVisible(false); + } } public function setControlsEnabled(enabled:Bool) { @@ -152,6 +165,16 @@ class TouchInput { if (this.rewindButton != null) this.rewindButton.setVisible(enabled); this.cameraInput.enabled = enabled; + + if (Settings.touchSettings.hideControls) { + this.jumpButton.setVisible(false); + this.powerupButton.setVisible(false); + if (this.blastbutton != null) + this.blastbutton.setVisible(false); + this.movementInput.setVisible(false); + if (this.rewindButton != null) + this.rewindButton.setVisible(false); + } } public function hideControls(parentGui:GuiControl) {