mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-01-19 20:24:49 +00:00
Fixes with handling of mouse to keyboard and vice versa remapping. Removed some unused function arguments, some organization / cleanup.
158 lines
5.4 KiB
Plaintext
158 lines
5.4 KiB
Plaintext
function OptRemapInputCtrl::onAxisEvent( %this, %device, %action, %axisVal)
|
|
{
|
|
if(%device $= "mouse")
|
|
return;
|
|
if(!startsWith(%device,$remapListDevice))
|
|
return;
|
|
if(%axisVal != 1 && %axisVal != -1) //we want full presses on sticks to be sure
|
|
return;
|
|
|
|
Canvas.popDialog( RemapDlg );
|
|
|
|
%this.doRemap(%device, %action, %axisVal);
|
|
}
|
|
|
|
function OptRemapInputCtrl::onInputEvent( %this, %device, %action )
|
|
{
|
|
if(%action $= "escape" || %action $= "btn_start"){
|
|
Canvas.popDialog( RemapDlg );
|
|
return;
|
|
}
|
|
// 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 );
|
|
%this.doRemap(%device, %action, 0);
|
|
$RemapDirty = true;
|
|
}
|
|
}
|
|
|
|
function OptRemapInputCtrl::doRemap(%this, %device, %action, %axisVal)
|
|
{
|
|
%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 );
|
|
|
|
// Make sure no other "action" (key / button press) is bound to this command
|
|
unbindExtraActions( %cmd, %actionMap, %device, 0 );
|
|
unbindExtraActions( %cmd, %actionMap, %device, 1 );
|
|
|
|
// If nothing was mapped to the previous command
|
|
// mapping then it's easy... just bind it.
|
|
// If the previous command is the same as the
|
|
// current then they hit the same input as what
|
|
// was already assigned.
|
|
if ( %prevMap $= "" || %prevMap $= %cmd )
|
|
{
|
|
%actionMap.bind( %device, %action, %cmd );
|
|
OptionsMenu.populateKBMControls();
|
|
OptionsMenu.populateGamepadControls();
|
|
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.
|
|
%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 @ "\");";
|
|
|
|
// Warn that we're about to remove the old mapping and
|
|
// replace it with another.
|
|
%prevCmdName = $RemapName[%prevMapIndex];
|
|
|
|
%remapWarnText = "\"" @ %mapName @ "\" is already bound to \"" @ %prevCmdName @ "\"! Do you wish to replace this mapping?";
|
|
|
|
%doRemapCommand = "redoMapping(" @ %device @ ", " @ %actionMap @ ", \"" @ %action @ "\", \"" @
|
|
%cmd @ "\");";
|
|
|
|
%cancelCommand = "";
|
|
|
|
MessageBoxYesNo( "Key already in use", %remapWarnText, %doRemapCommand, %cancelCommand );
|
|
}
|
|
|
|
/// This unbinds actions (buttons / key presses) beyond %count associated to the
|
|
/// particular actionMap %commmand.
|
|
function unbindExtraActions( %command, %actionMap, %device, %count )
|
|
{
|
|
%temp = %actionMap.getBinding( %command );
|
|
if ( %temp $= "" )
|
|
return;
|
|
|
|
%count = getFieldCount( %temp ) - ( %count * 2 );
|
|
for ( %i = 0; %i < %count; %i += 2 )
|
|
{
|
|
%amDevice = getField( %temp, %i + 0 );
|
|
%action = getField( %temp, %i + 1 );
|
|
|
|
if(amDevice !$= "") {
|
|
%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++;
|
|
}
|