From dff9100cf0f2d0e2ac52f21479aaac8a3331f14f Mon Sep 17 00:00:00 2001 From: JacobTech Date: Fri, 11 Oct 2024 16:36:16 -0400 Subject: [PATCH] Rendering Improvements New subframes. Working on better-centered content. --- .../MainScreen/Interfaces/IChannelAdder.cs | 2 +- .../GUI/MainScreen/UI/AddServerOverlayForm.cs | 285 ++++++++++++++++++ ...ServerOverlay.cs => AddServerOverlayld.cs} | 6 +- .../UI/{PublicServers => Generic}/Category.cs | 3 +- .../UI/{PublicServers => Generic}/Channel.cs | 17 +- .../ChannelSelector.cs | 27 +- .../UI/LuskiControls/CenterFullScreenBase.cs | 27 ++ .../ServerForms/CreateAccountUI.cs | 9 + .../UI/LuskiControls/ServerForms/LoginUI.cs | 13 + .../SettingsMenuBase/SettingsMenu.cs | 9 + .../MainScreen/UI/LuskiControls/TextBox.cs | 8 +- Luski/GUI/MainScreenWindow.cs | 278 ++++++++++++----- Luski/Globals.cs | 2 +- Luski/Luski.csproj | 4 +- Luski/Program.cs | 3 +- 15 files changed, 585 insertions(+), 108 deletions(-) create mode 100644 Luski/GUI/MainScreen/UI/AddServerOverlayForm.cs rename Luski/GUI/MainScreen/UI/{AddServerOverlay.cs => AddServerOverlayld.cs} (99%) rename Luski/GUI/MainScreen/UI/{PublicServers => Generic}/Category.cs (98%) rename Luski/GUI/MainScreen/UI/{PublicServers => Generic}/Channel.cs (85%) rename Luski/GUI/MainScreen/UI/{PublicServers => Generic}/ChannelSelector.cs (86%) create mode 100644 Luski/GUI/MainScreen/UI/LuskiControls/CenterFullScreenBase.cs create mode 100644 Luski/GUI/MainScreen/UI/LuskiControls/ServerForms/CreateAccountUI.cs create mode 100644 Luski/GUI/MainScreen/UI/LuskiControls/ServerForms/LoginUI.cs diff --git a/Luski/GUI/MainScreen/Interfaces/IChannelAdder.cs b/Luski/GUI/MainScreen/Interfaces/IChannelAdder.cs index 68a3ea4..828d534 100644 --- a/Luski/GUI/MainScreen/Interfaces/IChannelAdder.cs +++ b/Luski/GUI/MainScreen/Interfaces/IChannelAdder.cs @@ -1,4 +1,4 @@ -using Luski.GUI.MainScreen.UI.PublicServers; +using Luski.GUI.MainScreen.UI.Generic; using Luski.net.Structures.Public; namespace Luski.GUI.MainScreen.Interfaces; diff --git a/Luski/GUI/MainScreen/UI/AddServerOverlayForm.cs b/Luski/GUI/MainScreen/UI/AddServerOverlayForm.cs new file mode 100644 index 0000000..b266b3f --- /dev/null +++ b/Luski/GUI/MainScreen/UI/AddServerOverlayForm.cs @@ -0,0 +1,285 @@ +using GraphicsManager.Enums; +using GraphicsManager.Interfaces; +using GraphicsManager.Objects; +using GraphicsManager.Objects.Core; +using Luski.GUI.MainScreen.UI.LuskiControls; +using Luski.GUI.MainScreen.UI.LuskiControls.ServerForms; +using OpenTK.Mathematics; +using OpenTK.Windowing.GraphicsLibraryFramework; + +namespace Luski.GUI.MainScreen.UI; + +public class AddServerOverlayForm : UserControl +{ + private TextBox tb; + private CreateAccountUI caUI = new(); + private DropDown version; + private LoginUI lUI = new() + { + Visible = false + }; + + private UserControl btn; + + private TextBox UsernameTB + { + get + { + if (lUI.Visible) return lUI.Username; + return caUI.Username; + } + } + + private TextBox PasswordTB + { + get + { + if (lUI.Visible) return lUI.Password; + return caUI.Password; + } + } + + public AddServerOverlayForm() + :base(Globals.ms.TextureManager.GetTextureResource("RoundedRectangle.png")) + { + base.Size = new(350.ScaleInt(), 347.ScaleInt()); + base.BackgroundColor = new(32, 32, 32, 255); + Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context]; + TextureDisplay = TextureDisplay.Center; + Label t; + Controls.Add(t=new Label(Globals.DefaultFont) { Scale = 1.6f, Text = "Add Server", Color = Globals.DodgerBlue }); + t.Location = new((base.Size.X / 2) - (t.Size.X / 2), t.Location.Y, 0); + + Label? ll = new Label(Globals.DefaultFont) + { + Text = net.API.DefaultVersion, + Color = Color4.DarkGray, + IgnoreHover = true + }; + Vector2i s =new((int)(ll.Size.X * 1.6f),27.ScaleInt()); + ll = null; + + Rectangle line = new Rectangle() + { + Size = new Vector2i(1.ScaleInt()), + BackgroundColor = Globals.DodgerBlue + }; + + int ten = 10.ScaleInt(); + + tb = new("BadTextbox.png") + { + Location = new(ten,50.ScaleInt(), 0), + Size = (base.Size.X - ten - ten - ten - s.X, s.Y), + WatermarkText = "Server Address", + TextLocation = TextLocation.LineCenter, + AllowMultiLine = false + }; + tb.LetterPress += () => + { + Texture good = Globals.ms.TextureManager.GetTextureResource("Textbox.png"); + + if (tb.Textures[0].handel != good.handel) + { + tb.Textures[0] = good; + if (UsernameTB.Textures[0].handel == good.handel && + PasswordTB.Textures[0].handel == good.handel && + (lUI.Visible || caUI.Avatar.Textures.Count > 1) && + btn!.Textures[0].handel != good.handel && + tb.Textures[0].handel == good.handel) + { + btn.Textures[0] = good; + } + Globals.ms.TryDraw(); + } + return Task.CompletedTask; + }; + tb.LetterRemoved += () => + { + Texture bad = Globals.ms.TextureManager.GetTextureResource("BadTextbox.png"); + + if (tb.Text.Length == 0 && tb.Textures[0].handel != bad.handel) + { + tb.Textures[0] = bad; + btn!.Textures[0] = bad; + Globals.ms.TryDraw(); + } + + return Task.CompletedTask; + }; + tb.KeyPress += args => + { + if (args.Key == Keys.Tab && !args.Shift) + { + UsernameTB.Focus(); + } + + return Task.CompletedTask; + }; + + Controls.Add(tb); + + version = new DropDown(Textures[0], line) + { + DropDownParentOverride = this, + Size = s, + BackgroundColor = new(255,20,20,255), + TextureDisplay = TextureDisplay.HorizontalCenter, + Shader = Shader, + Location = new(tb.Location.X + tb.Size.X + tb.Location.X, tb.Location.Y, 0) + }; + + foreach (string v in Globals.Luski.SupportedVersions) + { + VersionDropButton option = new VersionDropButton(s, v) + { + LoadDisplay = () => + { + try + { + Label ll2 = new Label(Globals.DefaultFont) + { + Text = v, + Color = Color4.DarkGray, + IgnoreHover = true, + + }; + ll2.Location = new((version.Size.X / 2) - (ll2.Size.X / 2), + ((version.Size.Y - ll2.Size.Y) / 2) + , 0); + version.Controls.Add(ll2); + } + catch (Exception e) + { + Console.WriteLine(e); + } + } + }; + version.AddOption(option); + if (v == net.API.DefaultVersion) + { + version.SetSelected(option); + } + } + + version.OpenStatusChanged += VersionOnOpenStatusChanged; + version.OptionSelected += VersionOnOptionSelected; + + + version.DropDownContainer.Textures.Add(Globals.ms.TextureManager.GetTextureResource("RoundedRectangleBottom.png")); + version.DropDownContainer.TextureDisplay = TextureDisplay.Center; + version.DropDownContainer.Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context]; + version.DropDownContainer.BackgroundColor = version.BackgroundColor; + version.OpenStatusChanged += b => + { + BlockDraw = true; + if (b) + { + version.Textures[0] = Globals.ms.TextureManager.GetTextureResource("RoundedRectangleTop.png"); + } + else + { + version.Textures[0] = Globals.ms.TextureManager.GetTextureResource("RoundedRectangle.png"); + } + + BlockDraw = false; + return Task.CompletedTask; + }; + + + btn = new(Globals.ms.TextureManager.GetTextureResource("BadTextbox.png")) + { + Location = new(tb.Location.X, tb.Location.Y + tb.Size.Y + tb.Location.X, 0), + Size = new(tb.Size.X, tb.Size.Y), + TextureDisplay = TextureDisplay.Center + }; + Label sub = new(Globals.DefaultFont) + { + Text = "Submit", + IgnoreHover = true + }; + sub.Location = new((btn.Size.X / 2) - (sub.Size.X / 2), + ((btn.Size.Y - sub.Size.Y) / 2) + , 0); + sub.ForceDistanceUpdate(btn); + btn.Controls.Add(sub); + Controls.Add(btn); + } + + private Task VersionOnOpenStatusChanged(bool arg) + { + return Task.CompletedTask; + } + + private Task VersionOnOptionSelected(VersionDropButton arg) + { + return Task.CompletedTask; + } + + public override void ParentResize() + { + BlockDraw = true; + for (int i = 0; i < Controls.Length; i++) + { + if (!Controls[i].Loaded) continue; + bool top = (Controls[i].Anchor & ObjectAnchor.Top) == ObjectAnchor.Top; + bool left = (Controls[i].Anchor & ObjectAnchor.Left) == ObjectAnchor.Left; + bool right = (Controls[i].Anchor & ObjectAnchor.Right) == ObjectAnchor.Right; + bool bottom = (Controls[i].Anchor & ObjectAnchor.Bottom) == ObjectAnchor.Bottom; + if (!top && !bottom) { Controls[i].Anchor |= ObjectAnchor.Top; top = true; } + if (!left && !right) { Controls[i].Anchor |= ObjectAnchor.Left; left = true; } + + int lx, ly, sy, sx; + bool UpdateDistance = false; + if ((Controls[i].Anchor & ObjectAnchor.PreventWidthChange) == ObjectAnchor.PreventWidthChange) + { + UpdateDistance = true; + lx = Controls[i].Location.X + ((Size.X - Controls[i].Distance.X - Controls[i].Size.X - Controls[i].Location.X) / 2); + sx = Controls[i].Size.X; + } + else + { + lx = (left ? Controls[i].Location.X : Size.X - Controls[i].Distance.X - Controls[i].Size.X); + sx = (right ? Size.X - Controls[i].Distance.X - lx : Controls[i].Size.X); + } + if ((Controls[i].Anchor & ObjectAnchor.PreventHeightChange) == ObjectAnchor.PreventHeightChange) + { + UpdateDistance = true; + ly = Controls[i].Location.Y + ((Size.Y - Controls[i].Distance.Y - Controls[i].Size.Y - Controls[i].Location.Y) / 2); + sy = Controls[i].Size.Y; + } + else + { + ly = (top ? Controls[i].Location.Y : Size.Y - Controls[i].Distance.Y - Controls[i].Size.Y); + sy = (bottom ? Size.Y - Controls[i].Distance.Y - ly : Controls[i].Size.Y); + } + + bool mooved = false; + Console.WriteLine(Controls[i].Location); + Console.WriteLine(Controls[i].Size); + Console.WriteLine("New X:{0} Y:{1} W:{2} H:{3}", lx, ly, sx, sy); + if (sx != Controls[i].Size.X || sy != Controls[i].Size.Y) + { + mooved = true; + Controls[i].SetSize(sx, sy); + } + if (lx != Controls[i].Location.X || ly != Controls[i].Location.Y) + { + mooved = true; + Controls[i].SetLocation(lx, ly); + } + if (UpdateDistance) + { + Controls[i].ForceDistanceUpdate(this); + } + Console.WriteLine(mooved); + if (Controls[i] is IParent parent) + { + Console.WriteLine(Controls[i]); + parent.ParentResize(); + } + } + if (Parent is not null) Parent.TryDraw(); + BlockDraw = false; + } +} \ No newline at end of file diff --git a/Luski/GUI/MainScreen/UI/AddServerOverlay.cs b/Luski/GUI/MainScreen/UI/AddServerOverlayld.cs similarity index 99% rename from Luski/GUI/MainScreen/UI/AddServerOverlay.cs rename to Luski/GUI/MainScreen/UI/AddServerOverlayld.cs index cc5b0fc..f05e76f 100644 --- a/Luski/GUI/MainScreen/UI/AddServerOverlay.cs +++ b/Luski/GUI/MainScreen/UI/AddServerOverlayld.cs @@ -13,7 +13,7 @@ using Rectangle = GraphicsManager.Objects.Rectangle; namespace Luski.GUI.MainScreen.UI; -public class AddServerOverlay : UserControl, IServerOverlay +public class AddServerOverlayld : UserControl, IServerOverlay { private UserControl Form, btn; private DropDown version; @@ -24,7 +24,7 @@ public class AddServerOverlay : UserControl, IServerOverlay private Rectangle? rec; - public AddServerOverlay() + public AddServerOverlayld() { base.Size = Globals.ms.ClientSize; base.BackgroundColor = new(0, 0, 0, 130); @@ -582,7 +582,7 @@ public class AddServerOverlay : UserControl, IServerOverlay Globals.ServerList.Servers = l.ToArray(); Globals.ServerList.SaveSettings(Path.Combine(Globals.LuskiPath, "Servers.json"), ServerListContext.Default.ServerList); ServerIcon ss = new ServerIcon(ps); - Globals.ms.ser.Controls.Insert(Globals.ms.ser.Controls.Length - 1, ss); + Globals.ms.ServerFlow.Controls.Insert(Globals.ms.ServerFlow.Controls.Length - 1, ss); await ss.LoadServer(); Globals.ms.Controls.Remove(this); Globals.ms.TryDraw(); diff --git a/Luski/GUI/MainScreen/UI/PublicServers/Category.cs b/Luski/GUI/MainScreen/UI/Generic/Category.cs similarity index 98% rename from Luski/GUI/MainScreen/UI/PublicServers/Category.cs rename to Luski/GUI/MainScreen/UI/Generic/Category.cs index 952ff4b..d914571 100644 --- a/Luski/GUI/MainScreen/UI/PublicServers/Category.cs +++ b/Luski/GUI/MainScreen/UI/Generic/Category.cs @@ -5,10 +5,9 @@ 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; +namespace Luski.GUI.MainScreen.UI.Generic; public class Category : UserControl, IChannelAdder { diff --git a/Luski/GUI/MainScreen/UI/PublicServers/Channel.cs b/Luski/GUI/MainScreen/UI/Generic/Channel.cs similarity index 85% rename from Luski/GUI/MainScreen/UI/PublicServers/Channel.cs rename to Luski/GUI/MainScreen/UI/Generic/Channel.cs index c000115..d1ef559 100644 --- a/Luski/GUI/MainScreen/UI/PublicServers/Channel.cs +++ b/Luski/GUI/MainScreen/UI/Generic/Channel.cs @@ -3,14 +3,13 @@ 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; using OpenTK.Graphics.OpenGL4; using OpenTK.Mathematics; using OpenTK.Windowing.Common.Input; -namespace Luski.GUI.MainScreen.UI.PublicServers; +namespace Luski.GUI.MainScreen.UI.Generic; public class Channel : UserControl { @@ -106,19 +105,19 @@ public class Channel : UserControl CS.Selected = this; IReadOnlyList m; m = await CurrentChannel.GetMessages(CancellationToken.None, Globals.Settings.LoadPerChannel); - Globals.ms.pc.ClearChat(); - await Globals.ms.pc.LoadChannel(CurrentChannel); - mm = Globals.ms.pc.AddMessages(m); + Globals.ms.ChatBoxArea.ClearChat(); + await Globals.ms.ChatBoxArea.LoadChannel(CurrentChannel); + mm = Globals.ms.ChatBoxArea.AddMessages(m); } if (mm is not null) { Console.WriteLine("Waiting"); Task.WaitAll(mm); - Globals.ms.pc.MessageFlow.ForceScrollUpdate(); - if (Globals.ms.pc.MessageFlow.Controls.Length > 1 && Globals.ms.pc.MessageFlow.Controls[Globals.ms.pc.MessageFlow.Controls.Length - 1].Location.Y + Globals.ms.pc.MessageFlow.Controls[Globals.ms.pc.MessageFlow.Controls.Length - 1].Size.Y > Globals.ms.pc.MessageFlow.Size.Y) - Globals.ms.pc.MessageFlow.ScrollToBottom(); - else Globals.ms.pc.MessageFlow.ScrollToTop(); + Globals.ms.ChatBoxArea.MessageFlow.ForceScrollUpdate(); + if (Globals.ms.ChatBoxArea.MessageFlow.Controls.Length > 1 && Globals.ms.ChatBoxArea.MessageFlow.Controls[Globals.ms.ChatBoxArea.MessageFlow.Controls.Length - 1].Location.Y + Globals.ms.ChatBoxArea.MessageFlow.Controls[Globals.ms.ChatBoxArea.MessageFlow.Controls.Length - 1].Size.Y > Globals.ms.ChatBoxArea.MessageFlow.Size.Y) + Globals.ms.ChatBoxArea.MessageFlow.ScrollToBottom(); + else Globals.ms.ChatBoxArea.MessageFlow.ScrollToTop(); Console.WriteLine("Done"); } BlockDraw = false; diff --git a/Luski/GUI/MainScreen/UI/PublicServers/ChannelSelector.cs b/Luski/GUI/MainScreen/UI/Generic/ChannelSelector.cs similarity index 86% rename from Luski/GUI/MainScreen/UI/PublicServers/ChannelSelector.cs rename to Luski/GUI/MainScreen/UI/Generic/ChannelSelector.cs index 30a6433..e9e49b0 100644 --- a/Luski/GUI/MainScreen/UI/PublicServers/ChannelSelector.cs +++ b/Luski/GUI/MainScreen/UI/Generic/ChannelSelector.cs @@ -1,32 +1,25 @@ -using System.Runtime.CompilerServices; -using GraphicsManager.Enums; using GraphicsManager.Interfaces; using GraphicsManager.Objects; using Luski.GUI.MainScreen.Interfaces; +using Luski.GUI.MainScreen.UI.PublicServers; using Luski.net.Structures.Public; using Luski.Shared.PublicServers.V1.Enums; -using OpenTK.Mathematics; -namespace Luski.GUI.MainScreen.UI.PublicServers; +namespace Luski.GUI.MainScreen.UI.Generic; public class ChannelSelector : FlowLayout, IChannelAdder { - public SocketCategory CurrentCategory { get; } + public SocketCategory CurrentCategory { get; private set; } private readonly List cc = new(); private readonly List LoadedChannels = new(); public Dictionary ChannelAdders = new(); public Channel? Selected; - private ChannelSelector(SocketCategory Cat) + public async Task LoadSelectorRoot(SocketCategory Cat) { CurrentCategory = Cat; ChannelAdders.Add(Cat.ID, this); Cat.Server.MessageReceived += ServerOnMessageReceived; - } - - public static async Task MakeSelector(SocketCategory Cat) - { - ChannelSelector cs = new(Cat); bool MakeChannels = await Cat.Server.User.HasAccessToCategory(Cat, ServerPermission.CreateChannels); bool MakeRoles = await Cat.Server.User.HasPermissions(ServerPermission.ManageRoles); if (MakeChannels || MakeRoles) @@ -35,17 +28,15 @@ public class ChannelSelector : FlowLayout, IChannelAdder if (MakeChannels) { Label l = lcm.AddLabel("Create Channel"); - l.Clicked += cs.LOnClicked; + l.Clicked += LOnClicked; } if (MakeRoles) { Label l = lcm.AddLabel("Create Role"); - l.Clicked += cs.RLOnClicked; + l.Clicked += RLOnClicked; } - cs.ContextMenu = lcm; + ContextMenu = lcm; } - - return cs; } private async Task RLOnClicked(IRenderObject arg) @@ -63,8 +54,8 @@ public class ChannelSelector : FlowLayout, IChannelAdder private async Task ServerOnMessageReceived(SocketMessage arg) { if (Selected is null || arg.ChannelID != Selected.CurrentChannel.ID) return; - bool u = Globals.ms.pc.MessageFlow.MaxScrollValue == Globals.ms.pc.MessageFlow.ScrollValue; - await Globals.ms.pc.AddMessage(arg, u); + bool u = Globals.ms.ChatBoxArea.MessageFlow.MaxScrollValue == Globals.ms.ChatBoxArea.MessageFlow.ScrollValue; + await Globals.ms.ChatBoxArea.AddMessage(arg, u); } diff --git a/Luski/GUI/MainScreen/UI/LuskiControls/CenterFullScreenBase.cs b/Luski/GUI/MainScreen/UI/LuskiControls/CenterFullScreenBase.cs new file mode 100644 index 0000000..d25bdbd --- /dev/null +++ b/Luski/GUI/MainScreen/UI/LuskiControls/CenterFullScreenBase.cs @@ -0,0 +1,27 @@ +using GraphicsManager.Enums; +using GraphicsManager.Interfaces; +using GraphicsManager.Objects; + +namespace Luski.GUI.MainScreen.UI.LuskiControls; + +public class CenterFullScreenBase : UserControl +{ + private IRenderObject centerobj; + public CenterFullScreenBase(IRenderObject obj, bool Streach = false) + { + centerobj = obj; + if (!Streach) obj.Anchor = ObjectAnchor.Prevent; + else obj.Anchor = ObjectAnchor.All; + Controls.Add(obj); + base.BackgroundColor = new(0, 0, 0, 130); + Anchor = ObjectAnchor.All; + } + + public override void LoadToParent(IParent p, IWindow w) + { + base.SetSize(w.CS.X, w.CS.Y); + centerobj.SetLocation((w.CS.X - centerobj.Size.X)/2, (w.CS.Y - centerobj.Size.Y)/2); + centerobj.ForceDistanceUpdate(this); + base.LoadToParent(p, w); + } +} \ No newline at end of file diff --git a/Luski/GUI/MainScreen/UI/LuskiControls/ServerForms/CreateAccountUI.cs b/Luski/GUI/MainScreen/UI/LuskiControls/ServerForms/CreateAccountUI.cs new file mode 100644 index 0000000..b456b39 --- /dev/null +++ b/Luski/GUI/MainScreen/UI/LuskiControls/ServerForms/CreateAccountUI.cs @@ -0,0 +1,9 @@ +using GraphicsManager.Objects; + +namespace Luski.GUI.MainScreen.UI.LuskiControls.ServerForms; + +public class CreateAccountUI : UserControl +{ + public Rectangle Avatar = new(); + public TextBox Username = new(), Password = new(), DisplayName = new(); +} \ No newline at end of file diff --git a/Luski/GUI/MainScreen/UI/LuskiControls/ServerForms/LoginUI.cs b/Luski/GUI/MainScreen/UI/LuskiControls/ServerForms/LoginUI.cs new file mode 100644 index 0000000..4b43d32 --- /dev/null +++ b/Luski/GUI/MainScreen/UI/LuskiControls/ServerForms/LoginUI.cs @@ -0,0 +1,13 @@ +using GraphicsManager.Objects; + +namespace Luski.GUI.MainScreen.UI.LuskiControls.ServerForms; + +public class LoginUI : UserControl +{ + public TextBox Username = new(), Password = new(); + + public LoginUI() + { + + } +} \ No newline at end of file diff --git a/Luski/GUI/MainScreen/UI/LuskiControls/SettingsMenuBase/SettingsMenu.cs b/Luski/GUI/MainScreen/UI/LuskiControls/SettingsMenuBase/SettingsMenu.cs index 8335eb7..4b20b40 100644 --- a/Luski/GUI/MainScreen/UI/LuskiControls/SettingsMenuBase/SettingsMenu.cs +++ b/Luski/GUI/MainScreen/UI/LuskiControls/SettingsMenuBase/SettingsMenu.cs @@ -41,16 +41,25 @@ public class SettingsMenu : UserControl }; closebtn.MouseLeave += _ => { + if (bl) BlockDraw = true; closebtn.BackgroundColor = Color4.Gray; + if (bl) + { + BlockDraw = false; + bl = false; + } return Task.CompletedTask; }; closebtn.Clicked += ClosebtnOnClicked; closebtn.ForceDistanceUpdate(this); Controls.Add(closebtn); } + + private bool bl; private Task ClosebtnOnClicked(IRenderObject arg) { + bl = true; Globals.ms.Controls.Remove(this, false); Globals.ms.Title = BehindName; Globals.ms.DrawFrame(); diff --git a/Luski/GUI/MainScreen/UI/LuskiControls/TextBox.cs b/Luski/GUI/MainScreen/UI/LuskiControls/TextBox.cs index 144c39c..c464fb8 100644 --- a/Luski/GUI/MainScreen/UI/LuskiControls/TextBox.cs +++ b/Luski/GUI/MainScreen/UI/LuskiControls/TextBox.cs @@ -20,8 +20,8 @@ public class TextBox : UserControl public int CursorLocation { get; set; } - public TextBox() - :base(Globals.ms.TextureManager.GetTextureResource("Textbox.png")) + public TextBox(string defaul = "Textbox.png") + :base(Globals.ms.TextureManager.GetTextureResource(defaul)) { t = new(500); t.Elapsed += TOnElapsed; @@ -44,8 +44,10 @@ public class TextBox : UserControl (int)_label.LineHeight ), Location = _watermark.Location, BackgroundColor = Color4.White, - Visible = false + Visible = false, + IgnoreHover = true }; + IgnoreVisForChildren = true; Controls.Add(Pointer); Controls.Add(_label); diff --git a/Luski/GUI/MainScreenWindow.cs b/Luski/GUI/MainScreenWindow.cs index b389660..59a1a98 100644 --- a/Luski/GUI/MainScreenWindow.cs +++ b/Luski/GUI/MainScreenWindow.cs @@ -6,6 +6,7 @@ using GraphicsManager.Interfaces; using GraphicsManager.Objects; using GraphicsManager.Objects.Core; using Luski.GUI.MainScreen.UI; +using Luski.GUI.MainScreen.UI.Generic; using Luski.GUI.MainScreen.UI.LuskiControls; using Luski.GUI.MainScreen.UI.LuskiSettings; using Luski.GUI.MainScreen.UI.PublicServers; @@ -36,7 +37,7 @@ public class MainScreenWindow : Window APIVersion = new Version(3, 2), API = ContextAPI.OpenGL, StartFocused = true, - Size = new Vector2i(624, 1090), + ClientSize = new Vector2i(624, 1090), Icon = Globals.Icon, SharedContext = null, }; @@ -120,7 +121,6 @@ public class MainScreenWindow : Window ShowMissingChar = true; LogFrames = ((Globals.Settings.Logs & ConsoleLog.DrawFrames) == ConsoleLog.DrawFrames); VSync = VSyncMode.On; - GL.DebugMessageCallback(DebugMessageDelegate, IntPtr.Zero); GL.Enable(EnableCap.DebugOutput); GLFW.SetErrorCallback(GLFW_Error); @@ -150,7 +150,6 @@ public class MainScreenWindow : Window Console.WriteLine(e); } - Globals.DefaultFont.PixelHeight = Globals.Settings.DefaultFontPX.ScaleFont(); Globals.DefaultFont.FontSize = FontSize.Regular; Globals.TopTimeFont = Globals.DefaultFont.Clone(); @@ -175,10 +174,13 @@ public class MainScreenWindow : Window CenterWindow(); } WindowLoaded += OnWindowLoaded; + BlockDraw = true; } private async Task OnWindowLoaded(Window arg) { + BlockDraw = false; + Console.WriteLine("start"); if (Globals.UpdaterSettings.AutoUpdateCheck && new HttpClient() .GetAsync( $"https://www.jacobtech.com/Updater/GetProgramVersion?directory=Luski&branch=main&selfcontained={Globals.UpdaterSettings.SelfContained.ToString().ToLower()}&platform={Globals.UpdaterSettings.Platform}") @@ -196,9 +198,10 @@ public class MainScreenWindow : Window await LoginOnChangeToApp(); } - public FlowLayout ser; - private UserControl? SerBox; - public PublicChat pc; + public FlowLayout ServerFlow; + private UserControl SerBox, ServerTitle; + public PublicChat ChatBoxArea; + public ChannelSelector ChannelSelector; public async Task LoadPublicServer(PublicServer? Server) { @@ -211,38 +214,25 @@ public class MainScreenWindow : Window ServerLoginOverlay SLO = new(Server.Domain); Controls.Add(SLO); ForceUpdate(); - Globals.PrintParent(this); return; } BlockDraw = true; try { - #region Box Init - - if (SerBox is null) - { - SerBox = new() - { - Location = new(ser.Size.X, 0, 0), - Size = new(Size.X - ser.Size.X, CS.Y), - Anchor = ObjectAnchor.All, - BackgroundColor = new(20, 20, 20, 255) - }; - Controls.Add(SerBox); - SerBox.LoadToParent(this, this); - } + #region Control Removing + ServerTitle.Controls.Clear(); + ChannelSelector.Controls.Clear(); + SerBox.Controls.Remove(ServerTitle, false); + SerBox.Controls.Remove(ChannelSelector, false); SerBox.Controls.Clear(); + SerBox.Controls.Add(ServerTitle); + SerBox.Controls.Add(ChannelSelector); #endregion - + #region Server Title - - UserControl ServerTitle = new() - { - Size = new(307.ScaleInt(), 46.ScaleInt()), - BackgroundColor = new(30, 30, 30, 255) - }; + Label title = new(Globals.DefaultFont) { Text = Server.Name, @@ -280,35 +270,29 @@ public class MainScreenWindow : Window } parents.Reverse(); - ChannelSelector cs = await ChannelSelector.MakeSelector(parents[0]); - cs.BackgroundColor = new(34, 34, 34, 255); - cs.Location = new(0, ServerTitle.Size.Y +2.ScaleInt(), 0); - cs.Size = new(ServerTitle.Size.X, SerBox.Size.Y - 54.ScaleInt() - cs.Location.Y); - cs.Anchor = ObjectAnchor.Top | ObjectAnchor.Left | ObjectAnchor.Bottom; + await ChannelSelector.LoadSelectorRoot(parents[0]); parents.RemoveAt(0); - SerBox.Controls.Add(cs); - cs.ForceDistanceUpdate(SerBox); - + #endregion #region Chat Init - pc = new() + ChatBoxArea = new() { Anchor = ObjectAnchor.All, - Location = new(cs.Size.X, 0, 0), - Size = new(SerBox.Size.X - cs.Size.X, SerBox.Size.Y), + Location = new(ChannelSelector.Size.X, 0, 0), + Size = new(SerBox.Size.X - ChannelSelector.Size.X, SerBox.Size.Y), }; - SerBox.Controls.Add(pc); - pc.LoadToParent(SerBox, this); - pc.ForceDistanceUpdate(); - pc.MessageFlow.ForceDistanceUpdate(pc); + SerBox.Controls.Add(ChatBoxArea); + ChatBoxArea.LoadToParent(SerBox, this); + ChatBoxArea.ForceDistanceUpdate(); + ChatBoxArea.MessageFlow.ForceDistanceUpdate(ChatBoxArea); #endregion #region Channel Selector Loader - _ = cs.Load(current_channel, parents); + _ = ChannelSelector.Load(current_channel, parents); #endregion @@ -316,7 +300,7 @@ public class MainScreenWindow : Window ServerProfile DefaultProfile = await Server.GetProfile(Server.User.ServerProfile, CancellationToken.None); 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); + u.Location = new(ii, ChannelSelector.Location.Y + ChannelSelector.Size.Y + ii, 0); u.Anchor = ObjectAnchor.Bottom | ObjectAnchor.Left; SerBox.Controls.Add(u); u.LoadToParent(SerBox, this); @@ -364,11 +348,12 @@ public class MainScreenWindow : Window SerBox.Controls.Add(ul); Rectangle setting = new(TextureManager.GetTextureResource("settings.png")) { - Location = new(cs.Size.X - 40.ScaleInt(), cs.Location.Y + cs.Size.Y + 11.ScaleInt(),0), + Location = new(ChannelSelector.Size.X - 40.ScaleInt(), ChannelSelector.Location.Y + ChannelSelector.Size.Y + 11.ScaleInt(),0), Size = new(32.ScaleInt()), Shader = Rectangle.DefaultAlphaShader[Context], BackgroundColor = Color4.Gray, - Anchor = ObjectAnchor.Bottom | ObjectAnchor.Left + Anchor = ObjectAnchor.Bottom | ObjectAnchor.Left, + BlendOverride = true }; setting.MouseEnter += _ => { @@ -431,7 +416,7 @@ public class MainScreenWindow : Window ProfileFlow.Size = new((int)arg.SizeAsFloat.X, ProfileFlow.Size.Y + con.Size.Y); } - ProfileFlow.Location = new(ser.Size.X + 5.ScaleInt(), + ProfileFlow.Location = new(ServerFlow.Size.X + 5.ScaleInt(), CS.Y - 54.ScaleInt() - ProfileFlow.Size.Y, 0); Controls.Add(ProfileFlow); @@ -449,21 +434,26 @@ public class MainScreenWindow : Window } } + private GlobalSettingsMenu? gsm; + private Task SettingOnClicked(IRenderObject arg) { - GlobalSettingsMenu sm = new(); - Controls.Add(sm); + if (gsm is null) + { + gsm = new GlobalSettingsMenu(); + } + Controls.Add(gsm); Globals.ms.DrawFrame(); return Task.CompletedTask; } - + public async Task LoadMainServer(MainServer Server) { if (SerBox is null) SerBox = new() { - Location = new(ser.Size.X, 0, 0), - Size = new(Size.X - ser.Size.X, Size.Y), + Location = new(ServerFlow.Size.X, 0, 0), + Size = new(Size.X - ServerFlow.Size.X, Size.Y), Anchor = ObjectAnchor.All }; Controls.Add(SerBox); @@ -471,10 +461,54 @@ public class MainScreenWindow : Window SerBox.Controls.Clear(); } + protected override void OnKeyDown(KeyboardKeyEventArgs e) + { + base.OnKeyDown(e); + if (e.Key == Keys.F9) + { + Globals.PrintParent(this); + } + else if (e.Key == Keys.F10) + { + CheckParent(this); + } + else if (e.Key == Keys.F12) + { + Console.WriteLine("Update Time: " + UpdateAdverage); + Console.WriteLine("Draw Time: " + DrawAdverage); + Console.WriteLine("Total Time: " + TotalAdverage); + } + } + + public override void CheckParent(IParent p, IRenderObject c, int xx, Vector3i di) + { + if (p.IgnoreVisForChildren || p.Controls.Length <= 1 || xx >= p.Controls.Length || !c.Visible || c is ILabel) return; + for (int i = xx; i > 0; i--) + { + if (!p.Controls[i].IsVisible || + ((p.Controls[i].Location.X + di.X >= c.Location.X && p.Controls[i].Location.X + p.Controls[i].Size.X + di.X - c.Size.X <= c.Location.X) && + (p.Controls[i].Location.Y + di.Y >= c.Location.Y && p.Controls[i].Location.Y + p.Controls[i].Size.Y + di.X - c.Size.Y <= c.Location.Y))) + { + p.Controls[i].NotifiNotVisible(); + continue; + } + if (p.Controls[i] is IParent pp) CheckParent(pp, c, pp.Controls.Length-1, di + p.Controls[i].Location); + } + } + + public override void CheckParent(IParent p) + { + for (int i = p.Controls.Length - 1; i > 0; i--) + { + CheckParent(p, p.Controls[i], i-1, new()); + if (p.Controls[i] is IParent pp) CheckParent(pp); + } + } + private async Task LoginOnChangeToApp() { Controls.Clear(); - ForceUpdate(); + //ForceUpdate(); BlockDraw = true; Title = "Luski"; unsafe @@ -493,55 +527,162 @@ public class MainScreenWindow : Window WindowBorder = WindowBorder.Resizable; BackgroundColor = new Color4(20, 20, 20, 255); - Controls.Add(ser = new FlowLayout() + Controls.Add(ServerFlow = new FlowLayout() { BackgroundColor = new(26, 26, 26, 255), 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); + ServerFlow.ForceDistanceUpdate(this); + ServerFlow.LoadToParent(this,this); DrawFrame(); - DateTime utcNow = DateTime.UtcNow; + + SerBox = new() + { + Location = new(ServerFlow.Size.X, 0, 0), + Size = new(Size.X - ServerFlow.Size.X, CS.Y), + Anchor = ObjectAnchor.All, + BackgroundColor = new(20, 20, 20, 255) + }; + Controls.Add(SerBox); + SerBox.LoadToParent(this, this); + + ServerTitle = new() + { + Size = new(307.ScaleInt(), 46.ScaleInt()), + BackgroundColor = new(30, 30, 30, 255) + }; + SerBox.Controls.Add(ServerTitle); + + + ChannelSelector = new() + { + BackgroundColor = new(34, 34, 34, 255), + Location = new(0, ServerTitle.Size.Y +2.ScaleInt(), 0), + Anchor = ObjectAnchor.Top | ObjectAnchor.Left | ObjectAnchor.Bottom + }; + ChannelSelector.Size = new(ServerTitle.Size.X, SerBox.Size.Y - 54.ScaleInt() - ChannelSelector.Location.Y); + SerBox.Controls.Add(ChannelSelector); + ChannelSelector.ForceDistanceUpdate(SerBox); + + Console.WriteLine("Waiting"); Task.WhenAll(Globals.ServersLoading.ToArray()).Wait(); + Console.WriteLine("Done waiting"); foreach (PublicServer pser in Globals.Luski.LoadedServers) { ServerIcon si = new ServerIcon(pser); - ser.Controls.Add(si); - si.LoadToParent(ser, this); + ServerFlow.Controls.Add(si); + si.LoadToParent(ServerFlow, this); } foreach (PublicServer pser in Globals.Luski.FailedServers) { Console.WriteLine(pser.Name); ServerIcon si = new ServerIcon(pser, true); - ser.Controls.Add(si); - si.LoadToParent(ser, this); + ServerFlow.Controls.Add(si); + si.LoadToParent(ServerFlow, this); } AddServerIcon asi = new(); asi.Clicked += AddButtonClicked; - ser.Controls.Add(asi); + ServerFlow.Controls.Add(asi); - if (ser.Controls.Length > 1) (ser.Controls[0] as ServerIcon)!.LoadServer().Start(); + if (ServerFlow.Controls.Length > 1) (ServerFlow.Controls[0] as ServerIcon)!.LoadServer().Start(); DrawFrame(); MainShow += OnMainShow; return Task.CompletedTask; } + public override void ForceUpdate() + { + DateTime dt = DateTime.Now; + BlockDraw = true; + for (int i = 0; i < Controls.Length; i++) + { + if (!Controls[i].Loaded) continue; + bool top = (Controls[i].Anchor & ObjectAnchor.Top) == ObjectAnchor.Top; + bool left = (Controls[i].Anchor & ObjectAnchor.Left) == ObjectAnchor.Left; + bool right = (Controls[i].Anchor & ObjectAnchor.Right) == ObjectAnchor.Right; + bool bottom = (Controls[i].Anchor & ObjectAnchor.Bottom) == ObjectAnchor.Bottom; + if (!top && !bottom) { Controls[i].Anchor |= ObjectAnchor.Top; top = true; } + if (!left && !right) { Controls[i].Anchor |= ObjectAnchor.Left; left = true; } + + int lx, ly, sy, sx; + bool UpdateDistance = false; + if ((Controls[i].Anchor & ObjectAnchor.PreventWidthChange) == ObjectAnchor.PreventWidthChange) + { + UpdateDistance = true; + lx = Controls[i].Location.X + ((CS.X - Controls[i].Distance.X - Controls[i].Size.X - Controls[i].Location.X) / 2); + sx = Controls[i].Size.X; + } + else + { + lx = (left ? Controls[i].Location.X : CS.X - Controls[i].Distance.X - Controls[i].Size.X); + sx = (right ? CS.X - Controls[i].Distance.X - lx : Controls[i].Size.X); + } + if ((Controls[i].Anchor & ObjectAnchor.PreventHeightChange) == ObjectAnchor.PreventHeightChange) + { + UpdateDistance = true; + ly = Controls[i].Location.Y + ((CS.Y - Controls[i].Distance.Y - Controls[i].Size.Y - Controls[i].Location.Y) / 2); + sy = Controls[i].Size.Y; + } + else + { + ly = (top ? Controls[i].Location.Y : CS.Y - Controls[i].Distance.Y - Controls[i].Size.Y); + sy = (bottom ? CS.Y - Controls[i].Distance.Y - ly : Controls[i].Size.Y); + } + + Controls[i].SetSize(sx, sy); + Controls[i].SetLocation(lx, ly); + if (UpdateDistance) + { + Controls[i].ForceDistanceUpdate(this); + } + if (Controls[i] is IParent parent) + { + parent.ParentResize(); + } + } + if (UpdateAdverage is null) UpdateAdverage = DateTime.Now - dt; + else + { + UpdateAdverage = new((UpdateAdverage.Value.Ticks + (DateTime.Now - dt).Ticks)/2); + } + DateTime dtt = DateTime.Now; + DrawFrame(); + if (DrawAdverage is null || TotalAdverage is null) + { + DrawAdverage = DateTime.Now - dtt; + TotalAdverage = DateTime.Now - dt; + } + else + { + DrawAdverage = new((DrawAdverage.Value.Ticks + (DateTime.Now - dtt).Ticks)/2); + TotalAdverage = new((TotalAdverage.Value.Ticks + (DateTime.Now - dt).Ticks)/2); + } + BlockDraw = false; + } + + private TimeSpan? UpdateAdverage, DrawAdverage, TotalAdverage; + private Task AddButtonClicked(IRenderObject arg) { - AddServerOverlay aso = new(); + CenterFullScreenBase aso = new(new AddServerOverlayForm()) + { + AllowHoverFromBehind = false + }; + //AddServerOverlayld aso = new(); aso.Clicked += AsoOnClicked; Controls.Add(aso); - TryDraw(); - OnResize(new(CS)); + aso.LoadToParent(this, this); + GL.Scissor(0,0, CS.X, CS.Y); + aso.Draw(0,0,0,0, CS.X, CS.Y); return Task.CompletedTask; } @@ -550,7 +691,8 @@ public class MainScreenWindow : Window { Globals.ms.Controls.Remove(arg); Globals.ms.DrawFrame(); - AddServerOverlay aso = (arg as AddServerOverlay)!; + CenterFullScreenBase aso = (arg as CenterFullScreenBase)!; + //AddServerOverlayld aso = (arg as AddServerOverlayld)!; aso.Clicked -= AsoOnClicked; aso.Clean(); aso = null!; diff --git a/Luski/Globals.cs b/Luski/Globals.cs index 81dfd56..75c7276 100644 --- a/Luski/Globals.cs +++ b/Luski/Globals.cs @@ -110,7 +110,7 @@ public static class Globals for (int i = 0; i < p.Controls.Length; i++) { if (p.Controls[i].IgnoreHover) continue; - Console.WriteLine(sp + p.Controls[i] + ": " + p.Controls[i].Location + " " + (p.Controls[i].Location + l) + " "+ p.Controls[i].Size); + Console.WriteLine(sp + p.Controls[i] + ": " + p.Controls[i].IsVisible + " " + p.Controls[i].Location + " " + (p.Controls[i].Location + l) + " "+ p.Controls[i].Size); if (p.Controls[i] is IParent pp) PrintP(index + 1, pp, l + pp.Position); } } diff --git a/Luski/Luski.csproj b/Luski/Luski.csproj index 8dd1e58..395c081 100644 --- a/Luski/Luski.csproj +++ b/Luski/Luski.csproj @@ -22,8 +22,8 @@ - - + + diff --git a/Luski/Program.cs b/Luski/Program.cs index 9648c54..1627c30 100644 --- a/Luski/Program.cs +++ b/Luski/Program.cs @@ -50,6 +50,7 @@ try switch (server.Main) { case false: + // if (server.Domain == "jt.luskiserver.jacobtech.com") continue; Globals.ServersLoading.Add(Task.Run(async () => { return await Globals.Luski.TryGetPublicServer(out _, server.Domain, server.Version, @@ -76,7 +77,7 @@ try MainScreenWindow.Settings.Icon = Globals.Icon; Globals.ms = new MainScreenWindow(); Globals.ms.CustomF11 = false; - Globals.ms.DrawFrame(); + //Globals.ms.DrawFrame(); pixels = Array.Empty(); Globals.ms.StartRender(); Globals.ms.Dispose();