From 67ac556ecd4dc339fbf1fbc15f0148f0112d1f93 Mon Sep 17 00:00:00 2001 From: Areloch Date: Sun, 31 Dec 2023 12:46:48 -0600 Subject: [PATCH] - Added ability to explicitly execute a guiControl's console and altConsole command - Fixed formatting of resolution strings for the internal values, allowing them to be properly parsed and applied by the options menu/canvas - Fixed display of Display Device on option's menu - Fixed Issue of it not displaying any keybinds in keyboard/gamepad options if there's only a single actionmap - Added 'hold to scroll' action to optionsMenu - Added apply button to options menu - Added remap button to options menu when on keyboard/gamepad keybinds categories - Fixed up the remap logic so remapping a key only unbinds the matched device being bound, so binds for different devices are untouched - Made keybinds options properly refresh when keybinds are changed - Shifted keyboard "go" keybind for menu nav from Enter to Space for easier use - Removed stick keybinds from gamepad --- Engine/source/gui/core/guiControl.cpp | 16 +++ .../game/core/gui/scripts/canvas.tscript | 2 +- .../rendering/scripts/graphicsOptions.tscript | 38 +++++- .../scripts/client/defaultKeybinds.tscript | 8 +- .../game/data/UI/guis/ChooseLevelMenu.tscript | 2 +- .../game/data/UI/guis/GameMenu.tscript | 2 +- .../game/data/UI/guis/joinServerMenu.tscript | 2 +- .../game/data/UI/guis/mainMenu.tscript | 6 +- .../game/data/UI/guis/messageBoxDlg.tscript | 2 +- .../game/data/UI/guis/optionsMenu.gui | 32 ++++- .../game/data/UI/guis/optionsMenu.tscript | 109 ++++++++++++------ .../BaseGame/game/data/UI/guis/remapDlg.gui | 1 + .../game/data/UI/guis/remapDlg.tscript | 81 +++++++++---- .../game/data/UI/scripts/controlsMenu.tscript | 17 --- 14 files changed, 223 insertions(+), 95 deletions(-) diff --git a/Engine/source/gui/core/guiControl.cpp b/Engine/source/gui/core/guiControl.cpp index a5e21a984..6a888485d 100644 --- a/Engine/source/gui/core/guiControl.cpp +++ b/Engine/source/gui/core/guiControl.cpp @@ -2947,3 +2947,19 @@ DefineEngineMethod( GuiControl, getAspect, F32, (),, const Point2I &ext = object->getExtent(); return (F32)ext.x / (F32)ext.y; } + +//----------------------------------------------------------------------------- + +DefineEngineMethod(GuiControl, execCommand, const char*, (), , + "Forcefully executes the command field value(if any) on this guiControl.\n" + "@return The results of the evaluation of the command.") +{ + return object->execConsoleCallback(); +} + +DefineEngineMethod(GuiControl, execAltCommand, const char*, (), , + "Forcefully executes the altCommand field value(if any) on this guiControl.\n" + "@return The results of the evaluation of the altCommand.") +{ + return object->execAltConsoleCallback(); +} diff --git a/Templates/BaseGame/game/core/gui/scripts/canvas.tscript b/Templates/BaseGame/game/core/gui/scripts/canvas.tscript index 79988556d..8d6a0d98b 100644 --- a/Templates/BaseGame/game/core/gui/scripts/canvas.tscript +++ b/Templates/BaseGame/game/core/gui/scripts/canvas.tscript @@ -94,7 +94,7 @@ function configureCanvas() if ($pref::Video::deviceMode != $Video::ModeFullscreen) $pref::Video::FullScreen = false; %modeStr = Canvas.prefsToModeStr(); - + echo("--------------"); echo("Attempting to set resolution to \"" @ %modeStr @ "\""); diff --git a/Templates/BaseGame/game/core/rendering/scripts/graphicsOptions.tscript b/Templates/BaseGame/game/core/rendering/scripts/graphicsOptions.tscript index 42d6bef5f..450be2512 100644 --- a/Templates/BaseGame/game/core/rendering/scripts/graphicsOptions.tscript +++ b/Templates/BaseGame/game/core/rendering/scripts/graphicsOptions.tscript @@ -9,9 +9,10 @@ function OptionsQualityLevel::isCurrent( %this ) %value = %this.getValue( %i ); if ( getVariable( %pref ) !$= %value ) + { return false; + } } - return true; } @@ -971,7 +972,7 @@ function VideoSettingsGroup::populateDisplaySettings(%this) { class = "OptionsQualityLevel"; displayName = %device; - key["$pref::Video::displayDeviceId"] = %device; + key["$pref::Video::deviceId"] = %i; }; DisplayDevicesGroup.add(%entry); @@ -985,8 +986,9 @@ function VideoSettingsGroup::populateDisplaySettings(%this) for(%i=0; %i < getFieldCount(%resolutionList); %i++) { %rawResolution = getField(%resolutionList, %i); - %prettyResolution = _makePrettyResString(%rawResolution); + %prettyResolution = _makePrettyResString(%rawResolution); + %entry = new ArrayObject() { class = "OptionsQualityLevel"; @@ -997,6 +999,26 @@ function VideoSettingsGroup::populateDisplaySettings(%this) DisplayResSettingsGroup.add(%entry); } } + else + { + if($platform !$= "windows") + %monitorRect = Canvas.getMonitorUsableRect($pref::Video::deviceId); + else + %monitorRect = Canvas.getMonitorRect($pref::Video::deviceId); + + %rawResolution = getWords(%monitorRect, 2); + + %prettyResolution = _makePrettyResString(%rawResolution); + + %entry = new ArrayObject() + { + class = "OptionsQualityLevel"; + displayName = %prettyResolution; + key["$pref::Video::Resolution"] = %rawResolution; + }; + + DisplayResSettingsGroup.add(%entry); + } %refreshList = getScreenRefreshList($pref::Video::mode); for(%i=0; %i < getFieldCount(%refreshList); %i++) @@ -1100,6 +1122,7 @@ function updateDisplayOptionsSettings() $pref::Video::FullScreen = %newFullScreen; $pref::Video::RefreshRate = %newRefresh; $pref::Video::AA = %newAA; + configureCanvas(); } } @@ -1135,6 +1158,11 @@ function PostFXLightRayOptionsGroup::onApply(%this) function getCurrentQualityLevel(%qualityGroup) { + /*if(%qualityGroup.getId() == DisplayResSettingsGroup.getId()) + { + echo("Checking current quality level of Display Resolution"); + }*/ + for ( %i=0; %i < %qualityGroup.getCount(); %i++ ) { %level = %qualityGroup.getObject( %i ); @@ -1349,7 +1377,7 @@ function getScreenResolutionList(%deviceID, %deviceMode) if ((%deviceMode == $Video::ModeBorderless) && ($platform !$= "windows")) { %borderlessRes = getWords(Canvas.getMonitorUsableRect(%deviceID), 2); - return _makePrettyResString(%borderlessRes); + return %borderlessRes; } %resCount = Canvas.getModeCount(); @@ -1361,7 +1389,7 @@ function getScreenResolutionList(%deviceID, %deviceMode) if (!Canvas.checkCanvasRes(%testResString, %deviceID, %deviceMode, false)) continue; - %testRes = _makePrettyResString( %testResString ); + %testRes = getWords(%testResString, 0, 1); //sanitize %found = false; diff --git a/Templates/BaseGame/game/data/ExampleModule/scripts/client/defaultKeybinds.tscript b/Templates/BaseGame/game/data/ExampleModule/scripts/client/defaultKeybinds.tscript index 913b088fc..9a9a3ddd5 100644 --- a/Templates/BaseGame/game/data/ExampleModule/scripts/client/defaultKeybinds.tscript +++ b/Templates/BaseGame/game/data/ExampleModule/scripts/client/defaultKeybinds.tscript @@ -17,10 +17,10 @@ addKeyRemap("Ascend", "ExampleMoveMap", "keyboard", "moveup", "Makes the camera addKeyRemap("Descend", "ExampleMoveMap", "keyboard", "movedown", "Makes the camera descend"); addKeyRemap("Jump", "ExampleMoveMap", "keyboard", "jump", "Jump"); -addKeyRemap("Forward", "ExampleMoveMap", "gamepad", "gamePadMoveY", "Forward Movement"); -addKeyRemap("Backward", "ExampleMoveMap", "gamepad", "gamePadMoveY", "Backward Movement"); -addKeyRemap("Strafe Left", "ExampleMoveMap", "gamepad", "gamePadMoveX", "Left Strafing Movement"); -addKeyRemap("Strafe Right", "ExampleMoveMap", "gamepad", "gamePadMoveX", "Right Strafing Movement"); +//addKeyRemap("Forward", "ExampleMoveMap", "gamepad", "gamePadMoveY", "Forward Movement"); +//addKeyRemap("Backward", "ExampleMoveMap", "gamepad", "gamePadMoveY", "Backward Movement"); +//addKeyRemap("Strafe Left", "ExampleMoveMap", "gamepad", "gamePadMoveX", "Left Strafing Movement"); +//addKeyRemap("Strafe Right", "ExampleMoveMap", "gamepad", "gamePadMoveX", "Right Strafing Movement"); addKeyRemap("Jump", "ExampleMoveMap", "gamepad", "jump", "Jump"); //------------------------------------------------------------------------------ diff --git a/Templates/BaseGame/game/data/UI/guis/ChooseLevelMenu.tscript b/Templates/BaseGame/game/data/UI/guis/ChooseLevelMenu.tscript index 646a55101..df9f1f372 100644 --- a/Templates/BaseGame/game/data/UI/guis/ChooseLevelMenu.tscript +++ b/Templates/BaseGame/game/data/UI/guis/ChooseLevelMenu.tscript @@ -147,7 +147,7 @@ if(!isObject( ChooseLevelActionMap ) ) ChooseLevelActionMap.bind( gamepad, lpov, BaseUINavigatePrev ); ChooseLevelActionMap.bind( gamepad, rpov, BaseUINavigateNext ); - ChooseLevelActionMap.bind( keyboard, Enter, ChooseLevelBegin ); + ChooseLevelActionMap.bind( keyboard, Space, ChooseLevelBegin ); ChooseLevelActionMap.bind( gamepad, btn_a, ChooseLevelBegin ); } diff --git a/Templates/BaseGame/game/data/UI/guis/GameMenu.tscript b/Templates/BaseGame/game/data/UI/guis/GameMenu.tscript index 0b6177604..23a86e491 100644 --- a/Templates/BaseGame/game/data/UI/guis/GameMenu.tscript +++ b/Templates/BaseGame/game/data/UI/guis/GameMenu.tscript @@ -73,7 +73,7 @@ if(!isObject( GameMenuActionMap ) ) GameMenuActionMap.bind( gamepad, upov, BaseUINavigatePrev ); GameMenuActionMap.bind( gamepad, dpov, BaseUINavigateNext ); - GameMenuActionMap.bind( keyboard, Enter, BaseUIActivateSelected ); + GameMenuActionMap.bind( keyboard, Space, BaseUIActivateSelected ); GameMenuActionMap.bind( gamepad, btn_a, BaseUIActivateSelected ); GameMenuActionMap.bindCmd( keyboard, Escape, "Canvas.popDialog(GameMenu);", "" ); diff --git a/Templates/BaseGame/game/data/UI/guis/joinServerMenu.tscript b/Templates/BaseGame/game/data/UI/guis/joinServerMenu.tscript index f612a3117..15b8580f1 100644 --- a/Templates/BaseGame/game/data/UI/guis/joinServerMenu.tscript +++ b/Templates/BaseGame/game/data/UI/guis/joinServerMenu.tscript @@ -17,7 +17,7 @@ if(!isObject( JoinServerActionMap ) ) JoinServerActionMap.bindCmd( keyboard, e, "JoinServerMenu.queryLan();" ); JoinServerActionMap.bindCmd( gamepad, btn_y, "JoinServerMenu.queryLan();" ); - JoinServerActionMap.bindCmd( keyboard, Enter, "JoinServerMenu::join();" ); + JoinServerActionMap.bindCmd( keyboard, Space, "JoinServerMenu::join();" ); JoinServerActionMap.bindCmd( gamepad, btn_a, "JoinServerMenu::join();" ); } diff --git a/Templates/BaseGame/game/data/UI/guis/mainMenu.tscript b/Templates/BaseGame/game/data/UI/guis/mainMenu.tscript index fda741b68..770857ec8 100644 --- a/Templates/BaseGame/game/data/UI/guis/mainMenu.tscript +++ b/Templates/BaseGame/game/data/UI/guis/mainMenu.tscript @@ -9,6 +9,8 @@ function MainMenuGui::onWake(%this) { $MenuList = MainMenuButtonList; $MenuList.listPosition = 0; + + $MenuList.syncGui(); } function MainMenuGui::onSleep(%this) @@ -25,7 +27,7 @@ if(!isObject( BaseUIActionMap ) ) BaseUIActionMap.bind( gamepad, upov, BaseUINavigatePrev ); BaseUIActionMap.bind( gamepad, dpov, BaseUINavigateNext ); - BaseUIActionMap.bind( keyboard, Enter, BaseUIActivateSelected ); + BaseUIActionMap.bind( keyboard, Space, BaseUIActivateSelected ); BaseUIActionMap.bind( gamepad, btn_a, BaseUIActivateSelected ); BaseUIActionMap.bind( keyboard, Escape, BaseUIBackOut ); @@ -75,9 +77,7 @@ function BaseUIStickNavigate(%val) else if(%val == -1) BaseUINavigatePrev(1); else - { cancel($BaseUI::scrollSchedule); - } } function BaseUIBackOut(%val) diff --git a/Templates/BaseGame/game/data/UI/guis/messageBoxDlg.tscript b/Templates/BaseGame/game/data/UI/guis/messageBoxDlg.tscript index 7ef43ba05..71dc9bbea 100644 --- a/Templates/BaseGame/game/data/UI/guis/messageBoxDlg.tscript +++ b/Templates/BaseGame/game/data/UI/guis/messageBoxDlg.tscript @@ -125,7 +125,7 @@ if(!isObject( MessageBoxActionMap ) ) { new ActionMap(MessageBoxActionMap){}; - MessageBoxActionMap.bind( keyboard, Enter, messageBoxYesClicked ); + MessageBoxActionMap.bind( keyboard, Space, messageBoxYesClicked ); MessageBoxActionMap.bind( gamepad, btn_a, messageBoxYesClicked ); MessageBoxActionMap.bind( keyboard, Escape, messageBoxNoClicked ); diff --git a/Templates/BaseGame/game/data/UI/guis/optionsMenu.gui b/Templates/BaseGame/game/data/UI/guis/optionsMenu.gui index 9ef81c263..08e312d52 100644 --- a/Templates/BaseGame/game/data/UI/guis/optionsMenu.gui +++ b/Templates/BaseGame/game/data/UI/guis/optionsMenu.gui @@ -192,11 +192,41 @@ $guiContent = new GuiControl(OptionsMenu) { tooltipProfile = "GuiToolTipProfile"; class = "MenuInputButton"; }; - new GuiIconButtonCtrl(OptionsMenuResetBtn) { + new GuiIconButtonCtrl(OptionsMenuRemapBtn) { + BitmapAsset = "UI:Keyboard_Black_Space_image"; + sizeIconToButton = "1"; + makeIconSquare = "1"; + textLocation = "Center"; + text = "Remap"; + position = "850 0"; + extent = "140 40"; + horizSizing = "left"; + vertSizing = "center"; + profile = "GuiMenuButtonProfile"; + command = "OptionsMenuActivateOption(1)"; + tooltipProfile = "GuiToolTipProfile"; + class = "MenuInputButton"; + }; + new GuiIconButtonCtrl(OptionsMenuApplyBtn) { BitmapAsset = "UI:Keyboard_Black_Return_image"; sizeIconToButton = "1"; makeIconSquare = "1"; textLocation = "Center"; + text = "Apply"; + position = "990 0"; + extent = "140 40"; + horizSizing = "left"; + vertSizing = "center"; + profile = "GuiMenuButtonProfile"; + command = "OptionsMenu.applyChangedOptions();"; + tooltipProfile = "GuiToolTipProfile"; + class = "MenuInputButton"; + }; + new GuiIconButtonCtrl(OptionsMenuResetBtn) { + BitmapAsset = "UI:Keyboard_Black_R_image"; + sizeIconToButton = "1"; + makeIconSquare = "1"; + textLocation = "Center"; text = "Reset"; position = "1135 0"; extent = "140 40"; diff --git a/Templates/BaseGame/game/data/UI/guis/optionsMenu.tscript b/Templates/BaseGame/game/data/UI/guis/optionsMenu.tscript index ba6f1e9b4..81303f4ac 100644 --- a/Templates/BaseGame/game/data/UI/guis/optionsMenu.tscript +++ b/Templates/BaseGame/game/data/UI/guis/optionsMenu.tscript @@ -59,8 +59,11 @@ if(!isObject( OptionsMenuActionMap ) ) OptionsMenuActionMap.bind( keyboard, R, OptionsMenuReset ); OptionsMenuActionMap.bind( gamepad, btn_x, OptionsMenuReset ); - OptionsMenuActionMap.bind( keyboard, Enter, OptionsMenuActivateOption ); + OptionsMenuActionMap.bind( keyboard, Space, OptionsMenuActivateOption ); OptionsMenuActionMap.bind( gamepad, btn_a, OptionsMenuActivateOption ); + + OptionsMenuActionMap.bind( keyboard, Enter, tryApplyOptions); + OptionsMenuActionMap.bind( gamepad, btn_start, tryApplyOptions); } //============================================================================== @@ -237,6 +240,11 @@ function OptionsMenu::syncGui(%this) OptionsMenuPrevNavIcon.setBitmap(OptionsMenuActionMap.getCommandButtonBitmap(%device, "OptionsMenuPrevCategory")); OptionsMenuNextNavIcon.setBitmap(OptionsMenuActionMap.getCommandButtonBitmap(%device, "OptionsMenuNextCategory")); + + OptionsMenuApplyBtn.setBitmap(OptionsMenuActionMap.getCommandButtonBitmap(%device, "tryApplyOptions")); + + OptionsMenuRemapBtn.visible = KBMControlsList.visible || GamepadControlsList.visible; + OptionsMenuRemapBtn.setBitmap(OptionsMenuActionMap.getCommandButtonBitmap(%device, "OptionsMenuActivateOption")); } //============================================================================== @@ -292,6 +300,12 @@ function OptionMenuNavigatePrev(%val) $MenuList.listPosition = 0; $MenuList.syncGUI(); + + $BaseUI::scrollSchedule = schedule($BaseUI::scrollSpeedTimeMs, 0, "OptionMenuNavigatePrev", 1); + } + else + { + cancel($BaseUI::scrollSchedule); } } @@ -311,15 +325,23 @@ function OptionMenuNavigateNext(%val) $MenuList.listPosition = $MenuList.getCount()-1; $MenuList.syncGUI(); + + $BaseUI::scrollSchedule = schedule($BaseUI::scrollSpeedTimeMs, 0, "OptionMenuNavigateNext", 1); + } + else + { + cancel($BaseUI::scrollSchedule); } } function OptionMenuStickNavigate(%val) { - if(%val == -1) - BaseUINavigateNext(1); - else if(%val == 1) - mainMenuNavigateDown(1); + if(%val == 1) + OptionMenuNavigateNext(1); + else if(%val == -1) + OptionMenuNavigatePrev(1); + else + cancel($BaseUI::scrollSchedule); } function OptionMenuPrevSetting(%val) @@ -387,11 +409,9 @@ function OptionsMenuActivateOption(%val) if(!isObject(%option)) return; - echo(%option.class); - if(%option.class $= "OptionsKeybindEntry") { - eval(%option-->button.altCommand); + %option-->button.execAltCommand(); } } @@ -504,29 +524,29 @@ function OptionsMenu::populateAudioSettings(%this) function OptionsMenu::populateKBMControls(%this) { - //$remapListDevice = "keyboard"; %this.populateKeybinds("keyboard", KBMControlsList); %this.syncGui(); + + KBMControlsList.syncGui(); } function OptionsMenu::populateGamepadControls(%this) { - //$remapListDevice = ; %this.populateKeybinds("gamepad", GamepadControlsList); %this.syncGui(); + + GamepadControlsList.syncGui(); } function OptionsMenu::populateKeybinds(%this, %device, %controlsList) { - //%device = $remapListDevice; - %controlsList.clear(); //build out our list of action maps %actionMapCount = ActionMapGroup.getCount(); - + %actionMapList = ""; for(%i=0; %i < %actionMapCount; %i++) { @@ -567,32 +587,34 @@ function OptionsMenu::populateKeybinds(%this, %device, %controlsList) if($activeRemapControlSet $= "") $activeRemapControlSet = getField(%actionMapList, 0); - if(getFieldCount(%actionMapList) > 1) + for(%am = 0; %am < getFieldCount(%actionMapList); %am++) { - for(%am = 0; %am < getFieldCount(%actionMapList); %am++) + %currentActionMap = getField(%actionMapList, %am); + + //only add the group if we've got more than one group, otherwise it's obviously + //part of the single grouping + if(getFieldCount(%actionMapList) > 1) { - %currentActionMap = getField(%actionMapList, %am); - %actionMapGroupEntry = addOptionGroup(%currentActionMap); %controlsList.add(%actionMapGroupEntry); + } + + for ( %i = 0; %i < $RemapCount; %i++ ) + { + if(%device !$= "" && %device !$= $RemapDevice[%i]) + continue; + + %actionMapName = $RemapActionMap[%i].humanReadableName $= "" ? $RemapActionMap[%i].getName() : $RemapActionMap[%i].humanReadableName; + + if(%currentActionMap !$= %actionMapName) + continue; + + %keyMap = buildFullMapString( %i, $RemapActionMap[%i], %device ); + + %description = $RemapDescription[%i]; - for ( %i = 0; %i < $RemapCount; %i++ ) - { - if(%device !$= "" && %device !$= $RemapDevice[%i]) - continue; - - %actionMapName = $RemapActionMap[%i].humanReadableName $= "" ? $RemapActionMap[%i].getName() : $RemapActionMap[%i].humanReadableName; - - if(%currentActionMap !$= %actionMapName) - continue; - - %keyMap = buildFullMapString( %i, $RemapActionMap[%i], %device ); - - %description = $RemapDescription[%i]; - - %remapEntry = addActionMapEntry(%actionMapName, %device, %keyMap, %i, %description); - %controlsList.add(%remapEntry); - } + %remapEntry = addActionMapEntry(%actionMapName, %device, %keyMap, %i, %description); + %controlsList.add(%remapEntry); } } @@ -627,6 +649,20 @@ function tryCloseOptionsMenu(%val) } } +function tryApplyOptions(%val) +{ + if(!%val) + return; + + $optionsChangeRequiresRestart = false; + + %unappliedVideoChanges = VideoSettingsList.checkForUnappliedChanges(); + %unappliedAudioChanges = AudioSettingsList.checkForUnappliedChanges(); + + if(%unappliedVideoChanges || %unappliedAudioChanges) + OptionsMenu.applyChangedOptions(); +} + function OptionsMenu::applyChangedOptions(%this) { VideoSettingsList.applyChanges(); @@ -650,14 +686,13 @@ function OptionsMenu::applyChangedOptions(%this) function doKeyRemap( %optionEntry ) { - //%rowIndex = %row.remapIndex; - //%name = $RemapName[%rowIndex]; - %name = getField(%optionEntry.keymap,0); RemapDlg-->OptRemapText.text = "Re-bind \"" @ %name @ "\" to..." ; OptRemapInputCtrl.index = %optionEntry.remapIndex; + $remapListDevice = %optionEntry.device; + Canvas.pushDialog( RemapDlg ); } diff --git a/Templates/BaseGame/game/data/UI/guis/remapDlg.gui b/Templates/BaseGame/game/data/UI/guis/remapDlg.gui index ccc678df6..756eb7de5 100644 --- a/Templates/BaseGame/game/data/UI/guis/remapDlg.gui +++ b/Templates/BaseGame/game/data/UI/guis/remapDlg.gui @@ -24,6 +24,7 @@ $guiContent = new GuiControl(RemapDlg) { vertSizing = "height"; profile = "GuiInputCtrlProfile"; tooltipProfile = "GuiToolTipProfile"; + sendAxisEvents = "1"; }; new GuiControl(RemapBoxCtrl) { position = "-1 1"; diff --git a/Templates/BaseGame/game/data/UI/guis/remapDlg.tscript b/Templates/BaseGame/game/data/UI/guis/remapDlg.tscript index 107251735..7e4b55906 100644 --- a/Templates/BaseGame/game/data/UI/guis/remapDlg.tscript +++ b/Templates/BaseGame/game/data/UI/guis/remapDlg.tscript @@ -1,12 +1,36 @@ +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 ) { - Canvas.popDialog( RemapDlg ); - - if ( %device $= "keyboard" && %action $= "escape" ) - return; - else if( %device $= "gamepad" && %action $= "btn_start" ) + if(!startsWith(%device,$remapListDevice) && %action !$= "escape" && %action !$= "btn_start") + { + return; + } + else + { + Canvas.popDialog( RemapDlg ); + + if(%action $= "escape" || %action $= "btn_start") return; + + %this.doRemap(%device, %action, 0); + } +} +function OptRemapInputCtrl::doRemap(%this, %device, %action, %axisVal) +{ %cmd = $RemapCmd[%this.index]; %name = $RemapName[%this.index]; %actionMap = $RemapActionMap[%this.index]; @@ -21,32 +45,24 @@ function OptRemapInputCtrl::onInputEvent( %this, %device, %action ) %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 ); + 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 ( %prevMap $= "" ) + // 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 ) { //unbindExtraActions( %cmd, %actionMap, 1 ); %actionMap.bind( %device, %action, %cmd ); - OptionsMenu.syncGui(); + OptionsMenu.populateKBMControls(); + OptionsMenu.populateGamepadControls(); 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 ); @@ -73,5 +89,24 @@ function OptRemapInputCtrl::onInputEvent( %this, %device, %action ) %cmd @ "\", " @ %prevMapIndex @ ", " @ %this.index @ ");"; %cancelCommand = ""; - MessageBoxYesNo( "Key already in use", %remapWarnText, %doRemapCommand, %cancelCommand ); -} \ No newline at end of file + MessageBoxYesNo( "Key already in use", %remapWarnText, %doRemapCommand, %cancelCommand ); +} + +/// This unbinds actions 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(%device !$= "" || %device $= %amDevice) + %actionMap.unbind( %device, %action ); + } +} diff --git a/Templates/BaseGame/game/data/UI/scripts/controlsMenu.tscript b/Templates/BaseGame/game/data/UI/scripts/controlsMenu.tscript index ef2c85df0..dcf198969 100644 --- a/Templates/BaseGame/game/data/UI/scripts/controlsMenu.tscript +++ b/Templates/BaseGame/game/data/UI/scripts/controlsMenu.tscript @@ -225,23 +225,6 @@ function findRemapCmdIndex( %command ) 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 ) {