diff --git a/Luski/Classes/Settings.cs b/Luski/Classes/Settings.cs index 25df69b..2a48129 100644 --- a/Luski/Classes/Settings.cs +++ b/Luski/Classes/Settings.cs @@ -6,7 +6,7 @@ public class Settings { [JsonInclude] [JsonPropertyName("scale")] - public double Scale { get; set; } = 1; + public double? Scale { get; set; } = null; [JsonInclude] [JsonPropertyName("perscrollpixels")] public uint PerScrollPixels { get; set; } = 20; @@ -25,11 +25,25 @@ public class Settings [JsonInclude] [JsonPropertyName("default_display")] public int Display { get; set; } = 0; - [JsonInclude] [JsonPropertyName("log")] public ConsoleLog Logs { get; set; } = ConsoleLog.DrawFrames | ConsoleLog.BigErrosForOpenGL | ConsoleLog.MediumErrosForOpenGL | ConsoleLog.LowErrosForOpenGL; + [JsonInclude] + [JsonPropertyName("scale_fonts")] + public bool ScaleFonts { get; set; } = true; + [JsonInclude] + [JsonPropertyName("default_font_px")] + public uint DefaultFontPX { get; set; } = 20; + [JsonInclude] + [JsonPropertyName("top_time_font_px")] + public uint TopTimeFonttPX { get; set; } = 11; + [JsonInclude] + [JsonPropertyName("message_font_px")] + public uint MessageFontPX { get; set; } = 17; + [JsonInclude] + [JsonPropertyName("message_font_line_space_px")] + public uint MessageFontLineSpacePX { get; set; } = 5; } diff --git a/Luski/GUI/MainScreen/UI/AccountButton.cs b/Luski/GUI/MainScreen/UI/AccountButton.cs index 74ca355..a7a434e 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((int)(297 * Globals.Settings.Scale), (int)(40* Globals.Settings.Scale)); + base.Size = new(297.ScaleInt(), 40.ScaleInt()); TextureDisplay = TextureDisplay.HorizontalCenter; Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context]; l = new Label(Globals.DefaultFont) diff --git a/Luski/GUI/MainScreen/UI/AddServerIcon.cs b/Luski/GUI/MainScreen/UI/AddServerIcon.cs index 2104695..4d93c1a 100644 --- a/Luski/GUI/MainScreen/UI/AddServerIcon.cs +++ b/Luski/GUI/MainScreen/UI/AddServerIcon.cs @@ -10,14 +10,14 @@ public class AddServerIcon : UserControl { Button = new(Globals.ms.TextureManager.GetTextureResource("add.png")) { - Location = new((int)(18 * Globals.Settings.Scale), (int)(8 * Globals.Settings.Scale), 0), - Size = new((int)(32 * Globals.Settings.Scale)), + Location = new(18.ScaleInt(), 8.ScaleInt(), 0), + Size = new(32.ScaleInt()), Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context], BackgroundColor = Color4.White, IgnoreHover = true }; Controls.Add(Button); - BackgroundColor = new(26, 26, 26, 255); - base.Size = new((int)(68 * Globals.Settings.Scale), (int)(48 * Globals.Settings.Scale)); + base.BackgroundColor = new(26, 26, 26, 255); + base.Size = new(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 b2e3b3a..30137de 100644 --- a/Luski/GUI/MainScreen/UI/AddServerOverlay.cs +++ b/Luski/GUI/MainScreen/UI/AddServerOverlay.cs @@ -34,7 +34,7 @@ public class AddServerOverlay : UserControl, IServerOverlay Form = new(Globals.ms.TextureManager.GetTextureResource("RoundedRectangle.png")) { - Size = new((int)(350 * Globals.Settings.Scale), (int)(347 * Globals.Settings.Scale)), + Size = new(350.ScaleInt(), 347.ScaleInt()), BackgroundColor = new(32,32,32,255), Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context], TextureDisplay = TextureDisplay.Center @@ -50,18 +50,18 @@ public class AddServerOverlay : UserControl, IServerOverlay Color = Color4.DarkGray, IgnoreHover = true }; - Vector2i s =new((int)(ll.Size.X * 1.6f),(int)(27 * Globals.Settings.Scale)); + Vector2i s =new((int)(ll.Size.X * 1.6f),27.ScaleInt()); ll = null; Rectangle line = new Rectangle() { - Size = new Vector2i((int)Globals.Settings.Scale), + Size = new Vector2i(1.ScaleInt()), BackgroundColor = Globals.DodgerBlue }; tb = new() { - Location = new((int)(10*Globals.Settings.Scale),(int)(50 * Globals.Settings.Scale), 0), + Location = new(10.ScaleInt(),50.ScaleInt(), 0), Size = s, WatermarkText = "Server Address", TextLocation = TextLocation.PostiveTureCenterLeft, @@ -195,8 +195,8 @@ public class AddServerOverlay : UserControl, IServerOverlay btn.Textures[0] = Globals.ms.TextureManager.GetTextureResource("BadTextbox.png"); page!.Controls.Add(UserName = new() { - Location = new(0, (int)(10* Globals.Settings.Scale), 0), - Size = new(page.Size.X, (int)(30* Globals.Settings.Scale)), + Location = new(0, 10.ScaleInt(), 0), + Size = new(page.Size.X, 30.ScaleInt()), WatermarkText = "Username", TextLocation = TextLocation.PostiveTureCenterLeft, AllowMultiLine = false @@ -283,7 +283,7 @@ public class AddServerOverlay : UserControl, IServerOverlay page.Controls.Add(rec = new(Globals.ms.TextureManager.GetAlphaCircle()) { - Size = new((int)(50 * Globals.Settings.Scale)), + Size = new(50.ScaleInt()), BackgroundColor = Color4.Red, Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context], IgnoreHover = false @@ -355,8 +355,8 @@ public class AddServerOverlay : UserControl, IServerOverlay btn!.Textures[0] = Globals.ms.TextureManager.GetTextureResource("BadTextbox.png"); page!.Controls.Add(UserName = new() { - Location = new(0, (int)(22* Globals.Settings.Scale), 0), - Size = new(page.Size.X, (int)(31* Globals.Settings.Scale)), + Location = new(0, 22.ScaleInt(), 0), + Size = new(page.Size.X, 31.ScaleInt()), WatermarkText = "Username", TextLocation = TextLocation.PostiveTureCenterLeft, AllowMultiLine = false diff --git a/Luski/GUI/MainScreen/UI/LuskiContextMenu.cs b/Luski/GUI/MainScreen/UI/LuskiContextMenu.cs index 4633cc5..70d57fc 100644 --- a/Luski/GUI/MainScreen/UI/LuskiContextMenu.cs +++ b/Luski/GUI/MainScreen/UI/LuskiContextMenu.cs @@ -11,9 +11,9 @@ public class LuskiContextMenu : BetterContextMenu public LuskiContextMenu() :base(Globals.ms.TextureManager.GetTextureResource("Context.png")) { - Margins = new((int)(5 * Globals.Settings.Scale)); + Margins = new(5.ScaleInt()); TextureDisplay = TextureDisplay.Center; - SpaceBetweenObjects = (int)(8 * Globals.Settings.Scale); + SpaceBetweenObjects = 8.ScaleInt(); } public Label AddLabel(string text, Color4 color) @@ -47,6 +47,6 @@ public class LuskiContextMenu : BetterContextMenu public new void AddLine() { - AddLine(Color4.White, (int)Globals.Settings.Scale); + AddLine(Color4.White, 1.ScaleInt()); } } \ No newline at end of file diff --git a/Luski/GUI/MainScreen/UI/LuskiControls/RoleView.cs b/Luski/GUI/MainScreen/UI/LuskiControls/RoleView.cs new file mode 100644 index 0000000..29475ef --- /dev/null +++ b/Luski/GUI/MainScreen/UI/LuskiControls/RoleView.cs @@ -0,0 +1,34 @@ +using GraphicsManager.Objects; +using Luski.net.Structures.Public; + +namespace Luski.GUI.MainScreen.UI.LuskiControls; + +public class RoleView : FlowLayout +{ + private string n = ""; + private int i = 0; + private Label l; + private Role r; + public RoleView(Role r) + { + n = r.Name; + this.r = r; + Console.WriteLine(r.Name); + l = new(Globals.DefaultFont) + { + Text = " " + n + " — " + i.ToString(), + }; + base.Size = new(0, 30.ScaleInt()); + base.BackgroundColor = new(43, 45, 49, 255); + Controls.Add(l); + } + + public async Task AddUser(SocketUser user) + { + var f = await UserView.Make(user, r); + Controls.Add(f); + Size = new(Size.X, Size.Y + f.Size.Y); + i++; + l.Text = " " + n + " — " + i.ToString(); + } +} \ No newline at end of file diff --git a/Luski/GUI/MainScreen/UI/LuskiControls/TextBox.cs b/Luski/GUI/MainScreen/UI/LuskiControls/TextBox.cs index 06421ab..9693201 100644 --- a/Luski/GUI/MainScreen/UI/LuskiControls/TextBox.cs +++ b/Luski/GUI/MainScreen/UI/LuskiControls/TextBox.cs @@ -1,3 +1,4 @@ +using System.Timers; using GraphicsManager.Enums; using GraphicsManager.Interfaces; using GraphicsManager.Objects; @@ -6,6 +7,7 @@ using OpenTK.Mathematics; using OpenTK.Windowing.Common; using OpenTK.Windowing.Common.Input; using OpenTK.Windowing.GraphicsLibraryFramework; +using Timer = System.Timers.Timer; namespace Luski.GUI.MainScreen.UI.LuskiControls; @@ -13,10 +15,16 @@ public class TextBox : UserControl { private Label _watermark, _label; private bool use; + private Rectangle Pointer; + private Timer t; + + public int CursorLocation { get; set; } = 0; public TextBox() :base(Globals.ms.TextureManager.GetTextureResource("Textbox.png")) { + t = new(500); + t.Elapsed += TOnElapsed; TextureDisplay = TextureDisplay.Center; _label = new Label(Globals.DefaultFont) { @@ -30,18 +38,36 @@ public class TextBox : UserControl HoverMouse = MouseCursor.IBeam, IgnoreHover = true }; + Pointer = new() + { + Size = new(1.ScaleInt(), (int)(Globals.DefaultFont.PixelHeight * ((float)Globals.DefaultFont.CurrentFonts[0].Face.Height/Globals.DefaultFont.CurrentFonts[0].Face.UnitsPerEM)) ), + Location = _watermark.Location, + BackgroundColor = Color4.White, + Visible = false + }; + Controls.Add(Pointer); Controls.Add(_label); Controls.Add(_watermark); } - + + private void TOnElapsed(object? sender, ElapsedEventArgs e) + { + Globals.ms.Invoke(new Action(() => + { + Pointer.Visible = !Pointer.Visible; + })); + } + public event Func? KeyPress; public override void UnFocus() { use = false; + Pointer.Visible = false; if (Window is not null && Window.focused == this) Window.focused = null; + } public override void Focus() { @@ -51,6 +77,7 @@ public class TextBox : UserControl { Window.focused.UnFocus(); } + t.Start(); Window.focused = this; use = true; @@ -65,12 +92,17 @@ public class TextBox : UserControl window.TextInput += WindowOnTextInput; if (!window.Context.IsCurrent) window.Context.MakeCurrent(); base.LoadToParent(parent, window); + Pointer.Location = _watermark.Location; } private void WindowOnTextInput(TextInputEventArgs obj) { if (!use) return; - Text += obj.AsString; + Text = Text.Insert((int)CursorLocation, obj.AsString); + CursorLocation += obj.AsString.Length; + var f = _label.GetCharLocation((int)CursorLocation); + Pointer.Location = _label.Location + new Vector3i(f.X, f.Y, 0); + Pointer.Visible = true; } @@ -88,7 +120,7 @@ public class TextBox : UserControl { _label.Location = value switch { - TextLocation.PostiveTureCenterLeft => new((int)(10 * Globals.Settings.Scale), + TextLocation.PostiveTureCenterLeft => new(10.ScaleInt(), ((Size.Y - _label.PostiveTrueHeight) / 2) - _label.Size.Y + _label.TrueHeight, Location.Z), _ => _label.Location }; @@ -98,7 +130,7 @@ public class TextBox : UserControl { _watermark.Location = value switch { - TextLocation.PostiveTureCenterLeft => new((int)(10 * Globals.Settings.Scale), + TextLocation.PostiveTureCenterLeft => new(10.ScaleInt(), ((Size.Y - _watermark.PostiveTrueHeight) / 2) - _watermark.Size.Y + _watermark.TrueHeight, Location.Z), _ => _watermark.Location }; @@ -160,7 +192,7 @@ public class TextBox : UserControl _label.Visible = true; _label.Location = TextLocation switch { - TextLocation.PostiveTureCenterLeft => new((int)(10*Globals.Settings.Scale), ((Size.Y - _label.PostiveTrueHeight) / 2) - _label.Size.Y + _label.TrueHeight, Location.Z), + TextLocation.PostiveTureCenterLeft => new(10.ScaleInt(), ((Size.Y - _label.PostiveTrueHeight) / 2) - _label.Size.Y + _label.TrueHeight, Location.Z), _ => _label.Location }; /* @@ -188,7 +220,7 @@ public class TextBox : UserControl _watermark.Visible = true; _watermark.Location = TextLocation switch { - TextLocation.PostiveTureCenterLeft => new((int)(10*Globals.Settings.Scale), ((Size.Y - _watermark.PostiveTrueHeight) / 2) - _watermark.Size.Y + _watermark.TrueHeight, Location.Z), + TextLocation.PostiveTureCenterLeft => new(10.ScaleInt(), ((Size.Y - _watermark.PostiveTrueHeight) / 2) - _watermark.Size.Y + _watermark.TrueHeight, Location.Z), _ => _watermark.Location }; /* @@ -222,17 +254,48 @@ public class TextBox : UserControl private void Window_KeyDown(KeyboardKeyEventArgs obj) { if (!use) return; + if (obj.Key == Keys.Left) + { + CursorLocation--; + var f = _label.GetCharLocation((int)CursorLocation); + Pointer.Location = _label.Location + new Vector3i(f.X, f.Y, 0); + Pointer.Visible = true; + } + if (obj.Key == Keys.Right) + { + if (CursorLocation != Text.Length) + { + CursorLocation++; + var f = _label.GetCharLocation((int)CursorLocation); + Pointer.Location = _label.Location + new Vector3i(f.X, f.Y, 0); + Pointer.Visible = true; + } + + } if (obj.Key == Keys.CapsLock || obj.Key == Keys.Menu || obj.Key == Keys.LeftSuper || obj.Key == Keys.RightSuper || obj.Key == Keys.End || obj.Key == Keys.Home || obj.Key == Keys.PageDown || obj.Key == Keys.PageUp || obj.Key == Keys.Insert || obj.Key == Keys.Up || obj.Key == Keys.Down || obj.Key == Keys.Left || obj.Key == Keys.Right) return; - if (obj.Key == Keys.Backspace || obj.Key == Keys.Delete) + if (obj.Key == Keys.Backspace) { if (!(Text.Length > 0)) return; - if (Text[Text.Length - 1] == '\n') + if (Text[CursorLocation- 1] == '\n') { Size = new(Size.X, Size.Y - (int)_label.Font.PixelHeight); if (OnRemoveLine is not null) OnRemoveLine.Invoke(); } - Text = Text.Remove(Text.Length - 1, 1); - + Text = Text.Remove(CursorLocation - 1, 1); + CursorLocation--; + var f = _label.GetCharLocation(CursorLocation); + Pointer.Location = _label.Location + new Vector3i(f.X, f.Y, 0); + Pointer.Visible = true; + } + if (obj.Key == Keys.Delete) + { + if (CursorLocation == Text.Length) return; + if (Text[CursorLocation] == '\n') + { + Size = new(Size.X, Size.Y - (int)_label.Font.PixelHeight); + if (OnRemoveLine is not null) OnRemoveLine.Invoke(); + } + Text = Text.Remove(CursorLocation, 1); } if (obj.Key == Keys.Enter) diff --git a/Luski/GUI/MainScreen/UI/LuskiControls/UserView.cs b/Luski/GUI/MainScreen/UI/LuskiControls/UserView.cs new file mode 100644 index 0000000..606f1db --- /dev/null +++ b/Luski/GUI/MainScreen/UI/LuskiControls/UserView.cs @@ -0,0 +1,31 @@ +using GraphicsManager.Interfaces; +using GraphicsManager.Objects; +using Luski.net.Structures.Public; + +namespace Luski.GUI.MainScreen.UI.LuskiControls; + +public class UserView : UserControl +{ + private UserView(IRenderObject user, SocketUser u, Role r) + { + base.Size = new(244.ScaleInt(), 44.ScaleInt()); + base.BackgroundColor = new(43, 45, 49, 255); + user.Location = new(8.ScaleInt(), 6.ScaleInt(), 0); + user.ForceDistanceUpdate(this); + Label uname = new(Globals.DefaultFont) + { + Text = u.DisplayName, + Color = r.Color.ToColor4() + }; + uname.Location = new(user.Location.X + user.Size.X + 8.ScaleInt(), + (user.Location.Y + (user.Size.Y / 2) - (uname.PostiveTrueHeight / 2) - uname.Size.Y + uname.TrueHeight), 0); + Controls.Add(uname); + Controls.Add(user); + } + + public static async Task Make(SocketUser u, Role r) + { + UserView m = new(await u.MakeRct(new(32.ScaleInt()), true), u, r); + return m; + } +} \ No newline at end of file diff --git a/Luski/GUI/MainScreen/UI/PublicServers/AddChannel.cs b/Luski/GUI/MainScreen/UI/PublicServers/AddChannel.cs index edac13e..f482ebf 100644 --- a/Luski/GUI/MainScreen/UI/PublicServers/AddChannel.cs +++ b/Luski/GUI/MainScreen/UI/PublicServers/AddChannel.cs @@ -23,8 +23,8 @@ public class AddChannel : UserControl Anchor = ObjectAnchor.All; FlowLayout fl = new() { - SpaceBetweenObjects = (int)(5 * Globals.Settings.Scale), - Size = new((int)(350 * Globals.Settings.Scale), (int)(220 * Globals.Settings.Scale)), + SpaceBetweenObjects = 5.ScaleInt(), + Size = new(350.ScaleInt(), 220.ScaleInt()), BackgroundColor = new(32,32,32,255), //Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context], //TextureDisplay = TextureDisplay.Center @@ -34,7 +34,7 @@ public class AddChannel : UserControl fl.Controls.Add(cn =new TextBox() { WatermarkText = "Channel Name", - Size = new((int)(34 * Globals.Settings.Scale)), + Size = new(34.ScaleInt()), Anchor = ObjectAnchor.Bottom | ObjectAnchor.Left | ObjectAnchor.Right, TextLocation = TextLocation.PostiveTureCenterLeft }); @@ -42,14 +42,14 @@ public class AddChannel : UserControl fl.Controls.Add(cd =new TextBox() { WatermarkText = "Channel Description", - Size = new((int)(34 * Globals.Settings.Scale)), + Size = cn.Size, Anchor = ObjectAnchor.Bottom | ObjectAnchor.Left | ObjectAnchor.Right, TextLocation = TextLocation.PostiveTureCenterLeft }); fl.Controls.Add(new Label(Globals.DefaultFont) {Text = "\n "}); fl.Controls.Add(btn = new(Globals.ms.TextureManager.GetTextureResource("Textbox.png")) { - Size = new((int)(40 * Globals.Settings.Scale)), + Size = new(40.ScaleInt()), TextureDisplay = TextureDisplay.Center }); Label sub = new(Globals.DefaultFont) diff --git a/Luski/GUI/MainScreen/UI/PublicServers/Category.cs b/Luski/GUI/MainScreen/UI/PublicServers/Category.cs index 69749d2..060d144 100644 --- a/Luski/GUI/MainScreen/UI/PublicServers/Category.cs +++ b/Luski/GUI/MainScreen/UI/PublicServers/Category.cs @@ -27,7 +27,7 @@ public class Category : UserControl, IChannelAdder c.CurrentCategory = cat; c.CS = cs; c.Anchor = ObjectAnchor.All; - c.Size = new((int)(307 * Globals.Settings.Scale), (int)(40* Globals.Settings.Scale)); + c.Size = new(307.ScaleInt(), 40.ScaleInt()); c.tmp = new() { Size = c.Size, @@ -40,7 +40,7 @@ public class Category : UserControl, IChannelAdder c.tmp.Controls.Add(c.ee = new(Globals.DefaultFont) { Text = ">", - Location = new((int)(5*Globals.Settings.Scale)), + Location = new(5.ScaleInt()), Color = cat.Color.ToColor4(), DIR = new(1,0), IgnoreHover = true @@ -52,11 +52,11 @@ public class Category : UserControl, IChannelAdder IgnoreHover = true }); c.Clicked += c.AllOnClicked; - c.Name.Location = new((int)(26 * Globals.Settings.Scale), ((c.Size.Y/2) - (c.Name.TrueHeight/ 2) - (c.Name.Size.Y - c.Name.TrueHeight)), 0); + c.Name.Location = new(26.ScaleInt(), ((c.Size.Y/2) - (c.Name.TrueHeight/ 2) - (c.Name.Size.Y - c.Name.TrueHeight)), 0); c.Members = new() { Anchor = ObjectAnchor.All, - Location = new((int)(20 * Globals.Settings.Scale), c.Size.Y, 0), + Location = new(20.ScaleInt(), c.Size.Y, 0), IgnoreHover = true }; c.ee.Location = new(c.ee.Location.X, c.Name.Location.Y, 0); diff --git a/Luski/GUI/MainScreen/UI/PublicServers/Channel.cs b/Luski/GUI/MainScreen/UI/PublicServers/Channel.cs index 8967ef3..846a1f2 100644 --- a/Luski/GUI/MainScreen/UI/PublicServers/Channel.cs +++ b/Luski/GUI/MainScreen/UI/PublicServers/Channel.cs @@ -21,15 +21,15 @@ public class Channel : UserControl { CS = cs; CurrentChannel = chan; - base.Size = new((int)(307 * Globals.Settings.Scale), (int)(40* Globals.Settings.Scale)); + base.Size = new(307.ScaleInt(), 34.ScaleInt()); TextureDisplay = TextureDisplay.HorizontalCenter; Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context]; - int i = (int)(4 * Globals.Settings.Scale); + int i = 4.ScaleInt(); r = new Rectangle(Globals.ms.TextureManager.GetAlphaCircle()) { Location = new(i,i,0), - Size = new ((int)(32 * Globals.Settings.Scale)), + Size = new (32.ScaleInt()), IgnoreHover = true }; Texture tex; @@ -48,7 +48,7 @@ public class Channel : UserControl }; Controls.Add(ChannelName); Clicked += AllOnClicked; - ChannelName.Location = new((int)(40 * Globals.Settings.Scale), + ChannelName.Location = new(40.ScaleInt(), (base.Size.Y / 2) - ((int)ChannelName.Font.PixelHeight) + (ChannelName.PostiveTrueHeight / 2) , 0); base.HoverMouse = MouseCursor.Hand; @@ -59,11 +59,11 @@ public class Channel : UserControl { CS = cs; CurrentChannel = chan; - base.Size = new((int)(307 * Globals.Settings.Scale), (int)(40* Globals.Settings.Scale)); + base.Size = new(307.ScaleInt(), 34.ScaleInt()); TextureDisplay = TextureDisplay.HorizontalCenter; Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context]; - int i = (int)(4 * Globals.Settings.Scale); + int i = 4.ScaleInt(); GC.Collect(); ChannelName = new Label(Globals.DefaultFont) { diff --git a/Luski/GUI/MainScreen/UI/PublicServers/ChatMessage.cs b/Luski/GUI/MainScreen/UI/PublicServers/ChatMessage.cs index a6294f7..40a5b02 100644 --- a/Luski/GUI/MainScreen/UI/PublicServers/ChatMessage.cs +++ b/Luski/GUI/MainScreen/UI/PublicServers/ChatMessage.cs @@ -1,10 +1,7 @@ using System.Diagnostics; -using System.Reflection; -using GraphicsManager; using GraphicsManager.Enums; using GraphicsManager.Interfaces; using GraphicsManager.Objects; -using GraphicsManager.Objects.Core; using Luski.net.Interfaces; using Luski.net.Structures.Main; using Luski.net.Structures.Public; @@ -16,7 +13,6 @@ namespace Luski.GUI.MainScreen.UI.PublicServers; public class ChatMessage : UserControl { - //private static Font TimeFont;// = Font.MakeFontFromSystem(13); private SocketMessage Msg { get; } private SocketChannel ch { get; } @@ -25,8 +21,8 @@ public class ChatMessage : UserControl private IRenderObject LastObject; private Label FirstL; - private readonly double HorPadding = (12 * Globals.Settings.Scale), - VerticalPadding = (12 * Globals.Settings.Scale); + private readonly double HorPadding = 12.ScaleDouble(), + VerticalPadding = 0.ScaleDouble(); private static Dictionary> Messages = new(); @@ -35,7 +31,7 @@ public class ChatMessage : UserControl IUser auth = await message.GetAuthor(CancellationToken.None); Color c = await auth.GetColor(); Color4 c4 = new(c.R, c.G, c.B, c.A); - return new ChatMessage(p, message, await message.GetParent(CancellationToken.None), auth, await auth.MakeRct(new((int)(38 * Globals.Settings.Scale)), message.IsProfile), c4); + return new ChatMessage(p, message, await message.GetParent(CancellationToken.None), auth, await auth.MakeRct(new(40.ScaleInt()), message.IsProfile), c4); } @@ -43,70 +39,70 @@ public class ChatMessage : UserControl { pc = p; Label label1; - Size = new((int)(723.5 * Globals.Settings.Scale), (int)(37 * Globals.Settings.Scale)); + base.Size = new(723.5.ScaleInt(), 37.ScaleInt()); ch = chan; - BackgroundColor = new(40, 40, 40, 255); + base.BackgroundColor = new(40, 40, 40, 255); Msg = message; Anchor = ObjectAnchor.Left | ObjectAnchor.Right; DateTime time = chan.Epoch.AddMilliseconds(Msg.ID >> 20).ToLocalTime(); - string timestr; + string time_str; if (time.Date == DateTime.Now.ToLocalTime().Date) { - timestr = $"Today at {time.ToShortTimeString()}"; + time_str = $"Today at {time.ToShortTimeString()}"; } else if (time.Date == DateTime.Now.ToLocalTime().AddDays(-1).Date) { - timestr = $"Yesterday at {time.ToShortTimeString()}"; + time_str = $"Yesterday at {time.ToShortTimeString()}"; } else { - timestr = $"{time:M/dd/yyyy h:mm tt}"; + time_str = $"{time:M/dd/yyyy h:mm tt}"; } - UserIcon.Location = new((int)(10 * Globals.Settings.Scale), (int)(2 * Globals.Settings.Scale), 0); + UserIcon.Location = new(10.ScaleInt(), 2.ScaleInt(), 0); Controls.Add(UserIcon); Controls.Add(label1 = new Label(Globals.DefaultFont) { Color = UserNameColor, Text = Author.DisplayName }); label1.Location = new( - (int)(54 * Globals.Settings.Scale), - (int)(UserIcon.Location.Y + (UserIcon.Size.Y / 2) - (label1.Font.CurrentFonts[0].Face.Size.Metrics.NominalHeight / 2) - label1.Size.Y + label1.Font.PixelHeight), 0); + 54.ScaleInt(), + //(int)(UserIcon.Location.Y + (UserIcon.Size.Y / 2) - (label1.Font.CurrentFonts[0].Face.Size.Metrics.NominalHeight / 2) - label1.Size.Y + label1.Font.PixelHeight), + UserIcon.Location.Y, + 0); LastObject = label1; FirstL = label1; - Controls.Add(new Label(Globals.TopTimeFont) { Location = new(label1.Location.X + label1.Size.X + (int)(8 * Globals.Settings.Scale), (int)(label1.Location.Y + label1.Font.PixelHeight - Globals.TopTimeFont.PixelHeight), 0), Text = timestr}); + Controls.Add(new Label(Globals.TopTimeFont) { Location = new(label1.Location.X + label1.Size.X + 8.ScaleInt(), (int)(label1.Location.Y + label1.Font.PixelHeight - Globals.TopTimeFont.PixelHeight), 0), Text = time_str}); if (!string.IsNullOrWhiteSpace(Msg.Context)) { Label l; - Controls.Add(l = new Label(Globals.MessageFont) { Location = new(LastObject.Location.X, (int)(LastObject.Location.Y + (LastObject as Label)!.Size.Y + VerticalPadding), 0), Text = message.Context}); + Controls.Add(l = new Label(Globals.MessageFont) { Location = new(LastObject.Location.X, (int)(UserIcon.Location.Y + UserIcon.Size.Y - Globals.MessageFont.PixelHeight), 0), Text = message.Context}); LastObject = l; } if (Msg.Files.Count > 0) { int row = 1; - int filesonrow = 0; + int files_on_row = 0; for (int i = 0; i < Msg.Files.Count; i++) { - double lx = (HorPadding * filesonrow) + LastObject.Location.X + (333 * (filesonrow + 1)); - if (lx > Size.X) + double lx = (HorPadding * files_on_row) + LastObject.Location.X + (333 * (files_on_row + 1)); + if (lx > base.Size.X) { row++; - filesonrow = 0; - lx = (HorPadding * filesonrow) + LastObject.Location.X + (333 * (filesonrow + 1)); + files_on_row = 0; + lx = (HorPadding * files_on_row) + LastObject.Location.X + (333 * (files_on_row + 1)); } - filesonrow++; + files_on_row++; IRenderObject cem = ContentEmbed.GetEmbed(this, Msg.Files[i], Msg.ChannelID).Result; cem.Location = new((int)(lx - 333), (int)(LastObject.Location.Y + 2 + LastObject.Size.Y + (HorPadding * row) + (66 * (row - 1))), 0); LastObject = cem; - //lo = cem.Location; - // si = cem.Size; Controls.Add(cem); } } - if (LastObject is Label ll) Size = new(Size.X, (int)(ll.Location.Y + ll.Size.Y + VerticalPadding)); - else Size = new(Size.X ,(int)(LastObject.Location.Y + LastObject.Size.Y + VerticalPadding)); + if (LastObject is Label ll) base.Size = new(base.Size.X, (int)(ll.Location.Y + ll.Size.Y + VerticalPadding)); + else base.Size = new(base.Size.X ,(int)(LastObject.Location.Y + LastObject.Size.Y + VerticalPadding)); } public async Task AddMessage(SocketMessage msg) @@ -216,7 +212,7 @@ public class ChatMessage : UserControl Label m = new(Globals.DefaultFont) { Text = time.ToString("h:mm tt"), - Location = new((int)(7.5 * Globals.Settings.Scale), label.Location.Y - 13 + (int)label.Font.PixelHeight, 0), + Location = new(7.5.ScaleInt(), label.Location.Y - 13 + (int)label.Font.PixelHeight, 0), }; Controls.Add(m); diff --git a/Luski/GUI/MainScreen/UI/PublicServers/ContentEmbed.cs b/Luski/GUI/MainScreen/UI/PublicServers/ContentEmbed.cs index 23f35ae..677a37f 100644 --- a/Luski/GUI/MainScreen/UI/PublicServers/ContentEmbed.cs +++ b/Luski/GUI/MainScreen/UI/PublicServers/ContentEmbed.cs @@ -25,7 +25,7 @@ public class ContentEmbed : UserControl Texture t = Globals.ms.TextureManager.AddTexture(data); data.Dispose(); Rectangle r; - double s = (Globals.Settings.Scale * 322); + double s = 322.ScaleDouble(); double scale = s / t.RawSize!.Value.X; m.Controls.Add(r = new Rectangle(t) { diff --git a/Luski/GUI/MainScreen/UI/PublicServers/PublicChat.cs b/Luski/GUI/MainScreen/UI/PublicServers/PublicChat.cs index 79468de..472fc78 100644 --- a/Luski/GUI/MainScreen/UI/PublicServers/PublicChat.cs +++ b/Luski/GUI/MainScreen/UI/PublicServers/PublicChat.cs @@ -1,6 +1,7 @@ using System.Reflection; using GraphicsManager; using GraphicsManager.Enums; +using GraphicsManager.Interfaces; using GraphicsManager.Objects; using Luski.GUI.MainScreen.UI.LuskiControls; using Luski.net.Structures.Public; @@ -21,17 +22,18 @@ public class PublicChat : UserControl UserControl titlecon; private Rectangle? UserCon; private SocketMessage? first; + private FlowLayout? memberflow = null; public PublicChat() { - base.Size = new((int)(980 * Globals.Settings.Scale), (int)(866 * Globals.Settings.Scale)); + base.Size = new(980.ScaleInt(), 866.ScaleInt()); BackgroundColor = new(40,40,40,255); Anchor = ObjectAnchor.All; Controls.Add(MessageFlow = new() { - Size = new(base.Size.X, (int)(761 * Globals.Settings.Scale)), - Location = new(0, (int)(52 * Globals.Settings.Scale), 0), + Size = new(base.Size.X, 761.ScaleInt()), + Location = new(0, 52.ScaleInt(), 0), BackgroundColor = new(40,40,40,255), Anchor = ObjectAnchor.All, HScrollPixels = Globals.Settings.PerScrollPixels, @@ -41,7 +43,7 @@ public class PublicChat : UserControl Controls.Add(titlecon = new UserControl() { Anchor = ObjectAnchor.Left | ObjectAnchor.Top | ObjectAnchor.Right, - Size = new((int)(980 * Globals.Settings.Scale), (int)(48 * Globals.Settings.Scale)), + Size = new(980.ScaleInt(), 48.ScaleInt()), BackgroundColor = new(50,50,50,255), }); if (LuskiExperiments.ServerExperiments.MemberList.IsEnabled()) @@ -49,12 +51,13 @@ public class PublicChat : UserControl UserCon = new(Globals.ms.TextureManager.GetTextureResource("person.png")) { - Size = new((int)(24 * Globals.Settings.Scale)), - Location = new((int)(944 * Globals.Settings.Scale),(int)(12 * Globals.Settings.Scale),0), + Size = new(24.ScaleInt()), + Location = new(944.ScaleInt(), 12.ScaleInt(),0), Anchor = ObjectAnchor.Right | ObjectAnchor.Top, Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context], BackgroundColor = Color4.Red }; + UserCon.Clicked += UserConOnClicked; titlecon.Controls.Add(UserCon); } LuskiExperiments.ServerExperiments.MemberList.EventToggled += MemberListOnEventToggled; @@ -63,8 +66,6 @@ public class PublicChat : UserControl titlecon.Controls.Add(title = new Label(Globals.DefaultFont) { //Location = new( - // (int)((26 - (Globals.DefaultFont.PixelHeight / 2)) * Globals.Settings.Scale), - // (int)((26 * Globals.Settings.Scale) - (Globals.DefaultFont.PixelHeight/2.0))) }); titlecon.Controls.Add(desc = new Label(Globals.DefaultFont) { @@ -76,8 +77,8 @@ public class PublicChat : UserControl { // InsideColor = new(28, 28, 28, 255), //BorderColor = Color4.DarkCyan, - Location = new((int)(10 * Globals.Settings.Scale), (int)(824 * Globals.Settings.Scale), 0), - Size = new((int)(960 * Globals.Settings.Scale), (int)(34 * Globals.Settings.Scale)), + Location = new(10.ScaleInt(), 824.ScaleInt(), 0), + Size = new(960.ScaleInt(), 34.ScaleInt()), Anchor = ObjectAnchor.Bottom | ObjectAnchor.Left | ObjectAnchor.Right, HoverMouse = MouseCursor.IBeam, //Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context], @@ -118,6 +119,7 @@ public class PublicChat : UserControl { await Channel!.SendMessage(tb.Text); tb.Text = string.Empty; + tb.CursorLocation = 0; } } @@ -139,28 +141,74 @@ public class PublicChat : UserControl return Task.CompletedTask; } - private Task MemberListOnEventToggled(bool arg) + private async Task MemberListOnEventToggled(bool arg) { if (arg) { UserCon = new(Globals.ms.TextureManager.GetTextureResource("person.png")) { - Size = new((int)(24 * Globals.Settings.Scale)), - Location = new(base.Size.X - (int)(36 * Globals.Settings.Scale),(int)(12 * Globals.Settings.Scale),0), + Size = new(24.ScaleInt()), + Location = new(base.Size.X - 36.ScaleInt(), 12.ScaleInt(),0), Anchor = ObjectAnchor.Right | ObjectAnchor.Top, Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context], BackgroundColor = Color4.Red }; + UserCon.Clicked += UserConOnClicked; titlecon.Controls.Add(UserCon); } else { + if (um_open) await UserConOnClicked(UserCon!); titlecon.Controls.Remove(UserCon!); UserCon = null; } + } - return Task.CompletedTask; + private bool um_open = false; + + private async Task UserConOnClicked(IRenderObject arg) + { + um_open = !um_open; + if (um_open) + { + if (memberflow is null) + { + int x = 232.ScaleInt(); + memberflow = new() + { + BackgroundColor = new(255, 0, 0, 255), + Size = new(x, Size.Y - titlecon.Size.Y), + Location = new(Size.X - x, titlecon.Size.Y, 0) + }; + Controls.Add(memberflow); + Dictionary Roles = new(); + + foreach (var m in await Channel!.GetMembers()) + { + Role top_role = (await m.GetRoles())[0]; + if (!Roles.ContainsKey(top_role.ID)) + { + Roles.Add(top_role.ID, new(top_role)); + memberflow.Controls.Add(Roles[top_role.ID]); + } + Roles[top_role.ID].AddUser(m); + } + } + + memberflow.Visible = true; + + MessageFlow.Size = new(MessageFlow.Size.X - memberflow.Size.X, MessageFlow.Size.Y); + tb.Size = new(tb.Size.X - memberflow.Size.X, tb.Size.Y); + tb.ForceDistanceUpdate(); + } + else + { + memberflow!.Visible = false; + MessageFlow.Size = new(MessageFlow.Size.X + memberflow.Size.X, MessageFlow.Size.Y); + tb.Size = new(tb.Size.X + memberflow.Size.X, tb.Size.Y); + tb.ForceDistanceUpdate(); + } } private SocketMessage? lastm; @@ -177,15 +225,21 @@ public class PublicChat : UserControl public async Task LoadChannel(SocketChannel channel) { Channel = channel; + if (memberflow is not null) + { + memberflow.Controls.Clear(); + } title.Text = channel.Name; desc.Text = channel.Description; - desc.Location = new((int)(title.Location.X + title.Size.X + (5 * Globals.Settings.Scale)), desc.Location.Y, 0); + desc.Location = new((int)(title.Location.X + title.Size.X + 5.ScaleInt()), desc.Location.Y, 0); if (Window is not null) { Window.Title = $"{channel.Name} | {channel.Server.Name} - Luski"; } tb.WatermarkText = $"Message {channel.Name}"; tb.Text = ""; + tb.CursorLocation = 0; + tb.Focus(); } public void ClearChat() diff --git a/Luski/GUI/MainScreen/UI/ServerIcon.cs b/Luski/GUI/MainScreen/UI/ServerIcon.cs index 12601d2..83ba89c 100644 --- a/Luski/GUI/MainScreen/UI/ServerIcon.cs +++ b/Luski/GUI/MainScreen/UI/ServerIcon.cs @@ -45,23 +45,23 @@ public class ServerIcon : UserControl where TServer : Server { Rectangle r = new(Globals.ms.TextureManager.GetTextureResource("rc.png")) { - Location = new((int)(18 * Globals.Settings.Scale), (int)(8 * Globals.Settings.Scale), 0), - Size = new((int)(32 * Globals.Settings.Scale)), + Location = new(18.ScaleInt(), 8.ScaleInt(), 0), + Size = new(32.ScaleInt()), Shader = Rectangle.DefaultAlphaTextureShader[Globals.ms.Context], IgnoreHover = true }; Rectangle rr = new(r.Textures[0]) { - Location = new((int)(17 * Globals.Settings.Scale), (int)(7 * Globals.Settings.Scale), 0), - Size = new((int)(34 * Globals.Settings.Scale)), + Location = new(17.ScaleInt(), 7.ScaleInt(), 0), + Size = new(34.ScaleInt()), Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context], BackgroundColor = new(26, 26, 26, 255), IgnoreHover = true }; SelectedRect = new(r.Textures[0]) { - Location = new((int)(14 * Globals.Settings.Scale), (int)(4 * Globals.Settings.Scale), 0), - Size = new((int)(40 * Globals.Settings.Scale)), + Location = new(14.ScaleInt(), 4.ScaleInt(), 0), + Size = new(40.ScaleInt()), Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context], BackgroundColor = new(26, 26, 26, 255), IgnoreHover = true @@ -75,7 +75,7 @@ public class ServerIcon : UserControl where TServer : Server Controls.Add(r); BackgroundColor = new(26, 26, 26, 255); this.Clicked += OnClicked; - Size = new((int)(68 * Globals.Settings.Scale), (int)(48 * Globals.Settings.Scale)); + Size = new(68.ScaleInt(), 48.ScaleInt()); } private async Task OnClicked(IRenderObject arg) diff --git a/Luski/GUI/MainScreen/UI/ServerLoginOverlay.cs b/Luski/GUI/MainScreen/UI/ServerLoginOverlay.cs index fff86e5..c0df788 100644 --- a/Luski/GUI/MainScreen/UI/ServerLoginOverlay.cs +++ b/Luski/GUI/MainScreen/UI/ServerLoginOverlay.cs @@ -34,7 +34,7 @@ public class ServerLoginOverlay : UserControl, IServerOverlay Form = new(Globals.ms.TextureManager.GetTextureResource("RoundedRectangle.png")) { - Size = new((int)(350 * Globals.Settings.Scale), (int)(347 * Globals.Settings.Scale)), + Size = new(350.ScaleInt(), 347.ScaleInt()), BackgroundColor = new(32,32,32,255), Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context], TextureDisplay = TextureDisplay.Center @@ -50,18 +50,18 @@ public class ServerLoginOverlay : UserControl, IServerOverlay Color = Color4.DarkGray, IgnoreHover = true }; - Vector2i s =new((int)(ll.Size.X * 1.6f),(int)(27 * Globals.Settings.Scale)); + Vector2i s =new((int)(ll.Size.X * 1.6f),27.ScaleInt()); ll = null; Rectangle line = new Rectangle() { - Size = new Vector2i((int)Globals.Settings.Scale), + Size = new Vector2i(1.ScaleInt()), BackgroundColor = Globals.DodgerBlue }; tb = new() { - Location = new((int)(10*Globals.Settings.Scale),(int)(50 * Globals.Settings.Scale), 0), + Location = new(10.ScaleInt(),50.ScaleInt(), 0), Size = s, Text = address, WatermarkText = "Server Address", @@ -196,8 +196,8 @@ public class ServerLoginOverlay : UserControl, IServerOverlay btn.Textures[0] = Globals.ms.TextureManager.GetTextureResource("BadTextbox.png"); page!.Controls.Add(UserName = new() { - Location = new(0, (int)(10* Globals.Settings.Scale), 0), - Size = new(page.Size.X, (int)(30* Globals.Settings.Scale)), + Location = new(0, 10.ScaleInt(), 0), + Size = new(page.Size.X, 30.ScaleInt()), WatermarkText = "Username", TextLocation = TextLocation.PostiveTureCenterLeft, AllowMultiLine = false @@ -284,7 +284,7 @@ public class ServerLoginOverlay : UserControl, IServerOverlay page.Controls.Add(rec = new(Globals.ms.TextureManager.GetAlphaCircle()) { - Size = new((int)(50 * Globals.Settings.Scale)), + Size = new(50.ScaleInt()), BackgroundColor = Color4.Red, Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context], IgnoreHover = false @@ -356,8 +356,8 @@ public class ServerLoginOverlay : UserControl, IServerOverlay btn!.Textures[0] = Globals.ms.TextureManager.GetTextureResource("BadTextbox.png"); page!.Controls.Add(UserName = new() { - Location = new(0, (int)(22* Globals.Settings.Scale), 0), - Size = new(page.Size.X, (int)(31* Globals.Settings.Scale)), + Location = new(0, 22.ScaleInt(), 0), + Size = new(page.Size.X, 31.ScaleInt()), WatermarkText = "Username", TextLocation = TextLocation.PostiveTureCenterLeft, AllowMultiLine = false @@ -466,8 +466,6 @@ public class ServerLoginOverlay : UserControl, IServerOverlay BackgroundColor = Form.BackgroundColor }; page.Size = new(Form.Size.X - tb.Location.X - tb.Location.X, Form.Size.Y - tb.Location.X - page.Location.Y - ca.Size.Y - tb.Location.X); - Console.Write(page.Size.Y - tb.Location.X - tb.Location.X - (50*2*3)); - Console.WriteLine(page.Size); Form.Controls.Add(page); btn = new(Globals.ms.TextureManager.GetTextureResource("BadTextbox.png")) diff --git a/Luski/GUI/MainScreen/UI/SettingsMenu.cs b/Luski/GUI/MainScreen/UI/SettingsMenu.cs index 2d1e524..fbe6fcc 100644 --- a/Luski/GUI/MainScreen/UI/SettingsMenu.cs +++ b/Luski/GUI/MainScreen/UI/SettingsMenu.cs @@ -33,7 +33,7 @@ public class SettingsMenu : UserControl fl = new() { BackgroundColor = new(20, 20, 20, 255), - Size = new((int)(307 * Globals.Settings.Scale), base.Size.Y), + Size = new(307.ScaleInt(), base.Size.Y), Anchor = ObjectAnchor.Top | ObjectAnchor.Left | ObjectAnchor.Bottom }; f = Globals.DefaultFont.Clone(); @@ -46,7 +46,7 @@ public class SettingsMenu : UserControl AppSettings = new("APP SETTINGS"); Label Top = new(Globals.DefaultFont) { - Location = new((int)(5 * Globals.Settings.Scale), (int)(5 * Globals.Settings.Scale), 0), + Location = new(5.ScaleInt(), 5.ScaleInt(), 0), Text = LuskiThemes.Dark.Name }; CategoryButton cb2 = new("Appearance", this) @@ -60,9 +60,9 @@ public class SettingsMenu : UserControl ThemeDropButton LightDD; ThemeDrop = new(CategoryButton.seltec!,new Rectangle() { - Size = new(base.Size.X - 2, (int)Globals.Settings.Scale), + Size = new(base.Size.X - 2, 1.ScaleInt()), BackgroundColor = Color4.Gray, - Location = new(1, base.Size.Y - (int)Globals.Settings.Scale, 0), + Location = new(1, base.Size.Y - 1.ScaleInt(), 0), Anchor = ObjectAnchor.Left | ObjectAnchor.Right | ObjectAnchor.Bottom }, LightDD = new(LuskiThemes.Light) { @@ -74,13 +74,13 @@ public class SettingsMenu : UserControl Color = Color4.DarkGray, IgnoreHover = true }; - ll.Location = new((int)(10 * Globals.Settings.Scale), + ll.Location = new(10.ScaleInt(), (ThemeDrop!.Size.Y / 2) - ((int)ll.Font.PixelHeight) + (ll.PostiveTrueHeight / 2) , 0); ThemeDrop.Controls.Add(ll); }, - Size = new((int)(297 * Globals.Settings.Scale), (int)(40* Globals.Settings.Scale)), - }){DropDownParentOverride = Globals.ms,Size = new((int)(40 * Globals.Settings.Scale)), + Size = new(297.ScaleInt(), 40.ScaleInt()), + }){DropDownParentOverride = Globals.ms,Size = new(40.ScaleInt()), Location = new(Top.Location.X, Top.Location.Y, 0), BackgroundColor = new(40, 40, 40, 255), Anchor = ObjectAnchor.Right | ObjectAnchor.Left,}; @@ -98,12 +98,12 @@ public class SettingsMenu : UserControl Color = Color4.DarkGray, IgnoreHover = true }; - ll.Location = new((int)(10 * Globals.Settings.Scale), + ll.Location = new(10.ScaleInt(), (ThemeDrop!.Size.Y / 2) - ((int)ll.Font.PixelHeight) + (ll.PostiveTrueHeight / 2) , 0); ThemeDrop.Controls.Add(ll); }, - Size = new((int)(297 * Globals.Settings.Scale), (int)(40* Globals.Settings.Scale)), + Size = new(297.ScaleInt(), 40.ScaleInt()), }); if (themeStart.Name == Globals.Settings.Theme) ThemeDrop.SetSelected(tdb); } @@ -113,9 +113,9 @@ public class SettingsMenu : UserControl ThemeDrop.DropDownContainer.BackgroundColor = ThemeDrop.BackgroundColor; Rectangle line = new() { - Size = new(base.Size.X - 2, (int)Globals.Settings.Scale), + Size = new(base.Size.X - 2, 1.ScaleInt()), BackgroundColor = Color4.Gray, - Location = new(1, base.Size.Y - (int)Globals.Settings.Scale, 0), + Location = new(1, base.Size.Y - 1.ScaleInt(), 0), Anchor = ObjectAnchor.Left | ObjectAnchor.Right | ObjectAnchor.Bottom }; ThemeDrop.OpenStatusChanged += b => @@ -192,7 +192,7 @@ public class SettingsMenu : UserControl Text = Globals.UpdaterSettings.Updater!, WatermarkText = "Updater File", TextureDisplay = TextureDisplay.Center, - Size = new(page.Size.X, (int)(34 * Globals.Settings.Scale)), + Size = new(page.Size.X, 34.ScaleInt()), TextLocation = TextLocation.PostiveTureCenterLeft, AllowMultiLine = false }); @@ -210,8 +210,8 @@ public class SettingsMenu : UserControl page = new() { BackgroundColor = this.BackgroundColor, - Location = new(fl.Size.X + (int)(40 * Globals.Settings.Scale), 0, 0), - Size = new(Globals.ms.Size.X - fl.Size.X - ((int)(80 * Globals.Settings.Scale)), Globals.ms.Size.Y), + Location = new(fl.Size.X + 40.ScaleInt(), 0, 0), + Size = new(Globals.ms.Size.X - fl.Size.X - 80.ScaleInt(), Globals.ms.Size.Y), AllowHoverFromBehind = true, Anchor = ObjectAnchor.All, HScrollPixels = Globals.Settings.PerScrollPixels @@ -222,8 +222,8 @@ public class SettingsMenu : UserControl Rectangle closebtn = new(Globals.ms.TextureManager.GetTextureResource("close.png")) { - Location = new(Globals.ms.Size.X - (int)(40 * Globals.Settings.Scale), (int)(8 * Globals.Settings.Scale),0), - Size = new((int)(32 * Globals.Settings.Scale)), + Location = new(Globals.ms.Size.X - 40.ScaleInt(), 8.ScaleInt(),0), + Size = new(32.ScaleInt()), Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context], BackgroundColor = Color4.Gray, Anchor = ObjectAnchor.Top | ObjectAnchor.Right diff --git a/Luski/GUI/MainScreen/UI/SettingsPanel/Category.cs b/Luski/GUI/MainScreen/UI/SettingsPanel/Category.cs index a2d9c05..7eaaf5d 100644 --- a/Luski/GUI/MainScreen/UI/SettingsPanel/Category.cs +++ b/Luski/GUI/MainScreen/UI/SettingsPanel/Category.cs @@ -24,17 +24,17 @@ public class Category : UserControl } Top = new(fi) { - Location = new((int)(5 * Globals.Settings.Scale), (int)(5 * Globals.Settings.Scale), 0), + Location = new(5.ScaleInt(), 5.ScaleInt(), 0), Text = Name }; BackgroundColor = new(255, 255, 255, 0); - base.Size = new((int)(307 * Globals.Settings.Scale), (int)(20 * Globals.Settings.Scale) + Top.Size.Y); + 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, (int)Globals.Settings.Scale), + Size = new(base.Size.X, 1.ScaleInt()), BackgroundColor = Color4.Gray, - Location = new(0, base.Size.Y - (int)Globals.Settings.Scale, 0) + Location = new(0, base.Size.Y - 1.ScaleInt(), 0) }; line.ForceDistanceUpdate(this); Controls.Add(line); @@ -44,7 +44,7 @@ public class Category : UserControl public void AddButton(CategoryButton cb) { Controls.Add(cb); - int f = (int)(5 * Globals.Settings.Scale); + 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); diff --git a/Luski/GUI/MainScreen/UI/SettingsPanel/CategoryButton.cs b/Luski/GUI/MainScreen/UI/SettingsPanel/CategoryButton.cs index d209123..9d209bd 100644 --- a/Luski/GUI/MainScreen/UI/SettingsPanel/CategoryButton.cs +++ b/Luski/GUI/MainScreen/UI/SettingsPanel/CategoryButton.cs @@ -17,7 +17,7 @@ public class CategoryButton : UserControl :base(seltec) { this.SM = SM; - base.Size = new((int)(297 * Globals.Settings.Scale), (int)(40* Globals.Settings.Scale)); + base.Size = new(297.ScaleInt(), 40.ScaleInt()); TextureDisplay = TextureDisplay.HorizontalCenter; Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context]; l = new Label(Globals.DefaultFont) @@ -26,7 +26,7 @@ public class CategoryButton : UserControl Color = Color4.Gray, IgnoreHover = true }; - l.Location = new((int)(5 * Globals.Settings.Scale), + l.Location = new(5.ScaleInt(), (base.Size.Y / 2) - ((int)l.Font.PixelHeight) + (l.PostiveTrueHeight / 2) , 0); Controls.Add(l); diff --git a/Luski/GUI/MainScreen/UI/SettingsPanel/ExperimentDropButton.cs b/Luski/GUI/MainScreen/UI/SettingsPanel/ExperimentDropButton.cs index 1b6105f..bd7b64a 100644 --- a/Luski/GUI/MainScreen/UI/SettingsPanel/ExperimentDropButton.cs +++ b/Luski/GUI/MainScreen/UI/SettingsPanel/ExperimentDropButton.cs @@ -17,7 +17,7 @@ public class ExperimentDropButton : DropDownOption :base(CategoryButton.seltec!) { ESI = esi; - base.Size = new((int)(297 * Globals.Settings.Scale), (int)(40* Globals.Settings.Scale)); + base.Size = new(297.ScaleInt(), 40.ScaleInt()); TextureDisplay = TextureDisplay.HorizontalCenter; Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context]; l = new Label(Globals.DefaultFont) @@ -26,7 +26,7 @@ public class ExperimentDropButton : DropDownOption Color = Color4.DarkGray, IgnoreHover = true }; - l.Location = new((int)(10 * Globals.Settings.Scale), + l.Location = new(10.ScaleInt(), (base.Size.Y / 2) - ((int)l.Font.PixelHeight) + (l.PostiveTrueHeight / 2) , 0); d = new(Globals.MessageFont) diff --git a/Luski/GUI/MainScreen/UI/SettingsPanel/ExperimentGUI.cs b/Luski/GUI/MainScreen/UI/SettingsPanel/ExperimentGUI.cs index e0766c3..13c7159 100644 --- a/Luski/GUI/MainScreen/UI/SettingsPanel/ExperimentGUI.cs +++ b/Luski/GUI/MainScreen/UI/SettingsPanel/ExperimentGUI.cs @@ -38,7 +38,7 @@ public class ExperimentGUI : UserControl } Top = new(Globals.DefaultFont) { - Location = new((int)(5 * Globals.Settings.Scale), (int)(5 * Globals.Settings.Scale), 0), + Location = new(5.ScaleInt(), 5.ScaleInt(), 0), Text = ei.DisplayName }; Label n = new(Globals.MessageFont) @@ -59,20 +59,20 @@ public class ExperimentGUI : UserControl Color = Color4.DarkGray, IgnoreHover = true }; - ll.Location = new((int)(10 * Globals.Settings.Scale), + ll.Location = new(10.ScaleInt(), (dd!.Size.Y / 2) - ((int)ll.Font.PixelHeight) + (ll.PostiveTrueHeight / 2) , 0); dd.Controls.Add(ll); }, - Size = new((int)(297 * Globals.Settings.Scale), (int)(40* Globals.Settings.Scale)) + Size = new(297.ScaleInt(), 40.ScaleInt()) }; dd = new(CategoryButton.seltec!, new Rectangle() { - Size = new((int)Globals.Settings.Scale), + Size = new(1.ScaleInt()), BackgroundColor = Color4.Gray }, Disabled) { - Size = new((int)(40 * Globals.Settings.Scale)), + Size = new(40.ScaleInt()), Location = new(Top.Location.X, n.Location.Y + n.Size.Y + Top.Location.Y, 0), BackgroundColor = new(40, 40, 40, 255), Anchor = ObjectAnchor.Right | ObjectAnchor.Left, @@ -115,7 +115,7 @@ public class ExperimentGUI : UserControl Color = Color4.DarkGray, IgnoreHover = true }; - ll.Location = new((int)(10 * Globals.Settings.Scale), + ll.Location = new(10.ScaleInt(), (dd.Size.Y / 2) - ((int)ll.Font.PixelHeight) + (ll.PostiveTrueHeight / 2) , 0); dd.Controls.Add(ll); @@ -130,15 +130,15 @@ public class ExperimentGUI : UserControl } dd.OptionSelected += DdOnOptionSelected; Controls.Add(dd); - base.Size = new(Globals.ms.Size.X - (int)(307 * Globals.Settings.Scale) - (int)(80 * Globals.Settings.Scale), (int)(15 * Globals.Settings.Scale) + dd.Size.Y + dd.Location.Y ); + base.Size = new(Globals.ms.Size.X - 307.ScaleInt() - 80.ScaleInt(), 15.ScaleInt() + dd.Size.Y + dd.Location.Y ); dd.Size = new(base.Size.X - Top.Location.X - Top.Location.X, dd.Size.Y); dd.ForceDistanceUpdate(this); line = new() { - Size = new(base.Size.X - 2, (int)Globals.Settings.Scale), + Size = new(base.Size.X - 2, 1.ScaleInt()), BackgroundColor = Color4.Gray, - Location = new(1, base.Size.Y - (int)Globals.Settings.Scale, 0), + Location = new(1, base.Size.Y - 1.ScaleInt(), 0), Anchor = ObjectAnchor.Left | ObjectAnchor.Right | ObjectAnchor.Bottom }; line.ForceDistanceUpdate(this); diff --git a/Luski/GUI/MainScreen/UI/SettingsPanel/ThemeDropButton.cs b/Luski/GUI/MainScreen/UI/SettingsPanel/ThemeDropButton.cs index f1d43cf..6920e5b 100644 --- a/Luski/GUI/MainScreen/UI/SettingsPanel/ThemeDropButton.cs +++ b/Luski/GUI/MainScreen/UI/SettingsPanel/ThemeDropButton.cs @@ -17,7 +17,7 @@ public class ThemeDropButton : DropDownOption :base(CategoryButton.seltec!) { ESI = esi; - base.Size = new((int)(297 * Globals.Settings.Scale), (int)(40* Globals.Settings.Scale)); + base.Size = new(297.ScaleInt(), 40.ScaleInt()); TextureDisplay = TextureDisplay.HorizontalCenter; Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context]; l = new Label(Globals.DefaultFont) @@ -26,7 +26,7 @@ public class ThemeDropButton : DropDownOption Color = Color4.DarkGray, IgnoreHover = true }; - l.Location = new((int)(10 * Globals.Settings.Scale), + l.Location = new(10.ScaleInt(), (base.Size.Y / 2) - ((int)l.Font.PixelHeight) + (l.PostiveTrueHeight / 2) , 0); d = new(Globals.MessageFont) diff --git a/Luski/GUI/MainScreenWindow.cs b/Luski/GUI/MainScreenWindow.cs index d7a7262..f3d2b45 100644 --- a/Luski/GUI/MainScreenWindow.cs +++ b/Luski/GUI/MainScreenWindow.cs @@ -8,7 +8,6 @@ using GraphicsManager.Objects; using GraphicsManager.Objects.Core; using Luski.GUI.MainScreen.UI; using Luski.GUI.MainScreen.UI.PublicServers; -using Luski.GUI.StartPage.UI; using Luski.net; using Luski.net.Structures.Public; using OpenTK.Graphics.OpenGL4; @@ -28,7 +27,7 @@ public class MainScreenWindow : Window APIVersion = new Version(3, 2), API = ContextAPI.OpenGL, StartFocused = true, - Size = new Vector2i((int)(312 * Globals.Settings.Scale), (int)(545 * Globals.Settings.Scale)), + Size = new Vector2i(624, 1090), Icon = Globals.Icon, SharedContext = null, }; @@ -36,8 +35,6 @@ public class MainScreenWindow : Window public TabControl? tc; private FlowLayout? channelpicker, friends, friend_request; private RoundedButton? FriendManagerBtn; - Login login; - CreateAccount ca; private static DebugProc DebugMessageDelegate = OnDebugMessage; private static void OnDebugMessage( @@ -49,14 +46,8 @@ public class MainScreenWindow : Window IntPtr pMessage, // Pointer to message string. IntPtr pUserParam) // The pointer you gave to OpenGL, explained later. { - // In order to access the string pointed to by pMessage, you can use Marshal - // class to copy its contents to a C# string without unsafe code. You can - // also use the new function Marshal.PtrToStringUTF8 since .NET Core 1.1. string message = Marshal.PtrToStringAnsi(pMessage, length); - // The rest of the function is up to you to implement, however a debug output - // is always useful. - switch (severity) { case DebugSeverity.DebugSeverityHigh: @@ -98,41 +89,48 @@ public class MainScreenWindow : Window public MainScreenWindow() : base(Settings) { + Globals.ms = this; ShowMissingChar = true; LogFrames = ((Globals.Settings.Logs & ConsoleLog.DrawFrames) == ConsoleLog.DrawFrames); VSync = VSyncMode.On; - this.TryGetCurrentMonitorScale(out var h, out var v); + GL.DebugMessageCallback(DebugMessageDelegate, IntPtr.Zero); GL.Enable(EnableCap.DebugOutput); try { Globals.DefaultFontFamly = FontFamily.LoadFontFamily(Globals.GetResource("Fonts.OpenSans.zip"), "OpenSans"); Globals.DefaultFont = FontInteraction.Load(Globals.DefaultFontFamly); - //Globals.DefaultFont.AddFamily(FontFamily.LoadFontFamily(Globals.GetResource("Fonts.Exo.zip"), "Exo")); - //Globals.DefaultFont.AddFamily(FontFamily.LoadFontFamily(Globals.GetResource("Fonts.Roboto.zip"), "Roboto")); - Globals.DefaultFont.AddFamily(FontFamily.LoadFontFamily(Globals.GetResource("Fonts.Noto_Sans_JP.zip"), "Noto_Sans_JP")); - string t = ""; - for (int i = 9199; i < 9205; i++) + string fams = Path.Combine(Globals.LuskiPath, "FontFamilies"); + if (!Directory.Exists(fams)) Directory.CreateDirectory(fams); + DirectoryInfo di = new DirectoryInfo(fams); + + foreach (FileInfo fam in di.GetFiles()) { - t += (char)i; + try + { + if (fam.FullName.ToLower().EndsWith(".zip")) + Globals.DefaultFont.AddFamily(FontFamily.LoadFontFamily(File.Open(fam.FullName, FileMode.Open), fam.Name)); + } + catch (Exception e) + { + Console.WriteLine(e); + } } - //Console.WriteLine(t); } catch (Exception e) { Console.WriteLine(e); } - - - - Globals.DefaultFont.PixelHeight = (uint)(20 * Globals.Settings.Scale); + + + Globals.DefaultFont.PixelHeight = Globals.Settings.DefaultFontPX.ScaleFont(); Globals.DefaultFont.FontSize = FontSize.Regular; Globals.TopTimeFont = Globals.DefaultFont.Clone(); - Globals.TopTimeFont.PixelHeight = (uint)(12 * Globals.Settings.Scale); + Globals.TopTimeFont.PixelHeight = Globals.Settings.TopTimeFonttPX.ScaleFont(); Globals.TopTimeFont.FontSize = FontSize.Regular; Globals.MessageFont = Globals.DefaultFont.Clone(); - Globals.MessageFont.PixelHeight = (uint)(17 * Globals.Settings.Scale); - Globals.MessageFont.ExtraLinePixels = (uint)(5 * Globals.Settings.Scale); + Globals.MessageFont.PixelHeight = Globals.Settings.MessageFontPX.ScaleFont(); + Globals.MessageFont.ExtraLinePixels = Globals.Settings.MessageFontLineSpacePX.ScaleFont(); Globals.MessageFont.FontSize = FontSize.Regular; Globals.SmallTimeFont = Globals.DefaultFont.Clone(); Globals.LuskiTexture = TextureManager.GetTextureResource("Luski.png"); @@ -174,6 +172,7 @@ public class MainScreenWindow : Window public async Task LoadPublicServer(PublicServer? Server) { GL.Enable(EnableCap.DepthTest); + GL.Enable(EnableCap.Multisample); GL.DepthFunc(DepthFunction.Always); if (Server is null) return; if (!Server.IsLogedIn) @@ -218,7 +217,7 @@ public class MainScreenWindow : Window parents.Reverse(); ChannelSelector cs = await ChannelSelector.MakeSelector(parents[0]); cs.BackgroundColor = new(34, 34, 34, 255); - cs.Size = new((int)(307 * Globals.Settings.Scale), SerBox.Size.Y - (int)(54 * Globals.Settings.Scale)); + cs.Size = new(307.ScaleInt(), SerBox.Size.Y - 54.ScaleInt()); cs.Anchor = ObjectAnchor.Top | ObjectAnchor.Left | ObjectAnchor.Bottom; parents.RemoveAt(0); @@ -251,8 +250,8 @@ public class MainScreenWindow : Window Role[] ra = await Server.User.GetRoles(); Color c = ra[0].Color; Color4 c4 = new(c.R, c.G, c.B, c.A); - IRenderObject u = await Server.User.MakeRct(new((int)(46 * Globals.Settings.Scale)), false); - int ii = (int)(4 * Globals.Settings.Scale); + IRenderObject u = await Server.User.MakeRct(new(46.ScaleInt()), false); + int ii = 4.ScaleInt(); u.Location = new(ii, cs.Size.Y + ii, 0); u.Anchor = ObjectAnchor.Bottom | ObjectAnchor.Left; SerBox.Controls.Add(u); @@ -265,13 +264,13 @@ public class MainScreenWindow : Window Color = c4 }; - ul.Location = new(u.Location.X + u.Size.X + (int)(5 * Globals.Settings.Scale), + ul.Location = new(u.Location.X + u.Size.X + 5.ScaleInt(), (u.Location.Y + (u.Size.Y / 2) - (ul.PostiveTrueHeight / 2) - ul.Size.Y + ul.TrueHeight), 0); SerBox.Controls.Add(ul); Rectangle setting = new(TextureManager.GetTextureResource("settings.png")) { - Location = new(cs.Size.X - (int)(40 * Globals.Settings.Scale), cs.Size.Y + (int)(Globals.Settings.Scale * 11),0), - Size = new((int)(32 * Globals.Settings.Scale)), + Location = new(cs.Size.X - 40.ScaleInt(), cs.Size.Y + 11.ScaleInt(),0), + Size = new(32.ScaleInt()), Shader = Rectangle.DefaultAlphaShader[Context], BackgroundColor = Color4.Gray, Anchor = ObjectAnchor.Bottom | ObjectAnchor.Left @@ -328,7 +327,7 @@ public class MainScreenWindow : Window Controls.Clear(); BlockDraw = true; Title = "Luski"; - Size = new((int)(1332 * Globals.Settings.Scale), (int)(866 * Globals.Settings.Scale)); + Size = new(1332.ScaleInt(), 866.ScaleInt()); try { CenterWindow(Globals.Settings.Display); @@ -343,7 +342,7 @@ public class MainScreenWindow : Window Controls.Add(ser = new FlowLayout() { BackgroundColor = new(26, 26, 26, 255), - Size = new((int)(68 * Globals.Settings.Scale), (int)(868 * Globals.Settings.Scale)), + Size = new(68.ScaleInt(), 868.ScaleInt()), Anchor = ObjectAnchor.Top | ObjectAnchor.Left | ObjectAnchor.Bottom, Location = new(0,0,0) }); diff --git a/Luski/GUI/StartPage/UI/CreateAccount.cs b/Luski/GUI/StartPage/UI/CreateAccount.cs deleted file mode 100644 index 97d1f71..0000000 --- a/Luski/GUI/StartPage/UI/CreateAccount.cs +++ /dev/null @@ -1,124 +0,0 @@ -using System.Reflection; -using GraphicsManager; -using GraphicsManager.Enums; -using GraphicsManager.Interfaces; -using GraphicsManager.Objects; -using GraphicsManager.Objects.Core; -using Luski.net; -using OpenTK.Graphics.OpenGL4; -using OpenTK.Mathematics; -using OpenTK.Windowing.Common; -using OpenTK.Windowing.GraphicsLibraryFramework; - -namespace Luski.GUI.StartPage.UI; - -public class CreateAccount : UserControl -{ - private RoundedButton button; - private TexturedTextBox Password, UsernameTextbox, DisplaynameTextBox; - private Rectangle rec; - private string? pfp; - - public event Func? ChangeToApp; - - public CreateAccount() - { - Size = new((int)(312 * Globals.Settings.Scale), (int)(545 * Globals.Settings.Scale)); - Rectangle tt; - Controls.Add(tt=new Rectangle(Globals.LuskiTexture) { Size = new((int)(179*Globals.Settings.Scale), (int)(189*Globals.Settings.Scale))}); - Label t; - Controls.Add(t=new Label(Globals.DefaultFont) { Scale = 1.6f * (float)Globals.Settings.Scale, Location = new((int)(199*Globals.Settings.Scale)), Text = "Luski", Color = new(243, 119, 53, 255) }); - t.Location = new((Size.X / 2) - (t.Size.X / 2), t.Location.Y, 0); - tt.Location = new((Size.X / 2) - (tt.Size.X / 2), tt.Location.Y, 0); - Controls.Add(UsernameTextbox = new(Globals.LuskiTexture, Globals.DefaultFont, Globals.DefaultFont) { TextLocation = TextLocation.TrueCenterLeft, WatermarkText = "Username", Location = new((int)(27 * Globals.Settings.Scale),(int)(280 * Globals.Settings.Scale), 0), Size = new((int)(261 * Globals.Settings.Scale),(int)(27 * Globals.Settings.Scale)),}); - Controls.Add(Password = new(Globals.LuskiTexture, Globals.DefaultFont, Globals.DefaultFont) { TextLocation = TextLocation.TrueCenterLeft, WatermarkText = "Password", PasswordChar = '●', Location = new(UsernameTextbox.Location.X,(int)(346 * Globals.Settings.Scale), 0), Size = new(UsernameTextbox.Size.X, UsernameTextbox.Location.X), }); - Controls.Add(DisplaynameTextBox = new(Globals.LuskiTexture, Globals.DefaultFont, Globals.DefaultFont) { TextLocation = TextLocation.TrueCenterLeft, WatermarkText = "Displayname", Location = new(UsernameTextbox.Location.X,(int)(400 * Globals.Settings.Scale), 0), Size = new((int)(196 * Globals.Settings.Scale), UsernameTextbox.Location.X), }); - Controls.Add(button = new(Globals.LuskiTexture, Globals.DefaultFont) { Text = "Create Account", Location = new(UsernameTextbox.Location.X, (int)(456 * Globals.Settings.Scale), 0), Size = new(UsernameTextbox.Size.X, (int)(46 * Globals.Settings.Scale)),}); - Controls.Add(rec = new Rectangle(){ Location = new((int)(228 * Globals.Settings.Scale), (int)(384 * Globals.Settings.Scale), 0), Size = new((int)(50 * Globals.Settings.Scale)), BackgroundColor = Color4.Red}); - Password.KeyPress += PasswordOnKeyPress; - UsernameTextbox.KeyPress += UsernameTextboxOnKeyPress; - button.Clicked += ButtonOnClicked; - DisplaynameTextBox.KeyPress += DisplaynameTextBoxOnKeyPress; - rec.FilesDroped += RecOnFilesDroped; - } - - private Task DisplaynameTextBoxOnKeyPress(KeyboardKeyEventArgs arg) - { - if (arg.Key != Keys.Enter && arg.Key != Keys.KeyPadEnter && arg.Key != Keys.Tab) return Task.CompletedTask; - if (arg.Key == Keys.Tab && arg.Shift) { Password.Focus(); return Task.CompletedTask; } - if (arg.Key == Keys.Enter || arg.Key == Keys.KeyPadEnter) ButtonOnClicked(DisplaynameTextBox); - return Task.CompletedTask; - } - - private Task RecOnFilesDroped(string[] arg) - { - if (!arg[0].ToLower().EndsWith("png")) return Task.CompletedTask; - - pfp = arg[0]; - if (!rec.Textures.Any()) - { - Controls.Remove(rec); - Vector3i oldl = rec.Location; - Vector2i olds = rec.Size; - rec = new Rectangle(Globals.ms.TextureManager.AddTexture(Tools.GetResourceStream(Assembly.GetExecutingAssembly(), - "Luski.Resources.Textures.Status.png"))) { Location = oldl, Size = olds }; - Texture tex = Globals.ms.TextureManager.AddTexture(File.OpenRead(arg[0])); - tex.Unit = TextureUnit.Texture1; - rec.Shader = Rectangle.DefaultAlphaTextureShader[Globals.ms.Context]; - rec.Textures.Add(tex); - Controls.Add(rec); - //rec = new(Globals.ms.TextureManager.AddTexture(File.ReadAllBytes(arg[0]), true)){ Location = new(350, 585), Size = new(100) };Controls.Add(rec); - } - else - { - rec.Textures[1] = Globals.ms.TextureManager.AddTexture(File.OpenRead(arg[0])); - rec.Textures[1].Unit = TextureUnit.Texture1; - } - - Window!.TryDraw(); - return Task.CompletedTask; - } - - private bool tab; - private Task UsernameTextboxOnKeyPress(KeyboardKeyEventArgs arg) - { - if (arg.Key != Keys.Tab) return Task.CompletedTask; - if (arg.Key == Keys.Tab){ Password.Focus(); tab = true;} - return Task.CompletedTask; - } - - private Task PasswordOnKeyPress(KeyboardKeyEventArgs arg) - { - if (tab) - { - tab = false; - return Task.CompletedTask; - }; - if (arg.Key != Keys.Enter && arg.Key != Keys.KeyPadEnter && arg.Key != Keys.Tab) return Task.CompletedTask; - if (arg.Key == Keys.Tab && arg.Shift) { UsernameTextbox.Focus(); return Task.CompletedTask; } - if (arg.Key == Keys.Tab ){ DisplaynameTextBox.Focus(); return Task.CompletedTask; } - return Task.CompletedTask; - } - - private Task ButtonOnClicked(IRenderObject arg) - { - try - { - string[] arr = new string[] - { - UsernameTextbox.Text, - Password.Text, - DisplaynameTextBox.Text, - pfp! - }; - if (arr.Any(s => string.IsNullOrEmpty(s))) return Task.CompletedTask; - Globals.Luski.MainServer.CreateAccount(UsernameTextbox.Text, Password.Text, DisplaynameTextBox.Text, pfp!, CancellationToken.None); - ChangeToApp!.Invoke(); - } - catch (Exception e) - { - Console.WriteLine(e); - } - return Task.CompletedTask; - } -} \ No newline at end of file diff --git a/Luski/GUI/StartPage/UI/Login.cs b/Luski/GUI/StartPage/UI/Login.cs deleted file mode 100644 index 3ab84d9..0000000 --- a/Luski/GUI/StartPage/UI/Login.cs +++ /dev/null @@ -1,84 +0,0 @@ -using GraphicsManager.Enums; -using GraphicsManager.Interfaces; -using GraphicsManager.Objects; -using Luski.net; -using OpenTK.Mathematics; -using OpenTK.Windowing.Common; -using OpenTK.Windowing.GraphicsLibraryFramework; - -namespace Luski.GUI.StartPage.UI; - -public class Login : UserControl -{ - private RoundedButton button; - private TexturedTextBox Password, UsernameTextbox; - private Label ca; - public event Func? ChangeToApp; - public event Func? ChangeToCa; - public Login() - { - Size = new((int)(312 * Globals.Settings.Scale), (int)(545 * Globals.Settings.Scale)); - Rectangle tt; - Controls.Add(tt=new Rectangle(Globals.LuskiTexture) { Size = new((int)(179*Globals.Settings.Scale), (int)(189*Globals.Settings.Scale))}); - Label t; - Controls.Add(t=new Label(Globals.DefaultFont) { Scale = 1.6f, Location = new((int)(199*Globals.Settings.Scale)), Text = "Luski", Color = new(243, 119, 53, 255) }); - t.Location = new((Size.X / 2) - (t.Size.X / 2), t.Location.Y, 0); - tt.Location = new((Size.X / 2) - (tt.Size.X / 2), tt.Location.Y, 0); - Controls.Add(UsernameTextbox = new(Globals.LuskiTexture, Globals.DefaultFont, Globals.DefaultFont) { TextLocation = TextLocation.TrueCenterLeft, WatermarkText = "Username", Location = new((int)(27*Globals.Settings.Scale),(int)(280 * Globals.Settings.Scale), 0), Size = new((int)(261 * Globals.Settings.Scale),(int)(27 * Globals.Settings.Scale))}); - Controls.Add(Password = new(Globals.LuskiTexture, Globals.DefaultFont, Globals.DefaultFont) { TextLocation = TextLocation.TrueCenterLeft, WatermarkText = "Password", PasswordChar = '●', Location = new(UsernameTextbox.Location.X,(int)(365 * Globals.Settings.Scale), 0), Size = UsernameTextbox.Size, }); - Controls.Add(ca = new Label(Globals.DefaultFont) { Location = new(UsernameTextbox.Location.X,(int)(419 * Globals.Settings.Scale), 0), Text = "Create Account" }); - Controls.Add(button = new(Globals.LuskiTexture, Globals.DefaultFont) {Text = "Login", Location = new(UsernameTextbox.Location.X, (int)(455 * Globals.Settings.Scale), 0), Size = new(UsernameTextbox.Size.X,(int)(46 * Globals.Settings.Scale)),}); - Password.KeyPress += PasswordOnKeyPress; - UsernameTextbox.KeyPress += UsernameTextboxOnKeyPress; - button.Clicked += ButtonOnClicked; - ca.Clicked += CaOnClicked; - this.WindowLoaded += OnWindowLoaded; - } - - private Task OnWindowLoaded(IRenderObject arg) - { - UsernameTextbox.Focus(); - return Task.CompletedTask; - } - - private Task CaOnClicked(IRenderObject arg) - { - ChangeToCa!.Invoke(); - return Task.CompletedTask; - } - - private Task UsernameTextboxOnKeyPress(KeyboardKeyEventArgs arg) - { - if (arg.Key != Keys.Tab) return Task.CompletedTask; - Password.Focus(); - return Task.CompletedTask; - } - - private Task PasswordOnKeyPress(KeyboardKeyEventArgs arg) - { - if (arg.Key != Keys.Enter && arg.Key != Keys.KeyPadEnter && arg.Key != Keys.Tab) return Task.CompletedTask; - if (arg.Key == Keys.Tab && arg.Shift) UsernameTextbox.Focus(); - if (arg.Key != Keys.Tab ) ButtonOnClicked(Password); - return Task.CompletedTask; - } - - private Task ButtonOnClicked(IRenderObject arg) - { - try - { - Globals.Luski.MainServer.Login(UsernameTextbox.Text, Password.Text, CancellationToken.None); - ChangeToApp!.Invoke(); - } - catch (Exception e) - { - if (e.Message.Contains("Invaled Login")) - { - BlockDraw = true; - BlockDraw = false; - TryDraw(); - } - else Console.WriteLine(e); - } - return Task.CompletedTask; - } -} diff --git a/Luski/GUI/UpdateWindow.cs b/Luski/GUI/UpdateWindow.cs index a79ff8f..e5d96ea 100644 --- a/Luski/GUI/UpdateWindow.cs +++ b/Luski/GUI/UpdateWindow.cs @@ -33,7 +33,7 @@ public class UpdateWindow : Window public UpdateWindow() : base(Settings) { Label t; - Controls.Add(t = new Label(Globals.DefaultFont) { Scale = 1.2f, Location = new((int)(17.5*Globals.Settings.Scale)), Text = "Luski has detected that your\nclient is on an older version\nfor your branch."}); + Controls.Add(t = new Label(Globals.DefaultFont) { Scale = 1.2f, Location = new(17.5.ScaleInt()), Text = "Luski has detected that your\nclient is on an older version\nfor your branch."}); if (!Globals.Empty(Globals.UpdaterSettings.Updater)) { t.Text += "\n\nWould you like to update?"; @@ -41,12 +41,12 @@ public class UpdateWindow : Window { Text = "Yes", Location = new(t.Location.X, t.Location.Y + t.Size.Y + (int)(t.Scale * t.Font.PixelHeight), 0), - Size = new(t.Size.X, (int)(35.5 * Globals.Settings.Scale)) + Size = new(t.Size.X, 33.5.ScaleInt()) }); Controls.Add(no = new(Globals.LuskiTexture, Globals.DefaultFont) { Text = "No", Location = new(t.Location.X, yes.Location.Y + yes.Size.Y + 20, 0), - Size = new(yes.Size.X, (int)(35.5 * Globals.Settings.Scale)) + Size = new(yes.Size.X, 35.5.ScaleInt()) }); Size = new(t.Location.X + t.Location.X + t.Size.X, no.Location.Y + no.Size.Y + t.Location.X); yes.Clicked += YesOnClicked; @@ -59,7 +59,7 @@ public class UpdateWindow : Window { Text = "Ok", Location = new(t.Location.X, t.Location.Y + t.Size.Y + (int)(t.Scale * t.Font.PixelHeight), 0), - Size = new(t.Size.X, (int)(35.5 * Globals.Settings.Scale)), + Size = new(t.Size.X, 35.5.ScaleInt()), }); Size = new(t.Location.X + t.Location.X + t.Size.X, no.Location.Y + no.Size.Y + t.Location.X); no.Clicked += NoOnClicked; diff --git a/Luski/Globals.cs b/Luski/Globals.cs index ea160e9..61a1d11 100644 --- a/Luski/Globals.cs +++ b/Luski/Globals.cs @@ -18,6 +18,7 @@ using Luski.Shared.PublicServers.V1.Enums; using OpenTK.Graphics.OpenGL4; using OpenTK.Mathematics; using OpenTK.Windowing.Common.Input; +using OpenTK.Windowing.Desktop; namespace Luski; @@ -54,6 +55,33 @@ public static class Globals public static Color4 DodgerBlue = new Color4(30, 144, 255, 255); + public static double GetScale() + { + if (Settings.Scale is not null) return Settings.Scale.Value; + return Monitors.GetMonitorFromWindow(ms).HorizontalScale; + } + public static int ScaleInt(this int i) + { + return (int)(GetScale() * i); + } + public static int ScaleInt(this double i) + { + return (int)(GetScale() * i); + } + public static double ScaleDouble(this int i) + { + return (GetScale() * i); + } + public static double ScaleDouble(this double i) + { + return (GetScale() * i); + } + public static uint ScaleFont(this uint i) + { + if (Globals.Settings.ScaleFonts) return (uint)(GetScale() * i); + return i; + } + public static void PrintParent(IParent par) { void PrintP(int index, IParent p, Vector3i l) diff --git a/Luski/Luski.csproj b/Luski/Luski.csproj index a385c67..4e3f41c 100644 --- a/Luski/Luski.csproj +++ b/Luski/Luski.csproj @@ -21,8 +21,8 @@ - - + + diff --git a/Luski/Program.cs b/Luski/Program.cs index d565157..0bfdccb 100644 --- a/Luski/Program.cs +++ b/Luski/Program.cs @@ -1,10 +1,7 @@ using System.Diagnostics; -using System.Reflection; -using GraphicsManager; using Luski; using Luski.Classes; using Luski.GUI; -using Luski.net; using OpenTK.Windowing.Common.Input; using SixLabors.ImageSharp; using SixLabors.ImageSharp.PixelFormats; diff --git a/Luski/Resources/Textures/Context.png b/Luski/Resources/Textures/Context.png new file mode 100644 index 0000000..1fe1766 Binary files /dev/null and b/Luski/Resources/Textures/Context.png differ diff --git a/Luski/Resources/Textures/ContextBetter.jpg b/Luski/Resources/Textures/ContextBetter.jpg new file mode 100644 index 0000000..4be8620 Binary files /dev/null and b/Luski/Resources/Textures/ContextBetter.jpg differ diff --git a/Luski/Resources/Textures/ContextBetter.png b/Luski/Resources/Textures/ContextBetter.png new file mode 100644 index 0000000..4be8620 Binary files /dev/null and b/Luski/Resources/Textures/ContextBetter.png differ diff --git a/Luski/Resources/Textures/TextboxOutline.png b/Luski/Resources/Textures/TextboxOutline.png new file mode 100644 index 0000000..82edade Binary files /dev/null and b/Luski/Resources/Textures/TextboxOutline.png differ