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

FREE CustomButtons : 2.0.5 2.0.5

Нет прав для скачивания
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", "David", "2.0.5")]
    [Description("Custom UI Buttons")]
    public class CustomButtons : RustPlugin {
#region Create Cui
        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 = _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) => CreateCui(player);
        void OnLootEntity(BasePlayer player, BaseEntity entity) => CloseWhen(player, config.addSet.whenLooting);
        void OnLootEntityEnd(BasePlayer player, BaseEntity entity) => CreatePartialCui(player, config.addSet.whenLooting);
        void OnEntityMounted(ComputerStation entity, BasePlayer player) => CloseWhen(player, config.addSet.whenComputer);
        void OnEntityDismounted(ComputerStation entity, BasePlayer player) => CreatePartialCui(player, config.addSet.whenComputer);
        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();
        }
        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);
            }
        }
        void OnPluginLoaded(Plugin name) {
            if(name is CustomButtons) {
            }
        }
#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;
            }
            else {
                _playerData[player.userID].hidden = true;
            }
            SavePlayerData();
            CreateCui(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}");
            arg.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);
            CUIClass.CreateButton(ref _baseUI, "btn_create", "main_div", "0.38 0.51 0.16 0.85", $"Create New", 16, "0.12 0.37", $"0.38 0.48", $"custombuttons_open new", "", "1 1 1 0.5", 0f, TextAnchor.MiddleCenter, $"robotocondensed-bold.ttf");
            CUIClass.CreateButton(ref _baseUI, "btn_edit", "main_div", "0.16 0.34 0.49 0.85", $"Edit Existing", 16, "0.12 0.20", $"0.38 0.31", $"custombuttons_open edit", "", "1 1 1 0.5", 0f, TextAnchor.MiddleCenter, $"robotocondensed-bold.ttf");
            CUIClass.CreateButton(ref _baseUI, "btn_close", "title_div", "0.56 0.20 0.15 0.75", $"<size=13><color=#FFB8AA>CLOSE</color></size>", 19, "0.9 0.15", $"0.99 0.85", $"custombuttons_open closemain", "", "1 1 1 0.5", 0f, TextAnchor.MiddleCenter, $"robotocondensed-bold.ttf");
            CUIClass.CreateButton(ref _baseUI, "btn_discord", "main_div", "0.45 0.54 0.85 0.35", $"!David#1337", 16, "0.62 0.20", $"0.88 0.31", $"custombuttons_open discord", "", "1 1 1 0.7", 0f, TextAnchor.MiddleCenter, $"robotocondensed-bold.ttf");
            DestroyMainUI(player);
            CuiHelper.AddUi(player, _baseUI);
        }
        /*
                    
                    public string imageUrl;
                    public string imgAnchorMin;
                    public string imgAnchorMax;
                    public bool onCmdHide;
                    public bool onCmdOpen;
                */
        private void DestroyMainUI(BasePlayer player) {
            CuiHelper.DestroyUi(player, "MainMenu");
        }
