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

FREE CustomButtons : 2.0.72 2.0.72

Нет прав для скачивания
C#:
using Newtonsoft.Json;
using Oxide.Core;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using Oxide.Core.Configuration;
using Oxide.Core.Libraries.Covalence;
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using UnityEngine;
namespace Oxide.Plugins {
    [Info("CustomButtons", "Forum: https://topplugin.ru Ds: alone_sempai Vk: https://vk.com/rustnastroika", "2.0.72")]
    [Description("Custom UI Buttons")]
    public class CustomButtons : RustPlugin {
#region Create Cui
        CuiElementContainer buttons_nonToggle;
        CuiElementContainer buttons_withToggle;
        void ShowButtons(BasePlayer player) {
            if (!_playerData.ContainsKey(player.userID)) {
                _playerData.Add(player.userID, new PlayerData());
                _playerData[player.userID].hidden = false;
            }
            var withoutPermission = Facepunch.Pool.Get<List<string>>();
            foreach (string name in _cuiData.Keys) {
                // destroy all before creating new ones
                CuiHelper.DestroyUi(player, name);
                if (!permission.UserHasPermission(player.UserIDString, $"custombuttons.{name}") && !permission.UserHasPermission(player.UserIDString, $"custombuttons.admin")) withoutPermission.Add(name);
            }
            if (_playerData[player.userID].hidden) {
                CuiHelper.AddUi(player, buttons_nonToggle);
            }
            else {
                CuiHelper.AddUi(player, buttons_nonToggle);
                CuiHelper.AddUi(player, buttons_withToggle);
            }
            foreach (string name in withoutPermission) CuiHelper.DestroyUi(player, name);
            Facepunch.Pool.FreeUnmanaged(ref withoutPermission);
        }
        void DestroyWithToggle(BasePlayer player) {
            foreach (var button in _cuiData) {
                if (button.Value.onCmdHide == "true" && button.Value.onCmdHide != null) {
                    CuiHelper.DestroyUi(player, button.Key);
                }
            }
        }
        void DestroyAll(BasePlayer player) {
            foreach (string name in _cuiData.Keys) {
                CuiHelper.DestroyUi(player, name);
            }
        }
        void CreateComponent(CuiElementContainer container, CuiData button, string name) {
            // create button
            if (button.panelType == "button") {
                container.Add(new CuiButton {
                    Button = {
                        Command = (button.panelChatCmd == null ? "" : $"custombuttons_runbtncmd {name}"), Color = button.panelColor, FadeIn = 0.0f
                    }
                    , RectTransform = {
                        AnchorMin = config.anchSet.anchorMin, AnchorMax = config.anchSet.anchorMax, OffsetMin = button.OffsetMin, OffsetMax = button.OffsetMax
                    }
                    , Text = {
                        Text = "", FontSize = 12, Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf"
                    }
                }
                , button.uiType, name);
                // add image if exists
                if (button.imageUrl != null && button.imageUrl.StartsWith("http")) {
                    var comp = new CuiRawImageComponent {
                        Url = button.imageUrl, Sprite = "assets/content/textures/generic/fulltransparent.tga", FadeIn = 0.0f
                    }
                    ;
                    if (ImageLibrary != null && (bool)ImageLibrary.Call("HasImage", button.imageUrl)) comp.Png = (string)ImageLibrary.Call("GetImage", button.imageUrl);
                    container.Add(new CuiElement {
                        Parent = name, Components = {
                            comp, new CuiRectTransformComponent {
                                AnchorMin = button.imgAnchorMin, AnchorMax = button.imgAnchorMax
                            }
                        }
                    }
                    );
                }
                //add text if exists
                if (button.text != null && button.text != "") {
                    container.Add(new CuiElement {
                        Parent = name, Name = $"{name}_text", Components = {
                            new CuiTextComponent {
                                Text = button.text, FontSize = config.fontSet.fontSize, Font = config.fontSet.fontStyle, Align = TextAnchor.MiddleCenter, Color = config.fontSet.fontColor, FadeIn = 0f,
                            }
                            , new CuiOutlineComponent {
                                Color = config.fontSet.fontOutColor, Distance = config.fontSet.fontOutThic
                            }
                            , new CuiRectTransformComponent {
                                AnchorMin = "0 0", AnchorMax = "1 1"
                            }
                        }
                        ,
                    }
                    );
                }
            }
            if (button.panelType == "panel") {
                container.Add(new CuiPanel {
                    Image = {
                        Color = button.panelColor
                    }
                    , RectTransform = {
                        AnchorMin = config.anchSet.anchorMin, AnchorMax = config.anchSet.anchorMax, OffsetMin = button.OffsetMin, OffsetMax = button.OffsetMax
                    }
                }
                , button.uiType, name);
                // add image if exists
                if (button.imageUrl != null && button.imageUrl.StartsWith("http")) {
                    var comp = new CuiRawImageComponent {
                        Url = button.imageUrl, Sprite = "assets/content/textures/generic/fulltransparent.tga", FadeIn = 0.0f
                    }
                    ;
                    if (ImageLibrary != null && (bool)ImageLibrary.Call("HasImage", button.imageUrl)) comp.Png = (string)ImageLibrary.Call("GetImage", button.imageUrl);
                    container.Add(new CuiElement {
                        Parent = name, Components = {
                            comp, new CuiRectTransformComponent {
                                AnchorMin = button.imgAnchorMin, AnchorMax = button.imgAnchorMax
                            }
                        }
                    }
                    );
                }
                //add text if exists
                if (button.text != null && button.text != "") {
                    container.Add(new CuiElement {
                        Parent = name, Name = $"{name}_text", Components = {
                            new CuiTextComponent {
                                Text = button.text, FontSize = config.fontSet.fontSize, Font = config.fontSet.fontStyle, Align = TextAnchor.MiddleCenter, Color = config.fontSet.fontColor, FadeIn = 0f,
                            }
                            , new CuiOutlineComponent {
                                Color = config.fontSet.fontOutColor, Distance = config.fontSet.fontOutThic
                            }
                            , new CuiRectTransformComponent {
                                AnchorMin = "0 0", AnchorMax = "1 1"
                            }
                        }
                        ,
                    }
                    );
                }
            }
        }
        void BuildButtons() {
            buttons_nonToggle = new CuiElementContainer();
            buttons_withToggle = new CuiElementContainer();
            foreach (var button in _cuiData) {
                if (button.Value.onCmdHide == "true" && button.Value.onCmdHide != null)  // no idea why it's saved as string
                {
                    CreateComponent(buttons_withToggle, button.Value, button.Key);
                }
                if (button.Value.onCmdHide == "false" || button.Value.onCmdHide == null) {
                    CreateComponent(buttons_nonToggle, button.Value, button.Key);
                }
            }
        }
        private void CreateCui(BasePlayer player) {
            if (!_playerData.ContainsKey(player.userID)) return;
            var _createCui = CUIClass.CreateOverlay("empty*_", "0 0 0 0", "0 0", "0 0", false, 0.0f, $"assets/icons/iconmaterial.mat");
            //overlay
            //CUIClass.CreatePanel(ref _createCui, "overlay_main", "Hud", "0 0 0 0", "0 0", "1 1", false, 0f, "assets/icons/iconmaterial.mat");
            //CUIClass.CreatePanel(ref _createCui, "overlay_offset", "overlay_main", "0 0 0 0.0", "0.5 0.5", "0.5 0.5", false, 0f, "assets/icons/iconmaterial.mat", "-680 -360", "680 360");
            foreach (var element in _cuiData) {
                string elementName = element.Key;
                string panelColor = _cuiData[$"{element.Key}"].panelColor;
                string panelText = _cuiData[$"{element.Key}"].text;
                string anchorMin = _cuiData[$"{element.Key}"].OffsetMin;
                string anchorMax = _cuiData[$"{element.Key}"].OffsetMax;
                string _imgUrl = Img(_cuiData[$"{element.Key}"].imageUrl);
                string _imgAMin = $"{_cuiData[$" {
                    element.Key
                }
                "].imgAnchorMin}";
                if (_cuiData[$"{element.Key}"].imgAnchorMin == null) _imgAMin = "0 0";
                string _imgAMax = $"{_cuiData[$" {
                    element.Key
                }
                "].imgAnchorMax}";
                if (_cuiData[$"{element.Key}"].imgAnchorMax == null) _imgAMax = "1 1";
                if (_playerData[player.userID].hidden) {
                    if (_cuiData[$"{element.Key}"].onCmdHide == "true") {
                        continue;
                    }
                }
                if (permission.UserHasPermission(player.UserIDString, $"custombuttons.{element.Key}") || permission.UserHasPermission(player.UserIDString, $"custombuttons.admin")) {
                    if (_cuiData[$"{element.Key}"].uiType == "Overlay") {
                        CUIClass.CreatePanel(ref _createCui, elementName, "Overlay", $"{panelColor}", config.anchSet.anchorMin, config.anchSet.anchorMax, false, 0f, "assets/icons/iconmaterial.mat", anchorMin, anchorMax);
                        if (_cuiData[$"{element.Key}"].imageUrl != null) {
                            CUIClass.CreateImage(ref _createCui, elementName, _imgUrl, _imgAMin, _imgAMax);
                        }
                        if (_cuiData[$"{element.Key}"].text != null) {
                            CUIClass.CreateText(ref _createCui, "text" + elementName, elementName, config.fontSet.fontColor, $"{panelText}", config.fontSet.fontSize, "0 0", "1 1", TextAnchor.MiddleCenter, config.fontSet.fontStyle, config.fontSet.fontOutColor, config.fontSet.fontOutThic);
                        }
                        if (_cuiData[$"{element.Key}"].panelType == "button") {
                            string _command = "";
                            if (_cuiData[$"{element.Key}"].panelChatCmd != null) _command = $"custombuttons_runbtncmd {elementName}";
                            CUIClass.CreateButton(ref _createCui, "btn" + elementName, elementName, "0 0 0 0", "", 13, "0 0", $"1 1", _command, "", "1 1 1 0.7", 0f, TextAnchor.MiddleCenter, $"robotocondensed-bold.ttf");
                        }
                    }
                    if (_cuiData[$"{element.Key}"].uiType == "Hud") {
                        CUIClass.CreatePanel(ref _createCui, elementName, "Hud", $"{panelColor}", config.anchSet.anchorMin, config.anchSet.anchorMax, false, 0f, "assets/icons/iconmaterial.mat", anchorMin, anchorMax);
                        if (_cuiData[$"{element.Key}"].imageUrl != null) {
                            CUIClass.CreateImage(ref _createCui, elementName, _imgUrl, _imgAMin, _imgAMax);
                        }
                        if (_cuiData[$"{element.Key}"].text != null) {
                            CUIClass.CreateText(ref _createCui, "text" + elementName, elementName, config.fontSet.fontColor, $"{panelText}", config.fontSet.fontSize, "0 0", "1 1", TextAnchor.MiddleCenter, config.fontSet.fontStyle, config.fontSet.fontOutColor, config.fontSet.fontOutThic);
                        }
                        if (_cuiData[$"{element.Key}"].panelType == "button") {
                            string _command = $"";
                            if (_cuiData[$"{element.Key}"].panelChatCmd != null) _command = $"custombuttons_runbtncmd {elementName}";
                            CUIClass.CreateButton(ref _createCui, "btn" + elementName, elementName, "0 0 0 0", "", 13, "0 0", $"1 1", _command, "", "1 1 1 0.7", 0f, TextAnchor.MiddleCenter, $"robotocondensed-bold.ttf");
                        }
                    }
                }
            }
            DestroyCui(player);
            CuiHelper.AddUi(player, _createCui);
            //if (_playerData[player.userID].hidden) DestroyHidden(player);
        }
        private void DestroyCui(BasePlayer player) {
            CuiHelper.DestroyUi(player, "empty*_");
            CuiHelper.DestroyUi(player, "overlay_main");
            foreach (var element in _cuiData) {
                CuiHelper.DestroyUi(player, $"{element.Key}");
            }
        }
        private void CreatePartialCui(BasePlayer player, List<string> list) {
            if (!_playerData.ContainsKey(player.userID)) return;
            var _createPartialCui = CUIClass.CreateOverlay("empty*_", "0 0 0 0", "0 0", "0 0", false, 0.0f, $"assets/icons/iconmaterial.mat");
            //overlay
            //CUIClass.CreatePanel(ref _createCui, "overlay_main", "Hud", "0 0 0 0", "0 0", "1 1", false, 0f, "assets/icons/iconmaterial.mat");
            //CUIClass.CreatePanel(ref _createCui, "overlay_offset", "overlay_main", "0 0 0 0.0", "0.5 0.5", "0.5 0.5", false, 0f, "assets/icons/iconmaterial.mat", "-680 -360", "680 360");
            foreach (var element in _cuiData) {
                string elementName = element.Key;
                string panelColor = _cuiData[$"{element.Key}"].panelColor;
                string panelText = _cuiData[$"{element.Key}"].text;
                string anchorMin = _cuiData[$"{element.Key}"].OffsetMin;
                string anchorMax = _cuiData[$"{element.Key}"].OffsetMax;
                string _imgUrl = _cuiData[$"{element.Key}"].imageUrl;
                string _imgAMin = $"{_cuiData[$" {
                    element.Key
                }
                "].imgAnchorMin}";
                string _imgAMax = $"{_cuiData[$" {
                    element.Key
                }
                "].imgAnchorMax}";
                if (_playerData[player.userID].hidden) {
                    if (_cuiData[$"{element.Key}"].onCmdHide == "true") {
                        continue;
                    }
                }
                if (_playerData[player.userID].hidden) {
                    if (_cuiData[$"{element.Key}"].onCmdHide == "true") {
                        continue;
                    }
                }
                if (list.Contains("*")) {
                    // ignore
                }
                else {
                    if (!list.Contains($"{element.Key}")) {
                        continue;
                    }
                }
                if (permission.UserHasPermission(player.UserIDString, $"custombuttons.{element.Key}") || permission.UserHasPermission(player.UserIDString, $"custombuttons.admin")) {
                    if (_cuiData[$"{element.Key}"].uiType == "Overlay") {
                        CUIClass.CreatePanel(ref _createPartialCui, elementName, "Overlay", $"{panelColor}", config.anchSet.anchorMin, config.anchSet.anchorMax, false, 0f, "assets/icons/iconmaterial.mat", anchorMin, anchorMax);
                        if (_cuiData[$"{element.Key}"].imageUrl != null) {
                            CUIClass.CreateImage(ref _createPartialCui, elementName, _imgUrl, _imgAMin, _imgAMax);
                        }
                        if (_cuiData[$"{element.Key}"].text != null) {
                            CUIClass.CreateText(ref _createPartialCui, "text" + elementName, elementName, config.fontSet.fontColor, $"{panelText}", config.fontSet.fontSize, "0 0", "1 1", TextAnchor.MiddleCenter, config.fontSet.fontStyle, config.fontSet.fontOutColor, config.fontSet.fontOutThic);
                        }
                        if (_cuiData[$"{element.Key}"].panelType == "button") {
                            string _command = "";
                            if (_cuiData[$"{element.Key}"].panelChatCmd != null) _command = $"custombuttons_runbtncmd {elementName}";
                            CUIClass.CreateButton(ref _createPartialCui, "btn" + elementName, elementName, "0 0 0 0", "", 13, "0 0", $"1 1", _command, "", "1 1 1 0.7", 0f, TextAnchor.MiddleCenter, $"robotocondensed-bold.ttf");
                        }
                    }
                    if (_cuiData[$"{element.Key}"].uiType == "Hud") {
                        CUIClass.CreatePanel(ref _createPartialCui, elementName, "Hud", $"{panelColor}", config.anchSet.anchorMin, config.anchSet.anchorMax, false, 0f, "assets/icons/iconmaterial.mat", anchorMin, anchorMax);
                        if (_cuiData[$"{element.Key}"].imageUrl != null) {
                            CUIClass.CreateImage(ref _createPartialCui, elementName, _imgUrl, _imgAMin, _imgAMax);
                        }
                        if (_cuiData[$"{element.Key}"].text != null) {
                            CUIClass.CreateText(ref _createPartialCui, "text" + elementName, elementName, config.fontSet.fontColor, $"{panelText}", config.fontSet.fontSize, "0 0", "1 1", TextAnchor.MiddleCenter, config.fontSet.fontStyle, config.fontSet.fontOutColor, config.fontSet.fontOutThic);
                        }
                        if (_cuiData[$"{element.Key}"].panelType == "button") {
                            string _command = $"";
                            if (_cuiData[$"{element.Key}"].panelChatCmd != null) _command = $"custombuttons_runbtncmd {elementName}";
                            CUIClass.CreateButton(ref _createPartialCui, "btn" + elementName, elementName, "0 0 0 0", "", 13, "0 0", $"1 1", _command, "", "1 1 1 0.7", 0f, TextAnchor.MiddleCenter, $"robotocondensed-bold.ttf");
                        }
                    }
                }
            }
            CloseWhen(player, list);
            CuiHelper.AddUi(player, _createPartialCui);
            //if (_playerData[player.userID].hidden) DestroyHidden(player);
        }
#endregion
#region [Permissions]
        private void RegisterPerms() {
            foreach (var entry in _cuiData) {
                permission.RegisterPermission($"custombuttons.{entry.Key}", this);
            }
        }
#endregion
#region [CuiData]
        private void SaveData() {
            if (_cuiData != null) Interface.Oxide.DataFileSystem.WriteObject($"{Name}/CuiData", _cuiData);
        }
        private Dictionary<string, CuiData> _cuiData;
        private class CuiData {
            public string uiType;
            public string panelType;
            public string OffsetMin;
            public string OffsetMax;
            public string text;
            public string panelColor;
            public string panelChatCmd;
            public string imageUrl;
            public string imgAnchorMin;
            public string imgAnchorMax;
            public string onCmdHide;
        }
        private void LoadData() {
            if (Interface.Oxide.DataFileSystem.ExistsDatafile($"{Name}/CuiData")) {
                _cuiData = Interface.Oxide.DataFileSystem.ReadObject<Dictionary<string, CuiData>>($"{Name}/CuiData");
            }
            else {
                _cuiData = new Dictionary<string, CuiData>();
                SaveData();
            }
        }
#endregion
#region [PlayerData]
        private void SavePlayerData() {
            if (_playerData != null) Interface.Oxide.DataFileSystem.WriteObject($"{Name}/PlayerData", _playerData);
        }
        private Dictionary<ulong, PlayerData> _playerData;
        private class PlayerData {
            public bool hidden;
        }
        private void LoadPlayerData() {
            if (Interface.Oxide.DataFileSystem.ExistsDatafile($"{Name}/PlayerData")) {
                _playerData = Interface.Oxide.DataFileSystem.ReadObject<Dictionary<ulong, PlayerData>>($"{Name}/PlayerData");
            }
            else {
                _playerData = new Dictionary<ulong, PlayerData>();
                SavePlayerData();
            }
        }
        private void WritePlayerEntry(BasePlayer player) {
            if (!_playerData.ContainsKey(player.userID)) {
                _playerData.Add(player.userID, new PlayerData());
                _playerData[player.userID].hidden = false;
                SavePlayerData();
            }
        }
        //Added this for testing
        object CustomCommands(BasePlayer player, string command, string[] args) {
            if (command == config.commSet.togglePanels) {
                custombuttonstoggle(player);
            }
            else if (command == config.commSet.openCmd) {
                chatcmdOpenMenu(player);
            }
            else if (command == config.commSet.listPanels) {
                custombuttons_list(player);
            }
            return null;
        }
        private void DestroyHidden(BasePlayer player) {
            foreach (var element in _cuiData) {
                if (_cuiData[$"{element.Key}"].onCmdHide != null) {
                    if (_cuiData[$"{element.Key}"].onCmdHide == "true") CuiHelper.DestroyUi(player, $"{element.Key}");
                }
            }
        }
#endregion
#region [Hooks]
        private void CloseWhen(BasePlayer player, List<string> list) {
            if (list.Contains("*")) {
                DestroyCui(player);
            }
            else {
                foreach (string element in list) {
                    CuiHelper.DestroyUi(player, element);
                }
            }
        }
        void OnPlayerConnected(BasePlayer player) => WritePlayerEntry(player);
        void OnPlayerDeath(BasePlayer player, HitInfo info) => CloseWhen(player, config.addSet.whenDead);
        void OnPlayerSleepEnded(BasePlayer player) {
            if (player == null) return;
            ShowButtons(player);
        }
        void OnLootEntity(BasePlayer player, BaseEntity entity) => CloseWhen(player, config.addSet.whenLooting);
        void OnLootEntityEnd(BasePlayer player, BaseEntity entity) => ShowButtons(player);
        //CreatePartialCui(player, config.addSet.whenLooting);
        void OnEntityMounted(ComputerStation entity, BasePlayer player) => CloseWhen(player, config.addSet.whenComputer);
        void OnEntityDismounted(ComputerStation entity, BasePlayer player) => ShowButtons(player);
        //CreatePartialCui(player, config.addSet.whenComputer);
        [PluginReference]
        Plugin ImageLibrary;
        private void OnServerInitialized() {
            LoadData();
            LoadPlayerData();
            LoadConfig();
            cmd.AddChatCommand(config.commSet.listPanels, this, "CustomCommands");
            cmd.AddChatCommand(config.commSet.openCmd, this, "CustomCommands");
            cmd.AddChatCommand(config.commSet.togglePanels, this, "CustomCommands");
            foreach (var _player in BasePlayer.activePlayerList) WritePlayerEntry(_player);
            //foreach (var _player in BasePlayer.activePlayerList) CreateCui(_player);
            permission.RegisterPermission($"custombuttons.admin", this);
            RegisterPerms();
            if (ImageLibrary != null) {
                foreach (string element in _cuiData.Keys) {
                    if (_cuiData[element].imageUrl != null && _cuiData[element].imageUrl != "") {
                        ImageLibrary.Call("AddImage", _cuiData[element].imageUrl, _cuiData[element].imageUrl);
                    }
                }
            }
            BuildButtons();
            foreach (var _player in BasePlayer.activePlayerList) {
                ShowButtons(_player);
            }
        }
        private string Img(string url) {
            if (ImageLibrary != null) {
                if (!(bool) ImageLibrary.Call("HasImage", url)) return url;
                else return (string) ImageLibrary?.Call("GetImage", url);
            }
            else return url;
        }
        private void OnServerSave() {
            SaveData();
            SavePlayerData();
        }
        private void Unload() {
            foreach (var _player in BasePlayer.activePlayerList) {
                DestroyButtonMenuUI(_player);
                DestroyEnterName(_player);
                DestroyEditMenu(_player);
                DestroyEditPosMain(_player);
                DestroyEditType(_player);
                DestroyCui(_player);
            }
            SavePlayerData();
        }
#endregion
        private Dictionary<string, string> storedCuiFields = new Dictionary<string, string>();
#region [Commands]
        private void ClearSpecificField(string[] fieldNames) {
            foreach (string field in fieldNames) {
                if (storedCuiFields.ContainsKey(field)) {
                    storedCuiFields.Remove(field);
                }
            }
        }
        private void ClearStoredFields() {
            string[] preSet = {
                "panelName", "uiType", "panelType", "AnchorMin", "AnchorMax", "text", "panelColor", "imageUrl", "imgAnchorMin", "imgAnchorMax", "panelChatCmd", "onCmdHide"
            }
            ;
            foreach (string s in preSet) {
                if (storedCuiFields.ContainsKey($"{s}")) {
                    storedCuiFields.Remove($"{s}");
                }
            }
        }
        private void CheckStoredFields() {
            string[] preSet = {
                "panelName", "uiType", "panelType", "AnchorMin", "AnchorMax", "text", "panelColor", "imageUrl", "imgAnchorMin", "imgAnchorMax", "panelChatCmd", "onCmdHide"
            }
            ;
            foreach (string s in preSet) {
                if (!storedCuiFields.ContainsKey($"{s}")) {
                    Puts($"{s} not found");
                    break;
                }
                else {
                    Puts($"{s} found");
                }
            }
        }
        [ChatCommand("custombuttons_list")]
        private void custombuttons_list(BasePlayer player) {
            if (player == null) return;
            if (!permission.UserHasPermission(player.UserIDString, $"custombuttons.admin")) {
                SendReply(player, "You don't have permission to do that (custombuttons.admin).");
                return;
            }
            string list = "<size=16><color=#FF9300>List of CUI Elements</color></size> \n\n";
            foreach (var element in _cuiData) {
                list = list + $" <color=#FF9300>•</color> {element.Key}<size=11><color=#CDCDCD>({_cuiData[$" {
                    element.Key
                }
                "].uiType})</color></size>";
            }
            SendReply(player, list);
        }
        [ChatCommand("custombuttonstoggle")]
        private void custombuttonstoggle(BasePlayer player) {
            if (player == null) return;
            WritePlayerEntry(player);
            if (_playerData[player.userID].hidden) {
                _playerData[player.userID].hidden = false;
                ShowButtons(player);
            }
            else {
                _playerData[player.userID].hidden = true;
                DestroyWithToggle(player);
            }
        }
        [ConsoleCommand("custombuttons_runbtncmd")]
        private void custombuttons_runbtncmd(ConsoleSystem.Arg arg) {
            var player = arg?.Player();
            var args = arg.Args;
            if (arg.Player() == null) return;
            string chatcmd = _cuiData[$"{args[0]}"].panelChatCmd;
            string replacedValues = chatcmd.Replace("{player.name}", $"{player.displayName}").Replace("{player.steam}", $"{player.userID}");
            if (config.hideOnCommand) {
                player.SendConsoleCommand($"chat.say \"/{config.commSet.togglePanels}\"");
            }
            player.SendConsoleCommand($"chat.say \"/{replacedValues}\" ");
        }
        [ConsoleCommand("custombuttons_storechanges")]
        private void custombuttons_storechanges(ConsoleSystem.Arg arg) {
            var player = arg?.Player();
            var args = arg.Args;
            if (arg.Player() == null) return;
            string[] preSet = {
                "uiType", "panelType", "AnchorMin", "AnchorMax", "text", "panelColor", "imageUrl", "imgAnchorMin", "imgAnchorMax", "panelChatCmd", "onCmdHide"
            }
            ;
            if(args[0] == "textcolor") {
                if (storedCuiFields.ContainsKey("text")) {
                    _cuiData[args[1]].text = storedCuiFields["text"];
                }
                if (storedCuiFields.ContainsKey("panelColor")) {
                    _cuiData[args[1]].panelColor = storedCuiFields["panelColor"];
                }
                SaveData();
                DestroyAllSubs(player);
                //save and destroy text edit menu
                CreateCui(player);
                EditMenu(player, args[1]);
                PopUpWindow(player, "small", GetLang("changesSaved"));
                //open main edit menu + notification
                ClearSpecificField(preSet);
                return;
            }
            if(args[0] == "image") {
                if (storedCuiFields.ContainsKey("imageUrl")) {
                    _cuiData[args[1]].imageUrl = storedCuiFields["imageUrl"];
                }
                if (storedCuiFields.ContainsKey("imgAnchorMin")) {
                    _cuiData[args[1]].imgAnchorMin = storedCuiFields["imgAnchorMin"];
                }
                if (storedCuiFields.ContainsKey("imgAnchorMax")) {
                    _cuiData[args[1]].imgAnchorMax = storedCuiFields["imgAnchorMax"];
                }
                SaveData();
                DestroyAllSubs(player);
                //save and destroy text edit menu
                CreateCui(player);
                EditMenu(player, args[1]);
                PopUpWindow(player, "small", GetLang("changesSaved"));
                //open main edit menu + notification
                ClearSpecificField(preSet);
                return;
            }
            if(args[0] == "cui") {
                if (storedCuiFields.ContainsKey("uiType")) {
                    _cuiData[args[1]].uiType = storedCuiFields["uiType"];
                }
                if (storedCuiFields.ContainsKey("panelType")) {
                    _cuiData[args[1]].panelType = storedCuiFields["panelType"];
                }
                if (storedCuiFields.ContainsKey("panelChatCmd")) {
                    _cuiData[args[1]].panelChatCmd = storedCuiFields["panelChatCmd"];
                }
                SaveData();
                DestroyAllSubs(player);
                //save and destroy text edit menu
                CreateCui(player);
                EditMenu(player, args[1]);
                PopUpWindow(player, "small", GetLang("changesSaved"));
                //open main edit menu + notification
                ClearSpecificField(preSet);
                return;
            }
        }
        [ConsoleCommand("custombuttons_discardchanges")]
        private void custombuttons_discardchanges(ConsoleSystem.Arg arg) {
            var player = arg?.Player();
            var args = arg.Args;
            if (arg.Player() == null) return;
            //if (args.Length < 2) return;
            string[] preSet = {
                "uiType", "panelType", "AnchorMin", "AnchorMax", "text", "panelColor", "imageUrl", "imgAnchorMin", "imgAnchorMax", "panelChatCmd", "onCmdHide"
            }
            ;
            ClearSpecificField(preSet);
            EditMenu(player, $"{args[0]}");
        }
        [ChatCommand("custombuttons")]
        private void chatcmdOpenMenu(BasePlayer player) {
            if (player == null) return;
            if (!permission.UserHasPermission(player.UserIDString, $"custombuttons.admin")) {
                SendReply(player, "You don't have permission to do that (custombuttons.admin).");
                return;
            }
            MainMenuUI(player);
        }
        [ConsoleCommand("storemenuvalue")]
        private void storemenuvalue(ConsoleSystem.Arg arg) {
            var player = arg?.Player();
            var args = arg.Args;
            if (arg.Player() == null) return;
            //if (args.Length > 5) {Puts($"Too many arguments"); return;}
            if (args.Length < 2) return;
            if (!storedCuiFields.ContainsKey($"{args[0]}")) {
                storedCuiFields.Add($"{args[0]}", $"");
                _debug($"{args[0]} Not found, adding to dictionary");
            }
            if(args[0] == "panelColor") {
                if (args.Length != 5) {
                    PopUpWindow(player, "small", GetLang("wrongColorUsage"));
                    return;
                }
                storedCuiFields[$"{args[0]}"] = $"{args[1]} {args[2]} {args[3]} {args[4]}";
                _debug($"{args[0]}:{storedCuiFields[$" {
                    args[0]
                }
                "]}");
                ColorDisplay(player);
                return;
            }
            if(args[0] == "AnchorMin" || args[0] == "AnchorMax" || args[0] == "imgAnchorMin" || args[0] == "imgAnchorMax") {
                if (args.Length != 3) {
                    PopUpWindow(player, "small", GetLang("wrongAnchorUsage"));
                    return;
                }
                storedCuiFields[$"{args[0]}"] = $"{args[1]} {args[2]}";
                _debug($"{args[0]}:{storedCuiFields[$" {
                    args[0]
                }
                "]}");
                return;
            }
#region editing spec.if(args[0] == "panelNameEdit")
            {
                if (args.Length != 2) {
                    EditBtn(player, false, "");
                    PopUpWindow(player, "small", GetLang("tooManyArguments"));
                    return;
                }
                if (!_cuiData.ContainsKey($"{args[1]}")) {
                    EditBtn(player, false, "");
                    PopUpWindow(player, "small", GetLang("panelNameNotFound"));
                    return;
                }
                storedCuiFields[$"{args[0]}"] = $"{args[1]}";
                _debug($"{args[0]}:{storedCuiFields[$" {
                    args[0]
                }
                "]}");
                EditBtn(player, true, $"{storedCuiFields[$" {
                    args[0]
                }
                "]}");
                return;
            }
            if(args[0] == "imageUrlEdit") {
                if (args.Length > 3) {
                    PopUpWindow(player, "small", GetLang("tooManyArguments"));
                    return;
                }
                storedCuiFields["imageUrl"] = args[2];
                _debug($"{args[0]}:{storedCuiFields[$"imageUrl"]}");
                EditImagePreview(player, args[1]);
                return;
            }
            if(args[0] == "panelColorEdit") {
                if (args.Length != 6) {
                    PopUpWindow(player, "small", GetLang("wrongColorUsage"));
                    return;
                }
                storedCuiFields["panelColor"] = $"{args[2]} {args[3]} {args[4]} {args[5]}";
                _debug($"{args[0]}:{storedCuiFields[$" {
                    args[0]
                }
                "]}");
                EditColor(player, args[1]);
                return;
            }
            if(args[0] == "uiTypeEdit") {
                if (args.Length > 3) {
                    PopUpWindow(player, "small", GetLang("tooManyArguments"));
                    return;
                }
                _cuiData[$"{args[1]}"].uiType = args[2];
                _debug($"{args[0]}:{_cuiData[$" {
                    args[1]
                }
                "].uiType}");
                SaveData();
                EditType(player, args[1]);
                return;
            }
            if(args[0] == "panelTypeEdit") {
                if (args.Length > 3) {
                    PopUpWindow(player, "small", GetLang("tooManyArguments"));
                    return;
                }
                _cuiData[$"{args[1]}"].panelType = args[2];
                _debug($"{args[0]}:{_cuiData[$" {
                    args[1]
                }
                "].panelType}");
                SaveData();
                EditType(player, args[1]);
                return;
            }
            if(args[0] == "onCmdHideEdit") {
                if (args.Length > 3) {
                    PopUpWindow(player, "small", GetLang("tooManyArguments"));
                    return;
                }
                _cuiData[$"{args[1]}"].onCmdHide = args[2];
                _debug($"{args[0]}:{_cuiData[$" {
                    args[1]
                }
                "].onCmdHide}");
                SaveData();
                EditType(player, args[1]);
                return;
            }
            if(args[0] == "panelChatCmdEdit") {
                if (args.Length > 3) {
                    PopUpWindow(player, "small", GetLang("tooManyArguments"));
                    return;
                }
                if (!storedCuiFields.ContainsKey("panelChatCmd")) {
                    PopUpWindow(player, "small", GetLang("nothingToSave"));
                    return;
                }
                _cuiData[$"{args[1]}"].panelChatCmd = storedCuiFields["panelChatCmd"];
                _debug($"{args[0]}:{_cuiData[$" {
                    args[1]
                }
                "].panelChatCmd}");
                SaveData();
                EditType(player, args[1]);
                return;
            }
#endregion
            if (args.Length > 2) {
                PopUpWindow(player, "small", GetLang("tooManyArguments"));
                return;
            }
            storedCuiFields[$"{args[0]}"] = $"{args[1]}";
            _debug($"{args[0]}:{storedCuiFields[$" {
                args[0]
            }
            "]}");
            if(args[0] == "onCmdHide") {
                OpenCloseOption(player);
            }
            if(args[0] == "uiType") {
                UiTypeButtons(player);
            }
            if(args[0] == "panelType") {
                PanelTypeButtons(player);
            }
            if(args[0] == "imageUrl") {
                ImagePreview(player);
            }
        }
        [ConsoleCommand("custombuttons_save")]
        private void custombuttons_save(ConsoleSystem.Arg arg) {
            var player = arg?.Player();
            var args = arg.Args;
            //if (arg.Player() == null) return;
            if (!storedCuiFields.ContainsKey("uiType") || !storedCuiFields.ContainsKey("panelType") || !storedCuiFields.ContainsKey("AnchorMin") || !storedCuiFields.ContainsKey("AnchorMax") || !storedCuiFields.ContainsKey("panelName")) {
                PopUpWindow(player, "small", GetLang("missingCoreValues"));
                _debug("Missing core values");
                return;
            }
            if (_cuiData.ContainsKey(storedCuiFields["panelName"])) {
                _debug("Duplicate panel name");
                return;
            }
            string pN = storedCuiFields["panelName"];
            _cuiData.Add($"{storedCuiFields["panelName"]}", new CuiData());
            SaveData();
            //MUST HAVE
            _cuiData[pN].uiType = storedCuiFields["uiType"];
            _cuiData[pN].panelType = storedCuiFields["panelType"];
            _cuiData[pN].OffsetMin = storedCuiFields["AnchorMin"];
            _cuiData[pN].OffsetMax = storedCuiFields["AnchorMax"];
            //OPTIONAL REPLACED WITH DEFAULT VALUES
            if (storedCuiFields.ContainsKey("panelColor")) {
                _cuiData[pN].panelColor = storedCuiFields["panelColor"];
            }
            if (storedCuiFields.ContainsKey("text")) {
                _cuiData[pN].text = storedCuiFields["text"];
            }
            if (storedCuiFields.ContainsKey("panelChatCmd")) {
                _cuiData[pN].panelChatCmd = storedCuiFields["panelChatCmd"];
            }
            if (storedCuiFields.ContainsKey("imageUrl")) {
                _cuiData[pN].imageUrl = storedCuiFields["imageUrl"];
            }
            if (storedCuiFields.ContainsKey("imgAnchorMin")) {
                _cuiData[pN].imgAnchorMin = storedCuiFields["imgAnchorMin"];
            }
            if (storedCuiFields.ContainsKey("imgAnchorMax")) {
                _cuiData[pN].imgAnchorMax = storedCuiFields["imgAnchorMax"];
            }
            if (storedCuiFields.ContainsKey("onCmdHide")) {
                _cuiData[pN].onCmdHide = storedCuiFields["onCmdHide"];
            }
            SaveData();
            DestroyButtonMenuUI(player);
            CreateCui(player);
            MainMenuUI(player);
            PopUpWindow(player, "small", $"<size=45>✔</size>\n<size=18>{pN} has been created!</size>\n");
        }
        [ConsoleCommand("custombuttons_edit")]
        private void custombuttons_edit(ConsoleSystem.Arg arg) {
            var player = arg?.Player();
            var args = arg.Args;
            if (args[0] == "backtomain") {
                EditMenu(player, $"{args[1]}");
                return;
            }
            if (args[0] == "backtostart") {
                DestroyAllSubs(player);
                MainMenuUI(player);
                return;
            }
            if (!storedCuiFields.ContainsKey("panelNameEdit")) {
                PopUpWindow(player, "small", GetLang("panelNameNotFound"));
                return;
            }
            DestroyEnterName(player);
            EditMenu(player, $"{args[0]}");
        }
        [ConsoleCommand("custombuttons_editmenu")]
        private void custombuttons_editmenu(ConsoleSystem.Arg arg) {
            var player = arg?.Player();
            var args = arg.Args;
            if (!_cuiData.ContainsKey(args[1])) {
                PopUpWindow(player, "small", GetLang("panelNameNotFound"));
                return;
            }
            //if (!storedCuiFields.ContainsKey("panelNameEdit")) { PopUpWindow(player, "small", GetLang("panelNameNotFound")); return; }
            if(args[0] == "color") {
                EditText(player, args[1]);
                return;
            }
            if(args[0] == "image") {
                EditImage(player, args[1]);
                return;
            }
            if(args[0] == "cui") {
                EditType(player, args[1]);
                return;
            }
            if(args[0] == "anchor") {
                DestroyAllSubs(player);
                EditPosMain(player, args[1]);
                return;
            }
            /*
            color
            image
            cui
            anchor
            */
        }
        [ConsoleCommand("custombuttons_open")]
        private void custombuttons_open(ConsoleSystem.Arg arg) {
            var player = arg?.Player();
            var args = arg.Args;
            if (arg.Player() == null) return;
            //if (args.Length < 1)
            //DestroyMainUI(player);
            if(args[0] == "mainmenu") {
                DestroyEnterName(player);
                DestroyButtonMenuUI(player);
                MainMenuUI(player);
                return;
            }
            if(args[0] == "tooltip-offset") {
                PopUpWindow(player, "tooltip-offset", "");
            }
            if(args[0] == "closemain") {
                DestroyMainUI(player);
                return;
            }
            if(args[0] == "new") {
                DestroyMainUI(player);
                NewButtonMenuUI(player);
                return;
            }
            if(args[0] == "edit") {
                DestroyMainUI(player);
                EnterName(player);
                return;
            }
            if(args[0] == "closepp") {
                DestroyPopUpWindow(player);
                return;
            }
            if(args[0] == "discard") {
                DestroyButtonMenuUI(player);
                NewButtonMenuUI(player);
                return;
            }
        }
#endregion
#region [CUI Panels]
#region Main Menu
        private void MainMenuUI(BasePlayer player) {
            string editor_Text = $"<size=23>CUI EDITOR</size>\n<color=#D1D1D1>Cui elements are saved into data file where they can be edited.If you don't like working with json files you can use the in-game editor menu to create ui panels.</color>";
            string support_Text = $"<size=23>SUPPORT</size>\n<color=#D1D1D1>If you find a bug or have any questions related to my plugins, feel free to reach out.</color>\n\n<size=23>CONTACT</size>\n<color=#D1D1D1>The best way to get in touch is to message me on my discord.</color>";
            //Background
            var _baseUI = CUIClass.CreateOverlay("MainMenu", "0 0 0 0.4", "0 0", "1 1", true, 0.0f, $"assets/content/ui/uibackgroundblur.mat");
            //Main_Div
            CUIClass.CreatePanel(ref _baseUI, "main_div", "MainMenu", "0.25 0.23 0.22 0.95", "0.28 0.2", "0.72 0.75", false, 0f, "assets/content/ui/uibackgroundblur.mat");
            CUIClass.CreatePanel(ref _baseUI, "title_div", "main_div", "0.11 0.11 0.11 0.95", "-0.005 0.9", "1.005 1", false, 0f, "assets/content/ui/uibackgroundblur.mat");
            CUIClass.CreateText(ref _baseUI, "title_text", "title_div", "1 1 1 1", $"Custom Buttons <size=13><color=#D1D1D1>{Version}</color></size>", 18, "0.02 0", "1 1", TextAnchor.MiddleLeft, $"robotocondensed-bold.ttf", "0 0 0 1", $"1.5 1.5");
            //CUIClass.CreateImage(ref _baseUI, "BasePanel", $"image-URL", $"0 0", $"1 1");
            //CUIClass.CreatePanel(ref _baseUI, "BasePanel", "BaseUI", "0.16 0.34 0.49 1.0", "0.2 0.2", "0.8 0.8", false, 0f, "assets/content/ui/uibackgroundblur.mat");
            //Middle_Div
            CUIClass.CreatePanel(ref _baseUI, "splitter_div", "main_div", "1 1 1 0.4", "0.4995 0.20", "0.50 0.75", false, 0f, "assets/icons/iconmaterial.mat");
            //Text_
            CUIClass.CreateText(ref _baseUI, "editor_text", "main_div", "1 1 1 1", editor_Text, 14, "0.05 0", "0.45 0.79", TextAnchor.UpperLeft, $"robotocondensed-bold.ttf", "0 0 0 0.7", $"0.0 0.0");
            CUIClass.CreateText(ref _baseUI, "support_text", "main_div", "1 1 1 1", support_Text, 14, "0.55 0", "0.95 0.79", TextAnchor.UpperLeft, $"robotocondensed-bold.ttf", "0 0 0 0.7", $"0.0 0.0");
            //CUIClass.CreateInput(ref _baseUI, "_amountInput", "BasePanel", "1 1 1 1", 15, "0.2 0.3", "0.8 0.8", "robotocondensed-bold.ttf", $"storemenuvalue panelName", TextAnchor.MiddleLeft);
    
// ... [Code preview truncated due to length. Full source in attached file] ...

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