2017-02-24 08:40:56 +00:00
// =============================================================================
// 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.
2020-06-01 08:55:25 +00:00
//exec($KeybindPath);
//ControlsMenu.reload();
2017-02-24 08:40:56 +00:00
}
2019-09-06 05:00:17 +00:00
function getMapDisplayName ( % device , % action )
2017-02-24 08:40:56 +00:00
{
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!" ) ;
}
}
2020-06-01 08:55:25 +00:00
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!" ) ;
}
}
2017-02-24 08:40:56 +00:00
return ( "" ) ;
}
2020-06-01 08:55:25 +00:00
function buildFullMapString ( % index , % actionMap , % deviceType )
2017-02-24 08:40:56 +00:00
{
% name = $ RemapName [ % index ] ;
% cmd = $ RemapCmd [ % index ] ;
2020-06-01 08:55:25 +00:00
% temp = % actionMap . getBinding ( % cmd ) ;
2017-02-24 08:40:56 +00:00
if ( % temp $ = "" )
return % name TAB "" ;
% mapString = "" ;
% count = getFieldCount ( % temp ) ;
for ( % i = 0 ; % i < % count ; % i + = 2 )
{
if ( % mapString ! $ = "" )
2020-06-01 08:55:25 +00:00
continue ;
//%mapString = %mapString @ ", ";
2017-02-24 08:40:56 +00:00
% device = getField ( % temp , % i + 0 ) ;
% object = getField ( % temp , % i + 1 ) ;
2020-06-01 08:55:25 +00:00
if ( % deviceType ! $ = "" & & ! startsWith ( % device , % deviceType ) )
continue ;
% mapString = % mapString @ getMapDisplayName ( % device , % object ) ;
2017-02-24 08:40:56 +00:00
}
return % name TAB % mapString ;
}
2020-06-01 08:55:25 +00:00
function fillRemapList ( )
2017-02-24 08:40:56 +00:00
{
2020-06-01 08:55:25 +00:00
% device = $ remapListDevice ;
OptionsMenuSettingsList . clearRows ( ) ;
//build out our list of action maps
% actionMapCount = ActionMapGroup . getCount ( ) ;
% actionMapList = "" ;
for ( % i = 0 ; % i < % actionMapCount ; % i + + )
{
% actionMap = ActionMapGroup . getObject ( % i ) ;
if ( % actionMap = = GlobalActionMap . getId ( ) )
continue ;
% actionMapName = % actionMap . humanReadableName $ = "" ? % actionMap . getName ( ) : % actionMap . humanReadableName ;
if ( % actionMapList $ = "" )
% actionMapList = % actionMapName ;
else
% actionMapList = % actionMapList TAB % actionMapName ;
}
//If we didn't find any valid actionMaps, then just exit out
if ( % actionMapList $ = "" )
return ;
if ( $ activeRemapControlSet $ = "" )
$ activeRemapControlSet = getField ( % actionMapList , 0 ) ;
2017-02-24 08:40:56 +00:00
2020-06-01 08:55:25 +00:00
OptionsMenuSettingsList . addOptionRow ( "Control Set" , % actionMapList , false , "controlSetChanged" , - 1 , - 30 , true , "Which keybind control set to edit" , $ activeRemapControlSet ) ;
2017-02-24 08:40:56 +00:00
for ( % i = 0 ; % i < $ RemapCount ; % i + + )
2020-06-01 08:55:25 +00:00
{
if ( % device ! $ = "" & & % device ! $ = $ RemapDevice [ % i ] )
continue ;
% actionMapName = $ RemapActionMap [ % i ] . humanReadableName $ = "" ? $ RemapActionMap [ % i ] . getName ( ) : $ RemapActionMap [ % i ] . humanReadableName ;
if ( $ activeRemapControlSet ! $ = % actionMapName )
continue ;
% keyMap = buildFullMapString ( % i , $ RemapActionMap [ % i ] , % device ) ;
% description = $ RemapDescription [ % i ] ;
OptionsMenuSettingsList . addKeybindRow ( getField ( % keyMap , 0 ) , getButtonBitmap ( % device , getField ( % keyMap , 1 ) ) , "doKeyRemap" , - 1 , - 15 , true , % description ) ;
}
OptionsMenuSettingsList . refresh ( ) ;
//OptionsMenu.addRow( %i, %this.buildFullMapString( %i ) );
2017-02-24 08:40:56 +00:00
}
2020-06-01 08:55:25 +00:00
function controlSetChanged ( )
2017-02-24 08:40:56 +00:00
{
2020-06-01 08:55:25 +00:00
$ activeRemapControlSet = OptionsMenuSettingsList . getCurrentOption ( 0 ) ;
fillRemapList ( ) ;
}
function doKeyRemap ( % rowIndex )
{
% rowIndex - - ; //Offset the rowIndex to account for controlset option
% name = $ RemapName [ % rowIndex ] ;
2017-02-24 08:40:56 +00:00
RemapDlg - - > OptRemapText . setValue ( "Re-bind \"" @ % name @ "\" to..." ) ;
2020-06-01 08:55:25 +00:00
OptRemapInputCtrl . index = % rowIndex ;
2017-02-24 08:40:56 +00:00
Canvas . pushDialog ( RemapDlg ) ;
}
function ControlsMenuRebindButton : : onClick ( % this )
{
% name = $ RemapName [ % this . keybindIndex ] ;
RemapDlg - - > OptRemapText . setValue ( "Re-bind \"" @ % name @ "\" to..." ) ;
OptRemapInputCtrl . index = % this . keybindIndex ;
OptRemapInputCtrl . optionIndex = % this . optionIndex ;
Canvas . pushDialog ( RemapDlg ) ;
}
function OptRemapInputCtrl : : onInputEvent ( % this , % device , % action )
{
//error( "** onInputEvent called - device = " @ %device @ ", action = " @ %action @ " **" );
Canvas . popDialog ( RemapDlg ) ;
// Test for the reserved keystrokes:
if ( % device $ = "keyboard" )
{
// Cancel...
if ( % action $ = "escape" )
{
// Do nothing...
return ;
}
}
% cmd = $ RemapCmd [ % this . index ] ;
% name = $ RemapName [ % this . index ] ;
2020-06-01 08:55:25 +00:00
% actionMap = $ RemapActionMap [ % this . index ] ;
2017-02-24 08:40:56 +00:00
// Grab the friendly display name for this action
// which we'll use when prompting the user below.
2020-06-01 08:55:25 +00:00
% mapName = getMapDisplayName ( % device , % action ) ;
2017-02-24 08:40:56 +00:00
// Get the current command this action is mapped to.
2020-06-01 08:55:25 +00:00
% 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 ) ;
2017-02-24 08:40:56 +00:00
// If nothing was mapped to the previous command
// mapping then it's easy... just bind it.
if ( % prevMap $ = "" )
{
2020-06-01 08:55:25 +00:00
//unbindExtraActions( %cmd, %actionMap, 1 );
% actionMap . bind ( % device , % action , % cmd ) ;
2017-02-24 08:40:56 +00:00
2020-06-01 08:55:25 +00:00
fillRemapList ( ) ;
2017-02-24 08:40:56 +00:00
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 )
{
2020-06-01 08:55:25 +00:00
//unbindExtraActions( %cmd, %actionMap, 0 );
% actionMap . bind ( % device , % action , % cmd ) ;
2017-02-24 08:40:56 +00:00
2020-06-01 08:55:25 +00:00
fillRemapList ( ) ;
2017-02-24 08:40:56 +00:00
return ;
}
// Look for the index of the previous mapping.
2020-06-01 08:55:25 +00:00
% prevMapIndex = findRemapCmdIndex ( % prevMap ) ;
2017-02-24 08:40:56 +00:00
// 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.
2020-06-01 08:55:25 +00:00
% callback = "redoMapping(" @ % device @ ", " @ % actionMap @ ", \"" @ % action @ "\", \"" @
2017-02-24 08:40:56 +00:00
% 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 ) ;
RemapConfirmationText . setText ( "\"" @ % mapName @ "\" is already bound to \""
@ % prevCmdName @ "\"! Do you wish to replace this mapping?" ) ;
2020-06-01 08:55:25 +00:00
RemapConfirmationYesButton . command = "redoMapping(" @ % device @ ", " @ % actionMap @ ", \"" @ % action @ "\", \"" @
2017-02-24 08:40:56 +00:00
% cmd @ "\", " @ % prevMapIndex @ ", " @ % this . index @ "); Canvas.popDialog();" ;
RemapConfirmationNoButton . command = "Canvas.popDialog();" ;
/ * MessageBoxYesNo ( "Warning" ,
"\"" @ % mapName @ "\" is already bound to \""
@ % prevCmdName @ "\"!\nDo you wish to replace this mapping?" ,
% callback , "" ) ; * /
}
2020-06-01 08:55:25 +00:00
function findRemapCmdIndex ( % command )
2017-02-24 08:40:56 +00:00
{
for ( % i = 0 ; % i < $ RemapCount ; % i + + )
{
if ( % command $ = $ RemapCmd [ % i ] )
return ( % i ) ;
}
return ( - 1 ) ;
}
/// This unbinds actions beyond %count associated to the
2020-06-01 08:55:25 +00:00
/// particular actionMap %commmand.
function unbindExtraActions ( % command , % actionMap , % count )
2017-02-24 08:40:56 +00:00
{
2020-06-01 08:55:25 +00:00
% temp = % actionMap . getBinding ( % command ) ;
2017-02-24 08:40:56 +00:00
if ( % temp $ = "" )
return ;
% count = getFieldCount ( % temp ) - ( % count * 2 ) ;
for ( % i = 0 ; % i < % count ; % i + = 2 )
{
% device = getField ( % temp , % i + 0 ) ;
% action = getField ( % temp , % i + 1 ) ;
2020-06-01 08:55:25 +00:00
% actionMap . unbind ( % device , % action ) ;
2017-02-24 08:40:56 +00:00
}
}
2020-06-01 08:55:25 +00:00
function redoMapping ( % device , % actionMap , % action , % cmd , % oldIndex , % newIndex )
2017-02-24 08:40:56 +00:00
{
//%actionMap.bind( %device, %action, $RemapCmd[%newIndex] );
2020-06-01 08:55:25 +00:00
% actionMap . bind ( % device , % action , % cmd ) ;
2017-02-24 08:40:56 +00:00
2020-06-01 08:55:25 +00:00
fillRemapList ( ) ;
2017-02-24 08:40:56 +00:00
}