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

@ -8,24 +8,27 @@ function OptRemapInputCtrl::onAxisEvent( %this, %device, %action, %axisVal)
return; return;
Canvas.popDialog( RemapDlg ); Canvas.popDialog( RemapDlg );
%this.doRemap(%device, %action, %axisVal); %this.doRemap(%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;
} }
} }
@ -34,39 +37,40 @@ function OptRemapInputCtrl::doRemap(%this, %device, %action, %axisVal)
%cmd = $RemapCmd[%this.index]; %cmd = $RemapCmd[%this.index];
%name = $RemapName[%this.index]; %name = $RemapName[%this.index];
%actionMap = $RemapActionMap[%this.index]; %actionMap = $RemapActionMap[%this.index];
echo("OptRemapInputCtrl::onInputEvent() - remapping details: " @ %cmd @ ", " @ %name @ ", " @ %actionMap @ " remapped to: " @ %device @ ", " @ %action); echo("OptRemapInputCtrl::onInputEvent() - remapping details: " @ %cmd @ ", " @ %name @ ", " @ %actionMap @ " remapped to: " @ %device @ ", " @ %action);
// Grab the friendly display name for this action // Grab the friendly display name for this action
// which we'll use when prompting the user below. // which we'll use when prompting the user below.
%mapName = getMapDisplayName( %device, %action ); %mapName = getMapDisplayName( %device, %action );
// 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 );
// If nothing was mapped to the previous command // If nothing was mapped to the previous command
// mapping then it's easy... just bind it. // mapping then it's easy... just bind it.
// If the previous command is the same as the // If the previous command is the same as the
// current then they hit the same input as what // current then they hit the same input as what
// 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 );
// If we get a negative index then the previous // If we get a negative index then the previous
// mapping was to an item that isn't included in // mapping was to an item that isn't included in
// the mapping list... so we cannot unmap it. // the mapping list... so we cannot unmap it.
if ( %prevMapIndex == -1 ) if ( %prevMapIndex == -1 )
@ -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 )
{ {
@ -105,8 +110,48 @@ 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++;
}