private void OnPlayerConnected(BasePlayer player)
{
CuiElementContainer container = new CuiElementContainer();
// Создание фона меню
container.Add(new CuiPanel
{
Image = { Color = "0 0 0 0.5" },
RectTransform = { AnchorMin = "0 0.9", AnchorMax = "0.1 1" }
}, "Hud", "menuBackground");
// Добавление картинки с вызовом меню по нажатию на нее
container.Add(new CuiButton
{
Button = { Command = "showMenu", Color = "0 0 0 0" },
RectTransform = { AnchorMin = "0.1 0.9", AnchorMax = "0.2 1" },
Text = { Text = "" },
CursorEnabled = true
}, "menuBackground", "menuButton");
CuiHelper.AddUi(player, container);
}
[ChatCommand("showMenu")]
private void ShowMenu(BasePlayer player)
{
CuiElementContainer container = new CuiElementContainer();
// Создание фона меню
container.Add(new CuiPanel
{
Image = { Color = "0 0 0 0.5" },
RectTransform = { AnchorMin = "0 0", AnchorMax = "0.3 1" }
}, "Hud", "sideMenu");
// Добавление вкладок
for (int i = 0; i < 15; i++)
{
container.Add(new CuiButton
{
Button = { Command = $"showTab{i}", Color = "0 0 0 0" },
RectTransform = { AnchorMin = "0.05 0.9", AnchorMax = "0.25 1" },
Text = { Text = $"Tab {i+1}" },
CursorEnabled = true
}, "sideMenu", $"tabButton{i}");
container.Add(new CuiElement
{
Parent = "sideMenu",
Components =
{
new CuiRawImageComponent { Png = "base64_encoded_image", Color = "1 1 1 1" },
new CuiRectTransformComponent { AnchorMin = "0 0.8", AnchorMax = "0.3 0.9" }
}
}, $"tab{i}", $"tabImage{i}");
container.Add(new CuiElement
{
Parent = "sideMenu",
Components =
{
new CuiTextComponent { Text = $"Tab {i+1} content" },
new CuiRectTransformComponent { AnchorMin = "0 0", AnchorMax = "0.3 0.8" }
}
}, $"tab{i}", $"tabContent{i}");
}
CuiHelper.AddUi(player, container);
}
[ChatCommand("showTab{i}")]
private void ShowTab(BasePlayer player, int i)
{
CuiHelper.DestroyUi(player, $"sideMenu/tab{i}");
}