Update remapDlg.tscript

Fixes with handling of mouse to keyboard and vice versa remapping.  Removed some unused function arguments, some organization / cleanup.
This commit is contained in:
Sir-Skurpsalot 2025-12-12 20:03:39 -07:00 committed by GitHub
parent 04af5aafcc
commit b3b98cd58e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -14,18 +14,21 @@ function OptRemapInputCtrl::onAxisEvent( %this, %device, %action, %axisVal)
function OptRemapInputCtrl::onInputEvent( %this, %device, %action ) function OptRemapInputCtrl::onInputEvent( %this, %device, %action )
{ {
if(!startsWith(%device,$remapListDevice) && %action !$= "escape" && %action !$= "btn_start") if(%action $= "escape" || %action $= "btn_start"){
{ Canvas.popDialog( RemapDlg );
return; return;
} }
else // do nothing if gamepad is attempted to be used on the keyboard & mouse binds menu...
{ else if(%device $= "gamepad" && $remapListDevice $= "keyboard")
return;
// do nothing if keyboard or mouse is attempted to be used on the gamepad binds menu...
else if ((%device $= "mouse" || %device $= "keyboard") && $remapListDevice $= "gamePad")
return;
// procceed with remap if appropriate device used on binds menu...
else{
Canvas.popDialog( RemapDlg ); Canvas.popDialog( RemapDlg );
if(%action $= "escape" || %action $= "btn_start")
return;
%this.doRemap(%device, %action, 0); %this.doRemap(%device, %action, 0);
$RemapDirty = true;
} }
} }
@ -44,7 +47,7 @@ function OptRemapInputCtrl::doRemap(%this, %device, %action, %axisVal)
// Get the current command this action is mapped to. // Get the current command this action is mapped to.
%prevMap = %actionMap.getCommand( %device, %action ); %prevMap = %actionMap.getCommand( %device, %action );
//TODO: clear all existant keybinds to a command and then bind it so we only have a single one at all times // Make sure no other "action" (key / button press) is bound to this command
unbindExtraActions( %cmd, %actionMap, %device, 0 ); unbindExtraActions( %cmd, %actionMap, %device, 0 );
unbindExtraActions( %cmd, %actionMap, %device, 1 ); unbindExtraActions( %cmd, %actionMap, %device, 1 );
@ -55,14 +58,15 @@ function OptRemapInputCtrl::doRemap(%this, %device, %action, %axisVal)
// was already assigned. // was already assigned.
if ( %prevMap $= "" || %prevMap $= %cmd ) if ( %prevMap $= "" || %prevMap $= %cmd )
{ {
//unbindExtraActions( %cmd, %actionMap, 1 );
%actionMap.bind( %device, %action, %cmd ); %actionMap.bind( %device, %action, %cmd );
OptionsMenu.populateKBMControls(); OptionsMenu.populateKBMControls();
OptionsMenu.populateGamepadControls(); OptionsMenu.populateGamepadControls();
return; return;
} }
//------------------------------------------------------------------------------------------------------------------
// If this action (key / button press) was already bound to another command, undoing that is handled in this section
//------------------------------------------------------------------------------------------------------------------
// Look for the index of the previous mapping. // Look for the index of the previous mapping.
%prevMapIndex = findRemapCmdIndex( %prevMap ); %prevMapIndex = findRemapCmdIndex( %prevMap );
@ -77,22 +81,23 @@ function OptRemapInputCtrl::doRemap(%this, %device, %action, %axisVal)
// Setup the forced remapping callback command. // Setup the forced remapping callback command.
%callback = "redoMapping(" @ %device @ ", " @ %actionMap @ ", \"" @ %action @ "\", \"" @ %callback = "redoMapping(" @ %device @ ", " @ %actionMap @ ", \"" @ %action @ "\", \"" @
%cmd @ "\", " @ %prevMapIndex @ ", " @ %this.index @ ");"; %cmd @ "\");";
// Warn that we're about to remove the old mapping and // Warn that we're about to remove the old mapping and
// replace it with another. // replace it with another.
%prevCmdName = $RemapName[%prevMapIndex]; %prevCmdName = $RemapName[%prevMapIndex];
//Canvas.pushDialog( RemapConfirmDlg );
%remapWarnText = "\"" @ %mapName @ "\" is already bound to \"" @ %prevCmdName @ "\"! Do you wish to replace this mapping?"; %remapWarnText = "\"" @ %mapName @ "\" is already bound to \"" @ %prevCmdName @ "\"! Do you wish to replace this mapping?";
%doRemapCommand = "redoMapping(" @ %device @ ", " @ %actionMap @ ", \"" @ %action @ "\", \"" @ %doRemapCommand = "redoMapping(" @ %device @ ", " @ %actionMap @ ", \"" @ %action @ "\", \"" @
%cmd @ "\", " @ %prevMapIndex @ ", " @ %this.index @ ");"; %cmd @ "\");";
%cancelCommand = ""; %cancelCommand = "";
MessageBoxYesNo( "Key already in use", %remapWarnText, %doRemapCommand, %cancelCommand ); MessageBoxYesNo( "Key already in use", %remapWarnText, %doRemapCommand, %cancelCommand );
} }
/// This unbinds actions beyond %count associated to the /// This unbinds actions (buttons / key presses) beyond %count associated to the
/// particular actionMap %commmand. /// particular actionMap %commmand.
function unbindExtraActions( %command, %actionMap, %device, %count ) function unbindExtraActions( %command, %actionMap, %device, %count )
{ {
@ -106,7 +111,47 @@ function unbindExtraActions( %command, %actionMap, %device, %count )
%amDevice = getField( %temp, %i + 0 ); %amDevice = getField( %temp, %i + 0 );
%action = getField( %temp, %i + 1 ); %action = getField( %temp, %i + 1 );
if(%device !$= "" || %device $= %amDevice) if(amDevice !$= "") {
%actionMap.unbind( %device, %action ); %actionMap.unbind( %amDevice, %action ); //need to use %amDevice because could be changing from keyboard to mouse or vice versa
}
} }
} }
function findRemapCmdIndex( %command ){
for ( %i = 0; %i < $RemapCount; %i++ )
{
if ( %command $= $RemapCmd[%i] )
return( %i );
}
return( -1 );
}
function redoMapping( %device, %actionMap, %action, %cmd)
{
%actionMap.bind( %device, %action, %cmd );
OptionsMenu.populateKBMControls();
OptionsMenu.populateGamepadControls();
}
function addKeyRemap(%name, %actionMap, %device, %command, %description)
{
if(%name $= "" ||
%actionMap $= "" ||
%device $= "" ||
%command $= "")
{
error("addKeybindRemap() - tried to add a remap entry, but didn't have all the keeded info!");
return;
}
// "mouse" is accepted as a convenience, but the remappable actions related functions treat it same as "keyboard".
if(%device $= "mouse")
%device = "keyboard";
$RemapName[$RemapCount] = %name;
$RemapCmd[$RemapCount] = %command;
$RemapActionMap[$RemapCount] = %actionMap;
$RemapDevice[$RemapCount] = %device;
$RemapDescription[$RemapCount] = %description;
$RemapCount++;
}