Иконка ресурса

FREE AdminMenu : 0.1.49 0.1.49

Нет прав для скачивания
C#:
using System;
using System.Collections.Generic;
using System.Globalization;
using Newtonsoft.Json;
using Oxide.Core.Libraries.Covalence;
using Oxide.Game.Rust.Cui;
using Oxide.Core;
using Oxide.Core.Configuration;
using Oxide.Core.Plugins;
using UnityEngine;
using System.Linq;
namespace Oxide.Plugins {
    [Info("AdminMenu", "k1lly0u", "0.1.49")]
    [Description("Manage groups, permissions, and commands from a GUI menu")]
    class AdminMenu : RustPlugin {
#region Fields
        private StoredData storedData;
        private DynamicConfigFile data;
        private static AdminMenu ins;
        private Dictionary<string, string> uiColors = new Dictionary<string, string>();
        private enum MenuType {
            Permissions, Groups, Commands
        }
        private enum SelectType {
            Player, String
        }
        private enum PermSub {
            View, Player, Group
        }
        private enum CommSub {
            Chat, Console, Give, Player
        }
        private enum GroupSub {
            View, UserGroups, AddGroup, CloneGroup, RemoveGroup
        }
        private enum ItemType {
            Weapon, Construction, Items, Resources, Attire, Tool, Medical, Food, Ammunition, Traps, Misc, Component, Electrical, Fun
        }
        private Dictionary<ItemType, List<KeyValuePair<string, ItemDefinition>>> itemList = new Dictionary<ItemType, List<KeyValuePair<string, ItemDefinition>>>();
        private Hash<ulong, SelectionData> selectData = new Hash<ulong, SelectionData>();
        private Hash<ulong, GroupData> groupCreator = new Hash<ulong, GroupData>();
        private Hash<ulong, Timer> popupTimers = new Hash<ulong, Timer>();
        private string[] charFilter = new string[] {
            "~", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"
        }
        ;
        private List<KeyValuePair<string, bool>> permissionList = new List<KeyValuePair<string, bool>>();
        private const string USE_PERMISSION = "adminmenu.use";
        private const string PERM_PERMISSION = "adminmenu.permissions";
        private const string GROUP_PERMISSION = "adminmenu.groups";
        private const string GIVE_PERMISSION = "adminmenu.give";
        private const string GIVE_SELF_PERMISSION = "adminmenu.give.selfonly";
        private const string PLAYER_PERMISSION = "adminmenu.players";
        private const string PLAYER_KICKBAN_PERMISSION = "adminmenu.players.kickban";
        private const string PLAYER_MUTE_PERMISSION = "adminmenu.players.mute";
        private const string PLAYER_BLUERPRINTS_PERMISSION = "adminmenu.players.blueprints";
        private const string PLAYER_HURT_PERMISSION = "adminmenu.players.hurt";
        private const string PLAYER_HEAL_PERMISSION = "adminmenu.players.heal";
        private const string PLAYER_KILL_PERMISSION = "adminmenu.players.kill";
        private const string PLAYER_STRIP_PERMISSION = "adminmenu.players.strip";
        private const string PLAYER_TELEPORT_PERMISSION = "adminmenu.players.teleport";
#endregion
#region Classes
        private class SelectionData {
            public MenuType menuType;
            public string subType, selectDesc = string.Empty, returnCommand = string.Empty, target1_Name = string.Empty, target1_Id = string.Empty, target2_Name = string.Empty, target2_Id = string.Empty, character = string.Empty;
            public bool requireTarget1, requireTarget2, isOnline, isGroup, forceOnline;
            public int pageNum, listNum;
        }
        private class GroupData {
            public string fromname = string.Empty, name = string.Empty, title = string.Empty, rank = string.Empty;
            public bool copyusers = false, isClone = false;
        }
#endregion
#region Oxide Hooks
        private void Loaded() {
            permission.RegisterPermission(USE_PERMISSION, this);
            permission.RegisterPermission(PERM_PERMISSION, this);
            permission.RegisterPermission(GROUP_PERMISSION, this);
            permission.RegisterPermission(GIVE_PERMISSION, this);
            permission.RegisterPermission(PLAYER_PERMISSION, this);
            permission.RegisterPermission(GIVE_SELF_PERMISSION, this);
            permission.RegisterPermission(PLAYER_KICKBAN_PERMISSION, this);
            permission.RegisterPermission(PLAYER_MUTE_PERMISSION, this);
            permission.RegisterPermission(PLAYER_BLUERPRINTS_PERMISSION, this);
            permission.RegisterPermission(PLAYER_HURT_PERMISSION, this);
            permission.RegisterPermission(PLAYER_HEAL_PERMISSION, this);
            permission.RegisterPermission(PLAYER_KILL_PERMISSION, this);
            permission.RegisterPermission(PLAYER_STRIP_PERMISSION, this);
            permission.RegisterPermission(PLAYER_TELEPORT_PERMISSION, this);
            lang.RegisterMessages(Messages, this);
            data = Interface.Oxide.DataFileSystem.GetFile("AdminMenu/offline_players");
        }
        private void OnServerInitialized() {
            ins = this;
            LoadData();
            if (storedData == null || storedData.offlinePlayers == null) storedData = new StoredData();
            else storedData.RemoveOldPlayers();
            SetUIColors();
            foreach(var item in ItemManager.itemList) {
                ItemType itemType = (ItemType)Enum.Parse(typeof(ItemType), item.category.ToString(), true);
                if (!itemList.ContainsKey(itemType)) itemList.Add(itemType, new List<KeyValuePair<string, ItemDefinition>>());
                itemList[itemType].Add(new KeyValuePair<string, ItemDefinition>(item.displayName.english, item));
            }
            foreach (BasePlayer player in BasePlayer.activePlayerList) OnPlayerConnected(player);
        }
        private void OnPlayerConnected(BasePlayer player) => storedData.OnPlayerInit(player.UserIDString);
        private void OnPlayerDisconnected(BasePlayer player) {
            DestroyUI(player);
            storedData.AddOfflinePlayer(player.UserIDString);
        }
        private void OnPermissionRegistered(string name, Plugin owner) => UpdatePermissionList();
        private void OnPluginUnloaded(Plugin plugin) => UpdatePermissionList();
        private void OnServerSave() => SaveData();
        private void Unload() {
            foreach (BasePlayer player in BasePlayer.activePlayerList) OnPlayerDisconnected(player);
            ins = null;
        }
#endregion
#region CUI Helper
        public class UI {
            static public CuiElementContainer Container(string panelName, string color, string aMin, string aMax, bool useCursor = false, string parent = "Overlay") {
                var NewElement = new CuiElementContainer() {
                    {
                        new CuiPanel {
                            Image = {
                                Color = color
                            }
                            , RectTransform = {
                                AnchorMin = aMin, AnchorMax = aMax
                            }
                            , CursorEnabled = useCursor
                        }
                        , new CuiElement().Parent = parent, panelName
                    }
                }
                ;
                return NewElement;
            }
            static public void Panel(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 Label(ref CuiElementContainer container, string panel, string text, int size, string aMin, string aMax, TextAnchor align = TextAnchor.MiddleCenter) {
                container.Add(new CuiLabel {
                    Text = {
                        FontSize = size, Align = align, Text = text
                    }
                    , RectTransform = {
                        AnchorMin = aMin, AnchorMax = aMax
                    }
                }
                , panel);
            }
            static public void Button(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 = 0f
                    }
                    , RectTransform = {
                        AnchorMin = aMin, AnchorMax = aMax
                    }
                    , Text = {
                        Text = text, FontSize = size, Align = align
                    }
                }
                , panel);
            }
            static public void Input(ref CuiElementContainer container, string panel, string color, string text, int size, string command, string aMin, string aMax) {
                container.Add(new CuiElement {
                    Name = CuiHelper.GetGuid(), Parent = panel, Components = {
                        new CuiInputFieldComponent {
                            Align = TextAnchor.MiddleLeft, CharsLimit = 50, Color = color, Command = command + text, FontSize = size, IsPassword = false, Text = text
                        }
                        , new CuiRectTransformComponent {
                            AnchorMin = aMin, AnchorMax = aMax
                        }
                    }
                }
                );
            }
            public static void Toggle(ref CuiElementContainer container, string panel, string color, int fontSize, string aMin, string aMax, string command, bool isOn) {
                UI.Panel(ref container, panel, color, aMin, aMax);
                if (isOn) UI.Label(ref container, panel, "✔", fontSize, aMin, aMax);
                UI.Button(ref container, panel, "0 0 0 0", string.Empty, 0, aMin, aMax, command);
            }
            static public string Color(string hexColor, float alpha) {
                if (hexColor.StartsWith("#")) hexColor = hexColor.TrimStart('#');
                int red = int.Parse(hexColor.Substring(0, 2), NumberStyles.AllowHexSpecifier);
                int green = int.Parse(hexColor.Substring(2, 2), NumberStyles.AllowHexSpecifier);
                int blue = int.Parse(hexColor.Substring(4, 2), NumberStyles.AllowHexSpecifier);
                return $"{(double)red / 255} {(double)green / 255} {(double)blue / 255} {alpha}";
            }
        }
