The gameplay settings menu kinda works (only for luacsforbarotrauma).

This commit is contained in:
MapleWheels
2026-03-04 20:39:13 -05:00
parent ce8b984542
commit f38a7bd574
16 changed files with 182 additions and 16 deletions
@@ -8,7 +8,7 @@ using Barotrauma.Networking;
namespace Barotrauma.LuaCs.Data;
public interface ISettingBase : IDataInfo, IEquatable<ISettingBase>, IDisposable
public partial interface ISettingBase : IDataInfo, IEquatable<ISettingBase>, IDisposable
{
/// <summary>
/// Settings production factory. Should be implemented by all types and registered with the Dependency Injector.
@@ -1,6 +1,7 @@
using System;
using System.Xml.Linq;
using Barotrauma.LuaCs.Data;
using Microsoft.Xna.Framework;
using OneOf;
namespace Barotrauma.LuaCs.Data;
@@ -60,4 +61,17 @@ public abstract class SettingBase : ISettingBase
public abstract bool TrySetValue(OneOf<string, XElement> value);
public abstract event Action<ISettingBase> OnValueChanged;
public abstract OneOf<string, XElement> GetSerializableValue();
#if CLIENT
public virtual void AddDisplayComponent(GUILayoutGroup layoutGroup, Vector2 relativeSize, Action<string> onSerializedValue)
{
new GUITextBox(new RectTransform(relativeSize, layoutGroup.RectTransform), font: GUIStyle.SmallFont)
{
OnEnterPressed = (box, txt) =>
{
onSerializedValue?.Invoke(txt);
return true;
}
};
}
#endif
}
@@ -5,11 +5,12 @@ using Barotrauma.LuaCs.Data;
using Barotrauma.LuaCs;
using Barotrauma.Networking;
using Microsoft.Toolkit.Diagnostics;
using Microsoft.Xna.Framework;
using OneOf;
namespace Barotrauma.LuaCs.Data;
public class SettingEntry<T> : SettingBase, ISettingBase<T>, INetworkSyncVar where T : IEquatable<T>, IConvertible
public partial class SettingEntry<T> : SettingBase, ISettingBase<T>, INetworkSyncVar where T : IEquatable<T>, IConvertible
{
public class Factory : ISettingBase.IFactory<ISettingBase<T>>
{
@@ -302,4 +303,57 @@ public class SettingEntry<T> : SettingBase, ISettingBase<T>, INetworkSyncVar whe
#endif
}
}
#if CLIENT
public override void AddDisplayComponent(GUILayoutGroup layoutGroup, Vector2 relativeSize, Action<string> onSerializedValue)
{
switch (Type.GetTypeCode(typeof(T)))
{
case TypeCode.Boolean:
new GUITickBox(new RectTransform(relativeSize, layoutGroup.RectTransform), "")
{
Selected = (bool)Convert.ChangeType(this.Value, TypeCode.Boolean),
OnSelected = (box) =>
{
onSerializedValue?.Invoke(box.Selected.ToString());
return true;
}
};
break;
case TypeCode.Byte:
case TypeCode.SByte:
case TypeCode.Int16:
case TypeCode.Char:
case TypeCode.UInt16:
case TypeCode.Int32:
case TypeCode.UInt32:
case TypeCode.Int64:
case TypeCode.UInt64:
new GUINumberInput(new RectTransform(relativeSize, layoutGroup.RectTransform), NumberType.Int)
{
IntValue = (int)Convert.ChangeType(this.Value, TypeCode.Int32)!,
OnValueChanged = (num) =>
{
onSerializedValue?.Invoke(num.IntValue.ToString());
}
};
break;
case TypeCode.Single:
case TypeCode.Double:
new GUINumberInput(new RectTransform(relativeSize, layoutGroup.RectTransform), NumberType.Float)
{
FloatValue = (float)Convert.ChangeType(this.Value, TypeCode.Single)!,
OnValueChanged = (num) =>
{
onSerializedValue?.Invoke(num.FloatValue.ToString());
}
};
break;
case TypeCode.String:
default:
base.AddDisplayComponent(layoutGroup, relativeSize, onSerializedValue);
break;
}
}
#endif
}
@@ -75,7 +75,7 @@ public sealed class SettingsFileParserService :
continue;
}
var packageIdent = res.path.ContentPackage.ToIdentifier().ToString();
var packageIdent = res.path.ContentPackage!.Name;
foreach (var element in settingElements)
{