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

FREE TPKit : 1.0.0 1.0.0

Нет прав для скачивания
C#:
using System;
using System.Linq;
using System.Collections.Generic;
using Oxide.Core;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using Newtonsoft.Json;
using UnityEngine;
using System.Globalization;
using System.Collections;
using UnityEngine.Networking;
using System.IO;
namespace Oxide.Plugins {
    [Info("TPKit", "Forum: https://topplugin.ru Ds: alone_sempai", "1.0.0")]
    class TPKit : RustPlugin {
#region Вар
        private static TPKit _;
        private string Layer = "Kit_UI";
        [PluginReference]
        Plugin ImageLibrary;
        Dictionary<ulong, Data> Settings = new Dictionary<ulong, Data>();
        List<BasePlayer> KitOpen = new List<BasePlayer>();
#endregion
#region Класс
        public class KitSet {
            [JsonProperty("Название категории")]
            public string DisplayName;
            [JsonProperty("Описание категории")]
            public string Description;
            [JsonProperty("Картинка категории (url)")]
            public string Url;
            [JsonProperty("Настройки наборов")]
            public List<KitSettings> settings;
        }
        public class KitSettings {
            [JsonProperty("Название набора")]
            public string Name;
            [JsonProperty("Формат названия набора")]
            public string DisplayName;
            [JsonProperty("Название кулдаун набора")]
            public double Cooldown;
            [JsonProperty("Картинка набора (url)")]
            public string Url;
            [JsonProperty("Предметы набора")]
            public List<ItemSettings> Items;
        }
        public class ItemSettings {
            [JsonProperty("Название предмета")]
            public string ShortName;
            [JsonProperty("Количество предмета")]
            public int Amount;
            [JsonProperty("Скин предмета")]
            public ulong SkinID;
            [JsonProperty("Место в инвентаре")]
            public string Container;
            [JsonProperty("Чертеж?")]
            public int Blueprint;
            [JsonProperty("Прочность")]
            public float Condition;
            [JsonProperty("Патроны")]
            public Weapon Weapon;
            [JsonProperty("Содержимое предмета")]
            public List<ItemContent> Content;
        }
        public class Weapon {
            [JsonProperty("Тип патрона")]
            public string AmmoType;
            [JsonProperty("Количество патронов")]
            public int AmmoAmount;
        }
        public class ItemContent {
            [JsonProperty("Название предмета")]
            public string ShortName;
            [JsonProperty("Прочность")]
            public float Condition;
            [JsonProperty("Количество предмета")]
            public int Amount;
        }
        public class Data {
            [JsonProperty("Список наборов и их кулдаун")]
            public Dictionary<string, KitData> SettingsData = new Dictionary<string, KitData>();
        }
        public class KitData {
            [JsonProperty("Кулдаун набора")]
            public double Cooldown;
        }
#endregion
#region Конфиг
        Configuration config;
        class Configuration {
            [JsonProperty("Список категорий и их наборы")]
            public Dictionary<string, KitSet> set = new Dictionary<string, KitSet>();
            public static Configuration GetNewConfig() {
                return new Configuration();
            }
        }
        protected override void LoadConfig() {
            base.LoadConfig();
            try {
                config = Config.ReadObject<Configuration>();
                if (config?.set == null) LoadDefaultConfig();
            }
            catch {
                PrintWarning($"Ошибка чтения конфигурации 'oxide/config/{Name}', создаём новую конфигурацию!!");
                LoadDefaultConfig();
            }
            NextTick(SaveConfig);
        }
        protected override void LoadDefaultConfig() => config = Configuration.GetNewConfig();
        protected override void SaveConfig() => Config.WriteObject(config);
#endregion
#region Хуки
        private void OnServerInitialized() {
            _ = this;
            _imageUI = new ImageUI();
            _imageUI.DownloadImage();
            foreach (var check in config.set) {
                permission.RegisterPermission(check.Key, this);
                ImageLibrary.Call("AddImage", check.Value.Url, check.Value.Url);
                foreach (KitSettings kit in check.Value.settings) ImageLibrary.Call("AddImage", kit.Url, kit.Url);
            }
            foreach (BasePlayer check in BasePlayer.activePlayerList) OnPlayerConnected(check);
        }
        private void OnPlayerConnected(BasePlayer player) => CreateDataBase(player);
        private void OnPlayerDisconnected(BasePlayer player, string reason) => SaveDataBase(player.userID);
        private void Unload() {
            foreach (var check in Settings) SaveDataBase(check.Key);
            foreach (BasePlayer check in BasePlayer.activePlayerList) DestroyUi(check);
            if (_imageUI != null) {
                _imageUI.UnloadImages();
                _imageUI = null;
            }
            _ = null;
        }
#endregion
#region Методы
        KitData GetDataBase(ulong userID, string name) {
            if (!Settings.ContainsKey(userID)) Settings[userID].SettingsData = new Dictionary<string, KitData>();
            if (!Settings[userID].SettingsData.ContainsKey(name)) Settings[userID].SettingsData[name] = new KitData();
            return Settings[userID].SettingsData[name];
        }
        public static string FormatShortTime(TimeSpan time) {
            string result = string.Empty;
            if (time.Days != 0) result = $"{time.Days.ToString("00")}:";
            if (time.Hours != 0) result += $"{time.Hours.ToString("00")}:";
            if (time.Minutes != 0) result += $"{time.Minutes.ToString("00")}:";
            if (time.Seconds != 0) result += $"{time.Seconds.ToString("00")}";
            return result;
        }
        void DestroyUi(BasePlayer player) {
            CuiHelper.DestroyUi(player, Layer);
            KitOpen.Remove(player);
        }
        double CurTime() => new TimeSpan(DateTime.UtcNow.Ticks).TotalSeconds;
#endregion
#region Дата
        void CreateDataBase(BasePlayer player) {
            var DataBase = Interface.Oxide.DataFileSystem.ReadObject<Data>($"TPKit/{player.userID}");
            if (!Settings.ContainsKey(player.userID)) Settings.Add(player.userID, new Data());
            Settings[player.userID] = DataBase ?? new Data();
        }
        void SaveDataBase(ulong userId) => Interface.Oxide.DataFileSystem.WriteObject($"TPKit/{userId}", Settings[userId]);
#endregion
#region Создание наборов
        void CreateKit(BasePlayer player, string perm, string name) {
            var check = $"tpkit.{perm}";
            if (!config.set.ContainsKey(check)) {
                config.set.Add(check, new KitSet() {
                    DisplayName = "Название", Description = "Категория", Url = "https://i.imgur.com/yYchbX4.png", settings = new List<KitSettings>()
                }
                );
            }
            if (config.set.Values.Any(p => p.settings.Exists(z => z.Name == name))) {
                player.ConsoleMessage($"Набор {name} уже существует!");
                return;
            }
            if (config.set[check].settings.Count >= 5) {
                player.ConsoleMessage($"Вы уже добавили в категорию {check} максимальное количество наборов!");
                return;
            }
            config.set[check].settings.Add(new KitSettings() {
                Name = name, DisplayName = name, Cooldown = 600, Url = "https://i.imgur.com/yYchbX4.png", Items = GetItems(player)
            }
            );
            permission.RegisterPermission(check, this);
            SaveConfig();
            player.ConsoleMessage($"Вы успешно создали набор {name}");
        }
        List<ItemSettings> GetItems(BasePlayer player) {
            List<ItemSettings> kititems = new List<ItemSettings>();
            foreach (Item item in player.inventory.containerWear.itemList) {
                if (item != null) {
                    var iteminfo = CreateItem(item, "Одежда");
                    kititems.Add(iteminfo);
                }
            }
            foreach (Item item in player.inventory.containerMain.itemList) {
                if (item != null) {
                    var iteminfo = CreateItem(item, "Рюкзак");
                    kititems.Add(iteminfo);
                }
            }
            foreach (Item item in player.inventory.containerBelt.itemList) {
                if (item != null) {
                    var iteminfo = CreateItem(item, "Пояс");
                    kititems.Add(iteminfo);
                }
            }
            return kititems;
        }
        ItemSettings CreateItem(Item item, string container) {
            ItemSettings items = new ItemSettings();
            items.ShortName = item.info.shortname;
            items.Amount = item.amount;
            items.SkinID = item.skin;
            items.Container = container;
            items.Blueprint = item.blueprintTarget;
            items.Condition = item.condition;
            items.Weapon = null;
            items.Content = null;
            if (item.info.category == ItemCategory.Weapon) {
                BaseProjectile weapon = item.GetHeldEntity() as BaseProjectile;
                if (weapon != null) {
                    items.Weapon = new Weapon();
                    items.Weapon.AmmoType = weapon.primaryMagazine.ammoType.shortname;
                    items.Weapon.AmmoAmount = weapon.primaryMagazine.contents;
                }
            }
            if (item.contents != null) {
                items.Content = new List<ItemContent>();
                foreach (var cont in item.contents.itemList) {
                    items.Content.Add(new ItemContent() {
                        Amount = cont.amount, Condition = cont.condition, ShortName = cont.info.shortname
                    }
                    );
                }
            }
            return items;
        }
#endregion
#region Выдача наборов
        Item GetItem(string ShortName, int Amount, ulong SkinID, int Blueprint, float Condition, Weapon weapon, List<ItemContent> Content) {
            Item item = ItemManager.CreateByName(ShortName, Amount, SkinID);
            if (Blueprint != 0) item.blueprintTarget = Blueprint;
            item.condition = Condition;
            if (weapon != null) {
                (item.GetHeldEntity() as BaseProjectile).primaryMagazine.contents = weapon.AmmoAmount;
                (item.GetHeldEntity() as BaseProjectile).primaryMagazine.ammoType = ItemManager.FindItemDefinition(weapon.AmmoType);
            }
            if (Content != null) {
                foreach (var cont in Content) {
                    Item new_cont = ItemManager.CreateByName(cont.ShortName, cont.Amount);
                    new_cont.condition = cont.Condition;
                    new_cont.MoveToContainer(item.contents);
                }
            }
            return item;
        }
        void SetItem(BasePlayer player, Item item, string container) {
            if (item == null) return;
            var cont = container == "Пояс" ? player.inventory.containerBelt : container == "Одежда" ? player.inventory.containerWear : player.inventory.containerMain;
            var moved = item.MoveToContainer(cont) || item.MoveToContainer(player.inventory.containerMain);
            if (!moved) {
                if (player.inventory.containerBelt == cont) moved = item.MoveToContainer(player.inventory.containerWear);
                if (player.inventory.containerWear == cont) moved = item.MoveToContainer(player.inventory.containerBelt);
            }
            if (!moved) item.Drop(player.GetCenter(), player.GetDropVelocity());
        }
#endregion
#region Команды
        [ChatCommand("kit")]
        void ChatKit(BasePlayer player, string command, string[] args) {
            if (KitOpen.Contains(player)) {
                DestroyUi(player);
                return;
            }
            else {
                KitUI(player);
                return;
            }
        }
        [ConsoleCommand("kit")]
        void ConsoleKit(ConsoleSystem.Arg args) {
            var Time = CurTime();
            var player = args.Player();
            if (player != null && args.HasArgs(1)) {
                if (args.Args[0] == "new") {
                    if (!player.IsAdmin) return;
                    if (args.Args.Length < 3) {
                        player.ConsoleMessage("Используйте: kit new [название пермишена] [название набора]");
                        return;
                    }
                    CreateKit(player, args.Args[1], args.Args[2]);
                }
                if (args.Args[0] == "cremove") {
                    if (!player.IsAdmin) return;
                    if (args.Args.Length < 2) {
                        player.ConsoleMessage("Используйте: kit cremove [название пермишена]");
                        return;
                    }
                    if (config.set.ContainsKey($"tpkit.{args.Args[1]}")) {
                        config.set.Remove($"tpkit.{args.Args[1]}");
                        player.ConsoleMessage($"Вы успешно удали всю категорию пермишена {args.Args[1]}!");
                        SaveConfig();
                    }
                }
                if (args.Args[0] == "remove") {
                    if (!player.IsAdmin) return;
                    if (args.Args.Length < 2) {
                        player.ConsoleMessage("Используйте: kit remove [название набора]");
                        return;
                    }
                    if (!config.set.Values.Any(z => z.settings.RemoveAll(z => z.Name == args.Args[1]) <= 0)) {
                        config.set.Remove($"tpkit.{args.Args[1]}");
                        player.ConsoleMessage($"Набор {args.Args[1]} успешно удален!");
                        SaveConfig();
                    }
                    SaveConfig();
                }
                if (args.Args[0] == "ui") {
                    DestroyUi(player);
                }
                if (args.Args[0] == "infoCategory") {
                    DescriptionUI(player, args.Args[1]);
                }
                if (args.Args[0] == "category") {
                    CategoryUI(player, args.Args[1]);
                    DescriptionUI(player, args.Args[1]);
                    KitListUI(player, args.Args[1]);
                }
                if (args.Args[0] == "info") {
                    KitInfoUI(player, args.Args[1], args.Args[2]);
                }
                if (args.Args[0] == "take") {
                    var perm = config.set.FirstOrDefault(z => z.Key == args.Args[1]);
                    var check = perm.Value.settings.FirstOrDefault(z => z.Name == args.Args[2]);
                    if (!permission.UserHasPermission(player.UserIDString, perm.Key)) {
                        player.ChatMessage("Чтобы получить этот набор, сначала купите соответствующую привилегию в нашем магазине!");
                        return;
                    }
                    if (player.inventory.containerMain.itemList.Count >= 24) {
                        player.SendConsoleCommand($"note.inv 605467368 -1 \"Недостаточно места\"");
                        return;
                    }
                    var db = GetDataBase(player.userID, check.Name);
                    if (check.Cooldown > 0) {
                        if (db.Cooldown > Time) {
                            player.SendConsoleCommand("<size=12>Ахахахахахах, а вот и хуй тебе\nЖди кулдаун сука!</size>");
                            return;
                        }
                        db.Cooldown = Time + check.Cooldown;
                    }
                    foreach (var item in check.Items) {
                        SetItem(player, GetItem(item.ShortName, item.Amount, item.SkinID, item.Blueprint, item.Condition, item.Weapon, item.Content), item.Container);
                    }
                    KitListUI(player, perm.Key);
                    CuiHelper.DestroyUi(player, ".Kit_Info");
                    player.SendConsoleCommand($"note.inv 605467368 1 \"НАБОР ПОЛУЧЕН\"");
                    Effect x = new Effect("assets/bundled/prefabs/fx/notice/stack.world.fx.prefab", player, 0, new Vector3(), new Vector3());
                    EffectNetwork.Send(x, player.Connection);
                }
            }
        }
#endregion
#region Интерфейс
        private void KitUI(BasePlayer player) {
            CuiHelper.DestroyUi(player, Layer);
            KitOpen.Add(player);
            CuiElementContainer container = new CuiElementContainer();
            container.Add(new CuiPanel {
                CursorEnabled = true, RectTransform = {
                    AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"
                }
                , Image = {
                    Color = "0 0 0 0.9"
                }
                ,
            }
            , "Overlay", Layer);
            container.Add(new CuiButton {
                RectTransform = {
                    AnchorMin = "1 1", AnchorMax = "1 1", OffsetMin = "-100 -45", OffsetMax = "-10 -13"
                }
                , Button = {
                    Command = "kit ui", Color = "0 0 0 0"
                }
            }
            , Layer, "Close");
            container.Add(new CuiElement {
                Parent = "Close", Components = {
                    new CuiRawImageComponent {
                        Png = _imageUI.GetImage("BACKGROUND_CLOSE"), FadeIn = 1f
                    }
                    , new CuiRectTransformComponent {
                        AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"
                    }
                }
            }
            );
            container.Add(new CuiLabel {
                RectTransform = {
                    AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"
                }
                , Text = {
                    Text = "Закрыть", FontSize = 16, Align = TextAnchor.MiddleCenter, Color = HexToCuiColor("#DADADA", 100), Font = "robotocondensed-regular.ttf"
                }
                ,
            }
            , "Close");
            container.Add(new CuiPanel {
                RectTransform = {
                    AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-300 -200", OffsetMax = "300 200"
                }
                , Image = {
                    Color = "0 0 0 0"
                }
                ,
            }
            , Layer, "Interface");
            if (config.set.Count() == 0) {
                container.Add(new CuiLabel {
                    RectTransform = {
                        AnchorMin = "0 0.1", AnchorMax = "1 0.9", OffsetMax = "0 0"
                    }
                    , Text = {
                        Text = $"<b><size=60><color=#cec5bb>Наборы</color></size></b>\nНа данный момент, Вы не настроили ни одного набора.\nЧтобы закрыть меню наборов, щелкните по свободному месту!", Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf", Color = "1 1 1 0.2", FontSize = 14
                    }
                }
                , Layer);
                CuiHelper.AddUi(player, container);
            }
            else {
                container.Add(new CuiPanel {
                    RectTransform = {
                        AnchorMin = "0.4 0.355", AnchorMax = "0.6 0.655", OffsetMax = "0 0"
                    }
                    , Image = {
                        Color = "0 0 0 0"
                    }
                    ,
                }
                , "Interface", "Center");
                container.Add(new CuiElement {
                    Parent = "Center", Components = {
                        new CuiRawImageComponent {
                            Png = _imageUI.GetImage("BACKGROUND_CENTER"), FadeIn = 1f
                        }
                        , new CuiRectTransformComponent {
                            AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"
                        }
                    }
                }
                );
                container.Add(new CuiElement {
                    Parent = "Center", Components = {
                        new CuiRawImageComponent {
                            Png = _imageUI.GetImage("ICON_POCKET"), FadeIn = 1f
                        }
                        , new CuiRectTransformComponent {
                            AnchorMin = "0.38 0.52", AnchorMax = "0.62 0.77", OffsetMax = "0 0"
                        }
                    }
                }
                );
                CuiHelper.AddUi(player, container);
                DescriptionUI(player, "");
                var firstCategoryKey = config.set.ElementAt(0).Key;
                CategoryUI(player, firstCategoryKey);
                KitListUI(player, firstCategoryKey);
            }
        }
        private void DescriptionUI(BasePlayer player, string name) {
            CuiHelper.DestroyUi(player, "Description");
            CuiElementContainer container = new CuiElementContainer();
            var description = name != "" ? config.set.FirstOrDefault(p => p.Key == name).Value.Description : "Выберите нужную вам категорию, затем набор и заберите его.";
            container.Add(new CuiLabel {
                RectTransform = {
                    AnchorMin = "0.04 0.1", AnchorMax = "0.96 0.6", OffsetMax = "0 0"
                }
                , Text = {
                    Text = description, FontSize = 9, Align = TextAnchor.MiddleCenter, Color = HexToCuiColor("#DADADA"), Font = "robotocondensed-regular.ttf"
                }
                ,
            }
            , "Center", "Description");
            CuiHelper.AddUi(player, container);
        }
        private void CategoryUI(BasePlayer player, string name) {
            CuiHelper.DestroyUi(player, "Categorys");
            CuiElementContainer container = new CuiElementContainer();
            var set = config.set.ToList();
            container.Add(new CuiPanel {
                RectTransform = {
                    AnchorMin = "0.5 0", AnchorMax = "1 1", OffsetMax = "0 0"
                }
                , Image = {
                    Color = "0 0 0 0"
                }
                ,
            }
            , "Interface", "Categorys");
            float width = 0.67f, height = 0.1f, startxBox = 0.095f, startyBox = 0.813f - height, xmin = startxBox, ymin = startyBox;
            foreach (var i in Enumerable.Range(0, 5)) {
                if (i >= 1 && i <= 3) {
                    xmin += 0.2f;
                }
                container.Add(new CuiPanel {
                    RectTransform = {
                        AnchorMin = $"{xmin} {ymin}", AnchorMax = $"{xmin + width} {ymin + height * 1}", OffsetMax = "0 0"
                    }
                    , Image = {
                        Color = "0 0 0 0"
                    }
                }
                , "Categorys", "Category");
                xmin += width;
                if (xmin + width >= 0) {
                    xmin = startxBox;
                    ymin -= height + 0.03f;
                }
                var category = set.ElementAtOrDefault(i);
                string color = category.Key != null ? "1 1 1 1" : "1 1 1 0.1";
                container.Add(new CuiElement {
                    Name = "IconCategory", Parent = "Category", Components = {
                        new CuiRawImageComponent {
                            Png = _imageUI.GetImage("BACKGROUND_ICON"), FadeIn = 1f, Color = color
                        }
                        , new CuiRectTransformComponent {
                            AnchorMin = "0 0", AnchorMax = "0.22 1", OffsetMax = "0 0"
                        }
                    }
                }
                );
                container.Add(new CuiElement {
                    Name = "NameCategory", Parent = "Category", Components = {
                        new CuiRawImageComponent {
                            Png = _imageUI.GetImage("BACKGROUND_INFO"), FadeIn = 1f, Color = color
                        }
                        , new CuiRectTransformComponent {
                            AnchorMin = "0.25 0", AnchorMax = "0.75 1", OffsetMax = "0 0"
                        }
                    }
                }
                );
                container.Add(new CuiElement {
                    Name = "IconInfo", Parent = "Category", Components = {
                        new CuiRawImageComponent {
                            Png = _imageUI.GetImage("BACKGROUND_ICON"), FadeIn = 1f, Color = color
                        }
                        , new CuiRectTransformComponent {
                            AnchorMin = "0.78 0", AnchorMax = "1 1", OffsetMax = "0 0"
                        }
                    }
                }
                );
                if (category.Key != null) {
                    container.Add(new CuiElement {
                        Parent = "IconCategory", Components = {
                            new CuiRawImageComponent {
                                Png = (string)ImageLibrary.Call("GetImage", category.Value.Url), Color = "1 1 1 1"
                            }
                            , new CuiRectTransformComponent {
                                AnchorMin = "0 0", AnchorMax = $"1 1", OffsetMin = "6 6", OffsetMax = "-6 -6"
                            }
                            ,
                        }
                    }
                    );
                    container.Add(new CuiLabel {
                        RectTransform = {
                            AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"
                        }
                        , Text = {
                            Text = category.Value.DisplayName.ToUpper(), Align = TextAnchor.MiddleCenter, Font = "robotocondensed-bold.ttf", Color = HexToCuiColor("#DADADA", 100), FontSize = 12
                        }
                    }
                    , "NameCategory");
                    if (category.Key == name) {
                        container.Add(new CuiElement {
                            Parent = "NameCategory", Components = {
                                new CuiRawImageComponent {
                                    Png = _imageUI.GetImage("ICON_ACTIVE"), FadeIn = 1f
                                }
                                , new CuiRectTransformComponent {
                                    AnchorMin = "-0.04 0.15", AnchorMax = "0.07 0.85", OffsetMax = "0 0"
                                }
                            }
                        }
                        );
                    }
                    container.Add(new CuiButton {
                        RectTransform = {
                            AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"
                        }
                        , Button = {
                            Color = "0 0 0 0", Command = $"kit category {category.Key}"
                        }
                    }
                    , "NameCategory");
                    container.Add(new CuiElement {
                        Parent = "IconInfo", Components = {
                            new CuiRawImageComponent {
                                Png = _imageUI.GetImage("ICON_INFO"), FadeIn = 1f, Color = color
                            }
                            , new CuiRectTransformComponent {
                                AnchorMin = "0 0", AnchorMax = "1 1", OffsetMin = "9.3 9", OffsetMax = "-9.3 -9"
                            }
                        }
                    }
                    );
                    container.Add(new CuiButton {
                        RectTransform = {
                            AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"
                        }
                        , Button = {
                            Color = "0 0 0 0", Command = $"kit infoCategory {category.Key}"
                        }
                    }
                    , "IconInfo");
                }
            }
            CuiHelper.AddUi(player, container);
        }
        private void KitListUI(BasePlayer player, string category) {
            CuiHelper.DestroyUi(player, "KitList");
            CuiElementContainer container = new CuiElementContainer();
            var set = config.set.ToList();
            container.Add(new CuiPanel {
                RectTransform = {
                    AnchorMin = "0 0", AnchorMax = "0.5 1", OffsetMax = "0 0"
                }
                , Image = {
                    Color = "0 0 0 0"
                }
                ,
            }
            , "Interface", "KitList");
            float width = 0.67f, height = 0.1f, startxBox = 0.235f, startyBox = 0.813f - height, xmin = startxBox, ymin = startyBox;
            foreach (var i in Enumerable.Range(0, 5)) {
                if (i >= 1 && i <= 3) {
                    xmin -= 0.2f;
                }
                container.Add(new CuiPanel {
                    RectTransform = {
                        AnchorMin = $"{xmin} {ymin}", AnchorMax = $"{xmin + width} {ymin + height * 1}", OffsetMax = "0 0"
                    }
                    , Image = {
                        Color = "0 0 0 0"
                    }
                }
                , "KitList", "Kit");
                xmin += width;
                if (xmin + width >= 0) {
                    xmin = startxBox;
                    ymin -= height + 0.03f;
                }
                var kits = set.FirstOrDefault(p => p.Key == category).Value.settings.ElementAtOrDefault(i);
                string color = kits != null ? "1 1 1 1" : "1 1 1 0.1";
                container.Add(new CuiElement {
                    Name = "IconKit", Parent = "Kit", Components = {
                        new CuiRawImageComponent {
                            Png = _imageUI.GetImage("BACKGROUND_ICON"), FadeIn = 1f, Color = color
                        }
                        , new CuiRectTransformComponent {
                            AnchorMin = "0 0", AnchorMax = "0.22 1", OffsetMax = "0 0"
                        }
                    }
                }
                );
                container.Add(new CuiElement {
                    Name = "NameKit", Parent = "Kit", Components = {
                        new CuiRawImageComponent {
                            Png = _imageUI.GetImage("BACKGROUND_INFO"), FadeIn = 1f, Color = color
                        }
                        , new CuiRectTransformComponent {
                            AnchorMin = "0.25 0", AnchorMax = "0.75 1", OffsetMax = "0 0"
                        }
                    }
                }
                );
                container.Add(new CuiElement {
                    Name = "IconInfo", Parent = "Kit", Components = {
                        new CuiRawImageComponent {
                            Png = _imageUI.GetImage("BACKGROUND_ICON"), FadeIn = 1f, Color = color
                        }
                        , new CuiRectTransformComponent {
                            AnchorMin = "0.78 0", AnchorMax = "1 1", OffsetMax = "0 0"
                        }
                    }
                }
                );
                if (kits != null) {
                    container.Add(new CuiElement {
                        Parent = "IconKit", Components = {
                            new CuiRawImageComponent {
                                Png = (string)ImageLibrary.Call("GetImage", kits.Url), Color = "1 1 1 1"
                            }
                            , new CuiRectTransformComponent {
                                AnchorMin = "0 0", AnchorMax = $"1 1", OffsetMin = "6 6", OffsetMax = "-6 -6"
                            }
                            ,
                        }
                    }
                    );
                    container.Add(new CuiLabel {
                        RectTransform = {
                            AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"
                        }
                        , Text = {
                            Text = kits.DisplayName.ToUpper(), Align = TextAnchor.MiddleCenter, Font = "robotocondensed-bold.ttf", Color = HexToCuiColor("#DADADA", 100), FontSize = 12
                        }
                    }
                    , "NameKit");
                    KitData db = GetDataBase(player.userID, kits.Name);
                    double Time = CurTime();
                    bool cooldown = db.Cooldown > 0 && (db.Cooldown > Time);
                    var categoryData = set.FirstOrDefault(p => p.Key == category);
                    bool hasPermission = categoryData.Key != null && permission.UserHasPermission(player.UserIDString, categoryData.Key);
                    bool noPermission = categoryData.Key != null && !permission.UserHasPermission(player.UserIDString, categoryData.Key);
                    string image = (noPermission || cooldown) ? "ICON_NO_ACTIVE" : "ICON_ACTIVE";
                    container.Add(new CuiElement {
                        Parent = "NameKit", Components = {
                            new CuiRawImageComponent {
                                Png = _imageUI.GetImage(image), FadeIn = 1f
                            }
                            , new CuiRectTransformComponent {
                                AnchorMin = "-0.04 0.15", AnchorMax = "0.07 0.85", OffsetMax = "0 0"
                            }
                        }
                    }
                    );
                    if (noPermission) {
                        container.Add(new CuiLabel {
                            RectTransform = {
                                AnchorMin = "0 0", AnchorMax = "1 0.4", OffsetMax = "0 0"
                            }
                            , Text = {
                                Text = "НЕТ ДОСТУПА", Align = TextAnchor.MiddleCenter, Font = "robotocondensed-bold.ttf", Color = HexToCuiColor("#FF1153", 100), FontSize = 9
                            }
                        }
                        , "NameKit");
                        container.Add(new CuiButton {
                            RectTransform = {
                                AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"
                            }
                            , Button = {
                                Color = "0 0 0 0", Command = $"kit take {category} {kits.Name}"
                            }
                        }
                        , "NameKit");
                    }
                    else if (cooldown) {
                        container.Add(new CuiLabel {
                            RectTransform = {
                                AnchorMin = "0 0", AnchorMax = "1 0.4", OffsetMax = "0 0"
                            }
                            , Text = {
                                Text = $"{FormatShortTime(TimeSpan.FromSeconds(db.Cooldown - Time))}", Align = TextAnchor.MiddleCenter, Font = "robotocondensed-bold.ttf", Color = HexToCuiColor("#FF1153", 100), FontSize = 9
                            }
                        }
                        , "NameKit");
                    }
                    else {
                        container.Add(new CuiButton {
                            RectTransform = {
                                AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"
                            }
                            , Button = {
                                Color = "0 0 0 0", Command = $"kit take {category} {kits.Name}"
                            }
                        }
                        , "NameKit");
                    }
                    container.Add(new CuiElement {
                        Parent = "IconInfo", Components = {
                            new CuiRawImageComponent {
                                Png = _imageUI.GetImage("ICON_INFO"), FadeIn = 1f, Color = color
                            }
                            , new CuiRectTransformComponent {
                                AnchorMin = "0 0", AnchorMax = "1 1", OffsetMin = "9.3 9", OffsetMax = "-9.3 -9"
                            }
                        }
                    }
                    );
                    container.Add(new CuiButton {
                        RectTransform = {
                            AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"
                        }
                        , Button = {
                            Color = "0 0 0 0", Command = $"kit info {category} {kits.Name}"
                        }
                    }
                    , "IconInfo");
                }
            }
            CuiHelper.AddUi(player, container);
        }
        void KitInfoUI(BasePlayer player, string perm, string name) {
            CuiHelper.DestroyUi(player, ".Kit_Info");
            var container = new CuiElementContainer();
            container.Add(new CuiPanel {
                CursorEnabled = true, RectTransform = {
                    AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"
                }
                , Image = {
                    Color = "0 0 0 0.9"
                }
                ,
            }
            , Layer, ".Kit_Info");
            container.Add(new CuiPanel {
                RectTransform = {
                    AnchorMin = "0 0", AnchorMax = "1 1"
                }
                , Image = {
                    Color = "0 0 0 0.23", Material = "assets/content/ui/uibackgroundblur.mat"
                }
            }
            , ".Kit_Info");
            container.Add(new CuiPanel {
                RectTransform = {
                    AnchorMin = "0 0", AnchorMax = "1 1"
                }
                , Image = {
                    Sprite = "assets/content/ui/ui.background.transparent.radial.psd", Color = HexToCuiColor("#363636", 30)
                }
            }
            , ".Kit_Info");
            container.Add(new CuiPanel {
                RectTransform = {
                    AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-220 -190", OffsetMax = "220 210"
                }
                , Image = {
                    Color = "0 0 0 0"
                }
            }
            , ".Kit_Info", ".Info");
            container.Add(new CuiPanel {
                RectTransform = {
                    AnchorMin = "0 0.938", AnchorMax = "1 1", OffsetMax = "0 0"
                }
                , Image = {
                    Color = "0 0 0 0"
                }
            }
            , ".Info", ".Title");
            var check = config.set.FirstOrDefault(z => z.Key == perm).Value;
            var item = check.settings.FirstOrDefault(z => z.Name == name);
            container.Add(new CuiLabel {
                RectTransform = {
                    AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"
                }
                , Text = {
                    Text = $"НАБОР: {item.DisplayName.ToUpper()}", Align = TextAnchor.MiddleCenter, Font = "robotocondensed-bold.ttf", Color = HexToCuiColor("#DADADA", 100), FontSize = 16
                }
            }
            , ".Title");
            var itemMain = item.Items.FindAll(z => z.Container == "Рюкзак");
            float width = 0.1262f, height = 0.13f, startxBox = 0.09f, startyBox = 0.925f - height, xmin = startxBox, ymin = startyBox;
            foreach (var i in Enumerable.Range(0, 24)) {
                container.Add(new CuiPanel {
                    RectTransform = {
                        AnchorMin = $"{xmin} {ymin}", AnchorMax = $"{xmin + width} {ymin + height * 1}", OffsetMax = "0 0"
                    }
                    , Image = {
                        Color = "0 0 0 0"
                    }
                }
                , ".Info", ".Main");
                xmin += width + 0.008f;
                if (xmin + width >= 1) {
                    xmin = startxBox;
                    ymin -= height + 0.008f;
                }
                container.Add(new CuiElement {
                    Parent = ".Main", Components = {
                        new CuiRawImageComponent {
                            Png = _imageUI.GetImage("BACKGROUND_ITEM"), FadeIn = 1f, Color = "1 1 1 1"
                        }
                        , new CuiRectTransformComponent {
                            AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"
                        }
                    }
                }
                );
                var items = itemMain.ElementAtOrDefault(i);
                if (items != null) {
                    container.Add(new CuiElement {
                        Parent = ".Main", Components = {
                            new CuiImageComponent {
                                ItemId = ItemManager.FindItemDefinition(items.ShortName).itemid, SkinId = items.SkinID
                            }
                            , new CuiRectTransformComponent {
                                AnchorMin = "0 0", AnchorMax = "1 1", OffsetMin = "7 7", OffsetMax = "-7 -7"
                            }
                            ,
                        }
                    }
                    );
                    container.Add(new CuiLabel {
                        RectTransform = {
                            AnchorMin = "0 0.003", AnchorMax = "0.9 0.28", OffsetMax = "0 0"
                        }
                        , Text = {
                            Text = $"x{items.Amount}", Align = TextAnchor.MiddleRight, Font = "robotocondensed-regular.ttf", Color = HexToCuiColor("#DADADA", 100), FontSize = 10
                        }
                    }
                    , ".Main");
                }
            }
            var itemWear = item.Items.FindAll(z => z.Container == "Одежда");
            float width1 = 0.1262f, height1 = 0.13f, startxBox1 = 0.09f, startyBox1 = 0.35f - height1, xmin1 = startxBox1, ymin1 = startyBox1;
            foreach (var i in Enumerable.Range(0, 6)) {
                container.Add(new CuiPanel {
                    RectTransform = {
                        AnchorMin = $"{xmin1} {ymin1}", AnchorMax = $"{xmin1 + width1} {ymin1 + height1 * 1}", OffsetMax = "0 0"
                    }
                    , Image = {
                        Color = "0 0 0 0"
                    }
                }
                , ".Info", ".Wear");
                xmin1 += width1 + 0.008f;
                container.Add(new CuiElement {
                    Parent = ".Wear", Components = {
                        new CuiRawImageComponent {
                            Png = _imageUI.GetImage("BACKGROUND_ITEM"), FadeIn = 1f, Color = "1 1 1 1"
                        }
                        , new CuiRectTransformComponent {
                            AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"
                        }
                    }
                }
                );
                var items = itemWear.ElementAtOrDefault(i);
                if (items != null) {
                    container.Add(new CuiElement {
                        Parent = ".Wear", Components = {
                            new CuiImageComponent {
                                ItemId = ItemManager.FindItemDefinition(items.ShortName).itemid, SkinId = items.SkinID
                            }
                            , new CuiRectTransformComponent {
                                AnchorMin = "0 0", AnchorMax = "1 1", OffsetMin = "7 7", OffsetMax = "-7 -7"
                            }
                            ,
                        }
                    }
                    );
                    container.Add(new CuiLabel {
                        RectTransform = {
                            AnchorMin = "0 0.003", AnchorMax = "0.9 0.28", OffsetMax = "0 0"
                        }
                        , Text = {
                            Text = $"x{items.Amount}", Align = TextAnchor.MiddleRight, Font = "robotocondensed-regular.ttf", Color = HexToCuiColor("#DADADA", 100), FontSize = 10
                        }
                    }
                    , ".Wear");
                }
            }
            var itemBelt = item.Items.FindAll(z => z.Container == "Пояс");
            float width2 = 0.1262f, height2 = 0.13f, startxBox2 = 0.09f, startyBox2 = 0.19f - height2, xmin2 = startxBox2, ymin2 = startyBox2;
            foreach (var i in Enumerable.Range(0, 6)) {
                container.Add(new CuiPanel {
                    RectTransform = {
                        AnchorMin = $"{xmin2} {ymin2}", AnchorMax = $"{xmin2 + width2} {ymin2 + height2 * 1}", OffsetMax = "0 0"
                    }
                    , Image = {
                        Color = "0 0 0 0"
                    }
                }
                , ".Info", ".Belt");
                xmin2 += width2 + 0.008f;
                container.Add(new CuiElement {
                    Parent = ".Belt", Components = {
                        new CuiRawImageComponent {
                            Png = _imageUI.GetImage("BACKGROUND_ITEM"), FadeIn = 1f, Color = "1 1 1 1"
                        }
                        , new CuiRectTransformComponent {
                            AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"
                        }
                    }
                }
                );
                var items = itemBelt.ElementAtOrDefault(i);
                if (items != null) {
                    container.Add(new CuiElement {
                        Parent = ".Belt", Components = {
                            new CuiImageComponent {
                                ItemId = ItemManager.FindItemDefinition(items.ShortName).itemid, SkinId = items.SkinID
                            }
                            , new CuiRectTransformComponent {
                                AnchorMin = "0 0", AnchorMax = "1 1", OffsetMin = "7 7", OffsetMax = "-7 -7"
                            }
                            ,
                        }
                    }
                    );
                    container.Add(new CuiLabel {
                        RectTransform = {
                            AnchorMin = "0 0.003", AnchorMax = "0.9 0.28", OffsetMax = "0 0"
                        }
                        , Text = {
                            Text = $"x{items.Amount}", Align = TextAnchor.MiddleRight, Font = "robotocondensed-regular
// ... [Code preview truncated due to length. Full source in attached file] ...

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