2023-12-17 05:18:33 +00:00
$optionsEntryPad = 10;
2022-04-04 01:00:30 +00:00
2023-12-17 09:27:30 +00:00
$OptionsMenuCategories[0] = "Video";
$OptionsMenuCategories[1] = "Audio";
2023-12-19 05:49:13 +00:00
$OptionsMenuCategories[2] = "KBM";
$OptionsMenuCategories[3] = "Controller";
2023-12-17 09:27:30 +00:00
2022-02-23 02:12:39 +00:00
function OptionsMenu::onAdd(%this)
{
if(!isObject(%this.optionsCategories))
{
%this.optionsCategories = new ArrayObject();
}
Adjusted handling for the bitmap and bitmapAsset fields for guiBitmapButtonCtrl to forcefully update the button states when changed, ensuring that the bitmaps refresh when changed via the field
Added callback for onResize to guiWindowCtrl so controls - such as the EditorTree - can be properly resized in certain circumstances when the window is changed
Added getIncrement() and getRange() to GuiGameSettingsCtrl to better facilitate options manipulation on the script side
Corrected some of the console method documentation strings in GuiGameSettingsCtrl
Removed some unneeded, extraneous files and their asset definitions that came from odd import conversions. Where applicable, created cleaned up versions to make naming conventions and references stable
Fixed canvas mode update text typo: FSAA -> FXAA
Added logic to DOF, Light Rays, SSAO and Vignette postFX's to check both the preset setting AND the user preference before enabling.
Shifted initialization order so PostFX's are loaded before we configure the canvas, to ensure stuff like the FXAAPostFX exists and can be toggled on on load
Fixed multiple issues with options menu:
When using gamepad, unable to navigate from categories to options. Fixed so can now traverse as normal
Input limitations on gamepad necessitated changing of how setting applying happens, is now done as a 'apply or discard' prompt when leaving the options menu
Added proper handling for adjusting settings with gamepad with left/right inputs
Fixed issue where the unapplied change for an option was sometimes being processed as an object name rather than an implicit string. Now made to be explicit strings to avoid issue.
Made the menu button input for "Select" to go from categories to options gamepad only, and hidden when in the options list
Fixed issue where changing window mode didn't correctly affect resolution option. Now set up so changing this field correctly refreshes the resolution option. Specifically, when on borderless, the resolution field does not show, preventing confusion as it is always full resolution
Generally have the options list refresh when changes happen to allow any and all fields to be able to dynamically respond to other options having changed improving flexibility.
Cleaned up old, unused, commented out functions
Added ability on OKCancel message boxes to override the button text if needed
Fixed issue with AssetBrowser where the shrink/grow icons next to the preview size slider were not anchored correctly.
Adjusted callback logic so if preview slider is clicked on, rather than dragged, it will correctly update the zoom values
Added sorting to Modules List dropdown for the AssetBrowser
Improved standardization of double-clicking in AssetBrowser. Now defaults to editing action if regularly browsing and selecting if in select mode. Still allows regular per-type overrides as normal
Moved definition of GuiDisabledTextEditProfile to gui profiles.ed.tscript file, removed duplicates to stop error spam
Adjusted default settings value for double-click action in AB to be edit to prevent unstable behavior
Removed old file refs from Load Recent list in the default settings
2022-03-27 03:36:37 +00:00
%this.currentCategory = "";
2022-03-27 08:05:48 +00:00
callOnModules("populateOptionsMenuCategories", "Game");
2022-02-23 02:12:39 +00:00
}
2023-12-07 01:50:51 +00:00
function OptionsMenu::onWake(%this)
{
2023-12-19 05:49:13 +00:00
%this.populateVideoSettings();
2023-12-07 01:50:51 +00:00
2023-12-19 05:49:13 +00:00
%this.populateAudioSettings();
2023-12-17 05:18:33 +00:00
2023-12-19 05:49:13 +00:00
%this.populateKBMControls();
%this.populateGamepadControls();
2023-12-17 09:27:30 +00:00
//establish the cached prefs values here
2023-12-17 05:18:33 +00:00
2023-12-17 09:27:30 +00:00
%this.openOptionsCategory("Video");
2023-12-17 05:18:33 +00:00
}
if(!isObject( OptionsMenuActionMap ) )
{
new ActionMap(OptionsMenuActionMap){};
2023-12-19 08:36:43 +00:00
OptionsMenuActionMap.bind( keyboard, Escape, tryCloseOptionsMenu);
OptionsMenuActionMap.bind( gamepad, btn_b, tryCloseOptionsMenu);
2023-12-17 05:18:33 +00:00
OptionsMenuActionMap.bind( keyboard, w, OptionMenuNavigatePrev );
OptionsMenuActionMap.bind( keyboard, s, OptionMenuNavigateNext );
OptionsMenuActionMap.bind( gamepad, yaxis, "D", "-0.23 0.23", OptionMenuStickNavigate );
OptionsMenuActionMap.bind( gamepad, upov, OptionMenuNavigatePrev );
OptionsMenuActionMap.bind( gamepad, dpov, OptionMenuNavigateNext );
OptionsMenuActionMap.bind( keyboard, a, OptionMenuPrevSetting );
OptionsMenuActionMap.bind( keyboard, d, OptionMenuNextSetting );
OptionsMenuActionMap.bind( gamepad, xaxis, "D", "-0.23 0.23", OptionMenuStickChangeSetting );
OptionsMenuActionMap.bind( gamepad, lpov, OptionMenuPrevSetting );
OptionsMenuActionMap.bind( gamepad, lpov, OptionMenuNextSetting );
2023-12-17 09:27:30 +00:00
OptionsMenuActionMap.bind( keyboard, q, OptionsMenuPrevCategory );
OptionsMenuActionMap.bind( gamepad, btn_l, OptionsMenuPrevCategory );
OptionsMenuActionMap.bind( keyboard, e, OptionsMenuNextCategory );
OptionsMenuActionMap.bind( gamepad, btn_r, OptionsMenuNextCategory );
OptionsMenuActionMap.bind( keyboard, R, OptionsMenuReset );
OptionsMenuActionMap.bind( gamepad, btn_x, OptionsMenuReset );
2023-12-19 22:37:23 +00:00
2023-12-31 18:46:48 +00:00
OptionsMenuActionMap.bind( keyboard, Space, OptionsMenuActivateOption );
2023-12-19 22:37:23 +00:00
OptionsMenuActionMap.bind( gamepad, btn_a, OptionsMenuActivateOption );
2023-12-31 18:46:48 +00:00
OptionsMenuActionMap.bind( keyboard, Enter, tryApplyOptions);
OptionsMenuActionMap.bind( gamepad, btn_start, tryApplyOptions);
2023-12-17 05:18:33 +00:00
}
2023-12-22 05:59:19 +00:00
//==============================================================================
// This function updates all the elements in the actual lists to ensure they're
// sized, stylized and formatted correctly, as well as up to date values
2023-12-19 05:49:13 +00:00
function OptionsMenuList::syncGui(%this)
2023-12-17 05:18:33 +00:00
{
%this.callOnChildren("setHighlighted", false);
%btn = %this.getObject(%this.listPosition);
2023-12-19 05:49:13 +00:00
if(%btn.class $= "OptionsListEntry" ||
%btn.class $= "OptionsListSliderEntry" ||
%btn.class $= "OptionsKeybindEntry")
2023-12-17 05:18:33 +00:00
%btn-->button.setHighlighted(true);
2023-12-19 05:49:13 +00:00
//iterate over the items and ensure that they are formatted well based on the settings selected
foreach(%option in %this)
{
%container = %option-->valuesContainer;
if(%option.class $= "OptionsListEntry")
{
%hasLevels = %option.optionsObject.getCount() <= 1;
%optionObject = %option.optionsObject;
//If it's out of range of the options, it's probably a custom value
if(%option.currentOptionIndex < %optionObject.getCount() && %option.currentOptionIndex >= 0)
{
%currentOptionLevel = %optionObject.getObject(%option.currentOptionIndex);
%currentOptionLevelTxt = %currentOptionLevel.displayName;
}
else
{
%currentOptionLevelTxt = "Custom";
}
%optionValTextWidth = %option-->optionValue.profile.getStringWidth(%currentOptionLevelTxt);
%option-->optionValue.resize(%container.extent.x - %container-->prevValButton.extent.x - %optionValTextWidth - 20, 0,
%optionValTextWidth + 20, %container.extent.y);
%option-->optionValue.text = %currentOptionLevelTxt;
%container-->prevValButton.position.x = %option-->optionValue.position.x - 20;
%container-->nextValButton.position.x = %container.extent.x - %container-->prevValButton.extent.x;
//if there's no alternatives, disable the left/right buttons
%container-->prevValButton.setHidden(%hasLevels);
%container-->nextValButton.setHidden(%hasLevels);
}
else if(%option.class $= "OptionsListSliderEntry")
{
}
else if(%option.class $= "OptionsKeybindEntry")
{
%bindImgAsset = getButtonBitmap(%option.device, getField(%option.keymap, 1));
if(%bindImgAsset $= "UI:Keyboard_Black_Blank_image")
%bindImgAsset = "";
%container-->bindButton.setBitmap(%bindImgAsset);
}
}
2023-12-17 09:27:30 +00:00
}
2023-12-19 22:37:23 +00:00
function OptionsMenuList::checkForUnappliedChanges(%this)
{
%unappliedChanges = false;
foreach(%option in %this)
{
if(%option.class $= "OptionsListEntry")
{
if(%option.currentOptionIndex >= 0 && %option.currentOptionIndex < %option.optionsObject.getCount())
{
%targetOptionLevel = %option.optionsObject.getObject(%option.currentOptionIndex);
if(!%targetOptionLevel.isCurrent())
%unappliedChanges = true;
if(%option.optionsObject.requiresRestart)
$optionsChangeRequiresRestart = true;
}
}
}
return %unappliedChanges;
}
function OptionsMenuList::applyChanges(%this)
{
foreach(%option in %this)
{
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())
%targetOptionLevel.apply();
}
}
}
}
2023-12-17 09:27:30 +00:00
function OptionsMenu::openOptionsCategory(%this, %categoryName)
{
VideoSettingsList.setVisible(%categoryName $= "Video");
AudioSettingsList.setVisible(%categoryName $= "Audio");
2023-12-19 05:49:13 +00:00
KBMControlsList.setVisible(%categoryName $= "KBM");
GamepadControlsList.setVisible(%categoryName $= "Controller");
2023-12-17 09:27:30 +00:00
if(%categoryName $= "Video")
{
$MenuList = VideoSettingsList;
//Find our first non-group entry
while($MenuList.getObject($MenuList.listPosition).class !$= OptionsListEntry && $MenuList.listPosition < $MenuList.getCount())
{
$MenuList.listPosition += 1;
}
%this.currentCatgeoryIdx = 0;
}
else if(%categoryName $= "Audio")
{
$MenuList = AudioSettingsList;
%this.currentCatgeoryIdx = 1;
}
2023-12-19 05:49:13 +00:00
else if(%categoryName $= "KBM")
2023-12-17 09:27:30 +00:00
{
2023-12-19 05:49:13 +00:00
$MenuList = KBMControlsList;
2023-12-17 09:27:30 +00:00
%this.currentCatgeoryIdx = 2;
}
2023-12-19 05:49:13 +00:00
else if(%categoryName $= "Controller")
{
$MenuList = GamepadControlsList;
%this.currentCatgeoryIdx = 3;
}
2023-12-17 09:27:30 +00:00
$MenuList.syncGui();
%this.syncGui();
}
2023-12-22 05:59:19 +00:00
//==============================================================================
// This function updates the non-list items of the menu to be up to date and stylistically
// complaint. This ensures keybind hint buttons are presented correctly based on the current input
// device
2023-12-17 09:27:30 +00:00
function OptionsMenu::syncGui(%this)
{
OptionsMenuCategoryList.callOnChildren("setHighlighted", false);
%btn = OptionsMenuCategoryList.getObject(%this.currentCatgeoryIdx);
%btn.setHighlighted(true);
%buttonPosX = %btn.position.x + OptionsMenuCategoryList.position.x;
OptionsMenuPrevNavIcon.position.x = %buttonPosX - 5;
OptionsMenuNextNavIcon.position.x = %buttonPosX + %btn.extent.x - 35;
//Update the button imagery to comply to the last input device we'd used
%device = Canvas.getLastInputDevice();
if(%device $= "mouse")
%device = "keyboard";
OptionsMenuBackBtn.setBitmap(BaseUIActionMap.getCommandButtonBitmap(%device, "BaseUIBackOut"));
OptionsMenuResetBtn.setBitmap(OptionsMenuActionMap.getCommandButtonBitmap(%device, "OptionsMenuReset"));
OptionsMenuPrevNavIcon.setBitmap(OptionsMenuActionMap.getCommandButtonBitmap(%device, "OptionsMenuPrevCategory"));
OptionsMenuNextNavIcon.setBitmap(OptionsMenuActionMap.getCommandButtonBitmap(%device, "OptionsMenuNextCategory"));
2023-12-31 18:46:48 +00:00
OptionsMenuApplyBtn.setBitmap(OptionsMenuActionMap.getCommandButtonBitmap(%device, "tryApplyOptions"));
OptionsMenuRemapBtn.visible = KBMControlsList.visible || GamepadControlsList.visible;
OptionsMenuRemapBtn.setBitmap(OptionsMenuActionMap.getCommandButtonBitmap(%device, "OptionsMenuActivateOption"));
2023-12-17 09:27:30 +00:00
}
2023-12-22 05:59:19 +00:00
//==============================================================================
// Menu navigation functions
// Primarily used by keybinds
2023-12-17 09:27:30 +00:00
function OptionsMenuPrevCategory(%val)
{
if(%val)
{
%currentIdx = OptionsMenu.currentMenuIdx;
OptionsMenu.currentMenuIdx -= 1;
OptionsMenu.currentMenuIdx = mClamp(OptionsMenu.currentMenuIdx, 0, 3);
if(%currentIdx == OptionsMenu.currentMenuIdx)
return;
%newCategory = $OptionsMenuCategories[OptionsMenu.currentMenuIdx];
OptionsMenu.openOptionsCategory(%newCategory);
}
}
function OptionsMenuNextCategory(%val)
{
if(%val)
{
%currentIdx = OptionsMenu.currentMenuIdx;
OptionsMenu.currentMenuIdx += 1;
OptionsMenu.currentMenuIdx = mClamp(OptionsMenu.currentMenuIdx, 0, 3);
if(%currentIdx == OptionsMenu.currentMenuIdx)
return;
%newCategory = $OptionsMenuCategories[OptionsMenu.currentMenuIdx];
OptionsMenu.openOptionsCategory(%newCategory);
}
}
2023-12-17 05:18:33 +00:00
function OptionMenuNavigatePrev(%val)
{
if(%val)
{
$MenuList.listPosition -= 1;
2023-12-19 05:49:13 +00:00
while( $MenuList.listPosition >= 0 && ($MenuList.getObject($MenuList.listPosition).class !$= "OptionsListEntry" &&
$MenuList.getObject($MenuList.listPosition).class !$= "OptionsListSliderEntry" &&
$MenuList.getObject($MenuList.listPosition).class !$= "OptionsKeybindEntry"))
2023-12-17 05:18:33 +00:00
{
$MenuList.listPosition -= 1;
}
2023-12-07 01:50:51 +00:00
2023-12-17 05:18:33 +00:00
if($MenuList.listPosition < 0)
$MenuList.listPosition = 0;
$MenuList.syncGUI();
2023-12-31 18:46:48 +00:00
$BaseUI::scrollSchedule = schedule($BaseUI::scrollSpeedTimeMs, 0, "OptionMenuNavigatePrev", 1);
}
else
{
cancel($BaseUI::scrollSchedule);
2023-12-17 05:18:33 +00:00
}
}
function OptionMenuNavigateNext(%val)
{
if(%val)
{
$MenuList.listPosition += 1;
2023-12-19 05:49:13 +00:00
while($MenuList.listPosition < $MenuList.getCount() && ($MenuList.getObject($MenuList.listPosition).class !$= "OptionsListEntry" &&
$MenuList.getObject($MenuList.listPosition).class !$= "OptionsListSliderEntry" &&
$MenuList.getObject($MenuList.listPosition).class !$= "OptionsKeybindEntry"))
2023-12-17 05:18:33 +00:00
{
$MenuList.listPosition += 1;
2023-12-07 01:50:51 +00:00
}
2023-12-17 05:18:33 +00:00
if($MenuList.listPosition >= $MenuList.getCount())
$MenuList.listPosition = $MenuList.getCount()-1;
$MenuList.syncGUI();
2023-12-31 18:46:48 +00:00
$BaseUI::scrollSchedule = schedule($BaseUI::scrollSpeedTimeMs, 0, "OptionMenuNavigateNext", 1);
}
else
{
cancel($BaseUI::scrollSchedule);
2023-12-07 01:50:51 +00:00
}
}
2023-12-17 05:18:33 +00:00
function OptionMenuStickNavigate(%val)
{
2023-12-31 18:46:48 +00:00
if(%val == 1)
OptionMenuNavigateNext(1);
else if(%val == -1)
OptionMenuNavigatePrev(1);
else
cancel($BaseUI::scrollSchedule);
2023-12-17 05:18:33 +00:00
}
function OptionMenuPrevSetting(%val)
{
2023-12-19 05:49:13 +00:00
if(!%val)
return;
2023-12-17 05:18:33 +00:00
%option = $MenuList.getObject($MenuList.listPosition);
2023-12-19 05:49:13 +00:00
if(!isObject(%option))
return;
2023-12-19 08:36:43 +00:00
if(%option.class $= "OptionsListEntry")
2023-12-19 05:49:13 +00:00
{
%optionObject = %option.optionsObject;
%currentOptionLevel = %optionObject.getObject(%option.currentOptionIndex);
%option.currentOptionIndex = mClamp(%option.currentOptionIndex-1, 0, %optionObject.getCount()-1);
%newOptionLevel = %optionObject.getObject(%option.currentOptionIndex);
2023-12-19 22:37:23 +00:00
//echo("Changed option: " @ %optionObject.optionName @ " from level: " @ %currentOptionLevel.displayName @ " to level: " @ %newOptionLevel.displayName);
2023-12-19 05:49:13 +00:00
}
2023-12-17 05:18:33 +00:00
$MenuList.syncGUI();
}
function OptionMenuNextSetting(%val)
{
2023-12-19 05:49:13 +00:00
if(!%val)
return;
2023-12-17 05:18:33 +00:00
%option = $MenuList.getObject($MenuList.listPosition);
2023-12-19 05:49:13 +00:00
if(!isObject(%option) )
return;
2023-12-19 08:36:43 +00:00
if(%option.class $= "OptionsListEntry")
2023-12-19 05:49:13 +00:00
{
%optionObject = %option.optionsObject;
%currentOptionLevel = %optionObject.getObject(%option.currentOptionIndex);
%option.currentOptionIndex = mClamp(%option.currentOptionIndex+1, 0, %optionObject.getCount()-1);
%newOptionLevel = %optionObject.getObject(%option.currentOptionIndex);
2023-12-19 22:37:23 +00:00
//echo("Changed option: " @ %optionObject.optionName @ " from level: " @ %currentOptionLevel.displayName @ " to level: " @ %newOptionLevel.displayName);
2023-12-19 05:49:13 +00:00
}
2023-12-17 05:18:33 +00:00
$MenuList.syncGUI();
}
function OptionMenuStickChangeSetting(%val)
{
}
2023-12-17 09:27:30 +00:00
2023-12-19 22:37:23 +00:00
function OptionsMenuActivateOption(%val)
{
if(!%val)
return;
%option = $MenuList.getObject($MenuList.listPosition);
if(!isObject(%option))
return;
if(%option.class $= "OptionsKeybindEntry")
{
2023-12-31 18:46:48 +00:00
%option-->button.execAltCommand();
2023-12-19 22:37:23 +00:00
}
}
2023-12-22 05:59:19 +00:00
//==============================================================================
// This function utilizes the VideoSettingsGroup SimGroup to populate options.
// The object is defined in core/rendering/scripts/graphicsOptions.tscript
// A majority of the options are statically defined, but some are dynamically populated
// on refresh, like the display device or available resolution options.
// Once populated, we loop over the simgroup structure to populate our option entry
// rows in the options menu itself.
2023-12-19 05:49:13 +00:00
function OptionsMenu::populateVideoSettings(%this)
{
VideoSettingsList.clear();
VideoSettingsGroup::populateDisplaySettings();
for(%i=0; %i < VideoSettingsGroup.getCount(); %i++)
{
%setting = VideoSettingsGroup.getObject(%i);
if(%setting.class $= "SubOptionsGroup")
{
%entry = addOptionGroup(%setting.displayName);
if(isObject(%entry))
VideoSettingsList.add(%entry);
for(%s=0; %s < %setting.getCount(); %s++)
{
%option = %setting.getObject(%s);
%optionsEntry = addOptionEntry(%option);
if(isObject(%optionsEntry))
VideoSettingsList.add(%optionsEntry);
}
}
else if(%setting.class $= "OptionsSettings")
{
%optionsEntry = addOptionEntry(%setting);
if(isObject(%optionsEntry))
VideoSettingsList.add(%optionsEntry);
}
}
//Ensure our newly templated options listings are sized right
for(%i=0; %i < VideoSettingsList.getCount(); %i++)
{
%entry = VideoSettingsList.getObject(%i);
%entry.resize(0, 0, VideoSettingsList.extent.x - 15, %entry.extent.y); //-10 for the scroll wheel pad
}
}
2023-12-22 05:59:19 +00:00
//==============================================================================
// This function utilizes the AudioSettingsGroup SimGroup to populate options.
// The object is defined in core/sfx/scripts/audioOptions.tscript
// Similar to the video options, it can be a mix of static and dynamically populated
// option entries, which we then iterate over and populate the entry rows for the menu
2023-12-19 05:49:13 +00:00
function OptionsMenu::populateAudioSettings(%this)
{
AudioSettingsList.clear();
AudioSettingsGroup.populateSettings();
//Process the lists
for(%i=0; %i < AudioSettingsGroup.getCount(); %i++)
{
%setting = AudioSettingsGroup.getObject(%i);
if(%setting.class $= "SubOptionsGroup")
{
%entry = addOptionGroup(%setting.displayName);
if(isObject(%entry))
AudioSettingsList.add(%entry);
for(%s=0; %s < %setting.getCount(); %s++)
{
%option = %setting.getObject(%s);
%optionsEntry = addOptionEntry(%option);
if(isObject(%optionsEntry))
AudioSettingsList.add(%optionsEntry);
}
}
else if(%setting.class $= "AudioOptionsSettings")
{
%optionsEntry = addOptionEntry(%setting);
if(isObject(%optionsEntry))
AudioSettingsList.add(%optionsEntry);
}
}
AudioSettingsList.add(addOptionGroup("Channel Volume"));
AudioSettingsList.add(addOptionSlider("Master Volume", "", "$pref::SFX::masterVolume", 0, 1, 0.1));
AudioSettingsList.add(addOptionSlider("GUI Volume", "", "$pref::SFX::channelVolume[" @ $GuiAudioType @ "]", 0, 1, 0.1));
AudioSettingsList.add(addOptionSlider("Effects Volume", "", "$pref::SFX::channelVolume[" @ $SimAudioType @ "]", 0, 1, 0.1));
AudioSettingsList.add(addOptionSlider("Music Volume", "", "$pref::SFX::channelVolume[" @ $MusicAudioType @ "]", 0, 1, 0.1));
//Ensure our newly templated options listings are sized right
for(%i=0; %i < AudioSettingsList.getCount(); %i++)
{
%entry = AudioSettingsList.getObject(%i);
%entry.resize(0, 0, AudioSettingsList.extent.x - 15, %entry.extent.y); //-10 for the scroll wheel pad
}
}
function OptionsMenu::populateKBMControls(%this)
{
%this.populateKeybinds("keyboard", KBMControlsList);
%this.syncGui();
2023-12-31 18:46:48 +00:00
KBMControlsList.syncGui();
2023-12-19 05:49:13 +00:00
}
function OptionsMenu::populateGamepadControls(%this)
{
%this.populateKeybinds("gamepad", GamepadControlsList);
%this.syncGui();
2023-12-31 18:46:48 +00:00
GamepadControlsList.syncGui();
2023-12-19 05:49:13 +00:00
}
function OptionsMenu::populateKeybinds(%this, %device, %controlsList)
{
%controlsList.clear();
//build out our list of action maps
%actionMapCount = ActionMapGroup.getCount();
2023-12-31 18:46:48 +00:00
2023-12-19 05:49:13 +00:00
%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);
2023-12-31 18:46:48 +00:00
for(%am = 0; %am < getFieldCount(%actionMapList); %am++)
2023-12-19 05:49:13 +00:00
{
2023-12-31 18:46:48 +00:00
%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)
2023-12-19 05:49:13 +00:00
{
%actionMapGroupEntry = addOptionGroup(%currentActionMap);
%controlsList.add(%actionMapGroupEntry);
2023-12-31 18:46:48 +00:00
}
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];
2023-12-19 05:49:13 +00:00
2023-12-31 18:46:48 +00:00
%remapEntry = addActionMapEntry(%actionMapName, %device, %keyMap, %i, %description);
%controlsList.add(%remapEntry);
2023-12-19 05:49:13 +00:00
}
}
//Ensure our newly templated options listings are sized right
for(%i=0; %i < %controlsList.getCount(); %i++)
{
%entry = %controlsList.getObject(%i);
%entry.resize(0, 0, %controlsList.extent.x - 15, %entry.extent.y); //-10 for the scroll wheel pad
}
}
2023-12-19 08:36:43 +00:00
2023-12-22 05:59:19 +00:00
//==============================================================================
2023-12-19 08:36:43 +00:00
function tryCloseOptionsMenu(%val)
2022-05-07 04:39:16 +00:00
{
2023-12-19 08:36:43 +00:00
if(!%val)
return;
2023-12-19 22:37:23 +00:00
$optionsChangeRequiresRestart = false;
2023-12-19 08:36:43 +00:00
2023-12-19 22:37:23 +00:00
%unappliedVideoChanges = VideoSettingsList.checkForUnappliedChanges();
%unappliedAudioChanges = AudioSettingsList.checkForUnappliedChanges();
2023-12-19 08:36:43 +00:00
2023-12-19 22:37:23 +00:00
if(%unappliedVideoChanges || %unappliedAudioChanges)
2023-12-19 08:36:43 +00:00
{
MessageBoxOKCancel("Discard Changes?", "You have unapplied changes to your settings, do you wish to apply or discard them?",
"OptionsMenu.applyChangedOptions();", "Canvas.popDialog(OptionsMenu);",
2022-05-07 04:39:16 +00:00
"Apply", "Discard");
2023-12-19 08:36:43 +00:00
}
else
{
2023-12-27 07:36:58 +00:00
BaseUIBackOut(1);
2023-12-19 08:36:43 +00:00
}
2023-12-19 22:37:23 +00:00
}
2023-12-19 08:36:43 +00:00
2023-12-31 18:46:48 +00:00
function tryApplyOptions(%val)
{
if(!%val)
return;
$optionsChangeRequiresRestart = false;
%unappliedVideoChanges = VideoSettingsList.checkForUnappliedChanges();
%unappliedAudioChanges = AudioSettingsList.checkForUnappliedChanges();
if(%unappliedVideoChanges || %unappliedAudioChanges)
OptionsMenu.applyChangedOptions();
}
2023-12-19 08:36:43 +00:00
function OptionsMenu::applyChangedOptions(%this)
{
2023-12-19 22:37:23 +00:00
VideoSettingsList.applyChanges();
AudioSettingsList.applyChanges();
2020-07-23 05:22:15 +00:00
2023-12-19 22:37:23 +00:00
//$pref::SFX::masterVolume = OptionsMenuSettingsList.getValue(2);
sfxSetMasterVolume( $pref::SFX::masterVolume );
sfxSetChannelVolume( $GuiAudioType, $pref::SFX::channelVolume[ $GuiAudioType ] );
sfxSetChannelVolume( $SimAudioType, $pref::SFX::channelVolume[ $SimAudioType ] );
sfxSetChannelVolume( $MusicAudioType, $pref::SFX::channelVolume[ $MusicAudioType ] );
2023-12-19 08:36:43 +00:00
//Finally, write our prefs to file
%prefPath = getPrefpath();
export("$pref::*", %prefPath @ "/clientPrefs." @ $TorqueScriptFileExtension, false);
2023-12-27 07:36:58 +00:00
BaseUIBackOut(1);
2023-12-19 22:37:23 +00:00
if($optionsChangeRequiresRestart)
MessageBoxOK("Restart Required", "Some of your changes require the game to be restarted.");
2022-05-07 04:39:16 +00:00
}
2023-12-19 08:36:43 +00:00
function doKeyRemap( %optionEntry )
2022-05-07 04:39:16 +00:00
{
2023-12-19 08:36:43 +00:00
%name = getField(%optionEntry.keymap,0);
RemapDlg-->OptRemapText.text = "Re-bind \"" @ %name @ "\" to..." ;
OptRemapInputCtrl.index = %optionEntry.remapIndex;
2023-12-31 18:46:48 +00:00
$remapListDevice = %optionEntry.device;
2023-12-19 08:36:43 +00:00
Canvas.pushDialog( RemapDlg );
2020-05-20 22:19:52 +00:00
}
2023-12-19 22:37:23 +00:00
function OptionsMenu::resetSettings(%this)
2020-05-20 22:19:52 +00:00
{
2022-02-23 02:12:39 +00:00
MessageBoxOKCancel("", "This will set the graphical settings back to the auto-detected defaults. Do you wish to continue?", "AutodetectGraphics();", "");
2020-05-20 22:19:52 +00:00
}
2023-12-22 05:59:19 +00:00
//==============================================================================
// Option types
2023-12-19 05:49:13 +00:00
function addOptionGroup(%displayName)
2023-12-07 01:50:51 +00:00
{
%group = new GuiTextCtrl() {
2023-12-19 05:49:13 +00:00
text = %displayName;
2023-12-07 01:50:51 +00:00
position = "0 0";
2023-12-19 05:49:13 +00:00
extent = "500 45";
2023-12-07 01:50:51 +00:00
profile = "MenuHeaderText";
tooltipProfile = "GuiToolTipProfile";
};
return %group;
2023-12-17 05:18:33 +00:00
}
function optionsMenuButton::onHighlighted(%this, %highlighted)
{
%container = %this.getParent();
2023-12-07 01:50:51 +00:00
2023-12-17 05:18:33 +00:00
%container-->optionName.profile = %highlighted ? MenuSubHeaderTextHighlighted : MenuSubHeaderText;
%container-->optionDescription.profile = %highlighted ? GuiMLTextProfileHighlighted : GuiMLTextProfile;
%valuesContainer = %container-->valuesContainer;
2023-12-19 05:49:13 +00:00
%valuesContainer-->optionValue.profile = %highlighted ? GuiMenuTextProfileHL : GuiMenuTextProfile;
OptionsMenuSettingsScroll.scrollToObject(%container);
2023-12-07 01:50:51 +00:00
}
2023-12-17 05:18:33 +00:00
function addOptionEntry(%optionObj)
2023-12-07 01:50:51 +00:00
{
2023-12-19 05:49:13 +00:00
if(!isObject(%optionObj) || (%optionObj.class !$= "OptionsSettings" && %optionObj.class !$= "AudioOptionsSettings"))
2023-12-17 05:18:33 +00:00
{
error("addOptionsEntry() - attempting to create a new options entry, but was provided an invalid options object");
return 0;
}
2023-12-19 05:49:13 +00:00
%qualityLevel = getCurrentQualityLevel(%optionObj);
if(isObject(%qualityLevel))
{
%qualityLevelText = %qualityLevel.displayName;
%qualityLevelIndex = %optionObj.getObjectIndex(%qualityLevel);
}
else
{
%qualityLevelText = %qualityLevel;
%qualityLevelIndex = %optionObj.getCount();
}
%optionNameHeight = 20;
if(%optionObj.Description $= "")
%optionNameHeight = 40;
2023-12-17 05:18:33 +00:00
2023-12-07 01:50:51 +00:00
%entry = new GuiContainer() {
position = "0 0";
2023-12-17 09:27:30 +00:00
extent = "800 40";
2023-12-17 05:18:33 +00:00
profile = GuiMenuDefaultProfile;
2023-12-07 01:50:51 +00:00
tooltipProfile = "GuiToolTipProfile";
2023-12-17 05:18:33 +00:00
horizSizing = "width";
vertSizing = "bottom";
class = "OptionsListEntry";
optionsObject = %optionObj;
2023-12-19 05:49:13 +00:00
currentOptionIndex = %qualityLevelIndex;
canSave = "0";
2023-12-17 05:18:33 +00:00
new GuiButtonCtrl() {
profile = GuiMenuButtonProfile;
position = "0 0";
2023-12-17 09:27:30 +00:00
extent = "800 40";
2023-12-17 05:18:33 +00:00
horizSizing = "width";
vertSizing = "height";
internalName = "button";
class = "optionsMenuButton";
};
2023-12-07 01:50:51 +00:00
new GuiTextCtrl() {
2023-12-17 05:18:33 +00:00
text = %optionObj.OptionName;
position = $optionsEntryPad SPC -1;
2023-12-19 05:49:13 +00:00
extent = 400 SPC %optionNameHeight;
2023-12-07 01:50:51 +00:00
profile = "MenuSubHeaderText";
tooltipProfile = "GuiToolTipProfile";
internalName = "optionName";
};
new GuiTextCtrl() {
2023-12-17 05:18:33 +00:00
text = %optionObj.Description;
position = $optionsEntryPad SPC 17;
2023-12-17 09:27:30 +00:00
extent = "400 18";
2023-12-07 01:50:51 +00:00
profile = "GuiMLTextProfile";
tooltipProfile = "GuiToolTipProfile";
internalName = "optionDescription";
};
new GuiContainer() {
2023-12-17 09:27:30 +00:00
position = "400 0";
extent = "400 40";
2023-12-07 01:50:51 +00:00
profile = GuiModelessDialogProfile;
tooltipProfile = "GuiToolTipProfile";
horizSizing = "left";
vertSizing = "height";
2023-12-17 05:18:33 +00:00
internalName = "valuesContainer";
new GuiButtonCtrl() {
2023-12-17 09:27:30 +00:00
position = "310 0";
2023-12-17 05:18:33 +00:00
extent = "20 40";
text = "<";
profile = GuiMenuButtonProfile;
2023-12-17 09:27:30 +00:00
internalName = "prevValButton";
2023-12-17 05:18:33 +00:00
};
2023-12-07 01:50:51 +00:00
new GuiTextCtrl() {
2023-12-19 05:49:13 +00:00
text = %qualityLevelText;
2023-12-17 09:27:30 +00:00
position = "330 0";
2023-12-17 05:18:33 +00:00
extent = "50 40";
2023-12-07 01:50:51 +00:00
profile = "GuiMenuTextProfile";
tooltipProfile = "GuiToolTipProfile";
2023-12-17 05:18:33 +00:00
horizSizing = "right";
2023-12-07 01:50:51 +00:00
vertSizing = "center";
internalName = "optionValue";
};
2023-12-17 05:18:33 +00:00
new GuiButtonCtrl() {
2023-12-17 09:27:30 +00:00
position = "380 0";
2023-12-17 05:18:33 +00:00
extent = "20 40";
text = ">";
profile = GuiMenuButtonProfile;
2023-12-17 09:27:30 +00:00
internalName = "nextValButton";
2023-12-17 05:18:33 +00:00
};
2023-12-07 01:50:51 +00:00
};
};
2023-12-19 05:49:13 +00:00
return %entry;
}
function addOptionSlider(%optionName, %optionDesc, %prefName, %sliderMin, %sliderMax, %sliderTicks)
{
%currentVal = getVariable(%prefName);
if(%currentVal $= "")
%currentVal = %sliderMin;
%optionNameHeight = 20;
if(%optionDesc $= "")
%optionNameHeight = 40;
%entry = new GuiContainer() {
position = "0 0";
extent = "800 40";
profile = GuiMenuDefaultProfile;
tooltipProfile = "GuiToolTipProfile";
horizSizing = "width";
vertSizing = "bottom";
class = "OptionsListSliderEntry";
canSave = "0";
new GuiButtonCtrl() {
profile = GuiMenuButtonProfile;
position = "0 0";
extent = "800 40";
horizSizing = "width";
vertSizing = "height";
internalName = "button";
class = "optionsMenuButton";
};
new GuiTextCtrl() {
text = %optionName;
position = $optionsEntryPad SPC -1;
extent = 400 SPC %optionNameHeight;
profile = "MenuSubHeaderText";
tooltipProfile = "GuiToolTipProfile";
internalName = "optionName";
};
new GuiTextCtrl() {
text = %optionDesc;
position = $optionsEntryPad SPC 17;
extent = "400 18";
profile = "GuiMLTextProfile";
tooltipProfile = "GuiToolTipProfile";
internalName = "optionDescription";
};
new GuiContainer() {
position = "400 0";
extent = "400 40";
profile = GuiModelessDialogProfile;
tooltipProfile = "GuiToolTipProfile";
horizSizing = "left";
vertSizing = "height";
internalName = "valuesContainer";
new GuiSliderCtrl() {
range = %sliderMin SPC %sliderMax;
ticks = %sliderTicks;
snap = "1";
value = %currentVal;
useFillBar = "1";
fillBarColor = $TextMediumEmphasisColor;
renderTicks = "0";
position = "0 10";
extent = "300 20";
minExtent = "8 2";
horizSizing = "right";
vertSizing = "center";
profile = GuiMenuButtonProfile;
visible = "1";
active = "1";
command = "$thisControl.updateSliderValue();";
tooltipProfile = "GuiToolTipProfile";
hovertime = "1000";
isContainer = "0";
canSave = "1";
canSaveDynamicFields = "0";
class = "OptionsSliderEntrySlider";
};
};
};
return %entry;
}
function OptionsSliderEntrySlider::updateSliderValue(%this)
{
//update settings value here
}
function OptionsMenuActionMapButton::onHighlighted(%this, %highlighted)
{
%container = %this.getParent();
%container-->actionName.profile = %highlighted ? MenuSubHeaderTextHighlighted : MenuSubHeaderText;
OptionsMenuSettingsScroll.scrollToObject(%container);
}
2023-12-19 08:36:43 +00:00
function addActionMapEntry(%actionMap, %device, %keyMap, %index, %description)
2023-12-19 05:49:13 +00:00
{
%entry = new GuiContainer() {
position = "0 0";
extent = "800 40";
profile = GuiMenuDefaultProfile;
tooltipProfile = "GuiToolTipProfile";
horizSizing = "width";
vertSizing = "bottom";
class = "OptionsKeybindEntry";
canSave = "0";
actionMap = %actionMap;
device = %device;
keymap = %keyMap;
2023-12-19 08:36:43 +00:00
remapIndex = %index;
2023-12-19 05:49:13 +00:00
new GuiButtonCtrl() {
profile = GuiMenuButtonProfile;
position = "0 0";
extent = "800 40";
horizSizing = "width";
vertSizing = "height";
internalName = "button";
class = "OptionsMenuActionMapButton";
2023-12-19 08:36:43 +00:00
altCommand = "doKeyRemap($thisControl.getParent());";
2023-12-19 05:49:13 +00:00
};
new GuiTextCtrl() {
text = getField(%keyMap, 0);
position = $optionsEntryPad SPC -1;
extent = "400 40";
profile = "MenuSubHeaderText";
tooltipProfile = "GuiToolTipProfile";
internalName = "actionName";
};
new GuiContainer() {
position = "400 3";
extent = "400 34";
profile = GuiModelessDialogProfile;
tooltipProfile = "GuiToolTipProfile";
horizSizing = "left";
vertSizing = "height";
internalName = "valuesContainer";
new GuiIconButtonCtrl() {
position = "300 -10";
extent = "98 45";
BitmapAsset = "";
profile = GuiRemapActionMapButtonProfile;
sizeIconToButton = true;
makeIconSquare = true;
iconLocation = "center";
internalName = "bindButton";
active = false;
};
};
};
2023-12-07 01:50:51 +00:00
return %entry;
}