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

FREE CustomSets : 1.0.3 1.0.3

Нет прав для скачивания
C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
using System.Collections.Generic;
using System;
using System.Linq;
using UnityEngine;
using Oxide.Core.Plugins;
using Oxide.Core.Configuration;
using Oxide.Game.Rust.Cui;
using Oxide.Core;
using Newtonsoft.Json.Linq;
namespace Oxide.Plugins {
    [Info("CustomSets", "Absolut", "1.0.3", ResourceId = 2425)]
    [Description("An equipment set creation and management system.All Sets are managed through the UI and can be given or sold to players with Economics or ServerRewards")]
    class CustomSets : RustPlugin {
        [PluginReference]
        Plugin EventManager, ServerRewards, Economics, ImageLibrary;
        SavedData csData;
        private DynamicConfigFile CSDATA;
        bool ready;
        string TitleColor = "<color=#0045ff>";
        string MsgColor = "<color=#A9A9A9>";
        private List<ulong> SavingCollection = new List<ulong>();
        private Dictionary<string, Timer> timers = new Dictionary<string, Timer>();
        Dictionary<string, List<ulong>> ItemSkins = new Dictionary<string, List<ulong>>();
        private Dictionary<ulong, SetCreation> NewSet = new Dictionary<ulong, SetCreation>();
        class SetCreation {
            public string setname;
            public bool Editing;
            public bool UsePermission;
            public Set set = new Set();
        }
        private Dictionary<ulong, screen> CSUIInfo = new Dictionary<ulong, screen>();
        class screen {
            public bool open;
            public bool admin;
            public string SelectedCategory = string.Empty;
            public string SelectedSet;
            public int CategoryIndex;
            public int SetIndex;
            public int page;
            public int InspectedGear = -1;
            public string InspectedAttachment = string.Empty;
            public string location = string.Empty;
        }
        void Loaded() {
            ready = false;
            CSDATA = Interface.Oxide.DataFileSystem.GetFile("CustomSets_Data");
        }
        void Unload() {
            foreach (var player in BasePlayer.activePlayerList) DestroyPlayer(player);
            foreach (var timer in timers) timer.Value.Destroy();
            timers.Clear();
            SaveData();
        }
        void OnServerInitialized() {
            timer.Once(10, () => {
                if (!ImageLibrary) {
                    PrintWarning("Image Library not detected..This plugin will unload as it will not work", Name);
                    Interface.Oxide.UnloadPlugin(Name);
                    return;
                }
                LoadVariables();
                LoadData();
                InitializeStuff();
                permission.RegisterPermission(this.Title + ".admin", this);
                permission.RegisterPermission(this.Title + ".allow", this);
                foreach (var entry in csData.SavedSets.Where(k => !string.IsNullOrEmpty(k.Value.permission))) permission.RegisterPermission(this.Title + "." + entry.Value.permission.Replace(" ", string.Empty), this);
                timers.Add("info", timer.Once(900, () => InfoLoop()));
                timers.Add("save", timer.Once(600, () => SaveLoop()));
                foreach (BasePlayer p in BasePlayer.activePlayerList) OnPlayerInit(p);
            }
            );
        }
        private void InitializeStuff() {
            if (timers.ContainsKey("imageloading")) {
                timers["imageloading"].Destroy();
                timers.Remove("imageloading");
            }
            CreateLoadOrder();
            if (!isReady()) {
                Puts(GetMSG("WaitingImageLibrary"));
                timers.Add("imageloading", timer.Once(60, () => InitializeStuff()));
                return;
            }
            ;
            foreach (var itemDef in ItemManager.GetItemDefinitions()) {
                List<ulong> skins;
                skins = new List<ulong> {
                    0
                }
                ;
                skins.AddRange(ItemSkinDirectory.ForItem(itemDef).Select(skin => Convert.ToUInt64(skin.id)));
                List<ulong> templist = GetImageList(itemDef.shortname);
                if (templist != null && templist.Count >= 1) foreach (var entry in templist.Where(k => !skins.Contains(k))) skins.Add(entry);
                ItemSkins.Add(itemDef.shortname, skins);
            }
        }
        private void CreateLoadOrder() {
            Dictionary<string, string> newLoadOrder = new Dictionary<string, string> {
                {
                    "cs_selectedbutton", "http://i.imgur.com/tfpKLAQ.png"
                }
                , {
                    "cs_unselectedbutton", "http://i.imgur.com/i3XLvJb.png"
                }
                , {
                    "cs_attachmentoverlay", "http://i.imgur.com/Icl5BaB.png"
                }
                , {
                    "cs_next", "http://i.imgur.com/F4FnvVT.png"
                }
                , {
                    "cs_prior", "http://i.imgur.com/SP93UQj.png"
                }
                , {
                    "cs_smallbackground", "http://i.imgur.com/fIetbic.png"
                }
                , {
                    "cs_remove", "http://i.imgur.com/7D6cGeu.png"
                }
                , {
                    "cs_back", "http://i.imgur.com/Ymexrbe.jpg"
                }
                , {
                    "cs_background", "http://i.imgur.com/1sJtIBF.png"
                }
            }
            ;
            ImageLibrary.Call("ImportImageList", Title, newLoadOrder, (ulong)ResourceId, true);
        }
        private void OnPlayerInit(BasePlayer player) {
            if (player != null) {
                string key = String.Empty;
                //if (!string.IsNullOrEmpty(configData.MenuKeyBinding))
                //{
                //    player.Command($"bind {configData.MenuKeyBinding} \"ToggleCSUI\"");
                //    key = GetMSG("CSAltInfo", player, configData.MenuKeyBinding.ToUpper());
                //}
                if (configData.InfoInterval != 0) GetSendMSG(player, "CSInfo", key);
            }
        }
        private void OnPlayerRespawned(BasePlayer player) {
            DestroyUI(player);
            if (EventManager) {
                object isPlaying = EventManager?.Call("isPlaying", new object[] {
                    player
                }
                );
                if (isPlaying is bool) if ((bool)isPlaying) return;
            }
            foreach (var entry in configData.SpawnSets.OrderBy(k => k.Key)) if (csData.SavedSets.ContainsKey(entry.Value) && (string.IsNullOrEmpty(csData.SavedSets[entry.Value].permission) || permission.UserHasPermission(player.UserIDString, this.Title + "." + csData.SavedSets[entry.Value].permission.Replace(" ", string.Empty)))) {
                var setData = csData.SavedSets[entry.Value];
                if (setData.cooldown != 0 || setData.dailyUses != 0 && csData.PlayerData.ContainsKey(player.userID)) {
                    var data = csData.PlayerData[player.userID];
                    CoolandUse info = null;
                    data.cooldownANDuses.TryGetValue(entry.Value, out info);
                    if (info != null) {
                        if (info.CooldownExpiration < CurrentTotalMinutes()) info.CooldownExpiration = 0;
                        if (CurrentTotalMinutes() > info.FirstUse + (configData.UsesResetInterval_InHours * 60 * 60)) {
                            info.timesUsed = 0;
                            info.FirstUse = 0;
                        }
                        if (info.CooldownExpiration != 0 || setData.dailyUses - info.timesUsed == 0) continue;
                    }
                }
                player.inventory.Strip();
                ProcessSelection(player, entry.Value);
                return;
            }
        }
        private void SRAction(ulong ID, int amount, string action) {
            if (action == "ADD") ServerRewards?.Call("AddPoints", new object[] {
                ID, amount
            }
            );
            if (action == "REMOVE") ServerRewards?.Call("TakePoints", new object[] {
                ID, amount
            }
            );
        }
        private void ECOAction(ulong ID, int amount, string action) {
            if (action == "ADD") Economics.Call("DepositS", ID.ToString(), amount);
            if (action == "REMOVE") Economics.Call("WithdrawS", ID.ToString(), amount);
        }
        object OnServerCommand(ConsoleSystem.Arg arg) {
            var player = arg.Connection?.player as BasePlayer;
            if (player != null && SavingCollection.Contains(player.userID) && arg.cmd?.FullName == "chat.say" && !string.IsNullOrEmpty(string.Join(" ", arg.Args)) && !arg.GetString(0).StartsWith("/")) {
                CollectionCreationChat(player, string.Join(" ", arg.Args));
                return false;
            }
            return null;
        }
        private void CollectionCreationChat(BasePlayer player, string Args) {
            if (Args.Contains("quit")) {
                ExitSetCreation(player);
                return;
            }
            if (csData.SavedSets.ContainsKey(Args)) {
                GetSendMSG(player, "NameTaken", Args);
                return;
            }
            NewSet[player.userID].setname = Args;
            SaveCollection(player);
        }
        private string TryForImage(string shortname, ulong skin = 99) {
            if (shortname.Contains("http")) return shortname;
            if (skin == 99) skin = (ulong)ResourceId;
            return GetImage(shortname, skin, true);
        }
        public string GetImage(string shortname, ulong skin = 0, bool returnUrl = false) => (string)ImageLibrary.Call("GetImage", shortname.ToLower(), skin, returnUrl);
        public bool HasImage(string shortname, ulong skin = 0) => (bool)ImageLibrary.Call("HasImage", shortname.ToLower(), skin);
        public bool AddImage(string url, string shortname, ulong skin = 0) => (bool)ImageLibrary?.Call("AddImage", url, shortname.ToLower(), skin);
        public List<ulong> GetImageList(string shortname) => (List<ulong>)ImageLibrary.Call("GetImageList", shortname.ToLower());
        public bool isReady() => (bool)ImageLibrary?.Call("IsReady");
        private object CheckPoints(ulong ID) => ServerRewards?.Call("CheckPoints", ID);
        void DestroyPlayer(BasePlayer player) {
            if (player == null) return;
            {
                DestroyUI(player);
                //if (!string.IsNullOrEmpty(configData.MenuKeyBinding))
                //    player.Command($"bind {configData.MenuKeyBinding} \"\"");
                CSUIInfo.Remove(player.userID);
            }
        }
        private void OnPlayerDisconnected(BasePlayer player) {
            DestroyPlayer(player);
            SaveData();
        }
        private void GetSendMSG(BasePlayer player, string message, string arg1 = "", string arg2 = "", string arg3 = "") {
            string msg = string.Format(lang.GetMessage(message, this, player.UserIDString), arg1, arg2, arg3);
            SendReply(player, TitleColor + lang.GetMessage("title", this, player.UserIDString) + "</color>" + MsgColor + msg + "</color>");
        }
        private string GetMSG(string message, BasePlayer player = null, string arg1 = "", string arg2 = "", string arg3 = "") {
            string p = null;
            if (player != null) p = player.UserIDString;
            if (messages.ContainsKey(message)) return string.Format(lang.GetMessage(message, this, p), arg1, arg2, arg3);
            else return message;
        }
        [ChatCommand("sets")]
        private void chatauction(BasePlayer player, string cmd, string[] args) {
            if (player == null) return;
            if (!isAuth(player) && !permission.UserHasPermission(player.UserIDString, this.Title + ".allow")) {
                GetSendMSG(player, "NoPerm");
                return;
            }
            ToggleCSUI(player);
        }
        [ConsoleCommand("ToggleCSUI")]
        private void cmdToggleCSUI(ConsoleSystem.Arg arg) {
            var player = arg.Connection.player as BasePlayer;
            if (player == null) return;
            if (!isAuth(player) && !permission.UserHasPermission(player.UserIDString, this.Title + ".allow")) {
                GetSendMSG(player, "NoPerm");
                return;
            }
            if (arg.Args != null && arg.Args.Length > 0 && arg.Args[0] == "close") {
                CuiHelper.DestroyUi(player, BackgroundPanel);
                DestroySetPanels(player);
                return;
            }
            if (!ImageLibrary || !isReady()) {
                GetSendMSG(player, "ImagesLoading");
                return;
            }
            else if (CSUIInfo.ContainsKey(player.userID)) if (!CSUIInfo[player.userID].open) {
                CSUIInfo[player.userID].open = true;
                ToggleCSUI(player);
            }
            else {
                CuiHelper.DestroyUi(player, BackgroundPanel);
                DestroySetPanels(player);
            }
            else ToggleCSUI(player);
        }
        private void ToggleCSUI(BasePlayer player) {
            if (!CSUIInfo.ContainsKey(player.userID)) CSUIInfo.Add(player.userID, new screen());
            CSUIInfo[player.userID].open = true;
            UIPanel(player);
        }
        public void DestroyUI(BasePlayer player) {
            DestroySetPanels(player);
            CuiHelper.DestroyUi(player, BackgroundPanel);
            CuiHelper.DestroyUi(player, PanelOnScreen);
            CuiHelper.DestroyUi(player, PanelMisc);
        }
        public void DestroySetPanels(BasePlayer player) {
            if (CSUIInfo.ContainsKey(player.userID)) CSUIInfo[player.userID].open = false;
            CuiHelper.DestroyUi(player, SetContentsPanel);
            CuiHelper.DestroyUi(player, PanelInspector);
            CuiHelper.DestroyUi(player, SetIndexPanel);
            CuiHelper.DestroyUi(player, PanelMisc);
        }
        public void Broadcast(string message, string userid = "0") => PrintToChat(message);
        private void SaveCollection(BasePlayer player) {
            var name = NewSet[player.userID].setname;
            if (NewSet[player.userID].UsePermission) {
                NewSet[player.userID].set.permission = name.Replace(" ", string.Empty);
                permission.RegisterPermission(this.Title + "." + name, this);
            }
            if (csData.SavedSets.ContainsKey(name)) csData.SavedSets.Remove(name);
            csData.SavedSets.Add(name, NewSet[player.userID].set);
            NewSet.Remove(player.userID);
            SavingCollection.Remove(player.userID);
            GetSendMSG(player, "NewSetCreated", name);
            CuiHelper.DestroyUi(player, PanelMisc);
            SaveData();
            CSUIInfo[player.userID].SelectedSet = string.Empty;
            ToggleCSUI(player);
        }
        private void ExitSetCreation(BasePlayer player) {
            if (SavingCollection.Contains(player.userID)) SavingCollection.Remove(player.userID);
            SetPanel(player);
        }
        bool isAuth(BasePlayer player) {
            if (player.net.connection != null) if (player.net.connection.authLevel < 2 && !permission.UserHasPermission(player.UserIDString, this.Title + ".admin")) return false;
            return true;
        }
        private string BackgroundPanel = "BackgroundPanel";
        private string SetIndexPanel = "SetIndexPanel";
        private string SetContentsPanel = "SetContentsPanel";
        private string PanelInspector = "PanelInspector";
        private string PanelOnScreen = "OnScreen";
        private string PanelMisc = "PanelMisc";
        public class UI {
            static public CuiElementContainer CreateElementContainer(string panelName, string color, string aMin, string aMax, bool cursor = false) {
                var NewElement = new CuiElementContainer() {
                    {
                        new CuiPanel {
                            Image = {
                                Color = color
                            }
                            , RectTransform = {
                                AnchorMin = aMin, AnchorMax = aMax
                            }
                            , CursorEnabled = cursor
                        }
                        , new CuiElement().Parent, panelName
                    }
                }
                ;
                return NewElement;
            }
            static public CuiElementContainer CreateOverlayContainer(string panelName, string color, string aMin, string aMax, bool cursor = false) {
                var NewElement = new CuiElementContainer() {
                    {
                        new CuiPanel {
                            Image = {
                                Color = color
                            }
                            , RectTransform = {
                                AnchorMin = aMin, AnchorMax = aMax
                            }
                            , CursorEnabled = cursor
                        }
                        , new CuiElement().Parent = "Overlay", panelName
                    }
                }
                ;
                return NewElement;
            }
            static public void CreatePanel(ref CuiElementContainer container, string panel, string color, string aMin, string aMax, bool cursor = false) {
                container.Add(new CuiPanel {
                    Image = {
                        Color = color
                    }
                    , RectTransform = {
                        AnchorMin = aMin, AnchorMax = aMax
                    }
                    , CursorEnabled = cursor
                }
                , panel);
            }
            static public void CreateLabel(ref CuiElementContainer container, string panel, string color, string text, int size, string aMin, string aMax, TextAnchor align = TextAnchor.MiddleCenter) {
                container.Add(new CuiLabel {
                    Text = {
                        Color = color, FontSize = size, Align = align, FadeIn = 1.0f, Text = text
                    }
                    , RectTransform = {
                        AnchorMin = aMin, AnchorMax = aMax
                    }
                }
                , panel);
            }
            static public void CreateButton(ref CuiElementContainer container, string panel, string color, string text, int size, string aMin, string aMax, string command, TextAnchor align = TextAnchor.MiddleCenter) {
                container.Add(new CuiButton {
                    Button = {
                        Color = color, Command = command, FadeIn = 1.0f
                    }
                    , RectTransform = {
                        AnchorMin = aMin, AnchorMax = aMax
                    }
                    , Text = {
                        Text = text, FontSize = size, Align = align
                    }
                }
                , panel);
            }
            static public void LoadImage(ref CuiElementContainer container, string panel, string img, string aMin, string aMax) {
                if (img.StartsWith("http") || img.StartsWith("www")) {
                    container.Add(new CuiElement {
                        Parent = panel, Components = {
                            new CuiRawImageComponent {
                                Url = img, Sprite = "assets/content/textures/generic/fulltransparent.tga"
                            }
                            , new CuiRectTransformComponent {
                                AnchorMin = aMin, AnchorMax = aMax
                            }
                        }
                    }
                    );
                }
                else container.Add(new CuiElement {
                    Parent = panel, Components = {
                        new CuiRawImageComponent {
                            Png = img, Sprite = "assets/content/textures/generic/fulltransparent.tga"
                        }
                        , new CuiRectTransformComponent {
                            AnchorMin = aMin, AnchorMax = aMax
                        }
                    }
                }
                );
            }
            static public void CreateTextOutline(ref CuiElementContainer element, string panel, string colorText, string colorOutline, string text, int size, string aMin, string aMax, TextAnchor align = TextAnchor.MiddleCenter) {
                element.Add(new CuiElement {
                    Parent = panel, Components = {
                        new CuiTextComponent {
                            Color = colorText, FontSize = size, Align = align, Text = text
                        }
                        , new CuiOutlineComponent {
                            Distance = "1 1", Color = colorOutline
                        }
                        , new CuiRectTransformComponent {
                            AnchorMax = aMax, AnchorMin = aMin
                        }
                    }
                }
                );
            }
        }
        private Dictionary<string, string> UIColors = new Dictionary<string, string> {
            {
                "black", "0 0 0 1.0"
            }
            , {
                "dark", "0.1 0.1 0.1 0.98"
            }
            , {
                "header", "0.7 0.7 0.7 0.15"
            }
            , {
                "background", "0 0 0 1.0"
            }
            , {
                "white", "1 1 1 1"
            }
            , {
                "grey", "0.7 0.7 0.7 1.0"
            }
            , {
                "buttonblue", "0.05 0.08 0.176 1.0"
            }
            , {
                "buttonbg", "0.4 0.4 0.4 0.5"
            }
            , {
                "buttongreen", "0.133 0.965 0.133 0.9"
            }
            , {
                "buttonred", "0.964 0.133 0.133 0.9"
            }
            , {
                "buttongrey", "0.8 0.8 0.8 0.9"
            }
            , {
                "SpecialOrange", "0.956 0.388 0.03 1.0"
            }
        }
        ;
        void UIPanel(BasePlayer player) {
            CuiHelper.DestroyUi(player, BackgroundPanel);
            var element = UI.CreateOverlayContainer(BackgroundPanel, "0 0 0 0", "0.1 0.05", "0.9 0.97", true);
            //UI.CreatePanel(ref element, BackgroundPanel, UIColors["header"], "0.005 0.01", "0.995 0.99");
            UI.LoadImage(ref element, BackgroundPanel, TryForImage("CS_Background"), "0 0", "1 1");
            if (CSUIInfo.ContainsKey(player.userID)) CSUIInfo[player.userID].open = true;
            if (configData.UsePayment) {
                string money = ServerRewards && CheckPoints(player.userID) is int ? CheckPoints(player.userID).ToString() : Economics ? Economics.CallHook("GetPlayerMoney", player.userID).ToString() : "0";
                UI.CreateTextOutline(ref element, BackgroundPanel, UIColors["white"], UIColors["black"], money, 26, "0.8 0.92", "0.98 0.97", TextAnchor.LowerLeft);
            }
            UI.CreateButton(ref element, BackgroundPanel, "0 0 0 0", "", 16, "0.95 0.92", ".99.98", "ToggleCSUI close");
            CuiHelper.AddUi(player, element);
            SetListPanel(player);
            SetPanel(player);
        }
        private static readonly DateTime Epoch = new DateTime(1970, 1, 1, 0, 0, 0);
        static double CurrentTotalMinutes() => DateTime.UtcNow.Subtract(Epoch).TotalMinutes;
        private string GetMinutesFormat(double minutes) {
            TimeSpan dateDifference = TimeSpan.FromMinutes(minutes);
            var hours = dateDifference.Hours;
            hours += (dateDifference.Days * 24);
            return string.Format("{0:00}:{1:00}:{2:00}", hours, dateDifference.Minutes, dateDifference.Seconds);
        }
        void SetListPanel(BasePlayer player) {
            CuiHelper.DestroyUi(player, SetIndexPanel);
            var element = UI.CreateOverlayContainer(SetIndexPanel, "0 0 0 0", "0.11 0.1", "0.32 0.95");
            UI.CreateTextOutline(ref element, SetIndexPanel, UIColors["white"], UIColors["black"], GetMSG("ListOFSets", player), 22, "0.1 0.91", "0.9 0.985", TextAnchor.UpperCenter);
            var uiInfo = CSUIInfo[player.userID];
            if (string.IsNullOrEmpty(uiInfo.SelectedCategory)) {
                //UI.CreateTextOutline(ref element, SetIndexPanel, UIColors["white"], UIColors["black"], GetMSG("SetCategories", player), 16, "0.1 0.85", "0.9 0.9", TextAnchor.MiddleCenter);
                if (configData.Categories.Count() >= 1) {
                    if (CSUIInfo[player.userID].CategoryIndex + 10 < configData.Categories.Count()) {
                        UI.LoadImage(ref element, SetIndexPanel, TryForImage("CS_down"), "0.3 0.02", "0.45 0.07");
                        UI.CreateButton(ref element, SetIndexPanel, "0 0 0 0", "", 12, "0.3 0.02", "0.45 0.07", $"UI_CategoryIndexShownChange {CSUIInfo[player.userID].CategoryIndex + 1}");
                    }
                    if (CSUIInfo[player.userID].CategoryIndex != 0) {
                        UI.LoadImage(ref element, SetIndexPanel, TryForImage("CS_up"), "0.55 0.02", "0.7 0.07");
                        UI.CreateButton(ref element, SetIndexPanel, "0 0 0 0", "", 12, "0.55 0.02", "0.7 0.07", $"UI_CategoryIndexShownChange {CSUIInfo[player.userID].CategoryIndex - 1}");
                    }
                    var i = -1;
                    foreach (var entry in configData.Categories) {
                        i++;
                        if (i < CSUIInfo[player.userID].CategoryIndex) continue;
                        if (i > CSUIInfo[player.userID].CategoryIndex + 10) continue;
                        var pos = CalcSetButtons(i - CSUIInfo[player.userID].CategoryIndex);
                        UI.LoadImage(ref element, SetIndexPanel, TryForImage("CS_UnselectedButton"), $"{ pos[0]} {pos[1]}", $"{pos[2] -.04f} {pos[3]}");
                        UI.CreateLabel(ref element, SetIndexPanel, UIColors["white"], entry, 24, $"{pos[0] +.15f} {pos[1]}", $"{pos[2]} {pos[3]}", TextAnchor.MiddleLeft);
                        UI.CreateButton(ref element, SetIndexPanel, "0 0 0 0", "", 12, $"{pos[0]} {pos[1]}", $"{pos[2]} {pos[3]}", $"UI_ChangeCategory {entry}", TextAnchor.MiddleLeft);
                    }
                }
            }
            else {
                UI.CreateLabel(ref element, SetIndexPanel, UIColors["SpecialOrange"], GetMSG("Category", player, uiInfo.SelectedCategory), 16, "0.14 0.9", "0.75 0.97", TextAnchor.LowerLeft);
                UI.LoadImage(ref element, SetIndexPanel, TryForImage("CS_Back"), "0.75 0.9", "0.95 0.93");
                UI.CreateLabel(ref element, SetIndexPanel, UIColors["white"], GetMSG("Back"), 10, "0.84 0.9", "0.95 0.93", TextAnchor.MiddleLeft);
                UI.CreateButton(ref element, SetIndexPanel, "0 0 0 0", "", 12, "0.75 0.9", "0.95 0.93", $"UI_ChangeCategory BACK");
                List<string> sets = new List<string>();
                if (CSUIInfo[player.userID].admin) sets = csData.SavedSets.Where(k => k.Value.Category == uiInfo.SelectedCategory).Select(k => k.Key).ToList();
                else if (!configData.ShowLockedSets) sets = csData.SavedSets.Where(k => k.Value.Category == uiInfo.SelectedCategory && !k.Value.hidden && (string.IsNullOrEmpty(k.Value.permission) || permission.UserHasPermission(player.UserIDString, this.Title + "." + k.Value.permission.Replace(" ", string.Empty)))).Select(k => k.Key).ToList();
                else sets = csData.SavedSets.Where(k => k.Value.Category == uiInfo.SelectedCategory && !k.Value.hidden).Select(k => k.Key).ToList();
                if (sets.Count() >= 1) {
                    if (CSUIInfo[player.userID].SetIndex + 10 < sets.Count()) {
                        UI.LoadImage(ref element, SetIndexPanel, TryForImage("CS_Prior"), "0.135 -0.01", "0.58 0.035");
                        UI.CreateButton(ref element, SetIndexPanel, "0 0 0 0", "", 12, "0.135 -0.01", "0.58 0.035", $"UI_GearIndexShownChange {CSUIInfo[player.userID].SetIndex + 1}");
                    }
                    if (CSUIInfo[player.userID].SetIndex != 0) {
                        UI.LoadImage(ref element, SetIndexPanel, TryForImage("CS_Next"), "0.58 -0.01", "1.01 0.035");
                        UI.CreateButton(ref element, SetIndexPanel, "0 0 0 0", "", 12, "0.58 -0.01", "1.01 0.035", $"UI_GearIndexShownChange {CSUIInfo[player.userID].SetIndex - 1}");
                    }
                    var i = -1;
                    foreach (var entry in sets) {
                        i++;
                        if (i < CSUIInfo[player.userID].SetIndex) continue;
                        if (i > CSUIInfo[player.userID].SetIndex + 10) continue;
                        var pos = CalcSetButtons(i - CSUIInfo[player.userID].SetIndex);
                        if (CSUIInfo[player.userID].SelectedSet == entry) UI.LoadImage(ref element, SetIndexPanel, TryForImage("CS_SelectedButton"), $"{ pos[0]} {pos[1]}", $"{pos[2]} {pos[3]}");
                        else UI.LoadImage(ref element, SetIndexPanel, TryForImage("CS_UnselectedButton"), $"{ pos[0]} {pos[1]}", $"{pos[2] -.04f} {pos[3]}");
                        UI.CreateLabel(ref element, SetIndexPanel, UIColors["white"], entry, 24, $"{pos[0] +.15f} {pos[1]}", $"{pos[2]} {pos[3]}", TextAnchor.MiddleLeft);
                        //if (!string.IsNullOrEmpty(csData.SavedSets[entry].permission) && !permission.UserHasPermission(player.UserIDString, this.Title + "." + csData.SavedSets[entry].permission.Replace(" ", string.Empty)))
                        //    UI.LoadImage(ref element, SetIndexPanel, TryForImage("CS_lock"), $"{pos[0] +.02f} {pos[1]}", $"{pos[0] + 0.18f} {pos[3]}");
                        UI.CreateButton(ref element, SetIndexPanel, "0 0 0 0", "", 12, $"{pos[0]} {pos[1]}", $"{pos[2]} {pos[3]}", $"UI_ChangeSet {entry}", TextAnchor.MiddleLeft);
                    }
                }
            }
            CuiHelper.AddUi(player, element);
        }
        private float[] CalcSetButtons(int number) {
            Vector2 position = new Vector2(0.13f, 0.83f);
            Vector2 dimensions = new Vector2(0.88f, 0.05f);
            float offsetY = 0;
            float offsetX = 0;
            if (number >= 0 && number < 15) {
                offsetY = (-0.005f - dimensions.y) * number;
            }
            Vector2 offset = new Vector2(offsetX, offsetY);
            Vector2 posMin = position + offset;
            Vector2 posMax = posMin + dimensions;
            return new float[] {
                posMin.x, posMin.y, posMax.x, posMax.y
            }
            ;
        }
        void SetPanel(BasePlayer player) {
            CuiHelper.DestroyUi(player, PanelMisc);
            CuiHelper.DestroyUi(player, SetContentsPanel);
            CuiHelper.DestroyUi(player, PanelInspector);
            var element = UI.CreateOverlayContainer(SetContentsPanel, "0 0 0 0", "0.33 0.06", "0.7 0.86");
            UI.CreateTextOutline(ref element, SetContentsPanel, UIColors["white"], UIColors["black"], GetMSG("INFO", player), 22, "1.01 0.94", "1.42 1");
            UI.CreateTextOutline(ref element, SetContentsPanel, UIColors["white"], UIColors["black"], GetMSG("Container", player, "HOTBAR"), 20, "0.15 0.71", "0.79 0.84", TextAnchor.MiddleLeft);
            UI.CreateTextOutline(ref element, SetContentsPanel, UIColors["white"], UIColors["black"], GetMSG("Container", player, "INVENTORY"), 20, "0.15 0.55", "0.9 0.6", TextAnchor.MiddleLeft);
            UI.CreateTextOutline(ref element, SetContentsPanel, UIColors["white"], UIColors["black"], GetMSG("Container", player, "WEAR"), 20, "0.15 0.95", "0.9 0.99", TextAnchor.MiddleLeft);
            if (isAuth(player)) if (CSUIInfo[player.userID].admin) UI.CreateButton(ref element, SetContentsPanel, UIColors["SpecialOrange"], $"<color=black>{GetMSG("ToggleAdminView", player)}</color>", 12, "1.55 1.05", "1.7 1.1", "UI_SwitchAdminView");
            else UI.CreateButton(ref element, SetContentsPanel, UIColors["black"], $"<color=#F56201>{GetMSG("ToggleAdminView", player)}</color>", 12, "1.55 1.05", "1.7 1.1", "UI_SwitchAdminView");
            if (!string.IsNullOrEmpty(CSUIInfo[player.userID].SelectedCategory)) {
                if (NewSet.ContainsKey(player.userID) && CSUIInfo[player.userID].admin && (!NewSet[player.userID].Editing || (NewSet[player.userID].Editing && NewSet[player.userID].setname == CSUIInfo[player.userID].SelectedSet))) {
                    foreach (var entry in new Dictionary<string, List<Gear>> {
                        {
                            "belt", NewSet[player.userID].set.belt
                        }
                        , {
                            "wear", NewSet[player.userID].set.wear
                        }
                        , {
                            "main", NewSet[player.userID].set.main
                        }
                    }
                    ) GearEntries(player, element, entry.Value, entry.Key);
                    if (NewSet[player.userID].Editing) {
                        if (NewSet[player.userID].setname == CSUIInfo[player.userID].SelectedSet) {
                            var info = NewSet[player.userID].set;
                            UI.CreateButton(ref element, SetContentsPanel, UIColors["black"], $"<color=#F56201>{GetMSG("Cost", player, info.cost.ToString())}</color>", 10, "1.55.93", "1.7.98", $"UI_EditSetCost");
                            UI.CreateLabel(ref element, SetContentsPanel, UIColors["white"], GetMSG("DailyUses", player, info.dailyUses <= 0 ? GetMSG("Unlimited") : $"<color=green>{info.dailyUses}</color>/{info.dailyUses}"), 22, "1.03 0.86", "1.42 0.94", TextAnchor.MiddleLeft);
                            UI.CreateButton(ref element, SetContentsPanel, UIColors["black"], $"<color=#F56201>{GetMSG("Uses", player)}</color>", 10, "1.55 0.87", "1.7 0.92", $"UI_EditSetUses");
                            UI.CreateLabel(ref element, SetContentsPanel, UIColors["white"], GetMSG("Cooldown", player, info.cooldown <= 0 ? GetMSG("None", player) : GetMinutesFormat(info.cooldown).ToString()), 22, "1.03 0.78", "1.42 0.86", TextAnchor.MiddleLeft);
                            UI.CreateButton(ref element, SetContentsPanel, UIColors["black"], $"<color=#F56201>{GetMSG("CooldownTitle", player)}</color>", 10, "1.55 0.81", "1.7 0.86", $"UI_EditSetCooldown");
                            UI.CreateButton(ref element, SetContentsPanel, UIColors["black"], $"<color=#F56201>{GetMSG("Hidden", player, info.hidden.ToString())}</color>", 10, "1.55.75", "1.7.8", $"UI_HiddenSet");
                            UI.CreateButton(ref element, SetContentsPanel, UIColors["black"], $"<color=#F56201>{GetMSG("Permission", player, string.IsNullOrEmpty(info.permission).ToString())}</color>", 10, "1.55.69", "1.7.74", $"UI_Permission");
                            UI.CreateButton(ref element, SetContentsPanel, UIColors["black"], $"<color=#F56201>{GetMSG("ExitSetEditing", player)}</color>", 10, "1.55.99", "1.7 1.04", $"UI_CancelSetCreation");
                        }
                    }
                    else {
                        UI.CreateButton(ref element, SetContentsPanel, UIColors["black"], $"<color=#F56201>{GetMSG("CancelSet", player)}</color>", 10, "1.55.99", "1.7 1.04", $"UI_CancelSetCreation");
                        UI.CreateButton(ref element, SetContentsPanel, "0 0 0 0", GetMSG("SaveSet"), 18, "1.01 0.04", "1.42 0.14", $"UI_SaveCollect");
                    }
                }
                else if (string.IsNullOrEmpty(CSUIInfo[player.userID].SelectedSet) && CSUIInfo[player.userID].admin) UI.CreateButton(ref element, SetContentsPanel, UIColors["black"], $"<color=#F56201>{GetMSG("CreateSet", player)}</color>", 10, "1.55.99", "1.7 1.04", $"UI_CreateGearSet");
                else if (!string.IsNullOrEmpty(CSUIInfo[player.userID].SelectedSet)) {
                    var setname = CSUIInfo[player.userID].SelectedSet;
                    var money = 0;
                    if (ServerRewards && CheckPoints(player.userID) is int) money = (int)CheckPoints(player.userID);
                    else if (Economics) money = Convert.ToInt32(Economics.CallHook("GetPlayerMoney", player.userID));
                    if (string.IsNullOrEmpty(setname) || !csData.SavedSets.ContainsKey(setname)) return;
                    bool ready = true;
                    bool printed = false;
                    var set = csData.SavedSets[setname];
                    foreach (var entry in new Dictionary<string, List<Gear>> {
                        {
                            "belt", set.belt
                        }
                        , {
                            "wear", set.wear
                        }
                        , {
                            "main", set.main
                        }
                    }
                    ) {
                        GearEntries(player, element, entry.Value, entry.Key);
                    }
                    if ((set.cooldown != 0 || set.dailyUses != 0) && csData.PlayerData.ContainsKey(player.userID)) {
                        var data = csData.PlayerData[player.userID];
                        CoolandUse info = null;
                        data.cooldownANDuses.TryGetValue(setname, out info);
                        if (info != null) {
                            printed = true;
                            if (info.CooldownExpiration < CurrentTotalMinutes()) info.CooldownExpiration = 0;
                            if (CurrentTotalMinutes() > info.FirstUse + (configData.UsesResetInterval_InHours * 60 * 60)) {
                                info.timesUsed = 0;
                                info.FirstUse = 0;
                            }
                            UI.CreateLabel(ref element, SetContentsPanel, UIColors["white"], GetMSG("DailyUses", player, set.dailyUses <= 0 ? GetMSG("Unlimited") : $"<color=red>{set.dailyUses - info.timesUsed}</color>/{set.dailyUses}"), 22, "1.03 0.86", "1.42 0.94", TextAnchor.MiddleLeft);
                            UI.CreateLabel(ref element, SetContentsPanel, UIColors["white"], GetMSG("Cooldown", player, set.cooldown <= 0 ? GetMSG("None", player) : info.CooldownExpiration != 0 ? "<color=red> -" + GetMinutesFormat(info.CooldownExpiration - CurrentTotalMinutes()) + "</color>" : GetMinutesFormat(set.cooldown).ToString()), 22, "1.03 0.78", "1.42 0.86", TextAnchor.MiddleLeft);
                            if (info.CooldownExpiration != 0 || set.dailyUses - info.timesUsed == 0) ready = false;
                        }
                    }
                    if (!printed) {
                        UI.CreateLabel(ref element, SetContentsPanel, UIColors["white"], GetMSG("DailyUses", player, set.dailyUses <= 0 ? GetMSG("Unlimited") : $"<color=green>{set.dailyUses}</color>/{set.dailyUses}"), 22, "1.03 0.86", "1.42 0.94", TextAnchor.MiddleLeft);
                        UI.CreateLabel(ref element, SetContentsPanel, UIColors["white"], GetMSG("Cooldown", player, set.cooldown <= 0 ? GetMSG("None", player) : GetMinutesFormat(set.cooldown).ToString()), 22, "1.03 0.78", "1.42 0.86", TextAnchor.MiddleLeft);
                    }
                    if (string.IsNullOrEmpty(set.permission) || permission.UserHasPermission(player.UserIDString, this.Title + "." + set.permission.Replace(" ", string.Empty))) {
                        if (ready) UI.CreateButton(ref element, SetContentsPanel, "0 0 0 0", GetMSG("Redeem", player, setname.ToUpper()), 26, "1.01 0.04", "1.42 0.14", $"UI_ProcessSelection {setname}");
                    }
                    else if (configData.UsePayment) {
                        if (money >= set.cost) {
                            UI.CreateButton(ref element, SetContentsPanel, "0 0 0 0", GetMSG("UnlockSet", player, set.cost.ToString()), 22, "1.01 0.04", "1.42 0.14", $"UI_SetPurchase {setname}");
                        }
                        else UI.CreateTextOutline(ref element, SetContentsPanel, UIColors["white"], UIColors["black"], GetMSG("CostOFSet", player, set.cost.ToString()), 24, "1.01 0.04", "1.42 0.14");
                    }
                    if (CSUIInfo[player.userID].admin) {
                        if (!NewSet.ContainsKey(player.userID) || (NewSet[player.userID].Editing && NewSet[player.userID].setname != CSUIInfo[player.userID].SelectedSet)) {
                            UI.CreateButton(ref element, SetContentsPanel, UIColors["black"], $"<color=#F56201>{GetMSG("CreateSet", player)}</color>", 10, "1.55.99", "1.7 1.04", $"UI_CreateGearSet");
                            UI.CreateButton(ref element, SetContentsPanel, UIColors["black"], $"<color=#F56201>{GetMSG("Edit", player)}</color>", 14, "1.55 0.93", "1.7 0.98", $"UI_EditGearSet");
                            UI.CreateButton(ref element, SetContentsPanel, UIColors["black"], $"<color=#F56201>{GetMSG("Delete", player)}</color>", 14, "1.55 0.87", "1.7 0.92", $"UI_DeleteGearSet");
                        }
                    }
                }
            }
            CuiHelper.AddUi(player, element);
            InspectorPanel(player);
        }
        private void GearEntries(BasePlayer player, CuiElementContainer element, List<Gear> list, string location) {
            float[] pos;
            var i = 0;
            foreach (var item in list) {
                pos = MainLocation(i);
                if (location == "belt") pos = BeltLocation(i);
                if (location == "wear") pos = WearLocation(i);
                UI.LoadImage(ref element, SetContentsPanel, TryForImage(item.shortname, item.skin), $"{pos[0]} {pos[1]}", $"{pos[2]} {pos[3]}");
                if (item.attachments != null && item.attachments.Count > 0) UI.LoadImage(ref element, SetContentsPanel, TryForImage("CS_AttachmentOverlay"), $"{pos[0]} {pos[1]}", $"{pos[2]} {pos[3]}");
                UI.CreateButton(ref element, SetContentsPanel, "0 0 0 0", "", 16, $"{pos[0]} {pos[1]}", $"{pos[2]} {pos[3]}", $"UI_ChangeSelection {i} {location}", TextAnchor.MiddleCenter);
                i++;
            }
        }
        private void InspectorPanel(BasePlayer player) {
            CuiHelper.DestroyUi(player, PanelInspector);
            if (!CSUIInfo.ContainsKey(player.userID)) return;
            CuiElementContainer element = null;
            var i = 0;
            var money = 0;
            if (ServerRewards && CheckPoints(player.userID) is int) money = (int)CheckPoints(player.userID);
            else if (Economics) money = Convert.ToInt32(Economics.CallHook("GetPlayerMoney", player.userID));
            string set;
            element = UI.CreateOverlayContainer(PanelInspector, "0 0 0 0", "0.705 0.2", "0.86 0.68");
            UI.CreateTextOutline(ref element, PanelInspector, UIColors["white"], UIColors["black"], GetMSG("ITEM", player), 22, "0 0.91", "1.99");
            if (CSUIInfo[player.userID].InspectedGear != -1 && !string.IsNullOrEmpty(CSUIInfo[player.userID].location)) if (NewSet.ContainsKey(player.userID) && CSUIInfo[player.userID].admin) {
                var cont = NewSet[player.userID].set.main;
                if (CSUIInfo[player.userID].location == "belt") cont = NewSet[player.userID].set.belt;
                else if (CSUIInfo[player.userID].location == "wear") cont = NewSet[player.userID].set.wear;
                if (cont[CSUIInfo[player.userID].InspectedGear] == null) return;
                var item = cont[CSUIInfo[player.userID].InspectedGear];
                UI.LoadImage(ref element, PanelInspector, TryForImage(item.shortname, item.skin), $".05.24", $".95.76");
                if (item.attachments.Count == 0 || string.IsNullOrEmpty(CSUIInfo[player.userID].InspectedAttachment)) {
                    UI.CreateTextOutline(ref element, PanelInspector, UIColors["white"], UIColors["black"], item.displayName, 18, "0 0.81", "1.89");
                    if (ItemSkins.ContainsKey(item.shortname) && ItemSkins[item.shortname].Count() > 1) UI.CreateButton(ref element, PanelInspector, UIColors["black"], $"<color=#F56201>{GetMSG("SetSkin", player)}</color>", 12, $".27.77", $".73.81", $"UI_AddItemAttributes");
                }
                if (item.attachments.Count > 0) {
                    UI.CreateTextOutline(ref element, PanelInspector, UIColors["white"], UIColors["black"], GetMSG("ATTACHMENTS"), 16, "0 0.15", "1.21", TextAnchor.UpperCenter);
                    foreach (var entry in item.attachments) {
                        var pos = AttachmentInspectorPos(i);
                        UI.LoadImage(ref element, PanelInspector, TryForImage(entry, 0), $"{pos[0]} {pos[1]}", $"{pos[2]} {pos[3]}");
                        if (CSUIInfo[player.userID].InspectedAttachment == entry) {
                            UI.CreateTextOutline(ref element, PanelInspector, UIColors["white"], UIColors["black"], GetDisplayNameFromSN(entry), 18, "0 0.81", "1.89");
                            UI.CreateButton(ref element, PanelInspector, "0 0 0 0", "", 12, $".08.3", $".92.8", $"UI_ChangeSelection clear");
                        }
                        else UI.CreateButton(ref element, PanelInspector, "0 0 0 0", "", 12, $"{pos[0]} {pos[1]}", $"{pos[2]} {pos[3]}", $"UI_ChangeSelection {entry}");
                        i++;
                    }
                }
                UI.LoadImage(ref element, PanelInspector, TryForImage("CS_Remove"), "0.85 0.83", ".97.91");
                UI.CreateButton(ref element, PanelInspector, "0 0 0 0", "", 12, "0.85 0.83", ".97.91", $"UI_RemoveItem");
            }
            else {
                set = CSUIInfo[player.userID].SelectedSet;
                var cont = csData.SavedSets[set].main;
                if (CSUIInfo[player.userID].location == "belt") cont = csData.SavedSets[set].belt;
                else if (CSUIInfo[player.userID].location == "wear") cont = csData.SavedSets[set].wear;
                if (cont[CSUIInfo[player.userID].InspectedGear] == null) return;
                var item = cont[CSUIInfo[player.userID].InspectedGear];
                if (item == null) {
                    CuiHelper.AddUi(player, element);
                    return;
                }
                UI.LoadImage(ref element, PanelInspector, TryForImage(item.shortname, item.skin), $".05.24", $".95.76");
                if (item.attachments.Count == 0 || string.IsNullOrEmpty(CSUIInfo[player.userID].InspectedAttachment)) UI.CreateTextOutline(ref element, PanelInspector, UIColors["white"], UIColors["black"], item.displayName, 18, "0 0.81", "1.89");
                if (item.attachments.Count > 0) {
                    UI.CreateTextOutline(ref element, PanelInspector, UIColors["white"], UIColors["black"], GetMSG("ATTACHMENTS"), 16, "0 0.15", "1.21", TextAnchor.UpperCenter);
                    foreach (var entry in item.attachments) {
                        var pos = AttachmentInspectorPos(i);
                        UI.LoadImage(ref element, PanelInspector, TryForImage(entry, 0), $"{pos[0]} {pos[1]
// ... [Code preview truncated due to length. Full source in attached file] ...

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