dev #17

Merged
JacobTech merged 29 commits from dev into main 2024-04-11 15:50:14 -04:00
37 changed files with 2375 additions and 405 deletions
Showing only changes of commit d685737e1e - Show all commits

View File

@ -0,0 +1,48 @@
using System.IO.Compression;
namespace Luski.Classes;
public static class LuskiThemes
{
public static void LoadThemeFromDir(string dir)
{
ThemeStart ts = Globals.GetSettings(Path.Combine(dir, "theme.json"), ThemeStartContext.Default.ThemeStart);
LuskiThemes.LuskiThemeList.Add(ts);
}
public static void LoadThemeFromZip(string ZIP)
{
ZipArchive zf = ZipFile.OpenRead(ZIP);
ZipArchiveEntry? json = zf.GetEntry("theme.json");
ThemeStart ts = Globals.GetSettings(json?.Open()!, ThemeStartContext.Default.ThemeStart);
LuskiThemes.LuskiThemeList.Add(ts);
}
public readonly static ThemeStart Dark = new()
{
Name = "Dark",
Description = "A dark theme but still a bit lit."
};
public static ThemeStart Amoled = new()
{
Name = "Amoled",
Description = "A dark theme that is truly dark."
};
public static ThemeStart Light = new()
{
Name = "Light",
Description = "A light theme for the insane.",
GlobalServerTemplate = new()
{
SelectionColor = new("000000")
}
};
public static List<ThemeStart> LuskiThemeList = new()
{
Light,
Dark,
Amoled
};
}

View File

@ -16,4 +16,10 @@ public class ServerInfo
[JsonInclude]
[JsonPropertyName("is_secure")]
public bool Secure { get; set; } = true;
[JsonInclude]
[JsonPropertyName("pre_encrypt")]
public bool PreGenEncryption { get; set; } = true;
[JsonInclude]
[JsonPropertyName("show_server_messages")]
public bool ShowMessage { get; set; } = false;
}

View File

@ -6,16 +6,7 @@ public class ServerList
{
[JsonInclude]
[JsonPropertyName("servers")]
public ServerInfo[] Server { get; set; } = new []
{
new ServerInfo()
{
Domain = "10.100.0.10:5287",
Version = "v1",
Main = false,
Secure = false
}
};
public ServerInfo[] Servers { get; set; } = Array.Empty<ServerInfo>();
}
[JsonSerializable(typeof(ServerList))]

View File

@ -17,8 +17,19 @@ public class Settings
[JsonPropertyName("loadperchannel")]
public int LoadPerChannel { get; set; } = 50;
[JsonInclude]
[JsonPropertyName("theme")]
public string Theme { get; set; } = "Dark";
[JsonInclude]
[JsonPropertyName("experiments")]
public List<ExperimentJson> Experiments { get; set; } = Array.Empty<ExperimentJson>().ToList();
[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;
}

View File

@ -0,0 +1,32 @@
using System.Text.Json.Serialization;
using Luski.Classes.ThemeSub;
namespace Luski.Classes;
public class ThemeStart
{
[JsonInclude]
[JsonPropertyName("name")]
public string Name { get; set; } = default!;
[JsonInclude]
[JsonPropertyName("description")]
public string Description { get; set; } = default!;
[JsonInclude]
[JsonPropertyName("global_server_template")]
public ServerThemeProperties GlobalServerTemplate { get; set; } = new();
[JsonInclude]
[JsonPropertyName("server_overrides")]
public ServerTheme[] ServerOverrides { get; set; } = Array.Empty<ServerTheme>();
}
[JsonSerializable(typeof(ThemeStart))]
[JsonSourceGenerationOptions(
GenerationMode = JsonSourceGenerationMode.Default,
PropertyNamingPolicy = JsonKnownNamingPolicy.Unspecified,
WriteIndented = true,
DefaultIgnoreCondition = JsonIgnoreCondition.Never)]
internal partial class ThemeStartContext : JsonSerializerContext
{
}

View File

@ -0,0 +1,14 @@
using System.Text.Json.Serialization;
namespace Luski.Classes.ThemeSub;
public class ServerTheme
{
[JsonInclude]
[JsonPropertyName("address")]
public string Address { get; set; } = default!;
[JsonInclude]
[JsonPropertyName("properties")]
public ServerThemeProperties Properties { get; set; } = new();
}

View File

@ -0,0 +1,11 @@
using System.Text.Json.Serialization;
using Luski.net.Structures.Public;
namespace Luski.Classes.ThemeSub;
public class ServerThemeProperties
{
[JsonInclude]
[JsonPropertyName("selection_color")]
public Color SelectionColor { get; set; } = new("FFFFFF");
}

13
Luski/ConsoleLog.cs Normal file
View File

@ -0,0 +1,13 @@
namespace Luski;
[Flags]
public enum ConsoleLog : int
{
None = 0,
BigErrosForOpenGL = 1,
MediumErrosForOpenGL = 2,
LowErrosForOpenGL = 4,
InfoForOpenGL = 8,
DrawFrames = 16,
ShowMissingChar = 32
}

View File

@ -0,0 +1,95 @@
using GraphicsManager.Enums;
using GraphicsManager.Interfaces;
using GraphicsManager.Objects;
using GraphicsManager.Objects.Core;
using Luski.Interfaces;
using OpenTK.Mathematics;
namespace Luski.GUI.MainScreen.UI;
public class AccountButton : UserControl
{
private IServerOverlay SM;
public Label l;
public required Action OnPageLoad;
public AccountButton(string Text, IServerOverlay SM)
:base(Globals.ms.TextureManager.GetTextureResource("RoundedRectangle.png"))
{
this.SM = SM;
base.Size = new((int)(297 * Globals.Settings.Scale), (int)(40* Globals.Settings.Scale));
TextureDisplay = TextureDisplay.HorizontalCenter;
Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context];
l = new Label(Globals.DefaultFont)
{
Text = Text,
Color = Color4.Gray,
IgnoreHover = true,
};
l.Location = new((base.Size.X / 2) - (l.Size.X / 2),
(base.Size.Y / 2) - ((int)l.Font.PixelHeight) + (l.PostiveTrueHeight / 2)
, 0);
Controls.Add(l);
BackgroundColor = new(0, 0, 0, 0);
Clicked += OnClicked;
MouseEnter += o =>
{
if (!Selected)
{
BackgroundColor = new(141, 151, 165, 30);
}
return Task.CompletedTask;
};
MouseLeave += o =>
{
if (!Selected)
{
BackgroundColor = new(0,0,0,0);
}
return Task.CompletedTask;
};
}
private async Task OnClicked(IRenderObject arg)
{
if (!Selected) await ToggleSelected();
}
public bool Selected { get; private set; }
public async Task ToggleSelected()
{
try
{
Color4 bc = new(141,151,165,51), f= Color4.White;
if (Selected)
{
bc = new (0,0,0,0);
f = Color4.Gray;
}
BlockDraw = true;
Selected = !Selected;
if (SM.Selected is not null && SM.Selected != this)
{
await SM.Selected.ToggleSelected();
}
BackgroundColor = bc;
l.Color = f;
if (Selected)
{
SM.Selected = this;
SM.page.Controls.Clear();
OnPageLoad.Invoke();
}
BlockDraw = false;
TryDraw();
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
}

View File

@ -13,7 +13,8 @@ public class AddServerIcon : UserControl
Location = new((int)(18 * Globals.Settings.Scale), (int)(8 * Globals.Settings.Scale), 0),
Size = new((int)(32 * Globals.Settings.Scale)),
Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context],
BackgroundColor = Color4.White
BackgroundColor = Color4.White,
IgnoreHover = true
};
Controls.Add(Button);
BackgroundColor = new(26, 26, 26, 255);

View File

