I can't seem to get a command to run when a button is pressed.
I can make it close the UI with `Close = FormCompMain` but I can't figure out why the command won't run. The command runs fine when manually called.
Does anyone know how I can resolve this?
private string FormCompMain = "form-coomponent-main";
private void OpenForm(BasePlayer player)
{
var container = new CuiElementContainer();
container.Add(new CuiPanel
{
CursorEnabled = true,
Image =
{
Color = "0 0 0 0"
},
RectTransform =
{
AnchorMin = "0 0",
AnchorMax = "1 1"
},
}, "Overlay", FormCompMain);
container.Add(new CuiButton
{
RectTransform =
{
AnchorMin = "0.3 0.3",
AnchorMax = "0.7 0.4"
},
Button =
{
Color = "0.8 0.8 0.8 1",
Command = "mycommand"
},
Text =
{
Text = "Text",
Color = "0 0 0 1",
FontSize = 20,
Align = TextAnchor.MiddleCenter
}
}, FormCompMain);
CuiHelper.DestroyUi(player, FormCompMain);
CuiHelper.AddUi(player, container);
}
[Command("mycommand")]
public void mycommand(BasePlayer player, string label, string[] args)
{
// Do stuff
CuiHelper.DestroyUi(player, FormCompMain);
}