2024-04-01 10:12:49 -04:00

78 lines
2.8 KiB
C#

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 = 5.ScaleInt(),
Size = new(350.ScaleInt(), 220.ScaleInt()),
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(34.ScaleInt()),
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 = cn.Size,
Anchor = ObjectAnchor.Bottom | ObjectAnchor.Left | ObjectAnchor.Right,
TextLocation = TextLocation.PostiveTureCenterLeft
});
fl.Controls.Add(new Label(Globals.DefaultFont) {Text = "\n "});
fl.Controls.Add(btn = new(Globals.ms.TextureManager.GetTextureResource("Textbox.png"))
{
Size = new(40.ScaleInt()),
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();
}
}