@ -1,15 +1,606 @@
using GraphicsManager.Enums;
using GraphicsManager.Interfaces;
using GraphicsManager.Objects;
using GraphicsManager.Objects.Core;
using Luski.Classes;
using Luski.GUI.MainScreen.UI.LuskiControls;
using Luski.Interfaces;
using Luski.net;
using OpenTK.Graphics.OpenGL4;
using OpenTK.Mathematics;
using OpenTK.Windowing.GraphicsLibraryFramework;
using Rectangle = GraphicsManager.Objects.Rectangle;
namespace Luski.GUI.MainScreen.UI;
public class AddServerOverlay : UserControl
public class AddServerOverlay : UserControl, IServerOverlay
{
private UserControl Form, btn;
private DropDown<VersionDropButton> version;
public AccountButton? Selected { get; set; }
public UserControl page { get; set; }
private TextBox? UserName, Password, DisplayName, tb;
private Rectangle? rec;
public AddServerOverlay()
{
base.Size = Globals.ms.Size;
BackgroundColor = new(0, 0, 0, 130);
Anchor = ObjectAnchor.All;
Form = new(Globals.ms.TextureManager.GetTextureResource("RoundedRectangle.png"))
{
Size = new((int)(350 * Globals.Settings.Scale), (int)(347 * Globals.Settings.Scale)),
BackgroundColor = new(32,32,32,255),
Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context],
TextureDisplay = TextureDisplay.Center
};
Label t;
Form.Controls.Add(t=new Label(Globals.DefaultFont) { Scale = 1.6f, Text = "Add Server", Color = Globals.DodgerBlue });
t.Location = new((Form.Size.X / 2) - (t.Size.X / 2), t.Location.Y, 0);
#region Server Loc
Label? ll = new Label(Globals.DefaultFont)
{
Text = net.API.DefaultVersion,
Color = Color4.DarkGray,
IgnoreHover = true
};
Vector2i s =new((int)(ll.Size.X * 1.6f),(int)(27 * Globals.Settings.Scale));
ll = null;
Rectangle line = new Rectangle()
{
Size = new Vector2i((int)Globals.Settings.Scale),
BackgroundColor = Globals.DodgerBlue
};
tb = new()
{
Location = new((int)(10*Globals.Settings.Scale),(int)(50 * Globals.Settings.Scale), 0),
Size = s,
WatermarkText = "Server Address",
TextLocation = TextLocation.PostiveTureCenterLeft,
AllowMultiLine = false
};
tb.Textures[0] = Globals.ms.TextureManager.GetTextureResource("BadTextbox.png");
tb.KeyPress += args =>
{
Texture t;
Texture good = Globals.ms.TextureManager.GetTextureResource("Textbox.png");
if ((args.Key == Keys.Backspace || args.Key == Keys.Delete) && string.IsNullOrWhiteSpace(tb.Text))
{
t = Globals.ms.TextureManager.GetTextureResource("BadTextbox.png");
}
else
{
t = good;
}
if (tb.Textures[0].handel != t.handel)
{
tb.Textures[0] = t;
if (t.handel == good.handel &&
UserName!.Textures[0].handel == good.handel &&
Password!.Textures[0].handel == good.handel &&
(rec is null || rec.Textures.Count > 1) &&
btn!.Textures[0].handel != good.handel &&
tb.Textures[0].handel == good.handel)
{
if (Selected!.l.Text != "Login")
{
if (DisplayName!.Textures[0].handel == good.handel) btn.Textures[0] = good;
}
else btn.Textures[0] = good;
}
else if (t.handel != good.handel &&
(UserName!.Textures[0].handel != good.handel ||
Password!.Textures[0].handel != good.handel ||
(rec is not null && rec!.Textures.Count == 1) ||
btn!.Textures[0].handel == good.handel ||
tb.Textures[0].handel != good.handel ||
(DisplayName is not null && DisplayName.Textures[0].handel != good.handel)))
{
btn!.Textures[0] = t;
}
Globals.ms.TryDraw();
}
return Task.CompletedTask;
};
tb.Size = new(Form.Size.X - tb.Location.X - tb.Location.X - tb.Location.X - s.X, tb.Size.Y);
Form.Controls.Add(tb);
version = new DropDown<VersionDropButton>(Form.Textures[0], line)
{
DropDownParentOverride = Form,
Size = s,
BackgroundColor = new(255,20,20,255),
TextureDisplay = TextureDisplay.HorizontalCenter,
Shader = Form.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 / 2) - ((int)ll2.Font.PixelHeight) + (ll2.PostiveTrueHeight / 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;
};
#endregion
#region Buttons
AccountButton ca = new AccountButton("Create Account", this)
{
Location = new(tb.Location.X, tb.Location.Y + tb.Location.X + tb.Size.Y, 0),
OnPageLoad = () =>
{
btn.Textures[0] = Globals.ms.TextureManager.GetTextureResource("BadTextbox.png");
page!.Controls.Add(UserName = new()
{
Location = new(0, (int)(10* Globals.Settings.Scale), 0),
Size = new(page.Size.X, (int)(30* Globals.Settings.Scale)),
WatermarkText = "Username",
TextLocation = TextLocation.PostiveTureCenterLeft,
AllowMultiLine = false
});
UserName.Textures[0] = Globals.ms.TextureManager.GetTextureResource("BadTextbox.png");
UserName.KeyPress += args =>
{
Texture t;
Texture good = Globals.ms.TextureManager.GetTextureResource("Textbox.png");
if ((args.Key == Keys.Backspace || args.Key == Keys.Delete || args.Alt || args.Shift || args.Control || args.Key == Keys.Enter || args.Key == Keys.KeyPadEnter || args.Key== Keys.Space) && string.IsNullOrWhiteSpace(UserName.Text))
{
t = Globals.ms.TextureManager.GetTextureResource("BadTextbox.png");
}
else
{
t = good;
}
if (UserName.Textures[0].handel != t.handel)
{
UserName.Textures[0] = t;
if (t.handel == good.handel &&
Password!.Textures[0].handel == good.handel &&
DisplayName!.Textures[0].handel == good.handel &&
rec!.Textures.Count > 1 &&
btn!.Textures[0].handel != good.handel &&
tb.Textures[0].handel == good.handel)
{
btn.Textures[0] = good;
}
else if (t.handel != good.handel &&
(Password!.Textures[0].handel != good.handel ||
DisplayName!.Textures[0].handel != good.handel ||
rec!.Textures.Count == 1 ||
btn!.Textures[0].handel == good.handel || tb.Textures[0].handel != good.handel))
{
btn!.Textures[0] = t;
}
Globals.ms.TryDraw();
}
return Task.CompletedTask;
};
page.Controls.Add(Password = new()
{
Location = new(0, UserName.Location.Y + UserName.Size.Y + UserName.Location.Y + UserName.Location.Y, 0),
Size = new(page.Size.X, UserName.Size.Y),
WatermarkText = "Password",
TextLocation = TextLocation.PostiveTureCenterLeft,
AllowMultiLine = false,
PasswordChar = '●'
});
Password.Textures[0] = UserName.Textures[0];
Password.KeyPress += args =>
{
Texture t;
Texture good = Globals.ms.TextureManager.GetTextureResource("Textbox.png");
if ((args.Key == Keys.Backspace || args.Key == Keys.Delete || args.Alt || args.Shift || args.Control || args.Key == Keys.Enter || args.Key == Keys.KeyPadEnter || args.Key== Keys.Space) && string.IsNullOrWhiteSpace(Password.Text))
{
t = Globals.ms.TextureManager.GetTextureResource("BadTextbox.png");
}
else
{
t = good;
}
if (Password.Textures[0].handel != t.handel)
{
Password.Textures[0] = t;
if (t.handel == good.handel && UserName!.Textures[0].handel == good.handel && DisplayName!.Textures[0].handel == good.handel && rec!.Textures.Count > 1 && btn!.Textures[0].handel != good.handel && tb.Textures[0].handel == good.handel)
{
btn.Textures[0] = good;
}
else if (t.handel != good.handel && (UserName!.Textures[0].handel != good.handel || DisplayName!.Textures[0].handel != good.handel || rec!.Textures.Count == 1 || btn!.Textures[0].handel == good.handel || tb.Textures[0].handel != good.handel))
{
btn!.Textures[0] = t;
}
Globals.ms.TryDraw();
}
return Task.CompletedTask;
};
page.Controls.Add(rec = new(Globals.ms.TextureManager.GetAlphaCircle())
{
Size = new((int)(50 * Globals.Settings.Scale)),
BackgroundColor = Color4.Red,
Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context],
IgnoreHover = false
});
rec.Location = new(page.Size.X - rec.Size.X, page.Size.Y - rec.Size.Y, 0);
page.Controls.Add(DisplayName = new()
{
Location = new(0, Password.Location.Y + Password.Size.Y + UserName.Location.Y + UserName.Location.Y, 0),
Size = new(page.Size.X- tb.Location.X - rec.Size.X, Password.Size.Y ),
WatermarkText = "Display Name",
TextLocation = TextLocation.PostiveTureCenterLeft,
AllowMultiLine = false
});
DisplayName.KeyPress += args =>
{
Texture t;
Texture good = Globals.ms.TextureManager.GetTextureResource("Textbox.png");
if ((args.Key == Keys.Backspace || args.Key == Keys.Delete || args.Alt || args.Shift || args.Control || args.Key == Keys.Enter || args.Key == Keys.KeyPadEnter || args.Key== Keys.Space) &&
string.IsNullOrWhiteSpace(UserName.Text))
{
t = Globals.ms.TextureManager.GetTextureResource("BadTextbox.png");
}
else
{
t = good;
}
if (DisplayName.Textures[0].handel != t.handel)
{
DisplayName.Textures[0] = t;
if (t.handel == good.handel && UserName!.Textures[0].handel == good.handel &&
Password!.Textures[0].handel == good.handel && rec!.Textures.Count > 1 &&
btn!.Textures[0].handel != good.handel && tb.Textures[0].handel == good.handel)
{
btn.Textures[0] = good;
}
else if (t.handel != good.handel && (UserName!.Textures[0].handel != good.handel ||
Password!.Textures[0].handel != good.handel ||
rec!.Textures.Count == 1 ||
btn!.Textures[0].handel == good.handel || tb.Textures[0].handel != good.handel))
{
btn!.Textures[0] = t;
}
Globals.ms.TryDraw();
}
return Task.CompletedTask;
};
rec.FilesDroped += RecOnFilesDroped;
DisplayName.Textures[0] = UserName.Textures[0];
rec.ForceDistanceUpdate(page);
Globals.ms.TryDraw();
Globals.ms.ForceUpdate(new(Size));
}
};
ca.Size = new((Form.Size.X - tb.Location.X - tb.Location.X - (tb.Location.X / 2)) / 2, ca.Size.Y);
ca.l.Location = new((ca.Size.X - ca.l.Size.X) / 2,
(ca.Size.Y / 2) - ((int)ca.l.Font.PixelHeight) + (ca.l.PostiveTrueHeight / 2)
, 0);
ca.l.ForceDistanceUpdate(ca);
Form.Controls.Add(ca);
AccountButton lo = new AccountButton("Login", this)
{
Location = new(ca.Location.X + ca.Size.X + (tb.Location.X / 2),ca.Location.Y, 0),
OnPageLoad = () =>
{
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)),
WatermarkText = "Username",
TextLocation = TextLocation.PostiveTureCenterLeft,
AllowMultiLine = false
});
UserName.Textures[0] = Globals.ms.TextureManager.GetTextureResource("BadTextbox.png");
UserName.KeyPress += args =>
{
Texture t;
Texture good = Globals.ms.TextureManager.GetTextureResource("Textbox.png");
if ((args.Key == Keys.Backspace || args.Key == Keys.Delete || args.Alt || args.Shift || args.Control || args.Key == Keys.Enter || args.Key == Keys.KeyPadEnter || args.Key== Keys.Space) && string.IsNullOrWhiteSpace(UserName.Text))
{
t = Globals.ms.TextureManager.GetTextureResource("BadTextbox.png");
}
else
{
t = good;
}
if (UserName.Textures[0].handel != t.handel)
{
UserName.Textures[0] = t;
if (t.handel == good.handel &&
Password!.Textures[0].handel == good.handel &&
btn!.Textures[0].handel != good.handel &&
tb.Textures[0].handel == good.handel)
{
btn.Textures[0] = good;
}
else if (t.handel != good.handel &&
(Password!.Textures[0].handel != good.handel ||
btn!.Textures[0].handel == good.handel || tb.Textures[0].handel != good.handel))
{
btn!.Textures[0] = t;
}
Globals.ms.TryDraw();
}
return Task.CompletedTask;
};
page.Controls.Add(Password = new()
{
Location = new(0, UserName.Location.Y + UserName.Size.Y + UserName.Location.Y + UserName.Location.Y, 0),
Size = new(page.Size.X, UserName.Size.Y),
WatermarkText = "Password",
TextLocation = TextLocation.PostiveTureCenterLeft,
AllowMultiLine = false,
PasswordChar = '●'
});
Password.Textures[0] = UserName.Textures[0];
Password.KeyPress += args =>
{
Texture t;
Texture good = Globals.ms.TextureManager.GetTextureResource("Textbox.png");
if ((args.Key == Keys.Backspace || args.Key == Keys.Delete || args.Alt || args.Shift || args.Control || args.Key == Keys.Enter || args.Key == Keys.KeyPadEnter || args.Key== Keys.Space) &&
string.IsNullOrWhiteSpace(Password.Text))
{
t = Globals.ms.TextureManager.GetTextureResource("BadTextbox.png");
}
else
{
t = good;
}
if (Password.Textures[0].handel != t.handel)
{
Password.Textures[0] = t;
if (t.handel == good.handel &&
UserName!.Textures[0].handel == good.handel &&
btn!.Textures[0].handel != good.handel &&
tb.Textures[0].handel == good.handel)
{
btn.Textures[0] = good;
}
else if (t.handel != good.handel &&
(UserName!.Textures[0].handel != good.handel ||
btn!.Textures[0].handel == good.handel || tb.Textures[0].handel != good.handel))
{
btn!.Textures[0] = t;
}
Globals.ms.TryDraw();
}
return Task.CompletedTask;
};
DisplayName = null!;
rec = null!;
}
};
lo.Size = ca.Size;
lo.l.Location = new((lo.Size.X / 2) - (lo.l.Size.X / 2),
(lo.Size.Y / 2) - ((int)lo.l.Font.PixelHeight) + (lo.l.PostiveTrueHeight / 2)
, 0);
lo.l.ForceDistanceUpdate(lo);
Form.Controls.Add(lo);
#endregion
Form.Controls.Add(version);
page = new()
{
Location = new(tb.Location.X, ca.Location.Y + ca.Size.Y + tb.Location.X, 0),
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"))
{
Location = new(page.Location.X, page.Location.Y + page.Size.Y + tb.Location.X, 0),
Size = new(page.Size.X, ca.Size.Y),
TextureDisplay = TextureDisplay.Center
};
_ = ca.ToggleSelected();
Label sub = new(Globals.DefaultFont)
{
Text = "Submit",
IgnoreHover = true
};
sub.Location = new((btn.Size.X / 2) - (sub.Size.X / 2),
(btn.Size.Y / 2) - ((int)sub.Font.PixelHeight) + (sub.PostiveTrueHeight / 2)
, 0);
sub.ForceDistanceUpdate(btn);
btn.Controls.Add(sub);
Form.Controls.Add(btn);
Form.Location = new((base.Size.X - Form.Size.X) / 2, (base.Size.Y - Form.Size.Y) / 2, 0);
Controls.Add(Form);
btn.Clicked += BtnOnClicked;
}
private async Task BtnOnClicked(IRenderObject arg)
{
if (btn.Textures[0].handel == Globals.ms.TextureManager.GetTextureResource("BadTextbox.png").handel)
return;
bool s = true;
string d = tb!.Text;
if (d.Contains("://"))
{
string[] a = d.Split("://");
d = a[1];
if (a[0] == "http") s = false;
}
ServerInfo si = new()
{
Domain = d,
Version = version.SelectedOption.l.Text,
Main = false,
Secure = s
};
bool g = await Globals.Luski.TryGetPublicServer(out PublicServer ps, si.Domain, si.Version, si.Secure);
if (!g)
{
Texture b = Globals.ms.TextureManager.GetTextureResource("BadTextbox.png");
tb!.Textures[0] = b;
btn.Textures[0] = b;
Globals.ms.TryDraw();
return;
}
if (g && !ps.IsLogedIn)
{
if (DisplayName is null)
{
g = await ps.Login(UserName!.Text, Password!.Text, CancellationToken.None);
}
else
{
g = await ps.CreateAccount(UserName!.Text, Password!.Text, DisplayName.Text, pfp,
CancellationToken.None);
}
}
if (!g)
{
Texture b = Globals.ms.TextureManager.GetTextureResource("BadTextbox.png");
UserName!.Textures[0] = b;
Password!.Textures[0] = b;
btn.Textures[0] = b;
Globals.ms.TryDraw();
return;
}
var l = Globals.ServerList.Servers.ToList();
l.Add(si);
Globals.ServerList.Servers = l.ToArray();
Globals.ServerList.SaveSettings(Path.Combine(Globals.LuskiPath, "Servers.json"), ServerListContext.Default.ServerList);
ServerIcon<PublicServer> ss = new ServerIcon<PublicServer>(ps);
Globals.ms.ser.Controls.Insert(Globals.ms.ser.Controls.Length - 1, ss);
await ss.LoadServer();
Globals.ms.Controls.Remove(this);
Globals.ms.ForceUpdate(new(Size));
Globals.ms.TryDraw();
}
private Task VersionOnOptionSelected(VersionDropButton arg)
{
return Task.CompletedTask;
}
private Task VersionOnOpenStatusChanged(bool arg)
{
return Task.CompletedTask;
}
private string pfp = "";
private Task RecOnFilesDroped(string[] arg)
{
Console.WriteLine(arg[0]);
if (!arg[0].ToLower().EndsWith("png")) return Task.CompletedTask;
pfp = arg[0];
if (rec!.Textures.Count() ==1 )
{
Texture good = Globals.ms.TextureManager.GetTextureResource("Textbox.png");
if (UserName!.Textures[0].handel == good.handel &&
Password!.Textures[0].handel == good.handel &&
btn!.Textures[0].handel != good.handel && tb.Textures[0].handel == good.handel)
{
if (DisplayName is not null)
{
if (Password!.Textures[0].handel == good.handel) btn.Textures[0] = good;
}
else btn.Textures[0] = good;
}
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);
}
else
{
rec.Textures[1] = Globals.ms.TextureManager.AddTexture(File.OpenRead(arg[0]));
rec.Textures[1].Unit = TextureUnit.Texture1;
}
Window!.TryDraw();
return Task.CompletedTask;
}
}

View File

@ -0,0 +1,52 @@
using GraphicsManager.Enums;
using GraphicsManager.Objects;
using GraphicsManager.Objects.Core;
using OpenTK.Graphics.ES20;
using OpenTK.Mathematics;
namespace Luski.GUI.MainScreen.UI;
public class LuskiContextMenu : BetterContextMenu
{
public LuskiContextMenu()
:base(Globals.ms.TextureManager.GetTextureResource("Context.png"))
{
Margins = new((int)(5 * Globals.Settings.Scale));
TextureDisplay = TextureDisplay.Center;
SpaceBetweenObjects = (int)(8 * Globals.Settings.Scale);
}
public Label AddLabel(string text, Color4 color)
{
return AddLabel(Globals.DefaultFont, text, color);
}
public Label AddLabel(string text)
{
Label l = AddLabel(Globals.DefaultFont, text, Color4.Gray);
l.Clicked += o =>
{
HideContext(Window!);
TryDraw();
return Task.CompletedTask;
};
l.MouseEnter += o =>
{
l.Color = Color4.White;
TryDraw();
return Task.CompletedTask;
};
l.MouseLeave += o =>
{
l.Color = Color4.Gray;
TryDraw();
return Task.CompletedTask;
};
return l;
}
public new void AddLine()
{
AddLine(Color4.White, (int)Globals.Settings.Scale);
}
}

