[Save/Sync] Commit work before .NET 10 tests.
This commit is contained in:
@@ -18,6 +18,8 @@ public sealed partial class ConfigService
|
|||||||
return _settingsInstances.Values
|
return _settingsInstances.Values
|
||||||
.Where(s => !s.IsDisposed)
|
.Where(s => !s.IsDisposed)
|
||||||
.Where(s => s.GetDisplayInfo().ShowInMenus)
|
.Where(s => s.GetDisplayInfo().ShowInMenus)
|
||||||
|
.Where(s => !GameMain.IsMultiplayer || s.GetConfigInfo().NetSync != NetSync.ServerAuthority)
|
||||||
|
.Where(s => s.GetConfigInfo().EditableStates >= _infoProvider.CurrentRunState)
|
||||||
.ToImmutableArray();
|
.ToImmutableArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
namespace Barotrauma.LuaCs;
|
namespace Barotrauma.LuaCs;
|
||||||
|
|
||||||
internal sealed class ModsControlsSettingsMenu : ModsSettingsMenu
|
internal sealed class ModsControlsSettingsMenu : ModsSettingsMenuBase
|
||||||
{
|
{
|
||||||
public ModsControlsSettingsMenu(GUIFrame contentFrame,
|
public ModsControlsSettingsMenu(GUIFrame contentFrame,
|
||||||
IPackageManagementService packageManagementService,
|
IPackageManagementService packageManagementService,
|
||||||
+77
-22
@@ -3,10 +3,11 @@ using System.Collections.Immutable;
|
|||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Barotrauma.LuaCs.Data;
|
using Barotrauma.LuaCs.Data;
|
||||||
|
// ReSharper disable ObjectCreationAsStatement
|
||||||
|
|
||||||
namespace Barotrauma.LuaCs;
|
namespace Barotrauma.LuaCs;
|
||||||
|
|
||||||
internal sealed class ModsGameplaySettingsMenu : ModsSettingsMenu
|
internal sealed class ModsGameplaySettingsMenu : ModsSettingsMenuBase
|
||||||
{
|
{
|
||||||
private readonly ImmutableArray<ISettingBase> _settingsInstancesGameplay;
|
private readonly ImmutableArray<ISettingBase> _settingsInstancesGameplay;
|
||||||
// menu vars
|
// menu vars
|
||||||
@@ -57,65 +58,121 @@ internal sealed class ModsGameplaySettingsMenu : ModsSettingsMenu
|
|||||||
_modCategoryDisplayGroup.RectTransform.RelativeSize = new Vector2(0.3f, 1f);
|
_modCategoryDisplayGroup.RectTransform.RelativeSize = new Vector2(0.3f, 1f);
|
||||||
_settingsDisplayGroup.RectTransform.RelativeSize = new Vector2(0.7f, 1f);
|
_settingsDisplayGroup.RectTransform.RelativeSize = new Vector2(0.7f, 1f);
|
||||||
|
|
||||||
GenerateCategoryListDisplay(_modCategoryDisplayGroup, GetDisplayCategoriesList());
|
GenerateCategoryListDisplay(_modCategoryDisplayGroup, GetTargetPackagesList(), GetDisplayCategoriesList());
|
||||||
GenerateSettingsListDisplay(_settingsDisplayGroup, GetDisplaySettingsList());
|
GenerateSettingsListDisplay(_settingsDisplayGroup, GetDisplaySettingsList());
|
||||||
|
|
||||||
void GenerateDisplayFromFilter(string text)
|
void GenerateDisplayFromFilter(string text)
|
||||||
{
|
{
|
||||||
_selectedSearchQuery = text;
|
_selectedSearchQuery = text;
|
||||||
GenerateCategoryListDisplay(_modCategoryDisplayGroup, GetDisplayCategoriesList());
|
GenerateCategoryListDisplay(_modCategoryDisplayGroup, GetTargetPackagesList(), GetDisplayCategoriesList());
|
||||||
GenerateSettingsListDisplay(_settingsDisplayGroup, GetDisplaySettingsList());
|
GenerateSettingsListDisplay(_settingsDisplayGroup, GetDisplaySettingsList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string GetLocalizedString(string identifier)
|
||||||
|
{
|
||||||
|
var lstr = TextManager.Get(identifier);
|
||||||
|
return lstr.IsNullOrWhiteSpace() ? "General" : lstr.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filters by selected package and query text
|
||||||
ImmutableArray<string> GetDisplayCategoriesList()
|
ImmutableArray<string> GetDisplayCategoriesList()
|
||||||
{
|
{
|
||||||
return _settingsInstancesGameplay
|
return GetFilteredSettingsList()
|
||||||
.Select(s => s.GetDisplayInfo().DisplayCategory)
|
.Select(s => GetLocalizedString(s.GetDisplayInfo().DisplayCategory))
|
||||||
.Distinct()
|
.Distinct()
|
||||||
.ToImmutableArray();
|
.ToImmutableArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
ImmutableArray<ISettingBase> GetDisplaySettingsList()
|
// Filters by query text
|
||||||
|
ImmutableArray<ContentPackage> GetTargetPackagesList()
|
||||||
{
|
{
|
||||||
return _settingsInstancesGameplay
|
return _settingsInstancesGameplay
|
||||||
|
.Where(s => SettingMatchesQuery(s, _selectedSearchQuery))
|
||||||
|
.Select(s => s.OwnerPackage)
|
||||||
|
.Distinct()
|
||||||
|
.ToImmutableArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filters by selected package, query text, and selected category.
|
||||||
|
ImmutableArray<ISettingBase> GetDisplaySettingsList()
|
||||||
|
{
|
||||||
|
return GetFilteredSettingsList()
|
||||||
.Where(s => _selectedCategory.IsNullOrWhiteSpace()
|
.Where(s => _selectedCategory.IsNullOrWhiteSpace()
|
||||||
|| s.GetDisplayInfo().DisplayCategory == _selectedCategory)
|
|| GetLocalizedString(s.GetDisplayInfo().DisplayCategory) == _selectedCategory)
|
||||||
|
.ToImmutableArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filters by selected package and by query text.
|
||||||
|
ImmutableArray<ISettingBase> GetFilteredSettingsList()
|
||||||
|
{
|
||||||
|
return _settingsInstancesGameplay
|
||||||
|
.Where(s => SettingMatchesQuery(s, _selectedSearchQuery))
|
||||||
.Where(s => _selectedContentPackage is null
|
.Where(s => _selectedContentPackage is null
|
||||||
|
|| _selectedContentPackage == ContentPackageManager.VanillaCorePackage // vanilla is treated as all packages
|
||||||
|| s.OwnerPackage == _selectedContentPackage)
|
|| s.OwnerPackage == _selectedContentPackage)
|
||||||
.ToImmutableArray();
|
.ToImmutableArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GenerateCategoryListDisplay(GUILayoutGroup layoutGroup, ImmutableArray<string> categoryIdents)
|
|
||||||
|
bool SettingMatchesQuery(ISettingBase setting, string queryText)
|
||||||
|
{
|
||||||
|
if (queryText.IsNullOrWhiteSpace())
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
queryText = queryText.ToLowerInvariant().Trim();
|
||||||
|
|
||||||
|
if (setting.InternalName.ToLowerInvariant().Trim().Contains(queryText) || setting.OwnerPackage.Name.ToLowerInvariant().Trim().Contains(queryText))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
var displayInfo = setting.GetDisplayInfo();
|
||||||
|
return TextManager.Get(displayInfo.DisplayName).Value.ToLowerInvariant().Trim().Contains(queryText)
|
||||||
|
|| TextManager.Get(displayInfo.DisplayCategory).Value.ToLowerInvariant().Trim().Contains(queryText)
|
||||||
|
|| TextManager.Get(displayInfo.Description).Value.ToLowerInvariant().Trim().Contains(queryText)
|
||||||
|
|| TextManager.Get(displayInfo.Tooltip).Value.ToLowerInvariant().Trim().Contains(queryText);
|
||||||
|
}
|
||||||
|
|
||||||
|
string GetPackageName(ContentPackage package)
|
||||||
|
{
|
||||||
|
return package is null || package == ContentPackageManager.VanillaCorePackage ? "All" : package.Name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GenerateCategoryListDisplay(GUILayoutGroup layoutGroup, ImmutableArray<ContentPackage> packagesList,
|
||||||
|
ImmutableArray<string> categories)
|
||||||
{
|
{
|
||||||
layoutGroup.ClearChildren();
|
layoutGroup.ClearChildren();
|
||||||
|
var packageSelectionList = GUIUtil.Dropdown<ContentPackage>(layoutGroup, cp => GetPackageName(cp), null,
|
||||||
var packages = _settingsInstancesGameplay.Select(s => s.OwnerPackage)
|
packagesList, packagesList.Length > 0 ? packagesList[0] : null, cp =>
|
||||||
.Distinct()
|
|
||||||
.OrderBy(cp => cp.Name)
|
|
||||||
.ToImmutableArray();
|
|
||||||
var packageSelectionList = GUIUtil.Dropdown<ContentPackage>(layoutGroup, cp => cp.Name, null,
|
|
||||||
packages, packages.Length > 0 ? packages[0] : null, cp =>
|
|
||||||
{
|
{
|
||||||
_selectedContentPackage = cp;
|
_selectedContentPackage = cp == ContentPackageManager.VanillaCorePackage ? null : cp;
|
||||||
_selectedCategory = string.Empty;
|
_selectedCategory = string.Empty;
|
||||||
GenerateCategoryListDisplay(_modCategoryDisplayGroup, GetDisplayCategoriesList());
|
GenerateCategoryListDisplay(_modCategoryDisplayGroup, GetTargetPackagesList(), GetDisplayCategoriesList());
|
||||||
GenerateSettingsListDisplay(_settingsDisplayGroup, GetDisplaySettingsList());
|
GenerateSettingsListDisplay(_settingsDisplayGroup, GetDisplaySettingsList());
|
||||||
}, new Vector2(1f, 0.07f));
|
}, new Vector2(1f, 0.07f));
|
||||||
var containerBox = new GUIListBox(new RectTransform(new Vector2(1f, 0.93f), layoutGroup.RectTransform));
|
var containerBox = new GUIListBox(new RectTransform(new Vector2(1f, 0.93f), layoutGroup.RectTransform));
|
||||||
float size_y = MathF.Max(categoryIdents.Length * 0.122f, 1f);
|
float size_y = MathF.Max(categories.Length * 0.122f, 1f);
|
||||||
var displayedCategoriesFrame = new GUIFrame(new RectTransform(new Vector2(1f, size_y), containerBox.Content.RectTransform), style: null, color: Color.Black)
|
var displayedCategoriesFrame = new GUIFrame(new RectTransform(new Vector2(1f, size_y), containerBox.Content.RectTransform), style: null, color: Color.Black)
|
||||||
{
|
{
|
||||||
CanBeFocused = false
|
CanBeFocused = false
|
||||||
};
|
};
|
||||||
var displayCategoriesLayout = new GUILayoutGroup(new RectTransform(Vector2.One, displayedCategoriesFrame.RectTransform));
|
var displayCategoriesLayout = new GUILayoutGroup(new RectTransform(Vector2.One, displayedCategoriesFrame.RectTransform));
|
||||||
|
|
||||||
foreach (var category in categoryIdents)
|
foreach (var category in categories)
|
||||||
{
|
{
|
||||||
DebugConsole.Log(category);
|
DebugConsole.Log(category);
|
||||||
new GUIButton(new RectTransform(new Vector2(1f, 0.122f), displayCategoriesLayout.RectTransform), text: TextManager.Get(category))
|
var btn = new GUIButton(new RectTransform(new Vector2(1f, 0.122f), displayCategoriesLayout.RectTransform),
|
||||||
|
text: category, color: Color.TransparentBlack)
|
||||||
{
|
{
|
||||||
CanBeFocused = true,
|
CanBeFocused = true,
|
||||||
CanBeSelected = true,
|
CanBeSelected = true,
|
||||||
|
TextColor = Color.PeachPuff,
|
||||||
|
HoverColor = new Color(50, 50, 50, 255),
|
||||||
|
HoverTextColor = Color.White,
|
||||||
|
SelectedColor = new Color(50, 50, 50, 255),
|
||||||
|
SelectedTextColor = Color.White,
|
||||||
OnPressed = () =>
|
OnPressed = () =>
|
||||||
{
|
{
|
||||||
_selectedCategory = category;
|
_selectedCategory = category;
|
||||||
@@ -124,8 +181,6 @@ internal sealed class ModsGameplaySettingsMenu : ModsSettingsMenu
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GenerateSettingsListDisplay(GUILayoutGroup layoutGroup, ImmutableArray<ISettingBase> settings)
|
void GenerateSettingsListDisplay(GUILayoutGroup layoutGroup, ImmutableArray<ISettingBase> settings)
|
||||||
+2
-2
@@ -4,14 +4,14 @@ using Microsoft.Xna.Framework;
|
|||||||
|
|
||||||
namespace Barotrauma.LuaCs;
|
namespace Barotrauma.LuaCs;
|
||||||
|
|
||||||
internal abstract class ModsSettingsMenu : IDisposable
|
internal abstract class ModsSettingsMenuBase : IDisposable
|
||||||
{
|
{
|
||||||
public GUIFrame ContentFrame { get; private set; }
|
public GUIFrame ContentFrame { get; private set; }
|
||||||
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 ModsSettingsMenu(GUIFrame contentFrame,
|
protected ModsSettingsMenuBase(GUIFrame contentFrame,
|
||||||
IPackageManagementService packageManagementService,
|
IPackageManagementService packageManagementService,
|
||||||
IConfigService configService, SettingsMenu settingsMenuInstance)
|
IConfigService configService, SettingsMenu settingsMenuInstance)
|
||||||
{
|
{
|
||||||
+1
-1
@@ -42,7 +42,7 @@ public class SettingsMenuSystem : ISettingsMenuSystem
|
|||||||
var gameplayContentFrame = CreateNewContentTab(tabGameplayIndex, __instance,
|
var gameplayContentFrame = CreateNewContentTab(tabGameplayIndex, __instance,
|
||||||
"SettingsMenuTab.Mods", "LuaCsForBarotrauma.SettingsMenu.ModGameplayButton");
|
"SettingsMenuTab.Mods", "LuaCsForBarotrauma.SettingsMenu.ModGameplayButton");
|
||||||
var controlsContentFrame = CreateNewContentTab(tabControlsIndex, __instance,
|
var controlsContentFrame = CreateNewContentTab(tabControlsIndex, __instance,
|
||||||
"SettingsMenuTab.Mods", "LuaCsForBarotrauma.SettingsMenu.ModControlsButton");
|
"SettingsMenuTab.Controls", "LuaCsForBarotrauma.SettingsMenu.ModControlsButton");
|
||||||
|
|
||||||
_gameplayMenuInstance = new ModsGameplaySettingsMenu(gameplayContentFrame, _packageManagementService, _configService, __instance);
|
_gameplayMenuInstance = new ModsGameplaySettingsMenu(gameplayContentFrame, _packageManagementService, _configService, __instance);
|
||||||
_controlsMenuInstance = new ModsControlsSettingsMenu(controlsContentFrame, _packageManagementService, _configService, __instance);
|
_controlsMenuInstance = new ModsControlsSettingsMenu(controlsContentFrame, _packageManagementService, _configService, __instance);
|
||||||
@@ -26,6 +26,7 @@ public interface ISettingBase : IDataInfo, IEquatable<ISettingBase>, IDisposable
|
|||||||
T CreateInstance([NotNull]IConfigInfo configInfo, Func<OneOf<string, XElement, object>, bool> valueChangePredicate);
|
T CreateInstance([NotNull]IConfigInfo configInfo, Func<OneOf<string, XElement, object>, bool> valueChangePredicate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IConfigInfo GetConfigInfo();
|
||||||
#if CLIENT
|
#if CLIENT
|
||||||
IConfigDisplayInfo GetDisplayInfo();
|
IConfigDisplayInfo GetDisplayInfo();
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ public abstract class SettingBase : ISettingBase
|
|||||||
public string InternalName => ConfigInfo.InternalName;
|
public string InternalName => ConfigInfo.InternalName;
|
||||||
public ContentPackage OwnerPackage => ConfigInfo.OwnerPackage;
|
public ContentPackage OwnerPackage => ConfigInfo.OwnerPackage;
|
||||||
|
|
||||||
|
public IConfigInfo GetConfigInfo() => ConfigInfo;
|
||||||
#if CLIENT
|
#if CLIENT
|
||||||
public IConfigDisplayInfo GetDisplayInfo() => ConfigInfo;
|
public IConfigDisplayInfo GetDisplayInfo() => ConfigInfo;
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ public sealed partial class ConfigService : IConfigService
|
|||||||
_configInfoParserService = null;
|
_configInfoParserService = null;
|
||||||
_configProfileInfoParserService = null;
|
_configProfileInfoParserService = null;
|
||||||
_commandsService = null;
|
_commandsService = null;
|
||||||
|
_infoProvider = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FluentResults.Result Reset()
|
public FluentResults.Result Reset()
|
||||||
@@ -140,6 +141,7 @@ public sealed partial class ConfigService : IConfigService
|
|||||||
private ILoggerService _logger;
|
private ILoggerService _logger;
|
||||||
private IEventService _eventService;
|
private IEventService _eventService;
|
||||||
private IConsoleCommandsService _commandsService;
|
private IConsoleCommandsService _commandsService;
|
||||||
|
private ILuaCsInfoProvider _infoProvider;
|
||||||
private IParserServiceOneToManyAsync<IConfigResourceInfo, IConfigInfo> _configInfoParserService;
|
private IParserServiceOneToManyAsync<IConfigResourceInfo, IConfigInfo> _configInfoParserService;
|
||||||
private IParserServiceOneToManyAsync<IConfigResourceInfo, IConfigProfileInfo> _configProfileInfoParserService;
|
private IParserServiceOneToManyAsync<IConfigResourceInfo, IConfigProfileInfo> _configProfileInfoParserService;
|
||||||
|
|
||||||
@@ -148,7 +150,8 @@ public sealed partial class ConfigService : IConfigService
|
|||||||
IParserServiceOneToManyAsync<IConfigResourceInfo, IConfigInfo> configInfoParserService,
|
IParserServiceOneToManyAsync<IConfigResourceInfo, IConfigInfo> configInfoParserService,
|
||||||
IParserServiceOneToManyAsync<IConfigResourceInfo, IConfigProfileInfo> configProfileInfoParserService,
|
IParserServiceOneToManyAsync<IConfigResourceInfo, IConfigProfileInfo> configProfileInfoParserService,
|
||||||
IEventService eventService,
|
IEventService eventService,
|
||||||
IConsoleCommandsService commandsService)
|
IConsoleCommandsService commandsService,
|
||||||
|
ILuaCsInfoProvider infoProvider)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_storageService = storageService;
|
_storageService = storageService;
|
||||||
@@ -156,6 +159,7 @@ public sealed partial class ConfigService : IConfigService
|
|||||||
_configProfileInfoParserService = configProfileInfoParserService;
|
_configProfileInfoParserService = configProfileInfoParserService;
|
||||||
_eventService = eventService;
|
_eventService = eventService;
|
||||||
_commandsService = commandsService;
|
_commandsService = commandsService;
|
||||||
|
_infoProvider = infoProvider;
|
||||||
|
|
||||||
_storageService.UseCaching = true;
|
_storageService.UseCaching = true;
|
||||||
InjectCommands(commandsService);
|
InjectCommands(commandsService);
|
||||||
|
|||||||
Reference in New Issue
Block a user