- Fixed shet.
This commit is contained in:
@@ -3,15 +3,27 @@ using System.Globalization;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
using Barotrauma.LuaCs.Data;
|
using Barotrauma.LuaCs.Data;
|
||||||
|
using Microsoft.Toolkit.Diagnostics;
|
||||||
using Microsoft.Xna.Framework.Input;
|
using Microsoft.Xna.Framework.Input;
|
||||||
using OneOf;
|
using OneOf;
|
||||||
|
|
||||||
namespace Barotrauma.LuaCs.Data;
|
namespace Barotrauma.LuaCs.Data;
|
||||||
|
|
||||||
public class SettingControl : SettingBase, ISettingControl
|
public sealed class SettingControl : SettingBase, ISettingControl
|
||||||
{
|
{
|
||||||
public SettingControl(IConfigInfo configInfo) : base(configInfo)
|
public class Factory : ISettingBase.IFactory<ISettingBase>
|
||||||
{
|
{
|
||||||
|
public ISettingBase CreateInstance(IConfigInfo configInfo, Func<OneOf<string, XElement, object>, bool> valueChangePredicate)
|
||||||
|
{
|
||||||
|
Guard.IsNotNull(configInfo, nameof(configInfo));
|
||||||
|
return new SettingControl(configInfo, valueChangePredicate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public SettingControl(IConfigInfo configInfo, Func<OneOf<string, XElement, object>, bool> valueChangePredicate) : base(configInfo)
|
||||||
|
{
|
||||||
|
_valueChangePredicate = valueChangePredicate;
|
||||||
|
TrySetValue(configInfo.Element);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnDispose()
|
protected override void OnDispose()
|
||||||
@@ -19,9 +31,9 @@ public class SettingControl : SettingBase, ISettingControl
|
|||||||
OnValueChanged = null;
|
OnValueChanged = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Func<OneOf<string, XElement, object>, bool> _valueChangePredicate;
|
||||||
public override Type GetValueType() => typeof(KeyOrMouse);
|
public override Type GetValueType() => typeof(KeyOrMouse);
|
||||||
public override string GetStringValue() => Value.ToString();
|
public override string GetStringValue() => Value.ToString();
|
||||||
|
|
||||||
public override string GetDefaultStringValue() => new KeyOrMouse(Keys.NumLock).ToString();
|
public override string GetDefaultStringValue() => new KeyOrMouse(Keys.NumLock).ToString();
|
||||||
|
|
||||||
public override bool TrySetValue(OneOf<string, XElement> value)
|
public override bool TrySetValue(OneOf<string, XElement> value)
|
||||||
@@ -35,6 +47,11 @@ public class SettingControl : SettingBase, ISettingControl
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_valueChangePredicate is not null && !_valueChangePredicate.Invoke(newVal))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
Value = newVal;
|
Value = newVal;
|
||||||
OnValueChanged?.Invoke(this);
|
OnValueChanged?.Invoke(this);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
+4
-3
@@ -6,6 +6,7 @@ using System.Linq;
|
|||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using Barotrauma.LuaCs.Data;
|
using Barotrauma.LuaCs.Data;
|
||||||
using Vector2 = Microsoft.Xna.Framework.Vector2;
|
using Vector2 = Microsoft.Xna.Framework.Vector2;
|
||||||
|
using Vector4 = Microsoft.Xna.Framework.Vector4;
|
||||||
|
|
||||||
// ReSharper disable ObjectCreationAsStatement
|
// ReSharper disable ObjectCreationAsStatement
|
||||||
|
|
||||||
@@ -28,7 +29,6 @@ internal sealed class ModsGameplaySettingsMenu : ModsSettingsMenuBase
|
|||||||
SettingsMenu settingsMenuInstance) : base(contentFrame, packageManagementService, configService, settingsMenuInstance)
|
SettingsMenu settingsMenuInstance) : base(contentFrame, packageManagementService, configService, settingsMenuInstance)
|
||||||
{
|
{
|
||||||
_settingsInstancesGameplay = configService.GetDisplayableConfigs()
|
_settingsInstancesGameplay = configService.GetDisplayableConfigs()
|
||||||
.Where(s => s is not ISettingControl)
|
|
||||||
.ToImmutableArray();
|
.ToImmutableArray();
|
||||||
|
|
||||||
|
|
||||||
@@ -69,7 +69,6 @@ internal sealed class ModsGameplaySettingsMenu : ModsSettingsMenuBase
|
|||||||
OnApplyInstalledModsChanges = () =>
|
OnApplyInstalledModsChanges = () =>
|
||||||
{
|
{
|
||||||
_settingsInstancesGameplay = configService.GetDisplayableConfigs()
|
_settingsInstancesGameplay = configService.GetDisplayableConfigs()
|
||||||
.Where(s => s is not ISettingControl)
|
|
||||||
.ToImmutableArray();
|
.ToImmutableArray();
|
||||||
if (_selectedContentPackage is not null && !GetTargetPackagesList().Contains(_selectedContentPackage))
|
if (_selectedContentPackage is not null && !GetTargetPackagesList().Contains(_selectedContentPackage))
|
||||||
{
|
{
|
||||||
@@ -128,6 +127,7 @@ internal sealed class ModsGameplaySettingsMenu : ModsSettingsMenuBase
|
|||||||
.Where(s => _selectedCategory.IsNullOrWhiteSpace()
|
.Where(s => _selectedCategory.IsNullOrWhiteSpace()
|
||||||
|| _selectedCategory == "All"
|
|| _selectedCategory == "All"
|
||||||
|| GetLocalizedString(s.GetDisplayInfo().DisplayCategory, "General") == _selectedCategory)
|
|| GetLocalizedString(s.GetDisplayInfo().DisplayCategory, "General") == _selectedCategory)
|
||||||
|
.OrderBy(s => GetLocalizedString(s.GetDisplayInfo().DisplayName, s.InternalName))
|
||||||
.ToImmutableArray();
|
.ToImmutableArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,6 +139,7 @@ internal sealed class ModsGameplaySettingsMenu : ModsSettingsMenuBase
|
|||||||
.Where(s => _selectedContentPackage is null
|
.Where(s => _selectedContentPackage is null
|
||||||
|| _selectedContentPackage == ContentPackageManager.VanillaCorePackage // vanilla is treated as all packages
|
|| _selectedContentPackage == ContentPackageManager.VanillaCorePackage // vanilla is treated as all packages
|
||||||
|| s.OwnerPackage == _selectedContentPackage)
|
|| s.OwnerPackage == _selectedContentPackage)
|
||||||
|
.OrderBy(s => GetLocalizedString(s.GetDisplayInfo().DisplayName, s.InternalName))
|
||||||
.ToImmutableArray();
|
.ToImmutableArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,7 +213,6 @@ internal sealed class ModsGameplaySettingsMenu : ModsSettingsMenuBase
|
|||||||
|
|
||||||
foreach (var category in categories)
|
foreach (var category in categories)
|
||||||
{
|
{
|
||||||
DebugConsole.Log(category);
|
|
||||||
var btn = new GUIButton(new RectTransform(new Vector2(1f, 0.122f), displayCategoriesLayout.RectTransform),
|
var btn = new GUIButton(new RectTransform(new Vector2(1f, 0.122f), displayCategoriesLayout.RectTransform),
|
||||||
text: category, color: Color.TransparentBlack)
|
text: category, color: Color.TransparentBlack)
|
||||||
{
|
{
|
||||||
@@ -264,6 +264,7 @@ internal sealed class ModsGameplaySettingsMenu : ModsSettingsMenuBase
|
|||||||
font: GUIStyle.SmallFont,
|
font: GUIStyle.SmallFont,
|
||||||
textAlignment: Alignment.Left)
|
textAlignment: Alignment.Left)
|
||||||
{
|
{
|
||||||
|
Padding = new Vector4(0.02f,0,0,0),
|
||||||
CanBeFocused = false
|
CanBeFocused = false
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -45,11 +45,12 @@ public class SettingsMenuSystem : ISettingsMenuSystem
|
|||||||
|
|
||||||
_gameplayContentFrame = CreateNewContentTab(tabGameplayIndex, __instance,
|
_gameplayContentFrame = CreateNewContentTab(tabGameplayIndex, __instance,
|
||||||
"SettingsMenuTab.Mods", "LuaCsForBarotrauma.SettingsMenu.ModGameplayButton");
|
"SettingsMenuTab.Mods", "LuaCsForBarotrauma.SettingsMenu.ModGameplayButton");
|
||||||
_controlsContentFrame = CreateNewContentTab(tabControlsIndex, __instance,
|
/*_controlsContentFrame = CreateNewContentTab(tabControlsIndex, __instance,
|
||||||
"SettingsMenuTab.Controls", "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);
|
||||||
}
|
}
|
||||||
|
|
||||||
private GUIFrame CreateNewContentTab(SettingsMenu.Tab tab, SettingsMenu settingsMenuInstance, string settingsMenuTabName, string settingMenuHoverTextIdent)
|
private GUIFrame CreateNewContentTab(SettingsMenu.Tab tab, SettingsMenu settingsMenuInstance, string settingsMenuTabName, string settingMenuHoverTextIdent)
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
<Setting Name="TestRangeFloat" Type="rangeFloat" Min="0" Max="25" Steps="11"/>
|
<Setting Name="TestRangeFloat" Type="rangeFloat" Min="0" Max="25" Steps="11"/>
|
||||||
<Setting Name="TestRangeInt" Type="rangeInt" Min="0" Max="10" Steps="11"/>
|
<Setting Name="TestRangeInt" Type="rangeInt" Min="0" Max="10" Steps="11"/>
|
||||||
<Setting Name="TestString" Type="string" />
|
<Setting Name="TestString" Type="string" />
|
||||||
|
<Setting Name="TestControl" Type="control" Value="A"/>
|
||||||
</Settings>
|
</Settings>
|
||||||
<Profiles>
|
<Profiles>
|
||||||
<Profile Name="default">
|
<Profile Name="default">
|
||||||
|
|||||||
+8
-2
@@ -50,8 +50,14 @@ public class SettingsEntryRegistrar : ISettingsRegistrationProvider
|
|||||||
return new SettingRangeFloat.RangeFactory().CreateInstance(cfgInfo.Info, (val) =>
|
return new SettingRangeFloat.RangeFactory().CreateInstance(cfgInfo.Info, (val) =>
|
||||||
IsValueChangeAllowed(cfgInfo.Info, val, valueChangePredicate));
|
IsValueChangeAllowed(cfgInfo.Info, val, valueChangePredicate));
|
||||||
});
|
});
|
||||||
|
|
||||||
// ISettingList : Not Implemented yet
|
#if CLIENT
|
||||||
|
configService.RegisterSettingTypeInitializer("control" , cfgInfo =>
|
||||||
|
{
|
||||||
|
return new SettingControl.Factory().CreateInstance(cfgInfo.Info, val =>
|
||||||
|
IsValueChangeAllowed(cfgInfo.Info, val, valueChangePredicate));
|
||||||
|
});
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RegisterSettingEntry<T>(IConfigService configService, string typeName, Func<OneOf<string, XElement, object>, bool> valueChangePredicate) where T : IEquatable<T>, IConvertible
|
private void RegisterSettingEntry<T>(IConfigService configService, string typeName, Func<OneOf<string, XElement, object>, bool> valueChangePredicate) where T : IEquatable<T>, IConvertible
|
||||||
|
|||||||
Reference in New Issue
Block a user