C#:
using System.Linq;
using System.Text;
using Newtonsoft.Json;
using Oxide.Core;
using Oxide.Game.Rust.Cui;
using System.Collections.Generic;
using Oxide.Core.Plugins;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("Menu SETTINGS", "WOLF#4002", "0.0.1")]
public class WMenuS : RustPlugin
{
private void OnServerInitialized()
{
ImageLibrary.Call("AddImage", "https://rustplugins.top/api/image/menu/active.png", "ac");
ImageLibrary.Call("AddImage", "https://rustplugins.top/api/image/menu/not.png", "noac");
}
[PluginReference] Plugin ImageLibrary;
private static string MenS = "UI_MenuS";
private static string PoiS = "UI_PointS";
private static string InternalS = "WOLFS";
[ChatCommand("Set")]
private void CmdChatS(BasePlayer player, string command, string[] args)
{
UIS(player);
}
void UIS(BasePlayer player)
{
CuiElementContainer container = new CuiElementContainer();
CuiHelper.DestroyUi(player, MenS);
CuiHelper.DestroyUi(player, InternalS);
container.Add(new CuiPanel
{
CursorEnabled = true,
RectTransform = { AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0" },
Image = { Color = "0.25 0.50 0.50 0" },
}, "WOLF", MenS);
container.Add(new CuiPanel
{
RectTransform = { AnchorMin = "0.01 0.9", AnchorMax = "0.99 0.98", OffsetMax = "0 0" },
Image = { Color = "1.00 0.50 0.25 0" },
}, MenS, PoiS);
container.Add(new CuiPanel
{
RectTransform = { AnchorMin = "0.01 0.02", AnchorMax = "0.99 0.85", OffsetMax = "0 0" },
Image = { Color = "1.00 0.50 0.25 0" },
}, MenS, InternalS);
CuiHelper.AddUi(player, container);
DrawPoints(player);
}
void DrawPoints(BasePlayer player, MenuPoint choosed = null)
{
CuiElementContainer container = new CuiElementContainer();
float width = 0.2f, height = 0.9f, startxBox = 0.0f, startyBox = 0.92f - height, xmin = startxBox, ymin = startyBox;
foreach (var point in Settings.Points)
{ CuiHelper.DestroyUi(player, PoiS + Settings.Points.IndexOf(point));
string color = point == choosed ? "1.00 0.53 0.53 1" : "0.86 0.77 0.67 1";
string color1 = point == choosed ? "0.84 0.17 0.37 0" : "1 1 1 0";
string img = point == choosed ? (string) ImageLibrary.Call("GetImage", "ac") : (string) ImageLibrary.Call("GetImage", "noac");
container.Add(new CuiElement
{
Parent = PoiS,
Name = PoiS + Settings.Points.IndexOf(point),
Components =
{
new CuiRawImageComponent { Png = img},
new CuiRectTransformComponent{AnchorMin = $"{xmin} {ymin}", AnchorMax = $"{xmin + width} {ymin + height * 1}", OffsetMin = "2 2", OffsetMax = "-2 -2" },
}
});
container.Add(new CuiElement
{
Parent = PoiS + Settings.Points.IndexOf(point),
Components =
{
new CuiTextComponent {Color = color,Text = point.DisplayName, Align = TextAnchor.MiddleLeft, FontSize = 12},
new CuiRectTransformComponent { AnchorMin = "0.3 0", AnchorMax = "1 1" },
new CuiOutlineComponent { Color = "0 0 0 1", Distance = "1 1" }
}
});
container.Add(new CuiButton
{
RectTransform = {AnchorMin = "0 0", AnchorMax = "1 1" },
Button = { Command = $"menuS choose {Settings.Points.IndexOf(point)}", Color = color1 },
Text = { Text = "", Align = TextAnchor.MiddleLeft, Font = "robotocondensed-bold.ttf", FontSize = 20, Color = color }
},PoiS + Settings.Points.IndexOf(point));
xmin += width;
if (xmin + width >= 4)
{
xmin = startxBox;
ymin -= height;
}
}
CuiHelper.AddUi(player, container);
}
[ConsoleCommand("menuS")]
private void CmdConsoleRustMenu(ConsoleSystem.Arg args)
{
var player = args.Player();
if (player == null || !args.HasArgs(1)) return;
switch (args.Args[0].ToLower())
{
case "close":
{
CuiHelper.DestroyUi(player, MenS);
CuiHelper.DestroyUi(player, PoiS);
CuiHelper.DestroyUi(player, InternalS);
break;
}
case "choose":
{
int chooseIndex = -1;
if (!int.TryParse(args.Args[1], out chooseIndex)) return;
var chooseElement = Settings.Points.ElementAtOrDefault(chooseIndex);
if (chooseElement == null) return;
CuiHelper.DestroyUi(player, InternalS);
CuiElementContainer container = new CuiElementContainer();
container.Add(new CuiPanel
{
RectTransform = { AnchorMin = "0.01 0.02", AnchorMax = "0.99 0.85", OffsetMax = "0 0" },
Image = { Color = "1.00 0.50 0.25 0" },
}, MenS, InternalS);
CuiHelper.AddUi(player, container);
player.SendConsoleCommand(chooseElement.DrawMethod);
DrawPoints(player, chooseElement);
Effect effect = new Effect("assets/bundled/prefabs/fx/notice/stack.world.fx.prefab", player, 0, new Vector3(), new Vector3());
EffectNetwork.Send(effect, player.Connection);
break;
}
}
}
private class MenuPoint
{
[JsonProperty("Name Button")]
public string DisplayName;
[JsonProperty("Button")]
public string DrawMethod;
}
private class Configuration
{
[JsonProperty("Button")]
public List<MenuPoint> Points = new List<MenuPoint>();
public static Configuration Generate()
{
return new Configuration
{
Points = new List<MenuPoint>
{
new MenuPoint
{
DisplayName = "KIT",
DrawMethod = "chat.say /kit",
},
new MenuPoint
{
DisplayName = "KITtjtjmktkfyS",
DrawMethod = "chat.say /kits",
},
new MenuPoint
{
DisplayName = "",
DrawMethod = "",
},
new MenuPoint
{
DisplayName = "",
DrawMethod = "",
},
new MenuPoint
{
DisplayName = "",
DrawMethod = "",
},
new MenuPoint
{
DisplayName = "",
DrawMethod = "",
},
new MenuPoint
{
DisplayName = "",
DrawMethod = "",
},
new MenuPoint
{
DisplayName = "",
DrawMethod = "",
},
new MenuPoint
{
DisplayName = "",
DrawMethod = "",
},
new MenuPoint
{
DisplayName = "",
DrawMethod = "",
},
new MenuPoint
{
DisplayName = "",
DrawMethod = "",
},
new MenuPoint
{
DisplayName = "",
DrawMethod = "",
},
new MenuPoint
{
DisplayName = "",
DrawMethod = "",
},
new MenuPoint
{
DisplayName = "",
DrawMethod = "",
},
new MenuPoint
{
DisplayName = "",
DrawMethod = "",
},
},
};
}
}
private static Configuration Settings;
protected override void LoadConfig()
{
base.LoadConfig();
try
{
Settings = Config.ReadObject<Configuration>();
}
catch
{
PrintWarning($"Error reading config, creating one new config!");
LoadDefaultConfig();
}
SaveConfig();
}
protected override void LoadDefaultConfig() => Settings = Configuration.Generate();
protected override void SaveConfig() => Config.WriteObject(Settings);
}
}