Gamepad binds showed in Freeplay's hint

_lastDeviceUsed -> lastDeviceUsed
This commit is contained in:
MrMadera
2026-03-17 22:56:32 -06:00
committed by Hundrec
parent c3d3d2e547
commit 0f7859bfb6
3 changed files with 44 additions and 8 deletions
+34 -7
View File
@@ -1,5 +1,6 @@
package funkin.input;
import funkin.util.InputUtil;
import flixel.input.gamepad.FlxGamepad;
import flixel.util.FlxDirectionFlags;
import flixel.input.FlxInput.FlxInputState;
@@ -381,22 +382,22 @@ class Controls extends FlxActionSet
public function getDialogueName(action:FlxActionDigital, ?ignoreSurrounding:Bool = false):String
{
if (action.inputs.length == 0) return 'N/A';
var input = action.inputs[0];
var input = FunkinAction.lastDeviceUsed == KEYBOARD ? action.inputs[0] : action.inputs[1];
if (ignoreSurrounding == false)
{
return switch (input.device)
return switch (FunkinAction.lastDeviceUsed)
{
case KEYBOARD: return '[${(input.inputID : FlxKey)}]';
case GAMEPAD: return '(${(input.inputID : FlxGamepadInputID)})';
case KEYBOARD: return '[${InputUtil.format(input.inputID, Keys).toUpperCase()}]';
case GAMEPAD: return '(${InputUtil.format(input.inputID, Gamepad(input.deviceID)).toUpperCase()})';
case device: throw 'unhandled device: $device';
}
}
else
{
return switch (input.device)
return switch (FunkinAction.lastDeviceUsed)
{
case KEYBOARD: return '${(input.inputID : FlxKey)}';
case GAMEPAD: return '${(input.inputID : FlxGamepadInputID)}';
case KEYBOARD: return InputUtil.format(input.inputID, Keys).toUpperCase();
case GAMEPAD: return InputUtil.format(input.inputID, Gamepad(input.deviceID)).toUpperCase();
case device: throw 'unhandled device: $device';
}
}
@@ -1203,6 +1204,7 @@ class FunkinAction extends FlxActionDigital
*/
public function checkPressed():Bool
{
if (checkFiltered(PRESSED)) updateLastDeviceUsed();
return checkFiltered(PRESSED);
}
@@ -1211,6 +1213,7 @@ class FunkinAction extends FlxActionDigital
*/
public function checkJustPressed():Bool
{
if (checkFiltered(JUST_PRESSED)) updateLastDeviceUsed();
return checkFiltered(JUST_PRESSED);
}
@@ -1227,6 +1230,7 @@ class FunkinAction extends FlxActionDigital
*/
public function checkJustReleased():Bool
{
if (checkFiltered(JUST_RELEASED)) updateLastDeviceUsed();
return checkFiltered(JUST_RELEASED);
}
@@ -1353,6 +1357,29 @@ class FunkinAction extends FlxActionDigital
return triggered;
}
public static var lastDeviceUsed:FlxInputDevice;
/**
* Checks which is the last device you have used and stores the value in `lastDeviceUsed`.
*/
public function updateLastDeviceUsed()
{
if (FlxG.keys.pressed.ANY)
{
lastDeviceUsed = FlxInputDevice.KEYBOARD;
return;
}
if (FlxG.gamepads.lastActive != null)
{
lastDeviceUsed = FlxInputDevice.GAMEPAD;
return;
}
// Default value (just in case everything's null somehow)
lastDeviceUsed = FlxInputDevice.KEYBOARD;
}
}
/**
@@ -1758,6 +1758,15 @@ class FreeplayState extends MusicBeatSubState
handleTouchSelectionScroll(elapsed);
#end
#if FEATURE_TOUCH_CONTROLS
if (ControlsHandler.usingExternalInputDevice)
charSelectHint.text = 'Press [ ${controls.getDialogueNameFromControl(FREEPLAY_CHAR_SELECT, true)} ] to change characters';
else
charSelectHint.text = 'Tap the DJ to change characters';
#else
charSelectHint.text = 'Press [ ${controls.getDialogueNameFromControl(FREEPLAY_CHAR_SELECT, true)} ] to change characters';
#end
handleDirectionalInput(elapsed);
final wheelAmount:Int = Std.int(FlxMath.bound(FlxG.mouse.wheel, -1, 1));
+1 -1
View File
@@ -18,7 +18,7 @@ class InputUtil
return switch (device)
{
case Keys: getKeyName(id);
case Gamepad(gamepadID): getButtonName(id, FlxG.gamepads.getByID(gamepadID));
case Gamepad(gamepadID): FlxG.gamepads.getByID(gamepadID) != null ? getButtonName(id, FlxG.gamepads.getByID(gamepadID)) : 'N/A';
}
}