123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351 |
- // =============================================================================
- // 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 fillRemapList()
- {
- %device = $remapListDevice;
-
- OptionsMenuSettingsList.clear();
- //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;
-
- //see if we have any actual listed remappable keys for this movemap. if so, drop it from the listing
- %hasRemaps = false;
- for ( %r = 0; %r < $RemapCount; %r++ )
- {
- %testMapName = $RemapActionMap[%r].humanReadableName $= "" ? $RemapActionMap[%r].getName() : $RemapActionMap[%r].humanReadableName;
-
- if(%actionMapName $= %testMapName)
- {
- //got a match to at least one, so we're ok to continue
- %hasRemaps = true;
- break;
- }
- }
-
- if(!%hasRemaps)
- continue;
-
- 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);
-
- OptionsMenuSettingsList.addOptionRow("Control Set", "$activeRemapControlSet", %actionMapList, false, "controlSetChanged", true, "Which keybind control set to edit", $activeRemapControlSet);
-
- for ( %i = 0; %i < $RemapCount; %i++ )
- {
- 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];
-
- %buttonImageAsset = getButtonBitmap(%device, getField(%keyMap, 1));
-
- OptionsMenuSettingsList.addKeybindRow(getField(%keyMap, 0), %buttonImageAsset, "doKeyRemap", true, %description);
- }
- //OptionsMenuSettingsList.refresh();
- //OptionsMenu.addRow( %i, %this.buildFullMapString( %i ) );
- }
- function controlSetChanged()
- {
- $activeRemapControlSet = OptionsMenuSettingsList.getObject(0).getCurrentOption();
- fillRemapList();
- }
- function doKeyRemap( %row )
- {
- %rowIndex = %row.getParent().getObjectIndex(%row);
- %rowIndex--; //Offset the rowIndex to account for controlset option
- %name = $RemapName[%rowIndex];
- RemapDlg-->OptRemapText.text = "Re-bind \"" @ %name @ "\" to..." ;
- OptRemapInputCtrl.index = %rowIndex;
- Canvas.pushDialog( RemapDlg );
-
- //Let the options menu know
- %actionMap = $RemapActionMap[%rowIndex];
-
- OptionsMenu.onKeybindChanged(%actionMap, %name);
- }
- 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 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];
- %actionMap = $RemapActionMap[%this.index];
- // 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 );
-
- fillRemapList();
- 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 );
- fillRemapList();
- 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 @ "); Canvas.popDialog();";
- %cancelCommand = "Canvas.popDialog();";
-
- MessageBoxYesNo( "Key already in use", %remapWarnText, %doRemapCommand, %cancelCommand );
- }
- function findRemapCmdIndex( %command )
- {
- for ( %i = 0; %i < $RemapCount; %i++ )
- {
- if ( %command $= $RemapCmd[%i] )
- return( %i );
- }
- return( -1 );
- }
- /// This unbinds actions beyond %count associated to the
- /// particular actionMap %commmand.
- function unbindExtraActions( %command, %actionMap, %count )
- {
- %temp = %actionMap.getBinding( %command );
- 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 );
-
- %actionMap.unbind( %device, %action );
- }
- }
- function redoMapping( %device, %actionMap, %action, %cmd, %oldIndex, %newIndex )
- {
- //%actionMap.bind( %device, %action, $RemapCmd[%newIndex] );
- %actionMap.bind( %device, %action, %cmd );
-
- fillRemapList();
- }
|