#endregion
#region Create New Menu
        private void NewButtonMenuUI(BasePlayer player) {
            string editor_Text = $"<size=25>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=25>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=25>CONTACT</size>\n<color=#D1D1D1>The best way to get in touch is to message me in my discord channel for verified customers.</color>";
            //Background
            var _createNewMenu = CUIClass.CreateOverlay("NewMenu", "0 0 0 0.4", "0 0", "1 1", true, 0.0f, $"assets/content/ui/uibackgroundblur.mat");
            //Main_Div
            CUIClass.CreatePanel(ref _createNewMenu, "main_div", "NewMenu", "0.25 0.23 0.22 0.0", "0.25 0.15", "0.75 0.9", false, 0f, "assets/icons/iconmaterial.mat");
            CUIClass.CreatePanel(ref _createNewMenu, "main_div2", "main_div", "0.25 0.23 0.22 0.95", "0 0", "1 0.95", false, 0f, "assets/content/ui/uibackgroundblur.mat");
            CUIClass.CreatePanel(ref _createNewMenu, "title_div", "main_div2", "0.11 0.11 0.11 0.95", "-0.005 0.92", "1.002 1", false, 0f, "assets/content/ui/uibackgroundblur.mat");
            CUIClass.CreateText(ref _createNewMenu, "title_text", "title_div", "1 1 1 1", $"Create New Cui Element <size=13><color=#D1D1D1></color></size>", 18, "0.02 0", "1 1", TextAnchor.MiddleLeft, $"robotocondensed-bold.ttf", "0 0 0 1", $"1.5 1.5");
            CUIClass.CreateButton(ref _createNewMenu, "title_btn", "title_div", "0.56 0.20 0.15 0.65", $"✕", 11, "0.945 0.2", $"0.99 0.80", $"custombuttons_open mainmenu", "", "1 1 1 0.7", 0f, TextAnchor.MiddleCenter, $"robotocondensed-bold.ttf");
            //LEFT SIDE
            //Panel NAME
            CUIClass.CreatePanel(ref _createNewMenu, "field_div", "main_div", "0.11 0.11 0.11 0.95", "0.04 0.72", $"0.45 0.78", false, 0f, "assets/icons/iconmaterial.mat");
            CUIClass.CreateText(ref _createNewMenu, "panelType_text", "field_div", "1 1 1 0.3", "PANEL NAME:", 11, "0.03 0", "0.95 0.9", TextAnchor.MiddleLeft, $"robotocondensed-bold.ttf", "0 0 0 0.7", $"0.0 0.0");
            CUIClass.CreateInput(ref _createNewMenu, "_ammountInput", "field_div", "1 1 1 1", 17, "0.30 0.0", "1 0.95", "robotocondensed-bold.ttf", $"storemenuvalue panelName", TextAnchor.MiddleLeft);
            //UI TYPE
            CUIClass.CreatePanel(ref _createNewMenu, "field_div2", "main_div", "0.11 0.11 0.11 0.95", "0.04 0.633", $"0.45 0.71", false, 0f, "assets/icons/iconmaterial.mat");
            CUIClass.CreateText(ref _createNewMenu, "uiType_text", "field_div2", "1 1 1 0.3", "UI TYPE", 11, "0.05 0", "0.95 1", TextAnchor.MiddleLeft, $"robotocondensed-bold.ttf", "0 0 0 0.7", $"0.0 0.0");
            //UI TYPE BUTTONS
            //Panel Type
            CUIClass.CreatePanel(ref _createNewMenu, "field_div3", "main_div", "0.11 0.11 0.11 0.95", "0.04 0.545", $"0.45 0.622", false, 0f, "assets/icons/iconmaterial.mat");
            CUIClass.CreateText(ref _createNewMenu, "panelType_text", "field_div3", "1 1 1 0.3", "PANEL TYPE", 11, "0.05 0", "0.95 1", TextAnchor.MiddleLeft, $"robotocondensed-bold.ttf", "0 0 0 0.7", $"0.0 0.0");
            //PANEL TYPE BUTTONS
            //PANEL COLOR
            CUIClass.CreatePanel(ref _createNewMenu, "field_div4", "main_div", "0.11 0.11 0.11 0.95", "0.04 0.475", $"0.45 0.535", false, 0f, "assets/icons/iconmaterial.mat");
            CUIClass.CreateText(ref _createNewMenu, "panelType_text", "field_div4", "1 1 1 0.3", "PANEL COLOR:", 11, "0.03 0", "0.95 0.9", TextAnchor.MiddleLeft, $"robotocondensed-bold.ttf", "0 0 0 0.7", $"0.0 0.0");
            CUIClass.CreateInput(ref _createNewMenu, "_ammountInput", "field_div4", "1 1 1 1", 14, "0.32 0.0", "1 0.95", "robotocondensed-bold.ttf", $"storemenuvalue panelColor", TextAnchor.MiddleLeft);
            //CUIClass.CreatePanel(ref _createNewMenu, "field_color4", "field_div4", "0.16 0.34 0.49 1.0", "0.9 0.2", $"0.975 0.8", false, 0f, "assets/icons/iconmaterial.mat");
            //PANEL AnchorMin
            CUIClass.CreatePanel(ref _createNewMenu, "field_div5", "main_div", "0.11 0.11 0.11 0.95", "0.04 0.4", $"0.45 0.46", false, 0f, "assets/icons/iconmaterial.mat");
            CUIClass.CreateText(ref _createNewMenu, "panelType_text", "field_div5", "1 1 1 0.3", "OFFSET MIN:", 11, "0.03 0", "0.95 0.9", TextAnchor.MiddleLeft, $"robotocondensed-bold.ttf", "0 0 0 0.7", $"0.0 0.0");
            CUIClass.CreateInput(ref _createNewMenu, "_ammountInput", "field_div5", "1 1 1 1", 14, "0.32 0.0", "1 0.95", "robotocondensed-bold.ttf", $"storemenuvalue AnchorMin", TextAnchor.MiddleLeft);
            CUIClass.CreateButton(ref _createNewMenu, "btn_discord", "field_div5", "0.33 0.33 0.33 0.55", $"?", 11, "0.9 0.2", $"0.975 0.8", $"custombuttons_open tooltip-offset", "", "1 1 1 0.7", 0f, TextAnchor.MiddleCenter, $"robotocondensed-bold.ttf");
            //PANEL AnchorMax
            CUIClass.CreatePanel(ref _createNewMenu, "field_div6", "main_div", "0.11 0.11 0.11 0.95", "0.04 0.325", $"0.45 0.385", false, 0f, "assets/icons/iconmaterial.mat");
            CUIClass.CreateText(ref _createNewMenu, "panelType_text", "field_div6", "1 1 1 0.3", "OFFSET MAX:", 11, "0.03 0", "0.95 0.9", TextAnchor.MiddleLeft, $"robotocondensed-bold.ttf", "0 0 0 0.7", $"0.0 0.0");
            CUIClass.CreateInput(ref _createNewMenu, "_ammountInput", "field_div6", "1 1 1 1", 14, "0.32 0.0", "1 0.95", "robotocondensed-bold.ttf", $"storemenuvalue AnchorMax", TextAnchor.MiddleLeft);
            CUIClass.CreateButton(ref _createNewMenu, "btn_discord", "field_div6", "0.33 0.33 0.33 0.55", $"?", 11, "0.9 0.2", $"0.975 0.8", $"custombuttons_open tooltip-offset", "", "1 1 1 0.7", 0f, TextAnchor.MiddleCenter, $"robotocondensed-bold.ttf");
            //PANEL TEXT
            CUIClass.CreatePanel(ref _createNewMenu, "field_div7", "main_div", "0.11 0.11 0.11 0.95", "0.04 0.25", $"0.45 0.31", false, 0f, "assets/icons/iconmaterial.mat");
            CUIClass.CreateText(ref _createNewMenu, "panelType_text", "field_div7", "1 1 1 0.3", "TEXT:", 11, "0.03 0", "0.95 0.9", TextAnchor.MiddleLeft, $"robotocondensed-bold.ttf", "0 0 0 0.7", $"0.0 0.0");
            CUIClass.CreateInput(ref _createNewMenu, "_ammountInput", "field_div7", "1 1 1 1", 14, "0.20 0.0", "1 0.95", "robotocondensed-bold.ttf", $"storemenuvalue text", TextAnchor.MiddleLeft);
            //COMMAND TEXT
            CUIClass.CreatePanel(ref _createNewMenu, "field_div8", "main_div", "0.11 0.11 0.11 0.95", "0.04 0.17", $"0.45 0.235", false, 0f, "assets/icons/iconmaterial.mat");
            CUIClass.CreateText(ref _createNewMenu, "panelType_text", "field_div8", "1 1 1 0.3", "CHAT COMMAND:  <size=14>/</size>", 11, "0.03 0", "0.95 0.9", TextAnchor.MiddleLeft, $"robotocondensed-bold.ttf", "0 0 0 0.7", $"0.0 0.0");
            CUIClass.CreateInput(ref _createNewMenu, "_ammountInput", "field_div8", "1 1 1 1", 14, "0.40 0.0", "1 0.95", "robotocondensed-bold.ttf", $"storemenuvalue panelChatCmd", TextAnchor.MiddleLeft);
            CUIClass.CreateText(ref
// ... [Code preview truncated due to length. Full source in attached file] ...

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

Другие ресурсы пользователя 15FPS

Сверху