2023-02-18 22:48:06 -05:00

75 lines
3.2 KiB
C#

using System.Reflection;
using GraphicsManager;
using GraphicsManager.Interfaces;
using GraphicsManager.Objects;
using GraphicsManager.Objects.Core;
using Luski.net.JsonTypes;
using Luski.GUI.MainScreen.Interfaces;
using OpenTK.Graphics.OpenGL4;
using OpenTK.Mathematics;
namespace Luski.GUI.MainScreen.UI;
public class Group : UserControl, IChannelPick
{
public SocketTextChannel Channel { get; set; }
// private string members = "";
public Group(SocketGroupChannel chan)
{
Label Status, Username;
Rectangle r, rr;
Channel = chan;
Size = new((int)(240 * Globals.Settings.Scale), (int)(62* Globals.Settings.Scale));
BackgroundColor = new(34, 34, 34, 255);
Controls.Add(rr=new Rectangle(Globals.ms.TextureManager.AddTexture(Tools.GetResourceBytes(Assembly.GetExecutingAssembly(),
"Luski.Resources.Textures.Status.png"))) { Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context],
Location = new((int)(10 * Globals.Settings.Scale), (int)(10 * Globals.Settings.Scale)),
Size = new ((int)(42 * Globals.Settings.Scale)),
BackgroundColor = new(64, 220, 64, 255)
});
r = new Rectangle(rr.Textures.First()) { Location = new(rr.Location.X + 4,rr.Location.Y + 4), Size = new(rr.Size.X - 8)};
Controls.Add(rr);
Texture tex = Globals.ms.TextureManager.AddTexture(chan.GetPicture(CancellationToken.None).Result);
tex.Unit = TextureUnit.Texture1;
r.Textures.Add(tex);
r.Shader = Rectangle.DefaultAlphaTextureShader[Globals.ms.Context];
Controls.Add(r);
Controls.Add(Username = new Label() { Font = Globals.DefaultFont, Text = chan.Title});
string sl = "Online";
if (chan.Id != 0)
{
sl = chan.Members.Count + " Members";
}
Controls.Add(Status = new Label() { Scale = 0.7f, Font = Globals.DefaultFont, Text = sl, Location = new((int)(38.5 * Globals.Settings.Scale),(int)(24 * Globals.Settings.Scale))});
this.Clicked += AllOnClicked;
Username.Location = new((int)(58 * Globals.Settings.Scale),
(rr.Location.Y + (rr.Size.Y / 2) - ((Username.TrueHeight + 5 + Status.TrueHeight) / 2) -
(Username.Size.Y - (Username.TrueHeight)))
);
Status.Location = new(Username.Location.X, (int)(Username.Location.Y + Username.Font.PixelHeight + 5 - (Status.Size.Y - Status.TrueHeight)));
if (chan.Id == 0) return;
ContextMenu = new((int)(150 * Globals.Settings.Scale));
RoundedButton rrr;
ContextMenu.Items.Add(rrr=new()
{
InsideColor = new(28, 28, 28, 255), BorderColor = Color4.DarkCyan,
Size = new((int)(25 * Globals.Settings.Scale)), Font = Globals.DefaultFont, Text = "Export Keys"
});
rrr.Clicked += RrOnClicked;
}
private Task RrOnClicked(IRenderObject arg)
{
_ = Channel.SendKeysToUsers(CancellationToken.None);
ContextMenu!.HideContext(Window!);
return Task.CompletedTask;
}
private Task AllOnClicked(IRenderObject arg)
{
if (ClickCon is not null) _ = ClickCon.Invoke(this);
return Task.CompletedTask;
}
public event Func<IChannelPick, Task>? ClickCon;
}