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

FREE AdminMenu : 1.0.2 1.0.2

Нет прав для скачивания
C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
using Oxide.Core.Plugins;
using System.Collections.Generic;
using Network;
using System.Collections;
using System.Linq;
using System;
using UnityEngine;
using Newtonsoft.Json;
using Oxide.Game.Rust.Cui;
using UnityEngine.UI;
using Oxide.Core.Libraries.Covalence;
using System.Text.RegularExpressions;
using System.IO;
using System.Reflection;
namespace Oxide.Plugins {
    [Info("AdminMenu", "0xF", "1.0.2")]
    [Description("Multifunctional in-game admin menu.")]
    public class AdminMenu : RustPlugin {
        [PluginReference]
        private Plugin ImageLibrary, Economics, ServerRewards, Clans;
        private const string PERMISSION_USE = "adminmenu.use";
        private const string PERMISSION_FULLACCESS = "adminmenu.fullaccess";
        private const string PERMISSION_CONVARS = "adminmenu.convars";
        private const string PERMISSION_PERMISSIONMANAGER = "adminmenu.permissionmanager";
        private const string PERMISSION_PLUGINMANAGER = "adminmenu.pluginmanager";
        private const string PERMISSION_GIVE = "adminmenu.give";
        private const string ADMINMENU_IMAGEBASE64 = "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";
        private static AdminMenu Instance;
        private static Dictionary<string, Panel> panelList;
        private static string ADMINMENU_IMAGECRC;
        private MainMenu mainMenu;
        private Dictionary<string, string> defaultLang = new Dictionary<string, string>();
        static Configuration config;
        public AdminMenu() {
            Instance = this;
        }
        public class ButtonArray<T> : List<T> where T : Button {
            public ButtonArray() : base() {
            }
            public ButtonArray(IEnumerable<T> collection) : base(collection) {
            }
            public IEnumerable<T> GetAllowedButtons(Connection connection) {
                return GetAllowedButtons(connection.userid.ToString());
            }
            public IEnumerable<T> GetAllowedButtons(string userId) {
                return this.Where(b => b == null || b.UserHasPermission(userId));
            }
        }
        public class ButtonArray : ButtonArray<Button> {
        }
        public class Button {
            private string label = null;
            private string permission = null;
            public string Command {
                get;
                set;
            }
            public string[] Args {
                get;
                set;
            }
            public Label Label {
                get;
                set;
            }
            public virtual int FontSize {
                get;
                set;
            }
            = 14;
            public string BackgroundColor {
                get;
                set;
            }
            public string Permission {
                get {
                    return permission;
                }
                set {
                    permission = string.Format("adminmenu.{0}", value);
                    if (!Instance.permission.PermissionExists(permission)) Instance.permission.RegisterPermission(permission, Instance);
                }
            }
            public Button(string label, string backgroundColor, string command, params string[] args) {
                Label = new Label(label);
                BackgroundColor = backgroundColor;
                Command = command;
                Args = args;
            }
            public void Press(ConnectionData connectionData) {
                connectionData.userData[$"button_{this.GetHashCode()}.state.pressed"] = true;
            }
            public void Unpress(ConnectionData connectionData) {
                connectionData.userData[$"button_{this.GetHashCode()}.state.pressed"] = false;
            }
            public bool UserHasPermission(Connection connection) {
                return UserHasPermission(connection.userid.ToString());
            }
            public bool UserHasPermission(string userId) {
                return permission == null || Instance.permission.UserHasPermission(userId, PERMISSION_FULLACCESS) || Instance.permission.UserHasPermission(userId, Permission);
            }
            public virtual bool IsPressed(ConnectionData connectionData) {
                bool result = false;
                if (connectionData.userData.TryGetValue($"button_{this.GetHashCode()}.state.pressed", out object state)) result = (bool)state;
                return result;
            }
            public virtual bool IsHidden(ConnectionData connectionData) {
                return false;
            }
        }
        public class CategoryButton : Button {
            public override int FontSize {
                get;
                set;
            }
            = 22;
            public CategoryButton(string label, string command, params string[] args) : base(label, null, command, args) {
            }
        }
        public class HideButton : Button {
            public HideButton(string label, string command, params string[] args) : base(label, null, command, args) {
            }
            public override bool IsHidden(ConnectionData connectionData) {
                return connectionData.userData["backcommand"] == null;
            }
        }
        public static class SidebarCollection {
            private static Dictionary<string, Sidebar> all = new Dictionary<string, Sidebar>();
            public static Sidebar TryGet(string key) {
                if (all.TryGetValue(key, out Sidebar sidebars)) return sidebars;
                return null;
            }
            public static void Set(string key, Sidebar value) {
                all[key] = value;
            }
        }
        public static class ContentCollection {
            private static Dictionary<string, Content> all = new Dictionary<string, Content>();
            public static Content TryGet(string key) {
                if (all.TryGetValue(key, out Content content)) return content;
                return null;
            }
            public static void Set(string key, Content value) {
                all[key] = value;
            }
        }
        public static class Collector {
            public static void CollectAll() {
                CollectPluginsStaff();
            }
            public static void CollectPluginsStaff() {
                List<string> all_permissions = Instance.permission.GetPermissions().ToList();
                List<string> pluginNames = new List<string>();
                foreach (var plugin in Instance.plugins.GetAll()) {
                    if (plugin.IsCorePlugin) continue;
                    string pluginName = plugin.Name;
                    string pluginNameLower = plugin.ToString().Replace("Oxide.Plugins.", "").ToLower();
                    IEnumerable<string> permissions = all_permissions.Where(perm => perm.ToLower().Contains($"{pluginNameLower}"));
                    if (permissions.Count() > 0) {
                        pluginNames.Add(pluginName);
                        ContentCollection.Set($"permissions.{pluginName.GetHashCode()}", new PermissionsContent {
                            plugin = plugin, permissions = permissions.ToArray()
                        }
                        );
                    }
                }
                pluginNames = pluginNames.OrderBy(name => name).ToList();
                int pluginsCount = pluginNames.Count;
                int amountPerPage = 12;
                int c = Mathf.CeilToInt(pluginsCount / (float)amountPerPage);
                for (int i = 0; i < c; i++) {
                    List<string> range = pluginNames.GetRange(i * amountPerPage, Mathf.Min(amountPerPage, pluginsCount - i * amountPerPage));
                    ButtonArray<CategoryButton> buttons = new ButtonArray<CategoryButton>();
                    if (i > 0) buttons.Add(new CategoryButton("PREV PAGE", "permissions.pluginlistpage.open", $"{i - 1}") {
                        FontSize = 18
                    }
                    );
                    buttons.AddRange(range.Select(name => new CategoryButton(name, "permissions.pluginpermissions.open", name.GetHashCode().ToString()) {
                        FontSize = 18
                    }
                    ));
                    if (i < c - 1) buttons.Add(new CategoryButton("NEXT PAGE", "permissions.pluginlistpage.open", $"{i + 1}") {
                        FontSize = 18
                    }
                    );
                    SidebarCollection.Set($"pluginpermissions.{i}", new Sidebar() {
                        AutoActivateCategoryButtonIndex = -1, CategoryButtons = buttons
                    }
                    );
                }
            }
        }
        public class Configuration {
            [JsonProperty(PropertyName = "Text under the ADMIN MENU")]
            public string Subtext {
                get;
                set;
            }
            = "BY 0XF";
            [JsonProperty(PropertyName = "Disable X button hook")]
            public bool DisableSwapSeatsHook {
                get;
                set;
            }
            = false;
            [JsonProperty(PropertyName = "Chat command to show admin menu")]
            public string ChatCommand {
                get;
                set;
            }
            = "admin";
            public static Configuration DefaultConfig() {
                return new Configuration();
            }
        }
        public class ConnectionData {
            public Connection connection;
            public MainMenu currentMainMenu;
            public Panel currentPanel;
            public Sidebar currentSidebar;
            public Content currentContent;
            public Dictionary<string, object> userData;
            public ConnectionData(BasePlayer player) : this(player.Connection) {
            }
            public ConnectionData(Connection connection) {
                this.connection = connection;
                this.userData = new Dictionary<string, object>() {
                    {
                        "userId", connection.userid
                    }
                    , {
                        "userinfo.lastuserid", connection.userid
                    }
                    , {
                        "backcommand", null
                    }
                    ,
                }
                ;
                this.UI = new ConnectionUI(this);
                try {
                    Init();
                }
                catch (Exception ex) {
                    UnityEngine.Debug.LogException(ex);
                }
            }
            public ConnectionUI UI {
                get;
                private set;
            }
            public bool IsAdminMenuDisplay {
                get;
                set;
            }
            public bool IsDestroyed {
                get;
                set;
            }
            public void Init() {
                UI.RenderMainMenu(Instance.mainMenu);
                this.currentMainMenu = Instance.mainMenu;
            }
            public void ShowAdminMenu() {
                UI.ShowAdminMenu();
                IsAdminMenuDisplay = true;
            }
            public void HideAdminMenu() {
                UI.HideAdminMenu();
                IsAdminMenuDisplay = false;
            }
            public void OpenPanel(string panelName) {
                if (panelList.TryGetValue(panelName, out Panel panel)) {
                    if (currentPanel == panel) return;
                    if (currentContent != null) currentContent.RestoreUserData(userData);
                    currentContent = null;
                    if (currentPanel != null) currentPanel.OnClose(this);
                    currentPanel = panel;
                    currentSidebar = currentPanel.Sidebar;
                    UI.RenderPanel(currentPanel);
                    currentPanel.OnOpen(this);
                    Content defaultPanelContent = panel.DefaultContent;
                    if (defaultPanelContent != null) ShowPanelContent(defaultPanelContent);
                    if (panel.Sidebar != null && panel.Sidebar.AutoActivateCategoryButtonIndex.HasValue) Instance.HandleCommand(connection, "uipanel.sidebar.button_pressed", panel.Sidebar.AutoActivateCategoryButtonIndex.Value.ToString(), panel.Sidebar.CategoryButtons.GetAllowedButtons(connection).Count().ToString());
                }
                else {
                    Instance.PrintError($"Panel with name \"{panelName}\" not founded!");
                }
            }
            public void SetSidebar(Sidebar sidebar) {
                bool needsChangeContentSize = (currentSidebar != sidebar);
                currentSidebar = sidebar;
                CUI.Root root = new CUI.Root("AdminMenu_Panel");
                if (sidebar != null) UI.AddSidebar(root, sidebar);
                else root.Add(new CUI.Element {
                    DestroyUi = "AdminMenu_Panel_Sidebar"
                }
                );
                root.Render(connection);
                if (needsChangeContentSize) {
                    CUI.Root updateRoot = new CUI.Root();
                    updateRoot.Add(new CUI.Element {
                        Components = {
                            new CuiRectTransformComponent {
                                OffsetMin = $"{(sidebar != null ? 250 : 0)} 0",
                            }
                        }
                        , Name = "AdminMenu_Panel_Content"
                    }
                    );
                    updateRoot.Update(connection);
                }
            }
            public void ShowPanelContent(Content content) {
                if (content == null) {
                    CUI.Root root = new CUI.Root();
                    root.Add(new CUI.Element {
                        DestroyUi = "AdminMenu_Panel_TempContent"
                    }
                    );
                    root.Render(connection);
                    return;
                }
                if (currentContent != null) currentContent.RestoreUserData(userData);
                currentContent = content;
                currentContent.LoadDefaultUserData(userData);
                UI.RenderContent(content);
            }
            public void ShowPanelContent(string contentId) {
                ShowPanelContent(currentPanel.TryGetContent(contentId));
            }
            public void Dispose() {
                all.Remove(connection);
            }
            public static Dictionary<Connection, ConnectionData> all = new Dictionary<Connection, ConnectionData>();
            public static ConnectionData Get(Connection connection) {
                if (connection == null) return null;
                ConnectionData data;
                if (all.TryGetValue(connection, out data)) return data;
                return null;
            }
            public static ConnectionData Get(BasePlayer player) {
                return Get(player.Connection);
            }
            public static ConnectionData GetOrCreate(Connection connection) {
                if (connection == null) return null;
                ConnectionData data = Get(connection);
                if (data == null) data = all[connection] = new ConnectionData(connection);
                return data;
            }
            public static ConnectionData GetOrCreate(BasePlayer player) {
                return GetOrCreate(player.Connection);
            }
        }
        public class ConnectionUI {
            Connection connection;
            ConnectionData connectionData;
            public ConnectionUI(ConnectionData connectionData) {
                this.connectionData = connectionData;
                this.connection = connectionData.connection;
            }
            public void ShowAdminMenu() {
                CUI.Root root = new CUI.Root();
                root.Add(new CUI.Element {
                    Components = {
                        new CuiRectTransformComponent {
                            AnchorMin = "0 0.00001", AnchorMax = "1 1.00001"
                        }
                    }
                    , Name = "AdminMenu", Update = true
                }
                );
                root.Add(new CUI.Element {
                    Components = {
                        new CuiNeedsCursorComponent()
                    }
                    , Parent = "AdminMenu", Name = "AdminMenu_Cursor"
                }
                );
                root.Render(connection);
            }
            public void HideAdminMenu() {
                CUI.Root root = new CUI.Root();
                root.Add(new CUI.Element {
                    Components = {
                        new CuiRectTransformComponent {
                            AnchorMin = "1000 1000", AnchorMax = "1001 1001"
                        }
                    }
                    , DestroyUi = "AdminMenu_Cursor", Name = "AdminMenu", Update = true
                }
                );
                root.Render(connection);
            }
            public void DestroyAdminMenu() {
                CuiHelper.DestroyUi(connection.player as BasePlayer, "AdminMenu");
                connectionData.IsDestroyed = true;
            }
            public void DestroyAll() {
                DestroyAdminMenu();
                CuiHelper.DestroyUi(connection.player as BasePlayer, "AdminMenu_OpenButton");
            }
            public void AddSidebar(CUI.Element element, Sidebar sidebar) {
                if (sidebar == null) return;
                var sidebarPanel = element.AddPanel(color : "0.784 0.329 0.247 0.427", material : "assets/content/ui/uibackgroundblur-ingamemenu.mat", imageType : Image.Type.Tiled, anchorMin : "0 0", anchorMax : "0 1", offsetMin : "0 0", offsetMax : "250 0", name : "AdminMenu_Panel_Sidebar").AddDestroySelfAttribute();
                sidebarPanel.AddPanel(color : "0.217 0.217 0.217 0.796", sprite : "assets/content/ui/ui.background.transparent.linear.psd", material : "assets/content/ui/namefontmaterial.mat", anchorMin : "0 0", anchorMax : "1 1");
                IEnumerable<CategoryButton> categoryButtons = sidebar.CategoryButtons.GetAllowedButtons(connection);
                if (categoryButtons != null) {
                    int categoryButtonsCount = categoryButtons.Count();
                    if (categoryButtonsCount == 0) return;
                    var sidebarButtonGroup = sidebarPanel.AddContainer(anchorMin : "0 0.5", anchorMax : "1 0.5", offsetMin : $"0 -{categoryButtonsCount * 48 / 2}", offsetMax : $"0 {categoryButtonsCount * 48 / 2}");
                    for (int i = 0; i < categoryButtonsCount; i++) {
                        CategoryButton categoryButton = categoryButtons.ElementAt(i);
                        sidebarButtonGroup.AddButton(command : $"adminmenu uipanel.sidebar.button_pressed {i} {categoryButtonsCount}", color : $"0 0 0 0", anchorMin : "0 1", anchorMax : "1 1", offsetMin : $"16 -{(i + 1) * 48}", offsetMax : $"0 -{i * 48}", name : $"UIPanel_SideBar_Button{i}").AddText(text : categoryButton.Label.Localize(connection), color : "0.969 0.922 0.882 1", font : CUI.Font.RobotoCondensedBold, fontSize : categoryButton.FontSize, align : TextAnchor.MiddleRight, offsetMin : "16 0", offsetMax : "-16 0");
                    }
                }
            }
            private void AddNavButtons(CUI.Element element, MainMenu mainMenu) {
                IEnumerable<Button> navButtons = mainMenu.NavButtons.GetAllowedButtons(connection);
                int navButtonsCount = navButtons.Count();
                var navButtonGroup = element.AddContainer(anchorMin : "0 0", anchorMax : "1 0", offsetMin : "64 64", offsetMax : $"0 {64 + navButtonsCount * 42}", name : "Navigation ButtonGroup").AddDestroySelfAttribute();
                for (int i = 0; i < navButtonsCount; i++) {
                    Button navButton = navButtons.ElementAtOrDefault(i);
                    if (navButton == null) continue;
                    navButtonGroup.AddButton(command : navButton.IsHidden(connectionData) ? null : $"adminmenu navigation.button_pressed {i} {navButtonsCount}", anchorMin : "0 1", anchorMax : "1 1", offsetMin : $"0 -{(i + 1) * 42}", offsetMax : $"0 -{i * 42}").AddText(text : navButton.Label.Localize(connection).ToUpper(), color : $"0.969 0.922 0.882 {(navButton.IsHidden(connectionData) ? 0 : (navButton.IsPressed(connectionData) ? 1 : 0.180f))}", fontSize : 28, font : CUI.Font.RobotoCondensedBold, align : TextAnchor.LowerLeft, overflow : VerticalWrapMode.Truncate, offsetMin : "10 5", name : $"NavigationButtonText{i}");
                }
            }
            public void UpdateNavButtons(MainMenu mainMenu) {
                CUI.Root root = new CUI.Root("AdminMenu_Navigation");
                AddNavButtons(root, mainMenu);
                root.Render(connection);
            }
            public void RenderOverlayOpenButton() {
                CUI.Root root = new CUI.Root("Overlay");
                root.AddButton(command : "adminmenu", color : "0.969 0.922 0.882 0.035", material : "assets/icons/greyout.mat", anchorMin : "0 0", anchorMax : "0 0", offsetMin : "0 0", offsetMax : "100 30", name : "AdminMenu_OpenButton").AddDestroySelfAttribute().AddText(text : "ADMIN MENU", color : "0.969 0.922 0.882 0.45", font : CUI.Font.RobotoCondensedBold, fontSize : 14, align : TextAnchor.MiddleCenter);
                root.Render(connection);
            }
            public void RenderMainMenu(MainMenu mainMenu) {
                if (mainMenu == null) return;
                CUI.Root root = new CUI.Root("Overlay");
                var container = root.AddPanel(color : "0.169 0.162 0.143 1", material : "assets/content/ui/uibackgroundblur-mainmenu.mat", imageType : Image.Type.Tiled, anchorMin : "1000 1000", anchorMax : "1001 1001", name : "AdminMenu").AddDestroySelfAttribute();
                container.AddPanel(color : "0.301 0.283 0.235 1", sprite : "assets/content/ui/ui.background.transparent.radial.psd", material : "assets/content/ui/namefontmaterial.mat", anchorMin : "0 0", anchorMax : "1 1");
                container.AddPanel(color : "0.169 0.162 0.143 0.384", sprite : "assets/content/ui/ui.background.transparent.radial.psd", material : "assets/content/ui/namefontmaterial.mat", anchorMin : "0 0", anchorMax : "1 1");
                var navigation = container.AddContainer(anchorMin : "0 0", anchorMax : "0 1", offsetMin : "0 0", offsetMax : "350 0", name : "AdminMenu_Navigation");
                var homeButton = navigation.AddContainer( //command: "adminmenu homebutton",
                anchorMin : "0 1", anchorMax : "1 1", offsetMin : $"64 -{102f + 32}", offsetMax : "0 -32");
                homeButton.AddImage(content : ADMINMENU_IMAGECRC, color : "0.811 0.811 0.811 1", material : "assets/content/ui/namefontmaterial.mat", anchorMin : "0 0", anchorMax : "0 1", offsetMax : $"146.4 0");
                homeButton.AddText(text : config.Subtext, color : "0.824 0.824 0.824 1", font : CUI.Font.RobotoCondensedBold, fontSize : 16, anchorMin : "0 0", anchorMax : "0 0", offsetMin : "0 -35", offsetMax : "146.4 -10");
                AddNavButtons(navigation, mainMenu);
                var body = container.AddContainer(anchorMin : "0 0", anchorMax : "1 1", offsetMin : "350 0", offsetMax : "-64 0", name : "AdminMenu_Body");
                var right = container.AddContainer(anchorMin : "1 0", anchorMax : "1 1", offsetMin : "-64 0", offsetMax : "0 0");
                root.Render(connection);
                connectionData.IsDestroyed = false;
            }
            public void RenderPanel(Panel panel) {
                if (panel == null) return;
                CUI.Root root = new CUI.Root("AdminMenu_Body");
                var container = root.AddContainer(anchorMin : "0 0", anchorMax : "1 1", name : "AdminMenu_Panel").AddDestroySelfAttribute();
                Sidebar sidebar = panel.Sidebar;
                if (sidebar != null) AddSidebar(container, sidebar);
                CUI.Element panelBackground = container.AddContainer(anchorMin : "0 0", anchorMax : "1 1", offsetMin : $"{(sidebar != null ? 250 : 0)} 0", offsetMax : "0 0", name : "AdminMenu_Panel_Content");
                if (true) {
                    panelBackground = panelBackground.AddPanel(color : "1 1 1 1", material : "assets/content/ui/menuui/mainmenu.panel.mat", imageType : Image.Type.Tiled);
                }
                root.Render(connection);
            }
            public void RenderContent(Content content) {
                if (content == null) return;
                CUI.Root root = new CUI.Root("AdminMenu_Panel_Content");
                var container = root.AddContainer(name : "AdminMenu_Panel_TempContent").AddDestroySelfAttribute();
                root.Render(connection);
                content.Render(connectionData);
            }
        }
        public class Label {
            private static readonly Regex richTextRegex = new Regex(@"<[^>]*>");
            string label;
            string langKey;
            public Label(string label) {
                this.label = label;
                this.langKey = richTextRegex.Replace(label.ToPrintable(), string.Empty).Trim();
                if (!Instance.defaultLang.ContainsKey(this.langKey)) Instance.defaultLang.Add(this.langKey, label);
            }
            public override string ToString() {
                return label;
            }
            public string Localize(string userId) {
                return Instance.lang.GetMessage(this.langKey, Instance, userId);
            }
            public string Localize(Connection connection) {
                return Localize(connection.userid.ToString());
            }
        }
        public class MainMenu {
            public ButtonArray NavButtons {
                get;
                set;
            }
        }
        public class Panel {
            public virtual Sidebar Sidebar {
                get;
                set;
            }
            public virtual Dictionary<string, Content> Content {
                get;
                set;
            }
            public Content DefaultContent {
                get => TryGetContent("default");
            }
            public Content TryGetContent(string id) {
                if (Content == null) return null;
                if (Content.TryGetValue(id, out Content content)) return content;
                return null;
            }
            public virtual void OnOpen(ConnectionData connectionData) {
                connectionData.UI.UpdateNavButtons(connectionData.currentMainMenu);
            }
            public virtual void OnClose(ConnectionData connectionData) {
                connectionData.userData["backcommand"] = null;
            }
        }
        public class UserInfoPanel : Panel {
        }
        public class PermissionPanel : Panel {
            public override Sidebar Sidebar {
                get => SidebarCollection.TryGet("pluginpermissions.0");
            }
            public override void OnClose(ConnectionData connectionData) {
                connectionData.userData["backcommand"] = null;
            }
        }
        public class Sidebar {
            public ButtonArray<CategoryButton> CategoryButtons {
                get;
                set;
            }
            public int? AutoActivateCategoryButtonIndex {
                get;
                set;
            }
            = 0;
        }
        public class CUI {
            private static readonly string[] FontNames = new string[] {
                "RobotoCondensed-Bold.ttf", "RobotoCondensed-Regular.ttf", "RobotoMono-Regular.ttf", "DroidSansMono.ttf", "PermanentMarker.ttf"
            }
            ;
            public enum Font {
                RobotoCondensedBold, RobotoCondensedRegular, RobotoMonoRegular, DroidSansMono, PermanentMarker
            }
            public static void AddUI(Connection connection, string json) {
                CommunityEntity.ServerInstance.ClientRPCEx<string>(new SendInfo {
                    connection = connection
                }
                , null, "AddUI", json);
            }
            [JsonObject(MemberSerialization.OptIn)]
            public class Element : CuiElement {
                public string elementName;
                public new string Name {
                    get => elementName;
                    set {
                        if (value == null) return;
                        elementName = value;
                    }
                }
                public Element ParentElement {
                    get;
                    set;
                }
                public virtual List<Element> Container => ParentElement?.Container;
                [JsonProperty("name")]
                public string JsonName {
                    get {
                        if (Name == null) SetupDefaultName();
                        return Name;
                    }
                }
                public Element() {
                }
                public Element(Element parent) {
                    AssignParent(parent);
                }
                public void SetupDefaultName() {
                    Name = Guid.NewGuid().ToString().MurmurHashSigned().ToString();
                }
                public void AssignParent(Element parent) {
                    if (parent == null) return;
                    ParentElement = parent;
                    Parent = ParentElement.Name;
                    Name = Parent.MurmurHashSigned().ToString();
                }
                public Element AddDestroySelfAttribute() {
                    this.DestroyUi = this.Name;
                    return this;
                }
                public Element Add(Element element) {
                    if (element.Name == null && element.ParentElement == null) element.AssignParent(this);
                    Container.Add(element);
                    return element;
                }
                public Element AddText(string text = "Text", string color = "1 1 1 1", Font font = Font.RobotoCondensedRegular, int fontSize = 14, TextAnchor align = TextAnchor.UpperLeft, VerticalWrapMode overflow = VerticalWrapMode.Overflow, string anchorMin = "0 0", string anchorMax = "1 1", string offsetMin = "0 0", string offsetMax = "0 0", float fadeIn = 0f, float fadeOut = 0f, string name = null) {
                    return Add(new Element(this) {
                        Components = {
                            new CuiTextComponent {
                                Text = text, Color = color, Font = FontNames[(int)font], VerticalOverflow = overflow, FontSize = fontSize, Align = align, FadeIn = fadeIn
                            }
                            , new CuiRectTransformComponent() {
                                AnchorMin = anchorMin, AnchorMax = anchorMax, OffsetMin = offsetMin, OffsetMax = offsetMax
                            }
                            ,
                        }
                        , Name = name, FadeOut = fadeOut
                    }
                    );
                }
                public Element AddOutlinedText(string text = "Text", string color = "1 1 1 1", Font font = Font.RobotoCondensedRegular, int fontSize = 14, TextAnchor align = TextAnchor.UpperLeft, VerticalWrapMode overflow = VerticalWrapMode.Overflow, string outlineColor = "0 0 0 1", float outlineWidth = 1, string anchorMin = "0 0", string anchorMax = "1 1", string offsetMin = "0 0", string offsetMax = "0 0", float fadeIn = 0f, float fadeOut = 0f, string name = null) {
                    return Add(new Element(this) {
                        Components = {
                            new CuiTextComponent {
                                Text = text, Color = color, Font = FontNames[(int)font], VerticalOverflow = overflow, FontSize = fontSize, Align = align, FadeIn = fadeIn
                            }
                            , new CuiOutlineComponent {
                                Color = outlineColor, Distance = $"{outlineWidth} {outlineWidth}"
                            }
                            , new CuiRectTransformComponent() {
                                AnchorMin = anchorMin, AnchorMax = anchorMax, OffsetMin = offsetMin, OffsetMax = offsetMax
                            }
                            ,
                        }
                        , FadeOut = fadeOut, Name = name
                    }
                    );
                }
                public Element AddInputfield(string command, string text = "Enter text here...", string color = "1 1 1 1", Font font = Font.RobotoCondensedRegular, int fontSize = 14, TextAnchor align = TextAnchor.UpperLeft, string anchorMin = "0 0", string anchorMax = "1 1", string offsetMin = "0 0", string offsetMax = "0 0", bool needsKeyboard = true, bool autoFocus = false, bool isPassword = false, int charsLimit = 0, string name = null) {
                    return Add(new Element(this) {
                        Components = {
                            new CuiInputFieldComponent {
                                Text = text, Color = color, Font = FontNames[(int)font], FontSize = fontSize, Align = align, Autofocus = autoFocus, Command = command, IsPassword = isPassword, CharsLimit = charsLimit, NeedsKeyboard = needsKeyboard,
                            }
                            , new CuiRectTransformComponent() {
                                AnchorMin = anchorMin, AnchorMax = anchorMax, OffsetMin = offsetMin, OffsetMax = offsetMax
                            }
                            ,
                        }
                        , Name = name
                    }
                    );
                }
                public Element AddPanel(string color = "1 1 1 1", string sprite = "assets/content/ui/ui.background.tile.psd", string material = "assets/content/ui/namefontmaterial.mat", UnityEngine.UI.Image.Type imageType = UnityEngine.UI.Image.Type.Simple, string anchorMin = "0 0", string anchorMax = "1 1", string offsetMin = "0 0", string offsetMax = "0 0", float fadeIn = 0f, float fadeOut = 0f, bool cursorEnabled = false, bool keyboardEnabled = false, string name = null) {
                    Element element = new Element(this) {
                        Components = {
                            new CuiRectTransformComponent {
                                AnchorMin = anchorMin, AnchorMax = anchorMax, OffsetMin = offsetMin, OffsetMax = offsetMax,
                            }
                            , new CuiImageComponent {
                                Color = color, Sprite = sprite, Material = material, ImageType = imageType, FadeIn = fadeIn,
                            }
                        }
                        , Name = name, FadeOut = fadeOut
                    }
                    ;
                    if (cursorEnabled) element.Components.Add(new CuiNeedsCursorComponent());
                    if (keyboardEnabled) element.Components.Add(new CuiNeedsKeyboardComponent());
                    return Add(element);
                }
                public Element AddButton(string command, string close = null, string color = "0 0 0 0", string sprite = "assets/content/ui/ui.background.tile.psd", string material = "assets/icons/iconmaterial.mat", UnityEngine.UI.Image.Type imageType = UnityEngine.UI.Image.Type.Simple, string anchorMin = "0 0", string anchorMax = "1 1", string offsetMin = "0 0", string offsetMax = "0 0", float fadeIn = 0f, float fadeOut = 0f, string name = null) {
                    return Add(new Element(this) {
                        Components = {
                            new CuiRectTransformComponent {
                                AnchorMin = anchorMin, AnchorMax = anchorMax, OffsetMin = offsetMin, OffsetMax = offsetMax,
                            }
                            , new CuiButtonComponent {
                                Close = close, Command = command, Color = color, Sprite = sprite, Material = material, ImageType = imageType, FadeIn = fadeIn,
                            }
                        }
                        , Name = name, FadeOut = fadeOut
                    }
                    );
                }
                public Element AddImage(string content, string color = "1 1 1 1", string material = "assets/content/ui/namefontmaterial.mat", string anchorMin = "0 0", string anchorMax = "1 1", string offsetMin = "0 0", string offsetMax = "0 0", float fadeIn = 0f, float fadeOut = 0f, string name = null) {
                    Element element = new Element(this) {
                        Components = {
                            new CuiRectTransformComponent() {
                                AnchorMin = anchorMin, AnchorMax = anchorMax, OffsetMin = offsetMin, OffsetMax = offsetMax
                            }
                            ,
                        }
                        , Name = name, FadeOut = fadeOut
                    }
                    ;
                    if (!string.IsNullOrEmpty(content)) {
                        CuiRawImageComponent rawImageComponent = new CuiRawImageComponent() {
                            Color = color, Material = material, FadeIn = fadeIn
                        }
                        ;
                        if (content.Contains("://")) rawImageComponent.Url = content;
                        else rawImageComponent.Png = content;
                        element.Components.Add(rawImageComponent);
                    }
                    ;
                    return Add(element);
                }
                public Element AddHImage(string content, string color = "1 1 1 1", string anchorMin = "0 0", string anchorMax = "1 1", string offsetMin = "0 0", string offsetMax = "0 0", string name = null) {
                    return Add(new Element(this) {
                        Components = {
                            new CuiRawImageComponent() {
                                Color = color, Png = content, Material = "assets/icons/iconmaterial.mat"
                            }
                            , new CuiRectTransformComponent() {
                                AnchorMin = anchorMin, AnchorMax = anchorMax, OffsetMin = offsetMin, OffsetMax = offsetMax
                            }
                            ,
                        }
                        , Name = name
                    }
                    );
                }
                public Element AddIcon(int itemId, ulong skin = 0, string color = "1 1 1 1", string sprite = "assets/content/ui/ui.background.tile.psd", string material = "assets/icons/iconmaterial.mat", UnityEngine.UI.Image.Type imageType = UnityEngine.UI.Image.Type.Simple, string anchorMin = "0 0", string anchorMax = "1 1", string offsetMin = "0 0", string offsetMax = "0 0", float fadeIn = 0f, float fadeOut = 0f, string name = null) {
                    return Add(new Element(this) {
                        Components = {
                            new CuiImageComponent() {
                                Color = color, ItemId = itemId, SkinId = skin, Sprite = sprite, Material = material, ImageType = imageType, FadeIn = fadeIn
                            }
                            , new CuiRectTransformComponent() {
                                AnchorMin = anchorMin, AnchorMax = anchorMax, OffsetMin = offsetMin, OffsetMax = offsetMax
                            }
                            ,
                        }
                        , Name = name, FadeOut = fadeOut
                    }
                    );
                }
                public Element AddContainer(string anchorMin = "0 0", string anchorMax = "1 1", string offsetMin = "0 0", string offsetMax = "0 0", string name = null) {
                    return Add(new Element(this) {
                        Components = {
                            new CuiRectTransformComponent() {
                                AnchorMin = anchorMin, AnchorMax = anchorMax, OffsetMin = offsetMin, OffsetMax = offsetMax
                            }
                            ,
                        }
                        , Name = name,
                    }
                    );
                }
            }
            public class Root : Element {
                public bool wasRendered = false;
                public Root() {
                    Name = string.Empty;
                }
                public Root(string rootObjectName = "Overlay") {
                    Name = rootObjectName;
                }
                public override List<Element> Container {
                    get;
                }
                = new List<Element>();
                private void AddElementsToList(Element element, List<Element> list) {
                    list.Add(element);
                    foreach (Element child in element.Container) AddElementsToList(child, list);
                }
                public List<Element> GetCommonContainer(bool includeRoot = false) {
                    var list = new List<Element>();
                    if (includeRoot) list.Add(this);
                    foreach (Element child in this.Container) AddElementsToList(child, list);
                    return list;
                }
                public string ToJson(List<Element> elements, bool format = false) {
                    return JsonConvert.SerializeObject(elements, format ? Formatting.Indented : Formatting.None, new JsonSerializerSettings {
                        DefaultValueHandling = DefaultValueHandling.Ignore
                    }
                    ).Replace("\\n", "\n");
                }
                public string ToJson(bool format = false) {
                    return ToJson(Container, format);
                }
                public void Render(Connection connection) {
                    if (connection == null || !connection.connected) return;
                    wasRendered = true;
                    CUI.AddUI(connection, ToJson(Container));
                }
                public void Render(BasePlayer player) {
                    Render(player.Connection);
                }
                public void Update(Connection connection) {
                    foreach (Element element in Container) element.Update = true;
                    CUI.AddUI(connection, ToJson(Container));
                }
                public void Update(BasePlayer player) {
                    Update(player.Connection);
                }
            }
        }
        public class CenteredTextContent : Content {
            public string text = string.Empty;
            public CUI.Font font = CUI.Font.RobotoCondensedBold;
            public int fontSize = 24;
            protected override void Render(CUI.Element root, ConnectionData connectionData, Dictionary<string, object> userData) {
                root.AddText(text : text, font : CUI.Font.RobotoCondensedBold, fontSize : fontSize, align : TextAnchor.MiddleCenter).AddDestroySelfAttribute();
            }
        }
        public class Content {
            public void Render(ConnectionData connectionData) {
                CUI.Root root = new CUI.Root("AdminMenu_Panel_TempContent");
                Render(root, connectionData, connectionData.userData);
                root.Render(connectionData.connection);
            }
            protected virtual void Render(CUI.Element root, ConnectionData connectionData, Dictionary<string, object> userData) {
            }
            public virtual void LoadDefaultUserData(Dictionary<string, object> userData) {
            }
            public virtual void RestoreUserData(Dictionary<string, object> userData) {
            }
        }
        public class ConvarsContent : Content {
            private static readonly Label SEARCH_LABEL = new Label("Search..");
            public override void LoadDefaultUserData(Dictionary<string, object> userData) {
                userData["convars.searchQuery"] = string.Empty;
                userData["convars.page"] = 1;
            }
            protected override void Render(CUI.Element root, ConnectionData connectionData, Dictionary<string, object> userData) {
                string searchQuery = (string)userData["convars.searchQuery"];
                int page = (int)userData["convars.page"];
                var container = root.AddContainer(anchorMin : "0.03 0.04", anchorMax : "0.97 0.99", name : "AdminMenu_Convars").AddDestroySelfAttribute();
                int rows = 16;
                List<ConsoleSystem.Command> commands = ConsoleGen.All.Where(command => command.ServerAdmin 
// ... [Code preview truncated due to length. Full source in attached file] ...

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