- Fixed up the settings menu.
- Made SettingEntry throw an error if "Value" attribute is not found in XML. - Fixed saved values for settings sometimes not reloading after disabling and re-enabling a package.
This commit is contained in:
+178
-32
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -20,23 +21,87 @@ internal sealed class ModsGameplaySettingsMenu : ModsSettingsMenuBase
|
|||||||
private string _selectedSearchQuery = string.Empty;
|
private string _selectedSearchQuery = string.Empty;
|
||||||
private ContentPackage _selectedContentPackage;
|
private ContentPackage _selectedContentPackage;
|
||||||
private string _selectedCategory = string.Empty;
|
private string _selectedCategory = string.Empty;
|
||||||
|
private ImmutableArray<ISettingBase> _currentlyDisplayedSettings;
|
||||||
|
private ILoggerService _loggerService;
|
||||||
|
|
||||||
|
private bool _promptOpen = false;
|
||||||
|
|
||||||
|
|
||||||
|
// Note: "static" instead of "const" for Hot Reload and to allow changing at runtime.
|
||||||
|
// ReSharper disable FieldCanBeMadeReadOnly.Local
|
||||||
|
|
||||||
|
// --- UI controls ---
|
||||||
|
private static float MenuTitleHeight = 0.06f; // (ContentDisplayAreaHeightContainer + MenuTitleHeight) < 1f
|
||||||
|
private static float ContentDisplayAreaHeightContainer = 0.93f;
|
||||||
|
private static float ContentDisplayAreaHeightInnerCategories = 0.99f;
|
||||||
|
private static float ContentDisplayAreaHeightInnerSettings = 0.97f;
|
||||||
|
private static float ContentLeftRightSplitPosition = 0.3f;
|
||||||
|
|
||||||
|
// Search Bar
|
||||||
|
private static float SearchBarLayoutHeight = 0.06f;
|
||||||
|
private static float SearchBarLabelWidth = 0.1f;
|
||||||
|
private static float SearchBarLabelBoxSpacing = 0.05f;
|
||||||
|
|
||||||
|
private static float SearchBarTextBoxWidth = 1f - SearchBarLabelWidth - SearchBarLabelBoxSpacing;
|
||||||
|
|
||||||
|
// Categories, Packages Display Area
|
||||||
|
private static float CategoriesDisplayListHeight = 0.945f;
|
||||||
|
private static float CategoryButtonHeightRelative = 0.122f;
|
||||||
|
private static float PackageSelectionButtonHeight = 0.07f;
|
||||||
|
|
||||||
|
private static Color CategoryButtonHoverSelectColor = new Color(50, 50, 50, 255);
|
||||||
|
private static Color CategoryButtonTextColor = Color.PeachPuff;
|
||||||
|
private static Color CategoryButtonTextColorSelected = Color.White;
|
||||||
|
private static Color CategoryButtonColorPressed = Color.TransparentBlack;
|
||||||
|
|
||||||
|
// Settings Display Area
|
||||||
|
private static float SettingLabelWidth = 0.6f;
|
||||||
|
private static float SettingControlWidth = 0.4f;
|
||||||
|
private static float SettingHeight = 0.05625f/ContentDisplayAreaHeightContainer/ContentDisplayAreaHeightInnerSettings;
|
||||||
|
private static Color SettingEntryLabelTextColor = Color.PeachPuff;
|
||||||
|
private static string SettingGUIFrameStyle = "";
|
||||||
|
private static Color? SettingGUIFrameColor = null;
|
||||||
|
|
||||||
|
// settings reset
|
||||||
|
private static Vector2 SettingsResetButtonTopSpacer = new Vector2(0f, 0.02f);
|
||||||
|
private static Vector2 SettingsResetButtonDimensions = new Vector2(0.3f, 0.05f);
|
||||||
|
private static string SettingsResetButtonStyle = "GUIButtonSmall";
|
||||||
|
private static Color SettingsResetButtonColor = Color.DarkOliveGreen;
|
||||||
|
private static Color SettingsResetButtonHoverColor = Color.Olive;
|
||||||
|
private static Color SettingsResetButtonTextColor = Color.PeachPuff;
|
||||||
|
private static Color SettingsResetButtonTextColorSelected = Color.White;
|
||||||
|
|
||||||
|
private static Vector2 ResetConfirmationPromptDimensions = new Vector2(0.15f, 0.2f);
|
||||||
|
|
||||||
|
|
||||||
|
// ReSharper restore FieldCanBeMadeReadOnly.Local
|
||||||
|
private const string SettingsResetButtonText = "LuaCsForBarotrauma.SettingsMenu.ResetVisibleSettings";
|
||||||
|
private const string SettingsResetPromptTitle = "LuaCsForBarotrauma.SettingsMenu.ResetPrompt.Title";
|
||||||
|
private const string SettingsResetPromptContents = "LuaCsForBarotrauma.SettingsMenu.ResetPrompt.Message";
|
||||||
|
private const string SettingsResetPromptYesText = "LuaCsForBarotrauma.SettingsMenu.ResetPrompt.Yes";
|
||||||
|
private const string SettingsResetPromptNoText = "LuaCsForBarotrauma.SettingsMenu.ResetPrompt.No";
|
||||||
|
|
||||||
|
|
||||||
private event Action OnApplyInstalledModsChanges;
|
private event Action OnApplyInstalledModsChanges;
|
||||||
|
|
||||||
public ModsGameplaySettingsMenu(GUIFrame contentFrame,
|
public ModsGameplaySettingsMenu(GUIFrame contentFrame,
|
||||||
IPackageManagementService packageManagementService,
|
IPackageManagementService packageManagementService,
|
||||||
IConfigService configService,
|
IConfigService configService,
|
||||||
|
ILoggerService loggerService,
|
||||||
SettingsMenu settingsMenuInstance) : base(contentFrame, packageManagementService, configService, settingsMenuInstance)
|
SettingsMenu settingsMenuInstance) : base(contentFrame, packageManagementService, configService, settingsMenuInstance)
|
||||||
{
|
{
|
||||||
_settingsInstancesGameplay = configService.GetDisplayableConfigs()
|
_settingsInstancesGameplay = configService.GetDisplayableConfigs()
|
||||||
.ToImmutableArray();
|
.ToImmutableArray();
|
||||||
|
|
||||||
|
_loggerService = loggerService;
|
||||||
|
|
||||||
var mainLayoutGroup = new GUILayoutGroup(new RectTransform(new Vector2(1f, 1f), contentFrame.RectTransform, Anchor.Center), false, Anchor.TopLeft);
|
var mainLayoutGroup = new GUILayoutGroup(new RectTransform(new Vector2(1f, 1f), contentFrame.RectTransform, Anchor.Center), false, Anchor.TopLeft);
|
||||||
// page title
|
// page title
|
||||||
var menuTitleLayoutGroup = new GUILayoutGroup(
|
var menuTitleLayoutGroup = new GUILayoutGroup(
|
||||||
new RectTransform(new Vector2(1f, 0.06f), mainLayoutGroup.RectTransform, Anchor.TopLeft), true, Anchor.TopLeft);
|
new RectTransform(new Vector2(1f, MenuTitleHeight), mainLayoutGroup.RectTransform, Anchor.TopLeft), true, Anchor.TopLeft);
|
||||||
GUIUtil.Label(menuTitleLayoutGroup, "Mods Gameplay Settings", GUIStyle.LargeFont, new Vector2(1f, 1f));
|
GUIUtil.Label(menuTitleLayoutGroup,
|
||||||
|
GetLocalizedString("LuaCsForBarotrauma.SettingsMenu.ModGameplayButton", "Mod Gameplay Settings"),
|
||||||
|
GUIStyle.LargeFont, new Vector2(1f, 1f));
|
||||||
|
|
||||||
// page contents
|
// page contents
|
||||||
var contentAreaLayoutGroup = new GUILayoutGroup(
|
var contentAreaLayoutGroup = new GUILayoutGroup(
|
||||||
@@ -44,10 +109,10 @@ internal sealed class ModsGameplaySettingsMenu : ModsSettingsMenuBase
|
|||||||
Anchor.TopLeft);
|
Anchor.TopLeft);
|
||||||
|
|
||||||
var searchBarLayoutGroup = new GUILayoutGroup(
|
var searchBarLayoutGroup = new GUILayoutGroup(
|
||||||
new RectTransform(new Vector2(1f, 0.06f), contentAreaLayoutGroup.RectTransform, Anchor.TopCenter), true, Anchor.CenterLeft);
|
new RectTransform(new Vector2(1f, SearchBarLayoutHeight), contentAreaLayoutGroup.RectTransform, Anchor.TopCenter), true, Anchor.CenterLeft);
|
||||||
GUIUtil.Label(searchBarLayoutGroup, "Search: ", GUIStyle.SubHeadingFont, new Vector2(0.1f, 1f));
|
GUIUtil.Label(searchBarLayoutGroup, "Search: ", GUIStyle.SubHeadingFont, new Vector2(SearchBarLabelWidth, 1f));
|
||||||
var searchBar = new GUITextBox(
|
var searchBar = new GUITextBox(
|
||||||
new RectTransform(new Vector2(0.85f, 0.1f), searchBarLayoutGroup.RectTransform, Anchor.TopLeft),
|
new RectTransform(new Vector2(SearchBarTextBoxWidth, 0.1f), searchBarLayoutGroup.RectTransform, Anchor.TopLeft),
|
||||||
createClearButton: true)
|
createClearButton: true)
|
||||||
{
|
{
|
||||||
OnTextChangedDelegate = (btn, txt) =>
|
OnTextChangedDelegate = (btn, txt) =>
|
||||||
@@ -56,12 +121,13 @@ internal sealed class ModsGameplaySettingsMenu : ModsSettingsMenuBase
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// main display area
|
// main display area
|
||||||
var settingsContentAreaGroup = new GUILayoutGroup(new RectTransform(new Vector2(1f, 0.90f), contentAreaLayoutGroup.RectTransform, Anchor.BottomCenter));
|
var settingsContentAreaGroup = new GUILayoutGroup(new RectTransform(new Vector2(1f, ContentDisplayAreaHeightContainer), contentAreaLayoutGroup.RectTransform, Anchor.BottomCenter));
|
||||||
GUIUtil.Spacer(settingsContentAreaGroup, Vector2.One);
|
GUIUtil.Spacer(settingsContentAreaGroup, Vector2.One);
|
||||||
(_modCategoryDisplayGroup, _settingsDisplayGroup) = GUIUtil.CreateSidebars(settingsContentAreaGroup, true);
|
(_modCategoryDisplayGroup, _settingsDisplayGroup) = GUIUtil.CreateSidebars(settingsContentAreaGroup, true);
|
||||||
_modCategoryDisplayGroup.RectTransform.RelativeSize = new Vector2(0.3f, 1f);
|
_modCategoryDisplayGroup.RectTransform.RelativeSize = new Vector2(ContentLeftRightSplitPosition, ContentDisplayAreaHeightInnerCategories);
|
||||||
_settingsDisplayGroup.RectTransform.RelativeSize = new Vector2(0.7f, 1f);
|
_settingsDisplayGroup.RectTransform.RelativeSize = new Vector2(1f-ContentLeftRightSplitPosition, ContentDisplayAreaHeightInnerSettings);
|
||||||
|
|
||||||
// default category
|
// default category
|
||||||
_selectedCategory = "All";
|
_selectedCategory = "All";
|
||||||
@@ -202,10 +268,11 @@ internal sealed class ModsGameplaySettingsMenu : ModsSettingsMenuBase
|
|||||||
_selectedCategory = string.Empty;
|
_selectedCategory = string.Empty;
|
||||||
GenerateCategoryListDisplay(_modCategoryDisplayGroup, GetTargetPackagesList(), GetDisplayCategoriesList());
|
GenerateCategoryListDisplay(_modCategoryDisplayGroup, GetTargetPackagesList(), GetDisplayCategoriesList());
|
||||||
GenerateSettingsListDisplay(_settingsDisplayGroup, GetDisplaySettingsList());
|
GenerateSettingsListDisplay(_settingsDisplayGroup, GetDisplaySettingsList());
|
||||||
}, new Vector2(1f, 0.07f));
|
}, new Vector2(1f, PackageSelectionButtonHeight));
|
||||||
var containerBox = new GUIListBox(new RectTransform(new Vector2(1f, 0.945f), layoutGroup.RectTransform));
|
var containerBox = new GUIListBox(new RectTransform(new Vector2(1f, CategoriesDisplayListHeight), layoutGroup.RectTransform));
|
||||||
const float entryHeight = 0.122f;
|
|
||||||
float sizeY = MathF.Max(categories.Length * entryHeight, 1f);
|
|
||||||
|
float sizeY = MathF.Max(categories.Length * CategoryButtonHeightRelative, 1f);
|
||||||
var displayedCategoriesFrame = new GUIFrame(new RectTransform(new Vector2(1f, sizeY), containerBox.Content.RectTransform), style: null, color: Color.Black)
|
var displayedCategoriesFrame = new GUIFrame(new RectTransform(new Vector2(1f, sizeY), containerBox.Content.RectTransform), style: null, color: Color.Black)
|
||||||
{
|
{
|
||||||
CanBeFocused = false
|
CanBeFocused = false
|
||||||
@@ -214,17 +281,18 @@ internal sealed class ModsGameplaySettingsMenu : ModsSettingsMenuBase
|
|||||||
|
|
||||||
foreach (var category in categories)
|
foreach (var category in categories)
|
||||||
{
|
{
|
||||||
var btn = new GUIButton(new RectTransform(new Vector2(1f, entryHeight), displayCategoriesLayout.RectTransform),
|
var btn = new GUIButton(new RectTransform(new Vector2(1f, CategoryButtonHeightRelative), displayCategoriesLayout.RectTransform),
|
||||||
text: category, color: Color.TransparentBlack)
|
text: category, color: Color.TransparentBlack)
|
||||||
{
|
{
|
||||||
CanBeFocused = true,
|
CanBeFocused = true,
|
||||||
CanBeSelected = true,
|
CanBeSelected = true,
|
||||||
TextColor = Color.PeachPuff,
|
TextColor = CategoryButtonTextColor,
|
||||||
HoverColor = new Color(50, 50, 50, 255),
|
HoverColor = CategoryButtonHoverSelectColor,
|
||||||
HoverTextColor = Color.White,
|
HoverTextColor = CategoryButtonTextColorSelected,
|
||||||
SelectedColor = new Color(50, 50, 50, 255),
|
PressedColor = CategoryButtonColorPressed,
|
||||||
SelectedTextColor = Color.White,
|
SelectedColor = CategoryButtonHoverSelectColor,
|
||||||
OnPressed = () =>
|
SelectedTextColor = CategoryButtonHoverSelectColor,
|
||||||
|
OnClicked = (btn, obj) =>
|
||||||
{
|
{
|
||||||
_selectedCategory = category;
|
_selectedCategory = category;
|
||||||
GenerateSettingsListDisplay(_settingsDisplayGroup, GetDisplaySettingsList());
|
GenerateSettingsListDisplay(_settingsDisplayGroup, GetDisplaySettingsList());
|
||||||
@@ -237,26 +305,47 @@ internal sealed class ModsGameplaySettingsMenu : ModsSettingsMenuBase
|
|||||||
void GenerateSettingsListDisplay(GUILayoutGroup layoutGroup, ImmutableArray<ISettingBase> settings)
|
void GenerateSettingsListDisplay(GUILayoutGroup layoutGroup, ImmutableArray<ISettingBase> settings)
|
||||||
{
|
{
|
||||||
layoutGroup.ClearChildren();
|
layoutGroup.ClearChildren();
|
||||||
const float settingHeight = 0.0625f;
|
_currentlyDisplayedSettings = settings;
|
||||||
|
|
||||||
var containerBox = new GUIListBox(new RectTransform(new Vector2(1f, 1f), layoutGroup.RectTransform));
|
var containerBox = new GUIListBox(new RectTransform(new Vector2(1f, 1f-SettingsResetButtonDimensions.Y), layoutGroup.RectTransform));
|
||||||
foreach (var setting in settings)
|
foreach (var setting in settings)
|
||||||
{
|
{
|
||||||
var entry = AddSettingToDisplay(
|
var entry = AddSettingToDisplay(
|
||||||
setting,
|
setting,
|
||||||
containerBox.Content.RectTransform,
|
containerBox.Content.RectTransform,
|
||||||
settingHeight: settingHeight,
|
settingHeight: SettingHeight,
|
||||||
labelSize: new Vector2(0.6f, 1f),
|
labelSize: new Vector2(SettingLabelWidth, 1f),
|
||||||
controlSize: new Vector2(0.4f, 1f));
|
controlSize: new Vector2(SettingControlWidth, 1f));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var spacer = new GUIFrame(new RectTransform(SettingsResetButtonTopSpacer, layoutGroup.RectTransform),
|
||||||
|
style: null, color: Color.TransparentBlack);
|
||||||
|
|
||||||
|
var resetSettingsButton = new GUIButton(
|
||||||
|
new RectTransform(SettingsResetButtonDimensions, layoutGroup.RectTransform),
|
||||||
|
GetLocalizedString(SettingsResetButtonText, "Reset Visible Settings"),
|
||||||
|
style: SettingsResetButtonStyle)
|
||||||
|
{
|
||||||
|
CanBeSelected = true,
|
||||||
|
CanBeFocused = true,
|
||||||
|
Color = SettingsResetButtonColor,
|
||||||
|
HoverColor = SettingsResetButtonHoverColor,
|
||||||
|
SelectedColor = SettingsResetButtonHoverColor,
|
||||||
|
SelectedTextColor = SettingsResetButtonTextColorSelected,
|
||||||
|
TextColor = SettingsResetButtonTextColor,
|
||||||
|
OnClicked = (btn, obj) =>
|
||||||
|
{
|
||||||
|
DisplayResetConfirmationPrompt(settings);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
(GUIFrame entryFrame, GUILayoutGroup entryLayoutGroup) AddSettingToDisplay(ISettingBase setting,
|
(GUIFrame entryFrame, GUILayoutGroup entryLayoutGroup)
|
||||||
RectTransform parent, float settingHeight, Vector2 labelSize, Vector2 controlSize)
|
AddSettingToDisplay(ISettingBase setting, RectTransform parent, float settingHeight, Vector2 labelSize, Vector2 controlSize)
|
||||||
{
|
{
|
||||||
GUIFrame entryFrame = new GUIFrame(new RectTransform(new Vector2(1f, settingHeight), parent))
|
GUIFrame entryFrame = new GUIFrame(new RectTransform(new Vector2(1f, settingHeight), parent),
|
||||||
|
style: SettingGUIFrameStyle, color: SettingGUIFrameColor)
|
||||||
{
|
{
|
||||||
Color = Color.DarkGray
|
Color = Color.DarkGray
|
||||||
};
|
};
|
||||||
@@ -266,9 +355,10 @@ internal sealed class ModsGameplaySettingsMenu : ModsSettingsMenuBase
|
|||||||
new GUIFrame(new RectTransform(new Vector2(0.02f, 1f), entryLayoutGroup.RectTransform),
|
new GUIFrame(new RectTransform(new Vector2(0.02f, 1f), entryLayoutGroup.RectTransform),
|
||||||
color: Color.TransparentBlack);
|
color: Color.TransparentBlack);
|
||||||
|
|
||||||
|
// setting label
|
||||||
new GUITextBlock(new RectTransform(labelSize - new Vector2(0.05f, 0f), entryLayoutGroup.RectTransform),
|
new GUITextBlock(new RectTransform(labelSize - new Vector2(0.05f, 0f), entryLayoutGroup.RectTransform),
|
||||||
GetLocalizedString(setting.GetDisplayInfo().DisplayName, setting.GetDisplayInfo().DisplayName),
|
GetLocalizedString(setting.GetDisplayInfo().DisplayName, setting.GetDisplayInfo().DisplayName),
|
||||||
textColor: Color.PeachPuff,
|
textColor: SettingEntryLabelTextColor,
|
||||||
font: GUIStyle.SmallFont,
|
font: GUIStyle.SmallFont,
|
||||||
textAlignment: Alignment.Left)
|
textAlignment: Alignment.Left)
|
||||||
{
|
{
|
||||||
@@ -281,6 +371,58 @@ internal sealed class ModsGameplaySettingsMenu : ModsSettingsMenuBase
|
|||||||
});
|
});
|
||||||
return (entryFrame, entryLayoutGroup);
|
return (entryFrame, entryLayoutGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DisplayResetConfirmationPrompt(ImmutableArray<ISettingBase> settings)
|
||||||
|
{
|
||||||
|
if (_promptOpen)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_promptOpen = true;
|
||||||
|
|
||||||
|
var msgBox = new GUIMessageBox(GetLocalizedString(SettingsResetPromptTitle, "Reset Visible Settings"),
|
||||||
|
GetLocalizedString(SettingsResetPromptContents,
|
||||||
|
"Are you sure you want to reset the values for currently displayed settings?"),
|
||||||
|
new LocalizedString[]
|
||||||
|
{
|
||||||
|
GetLocalizedString(SettingsResetPromptYesText, "Yes"),
|
||||||
|
GetLocalizedString(SettingsResetPromptNoText, "No")
|
||||||
|
}, ResetConfirmationPromptDimensions);
|
||||||
|
msgBox.Buttons[0].OnClicked = (btn, obj) =>
|
||||||
|
{
|
||||||
|
ResetValuesForDisplayedSettings(settings);
|
||||||
|
btn.Visible = false;
|
||||||
|
_promptOpen = false;
|
||||||
|
msgBox.Close();
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
msgBox.Buttons[1].OnClicked = (btn, obj) =>
|
||||||
|
{
|
||||||
|
btn.Visible = false;
|
||||||
|
_promptOpen = false;
|
||||||
|
msgBox.Close();
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
void ResetValuesForDisplayedSettings(ImmutableArray<ISettingBase> settings)
|
||||||
|
{
|
||||||
|
if (settings.IsDefaultOrEmpty)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
NewValuesCache.Clear();
|
||||||
|
foreach (var setting in settings)
|
||||||
|
{
|
||||||
|
var str = setting.GetDefaultStringValue();
|
||||||
|
NewValuesCache[setting] = str;
|
||||||
|
loggerService.LogDebug($"Resetting value for {setting.InternalName} to '{str}'");
|
||||||
|
}
|
||||||
|
|
||||||
|
ApplyInstalledModChanges();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -303,8 +445,12 @@ internal sealed class ModsGameplaySettingsMenu : ModsSettingsMenuBase
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
kvp.Key.TrySetSerializedValue(kvp.Value);
|
var success = kvp.Key.TrySetSerializedValue(kvp.Value);
|
||||||
ConfigService.SaveConfigValue(kvp.Key);
|
if (success)
|
||||||
|
{
|
||||||
|
ConfigService.SaveConfigValue(kvp.Key);
|
||||||
|
_loggerService.LogDebug($"Applied save value for {kvp.Key.InternalName} of {kvp.Value.ToString()}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
NewValuesCache.Clear();
|
NewValuesCache.Clear();
|
||||||
OnApplyInstalledModsChanges?.Invoke();
|
OnApplyInstalledModsChanges?.Invoke();
|
||||||
|
|||||||
+3
-1
@@ -1,8 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
|
using System.Xml.Linq;
|
||||||
using Barotrauma.Extensions;
|
using Barotrauma.Extensions;
|
||||||
using Barotrauma.LuaCs.Data;
|
using Barotrauma.LuaCs.Data;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
|
using OneOf;
|
||||||
|
|
||||||
namespace Barotrauma.LuaCs;
|
namespace Barotrauma.LuaCs;
|
||||||
|
|
||||||
@@ -12,7 +14,7 @@ internal abstract class ModsSettingsMenuBase : IDisposable
|
|||||||
protected IPackageManagementService PackageManagementService { get; private set; }
|
protected IPackageManagementService PackageManagementService { get; private set; }
|
||||||
protected IConfigService ConfigService { get; private set; }
|
protected IConfigService ConfigService { get; private set; }
|
||||||
protected SettingsMenu SettingsMenuInstance { get; private set; }
|
protected SettingsMenu SettingsMenuInstance { get; private set; }
|
||||||
protected readonly ConcurrentDictionary<ISettingBase, string> NewValuesCache = new();
|
protected readonly ConcurrentDictionary<ISettingBase, OneOf<string, XElement>> NewValuesCache = new();
|
||||||
|
|
||||||
protected ModsSettingsMenuBase(GUIFrame contentFrame,
|
protected ModsSettingsMenuBase(GUIFrame contentFrame,
|
||||||
IPackageManagementService packageManagementService,
|
IPackageManagementService packageManagementService,
|
||||||
|
|||||||
+4
-2
@@ -18,12 +18,14 @@ public class SettingsMenuSystem : ISettingsMenuSystem
|
|||||||
private readonly Harmony _harmony;
|
private readonly Harmony _harmony;
|
||||||
private readonly IPackageManagementService _packageManagementService;
|
private readonly IPackageManagementService _packageManagementService;
|
||||||
private readonly IConfigService _configService;
|
private readonly IConfigService _configService;
|
||||||
|
private readonly ILoggerService _loggerService;
|
||||||
private static SettingsMenuSystem SystemInstance;
|
private static SettingsMenuSystem SystemInstance;
|
||||||
|
|
||||||
public SettingsMenuSystem(IPackageManagementService packageManagementService, IConfigService configService)
|
public SettingsMenuSystem(IPackageManagementService packageManagementService, IConfigService configService, ILoggerService loggerService)
|
||||||
{
|
{
|
||||||
_packageManagementService = packageManagementService;
|
_packageManagementService = packageManagementService;
|
||||||
_configService = configService;
|
_configService = configService;
|
||||||
|
_loggerService = loggerService;
|
||||||
SystemInstance = this;
|
SystemInstance = this;
|
||||||
_harmony = Harmony.CreateAndPatchAll(typeof(SettingsMenuSystem));
|
_harmony = Harmony.CreateAndPatchAll(typeof(SettingsMenuSystem));
|
||||||
}
|
}
|
||||||
@@ -49,7 +51,7 @@ public class SettingsMenuSystem : ISettingsMenuSystem
|
|||||||
"SettingsMenuTab.Controls", "LuaCsForBarotrauma.SettingsMenu.ModControlsButton");
|
"SettingsMenuTab.Controls", "LuaCsForBarotrauma.SettingsMenu.ModControlsButton");
|
||||||
*/
|
*/
|
||||||
|
|
||||||
_gameplayMenuInstance = new ModsGameplaySettingsMenu(_gameplayContentFrame, _packageManagementService, _configService, __instance);
|
_gameplayMenuInstance = new ModsGameplaySettingsMenu(_gameplayContentFrame, _packageManagementService, _configService, _loggerService, __instance);
|
||||||
//_controlsMenuInstance = new ModsControlsSettingsMenu(_controlsContentFrame, _packageManagementService, _configService, __instance);
|
//_controlsMenuInstance = new ModsControlsSettingsMenu(_controlsContentFrame, _packageManagementService, _configService, __instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,6 @@
|
|||||||
</Values>
|
</Values>
|
||||||
</Setting>
|
</Setting>
|
||||||
<Setting Name="UseCaching" Type="bool" Value="true" AllowChangesWhileExecuting="false"/>
|
<Setting Name="UseCaching" Type="bool" Value="true" AllowChangesWhileExecuting="false"/>
|
||||||
<Setting Name="IsCsEnabledForSession" Type="bool" AllowChangesWhileExecuting="false" ShowInMenus="false"/>
|
<Setting Name="IsCsEnabledForSession" Type="bool" AllowChangesWhileExecuting="false" ShowInMenus="false" Value="false"/>
|
||||||
</Settings>
|
</Settings>
|
||||||
</Configuration>
|
</Configuration>
|
||||||
|
|||||||
@@ -2,6 +2,11 @@
|
|||||||
<infotexts language="English" nowhitespace="false" translatedname="English">
|
<infotexts language="English" nowhitespace="false" translatedname="English">
|
||||||
<LuaCsForBarotrauma.SettingsMenu.ModControlsButton>Mod Controls Settings</LuaCsForBarotrauma.SettingsMenu.ModControlsButton>
|
<LuaCsForBarotrauma.SettingsMenu.ModControlsButton>Mod Controls Settings</LuaCsForBarotrauma.SettingsMenu.ModControlsButton>
|
||||||
<LuaCsForBarotrauma.SettingsMenu.ModGameplayButton>Mod Gameplay Settings</LuaCsForBarotrauma.SettingsMenu.ModGameplayButton>
|
<LuaCsForBarotrauma.SettingsMenu.ModGameplayButton>Mod Gameplay Settings</LuaCsForBarotrauma.SettingsMenu.ModGameplayButton>
|
||||||
|
<LuaCsForBarotrauma.SettingsMenu.ResetVisibleSettings>Reset Displayed Settings</LuaCsForBarotrauma.SettingsMenu.ResetVisibleSettings>
|
||||||
|
<LuaCsForBarotrauma.SettingsMenu.ResetPrompt.Title>Reset Visible Settings</LuaCsForBarotrauma.SettingsMenu.ResetPrompt.Title>
|
||||||
|
<LuaCsForBarotrauma.SettingsMenu.ResetPrompt.Message>Are you sure you want to reset the values for currently displayed settings?</LuaCsForBarotrauma.SettingsMenu.ResetPrompt.Message>
|
||||||
|
<LuaCsForBarotrauma.SettingsMenu.ResetPrompt.Yes>Yes</LuaCsForBarotrauma.SettingsMenu.ResetPrompt.Yes>
|
||||||
|
<LuaCsForBarotrauma.SettingsMenu.ResetPrompt.No>No</LuaCsForBarotrauma.SettingsMenu.ResetPrompt.No>
|
||||||
<!-- Settings -->
|
<!-- Settings -->
|
||||||
<!-- Is Cs Enabled-->
|
<!-- Is Cs Enabled-->
|
||||||
<LuaCsForBarotrauma.CsRunPolicy.DisplayName>Are C# Mods Allowed</LuaCsForBarotrauma.CsRunPolicy.DisplayName>
|
<LuaCsForBarotrauma.CsRunPolicy.DisplayName>Are C# Mods Allowed</LuaCsForBarotrauma.CsRunPolicy.DisplayName>
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Configuration>
|
<Configuration>
|
||||||
<Settings>
|
<Settings>
|
||||||
<Setting Name="TestTickbox" Type="bool"/>
|
<Setting Name="TestTickbox" Type="bool" Value="true"/>
|
||||||
<Setting Name="TestSynchroClient" Type="int" NetSync="TwoWay" />
|
<Setting Name="TestSynchroClient" Type="int" NetSync="TwoWay" Value="40"/>
|
||||||
<Setting Name="TestSynchroServer" Type="int" NetSync="ServerAuthority" />
|
<Setting Name="TestSynchroServer" Type="int" NetSync="ServerAuthority" Value="25"/>
|
||||||
<Setting Name="TestFloat" Type="float" NetSync="ServerAuthority" />
|
<Setting Name="TestFloat" Type="float" NetSync="ServerAuthority" Value="3498"/>
|
||||||
<Setting Name="TestHidden" Type="bool" ShowInMenus="false"/>
|
<Setting Name="TestHidden" Type="bool" ShowInMenus="false" Value="false"/>
|
||||||
<Setting Name="TestRangeFloat" Type="rangeFloat" Min="0" Max="25" Steps="11"/>
|
<Setting Name="TestRangeFloat" Type="rangeFloat" Min="0" Max="25" Steps="11" Value="4.5"/>
|
||||||
<Setting Name="TestRangeInt" Type="rangeInt" Min="0" Max="10" Steps="11"/>
|
<Setting Name="TestRangeInt" Type="rangeInt" Min="0" Max="10" Steps="11" Value="4"/>
|
||||||
<Setting Name="TestString" Type="string" />
|
<Setting Name="TestString" Type="string" Value="ok"/>
|
||||||
<Setting Name="TestControl" Type="control" Value="A"/>
|
<Setting Name="TestControl" Type="control" Value="A"/>
|
||||||
<Setting Name="TestDropdownList" Type="listString" Value="Hi">
|
<Setting Name="TestDropdownList" Type="listString" Value="Hi">
|
||||||
<Values>
|
<Values>
|
||||||
|
|||||||
@@ -34,6 +34,11 @@ public partial class SettingEntry<T> : SettingBase, ISettingBase<T>, INetworkSyn
|
|||||||
}
|
}
|
||||||
ValueChangePredicate = valueChangePredicate;
|
ValueChangePredicate = valueChangePredicate;
|
||||||
|
|
||||||
|
if (ConfigInfo.Element.Attribute("Value") is null)
|
||||||
|
{
|
||||||
|
ThrowHelper.ThrowArgumentException($"The Setting {InternalName} in package {OwnerPackage.Name} does not have a 'Value' attribute!");
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Value = (T)Convert.ChangeType(ConfigInfo.Element.GetAttributeString("Value", null), typeof(T));
|
Value = (T)Convert.ChangeType(ConfigInfo.Element.GetAttributeString("Value", null), typeof(T));
|
||||||
@@ -147,10 +152,8 @@ public partial class SettingEntry<T> : SettingBase, ISettingBase<T>, INetworkSyn
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override Type GetValueType() => typeof(T);
|
public override Type GetValueType() => typeof(T);
|
||||||
|
|
||||||
public override string GetStringValue() => Value?.ToString() ?? string.Empty;
|
public override string GetStringValue() => Value?.ToString() ?? string.Empty;
|
||||||
|
public override string GetDefaultStringValue() => DefaultValue?.ToString() ?? string.Empty;
|
||||||
public override string GetDefaultStringValue() => DefaultValue.ToString();
|
|
||||||
|
|
||||||
public override bool TrySetSerializedValue(OneOf<string, XElement> value)
|
public override bool TrySetSerializedValue(OneOf<string, XElement> value)
|
||||||
{
|
{
|
||||||
@@ -181,7 +184,6 @@ public partial class SettingEntry<T> : SettingBase, ISettingBase<T>, INetworkSyn
|
|||||||
return default(T);
|
return default(T);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return !isFailed && TrySetValue(typeConvertedValue);
|
return !isFailed && TrySetValue(typeConvertedValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -269,7 +269,10 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
var state = CurrentRunState;
|
var state = CurrentRunState;
|
||||||
SetRunState(RunState.Unloaded);
|
SetRunState(RunState.Unloaded);
|
||||||
SetRunState(state);
|
CoroutineManager.Invoke(() =>
|
||||||
|
{
|
||||||
|
SetRunState(state);
|
||||||
|
},0.25f);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -287,6 +290,7 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.Logger.LogResults(PackageManagementService.SyncLoadedPackagesList(GetLuaCsEnabledPackagesList(packages)));
|
this.Logger.LogResults(PackageManagementService.SyncLoadedPackagesList(GetLuaCsEnabledPackagesList(packages)));
|
||||||
|
ConfigService.LoadSavedConfigsValues();
|
||||||
SetRunState(state); // restore
|
SetRunState(state); // restore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user