mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-02-22 08:03:45 +00:00
Most of the keybind/remap stuff finished
Fixed up most of the options apply logic
This commit is contained in:
parent
55697cffdb
commit
70e121595f
6 changed files with 217 additions and 147 deletions
|
|
@ -57,6 +57,7 @@ function UI::initClient(%this)
|
|||
%this.queueExec("./guis/GameMenu");
|
||||
%this.queueExec("./guis/GameMenu.gui");
|
||||
|
||||
%this.queueExec("./guis/remapDlg");
|
||||
%this.queueExec("./guis/remapDlg.gui");
|
||||
%this.queueExec("./guis/remapConfirmDlg.gui");
|
||||
|
||||
|
|
|
|||
|
|
@ -188,7 +188,7 @@ $guiContent = new GuiControl(OptionsMenu) {
|
|||
extent = "140 40";
|
||||
vertSizing = "center";
|
||||
profile = "GuiMenuButtonProfile";
|
||||
command = "Canvas.popDialog();";
|
||||
command = "tryCloseOptionsMenu();";
|
||||
tooltipProfile = "GuiToolTipProfile";
|
||||
class = "MenuInputButton";
|
||||
};
|
||||
|
|
|
|||
|
|
@ -92,6 +92,9 @@ if(!isObject( OptionsMenuActionMap ) )
|
|||
{
|
||||
new ActionMap(OptionsMenuActionMap){};
|
||||
|
||||
OptionsMenuActionMap.bind( keyboard, Escape, tryCloseOptionsMenu);
|
||||
OptionsMenuActionMap.bind( gamepad, btn_b, tryCloseOptionsMenu);
|
||||
|
||||
OptionsMenuActionMap.bind( keyboard, w, OptionMenuNavigatePrev );
|
||||
OptionsMenuActionMap.bind( keyboard, s, OptionMenuNavigateNext );
|
||||
OptionsMenuActionMap.bind( gamepad, yaxis, "D", "-0.23 0.23", OptionMenuStickNavigate );
|
||||
|
|
@ -331,7 +334,7 @@ function OptionMenuPrevSetting(%val)
|
|||
if(!isObject(%option))
|
||||
return;
|
||||
|
||||
if(%option.class !$= "OptionsListEntry")
|
||||
if(%option.class $= "OptionsListEntry")
|
||||
{
|
||||
%optionObject = %option.optionsObject;
|
||||
%currentOptionLevel = %optionObject.getObject(%option.currentOptionIndex);
|
||||
|
|
@ -356,7 +359,7 @@ function OptionMenuNextSetting(%val)
|
|||
if(!isObject(%option) )
|
||||
return;
|
||||
|
||||
if(%option.class !$= "OptionsListEntry")
|
||||
if(%option.class $= "OptionsListEntry")
|
||||
{
|
||||
%optionObject = %option.optionsObject;
|
||||
%currentOptionLevel = %optionObject.getObject(%option.currentOptionIndex);
|
||||
|
|
@ -562,7 +565,7 @@ function OptionsMenu::populateKeybinds(%this, %device, %controlsList)
|
|||
|
||||
%description = $RemapDescription[%i];
|
||||
|
||||
%remapEntry = addActionMapEntry(%actionMapName, %device, %keyMap, %description);
|
||||
%remapEntry = addActionMapEntry(%actionMapName, %device, %keyMap, %i, %description);
|
||||
%controlsList.add(%remapEntry);
|
||||
}
|
||||
}
|
||||
|
|
@ -575,45 +578,128 @@ function OptionsMenu::populateKeybinds(%this, %device, %controlsList)
|
|||
%entry.resize(0, 0, %controlsList.extent.x - 15, %entry.extent.y); //-10 for the scroll wheel pad
|
||||
}
|
||||
}
|
||||
//
|
||||
// old
|
||||
//
|
||||
//We capitalize on the canClose test here, because we want to prompt for unapplied options changes before
|
||||
//backing out. So when the UINavigation test canClose, we can see if we have unapplied settings and prompt
|
||||
//that via the message box and return false.
|
||||
//This gives the user a chance to choose how they wish to proceed before we allow the
|
||||
//UINavigation to move away from the options menu
|
||||
function OptionsMenu::canClose(%this)
|
||||
|
||||
function tryCloseOptionsMenu(%val)
|
||||
{
|
||||
//Another special case is us catching the 'back/pop' action by just shifting from one
|
||||
//menu list to another. In this case, we check if we were on the settings list as our active MenuList
|
||||
//if so, then the back/pop just moves us to the Category list as our active and we inform the
|
||||
//UINavigation to not close the page
|
||||
if(OptionsMenuSettingsList.isActiveMenuList())
|
||||
if(!%val)
|
||||
return;
|
||||
|
||||
//scan through all our options and see if any are any unapplied changes. If
|
||||
//so we need to prompt to apply or discard them
|
||||
%unappliedChanges = false;
|
||||
|
||||
foreach(%option in VideoSettingsList)
|
||||
{
|
||||
OptionsMenuCategoryList.setAsActiveMenuList();
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Here, we're on the category list as our active, so we're actually trying to leae the page
|
||||
//If we have unapplied changes, we want to prompt about them before closing the page and navigating away
|
||||
//If we don't, then we can process the popPage as normal and let the OptionsMenu close
|
||||
if(%this.unappliedChanges.count() != 0)
|
||||
if(%option.class $= "OptionsListEntry")
|
||||
{
|
||||
MessageBoxOKCancel("Discard Changes?", "You have unapplied changes to your settings, do you wish to apply or discard them?",
|
||||
"OptionsMenu.apply(); MainMenuGUI.popPage();", "" @ %this @ ".unappliedChanges.empty(); " @ %this @ ".navigation.popPage();",
|
||||
"Apply", "Discard");
|
||||
return false;
|
||||
if(%option.currentOptionIndex >= 0 && %option.currentOptionIndex < %option.optionsObject.getCount())
|
||||
{
|
||||
%targetOptionLevel = %option.optionsObject.getObject(%option.currentOptionIndex);
|
||||
|
||||
echo("tryCloseOptionsMenu() - testing option: " @ %option.optionsObject.optionName @ " target level of: " @ %targetOptionLevel.displayName);
|
||||
|
||||
if(!%targetOptionLevel.isCurrent())
|
||||
{
|
||||
%unappliedChanges = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
//check if we already have unapplied changes, so we can skip further iterating
|
||||
if(!%unappliedChanges)
|
||||
{
|
||||
foreach(%option in AudioSettingsList)
|
||||
{
|
||||
if(%option.class $= "OptionsListEntry")
|
||||
{
|
||||
if(%option.currentOptionIndex >= 0 && %option.currentOptionIndex < %option.optionsObject.getCount())
|
||||
{
|
||||
%targetOptionLevel = %option.optionsObject.getObject(%option.currentOptionIndex);
|
||||
|
||||
echo("tryCloseOptionsMenu() - testing option: " @ %option.optionsObject.optionName @ " target level of: " @ %targetOptionLevel.displayName);
|
||||
|
||||
if(!%targetOptionLevel.isCurrent())
|
||||
{
|
||||
%unappliedChanges = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(%unappliedChanges)
|
||||
{
|
||||
MessageBoxOKCancel("Discard Changes?", "You have unapplied changes to your settings, do you wish to apply or discard them?",
|
||||
"OptionsMenu.applyChangedOptions();", "Canvas.popDialog(OptionsMenu);",
|
||||
"Apply", "Discard");
|
||||
}
|
||||
else
|
||||
{
|
||||
Canvas.popDialog(OptionsMenu);
|
||||
}
|
||||
}
|
||||
|
||||
function OptionsMenu::onClose(%this)
|
||||
function OptionsMenu::applyChangedOptions(%this)
|
||||
{
|
||||
foreach(%option in VideoSettingsList)
|
||||
{
|
||||
if(%option.class $= "OptionsListEntry")
|
||||
{
|
||||
//If it's custom or nonsensical index, there's some kind of external factor going on, so we're
|
||||
//just going to skip applying it because we don't know what we'd be applying
|
||||
if(%option.currentOptionIndex >= 0 && %option.currentOptionIndex < %option.optionsObject.getCount())
|
||||
{
|
||||
%targetOptionLevel = %option.optionsObject.getObject(%option.currentOptionIndex);
|
||||
|
||||
if(!%targetOptionLevel.isCurrent())
|
||||
{
|
||||
echo("Applying setting of " @ %option.optionsObject.optionName);
|
||||
%targetOptionLevel.apply();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach(%option in AudioSettingsList)
|
||||
{
|
||||
if(%option.class $= "OptionsListEntry")
|
||||
{
|
||||
//If it's custom or nonsensical index, there's some kind of external factor going on, so we're
|
||||
//just going to skip applying it because we don't know what we'd be applying
|
||||
if(%option.currentOptionIndex >= 0 && %option.currentOptionIndex < %option.optionsObject.getCount())
|
||||
{
|
||||
%targetOptionLevel = %option.optionsObject.getObject(%option.currentOptionIndex);
|
||||
|
||||
if(!%targetOptionLevel.isCurrent())
|
||||
{
|
||||
echo("Applying setting of " @ %option.optionsObject.optionName);
|
||||
%targetOptionLevel.apply();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Finally, write our prefs to file
|
||||
%prefPath = getPrefpath();
|
||||
export("$pref::*", %prefPath @ "/clientPrefs." @ $TorqueScriptFileExtension, false);
|
||||
|
||||
Canvas.popDialog(OptionsMenu);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
Canvas.pushDialog( RemapDlg );
|
||||
}
|
||||
|
||||
function OptionsMenu::apply(%this)
|
||||
|
|
@ -1423,7 +1509,7 @@ function OptionsMenuActionMapButton::onHighlighted(%this, %highlighted)
|
|||
OptionsMenuSettingsScroll.scrollToObject(%container);
|
||||
}
|
||||
|
||||
function addActionMapEntry(%actionMap, %device, %keyMap, %description)
|
||||
function addActionMapEntry(%actionMap, %device, %keyMap, %index, %description)
|
||||
{
|
||||
%entry = new GuiContainer() {
|
||||
position = "0 0";
|
||||
|
|
@ -1437,6 +1523,7 @@ function addActionMapEntry(%actionMap, %device, %keyMap, %description)
|
|||
actionMap = %actionMap;
|
||||
device = %device;
|
||||
keymap = %keyMap;
|
||||
remapIndex = %index;
|
||||
|
||||
new GuiButtonCtrl() {
|
||||
profile = GuiMenuButtonProfile;
|
||||
|
|
@ -1446,6 +1533,7 @@ function addActionMapEntry(%actionMap, %device, %keyMap, %description)
|
|||
vertSizing = "height";
|
||||
internalName = "button";
|
||||
class = "OptionsMenuActionMapButton";
|
||||
altCommand = "doKeyRemap($thisControl.getParent());";
|
||||
};
|
||||
|
||||
new GuiTextCtrl() {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
//--- OBJECT WRITE BEGIN ---
|
||||
$guiContent = new GuiControl(RemapDlg) {
|
||||
extent = "1024 768";
|
||||
extent = "1280 720";
|
||||
minExtent = "8 8";
|
||||
profile = "GuiDefaultProfile";
|
||||
tooltipProfile = "GuiToolTipProfile";
|
||||
|
|
@ -9,7 +9,7 @@ $guiContent = new GuiControl(RemapDlg) {
|
|||
helpTag = "0";
|
||||
|
||||
new GuiContainer(RemapPanel) {
|
||||
position = "162 332";
|
||||
position = "290 308";
|
||||
extent = "700 104";
|
||||
horizSizing = "center";
|
||||
vertSizing = "center";
|
||||
|
|
@ -34,26 +34,28 @@ $guiContent = new GuiControl(RemapDlg) {
|
|||
tooltipProfile = "GuiToolTipProfile";
|
||||
isContainer = "1";
|
||||
|
||||
new GuiBitmapBarCtrl() {
|
||||
BitmapAsset = "UI:panel_image";
|
||||
extent = "701 40";
|
||||
new GuiBitmapCtrl() {
|
||||
BitmapAsset = "UI:backdrop_image";
|
||||
position = "1 1";
|
||||
extent = "701 100";
|
||||
horizSizing = "width";
|
||||
vertSizing = "height";
|
||||
profile = "GuiDefaultProfile";
|
||||
tooltipProfile = "GuiToolTipProfile";
|
||||
};
|
||||
new GuiBitmapBarCtrl() {
|
||||
BitmapAsset = "UI:panel_low_image";
|
||||
position = "0 40";
|
||||
extent = "701 341";
|
||||
new GuiPanel() {
|
||||
position = "38 12";
|
||||
extent = "625 80";
|
||||
horizSizing = "width";
|
||||
profile = "GuiDefaultProfile";
|
||||
vertSizing = "height";
|
||||
profile = "GuiMenuBasePanelProfile";
|
||||
tooltipProfile = "GuiToolTipProfile";
|
||||
};
|
||||
new GuiTextCtrl() {
|
||||
text = "Press escape to cancel";
|
||||
text = "Press escape or start to cancel";
|
||||
maxLength = "255";
|
||||
position = "260 67";
|
||||
extent = "181 23";
|
||||
position = "252 51";
|
||||
extent = "245 23";
|
||||
minExtent = "8 8";
|
||||
horizSizing = "width";
|
||||
vertSizing = "height";
|
||||
|
|
@ -61,9 +63,9 @@ $guiContent = new GuiControl(RemapDlg) {
|
|||
tooltipProfile = "GuiToolTipProfile";
|
||||
};
|
||||
new GuiTextCtrl() {
|
||||
text = "Re-bind \"Forward\" to...";
|
||||
text = "Re-bind \"\" to...";
|
||||
maxLength = "255";
|
||||
position = "259 40";
|
||||
position = "251 24";
|
||||
extent = "184 23";
|
||||
minExtent = "8 8";
|
||||
horizSizing = "center";
|
||||
|
|
|
|||
77
Templates/BaseGame/game/data/UI/guis/remapDlg.tscript
Normal file
77
Templates/BaseGame/game/data/UI/guis/remapDlg.tscript
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
function OptRemapInputCtrl::onInputEvent( %this, %device, %action )
|
||||
{
|
||||
Canvas.popDialog( RemapDlg );
|
||||
|
||||
if ( %device $= "keyboard" && %action $= "escape" )
|
||||
return;
|
||||
else if( %device $= "gamepad" && %action $= "btn_start" )
|
||||
return;
|
||||
|
||||
%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 );
|
||||
|
||||
//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 );
|
||||
|
||||
OptionsMenu.syncGui();
|
||||
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 );
|
||||
|
||||
// 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 @ ");";
|
||||
%cancelCommand = "";
|
||||
|
||||
MessageBoxYesNo( "Key already in use", %remapWarnText, %doRemapCommand, %cancelCommand );
|
||||
}
|
||||
|
|
@ -205,21 +205,6 @@ function controlSetChanged()
|
|||
fillRemapList();
|
||||
}
|
||||
|
||||
function doKeyRemap( %row )
|
||||
{
|
||||
%rowIndex = %row.remapIndex;
|
||||
%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];
|
||||
|
|
@ -230,89 +215,6 @@ function ControlsMenuRebindButton::onClick(%this)
|
|||
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++ )
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue