more touch controls settings

This commit is contained in:
RandomityGuy 2024-07-04 01:33:46 +05:30
parent 54aae3c997
commit 0c58d597d4
5 changed files with 123 additions and 33 deletions

View file

@ -78,6 +78,9 @@ typedef TouchSettings = {
var rewindButtonPos:Array<Float>;
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;
}

View file

@ -141,8 +141,8 @@ class OptionsDlg extends GuiImage {
}
function makeOption(text:String, valueFunc:Void->String, yPos:Float, parent:GuiControl, size:String, options:Array<String>, 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);
}

View file

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

View file

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

View file

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