From 42b612bbc2b5d4db45dbae089ea6edea1fe578b3 Mon Sep 17 00:00:00 2001 From: JacobTech Date: Mon, 13 May 2024 11:47:29 -0400 Subject: [PATCH] I did too much. I was going to add a new munu to manage roles, but I got a bit carried away updating existing ones. --- Luski/Classes/LuskiThemes.cs | 2 +- Luski/Classes/Settings.cs | 22 +- .../Classes/ThemeSub/ServerThemeProperties.cs | 2 +- Luski/Classes/UpdaterSettings.cs | 12 +- Luski/ConsoleLog.cs | 14 +- Luski/GUI/MainScreen/UI/AddServerOverlay.cs | 339 +++++++------ .../MainScreen/UI/LuskiControls/TextBox.cs | 94 ++-- .../UI/LuskiSettings/Core/ISettingsPage.cs | 12 + .../UI/LuskiSettings/Core/PageFlow.cs | 38 ++ .../Core/PageTab.cs} | 14 +- .../UI/LuskiSettings/Core/SettingsCategory.cs | 80 ++++ .../AdvancedSettings/ExperimentSettings.cs | 30 ++ .../Pages/AdvancedSettings/Updater.cs | 91 ++++ .../Pages/AppSettings/Appearance.cs | 102 ++++ .../Pages/AppSettings/General.cs | 65 +++ .../UI/LuskiSettings/SettingsMenu.cs | 81 ++++ .../UI/PublicServers/ChannelSelector.cs | 24 +- .../UI/PublicServers/ChatMessage.cs | 2 +- .../MainScreen/UI/PublicServers/PublicChat.cs | 6 +- .../ServerSettingCategory.cs} | 40 +- .../UI/PublicServers/ServerSettingPageTab.cs | 96 ++++ .../ServerSettingPages/IPageBase.cs | 10 + .../ServerSettingPages/PageBaseControl.cs | 38 ++ .../ServerSettingPages/PageBaseFlow.cs | 38 ++ .../ServerSettingPages/RoleIcon.cs | 73 +++ .../ServerSettingPages/SaveWarning.cs | 56 +++ .../ServerRoleInteraction.cs | 83 ++++ .../ServerSettingPages/ServerRoleOptions.cs | 227 +++++++++ .../ServerSettingPages/ServerRolePage.cs | 35 ++ .../UI/PublicServers/ServerSettings.cs | 69 +++ Luski/GUI/MainScreen/UI/SettingsMenu.cs | 452 ------------------ .../UI/SettingsPanel/ExperimentDropButton.cs | 4 +- .../UI/SettingsPanel/ExperimentGUI.cs | 13 +- .../UI/SettingsPanel/ThemeDropButton.cs | 2 +- Luski/GUI/MainScreenWindow.cs | 66 ++- Luski/Globals.cs | 119 ++++- Luski/Luski.csproj | 14 +- Luski/LuskiExperiments.cs | 8 +- Luski/Program.cs | 1 + 39 files changed, 1752 insertions(+), 722 deletions(-) create mode 100644 Luski/GUI/MainScreen/UI/LuskiSettings/Core/ISettingsPage.cs create mode 100644 Luski/GUI/MainScreen/UI/LuskiSettings/Core/PageFlow.cs rename Luski/GUI/MainScreen/UI/{SettingsPanel/CategoryButton.cs => LuskiSettings/Core/PageTab.cs} (86%) create mode 100644 Luski/GUI/MainScreen/UI/LuskiSettings/Core/SettingsCategory.cs create mode 100644 Luski/GUI/MainScreen/UI/LuskiSettings/Pages/AdvancedSettings/ExperimentSettings.cs create mode 100644 Luski/GUI/MainScreen/UI/LuskiSettings/Pages/AdvancedSettings/Updater.cs create mode 100644 Luski/GUI/MainScreen/UI/LuskiSettings/Pages/AppSettings/Appearance.cs create mode 100644 Luski/GUI/MainScreen/UI/LuskiSettings/Pages/AppSettings/General.cs create mode 100644 Luski/GUI/MainScreen/UI/LuskiSettings/SettingsMenu.cs rename Luski/GUI/MainScreen/UI/{SettingsPanel/Category.cs => PublicServers/ServerSettingCategory.cs} (58%) create mode 100644 Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPageTab.cs create mode 100644 Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPages/IPageBase.cs create mode 100644 Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPages/PageBaseControl.cs create mode 100644 Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPages/PageBaseFlow.cs create mode 100644 Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPages/RoleIcon.cs create mode 100644 Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPages/SaveWarning.cs create mode 100644 Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPages/ServerRoleInteraction.cs create mode 100644 Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPages/ServerRoleOptions.cs create mode 100644 Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPages/ServerRolePage.cs create mode 100644 Luski/GUI/MainScreen/UI/PublicServers/ServerSettings.cs delete mode 100644 Luski/GUI/MainScreen/UI/SettingsMenu.cs diff --git a/Luski/Classes/LuskiThemes.cs b/Luski/Classes/LuskiThemes.cs index e5a071e..10f57fc 100644 --- a/Luski/Classes/LuskiThemes.cs +++ b/Luski/Classes/LuskiThemes.cs @@ -35,7 +35,7 @@ public static class LuskiThemes Description = "A light theme for the insane.", GlobalServerTemplate = new() { - SelectionColor = new("000000") + SelectionColor = new("00000000") } }; diff --git a/Luski/Classes/Settings.cs b/Luski/Classes/Settings.cs index 24d95b1..94a6d46 100644 --- a/Luski/Classes/Settings.cs +++ b/Luski/Classes/Settings.cs @@ -31,7 +31,8 @@ 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")] + [Shared.GlobalAttributes.DisplayName("Console Logs")] + [Description("The Log values for the console")] [JsonPropertyName("log")] public ConsoleLog Logs { @@ -51,7 +52,8 @@ public class Settings } [JsonInclude] - [Description("Scale Fonts")] + [Shared.GlobalAttributes.DisplayName("Scale Fonts")] + [Description("Scales fonts using the scale property")] [JsonPropertyName("scale_fonts")] public bool ScaleFonts { @@ -66,7 +68,7 @@ public class Settings { Globals.DefaultFont.PixelHeight = Globals.Settings.DefaultFontPX.ScaleFont(); Globals.MessageFont.PixelHeight = Globals.Settings.MessageFontPX.ScaleFont(); - Globals.TopTimeFont.PixelHeight = Globals.Settings.TopTimeFonttPX.ScaleFont(); + Globals.TopTimeFont.PixelHeight = Globals.Settings.TopTimeFontPX.ScaleFont(); Globals.SmallTimeFont.PixelHeight = ((uint)11).ScaleFont(); Label._characters[Globals.ms.Context][Globals.DefaultFont].Clear(); Label._characters[Globals.ms.Context][Globals.MessageFont].Clear(); @@ -83,7 +85,10 @@ public class Settings public uint DefaultFontPX { get; set; } = 20; [JsonInclude] [JsonPropertyName("top_time_font_px")] - public uint TopTimeFonttPX { get; set; } = 12; + public uint TopTimeFontPX { get; set; } = 12; + [JsonInclude] + [JsonPropertyName("role_settings_font_px")] + public uint RoleSettingsFontPX { get; set; } = 14; [JsonInclude] [JsonPropertyName("message_font_px")] public uint MessageFontPX { get; set; } = 17; @@ -92,7 +97,8 @@ public class Settings public uint MessageFontLineSpacePX { get; set; } = 5; [JsonInclude] - [Description("24 Hour Time")] + [Shared.GlobalAttributes.DisplayName("24 Hour Time")] + [Description("shows time in the 24 hour format")] [JsonPropertyName("24hour_time")] public bool DayTime { @@ -114,7 +120,6 @@ public class Settings [JsonIgnore] private bool _DayTime = false; public event Func? DayTimeChanged; - } [JsonSerializable(typeof(Settings))] @@ -123,7 +128,4 @@ public class Settings PropertyNamingPolicy = JsonKnownNamingPolicy.Unspecified, WriteIndented = true, DefaultIgnoreCondition = JsonIgnoreCondition.Never)] -internal partial class SettingsContext : JsonSerializerContext -{ - -} \ No newline at end of file +internal partial class SettingsContext : JsonSerializerContext; \ No newline at end of file diff --git a/Luski/Classes/ThemeSub/ServerThemeProperties.cs b/Luski/Classes/ThemeSub/ServerThemeProperties.cs index 69aa150..1082fce 100644 --- a/Luski/Classes/ThemeSub/ServerThemeProperties.cs +++ b/Luski/Classes/ThemeSub/ServerThemeProperties.cs @@ -7,5 +7,5 @@ public class ServerThemeProperties { [JsonInclude] [JsonPropertyName("selection_color")] - public Color SelectionColor { get; set; } = new("FFFFFF"); + public Color SelectionColor { get; set; } = new("FFFFFFFF"); } \ No newline at end of file diff --git a/Luski/Classes/UpdaterSettings.cs b/Luski/Classes/UpdaterSettings.cs index 63c467b..959e9ae 100644 --- a/Luski/Classes/UpdaterSettings.cs +++ b/Luski/Classes/UpdaterSettings.cs @@ -7,7 +7,8 @@ namespace Luski.Classes; public class UpdaterSettings { [JsonInclude] - [Description("Self Contained")] + [Shared.GlobalAttributes.DisplayName("Self Contained")] + [Description("This tells the updater to download the self contained version of the app.")] [JsonPropertyName("self_contained")] public bool SelfContained { get; set; } = false; @@ -20,16 +21,19 @@ public class UpdaterSettings public string Platform { get; set; } = "linux-x64"; [JsonInclude] - [Description("Auto Launch")] + [Shared.GlobalAttributes.DisplayName("Auto Launch")] + [Description("Tells the updater to relaunch the app after the update is complete.")] [JsonPropertyName("auto_launch")] public bool AutoLaunch { get; set; } = true; [JsonInclude] - [Description("Auto Update")] + [Description("If the app can check for updates and an update is available, then the app will start the update process automatically.")] + [Shared.GlobalAttributes.DisplayName("Auto Update")] [JsonPropertyName("auto_update")] public bool AutoUpdate { get; set; } = false; [JsonInclude] - [Description("Check For Updates")] + [Description("This will allow the client to check for update during the launch process.")] + [Shared.GlobalAttributes.DisplayName("Check For Updates")] [JsonPropertyName("update_check")] public bool AutoUpdateCheck { get; set; } = true; } diff --git a/Luski/ConsoleLog.cs b/Luski/ConsoleLog.cs index 8ea1ed6..7fe4f2d 100644 --- a/Luski/ConsoleLog.cs +++ b/Luski/ConsoleLog.cs @@ -1,4 +1,5 @@ using System.ComponentModel; +using Luski.Shared.GlobalAttributes; namespace Luski; @@ -6,16 +7,25 @@ namespace Luski; public enum ConsoleLog : long { None = 0, + [Shared.GlobalAttributes.DisplayName("OpenGL Errors")] [Description("Show OpenGL Major Errors")] BigErrosForOpenGL = 1, + [Shared.GlobalAttributes.DisplayName("OpenGL Medium Errors")] [Description("Show OpenGL Medium Errors")] MediumErrosForOpenGL = 2, + [Shared.GlobalAttributes.DisplayName("OpenGL Small Errors")] [Description("Show OpenGL Small Errors")] LowErrosForOpenGL = 4, + [Shared.GlobalAttributes.DisplayName("OpenGL Info")] [Description("Show OpenGL Info")] InfoForOpenGL = 8, - [Description("Show Draw Frams")] + [Shared.GlobalAttributes.DisplayName("Log Frames")] + [Description("Shows draw fram message in the console")] DrawFrames = 16, + [Shared.GlobalAttributes.DisplayName("Show Missing Charters")] [Description("Show Missing Charters")] - ShowMissingChar = 32 + ShowMissingChar = 32, + [Shared.GlobalAttributes.DisplayName("GLFW Errors")] + [Description("Show GLFW Errors")] + ShowErrorsForGLFW = 64 } \ No newline at end of file diff --git a/Luski/GUI/MainScreen/UI/AddServerOverlay.cs b/Luski/GUI/MainScreen/UI/AddServerOverlay.cs index 869effb..4f7b2cd 100644 --- a/Luski/GUI/MainScreen/UI/AddServerOverlay.cs +++ b/Luski/GUI/MainScreen/UI/AddServerOverlay.cs @@ -66,54 +66,50 @@ public class AddServerOverlay : UserControl, IServerOverlay AllowMultiLine = false }; tb.Textures[0] = Globals.ms.TextureManager.GetTextureResource("BadTextbox.png"); - tb.KeyPress += args => + tb.LetterPress += () => { - Texture t; Texture good = Globals.ms.TextureManager.GetTextureResource("Textbox.png"); - if ((args.Key == Keys.Backspace || args.Key == Keys.Delete) && string.IsNullOrWhiteSpace(tb.Text)) + + if (tb.Textures[0].handel != good.handel) { - t = Globals.ms.TextureManager.GetTextureResource("BadTextbox.png"); - } - else - { - t = good; - } - - if (tb.Textures[0].handel != t.handel) - { - tb.Textures[0] = t; - if (t.handel == good.handel && - UserName!.Textures[0].handel == good.handel && + tb.Textures[0] = good; + if (UserName!.Textures[0].handel == good.handel && Password!.Textures[0].handel == good.handel && (rec is null || rec.Textures.Count > 1) && btn!.Textures[0].handel != good.handel && tb.Textures[0].handel == good.handel) { - if (Selected!.l.Text != "Login") - { - if (DisplayName!.Textures[0].handel == good.handel) btn.Textures[0] = good; - } - else btn.Textures[0] = good; - } - else if (t.handel != good.handel && - (UserName!.Textures[0].handel != good.handel || - Password!.Textures[0].handel != good.handel || - (rec is not null && rec!.Textures.Count == 1) || - btn!.Textures[0].handel == good.handel || - tb.Textures[0].handel != good.handel || - (DisplayName is not null && DisplayName.Textures[0].handel != good.handel))) - { - btn!.Textures[0] = t; + btn.Textures[0] = good; } Globals.ms.TryDraw(); } + return Task.CompletedTask; + }; + tb.LetterRemoved += () => + { + Texture bad = Globals.ms.TextureManager.GetTextureResource("BadTextbox.png"); + + if (tb.Text.Length == 0 && tb.Textures[0].handel != bad.handel) + { + tb.Textures[0] = bad; + btn!.Textures[0] = bad; + Globals.ms.TryDraw(); + } + + return Task.CompletedTask; + }; + tb.KeyPress += args => + { + if (args.Key == Keys.Tab && !args.Shift) + { + UserName!.Focus(); + } return Task.CompletedTask; }; + tb.Size = new(Form.Size.X - tb.Location.X - tb.Location.X - tb.Location.X - s.X, tb.Size.Y); - Form.Controls.Add(tb); - version = new DropDown(Form.Textures[0], line) { DropDownParentOverride = Form, @@ -190,7 +186,7 @@ public class AddServerOverlay : UserControl, IServerOverlay Location = new(tb.Location.X, tb.Location.Y + tb.Location.X + tb.Size.Y, 0), OnPageLoad = () => { - btn.Textures[0] = Globals.ms.TextureManager.GetTextureResource("BadTextbox.png"); + btn!.Textures[0] = Globals.ms.TextureManager.GetTextureResource("BadTextbox.png"); page!.Controls.Add(UserName = new() { Location = new(0, 10.ScaleInt(), 0), @@ -200,41 +196,47 @@ public class AddServerOverlay : UserControl, IServerOverlay AllowMultiLine = false }); UserName.Textures[0] = Globals.ms.TextureManager.GetTextureResource("BadTextbox.png"); - UserName.KeyPress += args => + UserName.LetterPress += () => { - Texture t; Texture good = Globals.ms.TextureManager.GetTextureResource("Textbox.png"); - if ((args.Key == Keys.Backspace || args.Key == Keys.Delete || args.Alt || args.Shift || args.Control || args.Key == Keys.Enter || args.Key == Keys.KeyPadEnter || args.Key== Keys.Space) && string.IsNullOrWhiteSpace(UserName.Text)) + + if (UserName.Textures[0].handel != good.handel) { - t = Globals.ms.TextureManager.GetTextureResource("BadTextbox.png"); - } - else - { - t = good; - } - - if (UserName.Textures[0].handel != t.handel) - { - UserName.Textures[0] = t; - if (t.handel == good.handel && - Password!.Textures[0].handel == good.handel && - DisplayName!.Textures[0].handel == good.handel && - rec!.Textures.Count > 1 && - btn!.Textures[0].handel != good.handel && - tb.Textures[0].handel == good.handel) + UserName.Textures[0] = good; + if (Password!.Textures[0].handel == good.handel && DisplayName!.Textures[0].handel == good.handel && rec!.Textures.Count > 1 && btn!.Textures[0].handel != good.handel && tb.Textures[0].handel == good.handel) { btn.Textures[0] = good; } - else if (t.handel != good.handel && - (Password!.Textures[0].handel != good.handel || - DisplayName!.Textures[0].handel != good.handel || - rec!.Textures.Count == 1 || - btn!.Textures[0].handel == good.handel || tb.Textures[0].handel != good.handel)) - { - btn!.Textures[0] = t; - } Globals.ms.TryDraw(); } + return Task.CompletedTask; + }; + UserName.LetterRemoved += () => + { + Texture bad = Globals.ms.TextureManager.GetTextureResource("BadTextbox.png"); + + if (UserName.Text.Length == 0 && UserName.Textures[0].handel != bad.handel) + { + UserName.Textures[0] = bad; + btn.Textures[0] = bad; + Globals.ms.TryDraw(); + } + + return Task.CompletedTask; + }; + UserName.KeyPress += args => + { + if (args.Key == Keys.Tab) + { + if (args.Shift) + { + tb.Focus(); + } + else + { + Password!.Focus(); + } + } return Task.CompletedTask; }; @@ -249,36 +251,50 @@ public class AddServerOverlay : UserControl, IServerOverlay PasswordChar = '●' }); Password.Textures[0] = UserName.Textures[0]; - Password.KeyPress += args => + Password.LetterPress += () => { - Texture t; Texture good = Globals.ms.TextureManager.GetTextureResource("Textbox.png"); - if ((args.Key == Keys.Backspace || args.Key == Keys.Delete || args.Alt || args.Shift || args.Control || args.Key == Keys.Enter || args.Key == Keys.KeyPadEnter || args.Key== Keys.Space) && string.IsNullOrWhiteSpace(Password.Text)) + + if (Password.Textures[0].handel != good.handel) { - t = Globals.ms.TextureManager.GetTextureResource("BadTextbox.png"); - } - else - { - t = good; - } - - if (Password.Textures[0].handel != t.handel) - { - Password.Textures[0] = t; - if (t.handel == good.handel && UserName!.Textures[0].handel == good.handel && DisplayName!.Textures[0].handel == good.handel && rec!.Textures.Count > 1 && btn!.Textures[0].handel != good.handel && tb.Textures[0].handel == good.handel) + Password.Textures[0] = good; + if (UserName!.Textures[0].handel == good.handel && DisplayName!.Textures[0].handel == good.handel && rec!.Textures.Count > 1 && btn!.Textures[0].handel != good.handel && tb.Textures[0].handel == good.handel) { btn.Textures[0] = good; } - else if (t.handel != good.handel && (UserName!.Textures[0].handel != good.handel || DisplayName!.Textures[0].handel != good.handel || rec!.Textures.Count == 1 || btn!.Textures[0].handel == good.handel || tb.Textures[0].handel != good.handel)) - { - btn!.Textures[0] = t; - } Globals.ms.TryDraw(); } + return Task.CompletedTask; + }; + Password.LetterRemoved += () => + { + Texture bad = Globals.ms.TextureManager.GetTextureResource("BadTextbox.png"); + + if (Password.Text.Length == 0 && Password.Textures[0].handel != bad.handel) + { + Password.Textures[0] = bad; + btn.Textures[0] = bad; + Globals.ms.TryDraw(); + } + + return Task.CompletedTask; + }; + Password.KeyPress += args => + { + if (args.Key == Keys.Tab) + { + if (args.Shift) + { + UserName.Focus(); + } + else + { + DisplayName!.Focus(); + } + } return Task.CompletedTask; }; - page.Controls.Add(rec = new(Globals.ms.TextureManager.GetAlphaCircle()) { Size = new(50.ScaleInt()), @@ -296,44 +312,47 @@ public class AddServerOverlay : UserControl, IServerOverlay TextLocation = TextLocation.LineCenter, AllowMultiLine = false }); - DisplayName.KeyPress += args => + DisplayName.LetterPress += () => { - Texture t; Texture good = Globals.ms.TextureManager.GetTextureResource("Textbox.png"); - if ((args.Key == Keys.Backspace || args.Key == Keys.Delete || args.Alt || args.Shift || args.Control || args.Key == Keys.Enter || args.Key == Keys.KeyPadEnter || args.Key== Keys.Space) && - string.IsNullOrWhiteSpace(UserName.Text)) + + if (DisplayName.Textures[0].handel != good.handel) { - t = Globals.ms.TextureManager.GetTextureResource("BadTextbox.png"); - } - else - { - t = good; - } - - if (DisplayName.Textures[0].handel != t.handel) - { - DisplayName.Textures[0] = t; - if (t.handel == good.handel && UserName!.Textures[0].handel == good.handel && - Password!.Textures[0].handel == good.handel && rec!.Textures.Count > 1 && - btn!.Textures[0].handel != good.handel && tb.Textures[0].handel == good.handel) + DisplayName.Textures[0] = good; + if (UserName!.Textures[0].handel == good.handel && Password!.Textures[0].handel == good.handel && rec!.Textures.Count > 1 && btn!.Textures[0].handel != good.handel && tb.Textures[0].handel == good.handel) { btn.Textures[0] = good; } - else if (t.handel != good.handel && (UserName!.Textures[0].handel != good.handel || - Password!.Textures[0].handel != good.handel || - rec!.Textures.Count == 1 || - btn!.Textures[0].handel == good.handel || tb.Textures[0].handel != good.handel)) - { - btn!.Textures[0] = t; - } - Globals.ms.TryDraw(); } return Task.CompletedTask; }; + DisplayName.LetterRemoved += () => + { + Texture bad = Globals.ms.TextureManager.GetTextureResource("BadTextbox.png"); + + if (DisplayName.Text.Length == 0 && DisplayName.Textures[0].handel != bad.handel) + { + DisplayName.Textures[0] = bad; + btn.Textures[0] = bad; + Globals.ms.TryDraw(); + } + + return Task.CompletedTask; + }; + DisplayName.KeyPress += args => + { + if (args.Key == Keys.Tab && args.Shift) + { + Password.Focus(); + } + + return Task.CompletedTask; + }; rec.FilesDroped += RecOnFilesDroped; DisplayName.Textures[0] = UserName.Textures[0]; rec.ForceDistanceUpdate(page); + tb.Focus(); Globals.ms.TryDraw(); } }; @@ -359,42 +378,51 @@ public class AddServerOverlay : UserControl, IServerOverlay AllowMultiLine = false }); UserName.Textures[0] = Globals.ms.TextureManager.GetTextureResource("BadTextbox.png"); - UserName.KeyPress += args => + UserName.LetterPress += () => { - Texture t; Texture good = Globals.ms.TextureManager.GetTextureResource("Textbox.png"); - if ((args.Key == Keys.Backspace || args.Key == Keys.Delete || args.Alt || args.Shift || args.Control || args.Key == Keys.Enter || args.Key == Keys.KeyPadEnter || args.Key== Keys.Space) && string.IsNullOrWhiteSpace(UserName.Text)) + + if (UserName.Textures[0].handel != good.handel) { - t = Globals.ms.TextureManager.GetTextureResource("BadTextbox.png"); - } - else - { - t = good; - } - - if (UserName.Textures[0].handel != t.handel) - { - UserName.Textures[0] = t; - if (t.handel == good.handel && - Password!.Textures[0].handel == good.handel && - btn!.Textures[0].handel != good.handel && - tb.Textures[0].handel == good.handel) + UserName.Textures[0] = good; + if (Password!.Textures[0].handel == good.handel && btn.Textures[0].handel != good.handel && tb.Textures[0].handel == good.handel) { btn.Textures[0] = good; } - else if (t.handel != good.handel && - (Password!.Textures[0].handel != good.handel || - btn!.Textures[0].handel == good.handel || tb.Textures[0].handel != good.handel)) - { - btn!.Textures[0] = t; - } Globals.ms.TryDraw(); } + return Task.CompletedTask; + }; + UserName.LetterRemoved += () => + { + Texture bad = Globals.ms.TextureManager.GetTextureResource("BadTextbox.png"); + + if (UserName.Text.Length == 0 && UserName.Textures[0].handel != bad.handel) + { + UserName.Textures[0] = bad; + btn.Textures[0] = bad; + Globals.ms.TryDraw(); + } + + return Task.CompletedTask; + }; + UserName.KeyPress += args => + { + if (args.Key == Keys.Tab) + { + if (args.Shift) + { + tb.Focus(); + } + else + { + Password!.Focus(); + } + } return Task.CompletedTask; }; UserName.Size = UserName.Size; - page.Controls.Add(Password = new() { Location = new(0, UserName.Location.Y + UserName.Size.Y + UserName.Location.Y + UserName.Location.Y, 0), @@ -405,39 +433,40 @@ public class AddServerOverlay : UserControl, IServerOverlay PasswordChar = '●' }); Password.Textures[0] = UserName.Textures[0]; - Password.KeyPress += args => + Password.LetterPress += () => { - Texture t; Texture good = Globals.ms.TextureManager.GetTextureResource("Textbox.png"); - if ((args.Key == Keys.Backspace || args.Key == Keys.Delete || args.Alt || args.Shift || args.Control || args.Key == Keys.Enter || args.Key == Keys.KeyPadEnter || args.Key== Keys.Space) && - string.IsNullOrWhiteSpace(Password.Text)) + + if (Password.Textures[0].handel != good.handel) { - t = Globals.ms.TextureManager.GetTextureResource("BadTextbox.png"); - } - else - { - t = good; - } - - if (Password.Textures[0].handel != t.handel) - { - Password.Textures[0] = t; - if (t.handel == good.handel && - UserName!.Textures[0].handel == good.handel && - btn!.Textures[0].handel != good.handel && - tb.Textures[0].handel == good.handel) + Password.Textures[0] = good; + if (UserName.Textures[0].handel == good.handel && btn.Textures[0].handel != good.handel && tb.Textures[0].handel == good.handel) { btn.Textures[0] = good; } - else if (t.handel != good.handel && - (UserName!.Textures[0].handel != good.handel || - btn!.Textures[0].handel == good.handel || tb.Textures[0].handel != good.handel)) - { - btn!.Textures[0] = t; - } - Globals.ms.TryDraw(); } + return Task.CompletedTask; + }; + Password.LetterRemoved += () => + { + Texture bad = Globals.ms.TextureManager.GetTextureResource("BadTextbox.png"); + + if (Password.Text.Length == 0 && Password.Textures[0].handel != bad.handel) + { + Password.Textures[0] = bad; + btn.Textures[0] = bad; + Globals.ms.TryDraw(); + } + + return Task.CompletedTask; + }; + Password.KeyPress += args => + { + if (args.Key == Keys.Tab && args.Shift) + { + UserName.Focus(); + } return Task.CompletedTask; }; @@ -445,6 +474,7 @@ public class AddServerOverlay : UserControl, IServerOverlay Password.ForceDistanceUpdate(page); DisplayName = null!; rec = null!; + tb.Focus(); Globals.ms.ForceUpdate(new(Globals.ms.CS)); TryDraw(); } @@ -467,8 +497,6 @@ public class AddServerOverlay : UserControl, IServerOverlay BackgroundColor = Form.BackgroundColor }; page.Size = new(Form.Size.X - tb.Location.X - tb.Location.X, Form.Size.Y - tb.Location.X - page.Location.Y - ca.Size.Y - tb.Location.X); - Console.Write(page.Size.Y - tb.Location.X - tb.Location.X - (50*2*3)); - Console.WriteLine(page.Size); Form.Controls.Add(page); btn = new(Globals.ms.TextureManager.GetTextureResource("BadTextbox.png")) @@ -478,6 +506,7 @@ public class AddServerOverlay : UserControl, IServerOverlay TextureDisplay = TextureDisplay.Center }; _ = ca.ToggleSelected(); + tb.Focus(); Label sub = new(Globals.DefaultFont) { Text = "Submit", diff --git a/Luski/GUI/MainScreen/UI/LuskiControls/TextBox.cs b/Luski/GUI/MainScreen/UI/LuskiControls/TextBox.cs index 0fb71c8..40b2534 100644 --- a/Luski/GUI/MainScreen/UI/LuskiControls/TextBox.cs +++ b/Luski/GUI/MainScreen/UI/LuskiControls/TextBox.cs @@ -18,7 +18,7 @@ public class TextBox : UserControl private Rectangle Pointer; private Timer t; - public int CursorLocation { get; set; } = 0; + public int CursorLocation { get; set; } public TextBox() :base(Globals.ms.TextureManager.GetTextureResource("Textbox.png")) @@ -54,13 +54,15 @@ public class TextBox : UserControl private void TOnElapsed(object? sender, ElapsedEventArgs e) { - Globals.ms.Invoke(new Action(() => + Globals.ms.Invoke(() => { Pointer.Visible = !Pointer.Visible; - })); + }); } public event Func? KeyPress; + public event Func? LetterPress; + public event Func? LetterRemoved; public override void UnFocus() { @@ -90,24 +92,30 @@ public class TextBox : UserControl { if (Loaded) return; window.MouseDown += Window_MouseDown; - window.KeyDown += Window_KeyDown; - window.TextInput += WindowOnTextInput; if (!window.Context.IsCurrent) window.Context.MakeCurrent(); base.LoadToParent(parent, window); Pointer.Location = _watermark.Location; } - - private void WindowOnTextInput(TextInputEventArgs obj) + + public override void SendClipEvent(string ClipString) { + base.SendClipEvent(ClipString); if (!use) return; - Text = Text.Insert((int)CursorLocation, obj.AsString); - CursorLocation += obj.AsString.Length; - var f = _label.GetCharLocation((int)CursorLocation); - Pointer.Location = _label.Location + new Vector3i(f.X, f.Y, 0); - Pointer.Visible = true; + try + { + Text = Text.Insert(CursorLocation, ClipString); + CursorLocation += ClipString.Length; + Vector2i f = _label.GetCharLocation(CursorLocation); + Pointer.Location = _label.Location + new Vector3i(f.X, f.Y, 0); + Pointer.Visible = true; + if (LetterPress is not null) LetterPress.Invoke().Wait(); + } + catch + { + // ignored + } } - public char? PasswordChar { get => _label.PasswordChar; set => _label.PasswordChar = value; } private TextLocation tl = TextLocation.TopLeft; @@ -259,57 +267,56 @@ public class TextBox : UserControl public event Func? OnNewLine; public event Func? OnRemoveLine; - - private void Window_KeyDown(KeyboardKeyEventArgs obj) + + public override void SendKeyEvent(KeyboardKeyEventArgs KeyArgs) { + base.SendKeyEvent(KeyArgs); if (!use) return; - if (obj.Key == Keys.Left) + if (KeyArgs.Key == Keys.Left && CursorLocation != 0) { CursorLocation--; - var f = _label.GetCharLocation((int)CursorLocation); + var f = _label.GetCharLocation(CursorLocation); Pointer.Location = _label.Location + new Vector3i(f.X, f.Y, 0); Pointer.Visible = true; } - if (obj.Key == Keys.Right) + if (KeyArgs.Key == Keys.Right && CursorLocation != Text.Length) { - if (CursorLocation != Text.Length) - { - CursorLocation++; - var f = _label.GetCharLocation((int)CursorLocation); - Pointer.Location = _label.Location + new Vector3i(f.X, f.Y, 0); - Pointer.Visible = true; - } - + CursorLocation++; + var f = _label.GetCharLocation(CursorLocation); + Pointer.Location = _label.Location + new Vector3i(f.X, f.Y, 0); + Pointer.Visible = true; } - if (obj.Key == Keys.CapsLock || obj.Key == Keys.Menu || obj.Key == Keys.LeftSuper || obj.Key == Keys.RightSuper || obj.Key == Keys.End || obj.Key == Keys.Home || obj.Key == Keys.PageDown || obj.Key == Keys.PageUp || obj.Key == Keys.Insert || obj.Key == Keys.Up || obj.Key == Keys.Down || obj.Key == Keys.Left || obj.Key == Keys.Right) return; - if (obj.Key == Keys.Backspace) + if (KeyArgs.Key == Keys.CapsLock || KeyArgs.Key == Keys.Menu || KeyArgs.Key == Keys.LeftSuper || KeyArgs.Key == Keys.RightSuper || KeyArgs.Key == Keys.End || KeyArgs.Key == Keys.Home || KeyArgs.Key == Keys.PageDown || KeyArgs.Key == Keys.PageUp || KeyArgs.Key == Keys.Insert || KeyArgs.Key == Keys.Up || KeyArgs.Key == Keys.Down || KeyArgs.Key == Keys.Left || KeyArgs.Key == Keys.Right) return; + if (KeyArgs.Key == Keys.Backspace) { if (!(Text.Length > 0)) return; if (Text[CursorLocation- 1] == '\n') { Size = new(Size.X, Size.Y - (int)_label.Font.PixelHeight); - if (OnRemoveLine is not null) OnRemoveLine.Invoke(); + if (OnRemoveLine is not null) OnRemoveLine.Invoke().Wait(); } CursorLocation--; Text = Text.Remove(CursorLocation, 1); + if (LetterRemoved is not null) LetterRemoved.Invoke().Wait(); var f = _label.GetCharLocation(CursorLocation); Pointer.Location = _label.Location + new Vector3i(f.X, f.Y, 0); Pointer.Visible = true; } - if (obj.Key == Keys.Delete) + if (KeyArgs.Key == Keys.Delete) { if (CursorLocation == Text.Length) return; if (Text[CursorLocation] == '\n') { Size = new(Size.X, Size.Y - (int)_label.Font.PixelHeight); - if (OnRemoveLine is not null) OnRemoveLine.Invoke(); + if (OnRemoveLine is not null) OnRemoveLine.Invoke().Wait(); } Text = Text.Remove(CursorLocation, 1); + if (LetterRemoved is not null) LetterRemoved.Invoke().Wait(); } - if (obj.Key == Keys.Enter) + if (KeyArgs.Key == Keys.Enter) { - if (AllowMultiLine && obj.Shift) + if (AllowMultiLine && KeyArgs.Shift) { BlockDraw = true; Size = new(Size.X, Size.Y + (int)_label.Font.PixelHeight); @@ -323,12 +330,23 @@ public class TextBox : UserControl } } - - - if (obj.Key == Keys.V && obj.Control && Window is not null) Text += Window.ClipboardString; - if (KeyPress is not null) _ = KeyPress.Invoke(obj); - } + + if (KeyArgs.Key == Keys.V && KeyArgs.Control && Window is not null) + { + try + { + Text += Window.ClipboardString; + if (LetterPress is not null) LetterPress.Invoke().Wait(); + } + catch + { + // ignored + } + } + if (KeyPress is not null) _ = KeyPress.Invoke(KeyArgs); + } + private void Window_MouseDown(MouseButtonEventArgs e) { if (MouseInside && e.Button == MouseButton.Button1) diff --git a/Luski/GUI/MainScreen/UI/LuskiSettings/Core/ISettingsPage.cs b/Luski/GUI/MainScreen/UI/LuskiSettings/Core/ISettingsPage.cs new file mode 100644 index 0000000..a026438 --- /dev/null +++ b/Luski/GUI/MainScreen/UI/LuskiSettings/Core/ISettingsPage.cs @@ -0,0 +1,12 @@ +using GraphicsManager.Interfaces; +using GraphicsManager.Objects.Core; +using OpenTK.Mathematics; + +namespace Luski.GUI.MainScreen.UI.LuskiSettings.Core; + +public interface ISettingsPage : IRenderObject +{ + public string PageName { get; set; } + public FontInteraction TitleFont { get; set; } + public Color4 BackgroundColor { get; set; } +} \ No newline at end of file diff --git a/Luski/GUI/MainScreen/UI/LuskiSettings/Core/PageFlow.cs b/Luski/GUI/MainScreen/UI/LuskiSettings/Core/PageFlow.cs new file mode 100644 index 0000000..3b676bd --- /dev/null +++ b/Luski/GUI/MainScreen/UI/LuskiSettings/Core/PageFlow.cs @@ -0,0 +1,38 @@ +using GraphicsManager.Enums; +using GraphicsManager.Objects; +using GraphicsManager.Objects.Core; + +namespace Luski.GUI.MainScreen.UI.LuskiSettings.Core; + +public class PageFlow : FlowLayout, ISettingsPage +{ + public string PageName + { + get + { + return pn; + } + set + { + pn = value; + TitleLable.Text = $" \n{value}\n "; + } + } + public FontInteraction TitleFont { get; set; } + + public Label TitleLable; + private string pn = "Blank Page"; + + public PageFlow() + { + TitleFont = Globals.DefaultFont.Clone(); + TitleFont.FontSize = FontSize.Bold; + TitleFont.PixelHeight = (uint)(TitleFont.PixelHeight * 1.4f); + Controls.Add(TitleLable = new Label(TitleFont) + { + Text = $" \nBlank Page\n " + }); + base.Visible = false; + base.Size = new(945.ScaleInt(), 896.ScaleInt()); + } +} \ No newline at end of file diff --git a/Luski/GUI/MainScreen/UI/SettingsPanel/CategoryButton.cs b/Luski/GUI/MainScreen/UI/LuskiSettings/Core/PageTab.cs similarity index 86% rename from Luski/GUI/MainScreen/UI/SettingsPanel/CategoryButton.cs rename to Luski/GUI/MainScreen/UI/LuskiSettings/Core/PageTab.cs index 84fe7d9..63f13a8 100644 --- a/Luski/GUI/MainScreen/UI/SettingsPanel/CategoryButton.cs +++ b/Luski/GUI/MainScreen/UI/LuskiSettings/Core/PageTab.cs @@ -4,16 +4,16 @@ using GraphicsManager.Objects; using GraphicsManager.Objects.Core; using OpenTK.Mathematics; -namespace Luski.GUI.MainScreen.UI.SettingsPanel; +namespace Luski.GUI.MainScreen.UI.LuskiSettings.Core; -public class CategoryButton : UserControl +public class PageTab : UserControl { public static Texture? seltec = null; private SettingsMenu SM; private Label l; - public required Action OnPageLoad; + public required IRenderObject Page; - public CategoryButton(string Text, SettingsMenu SM) + public PageTab(string Text, SettingsMenu SM) :base(seltec) { this.SM = SM; @@ -30,7 +30,7 @@ public class CategoryButton : 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 => { @@ -79,10 +79,10 @@ public class CategoryButton : UserControl l.Color = f; if (Selected) { + if (SM.Selected is not null) SM.Selected.Page.Visible = false; SM.Selected = this; Globals.ms.Title = $"Settings | {l.Text} - Luski"; - SM.page.Controls.Clear(); - OnPageLoad.Invoke(); + Page.Visible = true; } BlockDraw = false; diff --git a/Luski/GUI/MainScreen/UI/LuskiSettings/Core/SettingsCategory.cs b/Luski/GUI/MainScreen/UI/LuskiSettings/Core/SettingsCategory.cs new file mode 100644 index 0000000..195625a --- /dev/null +++ b/Luski/GUI/MainScreen/UI/LuskiSettings/Core/SettingsCategory.cs @@ -0,0 +1,80 @@ +using GraphicsManager.Enums; +using GraphicsManager.Objects; +using GraphicsManager.Objects.Core; +using OpenTK.Mathematics; + +namespace Luski.GUI.MainScreen.UI.LuskiSettings.Core; + +public class SettingsCategory : UserControl +{ + private Label Top; + private static FontInteraction? fi; + private Rectangle line; + public string Name + { + get => Top.Text; + } + + private SettingsMenu ss; + + public SettingsCategory(string Name, SettingsMenu SS) + { + ss = SS; + if (fi is null) + { + fi = Globals.DefaultFont.Clone(); + fi.FontSize = FontSize.Bold; + } + Top = new(fi) + { + Location = new(5.ScaleInt(), 5.ScaleInt(), 0), + Text = Name + }; + base.BackgroundColor = new(255, 255, 255, 0); + base.Size = new(307.ScaleInt(), 20.ScaleInt() + Top.Size.Y); + Top.Location = new((base.Size.X - Top.Size.X) / 2, Top.Location.Y, 0); + line = new() + { + Size = new(base.Size.X, 1.ScaleInt()), + BackgroundColor = Color4.Gray, + Location = new(0, base.Size.Y - 1.ScaleInt(), 0) + }; + line.ForceDistanceUpdate(this); + Controls.Add(line); + Controls.Add(Top); + } + + public PageTab AddPage(TPage Page) where TPage : ISettingsPage + { + Page.Location = new(ss.fl.Size.X + 40.ScaleInt(), 0, 0); + Page.Size = new(Globals.ms.CS.X - ss.fl.Size.X - 80.ScaleInt(), Globals.ms.CS.Y); + Page.AllowHoverFromBehind = true; + Page.Anchor = ObjectAnchor.All; + Page.BackgroundColor = ss.BackgroundColor; + ss.Controls.Add(Page); + if (Page is PageFlow pbf) pbf.HScrollPixels = Globals.Settings.PerScrollPixels; + PageTab cb = new(Page.PageName, ss) + { + Page = Page + }; + Controls.Add(cb); + int f = 5.ScaleInt(); + cb.Location = new (line.Location.X + f, line.Location.Y - f, 0); + line.Location = new(line.Location.X, line.Location.Y + cb.Size.Y + f, 0); + Size = new(Size.X, Size.Y + cb.Size.Y + f); + Page.Tag = cb; + return cb; + } + + public void RemovePage(TPage Page) where TPage : ISettingsPage + { + if (Page.Tag is PageTab cb) + { + int f = 5.ScaleInt(); + line.Location = new(line.Location.X, line.Location.Y - cb.Size.Y - f, 0); + Size = new(Size.X, Size.Y - cb.Size.Y - f); + Controls.Remove(cb); + } + ss.Controls.Remove(Page); + } +} \ No newline at end of file diff --git a/Luski/GUI/MainScreen/UI/LuskiSettings/Pages/AdvancedSettings/ExperimentSettings.cs b/Luski/GUI/MainScreen/UI/LuskiSettings/Pages/AdvancedSettings/ExperimentSettings.cs new file mode 100644 index 0000000..f1b37c4 --- /dev/null +++ b/Luski/GUI/MainScreen/UI/LuskiSettings/Pages/AdvancedSettings/ExperimentSettings.cs @@ -0,0 +1,30 @@ +using GraphicsManager.Objects; +using Luski.Classes; +using Luski.GUI.MainScreen.UI.LuskiSettings.Core; +using Luski.GUI.MainScreen.UI.SettingsPanel; + +namespace Luski.GUI.MainScreen.UI.LuskiSettings.Pages.AdvancedSettings; + +public class ExperimentSettings : PageFlow +{ + public ExperimentSettings() + { + base.Size = new(500.ScaleInt()); + PageName = "Experiments"; + ExperimentGUI? g = null; + foreach (ExperimentInfo exp in Globals.Experiments) + { + g = new(exp); + Controls.Add(g); + } + + if (g is not null) + { + g.line.WindowLoaded += _ => + { + ParentResize(new(Globals.ms.ClientSize)); + return Task.CompletedTask; + }; + } + } +} \ No newline at end of file diff --git a/Luski/GUI/MainScreen/UI/LuskiSettings/Pages/AdvancedSettings/Updater.cs b/Luski/GUI/MainScreen/UI/LuskiSettings/Pages/AdvancedSettings/Updater.cs new file mode 100644 index 0000000..2e63702 --- /dev/null +++ b/Luski/GUI/MainScreen/UI/LuskiSettings/Pages/AdvancedSettings/Updater.cs @@ -0,0 +1,91 @@ +using System.Reflection; +using GraphicsManager.Enums; +using Luski.Classes; +using Luski.GUI.MainScreen.UI.LuskiControls; +using Luski.GUI.MainScreen.UI.LuskiSettings.Core; + +namespace Luski.GUI.MainScreen.UI.LuskiSettings.Pages.AdvancedSettings; + +public class Updater : PageFlow +{ + public Updater() + { + PageName = "Updater Config"; + TextBox t; + Controls.Add(t =new TextBox() + { + Text = Globals.UpdaterSettings.Updater!, + WatermarkText = "Updater File", + TextureDisplay = TextureDisplay.Center, + Size = new(base.Size.X, 34.ScaleInt()), + 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 + { + Globals.AddBool(this, PropType, val, ((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.UpdaterSettings, e); + } + Globals.UpdaterSettings.SaveSettings(Path.Combine(Globals.LuskiPath, "UpdaterSettings.json"), UpdaterSettingsContext.Default.UpdaterSettings); + }); + } + catch + { + //ignore + } + } + } + if (PropType.FullName == typeof(bool).FullName) + { + try + { + Globals.AddBool(this, prop, (bool)PropVal, b => + { + prop.SetValue(Globals.UpdaterSettings, b); + Globals.UpdaterSettings.SaveSettings(Path.Combine(Globals.LuskiPath, "UpdaterSettings.json"), UpdaterSettingsContext.Default.UpdaterSettings); + }); + } + catch + { + // ignored + } + } + } + + t.ForceDistanceUpdate(this); + t.KeyPress += _ => + { + Globals.UpdaterSettings.Updater = t.Text; + Globals.UpdaterSettings.SaveSettings(Path.Combine(Globals.LuskiPath, "UpdaterSettings.json"), UpdaterSettingsContext.Default.UpdaterSettings); + return Task.CompletedTask; + }; + WindowLoaded += _ => + { + Globals.ms.ForceUpdate(new(Globals.ms.CS)); + return Task.CompletedTask; + }; + } +} \ No newline at end of file diff --git a/Luski/GUI/MainScreen/UI/LuskiSettings/Pages/AppSettings/Appearance.cs b/Luski/GUI/MainScreen/UI/LuskiSettings/Pages/AppSettings/Appearance.cs new file mode 100644 index 0000000..c230126 --- /dev/null +++ b/Luski/GUI/MainScreen/UI/LuskiSettings/Pages/AppSettings/Appearance.cs @@ -0,0 +1,102 @@ +using GraphicsManager.Enums; +using GraphicsManager.Objects; +using Luski.Classes; +using Luski.GUI.MainScreen.UI.LuskiControls; +using Luski.GUI.MainScreen.UI.LuskiSettings.Core; +using Luski.GUI.MainScreen.UI.SettingsPanel; +using OpenTK.Mathematics; + +namespace Luski.GUI.MainScreen.UI.LuskiSettings.Pages.AppSettings; + +public class Appearance : PageFlow +{ + private DropDown ThemeDrop; + + public Appearance() + { + PageName = "Appearance"; + ThemeDropButton LightDD; + ThemeDrop = new(Globals.ms.TextureManager.GetTextureResource("RoundedRectangle.png"),new Rectangle() + { + Size = new(base.Size.X - 2, 1.ScaleInt()), + BackgroundColor = Color4.Gray, + Location = new(1, base.Size.Y - 1.ScaleInt(), 0), + Anchor = ObjectAnchor.Left | ObjectAnchor.Right | ObjectAnchor.Bottom + }, LightDD = new(LuskiThemes.Light) + { + LoadDisplay = () => + { + Label ll = new Label(Globals.DefaultFont) + { + Text = LuskiThemes.Light.Name, + Color = Color4.DarkGray, + IgnoreHover = true + }; + ll.Location = new(10.ScaleInt(), + ((ThemeDrop.Size.Y - ll.Size.Y) / 2) + , 0); + ThemeDrop.Controls.Add(ll); + }, + Size = new(297.ScaleInt(), 40.ScaleInt()), + }) + { + DropDownParentOverride = Globals.ms, + Size = new(40.ScaleInt()), + Location = new(5.ScaleInt(), 5.ScaleInt(), 0), + BackgroundColor = new(40, 40, 40, 255), + Anchor = ObjectAnchor.Right | ObjectAnchor.Left,}; + foreach (ThemeStart themeStart in LuskiThemes.LuskiThemeList) + { + if (themeStart.Name == LuskiThemes.Light.Name) continue; + ThemeDropButton tdb; + ThemeDrop.AddOption(tdb = new(themeStart) + { + LoadDisplay = () => + { + Label ll = new Label(Globals.DefaultFont) + { + Text = themeStart.Name, + Color = Color4.DarkGray, + IgnoreHover = true + }; + ll.Location = new(10.ScaleInt(), + ((ThemeDrop.Size.Y - ll.Size.Y) / 2) + , 0); + ThemeDrop.Controls.Add(ll); + }, + Size = new(297.ScaleInt(), 40.ScaleInt()), + }); + if (themeStart.Name == Globals.Settings.Theme) ThemeDrop.SetSelected(tdb); + } + ThemeDrop.DropDownContainer.Textures.Add(Globals.ms.TextureManager.GetTextureResource("RoundedRectangleBottom.png")); + ThemeDrop.DropDownContainer.TextureDisplay = TextureDisplay.Center; + ThemeDrop.DropDownContainer.Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context]; + ThemeDrop.DropDownContainer.BackgroundColor = ThemeDrop.BackgroundColor; + Rectangle line = new() + { + Size = new(base.Size.X - 2, 1.ScaleInt()), + BackgroundColor = Color4.Gray, + Location = new(1, base.Size.Y - 1.ScaleInt(), 0), + Anchor = ObjectAnchor.Left | ObjectAnchor.Right | ObjectAnchor.Bottom + }; + ThemeDrop.OpenStatusChanged += b => + { + BlockDraw = true; + Size = new(base.Size.X, base.Size.Y + ( b ? ThemeDrop.DropDownContainer.Size.Y : -1 * ThemeDrop.DropDownContainer.Size.Y)); + line!.Location = new(line.Location.X, + line.Location.Y + (b ? ThemeDrop.DropDownContainer.Size.Y : -1 * ThemeDrop.DropDownContainer.Size.Y), 0); + if (b) + { + ThemeDrop.Textures[0] = Globals.ms.TextureManager.GetTextureResource("RoundedRectangleTop.png"); + } + else + { + ThemeDrop.Textures[0] = Globals.ms.TextureManager.GetTextureResource("RoundedRectangle.png"); + } + + BlockDraw = false; + return Task.CompletedTask; + }; + Controls.Add(ThemeDrop); + } +} \ No newline at end of file diff --git a/Luski/GUI/MainScreen/UI/LuskiSettings/Pages/AppSettings/General.cs b/Luski/GUI/MainScreen/UI/LuskiSettings/Pages/AppSettings/General.cs new file mode 100644 index 0000000..12b8b17 --- /dev/null +++ b/Luski/GUI/MainScreen/UI/LuskiSettings/Pages/AppSettings/General.cs @@ -0,0 +1,65 @@ +using System.Reflection; +using Luski.Classes; +using Luski.GUI.MainScreen.UI.LuskiSettings.Core; + +namespace Luski.GUI.MainScreen.UI.LuskiSettings.Pages.AppSettings; + +public class General : PageFlow +{ + public General() + { + PageName = "General"; + 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 + { + Globals.AddBool(this, PropType, val, ((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 + { + Globals.AddBool(this, prop, (bool)PropVal, b => + { + prop.SetValue(Globals.Settings, b); + Globals.Settings.SaveSettings(Path.Combine(Globals.LuskiPath, "Settings.json"), SettingsContext.Default.Settings); + }); + } + catch + { + // ignored + } + } + } + } +} \ No newline at end of file diff --git a/Luski/GUI/MainScreen/UI/LuskiSettings/SettingsMenu.cs b/Luski/GUI/MainScreen/UI/LuskiSettings/SettingsMenu.cs new file mode 100644 index 0000000..20d2b4a --- /dev/null +++ b/Luski/GUI/MainScreen/UI/LuskiSettings/SettingsMenu.cs @@ -0,0 +1,81 @@ +using GraphicsManager.Enums; +using GraphicsManager.Interfaces; +using GraphicsManager.Objects; +using Luski.GUI.MainScreen.UI.LuskiSettings.Core; +using Luski.GUI.MainScreen.UI.LuskiSettings.Pages.AdvancedSettings; +using Luski.GUI.MainScreen.UI.LuskiSettings.Pages.AppSettings; +using OpenTK.Mathematics; + +namespace Luski.GUI.MainScreen.UI.LuskiSettings; + +public class SettingsMenu : UserControl +{ + private string BehindName; + public PageTab? Selected; + public FlowLayout fl; + private Appearance a; + + public SettingsMenu() + { + base.BackgroundColor = new(34, 34, 34, 255); + base.Size = Globals.ms.ClientSize; + BehindName = Globals.ms.Title; + Globals.ms.Title = $"Settings - Luski"; + fl = new() + { + BackgroundColor = new(20, 20, 20, 255), + Size = new(307.ScaleInt(), base.Size.Y), + Anchor = ObjectAnchor.Top | ObjectAnchor.Left | ObjectAnchor.Bottom + }; + SettingsCategory AppSettings = new("App Settings", this); + SettingsCategory AdvancedSettings = new("Advanced Settings", this); + PageTab cb = AppSettings.AddPage(new General()); + if (LuskiExperiments.Settings.Theme.IsEnabled()) _ = AppSettings.AddPage(a=new Appearance()); + LuskiExperiments.Settings.Theme.EventToggled += b => + { + if (b) + { + _ = AppSettings.AddPage(a=new Appearance()); + Globals.ms.ForceUpdate(new(Globals.ms.CS)); + } + else AppSettings.RemovePage(a!); + return Task.CompletedTask; + }; + _ = AdvancedSettings.AddPage(new ExperimentSettings()); + _ = AdvancedSettings.AddPage(new Updater()); + fl.Controls.Add(AppSettings); + fl.Controls.Add(AdvancedSettings); + cb.ToggleSelected().Wait(); + Anchor = ObjectAnchor.All; + Controls.Add(fl); + Rectangle closebtn = new(Globals.ms.TextureManager.GetTextureResource("close.png")) + { + Location = new(Globals.ms.ClientSize.X - 40.ScaleInt(), 8.ScaleInt(),0), + Size = new(32.ScaleInt()), + Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context], + BackgroundColor = Color4.Gray, + Anchor = ObjectAnchor.Top | ObjectAnchor.Right + }; + closebtn.MouseEnter += _ => + { + closebtn.BackgroundColor = Color4.White; + return Task.CompletedTask; + }; + closebtn.MouseLeave += _ => + { + closebtn.BackgroundColor = Color4.Gray; + return Task.CompletedTask; + }; + closebtn.Clicked += ClosebtnOnClicked; + closebtn.ForceDistanceUpdate(this); + Controls.Add(closebtn); + } + + private Task ClosebtnOnClicked(IRenderObject arg) + { + Globals.ms.Controls.Remove(this); + Globals.ms.Title = BehindName; + Globals.ms.DrawFrame(); + return Task.CompletedTask; + } +} \ No newline at end of file diff --git a/Luski/GUI/MainScreen/UI/PublicServers/ChannelSelector.cs b/Luski/GUI/MainScreen/UI/PublicServers/ChannelSelector.cs index 05301a9..30a6433 100644 --- a/Luski/GUI/MainScreen/UI/PublicServers/ChannelSelector.cs +++ b/Luski/GUI/MainScreen/UI/PublicServers/ChannelSelector.cs @@ -14,27 +14,45 @@ public class ChannelSelector : FlowLayout, IChannelAdder public SocketCategory CurrentCategory { get; } private readonly List cc = new(); private readonly List LoadedChannels = new(); + public Dictionary ChannelAdders = new(); public Channel? Selected; private ChannelSelector(SocketCategory Cat) { CurrentCategory = Cat; + ChannelAdders.Add(Cat.ID, this); Cat.Server.MessageReceived += ServerOnMessageReceived; } public static async Task MakeSelector(SocketCategory Cat) { ChannelSelector cs = new(Cat); - if (await Cat.Server.User.HasAccessToCategory(Cat, ServerPermission.CreateChannels)) + bool MakeChannels = await Cat.Server.User.HasAccessToCategory(Cat, ServerPermission.CreateChannels); + bool MakeRoles = await Cat.Server.User.HasPermissions(ServerPermission.ManageRoles); + if (MakeChannels || MakeRoles) { LuskiContextMenu lcm = new(); - Label l = lcm.AddLabel("Create Channel"); - l.Clicked += cs.LOnClicked; + if (MakeChannels) + { + Label l = lcm.AddLabel("Create Channel"); + l.Clicked += cs.LOnClicked; + } + if (MakeRoles) + { + Label l = lcm.AddLabel("Create Role"); + l.Clicked += cs.RLOnClicked; + } cs.ContextMenu = lcm; } return cs; } + + private async Task RLOnClicked(IRenderObject arg) + { + Globals.ms.Controls.Add(new AddChannel(this, CurrentCategory)); + TryDraw(); + } private async Task LOnClicked(IRenderObject arg) { diff --git a/Luski/GUI/MainScreen/UI/PublicServers/ChatMessage.cs b/Luski/GUI/MainScreen/UI/PublicServers/ChatMessage.cs index 89e2cb7..b0451bf 100644 --- a/Luski/GUI/MainScreen/UI/PublicServers/ChatMessage.cs +++ b/Luski/GUI/MainScreen/UI/PublicServers/ChatMessage.cs @@ -33,7 +33,7 @@ public class ChatMessage : UserControl ServerProfile prof = await message.GetProfile(CancellationToken.None); Color? c = await prof.GetColor(); if (c is null) c = await auth.GetColor(); - Color4 c4 = new(c.R, c.G, c.B, c.A); + Color4 c4 = c.ToColor4(); return new ChatMessage(p, message, await message.GetParent(CancellationToken.None), prof, await prof.MakeRct(auth, new(40.ScaleInt())), c4); } diff --git a/Luski/GUI/MainScreen/UI/PublicServers/PublicChat.cs b/Luski/GUI/MainScreen/UI/PublicServers/PublicChat.cs index d8ba652..05d39bc 100644 --- a/Luski/GUI/MainScreen/UI/PublicServers/PublicChat.cs +++ b/Luski/GUI/MainScreen/UI/PublicServers/PublicChat.cs @@ -42,10 +42,10 @@ public class PublicChat : UserControl HScrollPixels = Globals.Settings.PerScrollPixels, }); MessageFlow.FlowUpdate += MessageFlowOnFlowUpdate; - if (LuskiExperiments.GUI.MessageLiveSize.IsEnabled()) MessageFlow.SizeChanged += OnSizeChanged; - LuskiExperiments.GUI.MessageLiveSize.EventToggled += MessageLiveSizeOnEventToggled; + if (LuskiExperiments.GUI.LiveLabelSize.IsEnabled()) MessageFlow.SizeChanged += OnSizeChanged; + LuskiExperiments.GUI.LiveLabelSize.EventToggled += LiveLabelSizeOnEventToggled; - Task MessageLiveSizeOnEventToggled(bool arg) + Task LiveLabelSizeOnEventToggled(bool arg) { if (arg) MessageFlow.SizeChanged += OnSizeChanged; else MessageFlow.SizeChanged -= OnSizeChanged; diff --git a/Luski/GUI/MainScreen/UI/SettingsPanel/Category.cs b/Luski/GUI/MainScreen/UI/PublicServers/ServerSettingCategory.cs similarity index 58% rename from Luski/GUI/MainScreen/UI/SettingsPanel/Category.cs rename to Luski/GUI/MainScreen/UI/PublicServers/ServerSettingCategory.cs index 1722eb0..0f03e61 100644 --- a/Luski/GUI/MainScreen/UI/SettingsPanel/Category.cs +++ b/Luski/GUI/MainScreen/UI/PublicServers/ServerSettingCategory.cs @@ -1,11 +1,13 @@ using GraphicsManager.Enums; using GraphicsManager.Objects; using GraphicsManager.Objects.Core; +using Luski.GUI.MainScreen.UI.PublicServers.ServerSettingPages; +using Luski.GUI.MainScreen.UI.SettingsPanel; using OpenTK.Mathematics; -namespace Luski.GUI.MainScreen.UI.SettingsPanel; +namespace Luski.GUI.MainScreen.UI.PublicServers; -public class Category : UserControl +public class ServerSettingCategory : UserControl { private Label Top; private static FontInteraction? fi; @@ -15,8 +17,11 @@ public class Category : UserControl get => Top.Text; } - public Category(string Name) + private ServerSettings ss; + + public ServerSettingCategory(string Name, ServerSettings SS) { + ss = SS; if (fi is null) { fi = Globals.DefaultFont.Clone(); @@ -27,7 +32,7 @@ public class Category : UserControl Location = new(5.ScaleInt(), 5.ScaleInt(), 0), Text = Name }; - BackgroundColor = new(255, 255, 255, 0); + base.BackgroundColor = new(255, 255, 255, 0); base.Size = new(307.ScaleInt(), 20.ScaleInt() + Top.Size.Y); Top.Location = new((base.Size.X - Top.Size.X) / 2, Top.Location.Y, 0); line = new() @@ -40,26 +45,23 @@ public class Category : UserControl Controls.Add(line); Controls.Add(Top); } - - public void AddButton(CategoryButton cb) + + public ServerSettingPageTab AddPage(TPage Page) where TPage : IPageBase { + Page.Location = new(ss.fl.Size.X + 40.ScaleInt(), 0, 0); + Page.Size = new(Globals.ms.CS.X - ss.fl.Size.X - 80.ScaleInt(), Globals.ms.CS.Y); + Page.AllowHoverFromBehind = true; + Page.Anchor = ObjectAnchor.All; + if (Page is PageBaseFlow pbf) pbf.HScrollPixels = Globals.Settings.PerScrollPixels; + ServerSettingPageTab cb = new(Page.PageName, ss) + { + Page = Page + }; Controls.Add(cb); int f = 5.ScaleInt(); cb.Location = new (line.Location.X + f, line.Location.Y - f, 0); 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(); + return cb; } } \ No newline at end of file diff --git a/Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPageTab.cs b/Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPageTab.cs new file mode 100644 index 0000000..1ed131b --- /dev/null +++ b/Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPageTab.cs @@ -0,0 +1,96 @@ +using GraphicsManager.Enums; +using GraphicsManager.Interfaces; +using GraphicsManager.Objects; +using GraphicsManager.Objects.Core; +using OpenTK.Mathematics; + +namespace Luski.GUI.MainScreen.UI.PublicServers; + +public class ServerSettingPageTab : UserControl +{ + public static Texture? seltec = null; + private ServerSettings SM; + private Label l; + public required IRenderObject Page; + + public ServerSettingPageTab(string Text, ServerSettings SM) + :base(seltec) + { + this.SM = SM; + base.Size = new(297.ScaleInt(), 40.ScaleInt()); + TextureDisplay = TextureDisplay.HorizontalCenter; + Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context]; + l = new Label(Globals.DefaultFont) + { + Text = Text, + Color = Color4.Gray, + IgnoreHover = true + }; + l.Location = new(5.ScaleInt(), + ((base.Size.Y - l.Size.Y) / 2) + , 0); + Controls.Add(l); + base.BackgroundColor = new(0, 0, 0, 0); + Clicked += OnClicked; + MouseEnter += o => + { + if (!Selected) + { + BackgroundColor = new(141, 151, 165, 30); + } + return Task.CompletedTask; + }; + MouseLeave += o => + { + if (!Selected) + { + BackgroundColor = new(0,0,0,0); + } + return Task.CompletedTask; + }; + } + + private async Task OnClicked(IRenderObject arg) + { + if (!Selected) await ToggleSelected(); + } + + public bool Selected { get; private set; } + + public async Task ToggleSelected() + { + try + { + Color4 bc = new(141,151,165,51), f= Color4.White; + if (Selected) + { + bc = new (0,0,0,0); + f = Color4.Gray; + } + + BlockDraw = true; + Selected = !Selected; + + if (SM.Selected is not null && SM.Selected != this) + { + await SM.Selected.ToggleSelected(); + } + BackgroundColor = bc; + l.Color = f; + if (Selected) + { + if (SM.Selected is not null) SM.Selected.Page.Visible = false; + SM.Selected = this; + Globals.ms.Title = $"Server Settings | {l.Text} - Luski"; + Page.Visible = true; + } + + BlockDraw = false; + TryDraw(); + } + catch (Exception e) + { + Console.WriteLine(e); + } + } +} \ No newline at end of file diff --git a/Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPages/IPageBase.cs b/Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPages/IPageBase.cs new file mode 100644 index 0000000..a8bcb6d --- /dev/null +++ b/Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPages/IPageBase.cs @@ -0,0 +1,10 @@ +using GraphicsManager.Interfaces; +using GraphicsManager.Objects.Core; + +namespace Luski.GUI.MainScreen.UI.PublicServers.ServerSettingPages; + +public interface IPageBase : IRenderObject +{ + public string PageName { get; set; } + public FontInteraction TitleFont { get; set; } +} \ No newline at end of file diff --git a/Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPages/PageBaseControl.cs b/Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPages/PageBaseControl.cs new file mode 100644 index 0000000..7076b8b --- /dev/null +++ b/Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPages/PageBaseControl.cs @@ -0,0 +1,38 @@ +using GraphicsManager.Enums; +using GraphicsManager.Objects; +using GraphicsManager.Objects.Core; + +namespace Luski.GUI.MainScreen.UI.PublicServers.ServerSettingPages; + +public class PageBaseControl : UserControl, IPageBase +{ + public string PageName + { + get + { + return pn; + } + set + { + pn = value; + TitleLable.Text = $" \n{value}\n "; + } + } + public FontInteraction TitleFont { get; set; } + + public Label TitleLable; + private string pn = "Blank Page"; + + public PageBaseControl() + { + TitleFont = Globals.DefaultFont.Clone(); + TitleFont.FontSize = FontSize.Bold; + TitleFont.PixelHeight = (uint)(TitleFont.PixelHeight * 1.4f); + Controls.Add(TitleLable = new Label(TitleFont) + { + Text = $" \nBlank Page\n " + }); + base.Visible = false; + base.Size = new((16+231+48+508).ScaleInt()); + } +} \ No newline at end of file diff --git a/Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPages/PageBaseFlow.cs b/Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPages/PageBaseFlow.cs new file mode 100644 index 0000000..7999c80 --- /dev/null +++ b/Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPages/PageBaseFlow.cs @@ -0,0 +1,38 @@ +using GraphicsManager.Enums; +using GraphicsManager.Objects; +using GraphicsManager.Objects.Core; + +namespace Luski.GUI.MainScreen.UI.PublicServers.ServerSettingPages; + +public class PageBaseFlow : FlowLayout, IPageBase +{ + public string PageName + { + get + { + return pn; + } + set + { + pn = value; + TitleLable.Text = $" \n{value}\n "; + } + } + public FontInteraction TitleFont { get; set; } + + public Label TitleLable; + private string pn = "Blank Page"; + + public PageBaseFlow() + { + TitleFont = Globals.DefaultFont.Clone(); + TitleFont.FontSize = FontSize.Bold; + TitleFont.PixelHeight = (uint)(TitleFont.PixelHeight * 1.4f); + Controls.Add(TitleLable = new Label(TitleFont) + { + Text = $" \nBlank Page\n " + }); + base.Visible = false; + base.Size = new((16+231+48+508).ScaleInt()); + } +} \ No newline at end of file diff --git a/Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPages/RoleIcon.cs b/Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPages/RoleIcon.cs new file mode 100644 index 0000000..64967cd --- /dev/null +++ b/Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPages/RoleIcon.cs @@ -0,0 +1,73 @@ +using GraphicsManager.Enums; +using GraphicsManager.Objects; +using Luski.net.Structures.Public; +using OpenTK.Mathematics; +using SixLabors.ImageSharp.Processing; + +namespace Luski.GUI.MainScreen.UI.PublicServers.ServerSettingPages; + +public class RoleIcon : UserControl +{ + private ServerRoleInteraction SRI; + private Role ThisRole; + public RoleIcon(Role role, ServerRoleInteraction sri) + :base(Globals.ms.TextureManager.GetTextureResource("RoundedRectangle.png")) + { + SRI = sri; + ThisRole = role; + base.BackgroundColor = new (0,0,0,0); + TextureDisplay = TextureDisplay.HorizontalCenter; + Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context]; + base.Size = new(sri.RoleFlow.Size.X, 50.ScaleInt()); + Rectangle Color = new(Globals.ms.TextureManager.GetAlphaCircle()) + { + Size = new(12.ScaleInt()), + Location = new(4.ScaleInt(), 19.ScaleInt(), 0), + Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context], + IgnoreHover = true, + BackgroundColor = role.Color.ToColor4() + }; + Label name = new(Globals.ServerRoleFont) + { + Text = role.DisplayName, + IgnoreHover = true + }; + name.Location = new(Color.Location.X + Color.Size.X + 4.ScaleInt(), + (Color.Location.Y + ((Color.Size.Y - name.Size.Y) / 2)), 0); + Controls.Add(name); + Controls.Add(Color); + Clicked += _ => + { + if (sri.Selected != this) + { + sri.Selected.SetSelected(false); + sri.Selected = this; + SetSelected(true); + } + return Task.CompletedTask; + }; + MouseEnter += _ => + { + BackgroundColor = new(141, 151, 165, 30); + return Task.CompletedTask; + }; + MouseLeave += _ => + { + BackgroundColor = sri.Selected == this ? new(141, 151, 165, 51) : new(0, 0, 0, 0); + return Task.CompletedTask; + }; + } + + public void SetSelected(bool value) + { + if (value) + { + BackgroundColor = new(141, 151, 165, 51); + SRI.SRO.LoadRole(ThisRole); + } + else + { + BackgroundColor = new(0, 0, 0, 0); + } + } +} \ No newline at end of file diff --git a/Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPages/SaveWarning.cs b/Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPages/SaveWarning.cs new file mode 100644 index 0000000..3ea740c --- /dev/null +++ b/Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPages/SaveWarning.cs @@ -0,0 +1,56 @@ +using GraphicsManager.Enums; +using GraphicsManager.Objects; +using OpenTK.Mathematics; + +namespace Luski.GUI.MainScreen.UI.PublicServers.ServerSettingPages; + +public class SaveWarning : UserControl +{ + public event Func? SaveClicked; + + public SaveWarning() + { + Label warning = new(Globals.DefaultFont) + { + Text = "Careful — you have unsaved changes!", + IgnoreHover = true + }; + Label savetext = new(Globals.DefaultFont) + { + Text = "Save Changes", + IgnoreHover = true + }; + Controls.Add(warning); + base.Size = new(700.ScaleInt(), 52.ScaleInt()); + int space = 10.ScaleInt(); + UserControl uc = new() + { + BackgroundColor = new(36, 128, 70, 255), + Size = new(140.ScaleInt(), 32.ScaleInt()), + Anchor = ObjectAnchor.Right | ObjectAnchor.Top | ObjectAnchor.Bottom + }; + savetext.Location = new((uc.Size.X - savetext.Size.X) / 2, ((uc.Size.Y - savetext.Size.Y) / 2), 0); + uc.MouseEnter += _ => + { + uc.BackgroundColor = new(26, 99, 52, 255); + return Task.CompletedTask; + }; + uc.MouseLeave += _ => + { + uc.BackgroundColor = new(36, 128, 70, 255); + return Task.CompletedTask; + }; + uc.Clicked += _ => + { + if (SaveClicked is not null) return SaveClicked.Invoke(); + return Task.CompletedTask; + }; + uc.Location = new(base.Size.X - space - uc.Size.X, space, 0); + warning.Location = new(space, savetext.Location.Y + uc.Location.Y, 0); + uc.Controls.Add(savetext); + uc.ForceDistanceUpdate(this); + Controls.Add(uc); + Anchor = ObjectAnchor.Left | ObjectAnchor.Right | ObjectAnchor.Top; + base.BackgroundColor = new(17, 18, 20, 255); + } +} \ No newline at end of file diff --git a/Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPages/ServerRoleInteraction.cs b/Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPages/ServerRoleInteraction.cs new file mode 100644 index 0000000..af3c308 --- /dev/null +++ b/Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPages/ServerRoleInteraction.cs @@ -0,0 +1,83 @@ +using GraphicsManager.Enums; +using GraphicsManager.Objects; +using Luski.net; +using Luski.net.Structures.Public; +using OpenTK.Mathematics; + +namespace Luski.GUI.MainScreen.UI.PublicServers.ServerSettingPages; + +public class ServerRoleInteraction : UserControl +{ + public FlowLayout RoleFlow; + public RoleIcon Selected; + public ServerRoleOptions SRO; + + public ServerRoleInteraction(PublicServer server, ServerRolePage srp) + { + Task task = Task.Run(() => server.GetRoles()); + task.Wait(); + Role[] roles_pre = task.Result; + var roles = roles_pre.OrderByDescending(s => s.Index); + base.Size = new(srp.Size.X, srp.Size.Y - srp.TitleLable.Size.Y); + + RoleFlow = new() + { + Size = new(247.ScaleInt(), base.Size.Y) + }; + Rectangle hline = new() + { + Location = new(RoleFlow.Size.X, 0, 0), + Size = new(1.ScaleInt(), base.Size.Y), + Anchor = ObjectAnchor.Left | ObjectAnchor.Top | ObjectAnchor.Bottom, + BackgroundColor = Color4.White + }; + hline.ForceDistanceUpdate(this); + Controls.Add(hline); + SRO = new() + { + //BackgroundColor = base.BackgroundColor, + Size = new(srp.Size.X - RoleFlow.Size.X, base.Size.Y), + Location = new(RoleFlow.Size.X + hline.Size.X, 0, 0), + Anchor = ObjectAnchor.All + }; + SRO.ForceDistanceUpdate(this); + Controls.Add(SRO); + + foreach (var role in roles) + { + Selected = new RoleIcon(role, this); + RoleFlow.Controls.Add(Selected); + Selected.ForceDistanceUpdate(RoleFlow); + } + Selected!.SetSelected(true); + var space = 10.ScaleInt(); + Controls.Add(RoleFlow); + Warning = new() + { + Visible = false + }; + Warning.Size = new(base.Size.X - space - space, Warning.Size.Y); + Warning.Location = new(space, base.Size.Y - Warning.Size.Y - space, 0); + Warning.ForceDistanceUpdate(this); + Controls.Add(Warning); + SRO.Init(Warning); + SRO.ForceDistanceUpdate(this); + } + + public SaveWarning Warning; + + public override Color4 BackgroundColor + { + get + { + return base.BackgroundColor; + } + set + { + base.BackgroundColor = value; + RoleFlow.BackgroundColor = value; + SRO.BackgroundColor = value; + Selected.SetSelected(true); + } + } +} \ No newline at end of file diff --git a/Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPages/ServerRoleOptions.cs b/Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPages/ServerRoleOptions.cs new file mode 100644 index 0000000..bf778cb --- /dev/null +++ b/Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPages/ServerRoleOptions.cs @@ -0,0 +1,227 @@ +using System.ComponentModel; +using System.Reflection; +using GraphicsManager.Enums; +using GraphicsManager.Interfaces; +using GraphicsManager.Objects; +using Luski.Classes; +using Luski.GUI.MainScreen.UI.LuskiControls; +using Luski.net.Structures.Public; +using Luski.Shared.PublicServers.V1.Enums; +using OpenTK.Mathematics; +using DisplayNameAttribute = Luski.Shared.GlobalAttributes.DisplayNameAttribute; + +namespace Luski.GUI.MainScreen.UI.PublicServers.ServerSettingPages; + +public class ServerRoleOptions : UserControl +{ + public FlowLayout Page = new(); + private Label Display = new(Globals.DefaultFont) { Text = "Display" }, Permissions = new(Globals.DefaultFont) { Text = "Permissions" }, ManageMembers = new(Globals.DefaultFont); + private Rectangle Line = new() {BackgroundColor = new(63,65,71,255)}, SelectedLine = new(); + + private SaveWarning Warning; + + public delegate void LoadCurrent(); + + private LoadCurrent? CurrentPageToLoad = null; + + public void Init(SaveWarning sw) + { + Warning = sw; + Controls.Add(Display); + Controls.Add(Permissions); + Controls.Add(ManageMembers); + Controls.Add(Line); + Controls.Add(SelectedLine); + Controls.Add(Page); + Page.BackgroundColor = new(0, 0, 0, 0); + base.BackgroundColor = new(0, 0, 0, 0); + int space = 20.ScaleInt(); + Display.Location = new(space, 0, 0); + Permissions.Location = new(Display.Location.X + Display.Size.X + space, Permissions.Location.Y, + Permissions.Location.Z); + ManageMembers.Location = new(Permissions.Location.X + Permissions.Size.X + space, ManageMembers.Location.Y, + ManageMembers.Location.Z); + Line.Location = new(space, Display.Size.Y, 0); + Line.Size = new(Size.X - space - space, 2.ScaleInt()); + Line.Anchor = ObjectAnchor.Left | ObjectAnchor.Right | ObjectAnchor.Top; + Line.ForceDistanceUpdate(this); + SelectedLine.Location = new(Display.Location.X, Line.Location.Y, Line.Location.Z); + SelectedLine.BackgroundColor = Globals.DodgerBlue; + SelectedLine.Size = new(Display.Size.X, Line.Size.Y); + Display.Clicked += _ => + { + if (SelectedLine.Location.X == Display.Location.X) return Task.CompletedTask; + LoadDisplay(); + return Task.CompletedTask; + }; + Permissions.Clicked += _ => + { + if (SelectedLine.Location.X == Permissions.Location.X) return Task.CompletedTask; + LoadPermissions(); + return Task.CompletedTask; + }; + ManageMembers.Clicked += _ => + { + if (SelectedLine.Location.X == ManageMembers.Location.X) return Task.CompletedTask; + LoadMembers(); + return Task.CompletedTask; + }; + Page.Size = new(Line.Size.X, base.Size.Y - Line.Location.Y - Line.Size.Y); + Page.Location = new(Line.Location.X, Line.Size.Y + Line.Location.Y, 0); + Page.HScrollPixels = (uint)30.ScaleInt(); + Page.Anchor = ObjectAnchor.All; + Page.ForceDistanceUpdate(this); + if (LuskiExperiments.GUI.LiveLabelSize.IsEnabled()) + Page.SizeChanged += PageOnSizeChanged; + LuskiExperiments.GUI.LiveLabelSize.EventToggled += b => + { + if (b) Page.SizeChanged += PageOnSizeChanged; + else Page.SizeChanged -= PageOnSizeChanged; + return Task.CompletedTask; + }; + } + + private Task PageOnSizeChanged(IRenderObject arg) + { + foreach (Label l in NeedMax) + { + Vector2i oldsize = l.Size; + l.MaxSize = Page.Size; + Vector2i diff = oldsize - l.Size; + if (l.Parent is UserControl uc) + { + uc.Size = new(uc.Size.X, uc.Size.Y - diff.Y); + } + if (l.Tag is Rectangle line) + { + line.Location = new(line.Location.X, line.Location.Y - diff.Y, 0); + } + } + return Task.CompletedTask; + } + + private List