More settings

Some settings can now be represented as a number slider.
Floating point values have lag but work.
This commit is contained in:
JacobTech 2024-09-28 19:56:54 -04:00
parent bd5405866b
commit 0b2bfe1635
6 changed files with 127 additions and 35 deletions

View File

@ -12,7 +12,13 @@ public class Settings
{ {
[JsonInclude] [JsonInclude]
[JsonPropertyName("scale")] [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<double>(0.25)]
[NumberDefault<double>(1)]
[NumberMax<double>(2)]
public double? Scale { get; set; } = null; public double? Scale { get; set; } = null;
[JsonInclude] [JsonInclude]
[JsonPropertyName("perscrollpixels")] [JsonPropertyName("perscrollpixels")]
@ -93,6 +99,13 @@ public class Settings
public uint DefaultFontPX { get; set; } = 20; public uint DefaultFontPX { get; set; } = 20;
[JsonInclude] [JsonInclude]
[JsonPropertyName("top_time_font_px")] [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<uint>(8)]
[NumberDefault<uint>(12)]
[NumberMax<uint>(20)]
public uint TopTimeFontPX { get; set; } = 12; public uint TopTimeFontPX { get; set; } = 12;
[JsonInclude] [JsonInclude]
[JsonPropertyName("role_settings_font_px")] [JsonPropertyName("role_settings_font_px")]

View File

@ -183,7 +183,7 @@ public class NumberSelector<TNumber> : UserControl where TNumber : INumber<TNumb
public override void SetSize(int w, int h) public override void SetSize(int w, int h)
{ {
base.SetSize(w, 50.ScaleInt()); base.SetSize(w, 50.ScaleInt());
progressBar.SetSize(w, 8.ScaleInt()); progressBar.SetSize(w - space - space, 8.ScaleInt());
progressBar.UpdateProgress(); progressBar.UpdateProgress();
progressBar.ForceDistanceUpdate(this); progressBar.ForceDistanceUpdate(this);
Min = Min; Min = Min;

View File

@ -28,7 +28,6 @@ public class UserView : UserControl
{ {
name = $"[gradient colors=\"{r.Colors.ToDB()}\"]{name}[/gradient]"; name = $"[gradient colors=\"{r.Colors.ToDB()}\"]{name}[/gradient]";
} }
Console.WriteLine(name);
LuskiLabel uname = new(Globals.DefaultFont) LuskiLabel uname = new(Globals.DefaultFont)
{ {

View File

@ -77,27 +77,18 @@ public class Generic : PageFlow
prop.SetValue(Globals.Settings, b); prop.SetValue(Globals.Settings, b);
Globals.Settings.SaveSettings(Path.Combine(Globals.LuskiPath, "Settings.json"), SettingsContext.Default.Settings); Globals.Settings.SaveSettings(Path.Combine(Globals.LuskiPath, "Settings.json"), SettingsContext.Default.Settings);
}); });
//AddSelector(prop, (uint)PropVal);
}
}
}
} }
private void AddSelector<TNumber>(PropertyInfo prop , TNumber val) where TNumber : INumber<TNumber> if (typeinfo.Kind.FullName == typeof(double?).FullName)
{ {
UserControl space = new(); double? pv = (double?)PropVal;
space.BackgroundColor = Color4.Blue; Globals.AddNullNumberSlider(this, prop, pv, b =>
NumberSelector<TNumber> selector = new(); {
selector.BackgroundColor = this.BackgroundColor; prop.SetValue(Globals.Settings, b);
space.SetSize(Size.X, selector.Size.Y + 40.ScaleInt()); Globals.Settings.SaveSettings(Path.Combine(Globals.LuskiPath, "Settings.json"), SettingsContext.Default.Settings);
selector.SetSize(this.Size.X, 0); });
selector.SetLocation(0,40.ScaleInt()); }
selector.Min = prop.GetAnyAttribute<NumberMin<TNumber>>().Min; }
selector.Max = prop.GetAnyAttribute<NumberMax<TNumber>>().Max; }
selector.Default = prop.GetAnyAttribute<NumberDefault<TNumber>>().Default;
selector.Value = val;
selector.Anchor = ObjectAnchor.All;
space.Controls.Add(selector);
Controls.Add(space);
} }
} }

View File

