- Added float, double settingentry types. Adjusted display formatting.
- Added menu refresh on Apply button. - Fixed package name resolution for invalid chars. - Added helper console command to get xml-safe name for use in localization files. - Made error messages for bad settings xml more descriptive. - Modified GUISlider. - Converted HarmonyEventPatchesService to a System. - Fixed package name resolution for incompatible names in Xml and files, in many places. - Fixed base textbox implementation for settings.
This commit is contained in:
@@ -98,7 +98,7 @@ public static class GUIUtil
|
||||
public static (GUIScrollBar, GUITextBlock) Slider(GUILayoutGroup parent, Vector2 range, int steps, Func<float,
|
||||
string> labelFunc, float currentValue, Action<float> setter, LocalizedString? tooltip, Vector2 adjustRatio)
|
||||
{
|
||||
var layout = new GUILayoutGroup(NewItemRectT(parent, adjustRatio), isHorizontal: true);
|
||||
var layout = new GUILayoutGroup(new RectTransform(adjustRatio, parent.RectTransform), isHorizontal: true);
|
||||
var slider = new GUIScrollBar(new RectTransform((0.72f, 1.0f), layout.RectTransform), style: "GUISlider")
|
||||
{
|
||||
Range = range,
|
||||
|
||||
+44
-4
@@ -13,19 +13,20 @@ namespace Barotrauma.LuaCs;
|
||||
|
||||
internal sealed class ModsGameplaySettingsMenu : ModsSettingsMenuBase
|
||||
{
|
||||
private readonly ImmutableArray<ISettingBase> _settingsInstancesGameplay;
|
||||
private ImmutableArray<ISettingBase> _settingsInstancesGameplay;
|
||||
// menu vars
|
||||
private GUILayoutGroup _modCategoryDisplayGroup, _settingsDisplayGroup;
|
||||
private string _selectedSearchQuery = string.Empty;
|
||||
private ContentPackage _selectedContentPackage;
|
||||
private string _selectedCategory = string.Empty;
|
||||
|
||||
private event Action OnApplyInstalledModsChanges;
|
||||
|
||||
public ModsGameplaySettingsMenu(GUIFrame contentFrame,
|
||||
IPackageManagementService packageManagementService,
|
||||
IConfigService configService,
|
||||
SettingsMenu settingsMenuInstance) : base(contentFrame, packageManagementService, configService, settingsMenuInstance)
|
||||
{
|
||||
|
||||
_settingsInstancesGameplay = configService.GetDisplayableConfigs()
|
||||
.Where(s => s is not ISettingControl)
|
||||
.ToImmutableArray();
|
||||
@@ -65,6 +66,21 @@ internal sealed class ModsGameplaySettingsMenu : ModsSettingsMenuBase
|
||||
// default category
|
||||
_selectedCategory = "All";
|
||||
|
||||
OnApplyInstalledModsChanges = () =>
|
||||
{
|
||||
_settingsInstancesGameplay = configService.GetDisplayableConfigs()
|
||||
.Where(s => s is not ISettingControl)
|
||||
.ToImmutableArray();
|
||||
if (_selectedContentPackage is not null && !GetTargetPackagesList().Contains(_selectedContentPackage))
|
||||
{
|
||||
_selectedContentPackage = null;
|
||||
_selectedCategory = string.Empty;
|
||||
}
|
||||
|
||||
GenerateCategoryListDisplay(_modCategoryDisplayGroup, GetTargetPackagesList(), GetDisplayCategoriesList());
|
||||
GenerateSettingsListDisplay(_settingsDisplayGroup, GetDisplaySettingsList());
|
||||
};
|
||||
|
||||
GenerateCategoryListDisplay(_modCategoryDisplayGroup, GetTargetPackagesList(), GetDisplayCategoriesList());
|
||||
GenerateSettingsListDisplay(_settingsDisplayGroup, GetDisplaySettingsList());
|
||||
|
||||
@@ -100,7 +116,7 @@ internal sealed class ModsGameplaySettingsMenu : ModsSettingsMenuBase
|
||||
.Select(s => s.OwnerPackage)
|
||||
.Concat(new[] { ContentPackageManager.VanillaCorePackage })
|
||||
.Distinct()
|
||||
.OrderBy(p => p == ContentPackageManager.VanillaCorePackage ? 1 : 0)
|
||||
.OrderByDescending(p => p == ContentPackageManager.VanillaCorePackage ? 0 : 1)
|
||||
.ThenBy(p => p.Name)
|
||||
.ToImmutableArray();
|
||||
}
|
||||
@@ -153,12 +169,33 @@ internal sealed class ModsGameplaySettingsMenu : ModsSettingsMenuBase
|
||||
return package is null || package == ContentPackageManager.VanillaCorePackage ? "All" : package.Name;
|
||||
}
|
||||
|
||||
ContentPackage GetCurrentSelectedPackage(ImmutableArray<ContentPackage> packages)
|
||||
{
|
||||
if (_selectedContentPackage is null)
|
||||
{
|
||||
return ContentPackageManager.VanillaCorePackage;
|
||||
}
|
||||
|
||||
if (packages.Contains(_selectedContentPackage))
|
||||
{
|
||||
return _selectedContentPackage;
|
||||
}
|
||||
|
||||
if (packages.Length > 0)
|
||||
{
|
||||
_selectedContentPackage = packages[0];
|
||||
return packages[0];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
void GenerateCategoryListDisplay(GUILayoutGroup layoutGroup, ImmutableArray<ContentPackage> packagesList,
|
||||
ImmutableArray<string> categories)
|
||||
{
|
||||
layoutGroup.ClearChildren();
|
||||
var packageSelectionList = GUIUtil.Dropdown<ContentPackage>(layoutGroup, cp => GetPackageName(cp), null,
|
||||
packagesList, packagesList.Length > 0 ? packagesList[0] : null, cp =>
|
||||
packagesList, GetCurrentSelectedPackage(packagesList), cp =>
|
||||
{
|
||||
_selectedContentPackage = cp;
|
||||
_selectedCategory = string.Empty;
|
||||
@@ -246,6 +283,7 @@ internal sealed class ModsGameplaySettingsMenu : ModsSettingsMenuBase
|
||||
_settingsDisplayGroup?.Parent.RemoveChild(_settingsDisplayGroup);
|
||||
_modCategoryDisplayGroup = null;
|
||||
_settingsDisplayGroup = null;
|
||||
|
||||
}
|
||||
|
||||
public override void ApplyInstalledModChanges()
|
||||
@@ -258,7 +296,9 @@ internal sealed class ModsGameplaySettingsMenu : ModsSettingsMenuBase
|
||||
}
|
||||
|
||||
kvp.Key.TrySetValue(kvp.Value);
|
||||
ConfigService.SaveConfigValue(kvp.Key);
|
||||
}
|
||||
NewValuesCache.Clear();
|
||||
OnApplyInstalledModsChanges?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
+8
-4
@@ -11,6 +11,9 @@ public class SettingsMenuSystem : ISettingsMenuSystem
|
||||
|
||||
private ModsControlsSettingsMenu _controlsMenuInstance;
|
||||
private ModsGameplaySettingsMenu _gameplayMenuInstance;
|
||||
private GUIFrame _gameplayContentFrame;
|
||||
private GUIFrame _controlsContentFrame;
|
||||
private SettingsMenu _settingsMenuInstance;
|
||||
|
||||
private readonly Harmony _harmony;
|
||||
private readonly IPackageManagementService _packageManagementService;
|
||||
@@ -28,6 +31,7 @@ public class SettingsMenuSystem : ISettingsMenuSystem
|
||||
[HarmonyPatch(typeof(SettingsMenu), "CreateModsTab"), HarmonyPostfix]
|
||||
private static void SettingsMenu_CreateModsTab_Post(SettingsMenu __instance)
|
||||
{
|
||||
SystemInstance._settingsMenuInstance = __instance;
|
||||
SystemInstance.CreateSettingsMenu(__instance);
|
||||
}
|
||||
|
||||
@@ -39,13 +43,13 @@ public class SettingsMenuSystem : ISettingsMenuSystem
|
||||
var tabGameplayIndex = (SettingsMenu.Tab)tabCount;
|
||||
var tabControlsIndex = (SettingsMenu.Tab)tabCount+1;
|
||||
|
||||
var gameplayContentFrame = CreateNewContentTab(tabGameplayIndex, __instance,
|
||||
_gameplayContentFrame = CreateNewContentTab(tabGameplayIndex, __instance,
|
||||
"SettingsMenuTab.Mods", "LuaCsForBarotrauma.SettingsMenu.ModGameplayButton");
|
||||
var controlsContentFrame = CreateNewContentTab(tabControlsIndex, __instance,
|
||||
_controlsContentFrame = CreateNewContentTab(tabControlsIndex, __instance,
|
||||
"SettingsMenuTab.Controls", "LuaCsForBarotrauma.SettingsMenu.ModControlsButton");
|
||||
|
||||
_gameplayMenuInstance = new ModsGameplaySettingsMenu(gameplayContentFrame, _packageManagementService, _configService, __instance);
|
||||
_controlsMenuInstance = new ModsControlsSettingsMenu(controlsContentFrame, _packageManagementService, _configService, __instance);
|
||||
_gameplayMenuInstance = new ModsGameplaySettingsMenu(_gameplayContentFrame, _packageManagementService, _configService, __instance);
|
||||
_controlsMenuInstance = new ModsControlsSettingsMenu(_controlsContentFrame, _packageManagementService, _configService, __instance);
|
||||
}
|
||||
|
||||
private GUIFrame CreateNewContentTab(SettingsMenu.Tab tab, SettingsMenu settingsMenuInstance, string settingsMenuTabName, string settingMenuHoverTextIdent)
|
||||
|
||||
Reference in New Issue
Block a user