C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
using System.Collections.Generic;
using UnityEngine;
using Oxide.Game.Rust.Cui;
using System;
using System.Linq;
using Oxide.Core.Plugins;
using Oxide.Core;
namespace Oxide.Plugins {
[Info("Universal UI", "Absolut", "2.1.5")]
[Description("A fully customizable UI for info and buttons")]
class UniversalUI : RustPlugin {
[PluginReference]
Plugin ImageLibrary, Kits;
string TitleColor = "<color=orange>";
string MsgColor = "<color=#A9A9A9>";
bool SkinsReady = false;
private Dictionary<ulong, screen> UniversalUIInfo = new Dictionary<ulong, screen>();
class screen {
public int section;
public int page;
public bool open;
public int showSection;
public bool admin;
}
private bool Debugging;
private List<ulong> NoInfo = new List<ulong>();
private Dictionary<ulong, DelayedCommand> OnDelay = new Dictionary<ulong, DelayedCommand>();
class DelayedCommand {
public bool closeui;
public List<string> args;
}
private Dictionary<string, Timer> timers = new Dictionary<string, Timer>();
#region Server Hooks
void Loaded() {
lang.RegisterMessages(messages, this);
Debugging = false;
}
void Unload() {
foreach (BasePlayer p in BasePlayer.activePlayerList) {
DestroyPlayer(p);
}
foreach (var entry in timers) entry.Value.Destroy();
timers.Clear();
}
void OnServerInitialized() {
try {
ImageLibrary.Call("isLoaded", null);
}
catch (Exception) {
PrintWarning($"ImageLibrary is missing.Unloading {Name} as it will not work without ImageLibrary.");
Interface.Oxide.UnloadPlugin(Name);
return;
}
LoadVariables();
RegisterPermissions();
foreach (BasePlayer p in BasePlayer.activePlayerList) OnPlayerInit(p);
GetAllImages();
timers.Add("info", timer.Once(configData.InfoInterval * 60, () => InfoLoop()));
}
private void OnPlayerInit(BasePlayer player) {
if (player != null) {
if (player.HasPlayerFlag(BasePlayer.PlayerFlags.ReceivingSnapshot)) {
timer.Once(5, () => OnPlayerInit(player));
return;
}
if (configData.MenuKeyBinding != "") player.Command($"bind {configData.MenuKeyBinding} \"UI_OpenUniversalUI\"");
if (configData.InfoInterval != 0) if (configData.MenuKeyBinding != "") GetSendMSG(player, "UIInfo", configData.MenuKeyBinding.ToString());
else GetSendMSG(player, "UIInfo1");
if (configData.ForceOpenOnJoin) OpenUniversalUI(player);
}
}
private void OnPlayerRespawned(BasePlayer player) {
DestroyUniversalUI(player);
}
private void OnPlayerDisconnected(BasePlayer player) {
DestroyPlayer(player);
}
object OnServerCommand(ConsoleSystem.Arg arg) {
var player = arg.Connection?.player as BasePlayer;
if (player == null) return null;
if (OnDelay.ContainsKey(player.userID) && arg.cmd?.FullName == "chat.say") {
if (arg.Args.Contains("quit")) {
OnDelay.Remove(player.userID);
GetSendMSG(player, "ExitDelayed");
return false;
}
foreach (var entry in arg.Args) OnDelay[player.userID].args.Add(entry);
RunCommand(player, OnDelay[player.userID].args.ToArray());
return false;
}
return null;
}
private void RunCommand(BasePlayer player, string[] command) {
if (command[0] == "chat.say") {
rust.RunClientCommand(player, $"chat.say 0", string.Join(" ", command.Skip(1).ToArray()));
if(Debugging) Puts($"Chat say:");
}
else {
rust.RunClientCommand(player, string.Join(" ", command.ToArray()));
if (Debugging) Puts($"Console Command: {string.Join(" ", command.ToArray())}");
}
if (OnDelay.ContainsKey(player.userID)) OnDelay.Remove(player.userID);
}
#endregion
#region Functions
[ConsoleCommand("UI_OpenUniversalUI")]
private void cmdUI_OpenUniversalUI(ConsoleSystem.Arg arg) {
var player = arg.Connection.player as BasePlayer;
if (player == null) return;
if (UniversalUIInfo.ContainsKey(player.userID)) if (!UniversalUIInfo[player.userID].open) {
UniversalUIInfo[player.userID].open = true;
OpenUniversalUI(player);
}
else DestroyUniversalUI(player);
else OpenUniversalUI(player);
}
private void OpenUniversalUI(BasePlayer player) {
if (!SkinsReady) {
GetSendMSG(player, "ImageLibraryNotReady");
return;
}
if (!UniversalUIInfo.ContainsKey(player.userID)) UniversalUIInfo.Add(player.userID, new screen {
page = 0, section = 0, showSection = 0, open = true
}
);
UniversalUIPanel(player);
if (!NoInfo.Contains(player.userID)) BackgroundPanel(player);
return;
}
[ConsoleCommand("UI_DestroyUniversalUI")]
private void cmdUI_DestroyUniversalUI(ConsoleSystem.Arg arg) {
var player = arg.Connection.player as BasePlayer;
if (player == null) return;
DestroyUniversalUI(player);
}
[ConsoleCommand("UI_OpenInfoUI")]
private void cmdUI_OpenInfoUI(ConsoleSystem.Arg arg) {
var player = arg.Connection.player as BasePlayer;
if (player == null) return;
if (NoInfo.Contains(player.userID)) NoInfo.Remove(player.userID);
OpenUniversalUI(player);
}
[ConsoleCommand("UI_HideInfo")]
private void cmdUI_HideInfo(ConsoleSystem.Arg arg) {
var player = arg.Connection.player as BasePlayer;
if (player == null) return;
if (!NoInfo.Contains(player.userID)) NoInfo.Add(player.userID);
CuiHelper.DestroyUi(player, PanelInfo);
OpenUniversalUI(player);
}
private object KitMax(string kitname) => Kits?.Call("KitMax", kitname);
public int GetKitMax(string kitname) {
var Max = KitMax(kitname);
if (Max != null) {
return Convert.ToInt32(Max);
}
return 0;
}
private object KitItemAmount(string kitname, int ID) => Kits?.Call("KitItemAmount", kitname, ID);
public int GetKitItemAmount(string kitname, int ID) {
var amount = KitItemAmount(kitname, ID);
if (amount != null) {
return Convert.ToInt32(amount);
}
return 0;
}
private object KitDescription(string kitname) => Kits?.Call("KitDescription", kitname);
public string GetKitDescription(string kitname) {
var Desc = KitDescription(kitname);
if (Desc != null) {
if (Desc is string) {
string dsc = Desc as string;
return dsc;
}
}
return "NONE";
}
private object KitImage(string kitname) => Kits?.Call("KitImage", kitname);
public string GetKitImage(string kitname) {
var image = KitImage(kitname);
if (image != null) {
if (image is string) {
string img = image as string;
return img;
}
}
return "http://i.imgur.com/xxQnE1R.png";
}
private object KitCooldown(string kitname) => Kits?.Call("KitCooldown", kitname);
public int GetKitCooldown(string kitname) {
var cooldown = KitCooldown(kitname);
if (cooldown != null) {
return Convert.ToInt32(cooldown) / 60;
}
return 0;
}
private object GetKits() => Kits?.Call("GetAllKits");
public string[] GetKitNames() {
var kits = GetKits();
if (kits != null) {
if (kits is string[]) {
var array = kits as string[];
return array;
}
}
return null;
}
void AskForPageType(BasePlayer player, int page) {
if (!UniversalUIInfo.ContainsKey(player.userID)) return;
DestroyUniversalUI(player);
CuiHelper.DestroyUi(player, PanelInfo);
var element = UI.CreateElementContainer(PanelInfo, "0 0 0 0", "0.3 0.4", "0.7 0.6", true);
var types = Enum.GetValues(typeof(PageType)).Cast<PageType>();
var amount = types.Count();
var i = 0;
float[] pos;
foreach (var entry in types) {
pos = SelectionButtonLocation(i, amount);
UI.LoadImage(ref element, PanelInfo, TryForImage(entry.ToString()), $"{pos[0]} {pos[1]}", $"{pos[2]} {pos[3]}");
UI.CreateTextOutline(ref element, PanelInfo, UIColors["white"], UIColors["black"], GetMSG("Type", player, entry.ToString()), 14, $"{pos[0]} {pos[1]}", $"{pos[2]} {pos[3] +.05f}", TextAnchor.UpperCenter);
UI.CreateButton(ref element, PanelInfo, "0 0 0 0", "", 14, $"{pos[0]} {pos[1]}", $"{pos[2]} {pos[3]}", $"UI_SetPageType {entry.ToString()} {page}", TextAnchor.MiddleCenter);
i++;
}
CuiHelper.AddUi(player, element);
}
[ConsoleCommand("UI_SetPageType")]
private void cmdUI_SetPageType(ConsoleSystem.Arg arg) {
var player = arg.Connection.player as BasePlayer;
if (player == null) return;
if (!UniversalUIInfo.ContainsKey(player.userID)) return;
DestroyUniversalUI(player);
if (configData.sections.ContainsKey(UniversalUIInfo[player.userID].section)) {
configData.sections[UniversalUIInfo[player.userID].section].pages[Convert.ToInt32(arg.Args[1])].type = (PageType)Enum.Parse(typeof(PageType), arg.Args[0]);
Config.WriteObject(configData, true);
}
else GetSendMSG(player, "SectionNotFound");
OpenUniversalUI(player);
}
private float[] SelectionButtonLocation(int number, int amount) {
var size = Decimal.Divide(1, amount);
Vector2 position = new Vector2(0.03f, (float)(1 - size));
Vector2 dimensions = new Vector2((float)size, .9f);
float offsetY = 0;
float offsetX = (0.015f + dimensions.x) * number;
Vector2 offset = new Vector2(offsetX, offsetY);
Vector2 posMin = position + offset;
Vector2 posMax = posMin + dimensions;
return new float[] {
posMin.x, posMin.y, posMax.x, posMax.y
}
;
}
[ConsoleCommand("UI_AddNewSection")]
private void cmdUI_AddNewSection(ConsoleSystem.Arg arg) {
var player = arg.Connection.player as BasePlayer;
if (player == null) return;
if (!UniversalUIInfo.ContainsKey(player.userID)) return;
var index = 1;
foreach (var entry in configData.sections.Where(k => k.Key == index)) {
index++;
continue;
}
configData.sections.Add(index, new Section {
name = index.ToString().ToUpper(), pages = new List<Page> {
new Page {
page = 0, name = $"Added By {player.displayName}"
}
}
}
);
Config.WriteObject(configData, true);
OpenUniversalUI(player);
}
[ConsoleCommand("UI_RemoveSection")]
private void cmdUI_RemoveSection(ConsoleSystem.Arg arg) {
var player = arg.Connection.player as BasePlayer;
if (player == null) return;
if (!UniversalUIInfo.ContainsKey(player.userID)) return;
if (configData.sections.ContainsKey(UniversalUIInfo[player.userID].section)) configData.sections.Remove(UniversalUIInfo[player.userID].section);
Config.WriteObject(configData, true);
UniversalUIInfo[player.userID].section = 0;
OpenUniversalUI(player);
}
[ConsoleCommand("UI_AddNewPage")]
private void cmdUI_AddNewPage(ConsoleSystem.Arg arg) {
var player = arg.Connection.player as BasePlayer;
if (player == null) return;
if (!UniversalUIInfo.ContainsKey(player.userID)) return;
var existingPages = configData.sections[UniversalUIInfo[player.userID].section].pages;
var index = 0;
foreach (var entry in existingPages.Where(k => k.page == index)) index++;
configData.sections[UniversalUIInfo[player.userID].section].pages.Add(new Page {
page = index, name = $"Added By {player.displayName}", buttons = new List<PageButton> {
new PageButton {
order = 0
}
, new PageButton {
order = 1
}
, new PageButton {
order = 2
}
, new PageButton {
order = 3
}
}
}
);
AskForPageType(player, index);
Config.WriteObject(configData, true);
}
[ConsoleCommand("UI_RemovePage")]
private void cmdUI_RemovePage(ConsoleSystem.Arg arg) {
var player = arg.Connection.player as BasePlayer;
if (player == null) return;
if (!UniversalUIInfo.ContainsKey(player.userID)) return;
foreach (var entry in configData.sections[UniversalUIInfo[player.userID].section].pages.Where(k => k.page == UniversalUIInfo[player.userID].page)) {
configData.sections[UniversalUIInfo[player.userID].section].pages.Remove(entry);
break;
}
Config.WriteObject(configData, true);
UniversalUIInfo[player.userID].page = 0;
OpenUniversalUI(player);
}
[ConsoleCommand("UI_RunConsoleCommand")]
private void cmdUI_RunConsoleCommand(ConsoleSystem.Arg arg) {
var player = arg.Connection.player as BasePlayer;
if (player == null) return;
//Puts(string.Join(" ",arg.Args));
var cmd = "";
if (arg.Args[1] == "delay") {
if (OnDelay.ContainsKey(player.userID)) OnDelay.Remove(player.userID);
OnDelay.Add(player.userID, new DelayedCommand {
closeui = Convert.ToBoolean(arg.Args[0]), args = new List<string>()
}
);
foreach (var e in arg.Args.Skip(2)) OnDelay[player.userID].args.Add(e);
var message = string.Join(" ", arg.Args.Skip(2).ToArray());
//Puts(message);
//if (arg.Args[2] == "chat.say")
// message = string.Join(" ", arg.Args.Skip(3).ToArray());
GetSendMSG(player, "DelayedCMD", message);
DestroyUniversalUI(player);
}
else if (arg.Args[1] == "chat.say") {
cmd = string.Join(" ", arg.Args.Skip(2).ToArray());
rust.RunClientCommand(player, $"chat.say 0", cmd);
if (Convert.ToBoolean(arg.Args[0])) DestroyUniversalUI(player);
}
else {
cmd = string.Join(" ", arg.Args.Skip(1).ToArray());
rust.RunClientCommand(player, $"{cmd}");
if (Convert.ToBoolean(arg.Args[0])) DestroyUniversalUI(player);
}
}
[ConsoleCommand("UI_PageTurn")]
private void cmdUI_PageTurn(ConsoleSystem.Arg arg) {
var player = arg.Connection.player as BasePlayer;
if (player == null) return;
int page = Convert.ToInt32(arg.Args[0]);
UniversalUIInfo[player.userID].page = page;
UIInfoPanel(player);
}
[ConsoleCommand("UI_SwitchSection")]
private void cmdUI_SwitchSection(ConsoleSystem.Arg arg) {
var player = arg.Connection.player as BasePlayer;
if (player == null) return;
var section = Convert.ToInt32(arg.Args[0]);
if (section != 0) {
var admin = arg.Args[1];
if (admin == "false") {
if (arg.Args.Length > 2) if (!isAllowed(player, false, arg.Args[2])) {
GetSendMSG(player, "NotAuth");
return;
}
}
else {
if (!isAllowed(player, true)) {
GetSendMSG(player, "NotAuth");
return;
}
}
}
UniversalUIInfo[player.userID].section = section;
UniversalUIInfo[player.userID].page = 0;
UIInfoPanel(player);
}
[ConsoleCommand("UI_InfoSectionButtonChange")]
private void cmdUI_InfoSectionButtonChange(ConsoleSystem.Arg arg) {
var player = arg.Connection.player as BasePlayer;
if (player == null) return;
var section = Convert.ToInt32(arg.Args[0]);
if (Debugging) Puts($"{section}");
UniversalUIInfo[player.userID].showSection = section;
UIInfoPanel(player);
}
private void DestroyUniversalUI(BasePlayer player) {
if (UniversalUIInfo.ContainsKey(player.userID)) if (UniversalUIInfo[player.userID].open) UniversalUIInfo[player.userID].open = false;
CuiHelper.DestroyUi(player, PanelStatic);
CuiHelper.DestroyUi(player, PanelUUI);
CuiHelper.DestroyUi(player, PanelInfo);
}
private void DestroyPlayer(BasePlayer player) {
if (UniversalUIInfo.ContainsKey(player.userID)) UniversalUIInfo.Remove(player.userID);
CuiHelper.DestroyUi(player, PanelUUI);
CuiHelper.DestroyUi(player, PanelInfo);
//player.Command("bind tab \"inventory.toggle\"");
//player.Command("bind q \"inventory.togglecrafting\"");
//player.Command("bind escape \"\"");
if (configData.MenuKeyBinding != "") player.Command($"bind {configData.MenuKeyBinding} \"\"");
}
private string GetLang(string msg, BasePlayer player = null) {
if (messages.ContainsKey(msg)) return lang.GetMessage(msg, this);
else return msg;
}
private void GetSendMSG(BasePlayer player, string message, string arg1 = "", string arg2 = "", string arg3 = "") {
string msg = string.Format(lang.GetMessage(message, this, player.UserIDString), arg1, arg2, arg3);
SendReply(player, TitleColor + lang.GetMessage("title", this, player.UserIDString) + "</color>" + MsgColor + msg + "</color>");
}
private string GetMSG(string message, BasePlayer player = null, string arg1 = "", string arg2 = "", string arg3 = "") {
string p = null;
if (player != null) p = player.UserIDString;
string msg = string.Format(lang.GetMessage(message, this, p), arg1, arg2, arg3);
return msg;
}
bool isAuth(BasePlayer player) {
if (player.net.connection != null) if (player.net.connection.authLevel < 2 && !permission.UserHasPermission(player.UserIDString, "UniversalUI.admin")) return false;
return true;
}
private void RegisterPermissions() {
if (!permission.PermissionExists("UniversalUI.admin")) permission.RegisterPermission("UniversalUI.admin", this);
foreach (var entry in configData.buttons) if (!string.IsNullOrEmpty(entry.Value.permission) && !permission.PermissionExists("UniversalUI." + entry.Value.permission)) permission.RegisterPermission("UniversalUI."+entry.Value.permission, this);
foreach (var section in configData.sections) {
if (!string.IsNullOrEmpty(section.Value.permission) && !permission.PermissionExists("UniversalUI." + section.Value.permission)) permission.RegisterPermission("UniversalUI." + section.Value.permission, this);
foreach (var page in section.Value.pages) foreach (var button in page.buttons) if (!string.IsNullOrEmpty(button.permission) && !permission.PermissionExists("UniversalUI." + button.permission)) permission.RegisterPermission("UniversalUI." + button.permission, this);
}
}
bool isAllowed(BasePlayer player, bool adminonly, string perm = "") {
if (isAuth(player)) return true;
if (adminonly) return false;
if (!string.IsNullOrEmpty(perm)) if (!permission.UserHasPermission(player.UserIDString, "UniversalUI." + perm)) return false;
return true;
}
private string TryForImage(string shortname, ulong skin = 99) {
if (shortname.Contains("http")) return shortname;
if (skin == 99) skin = (ulong)ResourceId;
return GetImage(shortname, skin, true);
}
private bool Valid(string name, ulong id = 99) {
if (id == 99) id = (ulong)ResourceId;
return HasImage(name, id);
}
public string GetImage(string shortname, ulong skin = 0, bool returnUrl = false) => (string)ImageLibrary.Call("GetImage", shortname.ToLower(), skin, returnUrl);
public bool HasImage(string shortname, ulong skin = 0) => (bool)ImageLibrary.Call("HasImage", shortname.ToLower(), skin);
public bool AddImage(string url, string shortname, ulong skin = 0) => (bool)ImageLibrary?.Call("AddImage", url, shortname.ToLower(), skin);
public List<ulong> GetImageList(string shortname) => (List<ulong>)ImageLibrary.Call("GetImageList", shortname.ToLower());
public bool isReady() => (bool)ImageLibrary?.Call("IsReady");
#endregion
#region UI Creation
private string PanelStatic = "PanelStatic";
private string PanelUUI = "PanelUUI";
private string PanelInfo = "PanelInfo";
public class UI {
static public CuiElementContainer CreateElementContainer(string panelName, string color, string aMin, string aMax, bool cursor = false) {
var NewElement = new CuiElementContainer() {
{
new CuiPanel {
Image = {
Color = color
}
, RectTransform = {
AnchorMin = aMin, AnchorMax = aMax
}
, CursorEnabled = cursor
}
, new CuiElement().Parent, panelName
}
}
;
return NewElement;
}
static public void CreatePanel(ref CuiElementContainer container, string panel, string color, string aMin, string aMax, bool cursor = false) {
container.Add(new CuiPanel {
Image = {
Color = color
}
, RectTransform = {
AnchorMin = aMin, AnchorMax = aMax
}
, CursorEnabled = cursor
}
, panel);
}
static public void CreateLabel(ref CuiElementContainer container, string panel, string color, string text, int size, string aMin, string aMax, TextAnchor align = TextAnchor.MiddleCenter) {
container.Add(new CuiLabel {
Text = {
Color = color, FontSize = size, Align = align, FadeIn = 1.0f, Text = text
}
, RectTransform = {
AnchorMin = aMin, AnchorMax = aMax
}
}
, panel);
}
static public void CreateButton(ref CuiElementContainer container, string panel, string color, string text, int size, string aMin, string aMax, string command, TextAnchor align = TextAnchor.MiddleCenter) {
container.Add(new CuiButton {
Button = {
Color = color, Command = command, FadeIn = 1.0f
}
, RectTransform = {
AnchorMin = aMin, AnchorMax = aMax
}
, Text = {
Text = text, FontSize = size, Align = align
}
}
, panel);
}
static public void LoadImage(ref CuiElementContainer container, string panel, string img, string aMin, string aMax) {
if (img.StartsWith("http") || img.StartsWith("www")) {
container.Add(new CuiElement {
Parent = panel, Components = {
new CuiRawImageComponent {
Url = img, Sprite = "assets/content/textures/generic/fulltransparent.tga"
}
, new CuiRectTransformComponent {
AnchorMin = aMin, AnchorMax = aMax
}
}
}
);
}
else container.Add(new CuiElement {
Parent = panel, Components = {
new CuiRawImageComponent {
Png = img, Sprite = "assets/content/textures/generic/fulltransparent.tga"
}
, new CuiRectTransformComponent {
AnchorMin = aMin, AnchorMax = aMax
}
}
}
);
}
static public void CreateTextOverlay(ref CuiElementContainer element, string panel, string text, string color, int size, string aMin, string aMax, TextAnchor align = TextAnchor.MiddleCenter, float fadein = 1.0f) {
//if (configdata.DisableUI_FadeIn)
// fadein = 0;
element.Add(new CuiLabel {
Text = {
Color = color, FontSize = size, Align = align, FadeIn = fadein, Text = text
}
, RectTransform = {
AnchorMin = aMin, AnchorMax = aMax
}
}
, panel);
}
static public void CreateTextOutline(ref CuiElementContainer element, string panel, string colorText, string colorOutline, string text, int size, string aMin, string aMax, TextAnchor align = TextAnchor.MiddleCenter) {
element.Add(new CuiElement {
Parent = panel, Components = {
new CuiTextComponent {
Color = colorText, FontSize = size, Align = align, Text = text
}
, new CuiOutlineComponent {
Distance = "1 1", Color = colorOutline
}
, new CuiRectTransformComponent {
AnchorMax = aMax, AnchorMin = aMin
}
}
}
);
}
}
private Dictionary<string, string> UIColors = new Dictionary<string, string> {
{
"black", "0 0 0 1.0"
}
, {
"dark", "0.1 0.1 0.1 0.98"
}
, {
"header", "1 1 1 0.3"
}
, {
"light", "0.7 0.7 0.7 0.3"
}
, {
"grey1", "0.6 0.6 0.6 1.0"
}
, {
"brown", "0.3 0.16 0.0 1.0"
}
, {
"yellow", "0.9 0.9 0.0 1.0"
}
, {
"orange", "1.0 0.65 0.0 1.0"
}
, {
"limegreen", "0.42 1.0 0 1.0"
}
, {
"blue", "0.2 0.6 1.0 1.0"
}
, {
"red", "1.0 0.1 0.1 1.0"
}
, {
"white", "1 1 1 1"
}
, {
"green", "0.28 0.82 0.28 1.0"
}
, {
"grey", "0.85 0.85 0.85 1.0"
}
, {
"lightblue", "0.6 0.86 1.0 1.0"
}
, {
"buttonbg", "0.2 0.2 0.2 0.7"
}
, {
"buttongreen", "0.133 0.965 0.133 0.9"
}
, {
"buttonred", "0.964 0.133 0.133 0.9"
}
, {
"buttongrey", "0.8 0.8 0.8 0.9"
}
, {
"CSorange", "1.0 0.64 0.10 1.0"
}
}
;
private Dictionary<string, string> TextColors = new Dictionary<string, string> {
{
"limegreen", "<color=#6fff00>"
}
}
;
#endregion
#region UI Panels
void UniversalUIPanel(BasePlayer player) {
CuiHelper.DestroyUi(player, PanelUUI);
if (configData.UseButtonPanel) {
var element = UI.CreateElementContainer(PanelUUI, "0 0 0 0", "0.85 0.225", "1.0 0.725", true);
foreach (var entry in configData.buttons) if (!string.IsNullOrEmpty(entry.Value.command) && isAllowed(player, entry.Value.adminOnly, entry.Value.permission)) CreateButtonOnUI(ref element, PanelUUI, entry.Value, entry.Key);
if (configData.UseInfoPanel) if (NoInfo.Contains(player.userID)) UI.CreateButton(ref element, PanelUUI, UIColors["blue"], GetLang("InfoPanel"), 12, "0.2 -.1", "0.8 -.06", "UI_OpenInfoUI");
CuiHelper.AddUi(player, element);
}
}
private void CreateButtonOnUI(ref CuiElementContainer container, string panelName, MainButton button, int num) {
var pos = CalcButtonPos(num);
if (Valid($"UUIMainButton{num}")) {
UI.LoadImage(ref container, panelName, TryForImage($"UUIMainButton{num}"), $"{pos[0]} {pos[1]}", $"{pos[2]} {pos[3]}");
UI.CreateButton(ref container, panelName, "0 0 0 0", button.name, 12, $"{pos[0]} {pos[1]}", $"{pos[2]} {pos[3]}", $"UI_RunConsoleCommand {button.CloseUI} {button.command}");
}
else {
UI.CreateButton(ref container, panelName, UIColors["red"], button.name, 12, $"{pos[0]} {pos[1]}", $"{pos[2]} {pos[3]}", $"UI_RunConsoleCommand {button.CloseUI} {button.command}");
}
}
void BackgroundPanel(BasePlayer player) {
CuiHelper.DestroyUi(player, PanelStatic);
if (!UniversalUIInfo.ContainsKey(player.userID)) UniversalUIInfo.Add(player.userID, new screen {
page = 0, section = 0, showSection = 0
}
);
CuiElementContainer element = element = UI.CreateElementContainer(PanelStatic, "0 0 0 0", "0.2 0.2", "0.8 0.8", true);
CuiHelper.AddUi(player, element);
UIInfoPanel(player);
}
void UIInfoPanel(BasePlayer player) {
CuiHelper.DestroyUi(player, PanelInfo);
CuiElementContainer element = element = UI.CreateElementContainer(PanelInfo, "0 0 0 0", "0.2 0.2", "0.8 0.8");
//if (UniversalUIInfo[player.userID].section != 0)
foreach (var entry in configData.sections.Where(k => k.Key == UniversalUIInfo[player.userID].section)) {
if (Debugging) Puts($"No Home Page - Trying Section: {entry.Key.ToString()}");
if (entry.Key == UniversalUIInfo[player.userID].section) foreach (var page in entry.Value.pages.Where(kvp => kvp.page == UniversalUIInfo[player.userID].page)) {
switch (page.type) {
case PageType.text : {
if (Valid($"UUIPage{entry.Key}-{UniversalUIInfo[player.userID].page}")) UI.LoadImage(ref element, PanelInfo, TryForImage($"UUIPage{entry.Key}-{UniversalUIInfo[player.userID].page}"), "0 0", "1 0.88");
else {
UI.CreatePanel(ref element, PanelInfo, UIColors["dark"], "0 0", "1 1");
UI.CreatePanel(ref element, PanelInfo, UIColors["light"], "0.01 0.02", "0.99 0.98");
}
if (!string.IsNullOrEmpty(page.name)) UI.CreateLabel(ref element, PanelInfo, UIColors["white"], page.name.ToUpper(), 24, "0.3 0.8", "0.7 0.9");
if (!string.IsNullOrEmpty(page.text)) UI.CreateLabel(ref element, PanelInfo, UIColors["white"], page.text, 12, "0.03 0.2", "0.97 0.65");
//foreach (var button in page.buttons.OrderBy(kvp => kvp.order))
// if (!string.IsNullOrEmpty(button.command) && isAllowed(player, button.adminOnly, button.permission))
// {
// var pos = CalcInfoButtonPos(button.order);
// if (Valid($"UUIPageButton{entry.Key}-{UniversalUIInfo[player.userID].page}-{button.order}"))
// {
// UI.LoadImage(ref element, PanelInfo, TryForImage($"UUIPageButton{entry.Key}-{UniversalUIInfo[player.userID].page}-{button.order}"), $"{pos[0]} {pos[1]}", $"{pos[2]} {pos[3]}");
// if (!string.IsNullOrEmpty(button.name))
// {
// UI.CreateLabel(ref element, PanelInfo, UIColors["red"], button.name, 12, $"{pos[0]} {pos[1]}", $"{pos[2]} {pos[3]}");
// UI.CreateButton(ref element, PanelInfo, "0 0 0 0", button.name, 12, $"{pos[0]} {pos[1]}", $"{pos[2]} {pos[3]}", $"UI_RunConsoleCommand {button.CloseUI} {button.command}");
// }
// else
// UI.CreateButton(ref element, PanelInfo, "0 0 0 0", "", 12, $"{pos[0]} {pos[1]}", $"{pos[2]} {pos[3]}", $"UI_RunConsoleCommand {button.CloseUI} {button.command}");
// }
// else
// {
// if (!string.IsNullOrEmpty(button.name))
// UI.CreateButton(ref element, PanelInfo, UIColors["red"], button.name, 12, $"{pos[0]} {pos[1]}", $"{pos[2]} {pos[3]}", $"UI_RunConsoleCommand {button.CloseUI} {button.command}");
// else
// UI.CreateButton(ref element, PanelInfo, UIColors["red"], "", 12, $"{pos[0]} {pos[1]}", $"{pos[2]} {pos[3]}", $"UI_RunConsoleCommand {button.CloseUI} {button.command}");
// }
// }
break;
}
case PageType.buttons : {
if (Valid($"UUIPage{entry.Key}-{UniversalUIInfo[player.userID].page}")) UI.LoadImage(ref element, PanelInfo, TryForImage($"UUIPage{entry.Key}-{UniversalUIInfo[player.userID].page}"), "0 0", "1 0.88");
else {
UI.CreatePanel(ref element, PanelInfo, UIColors["dark"], "0 0", "1 1");
UI.CreatePanel(ref element, PanelInfo, UIColors["light"], "0.01 0.02", "0.99 0.98");
}
if (!string.IsNullOrEmpty(page.name)) UI.CreateLabel(ref element, PanelInfo, UIColors["white"], page.name.ToUpper(), 24, "0.3 0.8", "0.7 0.9");
//if (!string.IsNullOrEmpty(page.text))
// UI.CreateLabel(ref element, PanelInfo, UIColors["white"], page.text, 12, "0.03 0.2", "0.85 0.65", TextAnchor.UpperLeft);
foreach (var button in page.buttons.OrderByDescending(kvp => kvp.order)) if (!string.IsNullOrEmpty(button.command) && isAllowed(player, button.adminOnly, button.permission)) {
if (button.order > 69) continue;
var pos = CalcButtonPagePos(button.order);
if (Valid($"UUIPageButton{entry.Key}-{UniversalUIInfo[player.userID].page}-{button.order}")) {
UI.LoadImage(ref element, PanelInfo, TryForImage($"UUIPageButton{entry.Key}-{UniversalUIInfo[player.userID].page}-{button.order}"), $"{pos[0]} {pos[1]}", $"{pos[2]} {pos[3]}");
if (!string.IsNullOrEmpty(button.name)) {
UI.CreateLabel(ref element, PanelInfo, UIColors["red"], button.name, 12, $"{pos[0]} {pos[1]}", $"{pos[2]} {pos[3]}");
UI.CreateButton(ref element, PanelInfo, "0 0 0 0", button.name, 12, $"{pos[0]} {pos[1]}", $"{pos[2]} {pos[3]}", $"UI_RunConsoleCommand {button.CloseUI} {button.command}");
}
else UI.CreateButton(ref element, PanelInfo, "0 0 0 0", "", 12, $"{pos[0]} {pos[1]}", $"{pos[2]} {pos[3]}", $"UI_RunConsoleCommand {button.CloseUI} {button.command}");
}
else {
if (!string.IsNullOrEmpty(button.name)) UI.CreateButton(ref element, PanelInfo, UIColors["red"], button.name, 12, $"{pos[0]} {pos[1]}", $"{pos[2]} {pos[3]}", $"UI_RunConsoleCommand {button.CloseUI} {button.command}");
else UI.CreateButton(ref element, PanelInfo, UIColors["red"], "", 12, $"{pos[0]} {pos[1]}", $"{pos[2]} {pos[3]}", $"UI_RunConsoleCommand {button.CloseUI} {button.command}");
}
}
break;
}
case PageType.kits : {
if (Valid($"UUIPage{entry.Key}-{UniversalUIInfo[player.userID].page}")) UI.LoadImage(ref element, PanelInfo, TryForImage($"UUIPage{entry.Key}-{UniversalUIInfo[player.userID].page}"), "0 0", "1 0.88");
else {
UI.CreatePanel(ref element, PanelInfo, UIColors["dark"], "0 0", "1 1");
UI.CreatePanel(ref element, PanelInfo, UIColors["light"], "0.01 0.02", "0.99 0.98");
}
if (!string.IsNullOrEmpty(page.name)) UI.CreateLabel(ref element, PanelInfo, UIColors["white"], page.name.ToUpper(), 24, "0.3 0.8", "0.7 0.9");
var i = 0;
foreach (var kit in page.Kits) {
if (i > 7) break;
CreateKitEntry(ref element, PanelInfo, player, kit, i);
i++;
}
if (UniversalUIInfo[player.userID].admin) UI.CreateButton(ref element, PanelInfo, UIColors["header"], GetLang("AddKit"), 12, "0.03 0.11", "0.13 0.17", $"UI_SelectKitToAdd {0}");
break;
}
default : {
if (Valid($"UUIPage{entry.Key}-{UniversalUIInfo[player.userID].page}")) UI.LoadImage(ref element, PanelInfo, TryForImage($"UUIPage{entry.Key}-{UniversalUIInfo[player.userID].page}"), "0 0", "1 0.88");
else {
UI.CreatePanel(ref element, PanelInfo, UIColors["dark"], "0 0", "1 1");
UI.CreatePanel(ref element, PanelInfo, UIColors["light"], "0.01 0.02", "0.99 0.98");
}
if (!string.IsNullOrEmpty(page.name)) UI.CreateLabel(ref element, PanelInfo, UIColors["white"], page.name.ToUpper(), 24, "0.3 0.8", "0.7 0.9");
if (!string.IsNullOrEmpty(page.text)) UI.CreateLabel(ref element, PanelInfo, UIColors["white"], page.text, 12, "0.03 0.2", "0.85 0.65", TextAnchor.UpperLeft);
foreach (var button in page.buttons.OrderBy(kvp => kvp.order)) if (!string.IsNullOrEmpty(button.command) && isAllowed(player, button.adminOnly, button.permission)) {
var pos = CalcInfoButtonPos(button.order);
if (Valid($"UUIPageButton{entry.Key}-{UniversalUIInfo[player.userID].page}-{button.order}")) {
UI.LoadImage(ref element, PanelInfo, TryForImage($"UUIPageButton{entry.Key}-{UniversalUIInfo[player.userID].page}-{button.order}"), $"{pos[0]} {pos[1]}", $"{pos[2]} {pos[3]}");
if (!string.IsNullOrEmpty(button.name)) {
UI.CreateLabel(ref element, PanelInfo, UIColors["red"], button.name, 12, $"{pos[0]} {pos[1]}", $"{pos[2]} {pos[3]}");
UI.CreateButton(ref element, PanelInfo, "0 0 0 0", button.name, 12, $"{pos[0]} {pos[1]}", $"{pos[2]} {pos[3]}", $"UI_RunConsoleCommand {button.CloseUI} {button.command}");
}
else UI.CreateButton(ref element, PanelInfo, "0 0 0 0", "", 12, $"{pos[0]} {pos[1]}", $"{pos[2]} {pos[3]}", $"UI_RunConsoleCommand {button.CloseUI} {button.command}");
}
else {
if (!string.IsNullOrEmpty(button.name)) UI.CreateButton(ref element, PanelInfo, UIColors["red"], button.name, 12, $"{pos[0]} {pos[1]}", $"{pos[2]} {pos[3]}", $"UI_RunConsoleCommand {button.CloseUI} {button.command}");
else UI.CreateButton(ref element, PanelInfo, UIColors["red"], "", 12, $"{pos[0]} {pos[1]}", $"{pos[2]} {pos[3]}", $"UI_RunConsoleCommand {button.CloseUI} {button.command}");
}
}
break;
}
}
}
break;
}
//Create Section Buttons at the Top
if (UniversalUIInfo[player.userID].section == 0) {
if (Valid(configData.HomePage.name)) UI.LoadImage(ref element, PanelInfo, TryForImage(configData.HomePage.name), "0 0", "1 0.88");
else {
UI.CreatePanel(ref element, PanelInfo, UIColors["dark"], "0 0", "1 1");
UI.CreatePanel(ref element, PanelInfo, UIColors["light"], "0.01 0.02", "0.99 0.98");
}
if (!string.IsNullOrEmpty(configData.HomePage.text)) UI.CreateLabel(ref element, PanelInfo, UIColors["white"], configData.HomePage.text, 12, "0.02 0.2", "0.97 0.65");
UI.CreatePanel(ref element, PanelInfo, UIColors["red"], "0.02 0.9", "0.16 0.975");
UI.CreateLabel(ref element, PanelInfo, UIColors["white"], configData.HomePage.name.ToUpper(), 12, "0.02 0.9", "0.16 0.975");
}
else {
UI.CreateButton(ref element, PanelInfo, UIColors["blue"], configData.HomePage.name.ToUpper(), 12, "0.02 0.9", "0.16 0.975", $"UI_SwitchSection {0} false ");
}
foreach (var entry in configData.sections /*.Where(k => k.Key >= UniversalUIInfo[player.userID].showSection && k.Key < (UniversalUIInfo[player.userID].showSection + 4))*/
) {
if (entry.Key < UniversalUIInfo[player.userID].showSection) continue;
if (entry.Key > UniversalUIInfo[player.userID].showSection + 5) continue;
var pos = CalcSectionButtonPos(entry.Key - UniversalUIInfo[player.userID].showSection);
if (Debugging) Puts($"Trying Section: {entry.Key}");
if (Debugging) Puts($"Shown Section: { UniversalUIInfo[player.userID].showSection}");
if (Debugging) Puts($"Last Section: { UniversalUIInfo[player.userID].showSection + 4}");
var admin = "false";
if (entry.Value.adminOnly) admin = "true";
if (entry.Key == UniversalUIInfo[player.userID].section) {
if (Debugging) Puts($"Section Match: {entry.Key}");
var lastpage = configData.sections[UniversalUIInfo[player.userID].section].pages.Count() - 1;
var currentpage = UniversalUIInfo[player.userID].page;
if (currentpage < lastpage - 1) {
UI.CreateButton(ref element, PanelInfo, UIColors["dark"], GetLang("Last"), 12, "0.9 0.03", "0.95 0.085", $"UI_PageTurn {lastpage}");
}
if (currentpage < lastpage) {
UI.CreateButton(ref element, PanelInfo, UIColors["dark"], GetLang("Next"), 12, "0.84 0.03", "0.89 0.085", $"UI_PageTurn {currentpage + 1}");
}
if (currentpage > 0) {
UI.CreateButton(ref element, PanelInfo, UIColors["dark"], GetLang("Back"), 12, "0.77 0.03", "0.82 0.085", $"UI_PageTurn {currentpage - 1}");
}
if (currentpage > 1) {
UI.CreateButton(ref element, PanelInfo, UIColors["dark"], GetLang("First"), 12, "0.71 0.03", "0.76 0.085", $"UI_PageTurn {0}");
}
UI.CreatePanel(ref element, PanelInfo, UIColors["red"], $"{pos[0]} {pos[1]}", $"{pos[2]} {pos[3]}");
if (!string.IsNullOrEmpty(entry.Value.name)) UI.CreateLabel(ref element, PanelInfo, UIColors["white"], entry.Value.name.ToUpper(), 12, $"{pos[0]} {pos[1]}", $"{pos[2]} {pos[3]}");
else UI.CreateLabel(ref element, PanelInfo, UIColors["white"], $"Section:{entry.Key.ToString().ToUpper()}", 12, $"{pos[0]} {pos[1]}", $"{pos[2]} {pos[3]}");
}
else {
if (Debugging) Puts($"Section Didn't Match: {entry.Key}");
// ... [Code preview truncated due to length. Full source in attached file] ...