View File

@ -88,6 +88,23 @@ public class DropDown<TSelection> : UserControl where TSelection : DropDownOptio
SelectedOption = defaultOption;
}
public DropDown(Texture t, IRenderObject spacer)
:base(t)
{
ip = this;
TextureDisplay = TextureDisplay.HorizontalCenter;
DropDownContainer = new()
{
Visible = false,
Anchor = ObjectAnchor.Left | ObjectAnchor.Top | ObjectAnchor.Right
};
Clicked += OnClicked;
WindowLoaded += OnWindowLoaded;
DropDownContainer.Size = new(base.Size.X, DropDownContainer.Size.Y + spacer.Size.Y);
DropDownContainer.Controls.Add(spacer);
Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context];
}
public TSelection SelectedOption { get; private set; }
private Task OnWindowLoaded(IRenderObject arg)
@ -145,23 +162,31 @@ public class DropDown<TSelection> : UserControl where TSelection : DropDownOptio
private Task OptionOnClicked(IRenderObject arg)
{
TSelection but =(arg as TSelection)!;
if (but == SelectedOption)
try
{
TSelection but =(arg as TSelection)!;
if (but == SelectedOption)
{
IsOpen = false;
DropDownContainer.Visible = IsOpen;
if (OpenStatusChanged is not null) OpenStatusChanged.Invoke(IsOpen);
TryDraw();
return Task.CompletedTask;
}
SelectedOption = but;
Controls.Clear();
SelectedOption.LoadDisplay.Invoke();
IsOpen = false;
DropDownContainer.Visible = IsOpen;
if (OpenStatusChanged is not null) OpenStatusChanged.Invoke(IsOpen);
if (OptionSelected is not null) OptionSelected.Invoke(SelectedOption);
TryDraw();
return Task.CompletedTask;
}
SelectedOption = but;
Controls.Clear();
SelectedOption.LoadDisplay.Invoke();
IsOpen = false;
DropDownContainer.Visible = IsOpen;
if (OpenStatusChanged is not null) OpenStatusChanged.Invoke(IsOpen);
if (OptionSelected is not null) OptionSelected.Invoke(SelectedOption);
TryDraw();
catch (Exception e)
{
Console.WriteLine(e);
}
return Task.CompletedTask;
}
}

View File

