mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2025-10-30 08:11:25 +00:00
better controller support
This commit is contained in:
parent
b10f071d87
commit
23241ad258
6 changed files with 29 additions and 12 deletions
|
|
@ -173,6 +173,10 @@ class CameraController extends Object {
|
|||
return Util.clamp(delta, Math.PI / 10, Math.PI / 2) * 4;
|
||||
}
|
||||
|
||||
function applyNonlinearScale(value:Float) {
|
||||
return Math.pow(Math.abs(value), 3.2) * (value >= 0 ? 1 : -1);
|
||||
}
|
||||
|
||||
public function startCenterCamera() {
|
||||
if (this.marble.velocity.lengthSq() >= 81) {
|
||||
var marbAxis = this.marble.getMarbleAxis();
|
||||
|
|
@ -200,13 +204,15 @@ class CameraController extends Object {
|
|||
|
||||
var lerpt = Math.pow(0.5, dt / 0.032); // Math.min(1, 1 - Math.pow(0.6, dt / 0.032)); // hxd.Math.min(1, 1 - Math.pow(0.6, dt * 600));
|
||||
|
||||
var gamepadX = applyNonlinearScale(rescaleDeadZone(Gamepad.getAxis(Settings.gamepadSettings.cameraXAxis), 0.25));
|
||||
var gamepadY = applyNonlinearScale(rescaleDeadZone(Gamepad.getAxis(Settings.gamepadSettings.cameraYAxis), 0.25));
|
||||
|
||||
var cameraPitchDelta = (Key.isDown(Settings.controlsSettings.camBackward) ? 1 : 0)
|
||||
- (Key.isDown(Settings.controlsSettings.camForward) ? 1 : 0)
|
||||
+ Gamepad.getAxis(Settings.gamepadSettings.cameraYAxis);
|
||||
+ gamepadY;
|
||||
if (Settings.gamepadSettings.invertYAxis)
|
||||
cameraPitchDelta = -cameraPitchDelta;
|
||||
var cameraYawDelta = (Key.isDown(Settings.controlsSettings.camRight) ? 1 : 0) - (Key.isDown(Settings.controlsSettings.camLeft) ? 1 : 0)
|
||||
+ Gamepad.getAxis(Settings.gamepadSettings.cameraXAxis);
|
||||
var cameraYawDelta = (Key.isDown(Settings.controlsSettings.camRight) ? 1 : 0) - (Key.isDown(Settings.controlsSettings.camLeft) ? 1 : 0) + gamepadX;
|
||||
if (Settings.gamepadSettings.invertXAxis)
|
||||
cameraYawDelta = -cameraYawDelta;
|
||||
|
||||
|
|
@ -240,7 +246,8 @@ class CameraController extends Object {
|
|||
// Center the pitch
|
||||
if (!Settings.controlsSettings.alwaysFreeLook
|
||||
&& !Key.isDown(Settings.controlsSettings.freelook)
|
||||
&& !MarbleGame.instance.touchInput.cameraInput.pressed) {
|
||||
&& !MarbleGame.instance.touchInput.cameraInput.pressed
|
||||
&& deltaY == 0.0) {
|
||||
var rescaledY = deltaY;
|
||||
if (rescaledY <= 0.0)
|
||||
rescaledY = 0.4 - rescaledY * -0.75;
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@ class GuiXboxButton extends GuiControl {
|
|||
if (!disabled) {
|
||||
if (acceleratorWasPressed
|
||||
&& (accelerators.length != 0 && accelerators.map(x -> hxd.Key.isReleased(x)).contains(true))
|
||||
|| Gamepad.isReleased(gamepadAccelerator)) {
|
||||
|| Gamepad.isPressed(gamepadAccelerator)) {
|
||||
if (this.pressedAction != null) {
|
||||
this.pressedAction(new GuiEvent(this));
|
||||
}
|
||||
|
|
@ -130,7 +130,7 @@ class GuiXboxButton extends GuiControl {
|
|||
}
|
||||
if (acceleratorWasPressed) {
|
||||
if ((accelerators.length != 0 && accelerators.map(x -> hxd.Key.isReleased(x)).contains(true))
|
||||
|| Gamepad.isReleased(gamepadAccelerator))
|
||||
|| Gamepad.isPressed(gamepadAccelerator))
|
||||
acceleratorWasPressed = false;
|
||||
}
|
||||
super.update(dt, mouseState);
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ class GuiXboxList extends GuiControl {
|
|||
var selected:Int = 0;
|
||||
|
||||
var buttons:Array<GuiXboxListButton> = [];
|
||||
var usedGamepad:Bool = false;
|
||||
|
||||
public var active:Bool = true;
|
||||
|
||||
|
|
@ -36,10 +37,14 @@ class GuiXboxList extends GuiControl {
|
|||
if (!buttons[selected].selected)
|
||||
buttons[selected].selected = true;
|
||||
var prevSelected = selected;
|
||||
if (Key.isPressed(Key.DOWN) || Gamepad.isPressed(["dpadDown"]))
|
||||
if (Key.isPressed(Key.DOWN) || Gamepad.isPressed(["dpadDown"]) || (Gamepad.getAxis('analogY') > 0.75 && !usedGamepad))
|
||||
selected++;
|
||||
if (Key.isPressed(Key.UP) || Gamepad.isPressed(["dpadUp"]))
|
||||
if (Key.isPressed(Key.UP) || Gamepad.isPressed(["dpadUp"]) || (Gamepad.getAxis('analogY') < -0.75 && !usedGamepad))
|
||||
selected--;
|
||||
if (Math.abs(Gamepad.getAxis('analogY')) > 0.75)
|
||||
usedGamepad = true;
|
||||
else
|
||||
usedGamepad = false;
|
||||
if (selected < 0)
|
||||
selected = buttons.length - 1;
|
||||
if (selected >= buttons.length)
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ class GuiXboxOptionsList extends GuiControl {
|
|||
var onChangeFunc:Int->Bool = null;
|
||||
|
||||
var _prevMousePos:Vector;
|
||||
var usedGamepad:Bool = false;
|
||||
|
||||
public var selected:Bool = false;
|
||||
|
||||
|
|
@ -211,7 +212,7 @@ class GuiXboxOptionsList extends GuiControl {
|
|||
rightButton.anim.filter.enable = false;
|
||||
}
|
||||
if (selected || alwaysActive) {
|
||||
if (Key.isPressed(Key.LEFT) || Gamepad.isPressed(['dpadLeft'])) {
|
||||
if (Key.isPressed(Key.LEFT) || Gamepad.isPressed(['dpadLeft']) || (Gamepad.getAxis('analogX') < -0.75 && !usedGamepad)) {
|
||||
var newOption = currentOption - 1;
|
||||
if (newOption < 0)
|
||||
newOption = options.length - 1;
|
||||
|
|
@ -224,7 +225,7 @@ class GuiXboxOptionsList extends GuiControl {
|
|||
optionText.text.text = options[currentOption];
|
||||
}
|
||||
}
|
||||
if (Key.isPressed(Key.RIGHT) || Gamepad.isPressed(['dpadRight'])) {
|
||||
if (Key.isPressed(Key.RIGHT) || Gamepad.isPressed(['dpadRight']) || (Gamepad.getAxis('analogX') > 0.75 && !usedGamepad)) {
|
||||
var newOption = currentOption + 1;
|
||||
if (newOption >= options.length)
|
||||
newOption = 0;
|
||||
|
|
@ -237,6 +238,10 @@ class GuiXboxOptionsList extends GuiControl {
|
|||
optionText.text.text = options[currentOption];
|
||||
}
|
||||
}
|
||||
if (Math.abs(Gamepad.getAxis('analogX')) > 0.75)
|
||||
usedGamepad = true;
|
||||
else
|
||||
usedGamepad = false;
|
||||
}
|
||||
super.update(dt, mouseState);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -148,7 +148,7 @@ class LevelSelectGui extends GuiImage {
|
|||
recordButton.position = new Vector(560, 0);
|
||||
recordButton.vertSizing = Bottom;
|
||||
recordButton.horizSizing = Right;
|
||||
backButton.gamepadAccelerator = ["X"];
|
||||
recordButton.gamepadAccelerator = ["X"];
|
||||
recordButton.pressedAction = (e) -> {
|
||||
MarbleGame.instance.toRecord = true;
|
||||
MarbleGame.canvas.pushDialog(new MessageBoxOkDlg("The next mission you play will be recorded."));
|
||||
|
|
|
|||
|
|
@ -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 = ["A"];
|
||||
cancelButton.gamepadAccelerator = ["B"];
|
||||
cancelButton.pressedAction = (sender) -> {
|
||||
MarbleGame.canvas.popDialog(this);
|
||||
noFunc();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue