diff --git a/Luski/Classes/Settings.cs b/Luski/Classes/Settings.cs index 5d4d066..726cdea 100644 --- a/Luski/Classes/Settings.cs +++ b/Luski/Classes/Settings.cs @@ -12,7 +12,13 @@ public class Settings { [JsonInclude] [JsonPropertyName("scale")] - [SettingInfo(SettingGroup.AppSettings, SettingsPage.General)] + [SettingInfo(SettingGroup.AppSettings, SettingsPage.Appearance)] + [Shared.GlobalAttributes.DisplayName("Message Font Size")] + [Description("Sets the px value for the message font size")] + [NumberSelector(typeof(double?))] + [NumberMin(0.25)] + [NumberDefault(1)] + [NumberMax(2)] public double? Scale { get; set; } = null; [JsonInclude] [JsonPropertyName("perscrollpixels")] @@ -93,6 +99,13 @@ public class Settings public uint DefaultFontPX { get; set; } = 20; [JsonInclude] [JsonPropertyName("top_time_font_px")] + [SettingInfo(SettingGroup.AppSettings, SettingsPage.Appearance)] + [Shared.GlobalAttributes.DisplayName("Top Time Font Size")] + [Description("Sets the px value for the top time font size")] + [NumberSelector(typeof(uint))] + [NumberMin(8)] + [NumberDefault(12)] + [NumberMax(20)] public uint TopTimeFontPX { get; set; } = 12; [JsonInclude] [JsonPropertyName("role_settings_font_px")] diff --git a/Luski/GUI/MainScreen/UI/LuskiControls/NumberSelector.cs b/Luski/GUI/MainScreen/UI/LuskiControls/NumberSelector.cs index d79b950..933c9e1 100644 --- a/Luski/GUI/MainScreen/UI/LuskiControls/NumberSelector.cs +++ b/Luski/GUI/MainScreen/UI/LuskiControls/NumberSelector.cs @@ -183,7 +183,7 @@ public class NumberSelector : UserControl where TNumber : INumber + { + prop.SetValue(Globals.Settings, b); + Globals.Settings.SaveSettings(Path.Combine(Globals.LuskiPath, "Settings.json"), SettingsContext.Default.Settings); + }); } } } } - - private void AddSelector(PropertyInfo prop , TNumber val) where TNumber : INumber - { - UserControl space = new(); - space.BackgroundColor = Color4.Blue; - NumberSelector selector = new(); - selector.BackgroundColor = this.BackgroundColor; - space.SetSize(Size.X, selector.Size.Y + 40.ScaleInt()); - selector.SetSize(this.Size.X, 0); - selector.SetLocation(0,40.ScaleInt()); - selector.Min = prop.GetAnyAttribute>().Min; - selector.Max = prop.GetAnyAttribute>().Max; - selector.Default = prop.GetAnyAttribute>().Default; - selector.Value = val; - selector.Anchor = ObjectAnchor.All; - space.Controls.Add(selector); - Controls.Add(space); - } } \ No newline at end of file diff --git a/Luski/Globals.cs b/Luski/Globals.cs index 027aa34..81dfd56 100644 --- a/Luski/Globals.cs +++ b/Luski/Globals.cs @@ -319,7 +319,7 @@ public static class Globals public static UserControl AddNumberSlider(IParent parent, string Name, string description, TNumber defaul, TNumber min, TNumber val, TNumber max, Action a) where TNumber : INumber { - NumberSelector ts = new() + NumberSelector NumberSelector = new() { Default = defaul, Min = min, @@ -348,24 +348,105 @@ public static class Globals Text = description }); tc.Size = l.Size; - tc.Controls.Add(ts); - ts.Location = new(5.ScaleInt(), l.Location.Y + l.Size.Y + space, 0); + tc.Controls.Add(NumberSelector); + NumberSelector.Location = new(5.ScaleInt(), l.Location.Y + l.Size.Y + space, 0); Rectangle TempLine = new() { - Location = new(0, ts.Location.Y + ts.Size.Y + space, 0), + Location = new(0, NumberSelector.Location.Y + NumberSelector.Size.Y + space, 0), BackgroundColor = Color4.White, Anchor = ObjectAnchor.Left | ObjectAnchor.Right | ObjectAnchor.Top }; l.Tag = TempLine; TempLine.Size = new(parent.Size.X - space - space, 2.ScaleInt()); tc.SetSize(parent.Size.X, TempLine.Location.Y + TempLine.Size.Y); - ts.SetSize(TempLine.Size.X - 10.ScaleInt(), 0); - ts.SetLocation(TempLine.Location.X, ts.Location.Y); - ts.ForceDistanceUpdate(tc); + NumberSelector.SetSize(TempLine.Size.X, 0); + NumberSelector.SetLocation(TempLine.Location.X, NumberSelector.Location.Y); + NumberSelector.ForceDistanceUpdate(tc); TempLine.ForceDistanceUpdate(tc); tc.Controls.Add(TempLine); + NumberSelector.ValueChanged += @switch => + { + a.Invoke(@switch.Value); + return Task.CompletedTask; + }; + tc.ForceDistanceUpdate(parent); + parent.Controls.Add(tc); + return tc; + } + + public static UserControl AddNullNumberSlider(IParent parent, string Name, string description, TNumber defaul, TNumber min, TNumber? val, TNumber max, Action a) where TNumber : struct, INumber + { + TNumber v = defaul; + if (val is not null) v = val.Value; + ToggleSwitch ts = new() + { + Value = val is not null, + Anchor = ObjectAnchor.Top | ObjectAnchor.Right + }; + NumberSelector NumberSelector = new() + { + Default = defaul, + Min = min, + Max = max, + Value = v, + Anchor = ObjectAnchor.Top | ObjectAnchor.Right | ObjectAnchor.Left, + BackgroundColor = new(0,0,0,0), + Space = 10.ScaleInt() + }; + UserControl tc = new() + { + BackgroundColor = new(0,0,0,0) + }; + Label l, ll; + int space = 5.ScaleInt(); + tc.Controls.Add(ll =new Label(Globals.DefaultFont) + { + Location = new(0, space + space, 0), + Text = Name + }); + tc.Controls.Add(l =new Label(Globals.DefaultFont) + { + Location = new(ll.Location.X, ll.Size.Y + space, 0), + Color = Color4.Gray, + MaxSize = parent.Size, + Text = description + }); + tc.Size = l.Size; + tc.Controls.Add(ts); + ts.Location = new(parent.Size.X - ts.Size.X - 5.ScaleInt(), ll.Location.Y, 0); + tc.Controls.Add(NumberSelector); + NumberSelector.Location = new(5.ScaleInt(), l.Location.Y + l.Size.Y + space, 0); + + Rectangle TempLine = new() + { + Location = new(0, NumberSelector.Location.Y + NumberSelector.Size.Y + space, 0), + BackgroundColor = Color4.White, + Anchor = ObjectAnchor.Left | ObjectAnchor.Right | ObjectAnchor.Top + }; + l.Tag = TempLine; + TempLine.Size = new(parent.Size.X - space - space, 2.ScaleInt()); + tc.SetSize(parent.Size.X, TempLine.Location.Y + TempLine.Size.Y); + NumberSelector.SetSize(TempLine.Size.X, 0); + NumberSelector.SetLocation(TempLine.Location.X, NumberSelector.Location.Y); + NumberSelector.ForceDistanceUpdate(tc); + TempLine.ForceDistanceUpdate(tc); + tc.Controls.Add(TempLine); + ts.ForceDistanceUpdate(tc); ts.ValueChanged += @switch => + { + if (@switch.Value) + { + a.Invoke(defaul); + } + else + { + NumberSelector.Value = defaul; + a.Invoke(null); + } + return Task.CompletedTask; + }; + NumberSelector.ValueChanged += @switch => { a.Invoke(@switch.Value); return Task.CompletedTask; @@ -412,7 +493,20 @@ public static class Globals t.GetCustomAttributes(typeof(Luski.Shared.GlobalAttributes.DisplayNameAttribute), false); if (namevalueAttributes.Length == 0) return; string Name = ((Luski.Shared.GlobalAttributes.DisplayNameAttribute)namevalueAttributes[0]).DisplayName; - AddNumberSlider(parent, Name, description, t.GetAnyAttribute>().Default, t.GetAnyAttribute>().Min, s, t.GetAnyAttribute>().Max,a); + _ = AddNumberSlider(parent, Name, description, t.GetAnyAttribute>().Default, t.GetAnyAttribute>().Min, s, t.GetAnyAttribute>().Max,a); + } + + public static void AddNullNumberSlider(IParent parent, PropertyInfo t, TNumber? s, Action a) where TNumber : struct, INumber + { + object[] valueAttributes = + t.GetCustomAttributes(typeof(DescriptionAttribute), false); + if (valueAttributes.Length == 0) return; + string description = ((DescriptionAttribute)valueAttributes[0]).Description; + object[] namevalueAttributes = + t.GetCustomAttributes(typeof(Luski.Shared.GlobalAttributes.DisplayNameAttribute), false); + if (namevalueAttributes.Length == 0) return; + string Name = ((Luski.Shared.GlobalAttributes.DisplayNameAttribute)namevalueAttributes[0]).DisplayName; + _ = AddNullNumberSlider(parent, Name, description, t.GetAnyAttribute>().Default, t.GetAnyAttribute>().Min, s, t.GetAnyAttribute>().Max,a); } public static TAttribute GetAnyAttribute(this PropertyInfo t) diff --git a/Luski/Program.cs b/Luski/Program.cs index 0e753a0..9648c54 100644 --- a/Luski/Program.cs +++ b/Luski/Program.cs @@ -1,12 +1,7 @@ using System.Diagnostics; -using GraphicsManager; -using GraphicsManager.Enums; -using GraphicsManager.Objects.Core; using Luski; using Luski.Classes; using Luski.GUI; -using Luski.GUI.MainScreen.UI.LuskiControls; -using OpenTK.Mathematics; using OpenTK.Windowing.Common.Input; using SixLabors.ImageSharp; using SixLabors.ImageSharp.PixelFormats;