@ -17,8 +17,7 @@ public class TextBox : UserControl
public TextBox()
:base(Globals.ms.TextureManager.GetTextureResource("Textbox.png"))
{
TextureDisplay = TextureDisplay.HorizontalCenter;
Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context];
TextureDisplay = TextureDisplay.Center;
_label = new Label(Globals.DefaultFont)
{
HoverMouse = MouseCursor.IBeam,
@ -26,10 +25,12 @@ public class TextBox : UserControl
};
_watermark = new(_label.Font)
{
Text = "Text Box",
Color = new(128, 128, 128, 255),
HoverMouse = MouseCursor.IBeam,
IgnoreHover = true
};
Controls.Add(_label);
Controls.Add(_watermark);
}
@ -74,7 +75,37 @@ public class TextBox : UserControl
public char? PasswordChar { get => _label.PasswordChar; set => _label.PasswordChar = value; }
public TextLocation TextLocation { get; set; } = TextLocation.PostiveTureCenterLeft;
private TextLocation tl = TextLocation.PxLeft;
public TextLocation TextLocation
{
get => tl;
set
{
tl = value;
if (!string.IsNullOrWhiteSpace(Text))
{
_label.Location = value switch
{
TextLocation.PostiveTureCenterLeft => new((int)(10 * Globals.Settings.Scale),
((Size.Y - _label.PostiveTrueHeight) / 2) - _label.Size.Y + _label.TrueHeight, Location.Z),
_ => _label.Location
};
_watermark.Location = _label.Location;
}
else
{
_watermark.Location = value switch
{
TextLocation.PostiveTureCenterLeft => new((int)(10 * Globals.Settings.Scale),
((Size.Y - _watermark.PostiveTrueHeight) / 2) - _watermark.Size.Y + _watermark.TrueHeight, Location.Z),
_ => _watermark.Location
};
_label.Location = _watermark.Location;
}
}
}
public override bool Visible
{
@ -111,6 +142,8 @@ public class TextBox : UserControl
public Color4 TextColor { get => _label.Color; set => _label.Color = value; }
public Color4 WatermarkColor { get => _watermark.Color; set => _watermark.Color = value; }
public bool AllowMultiLine { get; set; } = true;
public string Text
{
get => _label.Text;
@ -127,7 +160,7 @@ public class TextBox : UserControl
_label.Visible = true;
_label.Location = TextLocation switch
{
TextLocation.PostiveTureCenterLeft => new(5, ((Size.Y - _label.PostiveTrueHeight) / 2) - _label.Size.Y + _label.TrueHeight, Location.Z),
TextLocation.PostiveTureCenterLeft => new((int)(10*Globals.Settings.Scale), ((Size.Y - _label.PostiveTrueHeight) / 2) - _label.Size.Y + _label.TrueHeight, Location.Z),
_ => _label.Location
};
/*
@ -153,6 +186,11 @@ public class TextBox : UserControl
if (!_watermark.Visible)
{
_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),
_ => _watermark.Location
};
/*
_watermark.Location = TextLocation switch
{
@ -178,6 +216,9 @@ public class TextBox : UserControl
}
}
public event Func<Task>? OnNewLine;
public event Func<Task>? OnRemoveLine;
private void Window_KeyDown(KeyboardKeyEventArgs obj)
{
if (!use) return;
@ -185,8 +226,33 @@ public class TextBox : UserControl
if (obj.Key == Keys.Backspace || obj.Key == Keys.Delete)
{
if (!(Text.Length > 0)) return;
if (Text[Text.Length - 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);
}
if (obj.Key == Keys.Enter)
{
if (AllowMultiLine && obj.Shift)
{
BlockDraw = true;
Size = new(Size.X, Size.Y + (int)_label.Font.PixelHeight);
if (OnNewLine is not null) OnNewLine.Invoke().Wait();
BlockDraw = false;
Text += '\n';
}
else
{
}
}
if (obj.Key == Keys.V && obj.Control && Window is not null) Text += Window.ClipboardString;
if (KeyPress is not null) _ = KeyPress.Invoke(obj);
}

View File

@ -0,0 +1,39 @@
using GraphicsManager.Enums;
using GraphicsManager.Objects;
using OpenTK.Mathematics;
namespace Luski.GUI.MainScreen.UI.LuskiControls;
public class VersionDropButton : DropDownOption
{
public Label l;
public VersionDropButton(Vector2i size, string v)
:base(Globals.ms.TextureManager.GetTextureResource("RoundedRectangle.png"))
{
base.Size = size;
TextureDisplay = TextureDisplay.HorizontalCenter;
Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context];
l = new Label(Globals.DefaultFont)
{
Text = v,
Color = Color4.DarkGray,
IgnoreHover = true
};
l.Location = new((base.Size.X / 2) - (l.Size.X / 2),
(base.Size.Y / 2) - ((int)l.Font.PixelHeight) + (l.PostiveTrueHeight / 2)
, 0);
Controls.Add(l);
BackgroundColor = new(0, 0, 0, 0);
MouseEnter += o =>
{
BackgroundColor = new(141, 151, 165, 30);
return Task.CompletedTask;
};
MouseLeave += o =>
{
BackgroundColor = new(0,0,0,0);
return Task.CompletedTask;
};
}
}

View File

@ -0,0 +1,78 @@
using GraphicsManager.Enums;
using GraphicsManager.Interfaces;
using GraphicsManager.Objects;
using Luski.GUI.MainScreen.Interfaces;
using Luski.GUI.MainScreen.UI.LuskiControls;
using Luski.net.Structures.Public;
namespace Luski.GUI.MainScreen.UI.PublicServers;
public class AddChannel : UserControl
{
private TextBox cn, cd;
private UserControl btn;
private SocketCategory Cat;
private IChannelAdder CA;
public AddChannel(IChannelAdder CA, SocketCategory cat)
{
this.CA = CA;
Cat = cat;
base.Size = Globals.ms.Size;
base.BackgroundColor = new(0, 0, 0, 130);
Anchor = ObjectAnchor.All;
FlowLayout fl = new()
{
SpaceBetweenObjects = (int)(5 * Globals.Settings.Scale),
Size = new((int)(350 * Globals.Settings.Scale), (int)(220 * Globals.Settings.Scale)),
BackgroundColor = new(32,32,32,255),
//Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context],
//TextureDisplay = TextureDisplay.Center
};
fl.Location = new((base.Size.X - fl.Size.X) / 2, (base.Size.Y - fl.Size.Y) / 2, 0);
fl.Controls.Add(new Label(Globals.DefaultFont) {Text = "Channel Name"});
fl.Controls.Add(cn =new TextBox()
{
WatermarkText = "Channel Name",
Size = new((int)(34 * Globals.Settings.Scale)),
Anchor = ObjectAnchor.Bottom | ObjectAnchor.Left | ObjectAnchor.Right,
TextLocation = TextLocation.PostiveTureCenterLeft
});
fl.Controls.Add(new Label(Globals.DefaultFont) {Text = "Channel Description"});
fl.Controls.Add(cd =new TextBox()
{
WatermarkText = "Channel Description",
Size = new((int)(34 * Globals.Settings.Scale)),
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)),
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 / 2) - ((int)sub.Font.PixelHeight) + (sub.PostiveTrueHeight / 2)
, 0);
btn.Clicked += BtnOnClicked;
sub.ForceDistanceUpdate(btn);
btn.Controls.Add(sub);
fl.ForceDistanceUpdate(this);
Controls.Add(fl);
Anchor = ObjectAnchor.All;
}
private async Task BtnOnClicked(IRenderObject arg)
{
SocketChannel chan = await Cat.Server.MakeChannel(Cat, cn.Text, cd.Text);
await CA.AddChannel(chan);
Globals.ms.Controls.Remove(this);
Globals.ms.DrawFrame();
}
}

View File

@ -2,7 +2,9 @@ using GraphicsManager.Enums;
using GraphicsManager.Interfaces;
using GraphicsManager.Objects;
using GraphicsManager.Objects.Core;
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;
@ -49,7 +51,31 @@ public class Channel : UserControl
ChannelName.Location = new((int)(40 * Globals.Settings.Scale),
(base.Size.Y / 2) - ((int)ChannelName.Font.PixelHeight) + (ChannelName.PostiveTrueHeight / 2)
, 0);
ContextMenu = new((int)(150 * Globals.Settings.Scale));
base.HoverMouse = MouseCursor.Hand;
}
private Channel(ChannelSelector cs, SocketChannel chan)
: base(Globals.ms.TextureManager.GetTextureResource("RoundedRectangle.png"))
{
CS = cs;
CurrentChannel = chan;
base.Size = new((int)(307 * Globals.Settings.Scale), (int)(40* Globals.Settings.Scale));
TextureDisplay = TextureDisplay.HorizontalCenter;
Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context];
int i = (int)(4 * Globals.Settings.Scale);
GC.Collect();
ChannelName = new Label(Globals.DefaultFont)
{
Text = chan.Name,
Color = chan.Color.ToColor4(),
IgnoreHover = true
};
Controls.Add(ChannelName);
Clicked += AllOnClicked;
ChannelName.Location = new(i,
(base.Size.Y / 2) - ((int)ChannelName.Font.PixelHeight) + (ChannelName.PostiveTrueHeight / 2)
, 0);
base.HoverMouse = MouseCursor.Hand;
}
@ -76,22 +102,20 @@ public class Channel : UserControl
Task? mm = null;
if (Selected)
{
CS.Selected = this;
IReadOnlyList<SocketMessage> m;
m = await CurrentChannel.GetMessages(CancellationToken.None, Globals.Settings.LoadPerChannel);
//m = Array.Empty<SocketMessage>();
Globals.ms.pc.ClearChat();
await Globals.ms.pc.LoadChannel(CurrentChannel);
mm = Globals.ms.pc.AddMessages(m);
if (m.Count > 0)Globals.ms.pc.MessageFlow.ScrollToBottom();
}
if (mm is not null)
{
Console.WriteLine("Waiting");
Task.WaitAll(mm);
Globals.ms.pc.MessageFlow.ForceScrollUpdate();
Globals.ms.pc.MessageFlow.ScrollToBottom();
Console.WriteLine("Done");
}
BlockDraw = false;
@ -107,7 +131,9 @@ public class Channel : UserControl
public static async Task<Channel> MakeChannel(SocketChannel chan, ChannelSelector cs)
{
Channel c = new(await chan.GetPicture(CancellationToken.None), cs, chan);
Channel c;
if (chan.PictureType == PictureType.none) c = new(cs, chan);
else c = new(await chan.GetPicture(CancellationToken.None), cs, chan);
return c;
}

View File

@ -1,7 +1,10 @@
using System.Runtime.CompilerServices;
using GraphicsManager.Enums;
using GraphicsManager.Interfaces;
using GraphicsManager.Objects;
using Luski.GUI.MainScreen.Interfaces;
using Luski.net.Structures.Public;
using Luski.Shared.PublicServers.V1.Enums;
using OpenTK.Mathematics;
namespace Luski.GUI.MainScreen.UI.PublicServers;
@ -13,9 +16,38 @@ public class ChannelSelector : FlowLayout, IChannelAdder
private readonly List<Channel> LoadedChannels = new();
public Channel? Selected;
public ChannelSelector(SocketCategory Cat)
private ChannelSelector(SocketCategory Cat)
{
CurrentCategory = Cat;
Cat.Server.MessageReceived += ServerOnMessageReceived;
}
public static async Task<ChannelSelector> MakeSelector(SocketCategory Cat)
{
ChannelSelector cs = new(Cat);
if (await Cat.Server.User.HasAccessToCategory(Cat, ServerPermission.CreateChannels))
{
LuskiContextMenu lcm = new();
Label l = lcm.AddLabel("Create Channel");
l.Clicked += cs.LOnClicked;
cs.ContextMenu = lcm;
}
return cs;
}
private async Task LOnClicked(IRenderObject arg)
{
Globals.ms.Controls.Add(new AddChannel(this, CurrentCategory));
TryDraw();
}
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);
}
public async Task Load(SocketChannel currentchannel, List<SocketCategory> parents)
@ -57,6 +89,7 @@ public class ChannelSelector : FlowLayout, IChannelAdder
Globals.ms.DrawFrame();
}
}
}
public async Task<Channel> AddChannel(SocketChannel chan)

View File

@ -16,8 +16,7 @@ namespace Luski.GUI.MainScreen.UI.PublicServers;
public class ChatMessage : UserControl
{
//readonly int padding = 10;
private static Font TimeFont;// = Font.MakeFontFromSystem(13);
//private static Font TimeFont;// = Font.MakeFontFromSystem(13);
private SocketMessage Msg { get; }
private SocketChannel ch { get; }
@ -29,20 +28,18 @@ public class ChatMessage : UserControl
private readonly double HorPadding = (12 * Globals.Settings.Scale),
VerticalPadding = (12 * Globals.Settings.Scale);
private static Dictionary<MainSocketRemoteUser, ContextMenu> Menues = new();
private static Dictionary<MainSocketRemoteUser, List<ChatMessage>> Messages = new();
public static async Task<ChatMessage> MakeChatMessage(PublicChat p, SocketMessage message)
{
IUser auth = await message.GetAuthor(CancellationToken.None);
Role[] ra = await ((SocketUser)auth).GetRoles();
Color c = ra[0].Color;
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.GetIcon(), c4);
return new ChatMessage(p, message, await message.GetParent(CancellationToken.None), auth, await auth.MakeRct(new((int)(38 * Globals.Settings.Scale)), message.IsProfile), c4);
}
private ChatMessage(PublicChat p, SocketMessage message, SocketChannel chan, IUser Author, Texture UserIcon, Color4 UserNameColor)
private ChatMessage(PublicChat p, SocketMessage message, SocketChannel chan, IUser Author, IRenderObject UserIcon, Color4 UserNameColor)
{
pc = p;
Label label1;
@ -53,6 +50,7 @@ public class ChatMessage : UserControl
Anchor = ObjectAnchor.Left | ObjectAnchor.Right;
DateTime time = chan.Epoch.AddMilliseconds(Msg.ID >> 20).ToLocalTime();
string timestr;
if (time.Date == DateTime.Now.ToLocalTime().Date)
{
@ -67,16 +65,12 @@ public class ChatMessage : UserControl
timestr = $"{time:M/dd/yyyy h:mm tt}";
}
Rectangle r = new Rectangle(Globals.ms.TextureManager.AddTexture(Tools.GetResourceStream(Assembly.GetExecutingAssembly(),
"Luski.Resources.Textures.Status.png"))) { Location = new((int)(10 * Globals.Settings.Scale), (int)(2 * Globals.Settings.Scale), 0), Size = new((int)(38 * Globals.Settings.Scale)) };
//UserIcon.Unit = TextureUnit.Texture1;
r.Shader = Rectangle.DefaultAlphaTextureShader[Globals.ms.Context];
r.Textures.Add(UserIcon);
Controls.Add(r);
UserIcon.Location = new((int)(10 * Globals.Settings.Scale), (int)(2 * Globals.Settings.Scale), 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)(r.Location.Y + (r.Size.Y / 2) - (label1.Font.CurrentFont.Fonts[0].Size.Metrics.NominalHeight / 2) - label1.Size.Y + label1.Font.PixelHeight), 0);
(int)(UserIcon.Location.Y + (UserIcon.Size.Y / 2) - (label1.Font.CurrentFonts[0].Face.Size.Metrics.NominalHeight / 2) - label1.Size.Y + label1.Font.PixelHeight), 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});
@ -173,6 +167,7 @@ public class ChatMessage : UserControl
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));
BlockDraw = false;
//if (Parent is not null) Globals.ms.pc.MessageFlow.ReportSizeUpdate(this);
TryDraw();
}

View File

@ -5,7 +5,9 @@ using GraphicsManager.Objects;
using Luski.GUI.MainScreen.UI.LuskiControls;
using Luski.net.Structures.Public;
using OpenTK.Mathematics;
using OpenTK.Windowing.Common;
using OpenTK.Windowing.Common.Input;
using OpenTK.Windowing.GraphicsLibraryFramework;
namespace Luski.GUI.MainScreen.UI.PublicServers;
@ -18,12 +20,13 @@ public class PublicChat : UserControl
private SocketChannel? Channel;
UserControl titlecon;
private Rectangle? UserCon;
private SocketMessage? first;
public PublicChat()
{
base.Size = new((int)(980 * Globals.Settings.Scale), (int)(866 * Globals.Settings.Scale));
BackgroundColor = new(50, 50, 50, 255);
BackgroundColor = new(40,40,40,255);
Anchor = ObjectAnchor.All;
Controls.Add(MessageFlow = new()
{
@ -33,12 +36,13 @@ public class PublicChat : UserControl
Anchor = ObjectAnchor.All,
HScrollPixels = Globals.Settings.PerScrollPixels,
});
MessageFlow.FlowUpdate += MessageFlowOnFlowUpdate;
Controls.Add(titlecon = new UserControl()
{
Anchor = ObjectAnchor.Left | ObjectAnchor.Top | ObjectAnchor.Right,
Size = new((int)(980 * Globals.Settings.Scale), (int)(48 * Globals.Settings.Scale)),
BackgroundColor = BackgroundColor
BackgroundColor = new(50,50,50,255),
});
if (LuskiExperiments.ServerExperiments.MemberList.IsEnabled())
{
@ -77,13 +81,64 @@ public class PublicChat : UserControl
Anchor = ObjectAnchor.Bottom | ObjectAnchor.Left | ObjectAnchor.Right,
HoverMouse = MouseCursor.IBeam,
//Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context],
BackgroundColor = Color4.Red
//Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context],
BackgroundColor = Color4.Red,
TextLocation = TextLocation.PostiveTureCenterLeft
});
tb.KeyPress += TbOnKeyPress;
tb.OnRemoveLine += TbOnOnRemoveLine;
tb.OnNewLine += TbOnOnNewLine;
tb.ForceDistanceUpdate(this);
//tb.KeyPress += TbOnKeyPress;
//Globals.Luski.MainServer.MessageReceived += LuskiOnMessageReceived;
}
private async Task MessageFlowOnFlowUpdate(bool arg1, uint arg2, uint arg3)
{
if (!loadingm && arg1 && arg3 == 0 && (arg2 != 0 || MessageFlow.MaxScrollValue == 0))
{
loadingm = true;
var messages = await Channel!.GetMessages(CancellationToken.None, first!, Globals.Settings.LoadPerChannel);
if (messages.Count == 0) return;
index = 0;
fakeIndex = false;
lastmIndex = null;
lastUserIndex = null;
LastChatMessageIndex = null;
await AddMessagesIndex(messages);
MessageFlow.ForceScrollUpdate();
first = messages.Last();
if (Globals.Settings.LoadPerChannel == messages.Count)loadingm = false;
}
}
private async Task TbOnKeyPress(KeyboardKeyEventArgs arg)
{
if (arg.Key == Keys.Enter && !arg.Shift)
{
await Channel!.SendMessage(tb.Text);
tb.Text = string.Empty;
}
}
private Task TbOnOnRemoveLine()
{
BlockDraw = true;
tb.Location = new(tb.Location.X, tb.Location.Y + (int)tb.Font.PixelHeight, 0);
MessageFlow.Size = new(MessageFlow.Size.X, MessageFlow.Size.Y + (int)tb.Font.PixelHeight);
BlockDraw = false;
return Task.CompletedTask;
}
private Task TbOnOnNewLine()
{
BlockDraw = true;
tb.Location = new(tb.Location.X, tb.Location.Y - (int)tb.Font.PixelHeight, 0);
MessageFlow.Size = new(MessageFlow.Size.X, MessageFlow.Size.Y - (int)tb.Font.PixelHeight);
BlockDraw = false;
return Task.CompletedTask;
}
private Task MemberListOnEventToggled(bool arg)
{
if (arg)
@ -110,7 +165,14 @@ public class PublicChat : UserControl
private SocketMessage? lastm;
private long? lastUser;
private ChatMessage? LastChatMessage;
private bool fake = false;
public ChatMessage? LastChatMessage;
private SocketMessage? lastmIndex;
private long? lastUserIndex;
private bool fakeIndex = false;
public ChatMessage? LastChatMessageIndex;
private bool loadingm = false;
public async Task LoadChannel(SocketChannel channel)
{
@ -123,14 +185,17 @@ public class PublicChat : UserControl
Window.Title = $"{channel.Name} | {channel.Server.Name} - Luski";
}
tb.WatermarkText = $"Message {channel.Name}";
tb.Text = "";
}
public void ClearChat()
{
MessageFlow.Controls.Clear();
MessageFlow.ScrollUpdatesInterval = 33;
lastm = null;
lastUser = null;
LastChatMessage = null;
first = null;
}
public async Task AddMessages(IEnumerable<SocketMessage> messages, bool reverse = true)
@ -153,19 +218,33 @@ public class PublicChat : UserControl
MessageFlow.BlockDraw = false;
}
public async Task AddMessage(SocketMessage Message)
public async Task AddMessagesIndex(IEnumerable<SocketMessage> messages)
{
MessageFlow.BlockDraw = true;
index = 0;
foreach (SocketMessage message in messages.Reverse())
{
await AddMessageIndex(message);
}
MessageFlow.BlockDraw = false;
}
public async Task AddMessage(SocketMessage Message, bool scrool = false)
{
if (first is null) first = Message;
bool hasbeentenmin = false;
if (lastm is not null)
hasbeentenmin =
Channel!.Epoch.AddMilliseconds(lastm.ID >> 22).ToLocalTime().AddMinutes(10) <
Channel!.Epoch.AddMilliseconds(Message.ID >> 22).ToLocalTime();
lastm = Message;
if (lastUser is null || lastUser != Message.AuthorID || hasbeentenmin)
if (lastUser is null || lastUser != Message.AuthorID || hasbeentenmin || fake != Message.IsProfile)
{
if (Window is null || !Globals.ms.InvokeRequired)
{
MessageFlow.Controls.Add(LastChatMessage = await ChatMessage.MakeChatMessage(this, Message));
if (scrool) MessageFlow.ScrollToBottom();
}
else
{
@ -173,6 +252,7 @@ public class PublicChat : UserControl
Globals.ms.Invoke(() =>
{
MessageFlow.Controls.Add(LastChatMessage);
if (scrool) MessageFlow.ScrollToBottom();
Window.TryDraw();
});
}
@ -182,17 +262,68 @@ public class PublicChat : UserControl
if (Window is null || !Globals.ms.InvokeRequired)
{
await LastChatMessage!.AddMessage(Message);
if (scrool) MessageFlow.ScrollToBottom();
}
else
{
Globals.ms.Invoke(() =>
{
LastChatMessage!.AddMessage(Message);
if (scrool) MessageFlow.ScrollToBottom();
Window!.TryDraw();
});
}
}
fake = Message.IsProfile;
lastUser = Message.AuthorID;
}
private int index = 0;
public async Task AddMessageIndex(SocketMessage Message)
{
bool hasbeentenmin = false;
if (lastmIndex is not null)
hasbeentenmin =
Channel!.Epoch.AddMilliseconds(lastmIndex.ID >> 22).ToLocalTime().AddMinutes(10) <
Channel!.Epoch.AddMilliseconds(Message.ID >> 22).ToLocalTime();
lastmIndex = Message;
if (lastUserIndex is null || lastUserIndex != Message.AuthorID || hasbeentenmin || fake != Message.IsProfile)
{
if (Window is null || !Globals.ms.InvokeRequired)
{
MessageFlow.Controls.Insert(index, LastChatMessageIndex = await ChatMessage.MakeChatMessage(this, Message));
LastChatMessageIndex.LoadToParent(MessageFlow, Globals.ms);
index++;
}
else
{
LastChatMessageIndex = await ChatMessage.MakeChatMessage(this, Message);
Globals.ms.Invoke(() =>
{
MessageFlow.Controls.Insert(index, LastChatMessageIndex);
LastChatMessageIndex.LoadToParent(MessageFlow, Globals.ms);
index++;
Window.TryDraw();
});
}
}
else
{
if (Window is null || !Globals.ms.InvokeRequired)
{
await LastChatMessageIndex!.AddMessage(Message);
}
else
{
Globals.ms.Invoke(() =>
{
LastChatMessageIndex!.AddMessage(Message);
Window!.TryDraw();
});
}
}
fakeIndex = Message.IsProfile;
lastUserIndex = Message.AuthorID;
}
}

View File

@ -78,10 +78,9 @@ public class ServerIcon<TServer> : UserControl where TServer : Server
Size = new((int)(68 * Globals.Settings.Scale), (int)(48 * Globals.Settings.Scale));
}
private Task OnClicked(IRenderObject arg)
private async Task OnClicked(IRenderObject arg)
{
return Task.CompletedTask;
await LoadServer();
}
public TServer Server { get; }

View File

@ -0,0 +1,594 @@
using GraphicsManager.Enums;
using GraphicsManager.Interfaces;
using GraphicsManager.Objects;
using GraphicsManager.Objects.Core;
using Luski.Classes;
using Luski.GUI.MainScreen.UI.LuskiControls;
using Luski.Interfaces;
using Luski.net;
using OpenTK.Graphics.OpenGL4;
using OpenTK.Mathematics;
using OpenTK.Windowing.GraphicsLibraryFramework;
using Rectangle = GraphicsManager.Objects.Rectangle;
namespace Luski.GUI.MainScreen.UI;
public class ServerLoginOverlay : UserControl, IServerOverlay
{
private UserControl Form, btn;
private DropDown<VersionDropButton> version;
public AccountButton? Selected { get; set; }
public UserControl page { get; set; }
private TextBox? UserName, Password, DisplayName, tb;
private Rectangle? rec;
public ServerLoginOverlay(string address)
{
base.Size = Globals.ms.Size;
BackgroundColor = new(0, 0, 0, 130);
Anchor = ObjectAnchor.All;
Form = new(Globals.ms.TextureManager.GetTextureResource("RoundedRectangle.png"))
{
Size = new((int)(350 * Globals.Settings.Scale), (int)(347 * Globals.Settings.Scale)),
BackgroundColor = new(32,32,32,255),
Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context],
TextureDisplay = TextureDisplay.Center
};
Label t;
Form.Controls.Add(t=new Label(Globals.DefaultFont) { Scale = 1.6f, Text = "Server Login", Color = Globals.DodgerBlue });
t.Location = new((Form.Size.X / 2) - (t.Size.X / 2), t.Location.Y, 0);
#region Server Loc
Label? ll = new Label(Globals.DefaultFont)
{
Text = net.API.DefaultVersion,
Color = Color4.DarkGray,
IgnoreHover = true
};
Vector2i s =new((int)(ll.Size.X * 1.6f),(int)(27 * Globals.Settings.Scale));
ll = null;
Rectangle line = new Rectangle()
{
Size = new Vector2i((int)Globals.Settings.Scale),
BackgroundColor = Globals.DodgerBlue
};
tb = new()
{
Location = new((int)(10*Globals.Settings.Scale),(int)(50 * Globals.Settings.Scale), 0),
Size = s,
Text = address,
WatermarkText = "Server Address",
TextLocation = TextLocation.PostiveTureCenterLeft,
AllowMultiLine = false
};
tb.Textures[0] = Globals.ms.TextureManager.GetTextureResource("Textbox.png");
tb.KeyPress += args =>
{
Texture t;
Texture good = Globals.ms.TextureManager.GetTextureResource("Textbox.png");
if ((args.Key == Keys.Backspace || args.Key == Keys.Delete) && string.IsNullOrWhiteSpace(tb.Text))
{
t = Globals.ms.TextureManager.GetTextureResource("BadTextbox.png");
}
else
{
t = good;
}
if (tb.Textures[0].handel != t.handel)
{
tb.Textures[0] = t;
if (t.handel == good.handel &&
UserName!.Textures[0].handel == good.handel &&
Password!.Textures[0].handel == good.handel &&
(rec is null || rec.Textures.Count > 1) &&
btn!.Textures[0].handel != good.handel &&
tb.Textures[0].handel == good.handel)
{
if (Selected!.l.Text != "Login")
{
if (DisplayName!.Textures[0].handel == good.handel) btn.Textures[0] = good;
}
else btn.Textures[0] = good;
}
else if (t.handel != good.handel &&
(UserName!.Textures[0].handel != good.handel ||
Password!.Textures[0].handel != good.handel ||
(rec is not null && rec!.Textures.Count == 1) ||
btn!.Textures[0].handel == good.handel ||
tb.Textures[0].handel != good.handel ||
(DisplayName is not null && DisplayName.Textures[0].handel != good.handel)))
{
btn!.Textures[0] = t;
}
Globals.ms.TryDraw();
}
return Task.CompletedTask;
};
tb.Size = new(Form.Size.X - tb.Location.X - tb.Location.X - tb.Location.X - s.X, tb.Size.Y);
Form.Controls.Add(tb);
version = new DropDown<VersionDropButton>(Form.Textures[0], line)
{
DropDownParentOverride = Form,
Size = s,
BackgroundColor = new(255,20,20,255),
TextureDisplay = TextureDisplay.HorizontalCenter,
Shader = Form.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 / 2) - ((int)ll2.Font.PixelHeight) + (ll2.PostiveTrueHeight / 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;
};
#endregion
#region Buttons
AccountButton ca = new AccountButton("Create Account", this)
{
Location = new(tb.Location.X, tb.Location.Y + tb.Location.X + tb.Size.Y, 0),
OnPageLoad = () =>
{
btn.Textures[0] = Globals.ms.TextureManager.GetTextureResource("BadTextbox.png");
page!.Controls.Add(UserName = new()
{
Location = new(0, (int)(10* Globals.Settings.Scale), 0),
Size = new(page.Size.X, (int)(30* Globals.Settings.Scale)),
WatermarkText = "Username",
TextLocation = TextLocation.PostiveTureCenterLeft,
AllowMultiLine = false
});
UserName.Textures[0] = Globals.ms.TextureManager.GetTextureResource("BadTextbox.png");
UserName.KeyPress += args =>
{
Texture t;
Texture good = Globals.ms.TextureManager.GetTextureResource("Textbox.png");
if ((args.Key == Keys.Backspace || args.Key == Keys.Delete || args.Alt || args.Shift || args.Control || args.Key == Keys.Enter || args.Key == Keys.KeyPadEnter || args.Key== Keys.Space) && string.IsNullOrWhiteSpace(UserName.Text))
{
t = Globals.ms.TextureManager.GetTextureResource("BadTextbox.png");
}
else
{
t = good;
}
if (UserName.Textures[0].handel != t.handel)
{
UserName.Textures[0] = t;
if (t.handel == good.handel &&
Password!.Textures[0].handel == good.handel &&
DisplayName!.Textures[0].handel == good.handel &&
rec!.Textures.Count > 1 &&
btn!.Textures[0].handel != good.handel &&
tb.Textures[0].handel == good.handel)
{
btn.Textures[0] = good;
}
else if (t.handel != good.handel &&
(Password!.Textures[0].handel != good.handel ||
DisplayName!.Textures[0].handel != good.handel ||
rec!.Textures.Count == 1 ||
btn!.Textures[0].handel == good.handel || tb.Textures[0].handel != good.handel))
{
btn!.Textures[0] = t;
}
Globals.ms.TryDraw();
}
return Task.CompletedTask;
};
page.Controls.Add(Password = new()
{
Location = new(0, UserName.Location.Y + UserName.Size.Y + UserName.Location.Y + UserName.Location.Y, 0),
Size = new(page.Size.X, UserName.Size.Y),
WatermarkText = "Password",
TextLocation = TextLocation.PostiveTureCenterLeft,
AllowMultiLine = false,
PasswordChar = '●'
});
Password.Textures[0] = UserName.Textures[0];
Password.KeyPress += args =>
{
Texture t;
Texture good = Globals.ms.TextureManager.GetTextureResource("Textbox.png");
if ((args.Key == Keys.Backspace || args.Key == Keys.Delete || args.Alt || args.Shift || args.Control || args.Key == Keys.Enter || args.Key == Keys.KeyPadEnter || args.Key== Keys.Space) && string.IsNullOrWhiteSpace(Password.Text))
{
t = Globals.ms.TextureManager.GetTextureResource("BadTextbox.png");
}
else
{
t = good;
}
if (Password.Textures[0].handel != t.handel)
{
Password.Textures[0] = t;
if (t.handel == good.handel && UserName!.Textures[0].handel == good.handel && DisplayName!.Textures[0].handel == good.handel && rec!.Textures.Count > 1 && btn!.Textures[0].handel != good.handel && tb.Textures[0].handel == good.handel)
{
btn.Textures[0] = good;
}
else if (t.handel != good.handel && (UserName!.Textures[0].handel != good.handel || DisplayName!.Textures[0].handel != good.handel || rec!.Textures.Count == 1 || btn!.Textures[0].handel == good.handel || tb.Textures[0].handel != good.handel))
{
btn!.Textures[0] = t;
}
Globals.ms.TryDraw();
}
return Task.CompletedTask;
};
page.Controls.Add(rec = new(Globals.ms.TextureManager.GetAlphaCircle())
{
Size = new((int)(50 * Globals.Settings.Scale)),
BackgroundColor = Color4.Red,
Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context],
IgnoreHover = false
});
rec.Location = new(page.Size.X - rec.Size.X, page.Size.Y - rec.Size.Y, 0);
page.Controls.Add(DisplayName = new()
{
Location = new(0, Password.Location.Y + Password.Size.Y + UserName.Location.Y + UserName.Location.Y, 0),
Size = new(page.Size.X- tb.Location.X - rec.Size.X, Password.Size.Y ),
WatermarkText = "Display Name",
TextLocation = TextLocation.PostiveTureCenterLeft,
AllowMultiLine = false
});
DisplayName.KeyPress += args =>
{
Texture t;
Texture good = Globals.ms.TextureManager.GetTextureResource("Textbox.png");
if ((args.Key == Keys.Backspace || args.Key == Keys.Delete || args.Alt || args.Shift || args.Control || args.Key == Keys.Enter || args.Key == Keys.KeyPadEnter || args.Key== Keys.Space) &&
string.IsNullOrWhiteSpace(UserName.Text))
{
t = Globals.ms.TextureManager.GetTextureResource("BadTextbox.png");
}
else
{
t = good;
}
if (DisplayName.Textures[0].handel != t.handel)
{
DisplayName.Textures[0] = t;
if (t.handel == good.handel && UserName!.Textures[0].handel == good.handel &&
Password!.Textures[0].handel == good.handel && rec!.Textures.Count > 1 &&
btn!.Textures[0].handel != good.handel && tb.Textures[0].handel == good.handel)
{
btn.Textures[0] = good;
}
else if (t.handel != good.handel && (UserName!.Textures[0].handel != good.handel ||
Password!.Textures[0].handel != good.handel ||
rec!.Textures.Count == 1 ||
btn!.Textures[0].handel == good.handel || tb.Textures[0].handel != good.handel))
{
btn!.Textures[0] = t;
}
Globals.ms.TryDraw();
}
return Task.CompletedTask;
};
rec.FilesDroped += RecOnFilesDroped;
DisplayName.Textures[0] = UserName.Textures[0];
rec.ForceDistanceUpdate(page);
Globals.ms.TryDraw();
Globals.ms.ForceUpdate(new(Size));
}
};
ca.Size = new((Form.Size.X - tb.Location.X - tb.Location.X - (tb.Location.X / 2)) / 2, ca.Size.Y);
ca.l.Location = new((ca.Size.X - ca.l.Size.X) / 2,
(ca.Size.Y / 2) - ((int)ca.l.Font.PixelHeight) + (ca.l.PostiveTrueHeight / 2)
, 0);
ca.l.ForceDistanceUpdate(ca);
Form.Controls.Add(ca);
AccountButton lo = new AccountButton("Login", this)
{
Location = new(ca.Location.X + ca.Size.X + (tb.Location.X / 2),ca.Location.Y, 0),
OnPageLoad = () =>
{
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)),
WatermarkText = "Username",
TextLocation = TextLocation.PostiveTureCenterLeft,
AllowMultiLine = false
});
UserName.Textures[0] = Globals.ms.TextureManager.GetTextureResource("BadTextbox.png");
UserName.KeyPress += args =>
{
Texture t;
Texture good = Globals.ms.TextureManager.GetTextureResource("Textbox.png");
if ((args.Key == Keys.Backspace || args.Key == Keys.Delete || args.Alt || args.Shift || args.Control || args.Key == Keys.Enter || args.Key == Keys.KeyPadEnter || args.Key== Keys.Space) && string.IsNullOrWhiteSpace(UserName.Text))
{
t = Globals.ms.TextureManager.GetTextureResource("BadTextbox.png");
}
else
{
t = good;
}
if (UserName.Textures[0].handel != t.handel)
{
UserName.Textures[0] = t;
if (t.handel == good.handel &&
Password!.Textures[0].handel == good.handel &&
btn!.Textures[0].handel != good.handel &&
tb.Textures[0].handel == good.handel)
{
btn.Textures[0] = good;
}
else if (t.handel != good.handel &&
(Password!.Textures[0].handel != good.handel ||
btn!.Textures[0].handel == good.handel || tb.Textures[0].handel != good.handel))
{
btn!.Textures[0] = t;
}
Globals.ms.TryDraw();
}
return Task.CompletedTask;
};
page.Controls.Add(Password = new()
{
Location = new(0, UserName.Location.Y + UserName.Size.Y + UserName.Location.Y + UserName.Location.Y, 0),
Size = new(page.Size.X, UserName.Size.Y),
WatermarkText = "Password",
TextLocation = TextLocation.PostiveTureCenterLeft,
AllowMultiLine = false,
PasswordChar = '●'
});
Password.Textures[0] = UserName.Textures[0];
Password.KeyPress += args =>
{
Texture t;
Texture good = Globals.ms.TextureManager.GetTextureResource("Textbox.png");
if ((args.Key == Keys.Backspace || args.Key == Keys.Delete || args.Alt || args.Shift || args.Control || args.Key == Keys.Enter || args.Key == Keys.KeyPadEnter || args.Key== Keys.Space) &&
string.IsNullOrWhiteSpace(Password.Text))
{
t = Globals.ms.TextureManager.GetTextureResource("BadTextbox.png");
}
else
{
t = good;
}
if (Password.Textures[0].handel != t.handel)
{
Password.Textures[0] = t;
if (t.handel == good.handel &&
UserName!.Textures[0].handel == good.handel &&
btn!.Textures[0].handel != good.handel &&
tb.Textures[0].handel == good.handel)
{
btn.Textures[0] = good;
}
else if (t.handel != good.handel &&
(UserName!.Textures[0].handel != good.handel ||
btn!.Textures[0].handel == good.handel || tb.Textures[0].handel != good.handel))
{
btn!.Textures[0] = t;
}
Globals.ms.TryDraw();
}
return Task.CompletedTask;
};
DisplayName = null!;
rec = null!;
}
};
lo.Size = ca.Size;
lo.l.Location = new((lo.Size.X / 2) - (lo.l.Size.X / 2),
(lo.Size.Y / 2) - ((int)lo.l.Font.PixelHeight) + (lo.l.PostiveTrueHeight / 2)
, 0);
lo.l.ForceDistanceUpdate(lo);
Form.Controls.Add(lo);
#endregion
Form.Controls.Add(version);
page = new()
{
Location = new(tb.Location.X, ca.Location.Y + ca.Size.Y + tb.Location.X, 0),
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"))
{
Location = new(page.Location.X, page.Location.Y + page.Size.Y + tb.Location.X, 0),
Size = new(page.Size.X, ca.Size.Y),
TextureDisplay = TextureDisplay.Center
};
_ = lo.ToggleSelected();
Label sub = new(Globals.DefaultFont)
{
Text = "Submit",
IgnoreHover = true
};
sub.Location = new((btn.Size.X / 2) - (sub.Size.X / 2),
(btn.Size.Y / 2) - ((int)sub.Font.PixelHeight) + (sub.PostiveTrueHeight / 2)
, 0);
sub.ForceDistanceUpdate(btn);
btn.Controls.Add(sub);
Form.Controls.Add(btn);
Form.Location = new((base.Size.X - Form.Size.X) / 2, (base.Size.Y - Form.Size.Y) / 2, 0);
Controls.Add(Form);
btn.Clicked += BtnOnClicked;
}
private async Task BtnOnClicked(IRenderObject arg)
{
if (btn.Textures[0].handel == Globals.ms.TextureManager.GetTextureResource("BadTextbox.png").handel)
return;
bool s = true;
string d = tb!.Text;
if (d.Contains("://"))
{
string[] a = d.Split("://");
d = a[1];
if (a[0] == "http") s = false;
}
ServerInfo si = new()
{
Domain = d,
Version = version.SelectedOption.l.Text,
Main = false,
Secure = s
};
IEnumerable<PublicServer> sers = Globals.Luski.LoadedServers.Where(s => s.Domain == tb.Text);
if (sers.Any())
{
bool g;
PublicServer ps = sers.First();
if (DisplayName is null)
{
g = await ps.Login(UserName!.Text, Password!.Text, CancellationToken.None);
}
else
{
g = await ps.CreateAccount(UserName!.Text, Password!.Text, DisplayName.Text, pfp,
CancellationToken.None);
}
if (!g)
{
Texture b = Globals.ms.TextureManager.GetTextureResource("BadTextbox.png");
UserName!.Textures[0] = b;
Password!.Textures[0] = b;
btn.Textures[0] = b;
_ = Globals.ms.LoadPublicServer(ps);
Globals.ms.TryDraw();
return;
}
}
Globals.ms.Controls.Remove(this);
Globals.ms.ForceUpdate(new(Size));
Globals.ms.TryDraw();
}
private Task VersionOnOptionSelected(VersionDropButton arg)
{
return Task.CompletedTask;
}
private Task VersionOnOpenStatusChanged(bool arg)
{
return Task.CompletedTask;
}
private string pfp = "";
private Task RecOnFilesDroped(string[] arg)
{
Console.WriteLine(arg[0]);
if (!arg[0].ToLower().EndsWith("png")) return Task.CompletedTask;
pfp = arg[0];
if (rec!.Textures.Count() ==1 )
{
Texture good = Globals.ms.TextureManager.GetTextureResource("Textbox.png");
if (UserName!.Textures[0].handel == good.handel &&
Password!.Textures[0].handel == good.handel &&
btn!.Textures[0].handel != good.handel && tb.Textures[0].handel == good.handel)
{
if (DisplayName is not null)
{
if (Password!.Textures[0].handel == good.handel) btn.Textures[0] = good;
}
else btn.Textures[0] = good;
}
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);
}
else
{
rec.Textures[1] = Globals.ms.TextureManager.AddTexture(File.OpenRead(arg[0]));
rec.Textures[1].Unit = TextureUnit.Texture1;
}
Window!.TryDraw();
return Task.CompletedTask;
}
}

View File

@ -3,6 +3,7 @@ using GraphicsManager.Interfaces;
using GraphicsManager.Objects;
using GraphicsManager.Objects.Core;
using Luski.Classes;
using Luski.GUI.MainScreen.UI.LuskiControls;
using Luski.GUI.MainScreen.UI.SettingsPanel;
using OpenTK.Mathematics;
@ -16,6 +17,7 @@ public class SettingsMenu : UserControl
private FlowLayout fl;
private Category? AppSettings;
private FontInteraction f;
private DropDown<ThemeDropButton> ThemeDrop;
public SettingsMenu()
{
LuskiExperiments.Settings.Theme.EventToggled += ThemeOnEventToggled;
@ -42,6 +44,11 @@ public class SettingsMenu : UserControl
if (LuskiExperiments.Settings.Theme.IsEnabled())
{
AppSettings = new("APP SETTINGS");
Label Top = new(Globals.DefaultFont)
{
Location = new((int)(5 * Globals.Settings.Scale), (int)(5 * Globals.Settings.Scale), 0),
Text = LuskiThemes.Dark.Name
};
CategoryButton cb2 = new("Appearance", this)
{
OnPageLoad = () =>
@ -50,6 +57,86 @@ public class SettingsMenu : UserControl
{
Text = " \nAppearance\n "
});
ThemeDropButton LightDD;
ThemeDrop = new(CategoryButton.seltec!,new Rectangle()
{
Size = new(base.Size.X - 2, (int)Globals.Settings.Scale),
BackgroundColor = Color4.Gray,
Location = new(1, base.Size.Y - (int)Globals.Settings.Scale, 0),
Anchor = ObjectAnchor.Left | ObjectAnchor.Right | ObjectAnchor.Bottom
}, LightDD = new(LuskiThemes.Light)
{
LoadDisplay = () =>
{
Label ll = new Label(Globals.DefaultFont)
{
Text = LuskiThemes.Light.Name,
Color = Color4.DarkGray,
IgnoreHover = true
};
ll.Location = new((int)(10 * Globals.Settings.Scale),
(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)),
Location = new(Top.Location.X, Top.Location.Y, 0),
BackgroundColor = new(40, 40, 40, 255),
Anchor = ObjectAnchor.Right | ObjectAnchor.Left,};
foreach (ThemeStart themeStart in LuskiThemes.LuskiThemeList)
{
if (themeStart.Name == LuskiThemes.Light.Name) continue;
ThemeDropButton tdb;
ThemeDrop.AddOption(tdb = new(themeStart)
{
LoadDisplay = () =>
{
Label ll = new Label(Globals.DefaultFont)
{
Text = themeStart.Name,
Color = Color4.DarkGray,
IgnoreHover = true
};
ll.Location = new((int)(10 * Globals.Settings.Scale),
(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)),
});
if (themeStart.Name == Globals.Settings.Theme) ThemeDrop.SetSelected(tdb);
}
ThemeDrop.DropDownContainer.Textures.Add(Globals.ms.TextureManager.GetTextureResource("RoundedRectangleBottom.png"));
ThemeDrop.DropDownContainer.TextureDisplay = TextureDisplay.Center;
ThemeDrop.DropDownContainer.Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context];
ThemeDrop.DropDownContainer.BackgroundColor = ThemeDrop.BackgroundColor;
Rectangle line = new()
{
Size = new(base.Size.X - 2, (int)Globals.Settings.Scale),
BackgroundColor = Color4.Gray,
Location = new(1, base.Size.Y - (int)Globals.Settings.Scale, 0),
Anchor = ObjectAnchor.Left | ObjectAnchor.Right | ObjectAnchor.Bottom
};
ThemeDrop.OpenStatusChanged += b =>
{
BlockDraw = true;
Size = new(base.Size.X, base.Size.Y + ( b ? ThemeDrop.DropDownContainer.Size.Y : -1 * ThemeDrop.DropDownContainer.Size.Y));
line!.Location = new(line.Location.X,
line.Location.Y + (b ? ThemeDrop.DropDownContainer.Size.Y : -1 * ThemeDrop.DropDownContainer.Size.Y), 0);
if (b)
{
ThemeDrop.Textures[0] = Globals.ms.TextureManager.GetTextureResource("RoundedRectangleTop.png");
}
else
{
ThemeDrop.Textures[0] = CategoryButton.seltec!;
}
BlockDraw = false;
return Task.CompletedTask;
};
page!.Controls.Add(ThemeDrop);
}
};
AppSettings.AddButton(cb2);
@ -91,7 +178,30 @@ public class SettingsMenu : UserControl
page!.Controls.Add(new Label(f)
{
Text = " \nUpdater Config\n "
});
void AddBool(string Name, ref bool s)
{
}
TextBox t;
page!.Controls.Add(t =new TextBox()
{
Text = Globals.UpdaterSettings.Updater!,
WatermarkText = "Updater File",
TextureDisplay = TextureDisplay.Center,
Size = new(page.Size.X, (int)(34 * Globals.Settings.Scale)),
TextLocation = TextLocation.PostiveTureCenterLeft,
AllowMultiLine = false
});
t.KeyPress += args =>
{
Globals.UpdaterSettings.Updater = t.Text;
Globals.UpdaterSettings.SaveSettings(Path.Combine(Globals.LuskiPath, "UpdaterSettings.json"), UpdaterSettingsContext.Default.UpdaterSettings);
return Task.CompletedTask;
};
}
};
As.AddButton(cb);

View File

@ -27,6 +27,7 @@ public class ExperimentGUI : UserControl
public ExperimentGUI(ExperimentInfo ei)
{
TextureDisplay = TextureDisplay.Center;
if (TopOpen is null)
{
TopOpen = Globals.ms.TextureManager.GetTextureResource("RoundedRectangleTop.png");
@ -78,7 +79,7 @@ public class ExperimentGUI : UserControl
DropDownParentOverride = this
};
dd.DropDownContainer.Textures.Add(BottomOpen);
dd.DropDownContainer.TextureDisplay = TextureDisplay.HorizontalCenter;
dd.DropDownContainer.TextureDisplay = TextureDisplay.Center;
dd.DropDownContainer.Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context];
dd.DropDownContainer.BackgroundColor = dd.BackgroundColor;
dd.OpenStatusChanged += b =>
@ -123,7 +124,6 @@ public class ExperimentGUI : UserControl
dd.AddOption(oo);
if (o.IsEnabled())
{
Console.WriteLine($"Default for {ei.DisplayName}: {o.Name}");
dd.SetSelected(oo);
currentEnabled = o;
}

View File

@ -0,0 +1,55 @@
using GraphicsManager.Enums;
using GraphicsManager.Interfaces;
using GraphicsManager.Objects;
using GraphicsManager.Objects.Core;
using Luski.Classes;
using Luski.GUI.MainScreen.UI.LuskiControls;
using OpenTK.Mathematics;
namespace Luski.GUI.MainScreen.UI.SettingsPanel;
public class ThemeDropButton : DropDownOption
{
private Label l, d;
public ThemeStart ESI;
public ThemeDropButton(ThemeStart esi)
:base(CategoryButton.seltec!)
{
ESI = esi;
base.Size = new((int)(297 * Globals.Settings.Scale), (int)(40* Globals.Settings.Scale));
TextureDisplay = TextureDisplay.HorizontalCenter;
Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context];
l = new Label(Globals.DefaultFont)
{
Text = esi.Name,
Color = Color4.DarkGray,
IgnoreHover = true
};
l.Location = new((int)(10 * Globals.Settings.Scale),
(base.Size.Y / 2) - ((int)l.Font.PixelHeight) + (l.PostiveTrueHeight / 2)
, 0);
d = new(Globals.MessageFont)
{
Text = esi.Description,
Color = Color4.Gray,
IgnoreHover = true
};
d.Location = new(l.Location.X + l.Size.X + l.Location.X,
l.Location.Y + (int)l.Font.PixelHeight - (int)d.Font.PixelHeight
, 0);
Controls.Add(d);
Controls.Add(l);
BackgroundColor = new(0, 0, 0, 0);
MouseEnter += o =>
{
BackgroundColor = new(141, 151, 165, 30);
return Task.CompletedTask;
};
MouseLeave += o =>
{
BackgroundColor = new(0,0,0,0);
return Task.CompletedTask;
};
}
}

View File

@ -23,7 +23,7 @@ public class MainScreenWindow : Window
{
private static readonly NativeWindowSettings Settings = new()
{
Title = "Luski Login",
Title = "Luski",
WindowBorder = WindowBorder.Fixed,
APIVersion = new Version(3, 2),
API = ContextAPI.OpenGL,
@ -57,37 +57,74 @@ public class MainScreenWindow : Window
// The rest of the function is up to you to implement, however a debug output
// is always useful.
if (false)
switch (severity)
{
switch (severity)
{
case DebugSeverity.DebugSeverityHigh:
case DebugSeverity.DebugSeverityHigh:
if ((Globals.Settings.Logs & ConsoleLog.BigErrosForOpenGL) == ConsoleLog.BigErrosForOpenGL)
{
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.WriteLine("[{0} source={1} type={2} id={3}] {4}", severity, source, type, id, message);
Console.ResetColor();
break;
case DebugSeverity.DebugSeverityMedium:
}
break;
case DebugSeverity.DebugSeverityMedium:
if ((Globals.Settings.Logs & ConsoleLog.MediumErrosForOpenGL) == ConsoleLog.MediumErrosForOpenGL)
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("[{0} source={1} type={2} id={3}] {4}", severity, source, type, id, message);
Console.ResetColor();
break;
default:
}
break;
case DebugSeverity.DebugSeverityLow:
if ((Globals.Settings.Logs & ConsoleLog.LowErrosForOpenGL) == ConsoleLog.LowErrosForOpenGL)
{
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.WriteLine("[{0} source={1} type={2} id={3}] {4}", severity, source, type, id, message);
Console.ResetColor();
}
break;
default:
if ((Globals.Settings.Logs & ConsoleLog.InfoForOpenGL) == ConsoleLog.InfoForOpenGL)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(message);
Console.ResetColor();
break;
}
}
break;
}
}
public MainScreenWindow() : base(Settings)
{
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);
Globals.DefaultFontFamly = FontFamily.LoadFontFamily("Noto Sans").Result;
Globals.DefaultFont = FontInteraction.Load(Globals.DefaultFontFamly);
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++)
{
t += (char)i;
}
//Console.WriteLine(t);
}
catch (Exception e)
{
Console.WriteLine(e);
}
Globals.DefaultFont.PixelHeight = (uint)(20 * Globals.Settings.Scale);
Globals.DefaultFont.FontSize = FontSize.Regular;
Globals.TopTimeFont = Globals.DefaultFont.Clone();
@ -99,35 +136,24 @@ public class MainScreenWindow : Window
Globals.MessageFont.FontSize = FontSize.Regular;
Globals.SmallTimeFont = Globals.DefaultFont.Clone();
Globals.LuskiTexture = TextureManager.GetTextureResource("Luski.png");
CenterWindow(0);
if ((Globals.Luski.MainServer is not null && !Globals.Luski.MainServer.IsLogedIn) ||
!Globals.Luski.LoadedServers.Any(s => s.IsLogedIn))
try
{
Controls.Add(ca = new CreateAccount());
ca.Visible = false;
ca.ChangeToApp += LoginOnChangeToApp;
Controls.Add(login = new Login());
login.ChangeToApp += LoginOnChangeToApp;
login.ChangeToCa += LoginOnChangeToCa;
Thread t = new(_ =>
{
if (Globals.Luski.MainServer is not null) Globals.Luski.MainServer.EncryptionHandler.GenerateKeys();
});
t.Start();
CenterWindow(Globals.Settings.Display);
}
catch (Exception e)
{
CenterWindow();
}
WindowLoaded += OnWindowLoaded;
}
private Task OnWindowLoaded(Window arg)
private async Task OnWindowLoaded(Window arg)
{
if (Globals.UpdaterSettings.AutoUpdateCheck && new HttpClient()
.GetAsync(
$"https://www.jacobtech.com/Updater/GetProgramVersion?directory=Luski&branch={Globals.UpdaterSettings.Branch.ToString()}&selfcontained={Globals.UpdaterSettings.SelfContained.ToString().ToLower()}&platform={Globals.UpdaterSettings.Platform}")
.Result.Content.ReadAsStringAsync().Result !=
string r = new HttpClient()
.GetAsync(
$"https://www.jacobtech.com/Updater/GetProgramVersion?directory=Luski&branch={Globals.UpdaterSettings.Branch.ToString()}&selfcontained={Globals.UpdaterSettings.SelfContained.ToString().ToLower()}&platform={Globals.UpdaterSettings.Platform}")
.Result.Content.ReadAsStringAsync().Result;
if (Globals.UpdaterSettings.AutoUpdateCheck && r !=
FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion)
{
var update = new UpdateWindow();
@ -138,19 +164,7 @@ public class MainScreenWindow : Window
Close();
}
}
if ((Globals.Luski.MainServer is not null && Globals.Luski.MainServer.IsLogedIn) ||
Globals.Luski.LoadedServers.Any(s => s.IsLogedIn)) Invoke(() => LoginOnChangeToApp());
return Task.CompletedTask;
}
private Task LoginOnChangeToCa()
{
Title = "Create Account";
ca.Visible = true;
login.Visible = false;
return Task.CompletedTask;
await LoginOnChangeToApp();
}
public FlowLayout ser;
@ -162,6 +176,12 @@ public class MainScreenWindow : Window
GL.Enable(EnableCap.DepthTest);
GL.DepthFunc(DepthFunction.Always);
if (Server is null) return;
if (!Server.IsLogedIn)
{
ServerLoginOverlay SLO = new(Server.Domain);
Controls.Add(SLO);
return;
}
BlockDraw = true;
try
{
@ -196,12 +216,11 @@ public class MainScreenWindow : Window
}
parents.Reverse();
ChannelSelector cs = new(parents[0])
{
BackgroundColor = new(34, 34, 34, 255),
Size = new((int)(307 * Globals.Settings.Scale), SerBox.Size.Y - (int)(54 * Globals.Settings.Scale)),
Anchor = ObjectAnchor.Top | ObjectAnchor.Left | ObjectAnchor.Bottom
};
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.Anchor = ObjectAnchor.Top | ObjectAnchor.Left | ObjectAnchor.Bottom;
parents.RemoveAt(0);
SerBox.Controls.Add(cs);
cs.ForceDistanceUpdate(SerBox);
@ -220,7 +239,6 @@ public class MainScreenWindow : Window
pc.LoadToParent(SerBox, this);
pc.ForceDistanceUpdate();
pc.MessageFlow.ForceDistanceUpdate(pc);
#endregion
#region Channel Selector Loader
@ -230,18 +248,13 @@ public class MainScreenWindow : Window
#endregion
#region User Icon
Role[] ra = await Server.User.GetRoles();
Color c = ra[0].Color;
Color4 c4 = new(c.R, c.G, c.B, c.A);
Rectangle u = new Rectangle(TextureManager.GetTextureResource("Status.png"))
{
Anchor = ObjectAnchor.Bottom | ObjectAnchor.Left, Size = new((int)(46 * Globals.Settings.Scale)),
Location = new((int)(4 * Globals.Settings.Scale), SerBox.Size.Y, 0)
};
u.Location = new(u.Location.X, cs.Size.Y + u.Location.X, 0);
u.Shader = Rectangle.DefaultAlphaTextureShader[Context];
u.Textures.Add(await Server.User.GetIcon());
IRenderObject u = await Server.User.MakeRct(new((int)(46 * Globals.Settings.Scale)), false);
int ii = (int)(4 * Globals.Settings.Scale);
u.Location = new(ii, cs.Size.Y + ii, 0);
u.Anchor = ObjectAnchor.Bottom | ObjectAnchor.Left;
SerBox.Controls.Add(u);
u.LoadToParent(SerBox, this);
u.ForceDistanceUpdate();
@ -255,7 +268,6 @@ public class MainScreenWindow : Window
ul.Location = new(u.Location.X + u.Size.X + (int)(5 * Globals.Settings.Scale),
(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),
@ -277,7 +289,8 @@ public class MainScreenWindow : Window
setting.Clicked += SettingOnClicked;
setting.ForceDistanceUpdate(SerBox);
SerBox.Controls.Add(setting);
ForceUpdate(new (Size));
TryDraw();
#endregion
}
catch (Exception e)
@ -316,11 +329,16 @@ public class MainScreenWindow : Window
BlockDraw = true;
Title = "Luski";
Size = new((int)(1332 * Globals.Settings.Scale), (int)(866 * Globals.Settings.Scale));
DateTime start = DateTime.Now;
CenterWindow(0);
DateTime start1 = DateTime.Now;
try
{
CenterWindow(Globals.Settings.Display);
}
catch (Exception e)
{
CenterWindow();
}
WindowBorder = WindowBorder.Resizable;
BackgroundColor = new Color4(34, 34, 34, 255);
BackgroundColor = new Color4(20, 20, 20, 255);
Controls.Add(ser = new FlowLayout()
{
@ -330,18 +348,23 @@ public class MainScreenWindow : Window
Location = new(0,0,0)
});
DrawFrame();
DateTime utcNow = DateTime.UtcNow;
Task.WhenAll(Globals.ServersLoading.ToArray()).Wait();
foreach (PublicServer pser in Globals.Luski.LoadedServers)
{
ser.Controls.Add(new ServerIcon<PublicServer>(pser));
ServerIcon<PublicServer> si = new ServerIcon<PublicServer>(pser);
ser.Controls.Add(si);
}
AddServerIcon asi = new();
asi.Button.Clicked += AddButtonClicked;
asi.Clicked += AddButtonClicked;
ser.Controls.Add(asi);
await (ser.Controls[0] as ServerIcon<PublicServer>)!.LoadServer();
if (ser.Controls.Length > 1) (ser.Controls[0] as ServerIcon<PublicServer>)!.LoadServer().Start();
DrawFrame();
MainShow += OnMainShow;
return Task.CompletedTask;
}
@ -351,8 +374,11 @@ public class MainScreenWindow : Window
AddServerOverlay aso = new();
aso.Clicked += AsoOnClicked;
Controls.Add(aso);
TryDraw();
OnResize(new(Size));
return Task.CompletedTask;
}
private Task AsoOnClicked(IRenderObject arg)

View File

@ -64,7 +64,15 @@ public class UpdateWindow : Window
Size = new(t.Location.X + t.Location.X + t.Size.X, no.Location.Y + no.Size.Y + t.Location.X);
no.Clicked += NoOnClicked;
}
CenterWindow();
try
{
CenterWindow(Globals.Settings.Display);
}
catch (Exception e)
{
CenterWindow();
}
}
private Task NoOnClicked(IRenderObject arg)

View File

@ -1,14 +1,20 @@
using System.CodeDom.Compiler;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text.Json;
using System.Text.Json.Serialization.Metadata;
using GraphicsManager;
using GraphicsManager.Interfaces;
using GraphicsManager.Objects;
using GraphicsManager.Objects.Core;
using Luski.Classes;
using Luski.Classes.ThemeSub;
using Luski.GUI;
using Luski.net;
using Luski.net.Enums;
using Luski.net.Interfaces;
using Luski.net.Structures.Public;
using Luski.Shared.PublicServers.V1.Enums;
using OpenTK.Graphics.OpenGL4;
using OpenTK.Mathematics;
using OpenTK.Windowing.Common.Input;
@ -18,8 +24,26 @@ namespace Luski;
public static class Globals
{
#pragma warning disable CS8618
public static List<Task<bool>> ServersLoading = new();
public static ServerList ServerList;
public static Dictionary<Window, List<IRenderObject>> AllowedBehindObjects = new();
public static ThemeStart Theme
{
get
{
return LuskiThemes.LuskiThemeList.Where(s => s.Name == Settings.Theme).First();
}
}
public static ServerThemeProperties GetTheme(this PublicServer ser)
{
IEnumerable<ServerTheme> l = Theme.ServerOverrides.Where(s => s.Address == ser.Domain);
ServerTheme[] serverThemes = l as ServerTheme[] ?? l.ToArray();
if (serverThemes.Any()) return serverThemes[0].Properties;
return Theme.GlobalServerTemplate;
}
private static List<ExperimentInfo> AddedExperiments = new();
private static List<ExperimentInfo> EnabledExperiments = new();
public static List<ExperimentJson> MissingExperiments = new();
@ -28,6 +52,29 @@ public static class Globals
private static int LastExpCount = 0;
public static Color4 DodgerBlue = new Color4(30, 144, 255, 255);
public static void PrintParent(IParent par)
{
void PrintP(int index, IParent p, Vector3i l)
{
string sp = "";
for (int i = 0; i < index; i++)
{
sp += " ";
}
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);
if (p.Controls[i] is IParent pp) PrintP(index + 1, pp, l + pp.Position);
}
}
Console.WriteLine(par + ": " + par.Position + par.Size);
PrintP(1,par, par.Position);
}
public static void RegisterExperiment(ExperimentInfo exp)
{
IEnumerable<ExperimentJson> found = MissingExperiments.Where(e => e.Name == exp.Name);
@ -123,6 +170,12 @@ public static class Globals
return t;
}
public static Stream GetResource(string File)
{
return Tools.GetResourceStream(Assembly.GetExecutingAssembly(),
$"Luski.Resources.{File}");
}
public static void AddBehindObject(this Window w, IRenderObject obj)
{
if (!AllowedBehindObjects.ContainsKey(w)) AllowedBehindObjects.Add(w, new());
@ -166,14 +219,20 @@ public static class Globals
return new(col.R, col.G, col.B, col.A);
}
public static Color ToColor(this Color4 col)
{
return new((byte)(col.R*byte.MaxValue), (byte)(col.G*byte.MaxValue), (byte)(col.B*byte.MaxValue), (byte)(col.A*byte.MaxValue));
}
public static Texture GetAlphaCircle(this TextureManager tm)
{
return tm.GetTextureResource("Status.png");
}
public static Dictionary<long, Texture> UserTextureMap = new();
public static Dictionary<long, Texture> ProfileTextureMap = new();
public static async Task<Texture> GetIcon(this SocketUser User)
private static async Task<Texture> GetIcon(this SocketUser User)
{
if (UserTextureMap.TryGetValue(User.Id, out Texture? t)) return t;
Stream UserStream = await User.GetAvatar(CancellationToken.None);
@ -184,15 +243,59 @@ public static class Globals
return t;
}
public static async Task<Texture> GetIcon(this IUser User)
public static async Task<IRenderObject> MakeRct<TUser>(this TUser User, Vector2i Size, bool IsProfile) where TUser : IUser
{
if (UserTextureMap.TryGetValue(User.Id, out Texture? t)) return t;
Stream UserStream = await User.GetAvatar(CancellationToken.None);
t = Globals.ms.TextureManager.AddTexture(UserStream);
UserTextureMap.Add(User.Id, t);
UserStream.Dispose();
t.Unit = TextureUnit.Texture1;
return t;
Texture t = ms.TextureManager.GetTextureResource("Status.png");
if (User.PictureType == PictureType.none)
{
UserControl r = new(t);
r.Size = Size;
r.Shader = Rectangle.DefaultAlphaShader[ms.Context];
Color c = await User.GetColor();
r.BackgroundColor = new(25, 25, 25, 255);
Label l = new(DefaultFont)
{
Color = c.ToColor4()
};
l.Text = User.DisplayName[0].ToString();
l.Location = new((r.Size.X - l.Size.X)/2,
(int)(r.Location.Y + (r.Size.Y / 2) - (l.Font.CurrentFonts[0].Face.Size.Metrics.NominalHeight / 2) - l.Size.Y + l.Font.PixelHeight),
0);
r.Controls.Add(l);
return r;
}
else
{
Rectangle r = new(t);
r.Size = Size;
r.Shader = Rectangle.DefaultAlphaTextureShader[ms.Context];
r.Textures.Add(await User.GetIcon(IsProfile));
return r;
}
}
private static async Task<Texture> GetIcon(this IUser User, bool IsProfile)
{
if (IsProfile)
{
if (ProfileTextureMap.TryGetValue(User.Id, out Texture? t)) return t;
Stream UserStream = await User.GetAvatar(CancellationToken.None);
t = Globals.ms.TextureManager.AddTexture(UserStream);
ProfileTextureMap.Add(User.Id, t);
UserStream.Dispose();
t.Unit = TextureUnit.Texture1;
return t;
}
else
{
if (UserTextureMap.TryGetValue(User.Id, out Texture? t)) return t;
Stream UserStream = await User.GetAvatar(CancellationToken.None);
t = Globals.ms.TextureManager.AddTexture(UserStream);
UserTextureMap.Add(User.Id, t);
UserStream.Dispose();
t.Unit = TextureUnit.Texture1;
return t;
}
}
public static Settings Settings { get; set; }
@ -240,6 +343,25 @@ public static class Globals
return @out;
}
public static TResult GetSettings<TResult>(Stream data, JsonTypeInfo<TResult> TypeInfo) where TResult : new()
{
TResult? @out;
try
{
@out = JsonSerializer.Deserialize(data, TypeInfo);
if (@out is null)
{
@out = new();
}
}
catch
{
@out = new();
}
return @out;
}
public static void SaveSettings<TResult>(this TResult json, string path, JsonTypeInfo<TResult> TypeInfo) where TResult : new()
{
File.WriteAllText(path, JsonSerializer.Serialize(json, TypeInfo));

View File

@ -0,0 +1,10 @@
using GraphicsManager.Objects;
using Luski.GUI.MainScreen.UI;
namespace Luski.Interfaces;
public interface IServerOverlay
{
public AccountButton? Selected { get; set; }
public UserControl page { get; set; }
}

View File

@ -5,22 +5,24 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<FileVersion>1.1.0.1</FileVersion>
<FileVersion>1.0.0.0</FileVersion>
<Company>JacobTech, LLC</Company>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DefineConstants />
<DebugType>none</DebugType>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<NoWarn>1701;1702;IL2121;MSB3246</NoWarn>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="GraphicsManager" Version="1.0.7-alpha69" />
<PackageReference Include="Luski.net" Version="2.0.0-alpha25" />
<PackageReference Include="GraphicsManager" Version="1.0.8-alpha82" />
<PackageReference Include="Luski.net" Version="2.0.0-alpha69" />
</ItemGroup>
<ItemGroup>

View File

@ -4,6 +4,7 @@ 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;
@ -18,15 +19,45 @@ try
}
ServerList serverlist = Globals.GetSettings(Path.Combine(Globals.LuskiPath, "Servers.json"), ServerListContext.Default.ServerList);
List<Task<bool>> bbb = new();
if (serverlist.Server.Length > 0)
Globals.ServerList = serverlist;
string themes = Path.Combine(Globals.LuskiPath, "Themes");
if (!Directory.Exists(themes)) Directory.CreateDirectory(themes);
DirectoryInfo di = new DirectoryInfo(themes);
foreach (DirectoryInfo Theme in di.GetDirectories())
{
foreach (ServerInfo server in serverlist.Server)
try
{
LuskiThemes.LoadThemeFromDir(Theme.FullName);
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
foreach (FileInfo Theme in di.GetFiles())
{
try
{
if (Theme.FullName.ToLower().EndsWith(".zip")) LuskiThemes.LoadThemeFromDir(Theme.FullName);
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
if (serverlist.Servers.Length > 0)
{
foreach (ServerInfo server in serverlist.Servers)
{
switch (server.Main)
{
case false:
bbb.Add(Globals.Luski.TryGetPublicServer(out _,server.Domain, server.Version, server.Secure));
Globals.ServersLoading.Add(Task.Run(async () =>
{
return await Globals.Luski.TryGetPublicServer(out _, server.Domain, server.Version,
server.Secure, server.PreGenEncryption, server.ShowMessage);
}));
break;
case true:
if (LuskiExperiments.MainServers.EnableMainServers.IsEnabled()) Globals.Luski.GetMainServer(server.Domain, server.Version);
@ -34,13 +65,9 @@ try
}
}
}
Globals.UpdaterSettings = Globals.GetSettings(Path.Combine(Globals.LuskiPath, "UpdaterSettings.json"), UpdaterSettingsContext.Default.UpdaterSettings);
//Globals.Luski.LoadedServers.First().CreateAccount("JacobTech", "JacobGuin12173*", "JacobTech", "/home/jacob/Pictures/Logo.png", CancellationToken.None);
Task.WaitAll(bbb.ToArray());
if (!Globals.Luski.IsAnyServerLoggedin)
_ = Globals.Luski.LoadedServers.First().Login("JacobTech", "JacobGuin12173*", CancellationToken.None).Result;
Image<Rgba32> Logo = SixLabors.ImageSharp.Image.Load<Rgba32>(Tools.GetResourceStream(Assembly.GetExecutingAssembly(), "Luski.Resources.Textures.Luski.png"));
if (Globals.UpdaterSettings.Updater is null) Globals.UpdaterSettings.Updater = string.Empty;
Image<Rgba32> Logo = SixLabors.ImageSharp.Image.Load<Rgba32>(Globals.GetResource("Textures.Luski.png"));
Logo.DangerousTryGetSinglePixelMemory(out Memory<Rgba32> m);
byte[] pixels = new byte[4 * Logo.Width * Logo.Height];
Logo.CopyPixelDataTo(pixels);
@ -51,7 +78,6 @@ try
Globals.ms = new MainScreenWindow();
Globals.ms.CustomF11 = false;
Globals.ms.DrawFrame();
//Globals.ms.Cursor = new MouseCursor(0, 0, Logo.Width, Logo.Height, pixels);
pixels = Array.Empty<byte>();
Globals.ms.StartRender();
Globals.ms.Dispose();
@ -88,6 +114,8 @@ if (Globals.Download)
}
Process p = new();
p.StartInfo.FileName = Globals.UpdaterSettings.Updater;
p.StartInfo.UseShellExecute = true;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.WorkingDirectory = new FileInfo(Globals.UpdaterSettings.Updater!).Directory!.FullName;
p.StartInfo.Arguments = $"\"{string.Join("\" \"", arguments)}\"";
p.Start();

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@ -1,242 +0,0 @@
using System.Security.Cryptography;
using System.Text;
using System.Text.Json;
namespace Luski;
public class Temp
{
internal static string pw = "bobbob";
public static class File
{
internal static void SetOfflineKey(string key)
{
MakeFile("Server.GetKeyFilePath", pw);
LuskiDataFile? fileLayout = JsonSerializer.Deserialize<LuskiDataFile>(FileString("Server.GetKeyFilePath", pw));
fileLayout.OfflineKey = key;
fileLayout.Save("Server.GetKeyFilePath", pw);
}
internal static string? GetOfflineKey()
{
MakeFile("/home/jacob/.config/JacobTech/Luski/Dev/win-x64/Data/1/keys.lsk", pw);
LuskiDataFile? fileLayout = JsonSerializer.Deserialize<LuskiDataFile>(FileString("Server.GetKeyFilePath", pw));
return fileLayout?.OfflineKey;
}
public static LuskiDataFile GetFile()
{
MakeFile("/home/jacob/.config/JacobTech/Luski/Dev/win-x64/Data/2/keys.lsk", pw);
return JsonSerializer.Deserialize<LuskiDataFile>(FileString("/home/jacob/.config/JacobTech/Luski/Dev/win-x64/Data/2/keys.lsk", pw))!;
}
private static string FileString(string path, string password)
{
byte[] passwordBytes = Encoding.UTF8.GetBytes(password);
byte[] salt = new byte[100];
FileStream fsCrypt = new(path, FileMode.Open);
fsCrypt.Read(salt, 0, salt.Length);
RijndaelManaged AES = new()
{
KeySize = 256,
BlockSize = 128
};
Rfc2898DeriveBytes key = new(passwordBytes, salt, 50000);
AES.Key = key.GetBytes(AES.KeySize / 8);
AES.IV = key.GetBytes(AES.BlockSize / 8);
AES.Padding = PaddingMode.PKCS7;
AES.Mode = CipherMode.CFB;
CryptoStream cs = new(fsCrypt, AES.CreateDecryptor(), CryptoStreamMode.Read);
MemoryStream fsOut = new();
int read;
byte[] buffer = new byte[1048576];
try
{
while ((read = cs.Read(buffer, 0, buffer.Length)) > 0)
{
fsOut.Write(buffer, 0, read);
}
}
catch (CryptographicException ex_CryptographicException)
{
Console.WriteLine("CryptographicException error: " + ex_CryptographicException.Message);
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
}
fsOut.Seek(0, SeekOrigin.Begin);
using BinaryReader reader = new(fsOut);
byte[] by = reader.ReadBytes((int)fsOut.Length);
fsOut.Close();
fsCrypt.Close();
return Encoding.UTF8.GetString(by);
}
public static class Channels
{
private static string GetKey(long channel)
{
LuskiDataFile? fileLayout;
IEnumerable<ChannelLayout>? lis;
try
{
#pragma warning disable CS8603 // Possible null reference return.
// if (channel == 0) return myPrivateKey;
#pragma warning restore CS8603 // Possible null reference return.
MakeFile("Server.GetKeyFilePath", pw);
fileLayout = JsonSerializer.Deserialize<LuskiDataFile>(FileString("Server.GetKeyFilePath", pw));
lis = fileLayout?.channels?.Where(s => s.id == channel);
if (lis?.Count() > 0)
{
return lis.First().key;
}
throw new Exception("You dont have a key for that channel");
}
finally
{
fileLayout = null;
lis = null;
}
}
internal static string GetKeyBranch(long channel)
{
LuskiDataFile? fileLayout;
IEnumerable<ChannelLayout>? lis;
try
{
#pragma warning disable CS8603 // Possible null reference return.
// if (channel == 0) return myPrivateKey;
#pragma warning restore CS8603 // Possible null reference return.
MakeFile("Server.GetKeyFilePathBr(branch.ToString())", pw);
fileLayout = JsonSerializer.Deserialize<LuskiDataFile>(FileString("", pw));
lis = fileLayout?.channels?.Where(s => s.id == channel);
if (lis?.Count() > 0)
{
return lis.First().key;
}
throw new Exception("You dont have a key for that channel");
}
finally
{
fileLayout = null;
lis = null;
}
}
public static void AddKey(long channel, string key)
{
MakeFile("Server.GetKeyFilePath", pw);
LuskiDataFile? fileLayout = JsonSerializer.Deserialize<LuskiDataFile>(FileString("Server.GetKeyFilePath", pw));
fileLayout?.Addchannelkey(channel, key);
fileLayout?.Save("Server.GetKeyFilePath", pw);
}
}
private static void MakeFile(string dir, string password)
{
if (!System.IO.File.Exists(dir))
{
LuskiDataFile? l = JsonSerializer.Deserialize<LuskiDataFile>("{\"channels\":[]}");
l?.Save(dir, password);
}
}
public class LuskiDataFile
{
public static LuskiDataFile GetDataFile(string path, string password)
{
MakeFile(path, password);
return JsonSerializer.Deserialize<LuskiDataFile>(FileString(path, password));
}
internal static LuskiDataFile GetDefualtDataFile()
{
return GetDataFile("Server.GetKeyFilePath", pw);
}
public ChannelLayout[]? channels { get; set; } = default!;
public string? OfflineKey { get; set; } = default!;
public void Save(string file, string password)
{
byte[] salt = new byte[100];
RandomNumberGenerator? provider = RandomNumberGenerator.Create();
provider.GetBytes(salt);
FileStream fsCrypt = new(file, FileMode.Create);
byte[] passwordBytes = Encoding.UTF8.GetBytes(password);
RijndaelManaged AES = new()
{
KeySize = 256,
BlockSize = 128,
Padding = PaddingMode.PKCS7
};
Rfc2898DeriveBytes key = new(passwordBytes, salt, 50000);
AES.Key = key.GetBytes(AES.KeySize / 8);
AES.IV = key.GetBytes(AES.BlockSize / 8);
AES.Mode = CipherMode.CFB;
fsCrypt.Write(salt, 0, salt.Length);
CryptoStream cs = new(fsCrypt, AES.CreateEncryptor(), CryptoStreamMode.Write);
string tempp = JsonSerializer.Serialize(this);
MemoryStream fsIn = new(Encoding.UTF8.GetBytes(tempp));
byte[] buffer = new byte[1048576];
int read;
try
{
while ((read = fsIn.Read(buffer, 0, buffer.Length)) > 0)
{
cs.Write(buffer, 0, read);
}
fsIn.Close();
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
}
finally
{
cs.Close();
fsCrypt.Close();
}
}
public void Addchannelkey(long chan, string Key)
{
List<ChannelLayout>? chans = channels?.ToList();
if (chans is null) chans = new();
if (!(chans?.Where(s => s.id == chan).Count() > 0))
{
ChannelLayout l = new()
{
id = chan,
key = Key
};
chans?.Add(l);
channels = chans?.ToArray();
}
else
{
chans.Remove(chans.Where(s => s.id == chan).First());
ChannelLayout l = new()
{
id = chan,
key = Key
};
chans?.Add(l);
channels = chans?.ToArray();
}
}
}
public class ChannelLayout
{
public long id { get; set; } = default!;
public string key { get; set; } = default!;
}
}
}