@ -319,7 +319,7 @@ public static class Globals
public static UserControl AddNumberSlider<TNumber>(IParent parent, string Name, string description, TNumber defaul, TNumber min, TNumber val, TNumber max, Action<TNumber> a) where TNumber : INumber<TNumber> public static UserControl AddNumberSlider<TNumber>(IParent parent, string Name, string description, TNumber defaul, TNumber min, TNumber val, TNumber max, Action<TNumber> a) where TNumber : INumber<TNumber>
{ {
NumberSelector<TNumber> ts = new() NumberSelector<TNumber> NumberSelector = new()
{ {
Default = defaul, Default = defaul,
Min = min, Min = min,
@ -348,24 +348,105 @@ public static class Globals
Text = description Text = description
}); });
tc.Size = l.Size; tc.Size = l.Size;
tc.Controls.Add(ts); tc.Controls.Add(NumberSelector);
ts.Location = new(5.ScaleInt(), l.Location.Y + l.Size.Y + space, 0); NumberSelector.Location = new(5.ScaleInt(), l.Location.Y + l.Size.Y + space, 0);
Rectangle TempLine = new() 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, BackgroundColor = Color4.White,
Anchor = ObjectAnchor.Left | ObjectAnchor.Right | ObjectAnchor.Top Anchor = ObjectAnchor.Left | ObjectAnchor.Right | ObjectAnchor.Top
}; };
l.Tag = TempLine; l.Tag = TempLine;
TempLine.Size = new(parent.Size.X - space - space, 2.ScaleInt()); TempLine.Size = new(parent.Size.X - space - space, 2.ScaleInt());
tc.SetSize(parent.Size.X, TempLine.Location.Y + TempLine.Size.Y); tc.SetSize(parent.Size.X, TempLine.Location.Y + TempLine.Size.Y);
ts.SetSize(TempLine.Size.X - 10.ScaleInt(), 0); NumberSelector.SetSize(TempLine.Size.X, 0);
ts.SetLocation(TempLine.Location.X, ts.Location.Y); NumberSelector.SetLocation(TempLine.Location.X, NumberSelector.Location.Y);
ts.ForceDistanceUpdate(tc); NumberSelector.ForceDistanceUpdate(tc);
TempLine.ForceDistanceUpdate(tc); TempLine.ForceDistanceUpdate(tc);
tc.Controls.Add(TempLine); 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<TNumber>(IParent parent, string Name, string description, TNumber defaul, TNumber min, TNumber? val, TNumber max, Action<TNumber?> a) where TNumber : struct, INumber<TNumber>
{
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<TNumber> 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 => 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); a.Invoke(@switch.Value);
return Task.CompletedTask; return Task.CompletedTask;
@ -412,7 +493,20 @@ public static class Globals
t.GetCustomAttributes(typeof(Luski.Shared.GlobalAttributes.DisplayNameAttribute), false); t.GetCustomAttributes(typeof(Luski.Shared.GlobalAttributes.DisplayNameAttribute), false);
if (namevalueAttributes.Length == 0) return; if (namevalueAttributes.Length == 0) return;
string Name = ((Luski.Shared.GlobalAttributes.DisplayNameAttribute)namevalueAttributes[0]).DisplayName; string Name = ((Luski.Shared.GlobalAttributes.DisplayNameAttribute)namevalueAttributes[0]).DisplayName;
AddNumberSlider(parent, Name, description, t.GetAnyAttribute<NumberDefault<TNumber>>().Default, t.GetAnyAttribute<NumberMin<TNumber>>().Min, s, t.GetAnyAttribute<NumberMax<TNumber>>().Max,a); _ = AddNumberSlider(parent, Name, description, t.GetAnyAttribute<NumberDefault<TNumber>>().Default, t.GetAnyAttribute<NumberMin<TNumber>>().Min, s, t.GetAnyAttribute<NumberMax<TNumber>>().Max,a);
}
public static void AddNullNumberSlider<TNumber>(IParent parent, PropertyInfo t, TNumber? s, Action<TNumber?> a) where TNumber : struct, INumber<TNumber>
{
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<NumberDefault<TNumber>>().Default, t.GetAnyAttribute<NumberMin<TNumber>>().Min, s, t.GetAnyAttribute<NumberMax<TNumber>>().Max,a);
} }
public static TAttribute GetAnyAttribute<TAttribute>(this PropertyInfo t) public static TAttribute GetAnyAttribute<TAttribute>(this PropertyInfo t)

View File

@ -1,12 +1,7 @@
using System.Diagnostics; using System.Diagnostics;
using GraphicsManager;
using GraphicsManager.Enums;
using GraphicsManager.Objects.Core;
using Luski; using Luski;
using Luski.Classes; using Luski.Classes;
using Luski.GUI; using Luski.GUI;
using Luski.GUI.MainScreen.UI.LuskiControls;
using OpenTK.Mathematics;
using OpenTK.Windowing.Common.Input; using OpenTK.Windowing.Common.Input;
using SixLabors.ImageSharp; using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;