mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-03-01 19:43:49 +00:00
77 lines
No EOL
2.8 KiB
Text
77 lines
No EOL
2.8 KiB
Text
function OptRemapInputCtrl::onInputEvent( %this, %device, %action )
|
|
{
|
|
Canvas.popDialog( RemapDlg );
|
|
|
|
if ( %device $= "keyboard" && %action $= "escape" )
|
|
return;
|
|
else if( %device $= "gamepad" && %action $= "btn_start" )
|
|
return;
|
|
|
|
%cmd = $RemapCmd[%this.index];
|
|
%name = $RemapName[%this.index];
|
|
%actionMap = $RemapActionMap[%this.index];
|
|
|
|
echo("OptRemapInputCtrl::onInputEvent() - remapping details: " @ %cmd @ ", " @ %name @ ", " @ %actionMap @ " remapped to: " @ %device @ ", " @ %action);
|
|
|
|
// Grab the friendly display name for this action
|
|
// which we'll use when prompting the user below.
|
|
%mapName = getMapDisplayName( %device, %action );
|
|
|
|
// Get the current command this action is mapped to.
|
|
%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
|
|
unbindExtraActions( %cmd, %actionMap, 0 );
|
|
unbindExtraActions( %cmd, %actionMap, 1 );
|
|
|
|
// If nothing was mapped to the previous command
|
|
// mapping then it's easy... just bind it.
|
|
if ( %prevMap $= "" )
|
|
{
|
|
//unbindExtraActions( %cmd, %actionMap, 1 );
|
|
%actionMap.bind( %device, %action, %cmd );
|
|
|
|
OptionsMenu.syncGui();
|
|
return;
|
|
}
|
|
|
|
// If the previous command is the same as the
|
|
// current then they hit the same input as what
|
|
// was already assigned.
|
|
if ( %prevMap $= %cmd )
|
|
{
|
|
//unbindExtraActions( %cmd, %actionMap, 0 );
|
|
%actionMap.bind( %device, %action, %cmd );
|
|
|
|
OptionsMenu.syncGui();
|
|
return;
|
|
}
|
|
|
|
// Look for the index of the previous mapping.
|
|
%prevMapIndex = findRemapCmdIndex( %prevMap );
|
|
|
|
// If we get a negative index then the previous
|
|
// mapping was to an item that isn't included in
|
|
// the mapping list... so we cannot unmap it.
|
|
if ( %prevMapIndex == -1 )
|
|
{
|
|
MessageBoxOK( "Remap Failed", "\"" @ %mapName @ "\" is already bound to a non-remappable command!" );
|
|
return;
|
|
}
|
|
|
|
// Setup the forced remapping callback command.
|
|
%callback = "redoMapping(" @ %device @ ", " @ %actionMap @ ", \"" @ %action @ "\", \"" @
|
|
%cmd @ "\", " @ %prevMapIndex @ ", " @ %this.index @ ");";
|
|
|
|
// Warn that we're about to remove the old mapping and
|
|
// replace it with another.
|
|
%prevCmdName = $RemapName[%prevMapIndex];
|
|
//Canvas.pushDialog( RemapConfirmDlg );
|
|
|
|
%remapWarnText = "\"" @ %mapName @ "\" is already bound to \"" @ %prevCmdName @ "\"! Do you wish to replace this mapping?";
|
|
%doRemapCommand = "redoMapping(" @ %device @ ", " @ %actionMap @ ", \"" @ %action @ "\", \"" @
|
|
%cmd @ "\", " @ %prevMapIndex @ ", " @ %this.index @ ");";
|
|
%cancelCommand = "";
|
|
|
|
MessageBoxYesNo( "Key already in use", %remapWarnText, %doRemapCommand, %cancelCommand );
|
|
} |