#endregion
#region UI Creation
        const string UIMain = "AMUI_MenuMain";
        const string UIElement = "AMUI_MenuElement";
        const string UIPopup = "AMUI_PopupMessage";
        private void OpenAdminMenu(BasePlayer player) {
            DestroyUI(player);
            CuiElementContainer container = UI.Container(UIMain, uiColors["bg1"], "0.05 0.08", "0.95 0.92", true);
            CuiHelper.AddUi(player, container);
            CreateMenuCommands(player, CommSub.Chat);
        }
        private void CreateMenuButtons(ref CuiElementContainer container, MenuType menuType, string playerId) {
            UI.Panel(ref container, UIElement, uiColors["bg3"], "0.005 0.925", "0.995 0.99");
            UI.Label(ref container, UIElement, string.Format(msg("title", playerId), Version), 24, "0.02 0.93", "0.25 0.98", TextAnchor.UpperLeft);
            UI.Button(ref container, UIElement, menuType == MenuType.Commands ? uiColors["button3"] : uiColors["button1"], msg(MenuType.Commands.ToString(), playerId), 16, "0.27 0.93", "0.42 0.985", menuType == MenuType.Commands ? "" : "amui.switchelement commands");
            if (HasPermission(playerId, PERM_PERMISSION)) UI.Button(ref container, UIElement, menuType == MenuType.Permissions ? uiColors["button3"] : uiColors["button1"], msg(MenuType.Permissions.ToString(), playerId), 16, "0.425 0.93", "0.575 0.985", menuType == MenuType.Permissions ? "" : "amui.switchelement permissions");
            if (HasPermission(playerId, GROUP_PERMISSION)) UI.Button(ref container, UIElement, menuType == MenuType.Groups ? uiColors["button3"] : uiColors["button1"], msg(MenuType.Groups.ToString(), playerId), 16, "0.58 0.93", "0.73 0.985", menuType == MenuType.Groups ? "" : "amui.switchelement groups");
            UI.Button(ref container, UIElement, uiColors["button1"], msg("exit", playerId), 16, "0.855 0.93", "0.985 0.985", "amui.switchelement exit");
        }
        private void CreateSubMenu(ref CuiElementContainer container, MenuType menuType, string playerId, string subType) {
            UI.Panel(ref container, UIElement, uiColors["bg3"], "0.005 0.87", "0.995 0.92");
            switch (menuType) {
                case MenuType.Permissions : PermSub permSub = ParseType<PermSub>(subType);
                UI.Button(ref container, UIElement, permSub == PermSub.View ? uiColors["button3"] : uiColors["button1"], msg("view", playerId), 16, "0.27 0.875", "0.42 0.915", permSub == PermSub.View ? "" : "amui.switchelement permissions view");
                UI.Button(ref container, UIElement, permSub == PermSub.Player ? uiColors["button3"] : uiColors["button1"], msg("player", playerId), 16, "0.425 0.875", "0.575 0.915", permSub == PermSub.Player ? "" : "amui.switchelement permissions player");
                UI.Button(ref container, UIElement, permSub == PermSub.Group ? uiColors["button3"] : uiColors["button1"], msg("group", playerId), 16, "0.58 0.875", "0.73 0.915", permSub == PermSub.Group ? "" : "amui.switchelement permissions group");
                return;
                case MenuType.Groups : GroupSub groupSub = ParseType<GroupSub>(subType);
                UI.Button(ref container, UIElement, groupSub == GroupSub.View ? uiColors["button3"] : uiColors["button1"], msg("view", playerId), 16, "0.115 0.875", "0.265 0.915", groupSub == GroupSub.View ? "" : "amui.switchelement groups view");
                UI.Button(ref container, UIElement, groupSub == GroupSub.AddGroup ? uiColors["button3"] : uiColors["button1"], msg("addgroup", playerId), 16, "0.27 0.875", "0.42 0.915", groupSub == GroupSub.AddGroup ? "" : "amui.switchelement groups addgroup");
                UI.Button(ref container, UIElement, groupSub == GroupSub.CloneGroup ? uiColors["button3"] : uiColors["button1"], msg("clonegroup", playerId), 16, "0.425 0.875", "0.575 0.915", groupSub == GroupSub.CloneGroup ? "" : "amui.switchelement groups clonegroup");
                UI.Button(ref container, UIElement, groupSub == GroupSub.RemoveGroup ? uiColors["button3"] : uiColors["button1"], msg("removegroup", playerId), 16, "0.58 0.875", "0.73 0.915", groupSub == GroupSub.RemoveGroup ? "" : "amui.switchelement groups removegroup");
                UI.Button(ref container, UIElement, groupSub == GroupSub.UserGroups ? uiColors["button3"] : uiColors["button1"], msg("usergroups", playerId), 16, "0.735 0.875", "0.885 0.915", groupSub == GroupSub.UserGroups ? "" : "amui.switchelement groups usergroups");
                return;
                case MenuType.Commands : CommSub commSub = ParseType<CommSub>(subType);
                UI.Button(ref container, UIElement, commSub == CommSub.Chat ? uiColors["button3"] : uiColors["button1"], msg("chat", playerId), 16, "0.1925 0.875", "0.3425 0.915" /*"0.27 0.875", "0.42 0.915"*/
                , commSub == CommSub.Chat ? "" : "amui.switchelement commands chat");
                UI.Button(ref container, UIElement, commSub == CommSub.Console ? uiColors["button3"] : uiColors["button1"], msg("console", playerId), 16, "0.3475 0.875", "0.4975 0.915" /*"0.425 0.875", "0.575 0.915"*/
                , commSub == CommSub.Console ? "" : "amui.switchelement commands console");
                if (HasPermission(playerId, GIVE_PERMISSION)) UI.Button(ref container, UIElement, commSub == CommSub.Give ? uiColors["button3"] : uiColors["button1"], msg("give", playerId), 16, "0.5025 0.875", "0.6525 0.915" /*"0.58 0.875", "0.73 0.915"*/
                , commSub == CommSub.Give ? "" : "amui.switchelement commands give");
                if (HasPermission(playerId, PLAYER_PERMISSION)) UI.Button(ref container, UIElement, commSub == CommSub.Player ? uiColors["button3"] : uiColors["button1"], msg("playerinfo", playerId), 16, "0.6575 0.875", "0.8075 0.915", commSub == CommSub.Player ? "" : "amui.switchelement commands player");
                return;
            }
        }
        private void CreateMenuPermissions(BasePlayer player, int page = 0, string filter = "") {
            CuiElementContainer container = UI.Container(UIElement, "0 0 0 0", "0.05 0.08", "0.95 0.92");
            CreateMenuButtons(ref container, MenuType.Permissions, player.UserIDString);
            CreateSubMenu(ref container, MenuType.Permissions, player.UserIDString, "view");
            CreateCharacterFilter(ref container, player.userID, filter, $"amui.switchelement permissions view 0");
            List<KeyValuePair<string, bool>> permList = new List<KeyValuePair<string, bool>>(permissionList);
            if (!string.IsNullOrEmpty(filter) && filter != "~") permList = permList.Where(x => x.Key.StartsWith(filter, StringComparison.OrdinalIgnoreCase)).ToList();
            permList.OrderBy(x => x.Key);
            if (page > 0) UI.Button(ref container, UIElement, uiColors["button1"], msg("back", player.UserIDString), 16, "0.015 0.875", "0.145 0.915", $"amui.switchelement permissions view {page - 1}");
            if (permList.Count > 72 && permList.Count > (72 * page + 72)) UI.Button(ref container, UIElement, uiColors["button1"], msg("next", player.UserIDString), 16, "0.855 0.875", "0.985 0.915", $"amui.switchelement permissions view {page + 1}");
            int count = 0;
            for (int i = page * 72; i < permList.Count; i++) {
                KeyValuePair<string, bool> perm = permList[i];
                float[] position = CalculateButtonPosVert(count);
                if (!perm.Value) {
                    UI.Panel(ref container, UIElement, uiColors["button2"], $"{position[0]} {position[1]}", $"{position[2]} {position[3]}");
                    UI.Label(ref container, UIElement, $"{perm.Key}", 12, $"{position[0]} {position[1]}", $"{position[2]} {position[3]}");
                }
                else {
                    UI.Panel(ref container, UIElement, uiColors["button1"], $"{position[0]} {position[1]}", $"{position[2]} {position[3]}");
                    UI.Label(ref container, UIElement, $"{perm.Key}", 10, $"{position[0]} {position[1]}", $"{position[2]} {position[3]}");
                }
                ++count;
                if (count >= 72) break;
            }
            CuiHelper.DestroyUi(player, UIElement);
            CuiHelper.AddUi(player, container);
        }
        private void CreateMenuGroups(BasePlayer player, GroupSub subType, int page = 0, string filter = "") {
            CuiElementContainer container = UI.Container(UIElement, "0 0 0 0", "0.05 0.08", "0.95 0.92");
            CreateMenuButtons(ref container, MenuType.Groups, player.UserIDString);
            CreateSubMenu(ref container, MenuType.Groups, player.UserIDString, subType.ToString());
            switch (subType) {
                case GroupSub.View : List<string> groupList = GetGroups();
                groupList.Sort();
                if (page > 0) UI.Button(ref container, UIElement, uiColors["button1"], msg("back", player.UserIDString), 16, "0.015 0.875", "0.145 0.915", $"amui.switchelement groups view {page - 1}");
                if (groupList.Count > 72 && groupList.Count > (72 * page + 72)) UI.Button(ref container, UIElement, uiColors["button1"], msg("next", player.UserIDString), 16, "0.855 0.875", "0.985 0.915", $"amui.switchelement groups view {page + 1}");
                int count = 0;
                for (int i = page * 72; i < groupList.Count; i++) {
                    string groupId = groupList[i];
                    float[] position = CalculateButtonPos(count);
                    UI.Button(ref container, UIElement, uiColors["button1"], groupId, 10, $"{position[0]} {position[1]}", $"{position[2]} {position[3]}", $"amui.switchelement groups view 0 {groupId}");
                    ++count;
                    if (count >= 72) break;
                }
                break;
                case GroupSub.UserGroups : break;
                case GroupSub.AddGroup : {
                    GroupData groupData;
                    if (!groupCreator.TryGetValue(player.userID, out groupData)) {
                        groupCreator.Add(player.userID, new GroupData());
                        groupData = groupCreator[player.userID];
                    }
                    UI.Label(ref container, UIElement, msg("inputhelper", player.UserIDString), 18, "0.1 0.75", "0.9 0.85");
                    UI.Label(ref container, UIElement, msg("groupname", player.UserIDString), 16, "0.1 0.62", "0.3 0.7", TextAnchor.MiddleLeft);
                    UI.Label(ref container, UIElement, msg("uiwarning", player.UserIDString), 8, "0.1 0.15", "0.9 0.2", TextAnchor.MiddleLeft);
                    UI.Panel(ref container, UIElement, uiColors["bg3"], "0.3 0.63", "0.9 0.69");
                    if (string.IsNullOrEmpty(groupData.name)) UI.Input(ref container, UIElement, "", groupData.name, 16, "amui.registergroup input name", "0.32 0.63", "0.9 0.69");
                    else UI.Label(ref container, UIElement, groupData.name, 16, "0.32 0.63", "0.9 0.69", TextAnchor.MiddleLeft);
                    UI.Label(ref container, UIElement, msg("grouptitle", player.UserIDString), 16, "0.1 0.54", "0.3 0.62", TextAnchor.MiddleLeft);
                    UI.Panel(ref container, UIElement, uiColors["bg3"], "0.3 0.55", "0.9 0.61");
                    if (string.IsNullOrEmpty(groupData.title)) UI.Input(ref container, UIElement, "", groupData.title, 16, "amui.registergroup input title", "0.32 0.55", "0.9 0.61");
                    else UI.Label(ref container, UIElement, groupData.title, 16, "0.32 0.55", "0.9 0.61", TextAnchor.MiddleLeft);
                    UI.Label(ref container, UIElement, msg("grouprank", player.UserIDString), 16, "0.1 0.46", "0.3 0.54", TextAnchor.MiddleLeft);
                    UI.Panel(ref container, UIElement, uiColors["bg3"], "0.3 0.47", "0.9 0.53");
                    if (string.IsNullOrEmpty(groupData.rank)) UI.Input(ref container, UIElement, "", groupData.rank, 16, "amui.registergroup input rank", "0.32 0.47", "0.9 0.53");
                    else UI.Label(ref container, UIElement, groupData.rank, 16, "0.32 0.47", "0.9 0.53", TextAnchor.MiddleLeft);
                    UI.Button(ref container, UIElement, uiColors["button2"], msg("reset", player.UserIDString), 16, "0.345 0.38", "0.495 0.44", "amui.registergroup reset");
                    UI.Button(ref container, UIElement, uiColors["button3"], msg("create", player.UserIDString), 16, "0.505 0.38", "0.655 0.44", "amui.registergroup create");
                    break;
                }
                case GroupSub.CloneGroup : {
                    GroupData groupData;
                    if (!groupCreator.TryGetValue(player.userID, out groupData)) {
                        groupCreator.Add(player.userID, groupData = new GroupData() {
                            isClone = true
                        }
                        );
                        groupData = groupCreator[player.userID];
                    }
                    UI.Label(ref container, UIElement, msg("clonehelper", player.UserIDString), 18, "0.1 0.75", "0.9 0.85");
                    UI.Label(ref container, UIElement, msg("uiwarning", player.UserIDString), 8, "0.1 0.1", "0.9 0.15", TextAnchor.MiddleLeft);
                    UI.Label(ref container, UIElement, msg("fromgroupname", player.UserIDString), 16, "0.1 0.62", "0.3 0.7", TextAnchor.MiddleLeft);
                    UI.Panel(ref container, UIElement, uiColors["bg3"], "0.3 0.63", "0.9 0.69");
                    if (string.IsNullOrEmpty(groupData.fromname)) UI.Input(ref container, UIElement, "", groupData.fromname, 16, "amui.registergroup input fromname", "0.32 0.63", "0.9 0.69");
                    else UI.Label(ref container, UIElement, groupData.fromname, 16, "0.32 0.63", "0.9 0.69", TextAnchor.MiddleLeft);
                    UI.Label(ref container, UIElement, msg("groupname", player.UserIDString), 16, "0.1 0.54", "0.3 0.62", TextAnchor.MiddleLeft);
                    UI.Panel(ref container, UIElement, uiColors["bg3"], "0.3 0.55", "0.9 0.61");
                    if (string.IsNullOrEmpty(groupData.name)) UI.Input(ref container, UIElement, "", groupData.name, 16, "amui.registergroup input name", "0.32 0.55", "0.9 0.61");
                    else UI.Label(ref container, UIElement, groupData.name, 16, "0.32 0.55", "0.9 0.61", TextAnchor.MiddleLeft);
                    UI.Label(ref container, UIElement, msg("grouptitle", player.UserIDString), 16, "0.1 0.46", "0.3 0.54", TextAnchor.MiddleLeft);
                    UI.Panel(ref container, UIElement, uiColors["bg3"], "0.3 0.47", "0.9 0.53");
                    if (string.IsNullOrEmpty(groupData.title)) UI.Input(ref container, UIElement, "", groupData.title, 16, "amui.registergroup input title", "0.32 0.47", "0.9 0.53");
                    else UI.Label(ref container, UIElement, groupData.title, 16, "0.32 0.47", "0.9 0.53", TextAnchor.MiddleLeft);
                    UI.Label(ref container, UIElement, msg("grouprank", player.UserIDString), 16, "0.1 0.38", "0.3 0.46", TextAnchor.MiddleLeft);
                    UI.Panel(ref container, UIElement, uiColors["bg3"], "0.3 0.39", "0.9 0.45");
                    if (string.IsNullOrEmpty(groupData.rank)) UI.Input(ref container, UIElement, "", groupData.rank, 16, "amui.registergroup input rank", "0.32 0.39", "0.9 0.45");
                    else UI.Label(ref container, UIElement, groupData.rank, 16, "0.32 0.39", "0.9 0.45", TextAnchor.MiddleLeft);
                    UI.Label(ref container, UIElement, msg("copyusers", player.UserIDString), 16, "0.1 0.30", "0.3 0.38", TextAnchor.MiddleLeft);
                    UI.Toggle(ref container, UIElement, uiColors["bg3"], 16, "0.3 0.31", "0.33 0.37", $"amui.registergroup input users {!groupData.copyusers}", groupData.copyusers);
                    UI.Button(ref container, UIElement, uiColors["button2"], msg("reset", player.UserIDString), 16, "0.345 0.18", "0.495 0.24", "amui.registergroup reset true");
                    UI.Button(ref container, UIElement, uiColors["button3"], msg("clone", player.UserIDString), 16, "0.505 0.18", "0.655 0.24", "amui.registergroup clone");
                    break;
                }
            }
            CuiHelper.DestroyUi(player, UIElement);
            CuiHelper.AddUi(player, container);
        }
        private void CreateMenuCommands(BasePlayer player, CommSub subType, int page = 0, ItemType itemType = ItemType.Weapon) {
            CuiElementContainer container = UI.Container(UIElement, "0 0 0 0", "0.05 0.08", "0.95 0.92");
            CreateMenuButtons(ref container, MenuType.Commands, player.UserIDString);
            CreateSubMenu(ref container, MenuType.Commands, player.UserIDString, subType.ToString());
            if (subType == CommSub.Give) CreateGiveMenu(ref container, itemType, page, player.UserIDString);
            else if (subType == CommSub.Player) {
                SelectionData data;
                if (selectData.TryGetValue(player.userID, out data) && !string.IsNullOrEmpty(data.target1_Id)) CreatePlayerMenu(ref container, data.target1_Id, player.UserIDString);
                else {
                    if (data == null) {
                        data = selectData[player.userID] = new SelectionData() {
                            menuType = MenuType.Commands, pageNum = 0, requireTarget1 = true, returnCommand = "amui.playerinfo", isGroup = false, selectDesc = msg("selectplayer", player.UserIDString), subType = "player", isOnline = true
                        }
                        ;
                    }
                    OpenSelectionMenu(player, SelectType.Player, data.isOnline ? covalence.Players.Connected.ToList() : storedData.GetOfflineList(), true);
                    return;
                }
            }
            else CreateCommandEntry(ref container, subType, page, player.UserIDString);
            CuiHelper.DestroyUi(player, UIElement);
            CuiHelper.AddUi(player, container);
        }
        private void CreateCommandEntry(ref CuiElementContainer container, CommSub subType, int page, string playerId) {
            UI.Label(ref container, UIElement, msg("command", playerId), 16, "0.02 0.82", "0.15 0.87", TextAnchor.MiddleLeft);
            UI.Label(ref container, UIElement, msg("description", playerId), 16, "0.15 0.82", "0.4 0.87", TextAnchor.MiddleLeft);
            UI.Label(ref container, UIElement, msg("command", playerId), 16, "0.52 0.82", "0.65 0.87", TextAnchor.MiddleLeft);
            UI.Label(ref container, UIElement, msg("description", playerId), 16, "0.65 0.82", "0.9 0.87", TextAnchor.MiddleLeft);
            List<CommandEntry> commands = subType == CommSub.Chat ? configData.ChatCommands : configData.ConsoleCommands;
            if (page > 0) UI.Button(ref container, UIElement, uiColors["button1"], msg("back", playerId), 16, "0.015 0.875", "0.145 0.915", $"amui.switchelement commands {subType.ToString()} {page - 1}");
            if (commands.Count > 32 && commands.Count > (32 * page + 32)) UI.Button(ref container, UIElement, uiColors["button1"], msg("next", playerId), 16, "0.855 0.875", "0.985 0.915", $"amui.switchelement commands {subType.ToString()} {page + 1}");
            int count = 1;
            for (int i = page * 32; i < commands.Count; i++) {
                CommandEntry entry = commands[i];
                bool isDivisable = IsDivisableBy2(i);
                UI.Label(ref container, UIElement, entry.Name, 15, $"{(isDivisable ? 0.02f : 0.52f)} {0.82f - (0.05f * count)}", $"{(isDivisable ? 0.15f : 0.65f)} {0.87f - (0.05f * count)}", TextAnchor.MiddleLeft);
                UI.Label(ref container, UIElement, entry.Description, 15, $"{(isDivisable ? 0.15f : 0.65f)} {0.82f - (0.05f * count)}", $"{(isDivisable ? 0.4f : 0.9f)} {0.87f - (0.05f * count)}", TextAnchor.MiddleLeft);
                UI.Button(ref container, UIElement, uiColors["button1"], msg("use", playerId), 15, $"{(isDivisable ? 0.41f : 0.91f)} {(0.82f - (0.05f * count)) + 0.005f}", $"{(isDivisable ? 0.49f : 0.99f)} {(0.87f - (0.05f * count)) - 0.005f}", $"amui.runcommand {subType} {i}");
                if (!isDivisable) ++count;
                if (count > 16) return;
            }
        }
        private void CreateGiveMenu(ref CuiElementContainer container, ItemType itemType, int page, string playerId) {
            UI.Panel(ref container, UIElement, uiColors["bg3"], "0.005 0.005", "0.995 0.055");
            UI.Panel(ref container, UIElement, uiColors["bg3"], "0.005 0.815", "0.995 0.865");
            int i = 0;
            foreach(var typeName in Enum.GetNames(typeof(ItemType))) {
                UI.Button(ref container, UIElement, itemType.ToString() == typeName ? uiColors["button3"] : uiColors["button1"], msg(typeName.ToString(), playerId), 12, $"{0.015f + ((0.97f / 14f) * i) + 0.0025f} 0.82", $"{0.015f + ((0.97f / 14f) * (i + 1)) - 0.0025f} 0.86", itemType.ToString() == typeName ? "" : $"amui.switchelement give {typeName} 0");
                i++;
            }
            //63
            int itemIndex = 60 * page;
            int length = itemList[itemType].Count;
            i = 6;
            List<KeyValuePair<string, ItemDefinition>> items = itemList[itemType].OrderBy(x => x.Value.displayName.english).ToList();
            for (int y = itemIndex; y < length; y++) {
                if (y - itemIndex >= 60) break;
                KeyValuePair<string, ItemDefinition> item = items.ElementAt(y);
                float[] position = CalculateItemPos(i);
                int[] amounts = configData.GiveAmounts[item.Value.category];
                UI.Label(ref container, UIElement, item.Key, 10, $"{position[0]} {position[1]}", $"{position[2]} {position[3]}");
                UI.Button(ref container, UIElement, uiColors["button3"], amounts[0].ToString(), 10, $"{position[2]} {position[1]}", $"{position[2] + (0.158f * 0.24f)} {position[3]}", $"amui.giveitem {item.Value.displayName.english.Replace(" ", "<><>")} {item.Value.shortname} {amounts[0]}");
                UI.Button(ref container, UIElement, uiColors["button3"], amounts[1].ToString(), 10, $"{position[2] + (0.158f * 0.26f)} {position[1]}", $"{position[2] + (0.158f * 0.49f)} {position[3]}", $"amui.giveitem {item.Value.displayName.english.Replace(" ", "<><>")} {item.Value.shortname} {amounts[1]}");
                UI.Button(ref container, UIElement, uiColors["button3"], amounts[2].ToString(), 10, $"{position[2] + (0.158f * 0.51f)} {position[1]}", $"{position[2] + (0.158f * 0.74f)} {position[3]}", $"amui.giveitem {item.Value.displayName.english.Replace(" ", "<><>")} {item.Value.shortname} {amounts[2]}");
                UI.Button(ref container, UIElement, uiColors["button3"], amounts[3].ToString(), 10, $"{position[2] + (0.158f * 0.76f)} {position[1]}", $"{position[2] + 0.158f} {position[3]}", $"amui.giveitem {item.Value.displayName.english.Replace(" ", "<><>")} {item.Value.shortname} {amounts[3]}");
                i += 2;
            }
            if (itemIndex > 0) UI.Button(ref container, UIElement, uiColors["button1"], msg("back", playerId), 10, "0.05 0.01", "0.15 0.05", $"amui.switchelement give {itemType.ToString()} {page - 1}");
            if (itemIndex + 60 < itemList[itemType].Count) UI.Button(ref container, UIElement, uiColors["button1"], msg("next", playerId), 10, "0.85 0.01", "0.95 0.05", $"amui.switchelement give {itemType.ToString()} {page + 1}");
        }
        private void CreatePlayerMenu(ref CuiElementContainer container, string targetId, string playerId) {
            UI.Panel(ref container, UIElement, uiColors["bg3"], "0.005 0.01", "0.25 0.865");
            UI.Panel(ref container, UIElement, uiColors["bg3"], "0.255 0.01", "0.995 0.865");
            IPlayer iPlayer = covalence.Players.FindPlayerById(targetId);
            if (iPlayer == null) {
                UI.Label(ref container, UIElement, $"No data found for {targetId}", 16, "0.01 0.815", "0.24 0.855", TextAnchor.MiddleLeft);
                return;
            }
            ulong userId = ulong.Parse(iPlayer.Id);
            BasePlayer player = BasePlayer.FindByID(userId);
            UI.Label(ref container, UIElement, $"Name: {iPlayer.Name}", 14, "0.01 0.825", "0.24 0.855", TextAnchor.MiddleLeft);
            UI.Label(ref container, UIElement, $"ID: {iPlayer.Id}", 14, "0.01 0.79", "0.24 0.82", TextAnchor.MiddleLeft);
            UI.Label(ref container, UIElement, $"Auth Level: {(DeveloperList.Contains(userId) ? "Developer" : (ServerUsers.Get(userId)?.group ?? ServerUsers.UserGroup.None).ToString())}", 14, "0.01 0.755", "0.24 0.785", TextAnchor.MiddleLeft);
            UI.Label(ref container, UIElement, $"Status: {(player != null && player.IsConnected ? "Online" : "Offline")}", 14, "0.01 0.72", "0.24 0.75", TextAnchor.MiddleLeft);
            if (player != null) {
                // Metabolism
                UI.Label(ref container, UIElement, $"Position: {player.ServerPosition}", 14, "0.01 0.65", "0.24 0.68", TextAnchor.MiddleLeft);
                UI.Label(ref container, UIElement, $"Health: {Math.Round(player.health, 2)}", 14, "0.01 0.58", "0.24 0.61", TextAnchor.MiddleLeft);
                UI.Label(ref container, UIElement, $"Calories: {Math.Round(player.metabolism?.calories?.value ?? 0, 2)}", 14, "0.01 0.545", "0.24 0.575", TextAnchor.MiddleLeft);
                UI.Label(ref container, UIElement, $"Hydration: {Math.Round(player.metabolism?.hydration?.value ?? 0, 2)}", 14, "0.01 0.51", "0.24 0.54", TextAnchor.MiddleLeft);
                UI.Label(ref container, UIElement, $"Temperature: {Math.Round(player.metabolism?.temperature?.value ?? 0, 2)}", 14, "0.01 0.475", "0.24 0.505", TextAnchor.MiddleLeft);
                UI.Label(ref container, UIElement, $"Comfort: {Math.Round(player.metabolism?.comfort?.value ?? 0, 2)}", 14, "0.01 0.44", "0.24 0.47", TextAnchor.MiddleLeft);
                UI.Label(ref container, UIElement, $"Wetness: {Math.Round(player.metabolism?.wetness?.value ?? 0, 2)}", 14, "0.01 0.4", "0.24 0.435", TextAnchor.MiddleLeft);
                UI.Label(ref container, UIElement, $"Bleeding: {Math.Round(player.metabolism?.bleeding?.value ?? 0, 2)}", 14, "0.01 0.365", "0.24 0.395", TextAnchor.MiddleLeft);
                UI.Label(ref container, UIElement, $"Radiation: {Math.Round(player.metabolism?.radiation_level?.value ?? 0, 2)}", 14, "0.01 0.33", "0.24 0.36", TextAnchor.MiddleLeft);
                //Actions
                if (!configData.UsePlayerAdminPermissions || (configData.UsePlayerAdminPermissions && permission.UserHasPermission(playerId, PLAYER_KICKBAN_PERMISSION))) {
                    UI.Button(ref container, UIElement, uiColors["button1"], msg("action.kick", playerId), 14, "0.26 0.825", "0.365 0.855", $"amui.performplayeraction {targetId} {PlayerAction.Kick}");
                    UI.Button(ref container, UIElement, uiColors["button1"], msg("action.ban", playerId), 14, "0.37 0.825", "0.475 0.855", $"amui.performplayeraction {targetId} {PlayerAction.Ban}");
                }
                if (!configData.UsePlayerAdminPermissions || (configData.UsePlayerAdminPermissions && permission.UserHasPermission(playerId, PLAYER_KILL_PERMISSION))) UI.Button(ref container, UIElement, uiColors["button1"], msg("action.kill", playerId), 14, "0.26 0.755", "0.365 0.785", $"amui.performplayeraction {targetId} {PlayerAction.Kill}");
                if (!configData.UsePlayerAdminPermissions || (configData.UsePlayerAdminPermissions && permission.UserHasPermission(playerId, PLAYER_STRIP_PERMISSION))) UI.Button(ref container, UIElement, uiColors["button1"], msg("action.stripinventory", playerId), 14, "0.37 0.755", "0.475 0.785", $"amui.performplayeraction {targetId} {PlayerAction.StripInventory}");
                if (!configData.UsePlayerAdminPermissions || (configData.UsePlayerAdminPermissions && permission.UserHasPermission(playerId, PLAYER_HEAL_PERMISSION))) UI.Button(ref container, UIElement, uiColors["button1"], msg("action.resetmetabolism", playerId), 14, "0.48 0.755", "0.585 0.785", $"amui.performplayeraction {targetId} {PlayerAction.ResetMetabolism}");
                if (!configData.UsePlayerAdminPermissions || (configData.UsePlayerAdminPermissions && permission.UserHasPermission(playerId, PLAYER_MUTE_PERMISSION))) {
                    UI.Button(ref container, UIElement, uiColors["button1"], msg("action.mutechat", playerId), 14, "0.26 0.685", "0.365 0.715", $"amui.performplayeraction {targetId} {PlayerAction.MuteChat}");
                    UI.Button(ref container, UIElement, uiColors["button1"], msg("action.unmutechat", playerId), 14, "0.37 0.685", "0.475 0.715", $"amui.performplayeraction {targetId} {PlayerAction.UnmuteChat}");
                }
                if (!configData.UsePlayerAdminPermissions || (configData.UsePlayerAdminPermissions && permission.UserHasPermission(playerId, PLAYER_BLUERPRINTS_PERMISSION))) {
                    UI.Button(ref container, UIElement, uiColors["button1"], msg("action.resetblueprints", playerId), 14, "0.26 0.615", "0.365 0.645", $"amui.performplayeraction {targetId} {PlayerAction.ResetBlueprints}");
                    UI.Button(ref container, UIElement, uiColors["button1"], msg("action.giveblueprints", playerId), 14, "0.37 0.615", "0.475 0.645", $"amui.performplayeraction {targetId} {PlayerAction.GiveBlueprints}");
                }
                if (!configData.UsePlayerAdminPermissions || (configData.UsePlayerAdminPermissions && permission.UserHasPermission(playerId, PLAYER_HURT_PERMISSION))) {
                    UI.Button(ref container, UIElement, uiColors["button1"], msg("action.hurt25", playerId), 14, "0.26 0.545", "0.365 0.575", $"amui.performplayeraction {targetId} {PlayerAction.Hurt25}");
                    UI.Button(ref container, UIElement, uiColors["button1"], msg("action.hurt50", playerId), 14, "0.37 0.545", "0.475 0.575", $"amui.performplayeraction {targetId} {PlayerAction.Hurt50}");
                    UI.Button(ref container, UIElement, uiColors["button1"], msg("action.hurt75", playerId), 14, "0.48 0.545", "0.585 0.575", $"amui.performplayeraction {targetId} {PlayerAction.Hurt75}");
                }
                if (!configData.UsePlayerAdminPermissions || (configData.UsePlayerAdminPermissions && permission.UserHasPermission(playerId, PLAYER_HEAL_PERMISSION))) {
                    UI.Button(ref container, UIElement, uiColors["button1"], msg("action.heal25", playerId), 14, "0.26 0.51", "0.365 0.54", $"amui.performplayeraction {targetId} {PlayerAction.Heal25}");
                    UI.Button(ref container, UIElement, uiColors["button1"], msg("action.heal50", playerId), 14, "0.37 0.51", "0.475 0.54", $"amui.performplayeraction {targetId} {PlayerAction.Heal50}");
                    UI.Button(ref container, UIElement, uiColors["button1"], msg("action.heal75", playerId), 14, "0.48 0.51", "0.585 0.54", $"amui.performplayeraction {targetId} {PlayerAction.Heal75}");
                    UI.Button(ref container, UIElement, uiColors["button1"], msg("action.heal100", playerId), 14, "0.59 0.51", "0.695 0.54", $"amui.performplayeraction {targetId} {PlayerAction.Heal100}");
                }
                if (!configData.UsePlayerAdminPermissions || (configData.UsePlayerAdminPermissions && permission.UserHasPermission(playerId, PLAYER_TELEPORT_PERMISSION))) UI.Button(ref container, UIElement, uiColors["button1"], msg("action.teleportselfto", playerId), 14, "0.26 0.44", "0.365 0.47", $"amui.performplayeraction {targetId} {PlayerAction.TeleportSelfTo}");
                if (!configData.UsePlayerAdminPermissions || (configData.UsePlayerAdminPermissions && permission.UserHasPermission(playerId, PERM_PERMISSION))) UI.Button(ref container, UIElement, uiColors["button1"], msg("action.permissions", playerId), 14, "0.37 0.44", "0.475 0.47", $"amui.performplayeraction {targetId} {PlayerAction.Permissions}");
            }
            else {
                if (!configData.UsePlayerAdminPermissions || (configData.UsePlayerAdminPermissions && permission.UserHasPermission(playerId, PLAYER_KICKBAN_PERMISSION))) UI.Button(ref container, UIElement, uiColors["button1"], msg("action.ban", playerId), 14, "0.37 0.825", "0.475 0.855", $"amui.performplayeraction {targetId} {PlayerAction.Ban}");
                if (!configData.UsePlayerAdminPermissions || (configData.UsePlayerAdminPermissions && permission.UserHasPermission(playerId, PLAYER_MUTE_PERMISSION))) {
                    UI.Button(ref container, UIElement, uiColors["button1"], msg("action.mutechat", playerId), 14, "0.26 0.685", "0.365 0.715", $"amui.performplayeraction {targetId} {PlayerAction.MuteChat}");
                    UI.Button(ref container, UIElement, uiColors["button1"], msg("action.unmutechat", playerId), 14, "0.37 0.685", "0.475 0.715", $"amui.performplayeraction {targetId} {PlayerAction.UnmuteChat}");
                }
                if (!configData.UsePlayerAdminPermissions || (configData.UsePlayerAdminPermissions && permission.UserHasPermission(playerId, PERM_PERMISSION))) UI.Button(ref container, UIElement, uiColors["button1"], msg("action.permissions", playerId), 14, "0.37 0.44", "0.475 0.47", $"amui.performplayeraction {targetId} {PlayerAction.Permissions}");
            }
        }
        private enum PlayerAction {
            Ban, Kick, Kill, MuteChat, UnmuteChat, StripInventory, ResetBlueprints, GiveBlueprints, ResetMetabolism, Hurt25, Hurt50, Hurt75, Heal25, Heal50, Heal75, Heal100, TeleportSelfTo, Permissions
        }
        private void OpenSelectionMenu(BasePlayer player, SelectType selectType, object objList, bool sortList = false) {
            SelectionData data = selectData[player.userID];
            CuiElementContainer container = UI.Container(UIElement, "0 0 0 0", "0.05 0.08", "0.95 0.92");
            UI.Panel(ref container, UIElement, uiColors["bg3"], "0.005 0.925", "0.995 0.99");
            UI.Panel(ref container, UIElement, uiColors["bg3"], "0.005 0.87", "0.995 0.92");
            CreateCharacterFilter(ref container, player.userID, data.character, string.Empty);
            UI.Label(ref container, UIElement, data.selectDesc, 24, "0.02 0.93", "0.8 0.985", TextAnchor.MiddleLeft);
            UI.Button(ref container, UIElement, uiColors["button1"], msg("return", player.UserIDString), 16, "0.855 0.93", "0.985 0.985", $"amui.switchelement {(data.menuType == MenuType.Commands ? "commands" : data.menuType == MenuType.Groups ? "groups" : "permissions")} {(data.subType.Equals("player") ? "chat" : data.subType)}");
            List<IPlayer> playerList = null;
            List<string> stringList = null;
            switch (selectType) {
                case SelectType.Player : playerList = (List<IPlayer>)objList;
                if (!string.IsNullOrEmpty(data.character)) playerList = playerList.Where(x => x.Name.ToLower().StartsWith(data.character.ToLower())).ToList();
                if (sortList) playerList = playerList.OrderBy(x => x.Name).ToList();
                if (!data.forceOnline) {
                    UI.Button(ref container, UIElement, data.isOnline ? uiColors["button3"] : uiColors["button1"], msg("onlineplayers", player.UserIDString), 16, "0.3475 0.875", "0.4975 0.915", data.isOnline ? "" : $"amui.makeselection online");
                    UI.Button(ref container, UIElement, !data.isOnline ? uiColors["button3"] : uiColors["button1"], msg("offlineplayers", player.UserIDString), 16, "0.5025 0.875", "0.6525 0.915", !data.isOnline ? "" : $"amui.makeselection offline");
                }
                break;
                case SelectType.String : stringList = (List<string>)objList;
                if (!string.IsNullOrEmpty(data.character)) stringList = stringList.Where(x => x.StartsWith(data.character)).ToList();
                if (sortList) stringList.Sort();
                break;
            }
            if (data.pageNum > 0) UI.Button(ref container, UIElement, uiColors["button1"], msg("back", player.UserIDString), 16, "0.015 0.875", "0.145 0.915", "amui.makeselection pageDown");
            if (selectType == SelectType.Player ? (playerList.Count > 72 && playerList.Count > (72 * data.pageNum + 72)) : stringList.Count > 72 && stringList.Count > (72 * data.pageNum + 72)) UI.Button(ref container, UIElement, uiColors["button1"], msg("next", player.UserIDString), 16, "0.855 0.875", "0.985 0.915", "amui.makeselection pageUp");
            int count = 0;
            for (int i = data.pageNum * 72; i < (selectType == SelectType.Player ? playerList.Count : stringList.Count);
            i++) {
                float[] position = CalculateButtonPos(count);
                if (selectType == SelectType.Player) {
                    IPlayer target = playerList[i];
                    string userName = StripTags(target.Name);
                
// ... [Code preview truncated due to length. Full source in attached file] ...

Автор
15FPS
Скачиваний
0
Просмотры
1
Первый выпуск
Обновление
Оценка
0.00 звёзд 0 оценок
Сверху