From d77f7dbf35661b3d9caf923fa2c134e12849b03b Mon Sep 17 00:00:00 2001 From: JacobTech Date: Mon, 27 May 2024 20:17:36 -0400 Subject: [PATCH 1/3] Colors --- Luski/Globals.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Luski/Globals.cs b/Luski/Globals.cs index 0e2c15f..56e40db 100644 --- a/Luski/Globals.cs +++ b/Luski/Globals.cs @@ -388,6 +388,8 @@ public static class Globals r.Size = Size; r.Shader = Rectangle.DefaultAlphaShader[ms.Context]; Color c = await User.GetColor(); + Color? cc = await Profile.GetColor(); + if (cc is not null) c = cc.Value; r.BackgroundColor = new(25, 25, 25, 255); Label l = new(DefaultFont) { -- 2.44.0 From ab73abc7c705dc37cc3e2601e60d2ecfcc2fac10 Mon Sep 17 00:00:00 2001 From: JacobTech Date: Thu, 22 Aug 2024 11:14:33 -0400 Subject: [PATCH 2/3] =?UTF-8?q?Menu=20Mayhem=20&=20Rendering=20Revelations?= =?UTF-8?q?=20=F0=9F=8E=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Killed it! The new menus and rendering won't crash... probably. --- Luski/Classes/Settings.cs | 24 +- Luski/Enums/FontCode.cs | 8 + Luski/Enums/GradType.cs | 7 + Luski/Enums/TextCode.cs | 10 + Luski/GUI/MainScreen/UI/AccountButton.cs | 9 +- Luski/GUI/MainScreen/UI/AddServerIcon.cs | 2 +- Luski/GUI/MainScreen/UI/AddServerOverlay.cs | 6 +- .../UI/LuskiControls/AdvancedGradientLabel.cs | 131 ++++ .../UI/LuskiControls/BasicGradientLabel.cs | 34 + .../UI/LuskiControls/CompressedFlow.cs | 88 +++ .../MainScreen/UI/LuskiControls/FileUpload.cs | 64 ++ .../MainScreen/UI/LuskiControls/LuskiLabel.cs | 741 ++++++++++++++++++ .../UI/LuskiControls/ProfileView.cs | 42 +- .../SettingsMenuBase}/Core/ISettingsPage.cs | 2 +- .../SettingsMenuBase}/Core/PageFlow.cs | 2 +- .../SettingsMenuBase}/Core/PageTab.cs | 2 +- .../Core/SettingsCategory.cs | 8 +- .../SettingsMenuBase/SettingsMenu.cs} | 22 +- .../MainScreen/UI/LuskiControls/TextBox.cs | 7 +- .../UI/LuskiControls/ToggleSwitch.cs | 2 +- .../MainScreen/UI/LuskiControls/UserView.cs | 40 +- .../UI/LuskiSettings/GlobalSettingsMenu.cs | 37 + .../AdvancedSettings/ExperimentSettings.cs | 5 +- .../Pages/AdvancedSettings/Updater.cs | 4 +- .../Pages/AppSettings/Appearance.cs | 2 +- .../Pages/AppSettings/General.cs | 2 +- .../UI/LuskiSettings/SettingsMenu.cs | 81 -- .../MainScreen/UI/PublicServers/Category.cs | 56 +- .../MainScreen/UI/PublicServers/Channel.cs | 49 +- .../UI/PublicServers/ChatMessage.cs | 35 +- .../UI/PublicServers/ContentEmbed.cs | 4 +- .../MainScreen/UI/PublicServers/PublicChat.cs | 95 ++- .../UI/PublicServers/ServerSettingCategory.cs | 67 -- .../UI/PublicServers/ServerSettingPageTab.cs | 96 --- .../ServerSettingPages/IPageBase.cs | 10 - .../ServerSettingPages/PageBaseControl.cs | 38 - .../ServerSettingPages/PageBaseFlow.cs | 38 - .../Pages/Server/Roles}/RoleIcon.cs | 5 +- .../Pages/Server/Roles/RoleMember.cs | 27 + .../Pages/Server/Roles/Roles.cs} | 9 +- .../Server/Roles}/ServerRoleInteraction.cs | 4 +- .../Pages/Server/Roles}/ServerRoleOptions.cs | 15 +- .../PublicServerSettingsMenu.cs | 25 + .../SaveWarning.cs | 2 +- Luski/GUI/MainScreen/UI/ServerIcon.cs | 2 +- Luski/GUI/MainScreen/UI/ServerLoginOverlay.cs | 6 +- Luski/GUI/MainScreenWindow.cs | 153 ++-- Luski/Globals.cs | 106 ++- Luski/Luski.csproj | 6 +- Luski/Program.cs | 28 + Luski/Resources/Shaders/LeftToRightLabel.frag | 19 + Luski/Resources/Shaders/LeftToRightLabel.vert | 15 + 52 files changed, 1751 insertions(+), 541 deletions(-) create mode 100644 Luski/Enums/FontCode.cs create mode 100644 Luski/Enums/GradType.cs create mode 100644 Luski/Enums/TextCode.cs create mode 100644 Luski/GUI/MainScreen/UI/LuskiControls/AdvancedGradientLabel.cs create mode 100644 Luski/GUI/MainScreen/UI/LuskiControls/BasicGradientLabel.cs create mode 100644 Luski/GUI/MainScreen/UI/LuskiControls/CompressedFlow.cs create mode 100644 Luski/GUI/MainScreen/UI/LuskiControls/FileUpload.cs create mode 100644 Luski/GUI/MainScreen/UI/LuskiControls/LuskiLabel.cs rename Luski/GUI/MainScreen/UI/{LuskiSettings => LuskiControls/SettingsMenuBase}/Core/ISettingsPage.cs (80%) rename Luski/GUI/MainScreen/UI/{LuskiSettings => LuskiControls/SettingsMenuBase}/Core/PageFlow.cs (92%) rename Luski/GUI/MainScreen/UI/{LuskiSettings => LuskiControls/SettingsMenuBase}/Core/PageTab.cs (97%) rename Luski/GUI/MainScreen/UI/{LuskiSettings => LuskiControls/SettingsMenuBase}/Core/SettingsCategory.cs (90%) rename Luski/GUI/MainScreen/UI/{PublicServers/ServerSettings.cs => LuskiControls/SettingsMenuBase/SettingsMenu.cs} (72%) create mode 100644 Luski/GUI/MainScreen/UI/LuskiSettings/GlobalSettingsMenu.cs delete mode 100644 Luski/GUI/MainScreen/UI/LuskiSettings/SettingsMenu.cs delete mode 100644 Luski/GUI/MainScreen/UI/PublicServers/ServerSettingCategory.cs delete mode 100644 Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPageTab.cs delete mode 100644 Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPages/IPageBase.cs delete mode 100644 Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPages/PageBaseControl.cs delete mode 100644 Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPages/PageBaseFlow.cs rename Luski/GUI/MainScreen/UI/PublicServers/{ServerSettingPages => ServerSettings/Pages/Server/Roles}/RoleIcon.cs (93%) create mode 100644 Luski/GUI/MainScreen/UI/PublicServers/ServerSettings/Pages/Server/Roles/RoleMember.cs rename Luski/GUI/MainScreen/UI/PublicServers/{ServerSettingPages/ServerRolePage.cs => ServerSettings/Pages/Server/Roles/Roles.cs} (69%) rename Luski/GUI/MainScreen/UI/PublicServers/{ServerSettingPages => ServerSettings/Pages/Server/Roles}/ServerRoleInteraction.cs (94%) rename Luski/GUI/MainScreen/UI/PublicServers/{ServerSettingPages => ServerSettings/Pages/Server/Roles}/ServerRoleOptions.cs (94%) create mode 100644 Luski/GUI/MainScreen/UI/PublicServers/ServerSettings/PublicServerSettingsMenu.cs rename Luski/GUI/MainScreen/UI/PublicServers/{ServerSettingPages => ServerSettings}/SaveWarning.cs (96%) create mode 100644 Luski/Resources/Shaders/LeftToRightLabel.frag create mode 100644 Luski/Resources/Shaders/LeftToRightLabel.vert diff --git a/Luski/Classes/Settings.cs b/Luski/Classes/Settings.cs index 94a6d46..4b16d68 100644 --- a/Luski/Classes/Settings.cs +++ b/Luski/Classes/Settings.cs @@ -75,7 +75,7 @@ public class Settings 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.ForceUpdate(); Globals.ms.DrawFrame(); } } @@ -98,7 +98,7 @@ public class Settings [JsonInclude] [Shared.GlobalAttributes.DisplayName("24 Hour Time")] - [Description("shows time in the 24 hour format")] + [Description("Shows time in the 24 hour format")] [JsonPropertyName("24hour_time")] public bool DayTime { @@ -113,12 +113,32 @@ public class Settings } } + [JsonInclude] + [Shared.GlobalAttributes.DisplayName("Memory Fonts")] + [Description("Stores fonts in memory for faster load times")] + [JsonPropertyName("memory_fonts")] + public bool StoreFontsInMemory + { + get + { + return _MemoryFonts; + } + set + { + _MemoryFonts = value; + //GraphicsManager.Objects.Core.FontFamily.MemoryFont = value; + //if (DayTimeChanged is not null) DayTimeChanged.Invoke(); + } + } + [JsonIgnore] private bool _ScaleFonts = true; [JsonIgnore] private ConsoleLog _Logs = (ConsoleLog)(-25); [JsonIgnore] private bool _DayTime = false; + [JsonIgnore] + private bool _MemoryFonts= false; public event Func? DayTimeChanged; } diff --git a/Luski/Enums/FontCode.cs b/Luski/Enums/FontCode.cs new file mode 100644 index 0000000..de28ec5 --- /dev/null +++ b/Luski/Enums/FontCode.cs @@ -0,0 +1,8 @@ +namespace Luski.Enums; + +public enum FontCode : byte +{ + Size, + Italics, + Height +} \ No newline at end of file diff --git a/Luski/Enums/GradType.cs b/Luski/Enums/GradType.cs new file mode 100644 index 0000000..9c0d58e --- /dev/null +++ b/Luski/Enums/GradType.cs @@ -0,0 +1,7 @@ +namespace Luski.Enums; + +public enum GradType : byte +{ + Block, + Line +} \ No newline at end of file diff --git a/Luski/Enums/TextCode.cs b/Luski/Enums/TextCode.cs new file mode 100644 index 0000000..7fa9c10 --- /dev/null +++ b/Luski/Enums/TextCode.cs @@ -0,0 +1,10 @@ +namespace Luski.Enums; + +public enum TextCode +{ + Rainbow, + Gradient, + Color, + Font, + url +} \ No newline at end of file diff --git a/Luski/GUI/MainScreen/UI/AccountButton.cs b/Luski/GUI/MainScreen/UI/AccountButton.cs index 934917e..aedbd1f 100644 --- a/Luski/GUI/MainScreen/UI/AccountButton.cs +++ b/Luski/GUI/MainScreen/UI/AccountButton.cs @@ -17,7 +17,7 @@ public class AccountButton : UserControl :base(Globals.ms.TextureManager.GetTextureResource("RoundedRectangle.png")) { this.SM = SM; - base.Size = new(297.ScaleInt(), 40.ScaleInt()); + base.SetSize(297.ScaleInt(), 40.ScaleInt()); TextureDisplay = TextureDisplay.HorizontalCenter; Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context]; l = new Label(Globals.DefaultFont) @@ -26,9 +26,8 @@ public class AccountButton : UserControl Color = Color4.Gray, IgnoreHover = true, }; - l.Location = new((base.Size.X / 2) - (l.Size.X / 2), - ((base.Size.Y - l.Size.Y) / 2) - , 0); + l.SetLocation((base.Size.X / 2) - (l.Size.X / 2), + ((base.Size.Y - l.Size.Y) / 2)); Controls.Add(l); base.BackgroundColor = new(0, 0, 0, 0); Clicked += OnClicked; @@ -82,7 +81,7 @@ public class AccountButton : UserControl SM.Selected = this; SM.page.Controls.Clear(); OnPageLoad.Invoke(); - Globals.ms.ForceUpdate(new(Globals.ms.CS)); + Globals.ms.ForceUpdate(); } BlockDraw = false; diff --git a/Luski/GUI/MainScreen/UI/AddServerIcon.cs b/Luski/GUI/MainScreen/UI/AddServerIcon.cs index 4d93c1a..30cbee0 100644 --- a/Luski/GUI/MainScreen/UI/AddServerIcon.cs +++ b/Luski/GUI/MainScreen/UI/AddServerIcon.cs @@ -18,6 +18,6 @@ public class AddServerIcon : UserControl }; Controls.Add(Button); base.BackgroundColor = new(26, 26, 26, 255); - base.Size = new(68.ScaleInt(), 48.ScaleInt()); + base.SetSize(68.ScaleInt(), 48.ScaleInt()); } } \ No newline at end of file diff --git a/Luski/GUI/MainScreen/UI/AddServerOverlay.cs b/Luski/GUI/MainScreen/UI/AddServerOverlay.cs index 4f7b2cd..cc5b0fc 100644 --- a/Luski/GUI/MainScreen/UI/AddServerOverlay.cs +++ b/Luski/GUI/MainScreen/UI/AddServerOverlay.cs @@ -108,7 +108,7 @@ public class AddServerOverlay : UserControl, IServerOverlay return Task.CompletedTask; }; - tb.Size = new(Form.Size.X - tb.Location.X - tb.Location.X - tb.Location.X - s.X, tb.Size.Y); + tb.SetSize(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) { @@ -475,7 +475,7 @@ public class AddServerOverlay : UserControl, IServerOverlay DisplayName = null!; rec = null!; tb.Focus(); - Globals.ms.ForceUpdate(new(Globals.ms.CS)); + Globals.ms.ForceUpdate(); TryDraw(); } }; @@ -600,7 +600,7 @@ public class AddServerOverlay : UserControl, IServerOverlay private string pfp = ""; - private Task RecOnFilesDroped(string[] arg) + private Task RecOnFilesDroped(IRenderObject obj, string[] arg) { Console.WriteLine(arg[0]); if (!arg[0].ToLower().EndsWith("png")) return Task.CompletedTask; diff --git a/Luski/GUI/MainScreen/UI/LuskiControls/AdvancedGradientLabel.cs b/Luski/GUI/MainScreen/UI/LuskiControls/AdvancedGradientLabel.cs new file mode 100644 index 0000000..de3fd99 --- /dev/null +++ b/Luski/GUI/MainScreen/UI/LuskiControls/AdvancedGradientLabel.cs @@ -0,0 +1,131 @@ +using GraphicsManager.Interfaces; +using GraphicsManager.Objects.Core; +using GraphicsManager.Structs; +using OpenTK.Graphics.OpenGL4; +using OpenTK.Mathematics; + +namespace Luski.GUI.MainScreen.UI.LuskiControls; + +public class AdvancedGradientLabel : LabelBase +{ + public AdvancedGradientLabel(FontInteraction fi) : base(fi) { } + + public Color4[] Colors { get; set; } = new[] + { + new Color4(255, 255, 255, 255), + new Color4(255, 255, 255, 255) + }; + + protected virtual (Color4,Color4) getcols(int charter) + { + Vector2i cl = GetCharLocation(charter); + Vector2i cs = GetSizeOfChar(charter); + return new(getcol(cl.X), getcol(cl.X + cs.X)); + } + protected virtual Color4 getcol(int pos) + { + float travel = (float)Size.X/(Colors.Length - 1); + int i = 1; + while (travel * i < pos) + { + i++; + } + i--; + float t = Math.Clamp((pos-(travel*i))/travel, 0, 1); + Color4 LeftColor = Colors[i], RightColor = Colors[i + 1]; + + float r = LeftColor.R + (RightColor.R - LeftColor.R) * t; + float g = LeftColor.G + (RightColor.G - LeftColor.G) * t; + float b = LeftColor.B + (RightColor.B - LeftColor.B) * t; + float a = LeftColor.A + (RightColor.A - LeftColor.A) * t; + + return new Color4(r, g, b, a); + } + public override void LoadToParent(IParent window, IWindow win) + { + if (Loaded) return; + if (Shader is null) Shader = Globals.GradientShader[win.Context]; + base.LoadToParent(window, win); + } + + public override void Draw(int x, int y, int ww, int hh) + { + if (Visible && Loaded && this.Font is not null && Colors.Length > 1) + { + if (!Window!.Context.IsCurrent) Window.Context.MakeCurrent(); + Shader.Use(); + GL.Enable(EnableCap.Blend); + GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); + GL.BlendFunc(0, BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); + Shader.SetMatrixF4("projection", Window.WindowSizeMatrix); + + GL.BindVertexArray(VAO); + + float angle_rad = (float)Math.Atan2(DIR.Y, DIR.X); + Matrix4 rotateM = Matrix4.CreateRotationZ(angle_rad); + Matrix4 transOriginM = Matrix4.CreateTranslation(new Vector3(loc_.X + Parent!.IntToWindow(0), loc_.Y + (Font.PixelHeight * Scale) + Parent!.IntToWindow(0, true), 0f)); + float char_x = 0.0f; + + GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1); + GL.ActiveTexture((Shader.GetUniformLocation("u_texture") switch + { + 0 => TextureUnit.Texture0, + 1 => TextureUnit.Texture1, + 2 => TextureUnit.Texture2, + 3 => TextureUnit.Texture3, + 4 => TextureUnit.Texture4, + 5 => TextureUnit.Texture5, + 6 => TextureUnit.Texture6, + 7 => TextureUnit.Texture7, + 8 => TextureUnit.Texture8, + 9 => TextureUnit.Texture9, + })); + + float hhh = 0f; + for (int i = 0; i < text_Calculated.Length; i++) + { + var col = getcols(i); + GL.Uniform4(Shader.GetUniformLocation("textColor"), col.Item1); + GL.Uniform4(Shader.GetUniformLocation("rightColor"), col.Item2); + char c; + if (PasswordChar is null) + c = text_Calculated[i]; + else + c = PasswordChar.Value; + bool n = (c == '\n'); + if (!_characters[Window!.Context][Font].ContainsKey(c) && !n) + { + _ = Texture.TextureForChar(Window!.Context, Font, c, Shader); + } + + if (n) + { + hhh += LineHeight; + hhh += Font.ExtraLinePixels; + char_x = 0f; + } + else + { + if (!_characters[Window!.Context][Font].ContainsKey(c)) continue; + Character ch = _characters[Window!.Context][Font][c]; + + float w = ch.Size.X * Scale; + float h = ch.Size.Y * Scale; + float xrel = char_x + ch.Bearing.X * Scale; + float yrel = (ch.Size.Y - ch.Bearing.Y) * Scale; + yrel += hhh; + char_x += (ch.Advance >> 6) * Scale; + Matrix4 scaleM = Matrix4.CreateScale(new Vector3(w, h, 1.0f)); + Matrix4 transRelM = Matrix4.CreateTranslation(new Vector3(xrel, yrel, 0.0f)); + + Matrix4 modelM = scaleM * transRelM * rotateM * transOriginM; + GL.UniformMatrix4(Shader.GetUniformLocation("model"), false, ref modelM); + + ch.Texture.Use(); + + GL.DrawArrays(PrimitiveType.Triangles, 0, 6); + } + } + } + } +} \ No newline at end of file diff --git a/Luski/GUI/MainScreen/UI/LuskiControls/BasicGradientLabel.cs b/Luski/GUI/MainScreen/UI/LuskiControls/BasicGradientLabel.cs new file mode 100644 index 0000000..b4b1d94 --- /dev/null +++ b/Luski/GUI/MainScreen/UI/LuskiControls/BasicGradientLabel.cs @@ -0,0 +1,34 @@ +using GraphicsManager.Interfaces; +using GraphicsManager.Objects; +using GraphicsManager.Objects.Core; +using GraphicsManager.Structs; +using OpenTK.Graphics.OpenGL4; +using OpenTK.Mathematics; + +namespace Luski.GUI.MainScreen.UI.LuskiControls; + +public class BasicGradientLabel : AdvancedGradientLabel +{ + public BasicGradientLabel(FontInteraction fi) : base(fi) { } + public Color4 LeftColor + { + get => Colors[0]; + set => Colors[0] = value; + } + public Color4 RightColor + { + get => Colors[1]; + set => Colors[1] = value; + } + protected override Color4 getcol(int pos) + { + float t = Math.Clamp(pos/(float)Size.X, 0, 1); + + float r = LeftColor.R + (RightColor.R - LeftColor.R) * t; + float g = LeftColor.G + (RightColor.G - LeftColor.G) * t; + float b = LeftColor.B + (RightColor.B - LeftColor.B) * t; + float a = LeftColor.A + (RightColor.A - LeftColor.A) * t; + + return new Color4(r, g, b, a); + } +} \ No newline at end of file diff --git a/Luski/GUI/MainScreen/UI/LuskiControls/CompressedFlow.cs b/Luski/GUI/MainScreen/UI/LuskiControls/CompressedFlow.cs new file mode 100644 index 0000000..05c80fc --- /dev/null +++ b/Luski/GUI/MainScreen/UI/LuskiControls/CompressedFlow.cs @@ -0,0 +1,88 @@ +using GraphicsManager.Interfaces; +using GraphicsManager.Objects; +using OpenTK.Mathematics; + +namespace Luski.GUI.MainScreen.UI.LuskiControls; + +public class CompressedFlow : UserControl +{ + public CompressedFlow() + { + Controls.ControlAfterAdded += ControlsOnControlAdded; + Controls.ControlRemoved += ControlsOnControlRemoved; + SizeChanged += OnSizeChanged; + Padding = new(5.ScaleInt()); + ChildPadding = new(Padding.X); + } + + public event Func? SizeUpdateNotIgnored; + + public Vector4i Padding { get; set; } + public Vector2i ChildPadding { get; set; } + + private bool IgnoreNextSizeChange; + + private Task OnSizeChanged(IRenderObject arg) + { + if (IgnoreNextSizeChange) + { + IgnoreNextSizeChange = false; + return Task.CompletedTask; + } + UpdateControlesFromIndex(0); + return Task.CompletedTask; + } + + private Task ControlsOnControlRemoved() + { + UpdateControlesFromIndex(0); + return Task.CompletedTask; + } + + private Task ControlsOnControlAdded(int arg1, IRenderObject arg2) + { + if (arg1 != 0) + { + if (arg1 + 1 < Controls.Length)arg2.Location = Controls[arg1 + 1].Location; + } + else + { + arg2.Location = new(Padding.X, Padding.Y, 0); + } + UpdateControlesFromIndex(arg1); + return Task.CompletedTask; + } + + private void UpdateControlesFromIndex(int index) + { + if (Controls.Length == 0) + { + IgnoreNextSizeChange = true; + Size = new(Size.X, 0); + if (SizeUpdateNotIgnored is not null) _ = SizeUpdateNotIgnored.Invoke(this); + return; + } + if (index == 0) index++; + for (int i = index; i < Controls.Length; i++) + { + if (Controls[i-1].Location.X + Controls[i-1].Size.X + Padding.Z + Controls[i].Size.X + ChildPadding.X > Size.X) + { + Controls[i].Location = new(Padding.X, + Controls[i - 1].Location.Y + Controls[i - 1].Size.Y + ChildPadding.Y, 0); + } + else + { + Controls[i].Location = new(ChildPadding.X + Controls[i - 1].Location.X + Controls[i - 1].Size.X, + Controls[i - 1].Location.Y, 0); + } + } + + if (Controls[Controls.Length - 1].Location.Y + Controls[Controls.Length - 1].Size.Y + Padding.W != Size.Y) + { + IgnoreNextSizeChange = true; + Size = new(Size.X, + Controls[Controls.Length - 1].Location.Y + Controls[Controls.Length - 1].Size.Y + Padding.W); + if (SizeUpdateNotIgnored is not null) _ = SizeUpdateNotIgnored.Invoke(this); + } + } +} \ No newline at end of file diff --git a/Luski/GUI/MainScreen/UI/LuskiControls/FileUpload.cs b/Luski/GUI/MainScreen/UI/LuskiControls/FileUpload.cs new file mode 100644 index 0000000..c75cee1 --- /dev/null +++ b/Luski/GUI/MainScreen/UI/LuskiControls/FileUpload.cs @@ -0,0 +1,64 @@ +using GraphicsManager.Objects; +using Luski.net; +using Luski.net.Structures.Public; + +namespace Luski.GUI.MainScreen.UI.LuskiControls; + +public class FileUpload : UserControl +{ + public long? FileID; + private PublicServer? PublicServer; + private MainServer? MainServer; + private string Path = ""; + public SocketFile? PublicSF; + + private void INIT(string FilePath) + { + Path = FilePath; + FileInfo FI = new(FilePath); + string fst = ""; + ulong size = (ulong)FI.Length; + if (size < 1000) + fst = size + " bytes"; + else if (size < 1000000) + fst = Math.Round(size / (double)1000, 2) + " KB"; + else if (size < 1000000000) + fst = Math.Round(size / (double)1000000, 2) + " MB"; + else if (size < 1000000000000) fst = Math.Round(size / (double)1000000000, 2) + " GB"; + Label fileNameLabel, fileSizeLabel; + base.Size = new(333.ScaleInt(), 66.ScaleInt()); + base.BackgroundColor = new(40, 40, 40, 255); + Controls.Add(fileSizeLabel = new Label(Globals.DefaultFont) { Text = fst, Location = new(64, 39, 0) }); + Controls.Add(fileNameLabel = new Label(Globals.DefaultFont) + { + Color = new(102 / (float)255, 227 / (float)255, 170 / (float)255, 1), Text = FI.Name, + Location = new(64, 6, 0) + }); + if (fileSizeLabel.Size.X > fileNameLabel.Size.X) + base.Size = new(fileSizeLabel.Location.X + fileSizeLabel.Size.X + 5.ScaleInt(), base.Size.Y); + else + base.Size = new(fileNameLabel.Location.X + fileNameLabel.Size.X + 5.ScaleInt(), base.Size.Y); + } + + public FileUpload(PublicServer ps, string FilePath) + { + INIT(FilePath); + PublicServer = ps; + } + + public FileUpload(MainServer ms, string FilePath) + { + INIT(FilePath); + MainServer = ms; + } + + public async Task StartUpload() + { + if (FileID is not null) return; + if (PublicServer is not null) + { + PublicSF = await PublicServer.UploadFile(Path); + return; + } + } +} \ No newline at end of file diff --git a/Luski/GUI/MainScreen/UI/LuskiControls/LuskiLabel.cs b/Luski/GUI/MainScreen/UI/LuskiControls/LuskiLabel.cs new file mode 100644 index 0000000..c6f6a18 --- /dev/null +++ b/Luski/GUI/MainScreen/UI/LuskiControls/LuskiLabel.cs @@ -0,0 +1,741 @@ +using System.Diagnostics; +using System.Text; +using GraphicsManager.Enums; +using GraphicsManager.Interfaces; +using GraphicsManager.Objects; +using GraphicsManager.Objects.Core; +using GraphicsManager.Structs; +using Luski.Enums; +using Luski.net.Structures.Public; +using OpenTK.Graphics.OpenGL4; +using OpenTK.Mathematics; +using OpenTK.Windowing.Common.Input; + +namespace Luski.GUI.MainScreen.UI.LuskiControls; + +public class LuskiLabel : LabelBase +{ + public LuskiLabel() : this(Globals.DefaultFont) { } + public LuskiLabel(FontInteraction fi) : base(fi) { } + public Color4 DefaultColor { get; set; } = Color4.White; + + public override void LoadToParent(IParent window, IWindow win) + { + if (Loaded) return; + if (Shader is null) Shader = Globals.GradientShader[win.Context]; + base.LoadToParent(window, win); + } + protected virtual (Color4,Color4) getGradcols(int Start, int charter, int End, int StartLine, int Line, int EndLine, GradType GT, Color4[] Colors) + { + Vector2i cl = GetCharLocation(charter); + Vector2i cs = GetSizeOfChar(charter); + Vector2i cls = GetCharLocation(Start); + Vector2i cle = GetCharLocation(End); + Vector2i cse = GetSizeOfChar(End); + if (GT == GradType.Line && StartLine != EndLine) + { + for (int i = StartLine; i < EndLine; i++) + { + Vector2i dis = new(MaxLineSizes[i].Item1.X, 0); + if (i == StartLine) dis -= new Vector2i(cls.X, 0); + cle += dis; + if (i < Line) cl += dis; + } + } + else if (GT == GradType.Block && StartLine != EndLine) + { + cls = new(0, cl.Y); + int longest = MaxLineSizes[StartLine].Item1.X; + for (int i = StartLine+1; i <= EndLine; i++) + { + if (MaxLineSizes[i].Item1.X > longest) longest = MaxLineSizes[i].Item1.X; + } + + cse = new(0); + cle = new(longest, cle.X); + } + + return new(getGradcol(cls.X, cl.X, cle.X + cse.X, Colors), getGradcol(cls.X, cl.X + cs.X, cle.X + cse.X, Colors)); + } + protected virtual Color4 getGradcol(int Start, int pos, int End, Color4[] Colors) + { + pos -= Start; + End -= Start; + float travel = (float)End/(Colors.Length - 1); + int i = 1; + while (travel * i < pos) + { + i++; + } + i--; + float t = Math.Clamp((pos-(travel*i))/travel, 0, 1); + Color4 LeftColor, RightColor; + try + { + LeftColor = Colors[i]; + RightColor = Colors[i + 1]; + } + catch (Exception e) + { + + LeftColor = Color4.DarkRed; + RightColor = Color4.DarkRed; + } + + + float r = LeftColor.R + (RightColor.R - LeftColor.R) * t; + float g = LeftColor.G + (RightColor.G - LeftColor.G) * t; + float b = LeftColor.B + (RightColor.B - LeftColor.B) * t; + float a = LeftColor.A + (RightColor.A - LeftColor.A) * t; + + return new Color4(r, g, b, a); + } + + List> Commands = new(); + + public string PlainText { get; protected set; } = string.Empty; + private List<(Vector2i, FontInteraction)> MaxLineSizes = new(); + + public override string Text + { + get => base.Text; + set + { + if (value is null) value = string.Empty; + text = value; + text_Calculated = string.Empty; + PlainText = string.Empty; + MaxLineSizes.Clear(); + float max_x = 0, lines = 1, char_x = 0F; + int len = Text.Length; + bool use_slash = true, usebrac = true; + List Rainbow_End = new(); + List Gradient_End = new(); + List Color_End = new(); + List Font_Starts = new(); + List Link_Starts = new(); + Commands.Clear(); + List<(GradType, int)> RainGrad = new(); + List<(Color4[], GradType, int)> Grad = new(); + List ccccc = new(); + List Itilacs = new(); + List Fonts = new(); + List Sizes = new(); + List Links = new(); + FontInteraction Current = Font; + FontInteraction? Largest = null; + int LastFontEnd = 0; + StringBuilder sb = new(); + uint lh = 0; + float lw = 0; + uint max_lh = 0; + + for (int i = 0; i < len; i++) + { + char c; + if (PasswordChar is null) + c = Text[i]; + else + c = PasswordChar.Value; + bool n = (c == '\n'); + + if (Text[i] == '\\' && use_slash) + { + if (i + 1 < len) + { + char tm = Text[i + 1]; + if (tm == '\\') + { + use_slash = false; + continue; + } + if (tm == '[') + { + usebrac = false; + continue; + } + } + + + } + + try + { + if (usebrac && Text[i] == '[') + { + int brack = Text.IndexOf(']', i); + string com = Text[(i + 1)..(brack )].Replace("\" ", "\""); + while (com.Contains(" ")) + { + com = com.Replace(" ", " "); + } + string[] args = com.Split('=', '"', ' '); + + FontInteraction tmp; + if (args[0][0] != '/') + { + switch (args[0]) + { + case "rainbow": + Rainbow_End.Add(sb.Length); + GradType rgt = GradType.Line; + for (int j = 1; j < args.Length-2; j+=3) + { + switch (args[j]) + { + case "type": + rgt = (GradType)byte.Parse(args[j + 2]); + break; + } + } + RainGrad.Add(new(rgt, (int)lines-1)); + i = brack; + continue; + case "gradient": + List cols = new(); + Gradient_End.Add(sb.Length); + GradType gt = GradType.Line; + for (int j = 1; j < args.Length-2; j+=3) + { + Console.WriteLine(args[j]); + switch (args[j]) + { + case "colors": + for (int w = 0; w < args[j+2].Length - 7; w+=8) + { + cols.Add(new(args[j+2][w..(w+8)])); + } + break; + case "type": + gt = (GradType)byte.Parse(args[j + 2]); + break; + } + } + Grad.Add(new(cols.ToArray().ToColor4Array(), gt, (int)lines-1)); + i = brack; + continue; + case "color": + i = brack; + Color_End.Add(sb.Length); + Color col = new(args[2].Replace("#", "")); + ccccc.Add(col.ToColor4()); + i = brack; + continue; + case "fontsize": + FontSize fs = (FontSize)int.Parse(args[2]); + tmp = Current.Clone(); + tmp.FontSize = fs; + if (Fonts.Count != 0 || Itilacs.Count != 0 || Sizes.Count != 0) + { + int pos = Font_Starts.Count - 1; + int last_Start = Font_Starts[pos]; + int end = sb.Length - 1; + if (end != -1 && last_Start != end) + Commands.Add(new(TextCode.Font, last_Start, end, Current)); + Font_Starts.RemoveAt(pos); + } + Fonts.Add(fs); + Font_Starts.Add(sb.Length); + Current = tmp; + i = brack; + continue; + case "px": + uint ph = uint.Parse(args[2]); + tmp = Current.Clone(); + tmp.PixelHeight = ph; + if (Fonts.Count != 0 || Itilacs.Count != 0 || Sizes.Count != 0) + { + int pos = Font_Starts.Count - 1; + int last_Start = Font_Starts[pos]; + int end = sb.Length - 1; + if (end != -1 && last_Start != end) + Commands.Add(new(TextCode.Font, last_Start, end, Current)); + Font_Starts.RemoveAt(pos); + } + i = brack; + Sizes.Add(ph); + Font_Starts.Add(sb.Length); + Current = tmp; + i = brack; + continue; + case "url": + Link_Starts.Add(i); + Links.Add(args[2]); + i = brack; + continue; + case "i": + tmp = Current.Clone(); + tmp.Italic = true; + if (Fonts.Count != 0 || Itilacs.Count != 0 || Sizes.Count != 0) + { + int pos = Font_Starts.Count - 1; + int last_Start = Font_Starts[pos]; + int end = sb.Length - 1; + if (end != -1 && last_Start != end) + Commands.Add(new(TextCode.Font, last_Start, end, Current)); + Font_Starts.RemoveAt(pos); + } + Itilacs.Add(true); + Font_Starts.Add(sb.Length); + Current = tmp; + i = brack; + continue; + + } + } + else + { + if (com == "/rainbow") + { + if (Rainbow_End.Count == 0) + { + i = brack; + continue; + } + (GradType, int) cc = RainGrad[RainGrad.Count - 1]; + Commands.Add(new(TextCode.Rainbow, Rainbow_End[Rainbow_End.Count-1], sb.Length-1, new Tuple(cc.Item1, cc.Item2, (int)lines-1))); + Rainbow_End.RemoveAt(Rainbow_End.Count-1); + i = brack; + continue; + } + if (com == "/gradient") + { + if (Gradient_End.Count == 0) + { + i = brack; + continue; + } + var cc = Grad[Grad.Count - 1]; + Commands.Add(new(TextCode.Gradient, Gradient_End[Gradient_End.Count-1], sb.Length-1, new Tuple(cc.Item1, cc.Item2, cc.Item3, (int)lines-1))); + Gradient_End.RemoveAt(Gradient_End.Count-1); + Grad.RemoveAt(Grad.Count-1); + i = brack; + continue; + } + if (com == "/color") + { + if (ccccc.Count == 0) + { + i = brack; + continue; + } + Commands.Add(new(TextCode.Color, Color_End[Color_End.Count-1], sb.Length-1, ccccc[ccccc.Count-1])); + Color_End.RemoveAt(Color_End.Count-1); + ccccc.RemoveAt(ccccc.Count-1); + i = brack; + continue; + } + if (com == "/url") + { + Commands.Add(new(TextCode.url, Link_Starts[Link_Starts.Count-1], sb.Length-1, Links[Links.Count-1])); + Link_Starts.RemoveAt(Link_Starts.Count-1); + Links.RemoveAt(Links.Count-1); + i = brack; + continue; + } + + if (com == "/fontsize" || com == "/i" || com == "/px") + { + int pos = Font_Starts.Count - 1; + if (pos == -1) + { + i = brack; + continue; + } + if (pos >= 0) + { + int last_Start = Font_Starts[pos]; + Font_Starts.RemoveAt(pos); + if (LastFontEnd != sb.Length - 1) + { + LastFontEnd = sb.Length - 1; + Commands.Add(new(TextCode.Font, last_Start, LastFontEnd, Current)); + } + } + } + + + if (com == "/fontsize") + { + Fonts.RemoveAt(Fonts.Count - 1); + if (Fonts.Count != 0) + { + Current = Current.Clone(); + Current.FontSize = Fonts[Fonts.Count - 1]; + Font_Starts.Add(sb.Length-1); + } + else + { + if (Sizes.Count == 0 && Itilacs.Count == 0) + Current = Font; + else + { + Current = Current.Clone(); + Current.FontSize = Font.FontSize; + Font_Starts.Add(sb.Length-1); + } + } + i = brack; + continue; + } + if (com == "/i") + { + Itilacs.RemoveAt(Itilacs.Count - 1); + if (Itilacs.Count != 0) + { + Current = Current.Clone(); + Current.Italic = Itilacs[Itilacs.Count - 1]; + Font_Starts.Add(sb.Length-1); + } + else + { + if (Sizes.Count == 0 && Fonts.Count == 0) + Current = Font; + else + { + Current = Current.Clone(); + Current.Italic = Font.Italic; + Font_Starts.Add(sb.Length-1); + } + } + i = brack; + continue; + } + if (com == "/px") + { + if (Sizes.Count == 0) + { + i = brack; + continue; + } + Sizes.RemoveAt(Sizes.Count - 1); + if (Sizes.Count != 0) + { + Current = Current.Clone(); + Current.PixelHeight = Sizes[Sizes.Count - 1]; + Font_Starts.Add(sb.Length-1); + } + else + { + if (Itilacs.Count == 0 && Fonts.Count == 0) + Current = Font; + else + { + Current = Current.Clone(); + Current.PixelHeight = Font.PixelHeight; + Font_Starts.Add(sb.Length-1); + } + } + i = brack; + continue; + } + } + } + } + catch (Exception e) + { + Console.WriteLine(value); + Console.WriteLine(e); + //ignore + } + + use_slash = true; + usebrac = true; + if (Largest is null || Current.PixelHeight > Largest.PixelHeight) + { + lh = Current.PixelHeight; + Largest = Current; + } + + if (n) + { + lines++; + char_x = 0f; + max_lh += lh; + MaxLineSizes.Add(new(new((int)lw,(int)lh), Largest)); + max_lh += (uint) ((double) lh * ((double) Largest.CurrentFonts[0].Face.Height / (double) Largest.CurrentFonts[0].Face.UnitsPerEM) * (double) this.Scale); + Largest = null; + lw = 0; + lh = 0; + sb.Append(c); + } + else + { + Character ch; + if (Window is not null) ch = Texture.GetChar(Font, c, Window.Context); + else ch = Texture.GetChar(Font, c); + if (MaxSize is not null && i > 0 && text[i-1] == ' ') + { + int addc = 0; + float word_char_x = char_x; + while (true) + { + if (addc + i == Text.Length) break; + if (text[addc + i] == ' ') break; + Character ch2; + if (Window is not null) ch2 = Texture.GetChar(Font, text[addc + i], Window.Context); + else ch2 = Texture.GetChar(Font, c); + word_char_x += (ch2.Advance >> 6) * Scale; + if (word_char_x > MaxSize.Value.X) + { + char_x = 0f; + lines++; + sb.Append('\n'); + break; + } + addc++; + } + } + + sb.Append(c); + float w = ch.Size.X * Scale; + float xrel = char_x + ch.Bearing.X * Scale; + char_x += (ch.Advance >> 6) * Scale; + if ((xrel + w) >= max_x) max_x = (xrel + w); + if ((xrel + w) >= lw) lw = (xrel + w); + } + } + MaxLineSizes.Add(new(new((int)lw,(int)lh), Largest)); + max_lh += (uint) ((double) lh * ((double) Largest.CurrentFonts[0].Face.Height / (double) Largest.CurrentFonts[0].Face.UnitsPerEM) * (double) this.Scale); + Largest = null; + + PlainText = sb.ToString(); + text_Calculated = sb.ToString(); + Commands.Sort((x, y) => x.Item2.CompareTo(y.Item2)); + + Size = new((int)max_x, (int)(max_lh) + (int)(lines * Font.ExtraLinePixels)); + if (Loaded) + { + if (Window is not null && Window.CanControleUpdate) + { + if (!Window.Context.IsCurrent) + { + try + { + Window.Context.MakeCurrent(); + GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1); + + } + catch (Exception e) + { + Console.WriteLine(e); + } + } + + if (Window.Context.IsCurrent) + { + Parent!.TryDraw(); + } + } + } + } + } + + public static Color4[] Rainbow = new[] + { + Color4.Red, + new(255,154,0,255), + new(208, 222, 33, 255), + new(79, 220, 74, 255), + new(63, 218, 216, 255), + new(47, 201, 226, 255), + new(28, 127, 238, 255), + new(95, 21, 242, 255), + new(186, 12, 248, 255), + new(251, 7, 217, 255) + }; + + public static Color4 LinkColor = Color4.Cyan; + + private List Links = new(); + + + public override void Draw(int x, int y, int ww, int hh) + { + if (Visible && Loaded) + { + if (!Window!.Context.IsCurrent) Window.Context.MakeCurrent(); + Shader.Use(); + GL.Enable(EnableCap.Blend); + GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); + GL.BlendFunc(0, BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); + Shader.SetMatrixF4("projection", Window.WindowSizeMatrix); + + GL.BindVertexArray(VAO); + + float angle_rad = (float)Math.Atan2(DIR.Y, DIR.X); + Matrix4 rotateM = Matrix4.CreateRotationZ(angle_rad); + Matrix4 transOriginM = Matrix4.CreateTranslation(new Vector3(loc_.X + Parent!.IntToWindow(0), loc_.Y + (MaxLineSizes[0].Item1.Y * Scale) + Parent!.IntToWindow(0, true), 0f)); + float char_x = 0.0f; + + GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1); + + float hhh = 0; + int NextCommand = 0; + List Active_Grads = new(); + List Active_Fonts = new(); + List Active_Links = new(); + Dictionary Olds = new(); + int line = 0; + int count = 0; + for (int i = 0; i < text_Calculated.Length; i++) + { + FontInteraction charfont = Font; + while (Commands.Count != 0 && NextCommand < Commands.Count && i == Commands[NextCommand].Item2) + { + switch (Commands[NextCommand].Item1) + { + case TextCode.Gradient or TextCode.Rainbow or TextCode.Color: + Active_Grads.Add(NextCommand); + break; + case TextCode.Font: + Active_Fonts.Add(NextCommand); + break; + case TextCode.url: + Active_Grads.Add(NextCommand); + Active_Links.Add(new((int)char_x, (int)hhh)); + break; + } + NextCommand++; + } + + if (Active_Fonts.Count != 0) + { + int g = Active_Fonts[Active_Fonts.Count - 1]; + Tuple com = Commands[g]; + + if (com.Item1 == TextCode.Font) + { + charfont = (FontInteraction)com.Item4!; + } + + if (com.Item3 <= i) + { + Active_Fonts.RemoveAt(Active_Fonts.Count-1); + } + } + + if (Active_Grads.Count != 0) + { + Tuple com = Commands[Active_Grads[Active_Grads.Count - 1]]; + (Color4, Color4) col; + + if (com.Item1 == TextCode.Rainbow) + { + Tuple item4 = (Tuple)com.Item4!; + col = getGradcols(com.Item2, i, com.Item3, 0,line, item4.Item3, item4.Item1, Rainbow); + } + else if (com.Item1 == TextCode.Color) + { + col = new((Color4)com.Item4!, (Color4)com.Item4!); + } + else if (com.Item1 == TextCode.url) + { + col = new(LinkColor, LinkColor); + } + else + { + Tuple item4 = (Tuple)com.Item4!; + col = getGradcols(com.Item2, i, com.Item3, item4.Item3, line, item4.Item4, item4.Item2, item4.Item1); + } + GL.Uniform4(Shader.GetUniformLocation("textColor"), col.Item1); + GL.Uniform4(Shader.GetUniformLocation("rightColor"), col.Item2); + if (com.Item3 == i) + { + if (com.Item1 == TextCode.url) + { + int index = Active_Links.Count - 1; + Vector2i now = new((int)char_x, (int)hhh); + Vector2i lc = Active_Links[index]; + Vector2i sz = new(now.X - Active_Links[Active_Links.Count - 1].X, + MaxLineSizes[line].Item1.Y); + if (Links.Count <= index || Links[index].Location != Active_Links[index] || Links[index].Size != sz) + { + if (Links.Count > count)Links.RemoveAt(count); + + SubHitBox hb = new() + { + Location = lc, + Size = sz, + HoverMouse = MouseCursor.Hand + }; + hb.Clicked += _ => + { + try + { + if (OperatingSystem.IsWindows()) + Process.Start((string)com.Item4!); + else if (OperatingSystem.IsLinux()) + { + Process.Start("xdg-open", (string)com.Item4!); + } + } + catch (Exception e) + { + Console.WriteLine(e); + } + + return Task.CompletedTask; + }; + Links.Insert(count, hb); + SubHitBoxes.Add(hb); + count++; + } + + Active_Links.RemoveAt(Active_Links.Count-1); + } + Active_Grads.RemoveAt(Active_Grads.Count-1); + } + } + else + { + GL.Uniform4(Shader.GetUniformLocation("textColor"), DefaultColor); + GL.Uniform4(Shader.GetUniformLocation("rightColor"), DefaultColor); + } + + + char c; + if (PasswordChar is null) + c = text_Calculated[i]; + else + c = PasswordChar.Value; + bool n = (c == '\n'); + if ((!_characters[Window!.Context].ContainsKey(charfont) || !_characters[Window!.Context][charfont].ContainsKey(c) ) && !n) + { + _ = Texture.TextureForChar(Window!.Context, charfont, c, Shader); + } + + if (n) + { + hhh += ((float)MaxLineSizes[line].Item1.Y * + ((float)MaxLineSizes[line].Item2.CurrentFonts[0].Face.Height / + (float)MaxLineSizes[line].Item2.CurrentFonts[0].Face.UnitsPerEM) * (float)this.Scale); + hhh += Font.ExtraLinePixels; + char_x = 0f; + line++; + } + else + { + if (!_characters[Window!.Context][charfont].ContainsKey(c)) continue; + Character ch = _characters[Window!.Context][charfont][c]; + + float w = ch.Size.X * Scale; + float h = ch.Size.Y * Scale; + float xrel = char_x + ch.Bearing.X * Scale; + float yrel = (ch.Size.Y - ch.Bearing.Y) * Scale; + yrel += hhh; + char_x += (ch.Advance >> 6) * Scale; + Matrix4 scaleM = Matrix4.CreateScale(new Vector3(w, h, 1.0f)); + Matrix4 transRelM = Matrix4.CreateTranslation(new Vector3(xrel, yrel, 0.0f)); + + Matrix4 modelM = scaleM * transRelM * rotateM * transOriginM; + GL.UniformMatrix4(Shader.GetUniformLocation("model"), false, ref modelM); + + ch.Texture.Use(); + + GL.DrawArrays(PrimitiveType.Triangles, 0, 6); + } + } + } + } +} \ No newline at end of file diff --git a/Luski/GUI/MainScreen/UI/LuskiControls/ProfileView.cs b/Luski/GUI/MainScreen/UI/LuskiControls/ProfileView.cs index 4911f43..3cc0da2 100644 --- a/Luski/GUI/MainScreen/UI/LuskiControls/ProfileView.cs +++ b/Luski/GUI/MainScreen/UI/LuskiControls/ProfileView.cs @@ -1,6 +1,8 @@ using GraphicsManager.Interfaces; using GraphicsManager.Objects; +using GraphicsManager.Objects.Core; using Luski.net.Structures.Public; +using Luski.Shared.PublicServers.V1.Enums; using OpenTK.Mathematics; namespace Luski.GUI.MainScreen.UI.LuskiControls; @@ -9,7 +11,7 @@ public class ProfileView : UserControl { public SocketUser User { get; set; } - private ProfileView(IRenderObject user, SocketUser u, ServerProfile p, Role r, Color? c = null) + private ProfileView(IRenderObject user, SocketUser u, ServerProfile p, Role r, Color[] c, ColorType ct) { this.User = u; base.Size = new(244.ScaleInt(), 44.ScaleInt()); @@ -17,14 +19,27 @@ public class ProfileView : UserControl user.Location = new(8.ScaleInt(), 6.ScaleInt(), 0); user.ForceDistanceUpdate(this); user.IgnoreHover = true; - Color4 col = r.Color.ToColor4(); - if (c is not null) col = c.ToColor4(); - Label uname = new(Globals.DefaultFont) + + LabelBase uname; + if (ct == ColorType.Full) { - Text = p.DisplayName, - Color = col, - IgnoreHover = true - }; + uname = new Label(Globals.DefaultFont) + { + Text = p.DisplayName, + Color = c[0].ToColor4(), + IgnoreHover = true + }; + } + else + { + uname = new AdvancedGradientLabel(Globals.DefaultFont) + { + Text = p.DisplayName, + Colors = c.ToColor4Array(), + IgnoreHover = true + }; + } + uname.Location = new(user.Location.X + user.Size.X + 8.ScaleInt(), (user.Location.Y + (user.Size.Y / 2) - (uname.Size.Y / 2)), 0); Controls.Add(uname); @@ -33,7 +48,16 @@ public class ProfileView : UserControl public static async Task Make(SocketUser u, ServerProfile p, Role r) { - ProfileView m = new(await p.MakeRct(u, new(32.ScaleInt())), u, p, r); + ColorType ct = await u.GetColorType(); + Color[] c = await u.GetColors(); + ColorType? cct = await p.GetColorType(); + Color[]? cc = await p.GetColors(); + if (cc is not null) + { + c = cc; + ct = cct!.Value; + } + ProfileView m = new(await p.MakeRct(u, new(32.ScaleInt())), u, p, r, c, ct); return m; } } \ No newline at end of file diff --git a/Luski/GUI/MainScreen/UI/LuskiSettings/Core/ISettingsPage.cs b/Luski/GUI/MainScreen/UI/LuskiControls/SettingsMenuBase/Core/ISettingsPage.cs similarity index 80% rename from Luski/GUI/MainScreen/UI/LuskiSettings/Core/ISettingsPage.cs rename to Luski/GUI/MainScreen/UI/LuskiControls/SettingsMenuBase/Core/ISettingsPage.cs index a026438..251f498 100644 --- a/Luski/GUI/MainScreen/UI/LuskiSettings/Core/ISettingsPage.cs +++ b/Luski/GUI/MainScreen/UI/LuskiControls/SettingsMenuBase/Core/ISettingsPage.cs @@ -2,7 +2,7 @@ using GraphicsManager.Interfaces; using GraphicsManager.Objects.Core; using OpenTK.Mathematics; -namespace Luski.GUI.MainScreen.UI.LuskiSettings.Core; +namespace Luski.GUI.MainScreen.UI.LuskiControls.SettingsMenuBase.Core; public interface ISettingsPage : IRenderObject { diff --git a/Luski/GUI/MainScreen/UI/LuskiSettings/Core/PageFlow.cs b/Luski/GUI/MainScreen/UI/LuskiControls/SettingsMenuBase/Core/PageFlow.cs similarity index 92% rename from Luski/GUI/MainScreen/UI/LuskiSettings/Core/PageFlow.cs rename to Luski/GUI/MainScreen/UI/LuskiControls/SettingsMenuBase/Core/PageFlow.cs index 3b676bd..e61bc9f 100644 --- a/Luski/GUI/MainScreen/UI/LuskiSettings/Core/PageFlow.cs +++ b/Luski/GUI/MainScreen/UI/LuskiControls/SettingsMenuBase/Core/PageFlow.cs @@ -2,7 +2,7 @@ using GraphicsManager.Enums; using GraphicsManager.Objects; using GraphicsManager.Objects.Core; -namespace Luski.GUI.MainScreen.UI.LuskiSettings.Core; +namespace Luski.GUI.MainScreen.UI.LuskiControls.SettingsMenuBase.Core; public class PageFlow : FlowLayout, ISettingsPage { diff --git a/Luski/GUI/MainScreen/UI/LuskiSettings/Core/PageTab.cs b/Luski/GUI/MainScreen/UI/LuskiControls/SettingsMenuBase/Core/PageTab.cs similarity index 97% rename from Luski/GUI/MainScreen/UI/LuskiSettings/Core/PageTab.cs rename to Luski/GUI/MainScreen/UI/LuskiControls/SettingsMenuBase/Core/PageTab.cs index 63f13a8..ba6bd51 100644 --- a/Luski/GUI/MainScreen/UI/LuskiSettings/Core/PageTab.cs +++ b/Luski/GUI/MainScreen/UI/LuskiControls/SettingsMenuBase/Core/PageTab.cs @@ -4,7 +4,7 @@ using GraphicsManager.Objects; using GraphicsManager.Objects.Core; using OpenTK.Mathematics; -namespace Luski.GUI.MainScreen.UI.LuskiSettings.Core; +namespace Luski.GUI.MainScreen.UI.LuskiControls.SettingsMenuBase.Core; public class PageTab : UserControl { diff --git a/Luski/GUI/MainScreen/UI/LuskiSettings/Core/SettingsCategory.cs b/Luski/GUI/MainScreen/UI/LuskiControls/SettingsMenuBase/Core/SettingsCategory.cs similarity index 90% rename from Luski/GUI/MainScreen/UI/LuskiSettings/Core/SettingsCategory.cs rename to Luski/GUI/MainScreen/UI/LuskiControls/SettingsMenuBase/Core/SettingsCategory.cs index 195625a..8f1ab87 100644 --- a/Luski/GUI/MainScreen/UI/LuskiSettings/Core/SettingsCategory.cs +++ b/Luski/GUI/MainScreen/UI/LuskiControls/SettingsMenuBase/Core/SettingsCategory.cs @@ -3,9 +3,9 @@ using GraphicsManager.Objects; using GraphicsManager.Objects.Core; using OpenTK.Mathematics; -namespace Luski.GUI.MainScreen.UI.LuskiSettings.Core; +namespace Luski.GUI.MainScreen.UI.LuskiControls.SettingsMenuBase.Core; -public class SettingsCategory : UserControl +public class SettingsCategory : UserControl where TSettingsMenu : SettingsMenu { private Label Top; private static FontInteraction? fi; @@ -15,9 +15,9 @@ public class SettingsCategory : UserControl get => Top.Text; } - private SettingsMenu ss; + private TSettingsMenu ss; - public SettingsCategory(string Name, SettingsMenu SS) + public SettingsCategory(string Name, TSettingsMenu SS) { ss = SS; if (fi is null) diff --git a/Luski/GUI/MainScreen/UI/PublicServers/ServerSettings.cs b/Luski/GUI/MainScreen/UI/LuskiControls/SettingsMenuBase/SettingsMenu.cs similarity index 72% rename from Luski/GUI/MainScreen/UI/PublicServers/ServerSettings.cs rename to Luski/GUI/MainScreen/UI/LuskiControls/SettingsMenuBase/SettingsMenu.cs index e57c531..0118ea9 100644 --- a/Luski/GUI/MainScreen/UI/PublicServers/ServerSettings.cs +++ b/Luski/GUI/MainScreen/UI/LuskiControls/SettingsMenuBase/SettingsMenu.cs @@ -1,39 +1,29 @@ using GraphicsManager.Enums; using GraphicsManager.Interfaces; using GraphicsManager.Objects; -using Luski.GUI.MainScreen.UI.PublicServers.ServerSettingPages; -using Luski.net; +using Luski.GUI.MainScreen.UI.LuskiControls.SettingsMenuBase.Core; using OpenTK.Mathematics; -namespace Luski.GUI.MainScreen.UI.PublicServers; +namespace Luski.GUI.MainScreen.UI.LuskiControls.SettingsMenuBase; -public class ServerSettings : UserControl +public class SettingsMenu : UserControl { private string BehindName; - public ServerSettingPageTab? Selected; + public PageTab? Selected; public FlowLayout fl; - public ServerSettings(PublicServer ps) + public SettingsMenu(string Name) { base.BackgroundColor = new(34, 34, 34, 255); base.Size = Globals.ms.ClientSize; BehindName = Globals.ms.Title; - Globals.ms.Title = $"Server Settings - Luski"; + Globals.ms.Title = Name; fl = new() { BackgroundColor = new(20, 20, 20, 255), Size = new(307.ScaleInt(), base.Size.Y), Anchor = ObjectAnchor.Top | ObjectAnchor.Left | ObjectAnchor.Bottom }; - ServerSettingCategory ssc = new(ps.Name, this); - ServerRolePage srp; - ServerSettingPageTab cb = ssc.AddPage(srp = new(ps) - { - BackgroundColor = base.BackgroundColor - }); - Controls.Add(srp); - fl.Controls.Add(ssc); - cb.ToggleSelected().Wait(); Anchor = ObjectAnchor.All; Controls.Add(fl); Rectangle closebtn = new(Globals.ms.TextureManager.GetTextureResource("close.png")) diff --git a/Luski/GUI/MainScreen/UI/LuskiControls/TextBox.cs b/Luski/GUI/MainScreen/UI/LuskiControls/TextBox.cs index 40b2534..144c39c 100644 --- a/Luski/GUI/MainScreen/UI/LuskiControls/TextBox.cs +++ b/Luski/GUI/MainScreen/UI/LuskiControls/TextBox.cs @@ -323,6 +323,10 @@ public class TextBox : UserControl if (OnNewLine is not null) OnNewLine.Invoke().Wait(); BlockDraw = false; Text += '\n'; + CursorLocation++; + var f = _label.GetCharLocation(CursorLocation); + Pointer.Location = _label.Location + new Vector3i(f.X, f.Y, 0); + Pointer.Visible = true; } else { @@ -334,9 +338,10 @@ public class TextBox : UserControl if (KeyArgs.Key == Keys.V && KeyArgs.Control && Window is not null) { + try { - Text += Window.ClipboardString; + SendClipEvent(Window.ClipboardString); if (LetterPress is not null) LetterPress.Invoke().Wait(); } catch diff --git a/Luski/GUI/MainScreen/UI/LuskiControls/ToggleSwitch.cs b/Luski/GUI/MainScreen/UI/LuskiControls/ToggleSwitch.cs index 7e7ab67..dbf7c59 100644 --- a/Luski/GUI/MainScreen/UI/LuskiControls/ToggleSwitch.cs +++ b/Luski/GUI/MainScreen/UI/LuskiControls/ToggleSwitch.cs @@ -9,7 +9,7 @@ public class ToggleSwitch : UserControl public ToggleSwitch() :base(Globals.ms.TextureManager.GetTextureResource("Toggle.png")) { - base.Size = new(40.ScaleInt(), 24.ScaleInt()); + base.SetSize(40.ScaleInt(), 24.ScaleInt()); base.BackgroundColor = OffBackgroundColor; Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context]; Clicked += o => diff --git a/Luski/GUI/MainScreen/UI/LuskiControls/UserView.cs b/Luski/GUI/MainScreen/UI/LuskiControls/UserView.cs index 743dbcf..8ed66a3 100644 --- a/Luski/GUI/MainScreen/UI/LuskiControls/UserView.cs +++ b/Luski/GUI/MainScreen/UI/LuskiControls/UserView.cs @@ -1,6 +1,8 @@ using GraphicsManager.Interfaces; using GraphicsManager.Objects; +using GraphicsManager.Objects.Core; using Luski.net.Structures.Public; +using Luski.Shared.PublicServers.V1.Enums; using OpenTK.Mathematics; namespace Luski.GUI.MainScreen.UI.LuskiControls; @@ -16,15 +18,37 @@ public class UserView : UserControl base.BackgroundColor = new(34, 34, 34, 255); user.Location = new(8.ScaleInt(), 6.ScaleInt(), 0); user.ForceDistanceUpdate(this); - Label uname = new(Globals.DefaultFont) + if (r.ColorType == ColorType.Full) { - Text = p.DisplayName, - Color = r.Color.ToColor4() - }; - if (offline) uname.Color = new(uname.Color.R, uname.Color.G, uname.Color.B, uname.Color.A * 0.6f); - uname.Location = new(user.Location.X + user.Size.X + 8.ScaleInt(), - (user.Location.Y + (user.Size.Y / 2) - (uname.Size.Y / 2)), 0); - Controls.Add(uname); + Label uname = new(Globals.DefaultFont) + { + Text = p.DisplayName, + Color = r.Colors[0].ToColor4() + }; + if (offline) uname.Color = new(uname.Color.R, uname.Color.G, uname.Color.B, uname.Color.A * 0.6f); + uname.Location = new(user.Location.X + user.Size.X + 8.ScaleInt(), + (user.Location.Y + (user.Size.Y / 2) - (uname.Size.Y / 2)), 0); + Controls.Add(uname); + } + else + { + AdvancedGradientLabel uname = new(Globals.DefaultFont) + { + Text = p.DisplayName, + Colors = r.Colors.ToColor4Array() + }; + if (offline) + { + for (int i = 0; i < uname.Colors.Length; i++) + { + uname.Colors[i] = new(uname.Colors[i].R, uname.Colors[i].G, uname.Colors[i].B, + uname.Colors[i].A * 0.6f); + } + } + uname.Location = new(user.Location.X + user.Size.X + 8.ScaleInt(), + (user.Location.Y + (user.Size.Y / 2) - (uname.Size.Y / 2)), 0); + Controls.Add(uname); + } Controls.Add(user); } diff --git a/Luski/GUI/MainScreen/UI/LuskiSettings/GlobalSettingsMenu.cs b/Luski/GUI/MainScreen/UI/LuskiSettings/GlobalSettingsMenu.cs new file mode 100644 index 0000000..9a050a9 --- /dev/null +++ b/Luski/GUI/MainScreen/UI/LuskiSettings/GlobalSettingsMenu.cs @@ -0,0 +1,37 @@ +using GraphicsManager.Enums; +using Luski.GUI.MainScreen.UI.LuskiControls.SettingsMenuBase; +using Luski.GUI.MainScreen.UI.LuskiControls.SettingsMenuBase.Core; +using Luski.GUI.MainScreen.UI.LuskiSettings.Pages.AdvancedSettings; +using Luski.GUI.MainScreen.UI.LuskiSettings.Pages.AppSettings; + +namespace Luski.GUI.MainScreen.UI.LuskiSettings; + +public class GlobalSettingsMenu : SettingsMenu +{ + private Appearance a; + + public GlobalSettingsMenu() + :base("Settings - Luski") + { + 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(); + } + 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; + } +} \ 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 index f1b37c4..2f806c7 100644 --- a/Luski/GUI/MainScreen/UI/LuskiSettings/Pages/AdvancedSettings/ExperimentSettings.cs +++ b/Luski/GUI/MainScreen/UI/LuskiSettings/Pages/AdvancedSettings/ExperimentSettings.cs @@ -1,6 +1,5 @@ -using GraphicsManager.Objects; using Luski.Classes; -using Luski.GUI.MainScreen.UI.LuskiSettings.Core; +using Luski.GUI.MainScreen.UI.LuskiControls.SettingsMenuBase.Core; using Luski.GUI.MainScreen.UI.SettingsPanel; namespace Luski.GUI.MainScreen.UI.LuskiSettings.Pages.AdvancedSettings; @@ -22,7 +21,7 @@ public class ExperimentSettings : PageFlow { g.line.WindowLoaded += _ => { - ParentResize(new(Globals.ms.ClientSize)); + ParentResize(); return Task.CompletedTask; }; } diff --git a/Luski/GUI/MainScreen/UI/LuskiSettings/Pages/AdvancedSettings/Updater.cs b/Luski/GUI/MainScreen/UI/LuskiSettings/Pages/AdvancedSettings/Updater.cs index 2e63702..dfa6eac 100644 --- a/Luski/GUI/MainScreen/UI/LuskiSettings/Pages/AdvancedSettings/Updater.cs +++ b/Luski/GUI/MainScreen/UI/LuskiSettings/Pages/AdvancedSettings/Updater.cs @@ -2,7 +2,7 @@ using System.Reflection; using GraphicsManager.Enums; using Luski.Classes; using Luski.GUI.MainScreen.UI.LuskiControls; -using Luski.GUI.MainScreen.UI.LuskiSettings.Core; +using Luski.GUI.MainScreen.UI.LuskiControls.SettingsMenuBase.Core; namespace Luski.GUI.MainScreen.UI.LuskiSettings.Pages.AdvancedSettings; @@ -84,7 +84,7 @@ public class Updater : PageFlow }; WindowLoaded += _ => { - Globals.ms.ForceUpdate(new(Globals.ms.CS)); + Globals.ms.ForceUpdate(); return Task.CompletedTask; }; } diff --git a/Luski/GUI/MainScreen/UI/LuskiSettings/Pages/AppSettings/Appearance.cs b/Luski/GUI/MainScreen/UI/LuskiSettings/Pages/AppSettings/Appearance.cs index c230126..bc810fb 100644 --- a/Luski/GUI/MainScreen/UI/LuskiSettings/Pages/AppSettings/Appearance.cs +++ b/Luski/GUI/MainScreen/UI/LuskiSettings/Pages/AppSettings/Appearance.cs @@ -2,7 +2,7 @@ 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.LuskiControls.SettingsMenuBase.Core; using Luski.GUI.MainScreen.UI.SettingsPanel; using OpenTK.Mathematics; diff --git a/Luski/GUI/MainScreen/UI/LuskiSettings/Pages/AppSettings/General.cs b/Luski/GUI/MainScreen/UI/LuskiSettings/Pages/AppSettings/General.cs index 12b8b17..63ad698 100644 --- a/Luski/GUI/MainScreen/UI/LuskiSettings/Pages/AppSettings/General.cs +++ b/Luski/GUI/MainScreen/UI/LuskiSettings/Pages/AppSettings/General.cs @@ -1,6 +1,6 @@ using System.Reflection; using Luski.Classes; -using Luski.GUI.MainScreen.UI.LuskiSettings.Core; +using Luski.GUI.MainScreen.UI.LuskiControls.SettingsMenuBase.Core; namespace Luski.GUI.MainScreen.UI.LuskiSettings.Pages.AppSettings; diff --git a/Luski/GUI/MainScreen/UI/LuskiSettings/SettingsMenu.cs b/Luski/GUI/MainScreen/UI/LuskiSettings/SettingsMenu.cs deleted file mode 100644 index 20d2b4a..0000000 --- a/Luski/GUI/MainScreen/UI/LuskiSettings/SettingsMenu.cs +++ /dev/null @@ -1,81 +0,0 @@ -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/Category.cs b/Luski/GUI/MainScreen/UI/PublicServers/Category.cs index ad85f8f..eadd40f 100644 --- a/Luski/GUI/MainScreen/UI/PublicServers/Category.cs +++ b/Luski/GUI/MainScreen/UI/PublicServers/Category.cs @@ -1,8 +1,11 @@ using GraphicsManager.Enums; using GraphicsManager.Interfaces; using GraphicsManager.Objects; +using GraphicsManager.Objects.Core; using Luski.GUI.MainScreen.Interfaces; +using Luski.GUI.MainScreen.UI.LuskiControls; using Luski.net.Structures.Public; +using Luski.Shared.PublicServers.V1.Enums; using OpenTK.Windowing.Common.Input; namespace Luski.GUI.MainScreen.UI.PublicServers; @@ -13,12 +16,12 @@ public class Category : UserControl, IChannelAdder public SocketCategory CurrentCategory { get; set; } private List cc = new(); private List cl = new(); - private Label ee; + private LabelBase ee; private ChannelSelector CS; public event Func? AddY; - private Label Name; + private LabelBase Name; public UserControl tmp; public static Task MakeCat(SocketCategory cat, ChannelSelector cs) @@ -27,7 +30,7 @@ public class Category : UserControl, IChannelAdder c.CurrentCategory = cat; c.CS = cs; c.Anchor = ObjectAnchor.All; - c.Size = new(307.ScaleInt(), 40.ScaleInt()); + c.SetSize(307.ScaleInt(), 40.ScaleInt()); c.tmp = new() { Size = c.Size, @@ -37,20 +40,41 @@ public class Category : UserControl, IChannelAdder c.tmp.Clicked += c.TmpOnClicked; c.tmp.HoverMouse = MouseCursor.Hand; c.Controls.Add(c.tmp); - c.tmp.Controls.Add(c.ee = new(Globals.DefaultFont) + if (cat.ColorType == ColorType.Full) { - Text = ">", - Location = new(5.ScaleInt()), - Color = cat.Color.ToColor4(), - DIR = new(1,0), - IgnoreHover = true - }); - c.tmp.Controls.Add(c.Name = new Label(Globals.DefaultFont) + c.tmp.Controls.Add(c.ee = new Label(Globals.DefaultFont) + { + Text = ">", + Location = new(5.ScaleInt()), + Color = cat.Colors[0].ToColor4(), + DIR = new(1,0), + IgnoreHover = true + }); + c.tmp.Controls.Add(c.Name = new Label(Globals.DefaultFont) + { + Text = cat.Name, + Color = cat.Colors[0].ToColor4(), + IgnoreHover = true + }); + } + else { - Text = cat.Name, - Color = c.ee.Color, - IgnoreHover = true - }); + c.tmp.Controls.Add(c.ee = new AdvancedGradientLabel(Globals.DefaultFont) + { + Text = ">", + Location = new(5.ScaleInt()), + Colors = cat.Colors.ToColor4Array(), + DIR = new(1,0), + IgnoreHover = true + }); + c.tmp.Controls.Add(c.Name = new AdvancedGradientLabel(Globals.DefaultFont) + { + Text = cat.Name, + Colors = cat.Colors.ToColor4Array(), + IgnoreHover = true + }); + } + c.Clicked += c.AllOnClicked; c.Name.Location = new(26.ScaleInt(), (((c.Size.Y - c.Name.Size.Y)/2)), 0); c.Members = new() @@ -60,7 +84,7 @@ public class Category : UserControl, IChannelAdder IgnoreHover = true }; c.ee.Location = new(c.ee.Location.X, c.Name.Location.Y, 0); - c.Members.Size = new(c.Size.X - c.Members.Location.X, 0); + c.Members.SetSize(c.Size.X - c.Members.Location.X, 0); c.Controls.Add(c.Members); c.Members.ForceDistanceUpdate(c); c.tmp.HoverMouse = MouseCursor.Hand; diff --git a/Luski/GUI/MainScreen/UI/PublicServers/Channel.cs b/Luski/GUI/MainScreen/UI/PublicServers/Channel.cs index 9388fb7..3d5a0a9 100644 --- a/Luski/GUI/MainScreen/UI/PublicServers/Channel.cs +++ b/Luski/GUI/MainScreen/UI/PublicServers/Channel.cs @@ -2,6 +2,7 @@ using GraphicsManager.Enums; using GraphicsManager.Interfaces; using GraphicsManager.Objects; using GraphicsManager.Objects.Core; +using Luski.GUI.MainScreen.UI.LuskiControls; using Luski.net.Enums; using Luski.net.Structures.Public; using Luski.Shared.PublicServers.V1.Enums; @@ -40,12 +41,26 @@ public class Channel : UserControl r.Textures.Add(tex); r.Shader = Rectangle.DefaultAlphaTextureShader[Globals.ms.Context]; Controls.Add(r); - ChannelName = new Label(Globals.DefaultFont) + + if (chan.ColorType == ColorType.Full) { - Text = chan.Name, - Color = chan.Color.ToColor4(), - IgnoreHover = true - }; + ChannelName = new Label(Globals.DefaultFont) + { + Text = chan.Name, + Color = chan.Colors[0].ToColor4(), + IgnoreHover = true + }; + } + else + { + ChannelName = new AdvancedGradientLabel(Globals.DefaultFont) + { + Text = chan.Name, + Colors = chan.Colors.ToColor4Array(), + IgnoreHover = true + }; + } + Controls.Add(ChannelName); Clicked += AllOnClicked; ChannelName.Location = new(40.ScaleInt(), @@ -65,12 +80,24 @@ public class Channel : UserControl Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context]; int i = 4.ScaleInt(); GC.Collect(); - ChannelName = new Label(Globals.DefaultFont) + if (chan.ColorType == ColorType.Full) { - Text = chan.Name, - Color = chan.Color.ToColor4(), - IgnoreHover = true - }; + ChannelName = new Label(Globals.DefaultFont) + { + Text = chan.Name, + Color = chan.Colors[0].ToColor4(), + IgnoreHover = true + }; + } + else + { + ChannelName = new AdvancedGradientLabel(Globals.DefaultFont) + { + Text = chan.Name, + Colors = chan.Colors.ToColor4Array(), + IgnoreHover = true + }; + } Controls.Add(ChannelName); Clicked += AllOnClicked; ChannelName.Location = new(i, @@ -128,7 +155,7 @@ public class Channel : UserControl Console.WriteLine(e); } } - public Label ChannelName; + public LabelBase ChannelName; public Rectangle r; public static async Task MakeChannel(SocketChannel chan, ChannelSelector cs) diff --git a/Luski/GUI/MainScreen/UI/PublicServers/ChatMessage.cs b/Luski/GUI/MainScreen/UI/PublicServers/ChatMessage.cs index b0451bf..beb5a96 100644 --- a/Luski/GUI/MainScreen/UI/PublicServers/ChatMessage.cs +++ b/Luski/GUI/MainScreen/UI/PublicServers/ChatMessage.cs @@ -2,8 +2,11 @@ using System.Diagnostics; using GraphicsManager.Enums; using GraphicsManager.Interfaces; using GraphicsManager.Objects; +using GraphicsManager.Objects.Core; +using Luski.GUI.MainScreen.UI.LuskiControls; using Luski.net.Structures.Main; using Luski.net.Structures.Public; +using Luski.Shared.PublicServers.V1.Enums; using OpenTK.Mathematics; using OpenTK.Windowing.Common.Input; using OpenTK.Windowing.GraphicsLibraryFramework; @@ -20,7 +23,7 @@ public class ChatMessage : UserControl private IRenderObject LastObject; public List MessageObjs = new(); - private Label FirstL; + private LabelBase FirstL; public readonly double HorPadding = 12.ScaleDouble(), VerticalPadding = 0.ScaleDouble(); @@ -31,18 +34,23 @@ public class ChatMessage : UserControl { SocketUser auth = (SocketUser)(await message.GetAuthor(CancellationToken.None)); ServerProfile prof = await message.GetProfile(CancellationToken.None); - Color? c = await prof.GetColor(); - if (c is null) c = await auth.GetColor(); - Color4 c4 = c.ToColor4(); - return new ChatMessage(p, message, await message.GetParent(CancellationToken.None), prof, await prof.MakeRct(auth, new(40.ScaleInt())), c4); + Color[]? c = await prof.GetColors(); + ColorType? ct = await prof.GetColorType(); + if (c is null) + { + c = await auth.GetColors(); + ct = await auth.GetColorType(); + } + Color4[] c4 = (ct!.Value == ColorType.Full ? new Color4[]{c[0].ToColor4()} : new Color4[]{c[0].ToColor4(), c[1].ToColor4()}); + return new ChatMessage(p, message, await message.GetParent(CancellationToken.None), prof, await prof.MakeRct(auth, new(40.ScaleInt())), ct.Value, c4); } - private ChatMessage(PublicChat p, SocketMessage message, SocketChannel chan, ServerProfile Author, IRenderObject UserIcon, Color4 UserNameColor) + private ChatMessage(PublicChat p, SocketMessage message, SocketChannel chan, ServerProfile Author, IRenderObject UserIcon, ColorType ct, Color4[] UserNameColor) { pc = p; - Label label1; - base.Size = new(723.5.ScaleInt(), 37.ScaleInt()); + LabelBase label1; + base.SetSize(723.5.ScaleInt(), 37.ScaleInt()); ch = chan; base.BackgroundColor = new(40, 40, 40, 255); Msg = message; @@ -84,7 +92,8 @@ public class ChatMessage : UserControl UserIcon.Location = new(10.ScaleInt(), 2.ScaleInt(), 0); Controls.Add(UserIcon); - Controls.Add(label1 = new Label(Globals.DefaultFont) { Color = UserNameColor, Text = Author.DisplayName }); + if (ct == ColorType.Full) Controls.Add(label1 = new Label(Globals.DefaultFont) { Color = UserNameColor[0], Text = Author.DisplayName }); + else Controls.Add(label1 = new AdvancedGradientLabel(Globals.DefaultFont) { Colors = UserNameColor, Text = Author.DisplayName }); label1.Location = new( 54.ScaleInt(), UserIcon.Location.Y, @@ -109,6 +118,10 @@ public class ChatMessage : UserControl }; } l.ContextMenu = lcm; + if (Msg.Context == "test message with picture") + { + //Console.WriteLine(Msg.FileIDs.Length); + } MessageObjs.Add(l); } Globals.Settings.DayTimeChanged += () => @@ -178,7 +191,7 @@ public class ChatMessage : UserControl public async Task AddMessage(SocketMessage msg) { BlockDraw = true; - Label newLabel; + LuskiLabel newLabel; if (!string.IsNullOrWhiteSpace(msg.Context)) { newLabel = new(Globals.MessageFont) @@ -199,7 +212,7 @@ public class ChatMessage : UserControl if (result) { newLabel.HoverMouse = MouseCursor.Hand; - newLabel.Color = Color4.Aqua; + newLabel.DefaultColor = Color4.Aqua; newLabel.Clicked += NewLabelOnClicked; } diff --git a/Luski/GUI/MainScreen/UI/PublicServers/ContentEmbed.cs b/Luski/GUI/MainScreen/UI/PublicServers/ContentEmbed.cs index 677a37f..28889b2 100644 --- a/Luski/GUI/MainScreen/UI/PublicServers/ContentEmbed.cs +++ b/Luski/GUI/MainScreen/UI/PublicServers/ContentEmbed.cs @@ -93,8 +93,8 @@ public class ContentEmbed : UserControl else if (size < 1000000000) fst = Math.Round(size / (double)1000000, 2) + " MB"; else if (size < 1000000000000) fst = Math.Round(size / (double)1000000000, 2) + " GB"; - base.Size = new(333, 66); - BackgroundColor = new(40, 40, 40, 255); + base.SetSize(333.ScaleInt(), 66.ScaleInt()); + base.BackgroundColor = new(40, 40, 40, 255); Controls.Add(fileSizeLabel = new Label(Globals.DefaultFont) { Text = fst, Location = new(64, 39, 0) }); Controls.Add(fileNameLabel = new Label(Globals.DefaultFont) { diff --git a/Luski/GUI/MainScreen/UI/PublicServers/PublicChat.cs b/Luski/GUI/MainScreen/UI/PublicServers/PublicChat.cs index 05d39bc..0cb71ad 100644 --- a/Luski/GUI/MainScreen/UI/PublicServers/PublicChat.cs +++ b/Luski/GUI/MainScreen/UI/PublicServers/PublicChat.cs @@ -3,6 +3,7 @@ using GraphicsManager; using GraphicsManager.Enums; using GraphicsManager.Interfaces; using GraphicsManager.Objects; +using GraphicsManager.Objects.Core; using Luski.GUI.MainScreen.UI.LuskiControls; using Luski.net.Structures.Public; using Luski.Shared.PublicServers.V1.Enums; @@ -19,7 +20,7 @@ public class PublicChat : UserControl { public FlowLayout MessageFlow; - private Label title, desc; + private LabelBase title, desc; private TextBox tb; private SocketChannel? Channel; UserControl titlecon; @@ -29,8 +30,7 @@ public class PublicChat : UserControl public PublicChat() { - - base.Size = new(980.ScaleInt(), 866.ScaleInt()); + base.SetSize(980.ScaleInt(), 866.ScaleInt()); base.BackgroundColor = new(40,40,40,255); Anchor = ObjectAnchor.All; Controls.Add(MessageFlow = new() @@ -102,8 +102,21 @@ public class PublicChat : UserControl tb.ForceDistanceUpdate(this); //tb.KeyPress += TbOnKeyPress; //Globals.Luski.MainServer.MessageReceived += LuskiOnMessageReceived; + FilesDroped += OnFilesDroped; + tb.FilesDroped += OnFilesDroped; + MessageFlow.FilesDroped += OnFilesDroped; + FileFlow = new() + { + BackgroundColor = base.BackgroundColor, + Size = new(MessageFlow.Size.X, 0), + Location = new(MessageFlow.Location.X, MessageFlow.Location.Y + MessageFlow.Size.Y, 0), + Anchor = ObjectAnchor.Left | ObjectAnchor.Bottom | ObjectAnchor.Right + }; + Controls.Add(FileFlow); } + + private bool ssss = false; private Task OnSizeChanged(IRenderObject arg) @@ -138,7 +151,7 @@ public class PublicChat : UserControl if (cm.Size.Y != ny) { - cm.Size = new(Size.X, ny); + cm.SetSize(Size.X, ny); MessageFlow.ReportSizeUpdate(cm); } ssss = false; @@ -169,12 +182,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, FakeProfile: Globals.ServerProfile); + var file = await Channel!.Server.UploadFile("/home/jacob/Pictures/Points.png"); + Console.WriteLine(file.ID); + await Channel!.SendMessage(tb.Text, Profile: Globals.ServerProfile, files: file); tb.Text = string.Empty; tb.CursorLocation = 0; } @@ -184,7 +196,7 @@ public class PublicChat : UserControl { BlockDraw = true; tb.Location = new(tb.Location.X, tb.Location.Y + (int)tb.Font.PixelHeight, 0); - MessageFlow.Size = new(MessageFlow.Size.X, MessageFlow.Size.Y + (int)tb.Font.PixelHeight); + MessageFlow.SetSize(MessageFlow.Size.X, MessageFlow.Size.Y + (int)tb.Font.PixelHeight); BlockDraw = false; return Task.CompletedTask; } @@ -363,6 +375,46 @@ public class PublicChat : UserControl public ChatMessage? LastChatMessageIndex; private bool loadingm = false; + private List FilesToUpload = new(); + private CompressedFlow FileFlow; + + private Task OnFilesDroped(IRenderObject arg1, string[] arg2) + { + int last = arg2.Length - 1; + BlockDraw = true; + for (int i = 0; i < last; i++) + { + AddFile(arg2[i], false); + } + BlockDraw = false; + AddFile(arg2[last]); + return Task.CompletedTask; + } + + public void AddFile(string FilePath, bool ReloadUI = true) + { + FileFlow.SizeUpdateNotIgnored += CFOnSizeChanged; + FileUpload FU = new(Channel!.Server, FilePath); + FileFlow.Controls.Add(FU); + FU.BackgroundColor = Color4.Red; + if (ReloadUI) TryDraw(); + } + + private int OldSize = 0; + + private Task CFOnSizeChanged(IRenderObject arg) + { + Console.WriteLine(arg.Size); + FileFlow.BackgroundColor = Color4.Green; + arg.Location = new(arg.Location.X, arg.Location.Y + OldSize - arg.Size.Y, 0); + OldSize = arg.Size.Y; + return Task.CompletedTask; + } + + public void RemoveFile(FileUpload FU) + { + } + public async Task LoadChannel(SocketChannel channel) { Channel = channel; @@ -374,6 +426,31 @@ public class PublicChat : UserControl memberflow.Controls.Clear(); await UserConOnClicked(UserCon!); } + + if (channel.ColorType == ColorType.Full) + { + titlecon.Controls.Remove(title, false); + if (title is not Label) title = new Label(title.Font) + { + Location = title.Location + }; + ((Label)title).Color = channel.Colors[0].ToColor4(); + titlecon.Controls.Add(title); + } + else + { + if (title is not AdvancedGradientLabel) + { + titlecon.Controls.Remove(title, false); + title = new AdvancedGradientLabel(title.Font) + { + Location = title.Location + }; + titlecon.Controls.Add(title); + } + ((AdvancedGradientLabel)title).Colors = channel.Colors.ToColor4Array(); + } + title.Text = channel.Name; var five = 5.ScaleInt(); title.Location = new(five + five, diff --git a/Luski/GUI/MainScreen/UI/PublicServers/ServerSettingCategory.cs b/Luski/GUI/MainScreen/UI/PublicServers/ServerSettingCategory.cs deleted file mode 100644 index 0f03e61..0000000 --- a/Luski/GUI/MainScreen/UI/PublicServers/ServerSettingCategory.cs +++ /dev/null @@ -1,67 +0,0 @@ -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.PublicServers; - -public class ServerSettingCategory : UserControl -{ - private Label Top; - private static FontInteraction? fi; - private Rectangle line; - public string Name - { - get => Top.Text; - } - - private ServerSettings ss; - - public ServerSettingCategory(string Name, ServerSettings 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 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); - 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 deleted file mode 100644 index 1ed131b..0000000 --- a/Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPageTab.cs +++ /dev/null @@ -1,96 +0,0 @@ -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 deleted file mode 100644 index a8bcb6d..0000000 --- a/Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPages/IPageBase.cs +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index 7076b8b..0000000 --- a/Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPages/PageBaseControl.cs +++ /dev/null @@ -1,38 +0,0 @@ -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 deleted file mode 100644 index 7999c80..0000000 --- a/Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPages/PageBaseFlow.cs +++ /dev/null @@ -1,38 +0,0 @@ -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/ServerSettings/Pages/Server/Roles/RoleIcon.cs similarity index 93% rename from Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPages/RoleIcon.cs rename to Luski/GUI/MainScreen/UI/PublicServers/ServerSettings/Pages/Server/Roles/RoleIcon.cs index 64967cd..5e2cde5 100644 --- a/Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPages/RoleIcon.cs +++ b/Luski/GUI/MainScreen/UI/PublicServers/ServerSettings/Pages/Server/Roles/RoleIcon.cs @@ -4,7 +4,7 @@ using Luski.net.Structures.Public; using OpenTK.Mathematics; using SixLabors.ImageSharp.Processing; -namespace Luski.GUI.MainScreen.UI.PublicServers.ServerSettingPages; +namespace Luski.GUI.MainScreen.UI.PublicServers.ServerSettings.Pages.Server.Roles; public class RoleIcon : UserControl { @@ -19,13 +19,14 @@ public class RoleIcon : UserControl TextureDisplay = TextureDisplay.HorizontalCenter; Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context]; base.Size = new(sri.RoleFlow.Size.X, 50.ScaleInt()); + //TODO what? 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() + BackgroundColor = role.Colors[0].ToColor4() }; Label name = new(Globals.ServerRoleFont) { diff --git a/Luski/GUI/MainScreen/UI/PublicServers/ServerSettings/Pages/Server/Roles/RoleMember.cs b/Luski/GUI/MainScreen/UI/PublicServers/ServerSettings/Pages/Server/Roles/RoleMember.cs new file mode 100644 index 0000000..815cfeb --- /dev/null +++ b/Luski/GUI/MainScreen/UI/PublicServers/ServerSettings/Pages/Server/Roles/RoleMember.cs @@ -0,0 +1,27 @@ +using GraphicsManager.Interfaces; +using GraphicsManager.Objects; +using Luski.net.Structures.Public; +using OpenTK.Mathematics; + +namespace Luski.GUI.MainScreen.UI.PublicServers.ServerSettings.Pages.Server.Roles; + +public class RoleMember : UserControl +{ + public RoleMember(ServerProfile p, SocketUser u) + { + base.Size = new(500.ScaleInt(), 40.ScaleInt()); + Task icon = p.MakeRct(u, new(24.ScaleInt())); + icon.Wait(); + int val = 8.ScaleInt(); + icon.Result.Location = new(val, val, 0); + Controls.Add(icon.Result); + Label dn = new(Globals.DefaultFont) + { + Text = p.DisplayName + }; + Controls.Add(dn); + + dn.Location = new(icon.Result.Location.X + icon.Result.Size.X + 5.ScaleInt(), + icon.Result.Location.Y + ((icon.Result.Size.Y - dn.Size.Y) / 2), 0); + } +} \ No newline at end of file diff --git a/Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPages/ServerRolePage.cs b/Luski/GUI/MainScreen/UI/PublicServers/ServerSettings/Pages/Server/Roles/Roles.cs similarity index 69% rename from Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPages/ServerRolePage.cs rename to Luski/GUI/MainScreen/UI/PublicServers/ServerSettings/Pages/Server/Roles/Roles.cs index b40b681..0aa8130 100644 --- a/Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPages/ServerRolePage.cs +++ b/Luski/GUI/MainScreen/UI/PublicServers/ServerSettings/Pages/Server/Roles/Roles.cs @@ -1,14 +1,15 @@ using GraphicsManager.Enums; +using Luski.GUI.MainScreen.UI.LuskiControls.SettingsMenuBase.Core; using Luski.net; using OpenTK.Mathematics; -namespace Luski.GUI.MainScreen.UI.PublicServers.ServerSettingPages; +namespace Luski.GUI.MainScreen.UI.PublicServers.ServerSettings.Pages.Server.Roles; -public class ServerRolePage : PageBaseControl +public class Roles : PageFlow { private ServerRoleInteraction Page; - public ServerRolePage(PublicServer ps) + public Roles(PublicServer ps) { PageName = "Roles"; Page = new(ps, this) @@ -17,7 +18,7 @@ public class ServerRolePage : PageBaseControl Anchor = ObjectAnchor.All }; Controls.Add(Page); - Globals.ms.ForceUpdate(new(Globals.ms.CS)); + Globals.ms.ForceUpdate(); } public override Color4 BackgroundColor diff --git a/Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPages/ServerRoleInteraction.cs b/Luski/GUI/MainScreen/UI/PublicServers/ServerSettings/Pages/Server/Roles/ServerRoleInteraction.cs similarity index 94% rename from Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPages/ServerRoleInteraction.cs rename to Luski/GUI/MainScreen/UI/PublicServers/ServerSettings/Pages/Server/Roles/ServerRoleInteraction.cs index af3c308..d82dfab 100644 --- a/Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPages/ServerRoleInteraction.cs +++ b/Luski/GUI/MainScreen/UI/PublicServers/ServerSettings/Pages/Server/Roles/ServerRoleInteraction.cs @@ -4,7 +4,7 @@ using Luski.net; using Luski.net.Structures.Public; using OpenTK.Mathematics; -namespace Luski.GUI.MainScreen.UI.PublicServers.ServerSettingPages; +namespace Luski.GUI.MainScreen.UI.PublicServers.ServerSettings.Pages.Server.Roles; public class ServerRoleInteraction : UserControl { @@ -12,7 +12,7 @@ public class ServerRoleInteraction : UserControl public RoleIcon Selected; public ServerRoleOptions SRO; - public ServerRoleInteraction(PublicServer server, ServerRolePage srp) + public ServerRoleInteraction(PublicServer server, Roles srp) { Task task = Task.Run(() => server.GetRoles()); task.Wait(); diff --git a/Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPages/ServerRoleOptions.cs b/Luski/GUI/MainScreen/UI/PublicServers/ServerSettings/Pages/Server/Roles/ServerRoleOptions.cs similarity index 94% rename from Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPages/ServerRoleOptions.cs rename to Luski/GUI/MainScreen/UI/PublicServers/ServerSettings/Pages/Server/Roles/ServerRoleOptions.cs index bf778cb..6bfd847 100644 --- a/Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPages/ServerRoleOptions.cs +++ b/Luski/GUI/MainScreen/UI/PublicServers/ServerSettings/Pages/Server/Roles/ServerRoleOptions.cs @@ -3,14 +3,12 @@ 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; +namespace Luski.GUI.MainScreen.UI.PublicServers.ServerSettings.Pages.Server.Roles; public class ServerRoleOptions : UserControl { @@ -211,6 +209,17 @@ public class ServerRoleOptions : UserControl SelectedLine.Size = new(ManageMembers.Size.X, Line.Size.Y); SelectedLine.Location = new(ManageMembers.Location.X, Line.Location.Y, Line.Location.Z); Page.Controls.Clear(); + var m = r.GetMembers(); + m.Wait(); + foreach (var meber in m.Result) + { + var p = meber.Server.GetProfile(meber.ServerProfile, CancellationToken.None); + p.Wait(); + Page.Controls.Add(new RoleMember(p.Result, meber) + { + BackgroundColor = Page.BackgroundColor + }); + } BlockDraw = false; TryDraw(); } diff --git a/Luski/GUI/MainScreen/UI/PublicServers/ServerSettings/PublicServerSettingsMenu.cs b/Luski/GUI/MainScreen/UI/PublicServers/ServerSettings/PublicServerSettingsMenu.cs new file mode 100644 index 0000000..49db837 --- /dev/null +++ b/Luski/GUI/MainScreen/UI/PublicServers/ServerSettings/PublicServerSettingsMenu.cs @@ -0,0 +1,25 @@ +using GraphicsManager.Enums; +using Luski.GUI.MainScreen.UI.LuskiControls.SettingsMenuBase; +using Luski.GUI.MainScreen.UI.LuskiControls.SettingsMenuBase.Core; +using Luski.GUI.MainScreen.UI.PublicServers.ServerSettings.Pages.Server.Roles; +using Luski.net; + +namespace Luski.GUI.MainScreen.UI.PublicServers.ServerSettings; + +public class PublicServerSettingsMenu : SettingsMenu +{ + public PublicServerSettingsMenu(PublicServer ps) : base("Server Settings - Luski") + { + SettingsCategory ServerCat = new(ps.Name, this); + Roles srp; + PageTab cb = ServerCat.AddPage(srp = new(ps) + { + BackgroundColor = base.BackgroundColor + }); + Controls.Add(srp); + fl.Controls.Add(ServerCat); + cb.ToggleSelected().Wait(); + Anchor = ObjectAnchor.All; + Controls.Add(fl); + } +} \ No newline at end of file diff --git a/Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPages/SaveWarning.cs b/Luski/GUI/MainScreen/UI/PublicServers/ServerSettings/SaveWarning.cs similarity index 96% rename from Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPages/SaveWarning.cs rename to Luski/GUI/MainScreen/UI/PublicServers/ServerSettings/SaveWarning.cs index 3ea740c..55461c5 100644 --- a/Luski/GUI/MainScreen/UI/PublicServers/ServerSettingPages/SaveWarning.cs +++ b/Luski/GUI/MainScreen/UI/PublicServers/ServerSettings/SaveWarning.cs @@ -2,7 +2,7 @@ using GraphicsManager.Enums; using GraphicsManager.Objects; using OpenTK.Mathematics; -namespace Luski.GUI.MainScreen.UI.PublicServers.ServerSettingPages; +namespace Luski.GUI.MainScreen.UI.PublicServers.ServerSettings; public class SaveWarning : UserControl { diff --git a/Luski/GUI/MainScreen/UI/ServerIcon.cs b/Luski/GUI/MainScreen/UI/ServerIcon.cs index c748036..3a9e6e3 100644 --- a/Luski/GUI/MainScreen/UI/ServerIcon.cs +++ b/Luski/GUI/MainScreen/UI/ServerIcon.cs @@ -94,7 +94,7 @@ public class ServerIcon : UserControl where TServer : Server Controls.Add(r); base.BackgroundColor = new(26, 26, 26, 255); this.Clicked += OnClicked; - base.Size = new(68.ScaleInt(), 48.ScaleInt()); + base.SetSize(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 c2fae12..51e1896 100644 --- a/Luski/GUI/MainScreen/UI/ServerLoginOverlay.cs +++ b/Luski/GUI/MainScreen/UI/ServerLoginOverlay.cs @@ -338,7 +338,7 @@ public class ServerLoginOverlay : UserControl, IServerOverlay DisplayName.Textures[0] = UserName.Textures[0]; rec.ForceDistanceUpdate(page); Globals.ms.TryDraw(); - Globals.ms.ForceUpdate(new(Size)); + Globals.ms.ForceUpdate(); } }; ca.Size = new((Form.Size.X - tb.Location.X - tb.Location.X - (tb.Location.X / 2)) / 2, ca.Size.Y); @@ -540,7 +540,7 @@ public class ServerLoginOverlay : UserControl, IServerOverlay } Globals.ms.Controls.Remove(this); - Globals.ms.ForceUpdate(new(Size)); + Globals.ms.ForceUpdate(); Globals.ms.TryDraw(); } @@ -556,7 +556,7 @@ public class ServerLoginOverlay : UserControl, IServerOverlay private string pfp = ""; - private Task RecOnFilesDroped(string[] arg) + private Task RecOnFilesDroped(IRenderObject obj, string[] arg) { Console.WriteLine(arg[0]); if (!arg[0].ToLower().EndsWith("png")) return Task.CompletedTask; diff --git a/Luski/GUI/MainScreenWindow.cs b/Luski/GUI/MainScreenWindow.cs index 8546115..99a8c5b 100644 --- a/Luski/GUI/MainScreenWindow.cs +++ b/Luski/GUI/MainScreenWindow.cs @@ -9,6 +9,7 @@ using Luski.GUI.MainScreen.UI; using Luski.GUI.MainScreen.UI.LuskiControls; using Luski.GUI.MainScreen.UI.LuskiSettings; using Luski.GUI.MainScreen.UI.PublicServers; +using Luski.GUI.MainScreen.UI.PublicServers.ServerSettings; using Luski.net; using Luski.net.Structures.Public; using Luski.Shared.PublicServers.V1.Enums; @@ -43,7 +44,7 @@ public class MainScreenWindow : Window public TabControl? tc; private FlowLayout? channelpicker, friends, friend_request; private RoundedButton? FriendManagerBtn; - private static DebugProc DebugMessageDelegate = OnDebugMessage; + public static DebugProc DebugMessageDelegate = OnDebugMessage; private static GLFWCallbacks.ErrorCallback GLFW_Error = OnGLFW_Error; private static void OnGLFW_Error(ErrorCode e, string d) @@ -106,12 +107,16 @@ public class MainScreenWindow : Window break; } } - public MainScreenWindow() : base(Settings) { Globals.ms = this; - Size = new(1332.ScaleInt(), 866.ScaleInt()); + SetWindowSize(new(1332.ScaleInt(), 866.ScaleInt())); + Shader s = new Shader("Luski.Resources.Shaders.LeftToRightLabel", Embeded: true, Assembly: Assembly.GetExecutingAssembly()); + s.Use(); + s.SetInt("u_texture", s.GetUniformLocation("u_texture")); + Globals.GradientShader.Add(Context, s); + ClientSize = CS; ShowMissingChar = true; LogFrames = ((Globals.Settings.Logs & ConsoleLog.DrawFrames) == ConsoleLog.DrawFrames); VSync = VSyncMode.On; @@ -205,7 +210,7 @@ public class MainScreenWindow : Window { ServerLoginOverlay SLO = new(Server.Domain); Controls.Add(SLO); - ForceUpdate(new(ClientSize)); + ForceUpdate(); Globals.PrintParent(this); return; } @@ -219,7 +224,7 @@ public class MainScreenWindow : Window SerBox = new() { Location = new(ser.Size.X, 0, 0), - Size = new(Size.X - ser.Size.X, ClientSize.Y), + Size = new(Size.X - ser.Size.X, CS.Y), Anchor = ObjectAnchor.All, BackgroundColor = new(20, 20, 20, 255) }; @@ -245,12 +250,12 @@ public class MainScreenWindow : Window }; if (await Server.User.HasPermissions(ServerPermission.ManageRoles)) { - ServerTitle.Clicked += o => + ServerTitle.Clicked += _ => { - ServerSettings sm = new(Server); + PublicServerSettingsMenu sm = new(Server); Controls.Add(sm); Globals.ms.DrawFrame(); - Globals.ms.ForceUpdate(new(Globals.ms.CS)); + Globals.ms.ForceUpdate(); Globals.ms.DrawFrame(); return Task.CompletedTask; }; @@ -308,10 +313,16 @@ public class MainScreenWindow : Window #endregion #region User Icon - Role[] ra = await Server.User.GetRoles(); - Color c = ra[0].Color; - Color4 c4 = new(c.R, c.G, c.B, c.A); ServerProfile DefaultProfile = await Server.GetProfile(Server.User.ServerProfile, CancellationToken.None); + ColorType ct = await Server.User.GetColorType(); + Color[] c = await Server.User.GetColors(); + ColorType? cct = await DefaultProfile.GetColorType(); + Color[]? cc = await DefaultProfile.GetColors(); + if (cc is not null) + { + c = cc; + ct = cct!.Value; + } IRenderObject u = await DefaultProfile.MakeRct(Server.User, new(46.ScaleInt())); int ii = 4.ScaleInt(); u.Location = new(ii, cs.Location.Y + cs.Size.Y + ii, 0); @@ -319,12 +330,25 @@ public class MainScreenWindow : Window SerBox.Controls.Add(u); u.LoadToParent(SerBox, this); u.ForceDistanceUpdate(); - Label ul = new Label(Globals.DefaultFont) + LabelBase ul; + if (ct == ColorType.Full) { - Anchor = u.Anchor, - Text = DefaultProfile.DisplayName, - Color = c4 - }; + ul = new Label(Globals.DefaultFont) + { + Anchor = u.Anchor, + Text = DefaultProfile.DisplayName, + Color = c[0].ToColor4() + }; + } + else + { + ul = new AdvancedGradientLabel(Globals.DefaultFont) + { + Anchor = u.Anchor, + Text = DefaultProfile.DisplayName, + Colors = c.ToColor4Array() + }; + } ul.Location = new(u.Location.X + u.Size.X + 5.ScaleInt(), (u.Location.Y + ((u.Size.Y - ul.Size.Y) / 2)), 0); @@ -333,7 +357,7 @@ public class MainScreenWindow : Window Size = new(20.ScaleInt()), Shader = Rectangle.DefaultAlphaShader[Context], BackgroundColor = Color4.Gray, - Tag = new Tuple(Server.User, u, ul), + Tag = new Tuple(Server.User, u, ul), Anchor = u.Anchor }; Expand.Clicked += ExpandOnClicked; @@ -360,12 +384,12 @@ public class MainScreenWindow : Window BackgroundColor = Color4.Gray, Anchor = ObjectAnchor.Bottom | ObjectAnchor.Left }; - setting.MouseEnter += o => + setting.MouseEnter += _ => { setting.BackgroundColor = Color4.White; return Task.CompletedTask; }; - setting.MouseLeave += o => + setting.MouseLeave += _ => { setting.BackgroundColor = Color4.Gray; return Task.CompletedTask; @@ -373,7 +397,7 @@ public class MainScreenWindow : Window setting.Clicked += SettingOnClicked; setting.ForceDistanceUpdate(SerBox); SerBox.Controls.Add(setting); - ForceUpdate(new (Size)); + ForceUpdate(); TryDraw(); #endregion } @@ -385,56 +409,63 @@ public class MainScreenWindow : Window BlockDraw = false; } - private FlowLayout? ProfileFlow = null; + private FlowLayout? ProfileFlow; private async Task ExpandOnClicked(IRenderObject arg) { - if (ProfileFlow is null) + try { - ProfileFlow = new(); - Tuple s = (Tuple)arg.Tag!; - var role = (await s.Item1.GetRoles())[0]; - foreach (var prof in await s.Item1.GetProfiles(CancellationToken.None)) + if (ProfileFlow is null) { - ProfileView con = await ProfileView.Make(s.Item1, prof, role); - con.Clicked += async o => + ProfileFlow = new(); + Tuple s = (Tuple)arg.Tag!; + var role = (await s.Item1.GetRoles())[0]; + foreach (ServerProfile prof in await s.Item1.GetProfiles(CancellationToken.None)) { - IRenderObject iro = await prof.MakeRct(s.Item1, s.Item2.Size); - iro.Location = s.Item2.Location; - iro.Distance = s.Item2.Distance; - iro.Anchor = s.Item2.Anchor; - int oldx = s.Item3.Size.X; - s.Item2.Parent!.Controls.Add(iro); - s.Item2.Parent!.Controls.Remove(s.Item2); - s.Item3.Text = prof.DisplayName; - Controls.Remove(ProfileFlow); - ProfileFlow = null; - arg.Location = new(arg.Location.X - oldx + s.Item3.Size.X, arg.Location.Y, arg.Location.Z); - arg.ForceDistanceUpdate(arg.Parent!); - Globals.ServerProfile = prof; - arg.Tag = new Tuple(s.Item1, iro, s.Item3); - TryDraw(); - }; - ProfileFlow.Controls.Add(con); - ProfileFlow.Size = new((int)arg.SizeAsFloat.X, ProfileFlow.Size.Y + con.Size.Y); - } + ProfileView con = await ProfileView.Make(s.Item1, prof, role); + con.Clicked += async _ => + { + IRenderObject iro = await prof.MakeRct(s.Item1, s.Item2.Size); + iro.Location = s.Item2.Location; + iro.Distance = s.Item2.Distance; + iro.Anchor = s.Item2.Anchor; + int oldx = s.Item3.Size.X; + s.Item2.Parent!.Controls.Add(iro); + s.Item2.Parent!.Controls.Remove(s.Item2); + s.Item3.Text = prof.DisplayName; + Controls.Remove(ProfileFlow); + ProfileFlow = null; + arg.Location = new(arg.Location.X - oldx + s.Item3.Size.X, arg.Location.Y, arg.Location.Z); + arg.ForceDistanceUpdate(arg.Parent!); + Globals.ServerProfile = prof; + arg.Tag = new Tuple(s.Item1, iro, s.Item3); + TryDraw(); + }; + ProfileFlow.Controls.Add(con); + ProfileFlow.Size = new((int)arg.SizeAsFloat.X, ProfileFlow.Size.Y + con.Size.Y); + } - ProfileFlow.Location = new(ser.Size.X + 5.ScaleInt(), - CS.Y - 54.ScaleInt() - ProfileFlow.Size.Y, - 0); - Controls.Add(ProfileFlow); + ProfileFlow.Location = new(ser.Size.X + 5.ScaleInt(), + CS.Y - 54.ScaleInt() - ProfileFlow.Size.Y, + 0); + Controls.Add(ProfileFlow); + } + else + { + Controls.Remove(ProfileFlow); + ProfileFlow = null; + } + DrawFrame(); } - else + catch (Exception e) { - Controls.Remove(ProfileFlow); - ProfileFlow = null; + Console.WriteLine(e); } - DrawFrame(); } private Task SettingOnClicked(IRenderObject arg) { - SettingsMenu sm = new(); + GlobalSettingsMenu sm = new(); Controls.Add(sm); Globals.ms.DrawFrame(); return Task.CompletedTask; @@ -457,7 +488,7 @@ public class MainScreenWindow : Window private async Task LoginOnChangeToApp() { Controls.Clear(); - ForceUpdate(new(ClientSize)); + ForceUpdate(); BlockDraw = true; Title = "Luski"; unsafe @@ -479,10 +510,11 @@ public class MainScreenWindow : Window Controls.Add(ser = new FlowLayout() { BackgroundColor = new(26, 26, 26, 255), - Size = new(68.ScaleInt(), ClientSize.Y), + Size = new(68.ScaleInt(), CS.Y), Anchor = ObjectAnchor.Top | ObjectAnchor.Left | ObjectAnchor.Bottom, Location = new(0,0,0) }); + ser.ForceDistanceUpdate(this); ser.LoadToParent(this,this); DrawFrame(); DateTime utcNow = DateTime.UtcNow; @@ -515,11 +547,6 @@ public class MainScreenWindow : Window return Task.CompletedTask; } - protected override void OnResize(ResizeEventArgs e) - { - base.OnResize(e); - - } private Task AddButtonClicked(IRenderObject arg) { diff --git a/Luski/Globals.cs b/Luski/Globals.cs index 56e40db..c566f63 100644 --- a/Luski/Globals.cs +++ b/Luski/Globals.cs @@ -2,6 +2,7 @@ using System.CodeDom.Compiler; using System.ComponentModel; using System.Reflection; using System.Runtime.InteropServices; +using System.Text; using System.Text.Json; using System.Text.Json.Serialization.Metadata; using GraphicsManager; @@ -200,11 +201,19 @@ public static class Globals public static Texture GetTextureResource(this TextureManager tm, string File) { - if (!TextureResources.ContainsKey(tm)) TextureResources.Add(tm, new()); - if (TextureResources[tm].TryGetValue(File, out Texture? t)) return t; - t = tm.AddTexture(GetResource($"Textures.{File}")); - TextureResources[tm].Add(File,t); - return t; + try + { + if (!TextureResources.ContainsKey(tm)) TextureResources.Add(tm, new()); + if (TextureResources[tm].TryGetValue(File, out Texture? t)) return t; + t = tm.AddTexture(GetResource($"Textures.{File}")); + TextureResources[tm].Add(File,t); + return t; + } + catch (Exception e) + { + Console.WriteLine(e); + throw; + } } public static Stream GetResource(string File) @@ -289,7 +298,7 @@ public static class Globals }; l.Tag = TempLine; TempLine.Size = new(parent.Size.X - space - space, 2.ScaleInt()); - tc.Size = new(parent.Size.X, TempLine.Location.Y + TempLine.Size.Y); + tc.SetSize(parent.Size.X, TempLine.Location.Y + TempLine.Size.Y); TempLine.ForceDistanceUpdate(tc); tc.Controls.Add(TempLine); //ts.ForceDistanceUpdate(tc); @@ -359,6 +368,35 @@ public static class Globals return new(col.R, col.G, col.B, col.A); } + public static Color4[] ToColor4Array(this Color[] col) + { + List cols = new(); + foreach (Color c in col) + { + cols.Add(new(c.R, c.G, c.B, c.A)); + } + return cols.ToArray(); + } + + public static string ToDB(this Color[] col) + { + StringBuilder sb = new(); + foreach (Color c in col) + { + sb.Append(Convert.ToHexString(new byte[] { c.R, c.G, c.B, c.A })); + } + return sb.ToString(); + } + public static string ToDB(this Color4[] col) + { + StringBuilder sb = new(); + foreach (Color4 c in col) + { + sb.Append(Convert.ToHexString(new byte[] { (byte)(c.R * byte.MaxValue), (byte)(c.G * byte.MaxValue), (byte)(c.B * byte.MaxValue), (byte)(c.A * byte.MaxValue) })); + } + return sb.ToString(); + } + public static Color4 ToColor4(this Color? col) { return new(col!.Value.R, col.Value.G, col.Value.B, col.Value.A); @@ -376,6 +414,7 @@ public static class Globals public static Dictionary UserTextureMap = new(); public static Dictionary ProfileTextureMap = new(); + public static readonly Dictionary GradientShader = new Dictionary(); public static ServerProfile? ServerProfile = null; @@ -387,20 +426,44 @@ public static class Globals UserControl r = new(t); r.Size = Size; r.Shader = Rectangle.DefaultAlphaShader[ms.Context]; - Color c = await User.GetColor(); - Color? cc = await Profile.GetColor(); - if (cc is not null) c = cc.Value; - r.BackgroundColor = new(25, 25, 25, 255); - Label l = new(DefaultFont) + ColorType ct = await User.GetColorType(); + Color[] c = await User.GetColors(); + ColorType? cct = await Profile.GetColorType(); + Color[]? cc = await Profile.GetColors(); + if (cc is not null) { - Color = c.ToColor4() - }; - l.Text = Profile.DisplayName[0].ToString(); - var y = l.GetSizeOfChar(0); - l.Location = new((r.Size.X - l.Size.X)/2, - (int)(r.Size.Y - (l.Font.PixelHeight - y.Y) - (r.Size.Y / 2) - (y.Y/2)), - 0); - r.Controls.Add(l); + c = cc; + ct = cct!.Value; + } + r.BackgroundColor = new(25, 25, 25, 255); + if (ct == ColorType.Full) + { + Label l = new(DefaultFont) + { + Color = c[0].ToColor4() + }; + l.Text = Profile.DisplayName[0].ToString(); + Vector2i y = l.GetSizeOfChar(0), + yy = l.GetBearingOfChar(0); + l.Location = new((r.Size.X - l.Size.X)/2, + (int)(r.Size.Y - l.Font.PixelHeight + yy.Y - (r.Size.Y / 2) - (y.Y/2)), + 0); + r.Controls.Add(l); + } + else + { + AdvancedGradientLabel l = new(DefaultFont) + { + Colors = c.ToColor4Array() + }; + l.Text = Profile.DisplayName[0].ToString(); + Vector2i y = l.GetSizeOfChar(0), + yy = l.GetBearingOfChar(0); + l.Location = new((r.Size.X - l.Size.X)/2, + (int)(r.Size.Y - l.Font.PixelHeight + yy.Y - (r.Size.Y / 2) - (y.Y/2)), + 0); + r.Controls.Add(l); + } return r; } else @@ -428,9 +491,10 @@ public static class Globals IgnoreHover = true, Text = Server.Name[0].ToString() }; - var y = l.GetSizeOfChar(0); + Vector2i y = l.GetSizeOfChar(0), + yy = l.GetBearingOfChar(0); l.Location = new((r.Size.X - l.Size.X)/2, - (int)(r.Size.Y - (l.Font.PixelHeight - y.Y) - (r.Size.Y / 2) - (y.Y/2)), + (int)(r.Size.Y - l.Font.PixelHeight + yy.Y - (r.Size.Y / 2) - (y.Y/2)), 0); r.Controls.Add(l); return r; diff --git a/Luski/Luski.csproj b/Luski/Luski.csproj index ff19547..e6fcd03 100644 --- a/Luski/Luski.csproj +++ b/Luski/Luski.csproj @@ -22,8 +22,8 @@ - - + + @@ -31,6 +31,8 @@ + + diff --git a/Luski/Program.cs b/Luski/Program.cs index 196f614..d9ad1ef 100644 --- a/Luski/Program.cs +++ b/Luski/Program.cs @@ -2,6 +2,7 @@ using Luski; using Luski.Classes; using Luski.GUI; +using OpenTK.Mathematics; using OpenTK.Windowing.Common.Input; using SixLabors.ImageSharp; using SixLabors.ImageSharp.PixelFormats; @@ -9,6 +10,23 @@ using Image = OpenTK.Windowing.Common.Input.Image; try { + unsafe + { + int * a1; + + int * a2; + + int b1; + + b1 = 20; + + a1 = &b1; + + a2 = a1; + + *a1 = 25; + Console.WriteLine(*a2); + } Globals.Settings = Globals.GetSettings(Path.Combine(Globals.LuskiPath, "Settings.json"), SettingsContext.Default.Settings); foreach (ExperimentInfo le in LuskiExperiments.LuskiExperimentsList) { @@ -72,6 +90,16 @@ try Globals.Icon = new WindowIcon(new Image(Logo.Width, Logo.Height, pixels)); Logo.Dispose(); + Console.WriteLine(new Color4[]{ + Color4.Red, + Color4.Orange, + Color4.Yellow, + Color4.Green, + Color4.Blue, + Color4.Indigo, + Color4.Violet, + }.ToDB()); + MainScreenWindow.Settings.Icon = Globals.Icon; Globals.ms = new MainScreenWindow(); Globals.ms.CustomF11 = false; diff --git a/Luski/Resources/Shaders/LeftToRightLabel.frag b/Luski/Resources/Shaders/LeftToRightLabel.frag new file mode 100644 index 0000000..2d221c2 --- /dev/null +++ b/Luski/Resources/Shaders/LeftToRightLabel.frag @@ -0,0 +1,19 @@ +#version 330 + +in vec2 vUV; + +uniform sampler2D u_texture; + +uniform vec4 textColor; +uniform vec4 rightColor; + +out vec4 fragColor; + +void main() +{ + vec2 uv = vUV.xy; + float text = texture(u_texture, uv).r; + vec4 gradientColor = mix(textColor, rightColor, uv.x); + fragColor = vec4(gradientColor.rgb, gradientColor.a*text); + +} \ No newline at end of file diff --git a/Luski/Resources/Shaders/LeftToRightLabel.vert b/Luski/Resources/Shaders/LeftToRightLabel.vert new file mode 100644 index 0000000..c292778 --- /dev/null +++ b/Luski/Resources/Shaders/LeftToRightLabel.vert @@ -0,0 +1,15 @@ +#version 330 + +layout (location = 0) in vec2 in_pos; +layout (location = 1) in vec2 in_uv; + +out vec2 vUV; + +uniform mat4 model; +uniform mat4 projection; + +void main() +{ + vUV = in_uv.xy; + gl_Position = projection * model * vec4(in_pos.xy, 0.0, 1.0); +} \ No newline at end of file -- 2.44.0 From 2dee38084e3ce52dcb0e663b4e4b700308591e80 Mon Sep 17 00:00:00 2001 From: JacobTech Date: Tue, 27 Aug 2024 10:55:36 -0400 Subject: [PATCH 3/3] Categories And Scissor The scissor code should now properly cut all controls from going past the parent. --- Luski/ConsoleLog.cs | 7 +++++ .../UI/LuskiControls/AdvancedGradientLabel.cs | 2 +- .../MainScreen/UI/LuskiControls/LuskiLabel.cs | 2 +- .../Pages/Server/Roles/ServerRoleOptions.cs | 26 ++++++++++++++++--- Luski/Globals.cs | 3 ++- Luski/Luski.csproj | 4 +-- 6 files changed, 36 insertions(+), 8 deletions(-) diff --git a/Luski/ConsoleLog.cs b/Luski/ConsoleLog.cs index 7fe4f2d..917502f 100644 --- a/Luski/ConsoleLog.cs +++ b/Luski/ConsoleLog.cs @@ -9,23 +9,30 @@ public enum ConsoleLog : long None = 0, [Shared.GlobalAttributes.DisplayName("OpenGL Errors")] [Description("Show OpenGL Major Errors")] + [Category("Rendering")] BigErrosForOpenGL = 1, [Shared.GlobalAttributes.DisplayName("OpenGL Medium Errors")] [Description("Show OpenGL Medium Errors")] + [Category("Rendering")] MediumErrosForOpenGL = 2, [Shared.GlobalAttributes.DisplayName("OpenGL Small Errors")] [Description("Show OpenGL Small Errors")] + [Category("Rendering")] LowErrosForOpenGL = 4, [Shared.GlobalAttributes.DisplayName("OpenGL Info")] [Description("Show OpenGL Info")] + [Category("Rendering")] InfoForOpenGL = 8, [Shared.GlobalAttributes.DisplayName("Log Frames")] [Description("Shows draw fram message in the console")] + [Category("Rendering")] DrawFrames = 16, [Shared.GlobalAttributes.DisplayName("Show Missing Charters")] [Description("Show Missing Charters")] + [Category("Rendering")] ShowMissingChar = 32, [Shared.GlobalAttributes.DisplayName("GLFW Errors")] [Description("Show GLFW Errors")] + [Category("Rendering")] ShowErrorsForGLFW = 64 } \ No newline at end of file diff --git a/Luski/GUI/MainScreen/UI/LuskiControls/AdvancedGradientLabel.cs b/Luski/GUI/MainScreen/UI/LuskiControls/AdvancedGradientLabel.cs index de3fd99..348011e 100644 --- a/Luski/GUI/MainScreen/UI/LuskiControls/AdvancedGradientLabel.cs +++ b/Luski/GUI/MainScreen/UI/LuskiControls/AdvancedGradientLabel.cs @@ -48,7 +48,7 @@ public class AdvancedGradientLabel : LabelBase base.LoadToParent(window, win); } - public override void Draw(int x, int y, int ww, int hh) + public override void Draw(int x, int y, int sx, int sy, int sw, int sh) { if (Visible && Loaded && this.Font is not null && Colors.Length > 1) { diff --git a/Luski/GUI/MainScreen/UI/LuskiControls/LuskiLabel.cs b/Luski/GUI/MainScreen/UI/LuskiControls/LuskiLabel.cs index c6f6a18..20699a9 100644 --- a/Luski/GUI/MainScreen/UI/LuskiControls/LuskiLabel.cs +++ b/Luski/GUI/MainScreen/UI/LuskiControls/LuskiLabel.cs @@ -550,7 +550,7 @@ public class LuskiLabel : LabelBase private List Links = new(); - public override void Draw(int x, int y, int ww, int hh) + public override void Draw(int x, int y, int sx, int sy, int sw, int sh) { if (Visible && Loaded) { diff --git a/Luski/GUI/MainScreen/UI/PublicServers/ServerSettings/Pages/Server/Roles/ServerRoleOptions.cs b/Luski/GUI/MainScreen/UI/PublicServers/ServerSettings/Pages/Server/Roles/ServerRoleOptions.cs index 6bfd847..643b36f 100644 --- a/Luski/GUI/MainScreen/UI/PublicServers/ServerSettings/Pages/Server/Roles/ServerRoleOptions.cs +++ b/Luski/GUI/MainScreen/UI/PublicServers/ServerSettings/Pages/Server/Roles/ServerRoleOptions.cs @@ -143,6 +143,7 @@ public class ServerRoleOptions : UserControl NeedMax.Clear(); Type PropType = typeof(ServerPermission); IEnumerable values = Enum.GetValues(PropType).Cast(); + Dictionary Cats = new(); foreach (var val in values) { try @@ -150,10 +151,27 @@ public class ServerRoleOptions : UserControl MemberInfo? enumValueMemberInfo = Globals.GetMemberInfo(PropType, val); string description = Globals.GetAttribute(enumValueMemberInfo!, val).Description; string Name = Globals.GetAttribute(enumValueMemberInfo!, val).DisplayName; + string cat = Globals.GetAttribute(enumValueMemberInfo!, val).Category; + if (cat.ToLower() == "internal") continue; + + if (!Cats.ContainsKey(cat)) + { + UserControl c = new UserControl() + { + BackgroundColor = Page.BackgroundColor, + Size = new(Page.Size.X, 50.ScaleInt()) + }; + Label tmp = new(Globals.DefaultFont) + { + Text = cat + " Permissions" + }; + tmp.SetLocation(2.ScaleInt(), (int)((c.Size.Y - tmp.Font.PixelHeight)/2)); + c.Controls.Add(tmp); + Page.Controls.Add(c); + Cats.Add(cat, c); + } - - if (Name.ToLower() == "view this") continue; - Globals.AddBool(Page, Name, description + " in the server.", r.ServerPermissions.HasFlag(val), _ => + UserControl tc = Globals.AddBool(Cats[cat], Name, description + " in the server.", r.ServerPermissions.HasFlag(val), _ => { TempPermissions ^= val; if (TempPermissions != r.ServerPermissions) @@ -165,6 +183,8 @@ public class ServerRoleOptions : UserControl Warning.Visible = false; } }, NeedMax); + tc.SetLocation(tc.Location.X, Cats[cat].Size.Y); + Cats[cat].SetSize(Cats[cat].Size.X, Cats[cat].Size.Y + tc.Size.Y); } catch diff --git a/Luski/Globals.cs b/Luski/Globals.cs index c566f63..aa83890 100644 --- a/Luski/Globals.cs +++ b/Luski/Globals.cs @@ -260,7 +260,7 @@ public static class Globals public static API Luski { get; } = new(); public static MainScreenWindow ms; - public static void AddBool(IParent parent, string Name, string description, bool s, Action a, List