From 0c58d597d40fa6164236262885eb22a297d0a036 Mon Sep 17 00:00:00 2001 From: RandomityGuy <31925790+RandomityGuy@users.noreply.github.com> Date: Thu, 4 Jul 2024 01:33:46 +0530 Subject: [PATCH] more touch controls settings --- src/Settings.hx | 22 ++++++++++- src/gui/OptionsDlg.hx | 79 +++++++++++++++++++++++--------------- src/touch/CameraInput.hx | 11 +++++- src/touch/MovementInput.hx | 21 ++++++++++ src/touch/TouchInput.hx | 23 +++++++++++ 5 files changed, 123 insertions(+), 33 deletions(-) diff --git a/src/Settings.hx b/src/Settings.hx index c64b32ff..9e4bc90c 100644 --- a/src/Settings.hx +++ b/src/Settings.hx @@ -78,6 +78,9 @@ typedef TouchSettings = { var rewindButtonPos:Array; var rewindButtonSize:Float; var buttonJoystickMultiplier:Float; + var hideControls:Bool; + var cameraSwipeExtent:Float; + var dynamicJoystick:Bool; } typedef GamepadSettings = { @@ -173,7 +176,10 @@ class Settings { blastButtonSize: 60, rewindButtonPos: [300, 100], rewindButtonSize: 60, - buttonJoystickMultiplier: 2.5 + buttonJoystickMultiplier: 2.5, + hideControls: false, + cameraSwipeExtent: 10.0, + dynamicJoystick: false } public static var gamepadSettings:GamepadSettings = { @@ -383,6 +389,20 @@ class Settings { touchSettings.rewindButtonPos = [300, 100]; touchSettings.rewindButtonSize = 60; } + #if js + if (touchSettings.hideControls == null) { + touchSettings.hideControls = false; + } + if (touchSettings.cameraSwipeExtent == null) { + touchSettings.cameraSwipeExtent = 10.0; + } + if (touchSettings.dynamicJoystick == null) { + touchSettings.dynamicJoystick = false; + } + #end + if (touchSettings.cameraSwipeExtent == 0) { + touchSettings.cameraSwipeExtent = 10.0; + } if (json.gamepad != null) { gamepadSettings = json.gamepad; } diff --git a/src/gui/OptionsDlg.hx b/src/gui/OptionsDlg.hx index 0e97cafe..f93264dc 100644 --- a/src/gui/OptionsDlg.hx +++ b/src/gui/OptionsDlg.hx @@ -141,8 +141,8 @@ class OptionsDlg extends GuiImage { } function makeOption(text:String, valueFunc:Void->String, yPos:Float, parent:GuiControl, size:String, options:Array, onSelect:Int->Void, - right:Bool = false) { - var textObj = new GuiText(markerFelt32); + right:Bool = false, smallfont:Bool = false) { + var textObj = new GuiText(smallfont ? markerFelt24 : markerFelt32); textObj.position = new Vector(right ? 388 : 7, yPos); textObj.extent = new Vector(212, 14); textObj.text.text = text; @@ -219,8 +219,8 @@ class OptionsDlg extends GuiImage { optBtns.push(optDropdown); } - function makeSlider(text:String, value:Float, yPos:Float, parent:GuiControl, onChange:Float->Void, right:Bool = false) { - var textObj = new GuiText(markerFelt32); + function makeSlider(text:String, value:Float, yPos:Float, parent:GuiControl, onChange:Float->Void, right:Bool = false, smallfont:Bool = false) { + var textObj = new GuiText(smallfont ? markerFelt24 : markerFelt32); textObj.position = new Vector(right ? 388 : 7, yPos); textObj.extent = new Vector(212, 14); textObj.text.text = text; @@ -428,34 +428,9 @@ class OptionsDlg extends GuiImage { parent.addChild(remapBtn); } - makeRemapOption("Move Forward:", 38, Util.getKeyForButton2(Settings.controlsSettings.forward), (key) -> Settings.controlsSettings.forward = key, - hotkeysPanel); - makeRemapOption("Move Left:", 38, Util.getKeyForButton2(Settings.controlsSettings.left), (key) -> Settings.controlsSettings.left = key, hotkeysPanel, - true); - makeRemapOption("Move Backward:", 86, Util.getKeyForButton2(Settings.controlsSettings.backward), (key) -> Settings.controlsSettings.backward = key, - hotkeysPanel); - makeRemapOption("Move Right:", 86, Util.getKeyForButton2(Settings.controlsSettings.right), (key) -> Settings.controlsSettings.right = key, - hotkeysPanel, true); - makeRemapOption("Look Up:", 134, Util.getKeyForButton2(Settings.controlsSettings.camForward), (key) -> Settings.controlsSettings.camForward = key, - hotkeysPanel); - makeRemapOption("Look Left:", 134, Util.getKeyForButton2(Settings.controlsSettings.camLeft), (key) -> Settings.controlsSettings.camLeft = key, - hotkeysPanel, true); - makeRemapOption("Look Down:", 182, Util.getKeyForButton2(Settings.controlsSettings.camBackward), (key) -> Settings.controlsSettings.camBackward = key, - hotkeysPanel); - makeRemapOption("Look Right:", 182, Util.getKeyForButton2(Settings.controlsSettings.camRight), (key) -> Settings.controlsSettings.camRight = key, - hotkeysPanel, true); - makeRemapOption("Jump:", 230, Util.getKeyForButton2(Settings.controlsSettings.jump), (key) -> Settings.controlsSettings.jump = key, hotkeysPanel); - makeRemapOption("Use Powerup:", 230, Util.getKeyForButton2(Settings.controlsSettings.powerup), (key) -> Settings.controlsSettings.powerup = key, - hotkeysPanel, true); - makeRemapOption("Free Look:", 278, Util.getKeyForButton2(Settings.controlsSettings.freelook), (key) -> Settings.controlsSettings.freelook = key, - hotkeysPanel); - makeRemapOption("Respawn:", 278, Util.getKeyForButton2(Settings.controlsSettings.respawn), (key) -> Settings.controlsSettings.respawn = key, - hotkeysPanel, true); - makeRemapOption("Blast:", 326, Util.getKeyForButton2(Settings.controlsSettings.blast), (key) -> Settings.controlsSettings.blast = key, hotkeysPanel); - if (Util.isTouchDevice()) { var textObj = new GuiText(markerFelt32); - textObj.position = new Vector(368, 326); + textObj.position = new Vector(5, 38); textObj.extent = new Vector(212, 14); textObj.text.text = "Touch Controls"; textObj.text.textColor = 0xFFFFFF; @@ -468,14 +443,56 @@ class OptionsDlg extends GuiImage { hotkeysPanel.addChild(textObj); var remapBtn = new GuiButtonText(loadButtonImages("data/ui/options/bind"), markerFelt24); - remapBtn.position = new Vector(363 + 203, 323); + remapBtn.position = new Vector(5 + 203, 35); remapBtn.txtCtrl.text.text = "Edit"; remapBtn.setExtent(new Vector(152, 49)); remapBtn.pressedAction = (sender) -> { MarbleGame.canvas.setContent(new TouchCtrlsEditGui()); } hotkeysPanel.addChild(remapBtn); + + makeOption("Hide Controls:", () -> '${Settings.touchSettings.hideControls ? "Yes" : "No"}', 38, hotkeysPanel, "small", ["No", "Yes"], (idx) -> { + Settings.touchSettings.hideControls = idx == 1; + }, true); + + makeSlider("Button-Camera Factor:", (Settings.touchSettings.buttonJoystickMultiplier) / 3, 86, hotkeysPanel, (val) -> { + Settings.touchSettings.buttonJoystickMultiplier = val * 3; + }, false, true); + + makeSlider("Camera Swipe Extent:", (Settings.touchSettings.cameraSwipeExtent - 5) / (35 - 5), 86, hotkeysPanel, (val) -> { + Settings.touchSettings.cameraSwipeExtent = 5 + (35 - 5) * val; + }, true, true); + + makeOption("Dynamic Joystick:", () -> '${Settings.touchSettings.dynamicJoystick ? "Yes" : "No"}', 134, hotkeysPanel, "small", ["No", "Yes"], + (idx) -> { + Settings.touchSettings.dynamicJoystick = idx == 1; + }, false, true); } else { + makeRemapOption("Move Forward:", 38, Util.getKeyForButton2(Settings.controlsSettings.forward), (key) -> Settings.controlsSettings.forward = key, + hotkeysPanel); + makeRemapOption("Move Left:", 38, Util.getKeyForButton2(Settings.controlsSettings.left), (key) -> Settings.controlsSettings.left = key, + hotkeysPanel, true); + makeRemapOption("Move Backward:", 86, Util.getKeyForButton2(Settings.controlsSettings.backward), + (key) -> Settings.controlsSettings.backward = key, hotkeysPanel); + makeRemapOption("Move Right:", 86, Util.getKeyForButton2(Settings.controlsSettings.right), (key) -> Settings.controlsSettings.right = key, + hotkeysPanel, true); + makeRemapOption("Look Up:", 134, Util.getKeyForButton2(Settings.controlsSettings.camForward), (key) -> Settings.controlsSettings.camForward = key, + hotkeysPanel); + makeRemapOption("Look Left:", 134, Util.getKeyForButton2(Settings.controlsSettings.camLeft), (key) -> Settings.controlsSettings.camLeft = key, + hotkeysPanel, true); + makeRemapOption("Look Down:", 182, Util.getKeyForButton2(Settings.controlsSettings.camBackward), + (key) -> Settings.controlsSettings.camBackward = key, hotkeysPanel); + makeRemapOption("Look Right:", 182, Util.getKeyForButton2(Settings.controlsSettings.camRight), (key) -> Settings.controlsSettings.camRight = key, + hotkeysPanel, true); + makeRemapOption("Jump:", 230, Util.getKeyForButton2(Settings.controlsSettings.jump), (key) -> Settings.controlsSettings.jump = key, hotkeysPanel); + makeRemapOption("Use Powerup:", 230, Util.getKeyForButton2(Settings.controlsSettings.powerup), (key) -> Settings.controlsSettings.powerup = key, + hotkeysPanel, true); + makeRemapOption("Free Look:", 278, Util.getKeyForButton2(Settings.controlsSettings.freelook), (key) -> Settings.controlsSettings.freelook = key, + hotkeysPanel); + makeRemapOption("Respawn:", 278, Util.getKeyForButton2(Settings.controlsSettings.respawn), (key) -> Settings.controlsSettings.respawn = key, + hotkeysPanel, true); + makeRemapOption("Blast:", 326, Util.getKeyForButton2(Settings.controlsSettings.blast), (key) -> Settings.controlsSettings.blast = key, + hotkeysPanel); makeRemapOption("Rewind:", 326, Util.getKeyForButton2(Settings.controlsSettings.rewind), (key) -> Settings.controlsSettings.rewind = key, hotkeysPanel, true); } diff --git a/src/touch/CameraInput.hx b/src/touch/CameraInput.hx index add5e135..c059eba6 100644 --- a/src/touch/CameraInput.hx +++ b/src/touch/CameraInput.hx @@ -50,6 +50,15 @@ class CameraInput { var scene2d = interactive.getScene(); if (e.relX < scene2d.width / 2) { + var restartG = @:privateAccess MarbleGame.instance.touchInput.pauseButton?.collider; + if (restartG != null) { + if (e.relY > restartG.getAbsPos().y + restartG.height) { + if (Settings.touchSettings.dynamicJoystick) { + // Move that joystick over our finger + MarbleGame.instance.touchInput.movementInput.moveToFinger(e); + } + } + } return; } @@ -104,7 +113,7 @@ class CameraInput { } function applyNonlinearScale(value:Float) { - var clamped = Util.clamp(value, -10, 10); + var clamped = Util.clamp(value, -Settings.touchSettings.cameraSwipeExtent, Settings.touchSettings.cameraSwipeExtent); return Math.abs(clamped) < 3 ? Math.pow(Math.abs(clamped / 2), 2.7) * (clamped >= 0 ? 1 : -1) : clamped; } diff --git a/src/touch/MovementInput.hx b/src/touch/MovementInput.hx index 2e07fb34..b99d32f2 100644 --- a/src/touch/MovementInput.hx +++ b/src/touch/MovementInput.hx @@ -7,6 +7,7 @@ import h2d.col.Bounds; import gui.GuiControl; import h3d.Vector; import gui.GuiGraphics; +import src.MarbleGame; class MovementInput { var area:GuiGraphics; @@ -103,6 +104,26 @@ class MovementInput { this.joystick.graphics.alpha = 1; } + public function moveToFinger(e:hxd.Event) { + var restartG = @:privateAccess MarbleGame.instance.touchInput.pauseButton?.collider; + if (restartG != null) { + var size = Settings.touchSettings.joystickSize; + var scene2d = collider.getScene(); + this.area.graphics.setPosition(Util.clamp(e.relX - size * 3, 0, scene2d.width / 2 - size * 6), + Util.clamp(e.relY - size * 3, restartG.getAbsPos().y + restartG.height, scene2d.height - size * 6)); + + var xPos = Util.clamp(e.relX - this.area.graphics.x, size, size * 5); + var yPos = Util.clamp(e.relY - this.area.graphics.y, size, size * 5); + + this.value.x = (xPos - (size * 3)) / (size * 2); + this.value.y = (yPos - (size * 3)) / (size * 2); + + this.joystick.graphics.setPosition(this.area.graphics.x + xPos, this.area.graphics.y + yPos); + + this.collider.onPush(e); + } + } + public function add(parentGui:GuiControl) { parentGui.addChild(this.area); added = true; diff --git a/src/touch/TouchInput.hx b/src/touch/TouchInput.hx index 3fc0e430..f09b803e 100644 --- a/src/touch/TouchInput.hx +++ b/src/touch/TouchInput.hx @@ -135,6 +135,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) { @@ -148,6 +161,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) {