Torque3D/Templates/BaseGame/game/data/UI/scripts/controlsMenu.tscript
Sir-Skurpsalot 2e291d8ab2
Update controlsMenu.tscript
Fixed broken refreshing of the mapping list in the menu when you remap an action to a key / button that is already being used.  Got rid of unused  / broken / redundant functions in this script.
2025-12-09 18:31:01 -07:00

158 lines
4.6 KiB
Plaintext

// =============================================================================
// KEYBINDS MENU
// =============================================================================
function ControlsMenuDefaultsButton::onClick(%this)
{
//For this to work with module-style, we have to figure that somewhere, we'll set where our default keybind script is at.
//This can be hardcoded in your actual project.
//exec($KeybindPath);
//ControlsMenu.reload();
}
function getMapDisplayName( %device, %action )
{
if ( %device $= "keyboard" )
return( %action );
else if ( strstr( %device, "mouse" ) != -1 )
{
// Substitute "mouse" for "button" in the action string:
%pos = strstr( %action, "button" );
if ( %pos != -1 )
{
%mods = getSubStr( %action, 0, %pos );
%object = getSubStr( %action, %pos, 1000 );
%instance = getSubStr( %object, strlen( "button" ), 1000 );
return( %mods @ "mouse" @ ( %instance + 1 ) );
}
else
error( "Mouse input object other than button passed to getDisplayMapName!" );
}
else if ( strstr( %device, "joystick" ) != -1 )
{
// Substitute "joystick" for "button" in the action string:
%pos = strstr( %action, "button" );
if ( %pos != -1 )
{
%mods = getSubStr( %action, 0, %pos );
%object = getSubStr( %action, %pos, 1000 );
%instance = getSubStr( %object, strlen( "button" ), 1000 );
return( %mods @ "joystick" @ ( %instance + 1 ) );
}
else
{
%pos = strstr( %action, "pov" );
if ( %pos != -1 )
{
%wordCount = getWordCount( %action );
%mods = %wordCount > 1 ? getWords( %action, 0, %wordCount - 2 ) @ " " : "";
%object = getWord( %action, %wordCount - 1 );
switch$ ( %object )
{
case "upov": %object = "POV1 up";
case "dpov": %object = "POV1 down";
case "lpov": %object = "POV1 left";
case "rpov": %object = "POV1 right";
case "upov2": %object = "POV2 up";
case "dpov2": %object = "POV2 down";
case "lpov2": %object = "POV2 left";
case "rpov2": %object = "POV2 right";
default: %object = "";
}
return( %mods @ %object );
}
else
error( "Unsupported Joystick input object passed to getDisplayMapName!" );
}
}
else if ( strstr( %device, "gamepad" ) != -1 )
{
return %action;
%pos = strstr( %action, "button" );
if ( %pos != -1 )
{
%mods = getSubStr( %action, 0, %pos );
%object = getSubStr( %action, %pos, 1000 );
%instance = getSubStr( %object, strlen( "button" ), 1000 );
return( %mods @ "joystick" @ ( %instance + 1 ) );
}
else
{
%pos = strstr( %action, "thumb" );
if ( %pos != -1 )
{
//%instance = getSubStr( %action, strlen( "thumb" ), 1000 );
//return( "thumb" @ ( %instance + 1 ) );
return %action;
}
else
error( "Unsupported gamepad input object passed to getDisplayMapName!" );
}
}
return( "" );
}
function buildFullMapString( %index, %actionMap, %deviceType )
{
%name = $RemapName[%index];
%cmd = $RemapCmd[%index];
%temp = %actionMap.getBinding( %cmd );
if ( %temp $= "" )
return %name TAB "";
%mapString = "";
%count = getFieldCount( %temp );
for ( %i = 0; %i < %count; %i += 2 )
{
if ( %mapString !$= "" )
continue;
//%mapString = %mapString @ ", ";
%device = getField( %temp, %i + 0 );
%object = getField( %temp, %i + 1 );
if (startsWith(%device,"mouse"))
%deviceType = "mouse";
if(%deviceType !$= "" && !startsWith(%device, %deviceType))
continue;
%mapString = %mapString @ getMapDisplayName( %device, %object );
}
return %name TAB %mapString;
}
function ControlsMenuRebindButton::onClick(%this)
{
%name = $RemapName[%this.keybindIndex];
RemapDlg-->OptRemapText.text = "Re-bind \"" @ %name @ "\" to..." ;
OptRemapInputCtrl.index = %this.keybindIndex;
OptRemapInputCtrl.optionIndex = %this.optionIndex;
Canvas.pushDialog( RemapDlg );
}
function findRemapCmdIndex( %command )
{
for ( %i = 0; %i < $RemapCount; %i++ )
{
if ( %command $= $RemapCmd[%i] )
return( %i );
}
return( -1 );
}
function redoMapping( %device, %actionMap, %action, %cmd, %oldIndex, %newIndex )
{
//%actionMap.bind( %device, %action, $RemapCmd[%newIndex] );
%actionMap.bind( %device, %action, %cmd );
OptionsMenu.populateKBMControls();
OptionsMenu.populateGamepadControls();
}