From 452009675e484da280e5894e8c74c976adc12cf8 Mon Sep 17 00:00:00 2001 From: JacobTech Date: Thu, 11 Apr 2024 15:44:12 -0400 Subject: [PATCH] Coordinates & Switches MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • The client now uses the new coordinate system. • Added a new control for a toggle switch. --- Luski/Classes/Settings.cs | 71 +++++- Luski/Classes/UpdaterSettings.cs | 12 +- Luski/ConsoleLog.cs | 10 +- Luski/GUI/MainScreen/UI/AccountButton.cs | 2 +- Luski/GUI/MainScreen/UI/AddServerOverlay.cs | 2 +- Luski/GUI/MainScreen/UI/FullScreenMedia.cs | 2 +- .../UI/LuskiControls/ToggleSwitch.cs | 52 +++++ .../MainScreen/UI/PublicServers/AddChannel.cs | 2 +- .../UI/PublicServers/ChatMessage.cs | 52 ++++- .../MainScreen/UI/PublicServers/PublicChat.cs | 67 ++---- Luski/GUI/MainScreen/UI/ServerIcon.cs | 4 +- Luski/GUI/MainScreen/UI/ServerLoginOverlay.cs | 4 +- Luski/GUI/MainScreen/UI/SettingsMenu.cs | 202 ++++++++++++++++-- .../MainScreen/UI/SettingsPanel/Category.cs | 13 ++ .../UI/SettingsPanel/ExperimentGUI.cs | 2 +- Luski/GUI/MainScreenWindow.cs | 42 +++- Luski/Globals.cs | 9 +- Luski/Luski.csproj | 6 +- Luski/LuskiExperiments.cs | 15 -- Luski/Program.cs | 2 +- Luski/Resources/Textures/Toggle.png | Bin 0 -> 3132 bytes 21 files changed, 459 insertions(+), 112 deletions(-) create mode 100644 Luski/GUI/MainScreen/UI/LuskiControls/ToggleSwitch.cs create mode 100644 Luski/Resources/Textures/Toggle.png diff --git a/Luski/Classes/Settings.cs b/Luski/Classes/Settings.cs index 69049ef..24d95b1 100644 --- a/Luski/Classes/Settings.cs +++ b/Luski/Classes/Settings.cs @@ -1,4 +1,6 @@ +using System.ComponentModel; using System.Text.Json.Serialization; +using GraphicsManager.Objects; namespace Luski.Classes; @@ -29,11 +31,53 @@ public class Settings /// Sets the log value for the console. Default value of -25 to enable all logs by default except for DrawFrames and InfoOpenGL even if new ones are added. /// [JsonInclude] + [Description("Console Logs")] [JsonPropertyName("log")] - public ConsoleLog Logs { get; set; } = (ConsoleLog)(-25); + public ConsoleLog Logs + { + get + { + return _Logs; + } + set + { + _Logs = value; + if (Globals.ms is not null) + { + Globals.ms.LogFrames = (_Logs & ConsoleLog.DrawFrames) == ConsoleLog.DrawFrames; + Globals.ms.ShowMissingChar = (_Logs & ConsoleLog.ShowMissingChar) == ConsoleLog.ShowMissingChar; + } + } + } + [JsonInclude] + [Description("Scale Fonts")] [JsonPropertyName("scale_fonts")] - public bool ScaleFonts { get; set; } = true; + public bool ScaleFonts + { + get + { + return _ScaleFonts; + } + set + { + _ScaleFonts = value; + if (Globals.ms is not null) + { + Globals.DefaultFont.PixelHeight = Globals.Settings.DefaultFontPX.ScaleFont(); + Globals.MessageFont.PixelHeight = Globals.Settings.MessageFontPX.ScaleFont(); + Globals.TopTimeFont.PixelHeight = Globals.Settings.TopTimeFonttPX.ScaleFont(); + Globals.SmallTimeFont.PixelHeight = ((uint)11).ScaleFont(); + Label._characters[Globals.ms.Context][Globals.DefaultFont].Clear(); + Label._characters[Globals.ms.Context][Globals.MessageFont].Clear(); + Label._characters[Globals.ms.Context][Globals.TopTimeFont].Clear(); + Label._characters[Globals.ms.Context][Globals.SmallTimeFont].Clear(); + + Globals.ms.ForceUpdate(new(Globals.ms.ClientSize)); + Globals.ms.DrawFrame(); + } + } + } [JsonInclude] [JsonPropertyName("default_font_px")] public uint DefaultFontPX { get; set; } = 20; @@ -46,9 +90,30 @@ public class Settings [JsonInclude] [JsonPropertyName("message_font_line_space_px")] public uint MessageFontLineSpacePX { get; set; } = 5; + [JsonInclude] + [Description("24 Hour Time")] [JsonPropertyName("24hour_time")] - public bool DayTime { get; set; } = false; + public bool DayTime + { + get + { + return _DayTime; + } + set + { + _DayTime = value; + if (DayTimeChanged is not null) DayTimeChanged.Invoke(); + } + } + + [JsonIgnore] + private bool _ScaleFonts = true; + [JsonIgnore] + private ConsoleLog _Logs = (ConsoleLog)(-25); + [JsonIgnore] + private bool _DayTime = false; + public event Func? DayTimeChanged; } diff --git a/Luski/Classes/UpdaterSettings.cs b/Luski/Classes/UpdaterSettings.cs index 1488b80..63c467b 100644 --- a/Luski/Classes/UpdaterSettings.cs +++ b/Luski/Classes/UpdaterSettings.cs @@ -1,3 +1,4 @@ +using System.ComponentModel; using System.Text.Json.Serialization; using Luski.net.Enums; @@ -6,26 +7,29 @@ namespace Luski.Classes; public class UpdaterSettings { [JsonInclude] + [Description("Self Contained")] [JsonPropertyName("self_contained")] public bool SelfContained { get; set; } = false; [JsonInclude] [JsonPropertyName("updater")] public string? Updater { get; set; } = null; - - [JsonInclude] - [JsonPropertyName("branch")] - public string Branch { get; set; } = "beta"; [JsonInclude] [JsonPropertyName("platform")] public string Platform { get; set; } = "linux-x64"; [JsonInclude] + [Description("Auto Launch")] [JsonPropertyName("auto_launch")] public bool AutoLaunch { get; set; } = true; + [JsonInclude] + [Description("Auto Update")] + [JsonPropertyName("auto_update")] + public bool AutoUpdate { get; set; } = false; [JsonInclude] + [Description("Check For Updates")] [JsonPropertyName("update_check")] public bool AutoUpdateCheck { get; set; } = true; } diff --git a/Luski/ConsoleLog.cs b/Luski/ConsoleLog.cs index 7cd8410..8ea1ed6 100644 --- a/Luski/ConsoleLog.cs +++ b/Luski/ConsoleLog.cs @@ -1,13 +1,21 @@ +using System.ComponentModel; + namespace Luski; [Flags] -public enum ConsoleLog : int +public enum ConsoleLog : long { None = 0, + [Description("Show OpenGL Major Errors")] BigErrosForOpenGL = 1, + [Description("Show OpenGL Medium Errors")] MediumErrosForOpenGL = 2, + [Description("Show OpenGL Small Errors")] LowErrosForOpenGL = 4, + [Description("Show OpenGL Info")] InfoForOpenGL = 8, + [Description("Show Draw Frams")] DrawFrames = 16, + [Description("Show Missing Charters")] ShowMissingChar = 32 } \ No newline at end of file diff --git a/Luski/GUI/MainScreen/UI/AccountButton.cs b/Luski/GUI/MainScreen/UI/AccountButton.cs index e568cc3..1723302 100644 --- a/Luski/GUI/MainScreen/UI/AccountButton.cs +++ b/Luski/GUI/MainScreen/UI/AccountButton.cs @@ -30,7 +30,7 @@ public class AccountButton : UserControl ((base.Size.Y - l.Size.Y) / 2) , 0); Controls.Add(l); - BackgroundColor = new(0, 0, 0, 0); + base.BackgroundColor = new(0, 0, 0, 0); Clicked += OnClicked; MouseEnter += o => { diff --git a/Luski/GUI/MainScreen/UI/AddServerOverlay.cs b/Luski/GUI/MainScreen/UI/AddServerOverlay.cs index 0446672..05967f3 100644 --- a/Luski/GUI/MainScreen/UI/AddServerOverlay.cs +++ b/Luski/GUI/MainScreen/UI/AddServerOverlay.cs @@ -26,7 +26,7 @@ public class AddServerOverlay : UserControl, IServerOverlay public AddServerOverlay() { - base.Size = Globals.ms.Size; + base.Size = Globals.ms.ClientSize; BackgroundColor = new(0, 0, 0, 130); Anchor = ObjectAnchor.All; diff --git a/Luski/GUI/MainScreen/UI/FullScreenMedia.cs b/Luski/GUI/MainScreen/UI/FullScreenMedia.cs index acbe1f9..64f1d0c 100644 --- a/Luski/GUI/MainScreen/UI/FullScreenMedia.cs +++ b/Luski/GUI/MainScreen/UI/FullScreenMedia.cs @@ -10,7 +10,7 @@ public class FullScreenMedia : UserControl public FullScreenMedia(Texture t) { - base.Size = Globals.ms.Size; + base.Size = Globals.ms.ClientSize; IMG = new(t) { Size = t.RawSize!.Value, diff --git a/Luski/GUI/MainScreen/UI/LuskiControls/ToggleSwitch.cs b/Luski/GUI/MainScreen/UI/LuskiControls/ToggleSwitch.cs new file mode 100644 index 0000000..7e7ab67 --- /dev/null +++ b/Luski/GUI/MainScreen/UI/LuskiControls/ToggleSwitch.cs @@ -0,0 +1,52 @@ +using GraphicsManager.Interfaces; +using GraphicsManager.Objects; +using OpenTK.Mathematics; + +namespace Luski.GUI.MainScreen.UI.LuskiControls; + +public class ToggleSwitch : UserControl +{ + public ToggleSwitch() + :base(Globals.ms.TextureManager.GetTextureResource("Toggle.png")) + { + base.Size = new(40.ScaleInt(), 24.ScaleInt()); + base.BackgroundColor = OffBackgroundColor; + Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context]; + Clicked += o => + { + Value = !Value; + return Task.CompletedTask; + }; + } + + public event Func? ValueChanged; + + public override void LoadToParent(IParent Parent, IWindow Window) + { + Value = !Value; + Value = !Value; + base.LoadToParent(Parent, Window); + } + + public new Vector2i Size + { + get => base.Size; + private set => base.Size = value; + } + + public bool Value + { + get => val; + set + { + if (value) BackgroundColor = OnBackgroundColor; + else BackgroundColor = OffBackgroundColor; + val = value; + if (Loaded && ValueChanged is not null) ValueChanged.Invoke(this); + } + } + + public Color4 OnBackgroundColor { get; set; }= new(35, 165, 90, 255); + public Color4 OffBackgroundColor { get; set; } = new(128, 132, 142, 255); + private bool val = true; +} \ No newline at end of file diff --git a/Luski/GUI/MainScreen/UI/PublicServers/AddChannel.cs b/Luski/GUI/MainScreen/UI/PublicServers/AddChannel.cs index 9fd8d28..7542718 100644 --- a/Luski/GUI/MainScreen/UI/PublicServers/AddChannel.cs +++ b/Luski/GUI/MainScreen/UI/PublicServers/AddChannel.cs @@ -18,7 +18,7 @@ public class AddChannel : UserControl { this.CA = CA; Cat = cat; - base.Size = Globals.ms.Size; + base.Size = Globals.ms.ClientSize; base.BackgroundColor = new(0, 0, 0, 130); Anchor = ObjectAnchor.All; FlowLayout fl = new() diff --git a/Luski/GUI/MainScreen/UI/PublicServers/ChatMessage.cs b/Luski/GUI/MainScreen/UI/PublicServers/ChatMessage.cs index e940880..405f9c8 100644 --- a/Luski/GUI/MainScreen/UI/PublicServers/ChatMessage.cs +++ b/Luski/GUI/MainScreen/UI/PublicServers/ChatMessage.cs @@ -88,9 +88,10 @@ public class ChatMessage : UserControl //(int)(UserIcon.Location.Y + (UserIcon.Size.Y / 2) - (label1.Font.CurrentFonts[0].Face.Size.Metrics.NominalHeight / 2) - label1.Size.Y + label1.Font.PixelHeight), UserIcon.Location.Y, 0); + Label label2; LastObject = label1; FirstL = label1; - Controls.Add(new Label(Globals.TopTimeFont) { Location = new(label1.Location.X + label1.Size.X + 8.ScaleInt(), (int)(label1.Location.Y + label1.Font.PixelHeight - Globals.TopTimeFont.PixelHeight), 0), Text = time_str}); + Controls.Add(label2 = new Label(Globals.TopTimeFont) { Location = new(label1.Location.X + label1.Size.X + 8.ScaleInt(), (int)(label1.Location.Y + label1.Font.PixelHeight - Globals.TopTimeFont.PixelHeight), 0), Text = time_str}); if (!string.IsNullOrWhiteSpace(Msg.Context)) { Label l; @@ -98,6 +99,42 @@ public class ChatMessage : UserControl LastObject = l; MessageObjs.Add(l); } + Globals.Settings.DayTimeChanged += () => + { + if (Globals.Settings.DayTime) + { + if (time.Date == DateTime.Now.ToLocalTime().Date) + { + time_str = $"Today at {time:HH:mm}"; + } + else if (time.Date == DateTime.Now.ToLocalTime().AddDays(-1).Date) + { + time_str = $"Yesterday at {time:HH:mm}"; + } + else + { + time_str = $"{time:M/dd/yyyy HH:mm}"; + } + } + else + { + if (time.Date == DateTime.Now.ToLocalTime().Date) + { + time_str = $"Today at {time.ToShortTimeString().Replace('\u202f', ' ')}"; + } + else if (time.Date == DateTime.Now.ToLocalTime().AddDays(-1).Date) + { + time_str = $"Yesterday at {time.ToShortTimeString().Replace('\u202f', ' ')}"; + } + else + { + time_str = $"{time:M/dd/yyyy h:mm tt}"; + } + } + + label2.Text = time_str; + return Task.CompletedTask; + }; if (Msg.Files.Count > 0) { @@ -219,6 +256,13 @@ public class ChatMessage : UserControl string b; if (!Globals.Settings.DayTime) b = time.ToString("h:mm tt"); else b = time.ToString("HH:mm"); + Globals.Settings.DayTimeChanged += () => + { + if (!Globals.Settings.DayTime) b = time.ToString("h:mm tt"); + else b = time.ToString("HH:mm"); + return Task.CompletedTask; + + }; Label[] l = Labels.Where(s => s.Text == b).ToArray(); if (l.Any()) { @@ -242,6 +286,12 @@ public class ChatMessage : UserControl { Text = time.ToString("HH:mm"), }; + Globals.Settings.DayTimeChanged += () => + { + if (!Globals.Settings.DayTime) m.Text = time.ToString("h:mm tt"); + else m.Text = time.ToString("HH:mm"); + return Task.CompletedTask; + }; m.Location = new( label.Location.X - m.Size.X - 5.ScaleInt(), (int)(label.Location.Y + label.Font.PixelHeight - Globals.SmallTimeFont.PixelHeight), diff --git a/Luski/GUI/MainScreen/UI/PublicServers/PublicChat.cs b/Luski/GUI/MainScreen/UI/PublicServers/PublicChat.cs index e1c5c5c..3b2b64f 100644 --- a/Luski/GUI/MainScreen/UI/PublicServers/PublicChat.cs +++ b/Luski/GUI/MainScreen/UI/PublicServers/PublicChat.cs @@ -6,10 +6,12 @@ using GraphicsManager.Objects; using Luski.GUI.MainScreen.UI.LuskiControls; using Luski.net.Structures.Public; using Luski.Shared.PublicServers.V1.Enums; +using OpenTK.Graphics.ES11; using OpenTK.Mathematics; using OpenTK.Windowing.Common; using OpenTK.Windowing.Common.Input; using OpenTK.Windowing.GraphicsLibraryFramework; +using MatrixMode = OpenTK.Graphics.OpenGL.MatrixMode; namespace Luski.GUI.MainScreen.UI.PublicServers; @@ -33,7 +35,7 @@ public class PublicChat : UserControl Anchor = ObjectAnchor.All; Controls.Add(MessageFlow = new() { - Size = new(base.Size.X, 761.ScaleInt()), + Size = new(base.Size.X, 785.ScaleInt()), Location = new(0, 52.ScaleInt(), 0), BackgroundColor = new(40,40,40,255), Anchor = ObjectAnchor.All, @@ -55,23 +57,20 @@ public class PublicChat : UserControl Size = new(980.ScaleInt(), 48.ScaleInt()), BackgroundColor = new(50,50,50,255), }); - if (LuskiExperiments.GUI.MemberList.IsEnabled()) - { - UserCon = - new(Globals.ms.TextureManager.GetTextureResource("person.png")) - { - Size = new(24.ScaleInt()), - Location = new(944.ScaleInt(), 12.ScaleInt(),0), - Anchor = ObjectAnchor.Right | ObjectAnchor.Top, - Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context], - BackgroundColor = Color4.LightGray - }; - UserCon.MouseEnter += o => { UserCon.BackgroundColor = Color4.White; return Task.CompletedTask; }; - UserCon.MouseLeave += o => { UserCon.BackgroundColor = Color4.LightGray; return Task.CompletedTask; }; - UserCon.Clicked += UserConOnClicked; - titlecon.Controls.Add(UserCon); - } - LuskiExperiments.GUI.MemberList.EventToggled += MemberListOnEventToggled; + UserCon = + new(Globals.ms.TextureManager.GetTextureResource("person.png")) + { + Size = new(24.ScaleInt()), + Location = new(944.ScaleInt(), 12.ScaleInt(),0), + Anchor = ObjectAnchor.Right | ObjectAnchor.Top, + Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context], + BackgroundColor = Color4.LightGray + }; + UserCon.MouseEnter += o => { UserCon.BackgroundColor = Color4.White; return Task.CompletedTask; }; + UserCon.MouseLeave += o => { UserCon.BackgroundColor = Color4.LightGray; return Task.CompletedTask; }; + UserCon.Clicked += UserConOnClicked; + titlecon.Controls.Add(UserCon); + titlecon.ForceDistanceUpdate(this); titlecon.Controls.Add(title = new Label(Globals.DefaultFont) @@ -131,7 +130,6 @@ public class PublicChat : UserControl if (cm.MessageObjs[i] is Label l) { l.MaxSize = new(MessageFlow.Size.X - l.Location.X - 10.ScaleInt(), Int32.MaxValue); - //l.Text = l.Text; } } @@ -171,8 +169,11 @@ public class PublicChat : UserControl private async Task TbOnKeyPress(KeyboardKeyEventArgs arg) { + //var t = Matrix4.Identity * Matrix4.CreateScale(2 / (float)Size.X, 2 / (float)Size.Y, 1) * Matrix4.CreateTranslation(-1.0f, -1.0f, 0.0f); + //var tt = Matrix4.CreateOrthographicOffCenter(0.0f, Size.X, 0.0f, Size.Y, 1, -1); if (arg.Key == Keys.Enter && !arg.Shift) { + await Channel!.SendMessage(tb.Text); tb.Text = string.Empty; tb.CursorLocation = 0; @@ -196,33 +197,7 @@ public class PublicChat : UserControl BlockDraw = false; return Task.CompletedTask; } - - private async Task MemberListOnEventToggled(bool arg) - { - if (arg) - { - UserCon = - new(Globals.ms.TextureManager.GetTextureResource("person.png")) - { - Size = new(24.ScaleInt()), - Location = new(base.Size.X - 36.ScaleInt(), 12.ScaleInt(),0), - Anchor = ObjectAnchor.Right | ObjectAnchor.Top, - Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context], - BackgroundColor = Color4.LightGray - }; - UserCon.MouseEnter += o => { UserCon.BackgroundColor = Color4.White; return Task.CompletedTask; }; - UserCon.MouseLeave += o => { UserCon.BackgroundColor = Color4.LightGray; return Task.CompletedTask; }; - UserCon.Clicked += UserConOnClicked; - titlecon.Controls.Add(UserCon); - } - else - { - if (um_open) await UserConOnClicked(UserCon!); - titlecon.Controls.Remove(UserCon!); - UserCon = null; - } - } - + private bool um_open = false; private bool SeperateOffline = true; diff --git a/Luski/GUI/MainScreen/UI/ServerIcon.cs b/Luski/GUI/MainScreen/UI/ServerIcon.cs index 83ba89c..f041960 100644 --- a/Luski/GUI/MainScreen/UI/ServerIcon.cs +++ b/Luski/GUI/MainScreen/UI/ServerIcon.cs @@ -73,9 +73,9 @@ public class ServerIcon : UserControl where TServer : Server Controls.Add(SelectedRect); Controls.Add(rr); Controls.Add(r); - BackgroundColor = new(26, 26, 26, 255); + base.BackgroundColor = new(26, 26, 26, 255); this.Clicked += OnClicked; - Size = new(68.ScaleInt(), 48.ScaleInt()); + base.Size = new(68.ScaleInt(), 48.ScaleInt()); } private async Task OnClicked(IRenderObject arg) diff --git a/Luski/GUI/MainScreen/UI/ServerLoginOverlay.cs b/Luski/GUI/MainScreen/UI/ServerLoginOverlay.cs index 810f1dc..c2fae12 100644 --- a/Luski/GUI/MainScreen/UI/ServerLoginOverlay.cs +++ b/Luski/GUI/MainScreen/UI/ServerLoginOverlay.cs @@ -26,8 +26,8 @@ public class ServerLoginOverlay : UserControl, IServerOverlay public ServerLoginOverlay(string address) { - base.Size = Globals.ms.Size; - BackgroundColor = new(0, 0, 0, 130); + base.Size = Globals.ms.ClientSize; + base.BackgroundColor = new(0, 0, 0, 130); Anchor = ObjectAnchor.All; diff --git a/Luski/GUI/MainScreen/UI/SettingsMenu.cs b/Luski/GUI/MainScreen/UI/SettingsMenu.cs index d3535f1..23e7057 100644 --- a/Luski/GUI/MainScreen/UI/SettingsMenu.cs +++ b/Luski/GUI/MainScreen/UI/SettingsMenu.cs @@ -1,3 +1,5 @@ +using System.ComponentModel; +using System.Reflection; using GraphicsManager.Enums; using GraphicsManager.Interfaces; using GraphicsManager.Objects; @@ -13,7 +15,7 @@ public class SettingsMenu : UserControl { private string BehindName; public FlowLayout page; - public CategoryButton? Selected; + public CategoryButton? Selected, apper; private FlowLayout fl; private Category? AppSettings; private FontInteraction f; @@ -24,7 +26,7 @@ public class SettingsMenu : UserControl BehindName = Globals.ms.Title; Globals.ms.Title = "Settings - Luski"; base.BackgroundColor = new(34, 34, 34, 255); - base.Size = Globals.ms.Size; + base.Size = Globals.ms.ClientSize; Anchor = ObjectAnchor.All; if (CategoryButton.seltec is null) { @@ -39,11 +41,89 @@ public class SettingsMenu : UserControl f = Globals.DefaultFont.Clone(); f.FontSize = FontSize.Bold; f.PixelHeight = (uint)(f.PixelHeight * 1.4f); + AppSettings = new("APP SETTINGS"); + CategoryButton cb3 = new("General", this) + { + OnPageLoad = () => + { + page!.Controls.Add(new Label(f) + { + Text = " \nGeneral\n " + }); + foreach (PropertyInfo prop in typeof(Settings).GetProperties()) + { + object PropVal = prop.GetValue(Globals.Settings)!; + Type PropType = prop.PropertyType; + if (PropType.IsEnum) + { + IEnumerable values = Enum.GetValues(PropType).Cast(); + foreach (var val in values) + { + try + { + MemberInfo[] memberInfos = + PropType.GetMember(val.ToString()); + MemberInfo? enumValueMemberInfo = memberInfos.FirstOrDefault(m => + m.DeclaringType == PropType); + object[] valueAttributes = + enumValueMemberInfo.GetCustomAttributes(typeof(DescriptionAttribute), false); + if (valueAttributes.Length == 0) continue; + string description = ((DescriptionAttribute)valueAttributes[0]).Description; + + AddBool(description, ((Enum)PropVal).HasFlag(val), bb => + { + long va = Convert.ToInt64(val); + long v = Convert.ToInt64(PropVal); + if (bb) + { + object e = Enum.Parse(PropType, (v + va).ToString()); + PropVal = e; + prop.SetValue(Globals.Settings, e); + } + else + { + var e = Enum.Parse(PropType, (v - va).ToString()); + PropVal = e; + prop.SetValue(Globals.Settings, e); + } + Globals.Settings.SaveSettings(Path.Combine(Globals.LuskiPath, "Settings.json"), SettingsContext.Default.Settings); + }); + } + catch + { + //ignore + } + } + } + if (PropType.FullName == typeof(bool).FullName) + { + try + { + object[] valueAttributes = + prop.GetCustomAttributes(typeof(DescriptionAttribute), false); + string description = ((DescriptionAttribute)valueAttributes[0]).Description; + AddBool(description, (bool)PropVal, b => + { + prop.SetValue(Globals.Settings, b); + Globals.Settings.SaveSettings(Path.Combine(Globals.LuskiPath, "Settings.json"), SettingsContext.Default.Settings); + }); + } + catch + { + // ignored + } + + } + } + } + }; + AppSettings.AddButton(cb3); + + fl.Controls.Add(AppSettings); if (LuskiExperiments.Settings.Theme.IsEnabled()) { - AppSettings = new("APP SETTINGS"); Label Top = new(Globals.DefaultFont) { Location = new(5.ScaleInt(), 5.ScaleInt(), 0), @@ -147,12 +227,40 @@ public class SettingsMenu : UserControl { BackgroundColor = this.BackgroundColor, Location = new(fl.Size.X + 40.ScaleInt(), 0, 0), - Size = new(Globals.ms.Size.X - fl.Size.X - 80.ScaleInt(), Globals.ms.Size.Y), + Size = new(Globals.ms.ClientSize.X - fl.Size.X - 80.ScaleInt(), Globals.ms.Size.Y), AllowHoverFromBehind = true, Anchor = ObjectAnchor.All, HScrollPixels = Globals.Settings.PerScrollPixels }; Controls.Add(page); + void AddBool(string Name, bool s, Action a) + { + ToggleSwitch ts = new() + { + Value = s + }; + UserControl tc = new() + { + Size = ts.Size, + BackgroundColor = page.BackgroundColor + }; + Label l; + tc.Controls.Add(l =new Label(Globals.DefaultFont) + { + Text = Name + ": " + }); + tc.Size = l.Size; + tc.Controls.Add(ts); + ts.Location = new(l.Size.X + 10.ScaleInt(), 0, 0); + + + ts.ValueChanged += @switch => + { + a.Invoke(@switch .Value); + return Task.CompletedTask; + }; + page.Controls.Add(tc); + } page.ForceDistanceUpdate(this); Category As = new("ADVANCED SETTINGS"); CategoryButton cb = new("Experiments", this) @@ -174,7 +282,7 @@ public class SettingsMenu : UserControl { g.line.WindowLoaded += _ => { - page.ParentResize(new(Globals.ms.Size)); + page.ParentResize(new(Globals.ms.ClientSize)); return Task.CompletedTask; }; } @@ -190,10 +298,7 @@ public class SettingsMenu : UserControl }); - void AddBool(string Name, ref bool s) - { - - } + TextBox t; page!.Controls.Add(t =new TextBox() @@ -205,6 +310,71 @@ public class SettingsMenu : UserControl TextLocation = TextLocation.LineCenter, AllowMultiLine = false }); + foreach (PropertyInfo prop in typeof(UpdaterSettings).GetProperties()) + { + object PropVal = prop.GetValue(Globals.UpdaterSettings)!; + Type PropType = prop.PropertyType; + if (PropType.IsEnum) + { + IEnumerable values = Enum.GetValues(PropType).Cast(); + foreach (var val in values) + { + try + { + MemberInfo[] memberInfos = + PropType.GetMember(val.ToString()); + MemberInfo? enumValueMemberInfo = memberInfos.FirstOrDefault(m => + m.DeclaringType == PropType); + object[] valueAttributes = + enumValueMemberInfo.GetCustomAttributes(typeof(DescriptionAttribute), false); + if (valueAttributes.Length == 0) continue; + string description = ((DescriptionAttribute)valueAttributes[0]).Description; + + AddBool(description, ((Enum)PropVal).HasFlag(val), bb => + { + long va = Convert.ToInt64(val); + long v = Convert.ToInt64(PropVal); + if (bb) + { + object e = Enum.Parse(PropType, (v + va).ToString()); + PropVal = e; + prop.SetValue(Globals.Settings, e); + } + else + { + var e = Enum.Parse(PropType, (v - va).ToString()); + PropVal = e; + prop.SetValue(Globals.Settings, e); + } + Globals.UpdaterSettings.SaveSettings(Path.Combine(Globals.LuskiPath, "UpdaterSettings.json"), UpdaterSettingsContext.Default.UpdaterSettings); + }); + } + catch + { + //ignore + } + } + } + if (PropType.FullName == typeof(bool).FullName) + { + try + { + object[] valueAttributes = + prop.GetCustomAttributes(typeof(DescriptionAttribute), false); + string description = ((DescriptionAttribute)valueAttributes[0]).Description; + AddBool(description, (bool)PropVal, b => + { + prop.SetValue(Globals.Settings, b); + Globals.UpdaterSettings.SaveSettings(Path.Combine(Globals.LuskiPath, "UpdaterSettings.json"), UpdaterSettingsContext.Default.UpdaterSettings); + }); + } + catch + { + // ignored + } + } + } + t.ForceDistanceUpdate(page); t.KeyPress += args => { @@ -212,7 +382,7 @@ public class SettingsMenu : UserControl Globals.UpdaterSettings.SaveSettings(Path.Combine(Globals.LuskiPath, "UpdaterSettings.json"), UpdaterSettingsContext.Default.UpdaterSettings); return Task.CompletedTask; }; - Globals.ms.ForceUpdate(new(Globals.ms.Size)); + Globals.ms.ForceUpdate(new(Globals.ms.ClientSize)); } }; As.AddButton(cb); @@ -221,11 +391,11 @@ public class SettingsMenu : UserControl fl.ForceDistanceUpdate(this); - _ = cb.ToggleSelected(); + _ = cb3.ToggleSelected(); Rectangle closebtn = new(Globals.ms.TextureManager.GetTextureResource("close.png")) { - Location = new(Globals.ms.Size.X - 40.ScaleInt(), 8.ScaleInt(),0), + Location = new(Globals.ms.ClientSize.X - 40.ScaleInt(), 8.ScaleInt(),0), Size = new(32.ScaleInt()), Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context], BackgroundColor = Color4.Gray, @@ -251,8 +421,7 @@ public class SettingsMenu : UserControl { if (arg) { - AppSettings = new("APP SETTINGS"); - CategoryButton cb = new("Appearance", this) + apper = new("Appearance", this) { OnPageLoad = () => { @@ -262,13 +431,12 @@ public class SettingsMenu : UserControl }); } }; - AppSettings.AddButton(cb); - fl.Controls.Insert(0, AppSettings); + AppSettings!.AddButton(apper); fl.ScrollToBottom(); } else { - fl.Controls.Remove(AppSettings!); + AppSettings!.RemoveButton(apper); } return Task.CompletedTask; diff --git a/Luski/GUI/MainScreen/UI/SettingsPanel/Category.cs b/Luski/GUI/MainScreen/UI/SettingsPanel/Category.cs index 7eaaf5d..1722eb0 100644 --- a/Luski/GUI/MainScreen/UI/SettingsPanel/Category.cs +++ b/Luski/GUI/MainScreen/UI/SettingsPanel/Category.cs @@ -49,4 +49,17 @@ public class Category : UserControl line.Location = new(line.Location.X, line.Location.Y + cb.Size.Y + f, 0); Size = new(Size.X, Size.Y + cb.Size.Y + f); } + + public void RemoveButton(CategoryButton cb) + { + int f = 5.ScaleInt(); + line.Location = new(line.Location.X, line.Location.Y - cb.Size.Y - f, 0); + Controls.Remove(cb); + Size = new(Size.X, Size.Y - cb.Size.Y + f); + for (int i = 0; i < Controls.Length; i++) + { + ReportSizeUpdate(Controls[i]); + } + TryDraw(); + } } \ No newline at end of file diff --git a/Luski/GUI/MainScreen/UI/SettingsPanel/ExperimentGUI.cs b/Luski/GUI/MainScreen/UI/SettingsPanel/ExperimentGUI.cs index 627cc06..ae7eeea 100644 --- a/Luski/GUI/MainScreen/UI/SettingsPanel/ExperimentGUI.cs +++ b/Luski/GUI/MainScreen/UI/SettingsPanel/ExperimentGUI.cs @@ -130,7 +130,7 @@ public class ExperimentGUI : UserControl } dd.OptionSelected += DdOnOptionSelected; Controls.Add(dd); - base.Size = new(Globals.ms.Size.X - 307.ScaleInt() - 80.ScaleInt(), 15.ScaleInt() + dd.Size.Y + dd.Location.Y ); + base.Size = new(Globals.ms.ClientSize.X - 307.ScaleInt() - 80.ScaleInt(), 15.ScaleInt() + dd.Size.Y + dd.Location.Y ); dd.Size = new(base.Size.X - Top.Location.X - Top.Location.X, dd.Size.Y); dd.ForceDistanceUpdate(this); diff --git a/Luski/GUI/MainScreenWindow.cs b/Luski/GUI/MainScreenWindow.cs index 3013b80..3fa297b 100644 --- a/Luski/GUI/MainScreenWindow.cs +++ b/Luski/GUI/MainScreenWindow.cs @@ -2,6 +2,7 @@ using System.Diagnostics; using System.Reflection; using System.Runtime.InteropServices; using GraphicsManager.Enums; +using GraphicsManager.Globals; using GraphicsManager.Interfaces; using GraphicsManager.Objects; using GraphicsManager.Objects.Core; @@ -9,20 +10,26 @@ using Luski.GUI.MainScreen.UI; using Luski.GUI.MainScreen.UI.PublicServers; using Luski.net; using Luski.net.Structures.Public; +using OpenTK.Graphics.GL; using OpenTK.Graphics.OpenGL4; using OpenTK.Mathematics; using OpenTK.Windowing.Common; using OpenTK.Windowing.Desktop; +using OpenTK.Windowing.GraphicsLibraryFramework; +using DebugProc = OpenTK.Graphics.OpenGL4.DebugProc; +using DebugSeverity = OpenTK.Graphics.OpenGL4.DebugSeverity; +using DebugSource = OpenTK.Graphics.OpenGL4.DebugSource; +using DebugType = OpenTK.Graphics.OpenGL4.DebugType; using Window = GraphicsManager.Window; namespace Luski.GUI; public class MainScreenWindow : Window { - private static readonly NativeWindowSettings Settings = new() + public static readonly NativeWindowSettings Settings = new() { Title = "Luski", - WindowBorder = WindowBorder.Fixed, + WindowBorder = WindowBorder.Resizable, APIVersion = new Version(3, 2), API = ContextAPI.OpenGL, StartFocused = true, @@ -89,6 +96,7 @@ public class MainScreenWindow : Window public MainScreenWindow() : base(Settings) { Globals.ms = this; + Size = new(1332.ScaleInt(), 866.ScaleInt()); ShowMissingChar = true; LogFrames = ((Globals.Settings.Logs & ConsoleLog.DrawFrames) == ConsoleLog.DrawFrames); VSync = VSyncMode.On; @@ -147,11 +155,10 @@ public class MainScreenWindow : Window private async Task OnWindowLoaded(Window arg) { - string r = new HttpClient() - .GetAsync( - $"https://www.jacobtech.com/Updater/GetProgramVersion?directory=Luski&branch={Globals.UpdaterSettings.Branch.ToString()}&selfcontained={Globals.UpdaterSettings.SelfContained.ToString().ToLower()}&platform={Globals.UpdaterSettings.Platform}") - .Result.Content.ReadAsStringAsync().Result; - if (Globals.UpdaterSettings.AutoUpdateCheck && r != + if (Globals.UpdaterSettings.AutoUpdateCheck && new HttpClient() + .GetAsync( + $"https://www.jacobtech.com/Updater/GetProgramVersion?directory=Luski&branch=main&selfcontained={Globals.UpdaterSettings.SelfContained.ToString().ToLower()}&platform={Globals.UpdaterSettings.Platform}") + .Result.Content.ReadAsStringAsync().Result != FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion) { var update = new UpdateWindow(); @@ -179,7 +186,8 @@ public class MainScreenWindow : Window { ServerLoginOverlay SLO = new(Server.Domain); Controls.Add(SLO); - ForceUpdate(new(Size)); + ForceUpdate(new(ClientSize)); + Globals.PrintParent(this); return; } BlockDraw = true; @@ -192,7 +200,7 @@ public class MainScreenWindow : Window SerBox = new() { Location = new(ser.Size.X, 0, 0), - Size = new(Size.X - ser.Size.X, Size.Y), + Size = new(Size.X - ser.Size.X, ClientSize.Y), Anchor = ObjectAnchor.All, BackgroundColor = new(20, 20, 20, 255) }; @@ -328,7 +336,11 @@ public class MainScreenWindow : Window Controls.Clear(); BlockDraw = true; Title = "Luski"; - Size = new(1332.ScaleInt(), 866.ScaleInt()); + unsafe + { + GLFW.SetWindowSizeLimits(WindowPtr, 500.ScaleInt(), 250.ScaleInt(),GLFW.DontCare, GLFW.DontCare); + } + try { CenterWindow(Globals.Settings.Display); @@ -343,10 +355,11 @@ public class MainScreenWindow : Window Controls.Add(ser = new FlowLayout() { BackgroundColor = new(26, 26, 26, 255), - Size = new(68.ScaleInt(), 868.ScaleInt()), + Size = new(68.ScaleInt(), ClientSize.Y), Anchor = ObjectAnchor.Top | ObjectAnchor.Left | ObjectAnchor.Bottom, Location = new(0,0,0) }); + ser.LoadToParent(this,this); DrawFrame(); DateTime utcNow = DateTime.UtcNow; Task.WhenAll(Globals.ServersLoading.ToArray()).Wait(); @@ -354,6 +367,7 @@ public class MainScreenWindow : Window { ServerIcon si = new ServerIcon(pser); ser.Controls.Add(si); + si.LoadToParent(ser, this); } AddServerIcon asi = new(); @@ -369,6 +383,12 @@ public class MainScreenWindow : Window return Task.CompletedTask; } + protected override void OnResize(ResizeEventArgs e) + { + base.OnResize(e); + + } + private Task AddButtonClicked(IRenderObject arg) { AddServerOverlay aso = new(); diff --git a/Luski/Globals.cs b/Luski/Globals.cs index 059fa27..cc31b91 100644 --- a/Luski/Globals.cs +++ b/Luski/Globals.cs @@ -54,11 +54,18 @@ public static class Globals private static int LastExpCount = 0; public static Color4 DodgerBlue = new Color4(30, 144, 255, 255); + private static bool msc = true; + private static double mscale = -1; public static double GetScale() { if (Settings.Scale is not null) return Settings.Scale.Value; - return Monitors.GetMonitorFromWindow(ms).HorizontalScale; + if (msc) + { + msc = false; + mscale = Monitors.GetMonitorFromWindow(ms).HorizontalScale; + } + return mscale; } public static int ScaleInt(this int i) { diff --git a/Luski/Luski.csproj b/Luski/Luski.csproj index 072cd42..9c2d070 100644 --- a/Luski/Luski.csproj +++ b/Luski/Luski.csproj @@ -5,7 +5,7 @@ net8.0 enable enable - 1.0.0.0 + 0.0.0.1 JacobTech, LLC @@ -21,8 +21,8 @@ - - + + diff --git a/Luski/LuskiExperiments.cs b/Luski/LuskiExperiments.cs index 4215e06..87254d2 100644 --- a/Luski/LuskiExperiments.cs +++ b/Luski/LuskiExperiments.cs @@ -9,15 +9,6 @@ public static class LuskiExperiments Parents.MainServer, Parents.ThemeEdit, new() - { - DisplayName = "Server Member List", - Name = "2023_12_member_list", - Options = new() - { - GUI.MemberList - } - }, - new() { DisplayName = "Proper Message Label Size", Name = "2024_04_label_size", @@ -78,12 +69,6 @@ public static class LuskiExperiments public static class GUI { - public static readonly ExperimentSelectorInfo MemberList = new() - { - Name = "Member List", - Description = "Adds a list on the side of a chat that shows members.",RequiresRestart = false - }; - public static readonly ExperimentSelectorInfo MessageLiveSize = new() { Name = "Proper Label Size", diff --git a/Luski/Program.cs b/Luski/Program.cs index 0bfdccb..ce1a077 100644 --- a/Luski/Program.cs +++ b/Luski/Program.cs @@ -96,7 +96,7 @@ if (Globals.Download) "--localdirectory", AppDomain.CurrentDomain.BaseDirectory, "--branch", - Globals.UpdaterSettings.Branch.ToString(), + "main", "--selfcontained", Globals.UpdaterSettings.SelfContained.ToString().ToLower(), "--platform", diff --git a/Luski/Resources/Textures/Toggle.png b/Luski/Resources/Textures/Toggle.png new file mode 100644 index 0000000000000000000000000000000000000000..86ac59fed4e6b8c71934757a5efbd9f6e65d6eab GIT binary patch literal 3132 zcmV-C48!w@P)e^=UC6NNW{Kn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