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

FREE Case : 1.3.0 1.3.0

Нет прав для скачивания
C#:
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Newtonsoft.Json;
using Oxide.Core;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using UnityEngine;
namespace Oxide.Plugins {
    [Info("Case", "Chibubrik", "1.3.0")]
    class Case : RustPlugin {
#region Вар
        private string Layer = "Case_UI";
        private string LayerCaseInfo = "CaseInfo";
        private string LayerInventory = "Inventory_UI";
        private string LayerReward = "Reward_UI";
        [PluginReference]
        private Plugin ImageLibrary, XpSystem;
        private Dictionary<ulong, PlayerInventory> PlayerInventories;
#endregion
#region Класс
        private static Case inst;
        public class CaseSetting {
            [JsonProperty("Название кейса")]
            public string DisplayName;
            [JsonProperty("Цена кейса")]
            public float Price;
            [JsonProperty("Ссылка на изображение кейса")]
            public string Url;
            [JsonProperty("Список предметов (выбирается случайно)")]
            public List<ItemSettings> itemSettings;
        }
        public class ItemSettings {
            [JsonProperty("Название предмета или услуги")]
            public string Name;
            [JsonProperty("Короткое название предмета")]
            public string ShortName;
            [JsonProperty("Минимальное количество при выпадени")]
            public int AmountMin;
            [JsonProperty("Максимальное Количество при выпадени")]
            public int AmountMax;
            [JsonProperty("Дополнительная команда")]
            public string Command;
            [JsonProperty("Ссылка на изображение")]
            public string Url;
            public int GetRandomAmount() => Core.Random.Range(AmountMin, AmountMax);
        }
        private class InventoryItem {
            [JsonProperty("Название предмета или услуги")]
            public string Name;
            [JsonProperty("Короткое название предмета")]
            public string ShortName;
            [JsonProperty("Количество предметов")]
            public int Amount;
            [JsonProperty("Дополнительная команда")]
            public string Command;
            [JsonProperty("Ссылка на изображение")]
            public string Url;
            public Item GiveItem(BasePlayer player) {
                if (!string.IsNullOrEmpty(Command)) inst.Server.Command(Command.Replace("%STEAMID%", player.UserIDString));
                if (!string.IsNullOrEmpty(ShortName)) {
                    Item item = ItemManager.CreateByPartialName(ShortName, Amount);
                    return item;
                }
                return null;
            }
            public static InventoryItem Generate(ItemSettings itemSettings) {
                return new InventoryItem {
                    Name = itemSettings.Name, ShortName = itemSettings.ShortName, Amount = itemSettings.GetRandomAmount(), Command = itemSettings.Command, Url = itemSettings.Url
                }
                ;
            }
        }
        private class PlayerInventory {
            [JsonProperty("Список вещей")]
            public List<InventoryItem> Inventory = new List<InventoryItem>();
        }
#endregion
#region Конфиг
        public Configuration config;
        public class Configuration {
            [JsonProperty("Список кейсов")]
            public List<CaseSetting> cases;
            public static Configuration GetNewCong() {
                return new Configuration {
                    cases = new List<CaseSetting> {
                        new CaseSetting {
                            DisplayName = "Компонентный кейс", Price = 10f, Url = "https://imgur.com/zIlBl7u.png", itemSettings = new List<ItemSettings> {
                                new ItemSettings {
                                    Name = "Шестеренки", ShortName = "gears", AmountMin = 5, AmountMax = 20, Command = null, Url = null
                                }
                                , new ItemSettings {
                                    Name = "Вип на 3 дня", ShortName = null, AmountMin = 1, AmountMax = 1, Command = "o.grant user %STEAMID% vip", Url = "https://imgur.com/rfg3RRS.png"
                                }
                                ,
                            }
                        }
                        , new CaseSetting {
                            DisplayName = "Ресурсный кейс", Price = 15f, Url = "https://imgur.com/5wxGsUp.png", itemSettings = new List<ItemSettings> {
                                new ItemSettings {
                                    Name = "Дерево", ShortName = "wood", AmountMin = 1000, AmountMax = 10000, Command = null, Url = null
                                }
                                ,
                            }
                        }
                        , new CaseSetting {
                            DisplayName = "Оружейный кейс", Price = 20f, Url = "https://imgur.com/nhZsDFD.png", itemSettings = new List<ItemSettings> {
                                new ItemSettings {
                                    Name = "Ак", ShortName = "rifle.ak", AmountMin = 1, AmountMax = 5, Command = null, Url = null
                                }
                                ,
                            }
                        }
                        , new CaseSetting {
                            DisplayName = "Взрывной кейс", Price = 30f, Url = "https://imgur.com/Bau8WLl.png", itemSettings = new List<ItemSettings> {
                                new ItemSettings {
                                    Name = "Ак", ShortName = "rifle.ak", AmountMin = 1, AmountMax = 5, Command = null, Url = null
                                }
                                ,
                            }
                        }
                        , new CaseSetting {
                            DisplayName = "Кейс привилегий", Price = 50f, Url = "https://imgur.com/jq9xsSt.png", itemSettings = new List<ItemSettings> {
                                new ItemSettings {
                                    Name = "Ак", ShortName = "rifle.ak", AmountMin = 1, AmountMax = 5, Command = null, Url = null
                                }
                                ,
                            }
                        }
                        ,
                    }
                }
                ;
            }
        }
        protected override void LoadConfig() {
            base.LoadConfig();
            try {
                config = Config.ReadObject<Configuration>();
                if (config?.cases == null) LoadDefaultConfig();
            }
            catch {
                PrintWarning($"Ошибка чтения конфигурации 'oxide/config/{Name}', создаём новую конфигурацию!!");
                LoadDefaultConfig();
            }
            NextTick(SaveConfig);
        }
        protected override void LoadDefaultConfig() => config = Configuration.GetNewCong();
        protected override void SaveConfig() => Config.WriteObject(config);
#endregion
#region Хуки
        void OnServerInitialized() {
            inst = this;
            foreach (var check in config.cases) {
                ImageLibrary.Call("AddImage", check.Url, check.Url);
                for (var i = 0; i < check.itemSettings.Count();
                i++) {
                    var image = !string.IsNullOrEmpty(check.itemSettings.ElementAt(i).Command) ? check.itemSettings.ElementAt(i).Url : check.itemSettings.ElementAt(i).ShortName;
                    ImageLibrary.Call("AddImage", check.itemSettings.ElementAt(i).Url, image);
                }
            }
            if (Interface.Oxide.DataFileSystem.ExistsDatafile("Case/PlayerInventory")) {
                PlayerInventories = Interface.Oxide.DataFileSystem.ReadObject<Dictionary<ulong, PlayerInventory>>("Case/PlayerInventory");
            }
            else {
                PlayerInventories = new Dictionary<ulong, PlayerInventory>();
            }
            foreach (var check in BasePlayer.activePlayerList) OnPlayerConnected(check);
        }
        void OnPlayerConnected(BasePlayer player) {
            if (!PlayerInventories.ContainsKey(player.userID)) PlayerInventories.Add(player.userID, new PlayerInventory());
        }
        void Unload() {
            foreach (var player in BasePlayer.activePlayerList) {
                CuiHelper.DestroyUi(player, Layer);
                CuiHelper.DestroyUi(player, LayerCaseInfo);
                CuiHelper.DestroyUi(player, LayerInventory);
                CuiHelper.DestroyUi(player, LayerReward);
            }
            SaveData();
        }
        InventoryItem AddItem(BasePlayer player, ItemSettings itemSettings) {
            var item = InventoryItem.Generate(itemSettings);
            PlayerInventories[player.userID].Inventory.Add(item);
            return item;
        }
        void SaveData() {
            Interface.Oxide.DataFileSystem.WriteObject("Case/PlayerInventory", PlayerInventories);
        }
        void OnPlayerDisconnected(BasePlayer player, string reason) {
            SaveData();
        }
#endregion
#region Апдейт
        private void UpdateBalance(BasePlayer player) {
            CuiHelper.DestroyUi(player, "Balance");
            CuiElementContainer container = new CuiElementContainer();
            container.Add(new CuiLabel {
                RectTransform = {
                    AnchorMin = "0 0", AnchorMax = "1 0.04", OffsetMax = "0 0"
                }
                , Text = {
                    Text = $"Ваш баланс: <b>{XpSystem.Call("API_GetBalance", player.userID)}$</b>", Color = "1 1 1 1", Align = TextAnchor.MiddleCenter, FontSize = 14, Font = "robotocondensed-regular.ttf"
                }
            }
            , LayerCaseInfo, "Balance");
            CuiHelper.AddUi(player, container);
        }
#endregion
#region Команды
        [ChatCommand("case")]
        private void cmdCase(BasePlayer player, string command, string[] args, int count) {
            CaseUI(player);
        }
        [ConsoleCommand("case")]
        private void CmdCase(ConsoleSystem.Arg args) {
            var player = args.Player();
            if (player != null && args.HasArgs(1)) {
                if (args.Args[0] == "open") {
                    var item = config.cases.ElementAt(int.Parse(args.Args[1]));
                    if ((float)XpSystem.Call("API_GetBalance", player.userID) >= item.Price) {
                        var items = item.itemSettings.ToList().GetRandom();
                        XpSystem.Call("API_ShopRemBalance", player.userID, item.Price);
                        UpdateBalance(player);
                        RewarUI(player, items);
                    }
                    else {
                        SendReply(player, $"<color=#CF1E1E><size=16>Кейсы:</size></color>\nУ вас <color=#CF1E1E>недостаточно</color> средств!");
                        return;
                    }
                }
                if (args.Args[0] == "ui") {
                    CaseUI(player);
                }
                if (args.Args[0] == "info") {
                    CaseInfoUI(player, int.Parse(args.Args[1]));
                }
                if (args.Args[0] == "inventory") {
                    InventoryUI(player);
                }
                if (args.Args[0] == "take") {
                    var item = PlayerInventories[player.userID].Inventory.ElementAt(int.Parse(args.Args[1]));
                    if (item.ShortName != null) {
                        if (player.inventory.containerMain.itemList.Count >= 24) {
                            player.ChatMessage($"<color=#CF1E1E><size=16>Кейсы:</size></color>\nУ вас <color=#CF1E1E>недостаточно</color> места в основном инвентаре!");
                            return;
                        }
                    }
                    var text = item.Command != null ? $"<color=#CF1E1E><size=16>Кейсы:</size></color>\nВы получили услугу: <color=#CF1E1E>{item.Name}</color>" : $"<color=#CF1E1E><size=16>Кейсы:</size></color>\nВы получили предмет: <color=#CF1E1E>{item.Name}</color>\nВ размере: <color=#CF1E1E>{item.Amount}шт.</color>";
                    SendReply(player, text);
                    item.GiveItem(player)?.MoveToContainer(player.inventory.containerMain);
                    PlayerInventories[player.userID].Inventory.Remove(item);
                    InventoryUI(player);
                }
                if (args.Args[0] == "skip") {
                    InventoryUI(player, int.Parse(args.Args[1]));
                }
            }
        }
#endregion
#region Интерфейс
#region Основной
        private void CaseUI(BasePlayer player) {
            CuiHelper.DestroyUi(player, Layer);
            CuiElementContainer container = new CuiElementContainer();
            int CaseCount = config.cases.Count(), CountCase = 0, Count = 5;
            float Position = 0.2f, Width = (0.15f), Height = 0.3f, Margin = 0.002f, MinHeight = 0.38f;
            Position = 0.5f - CaseCount / 2f * Width - (CaseCount - 1) / 2f * Margin;
            container.Add(new CuiPanel {
                CursorEnabled = true, RectTransform = {
                    AnchorMin = "0 0", AnchorMax = "1 1"
                }
                , Image = {
                    Color = "0 0 0 0.5", Material = "assets/content/ui/uibackgroundblur-ingamemenu.mat"
                }
                ,
            }
            , "Overlay", Layer);
            container.Add(new CuiButton {
                RectTransform = {
                    AnchorMin = "0.9656251 0.9435185", AnchorMax = "0.9960139 0.9938782"
                }
                , Button = {
                    Color = "0 0 0 0", Close = Layer
                }
                , Text = {
                    Text = "X", FontSize = 14, Align = TextAnchor.MiddleCenter, Color = "1 1 1 1", Font = "robotocondensed-bold.ttf"
                }
            }
            , Layer);
            container.Add(new CuiButton {
                RectTransform = {
                    AnchorMin = "0 0.7762979", AnchorMax = "1 0.8112979", OffsetMax = "0 0"
                }
                , Button = {
                    Color = "0 0 0 0", Command = "case inventory"
                }
                , Text = {
                    Text = "-> ОТКРЫТЬ ИНВЕНТАРЬ <-", Color = "1 1 1 1", Align = TextAnchor.MiddleCenter, FontSize = 20, Font = "robotocondensed-regular.ttf"
                }
            }
            , Layer);
            container.Add(new CuiLabel {
                RectTransform = {
                    AnchorMin = "0 0.8098166", AnchorMax = "1 0.9398166", OffsetMax = "0 0"
                }
                , Text = {
                    Text = $"<b><size=25>РУЛЕТКА УДАЧИ</size></b>\nПривет {player.displayName}, ты открыл меню рулетки в которой ты найдешь множество кейсов и сможешь испытать свою удачу\nКаждый кейс имеет свое назначение и за каждый из них тебе предстоит заплатить!", Color = "1 1 1 1", Align = TextAnchor.MiddleCenter, FontSize = 14, Font = "robotocondensed-regular.ttf"
                }
            }
            , Layer);
            container.Add(new CuiLabel {
                RectTransform = {
                    AnchorMin = "0 0.09444449", AnchorMax = "1 0.2244445", OffsetMax = "0 0"
                }
                , Text = {
                    Text = $"<b><size=19>Ваш баланс: {XpSystem.Call("API_GetBalance", player.userID)}$</size></b>\n{XpSystem.Call("API_GetXp", player.userID)} из {XpSystem.Call("API_SetXp")}xp\nПополнить баланс ты можешь добывая ресурсы, убивая игроков, сбивая вертолеты, взрывая танки!", Color = "1 1 1 1", Align = TextAnchor.MiddleCenter, FontSize = 12, Font = "robotocondensed-regular.ttf"
                }
            }
            , Layer);
            container.Add(new CuiLabel {
                RectTransform = {
                    AnchorMin = "0 0.28", AnchorMax = "1 0.35", OffsetMax = "0 0"
                }
                , Text = {
                    Text = $"Испытай удачу и выбирай кейсы по вкусу\nНу а я, желаю тебе удачи!", Color = "1 1 1 1", Align = TextAnchor.MiddleCenter, FontSize = 16, Font = "robotocondensed-regular.ttf"
                }
            }
            , Layer);
            for (var i = 0; i < config.cases.Count();
            i++) {
                container.Add(new CuiPanel {
                    RectTransform = {
                        AnchorMin = $"{Position} {MinHeight}", AnchorMax = $"{Position + Width} {MinHeight + Height}", OffsetMin = "4 4", OffsetMax = "-4 -4"
                    }
                    , Image = {
                        Color = "0 0 0 0"
                    }
                }
                , Layer, $"{i}");
                Position += (Width + Margin);
                container.Add(new CuiPanel {
                    RectTransform = {
                        AnchorMin = "0 0.2", AnchorMax = "1 1", OffsetMax = "0 0"
                    }
                    , Image = {
                        Color = "0 0 0 0"
                    }
                    ,
                }
                , $"{i}", "Image");
                container.Add(new CuiElement {
                    Parent = "Image", Components = {
                        new CuiRawImageComponent {
                            Png = (string) ImageLibrary.Call("GetImage", config.cases.ElementAt(i).Url)
                        }
                        , new CuiRectTransformComponent {
                            AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"
                        }
                    }
                }
                );
                container.Add(new CuiLabel {
                    RectTransform = {
                        AnchorMin = "0 0", AnchorMax = "1 0.19", OffsetMax = "0 0"
                    }
                    , Text = {
                        Text = $"<b><size=14>{config.cases.ElementAt(i).DisplayName}</size></b>\nЦена: {config.cases.ElementAt(i).Price}$ ", Color = "1 1 1 0.7", Align = TextAnchor.MiddleCenter, FontSize = 12, Font = "robotocondensed-regular.ttf"
                    }
                }
                , $"{i}");
                container.Add(new CuiButton {
                    RectTransform = {
                        AnchorMin = "0 0.87", AnchorMax = "0.4 1", OffsetMax = "0 0"
                    }
                    , Button = {
                        Color = "0 0 0 0", Command = $"case info {i}"
                    }
                    , Text = {
                        Text = "ОТКРЫТЬ", Color = "1 1 1 0.7", Align = TextAnchor.MiddleRight, FontSize = 10, Font = "robotocondensed-bold.ttf"
                    }
                }
                , $"{i}");
            }
            CuiHelper.AddUi(player, container);
        }
#endregion
#region Информация кейса
        private void CaseInfoUI(BasePlayer player, int cases = 0) {
            CuiHelper.DestroyUi(player, LayerCaseInfo);
            CuiElementContainer container = new CuiElementContainer();
            CaseSetting check = config.cases.ElementAt(cases);
            int current = 0;
            container.Add(new CuiPanel {
                CursorEnabled = true, RectTransform = {
                    AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"
                }
                , Image = {
                    Color = "0 0 0 0.9", Material = "assets/content/ui/uibackgroundblur-ingamemenu.mat"
                }
                ,
            }
            , "Overlay", LayerCaseInfo);
            container.Add(new CuiButton {
                RectTransform = {
                    AnchorMin = "-2 -2", AnchorMax = "2 2", OffsetMax = "0 0"
                }
                , Button = {
                    Color = "0 0 0 0.5", Command = "case ui", Close = LayerCaseInfo
                }
            }
            , LayerCaseInfo);
            container.Add(new CuiLabel {
                RectTransform = {
                    AnchorMin = "0 0.9", AnchorMax = "1 1", OffsetMax = "0 0"
                }
                , Text = {
                    Text = $"{check.DisplayName.ToUpper()}", Color = "1 1 1 1", Align = TextAnchor.MiddleCenter, FontSize = 40, Font = "robotocondensed-bold.ttf"
                }
            }
            , LayerCaseInfo);
            container.Add(new CuiPanel {
                RectTransform = {
                    AnchorMin = "0.41 0.36", AnchorMax = "0.59 0.64", OffsetMax = "0 0"
                }
                , Image = {
                    Color = "0 0 0 0"
                }
            }
            , LayerCaseInfo, "Image");
            container.Add(new CuiElement {
                Parent = "Image", Components = {
                    new CuiRawImageComponent {
                        Png = (string) ImageLibrary.Call("GetImage", check.Url)
                    }
                    , new CuiRectTransformComponent {
                        AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"
                    }
                }
            }
            );
            container.Add(new CuiLabel {
                RectTransform = {
                    AnchorMin = "0 0", AnchorMax = "1 0.04", OffsetMax = "0 0"
                }
                , Text = {
                    Text = $"Ваш баланс: <b>{XpSystem.Call("API_GetBalance", player.userID)}$</b>", Color = "1 1 1 1", Align = TextAnchor.MiddleCenter, FontSize = 14, Font = "robotocondensed-regular.ttf"
                }
            }
            , LayerCaseInfo, "Balance");
            container.Add(new CuiButton {
                RectTransform = {
                    AnchorMin = "0.42 0.08", AnchorMax = "0.58 0.13", OffsetMax = "0 0"
                }
                , Button = {
                    Color = "1 1 1 0.1", Command = $"case open {cases}"
                }
                , Text = {
                    Text = $"<b><size=16>ОТКРЫТЬ</size></b>\nЗа {check.Price}$", Color = "1 1 1 1", Align = TextAnchor.MiddleCenter, FontSize = 14, Font = "robotocondensed-regular.ttf"
                }
            }
            , LayerCaseInfo);
            container.Add(new CuiPanel {
                RectTransform = {
                    AnchorMin = $"0.5 0.5", AnchorMax = $"0.5 0.5"
                }
                , Image = {
                    Color = "0 0 0 0"
                }
            }
            , LayerCaseInfo, "Center");
            int num = 0;
            int radius = 120;
            for (var i = 0; i < check.itemSettings.Count; i++) {
                int r = radius + 6 * check.itemSettings.Count();
                double c = (double) check.itemSettings.Count() / 2;
                double rad = (double)num / c * 3.142;
                double x = r * Math.Cos(rad);
                double y = r * Math.Sin(rad);
                container.Add(new CuiPanel {
                    RectTransform = {
                        AnchorMin = $"{x - 40} {y - 40}", AnchorMax = $"{x + 40} {y + 40}"
                    }
                    , Image = {
                        Color = "0 0 0 0"
                    }
                }
                , "Center", $"Images");
                var image = check.itemSettings.ElementAt(i).Command != null ? check.itemSettings.ElementAt(i).Url : check.itemSettings.ElementAt(i).ShortName;
                container.Add(new CuiElement {
                    Parent = "Images", Components = {
                        new CuiRawImageComponent {
                            Png = (string) ImageLibrary.Call("GetImage", image)
                        }
                        , new CuiRectTransformComponent {
                            AnchorMin = "0 0", AnchorMax = "1 1", OffsetMin = "5 5", OffsetMax = "-5 -5"
                        }
                    }
                }
                );
                var text = check.itemSettings.ElementAt(i).Command != null ? "Услуга" : "Предмет";
                container.Add(new CuiLabel {
                    RectTransform = {
                        AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"
                    }
                    , Text = {
                        Text = $"{text} ", Color = "1 1 1 1", Align = TextAnchor.UpperCenter, FontSize = 12, Font = "robotocondensed-regular.ttf"
                    }
                }
                , "Images");
                var textAmount = check.itemSettings.ElementAt(i).AmountMin != check.itemSettings.ElementAt(i).AmountMax ? $"{check.itemSettings.ElementAt(i).AmountMin}-{check.itemSettings.ElementAt(i).AmountMax}" : $"{check.itemSettings.ElementAt(i).AmountMax}";
                container.Add(new CuiLabel {
                    RectTransform = {
                        AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"
                    }
                    , Text = {
                        Text = $"{textAmount}шт. ", Color = "1 1 1 1", Align = TextAnchor.LowerCenter, FontSize = 12, Font = "robotocondensed-regular.ttf"
                    }
                }
                , "Images");
                num++;
                current++;
                if (current > 13) {
                    break;
                }
            }
            CuiHelper.AddUi(player, container);
        }
#endregion
#region Приз
        private void RewarUI(BasePlayer player, ItemSettings itemSettings) {
            CuiHelper.DestroyUi(player, LayerReward);
            CuiElementContainer container = new CuiElementContainer();
            var items = AddItem(player, itemSettings);
            container.Add(new CuiPanel {
                CursorEnabled = true, RectTransform = {
                    AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"
                }
                , Image = {
                    Color = "0 0 0 0.9", Material = "assets/content/ui/uibackgroundblur-ingamemenu.mat"
                }
                ,
            }
            , "Overlay", LayerReward);
            container.Add(new CuiPanel {
                RectTransform = {
                    AnchorMin = "0.45 0.44", AnchorMax = "0.55 0.6", OffsetMax = "0 0"
                }
                , Image = {
                    Color = "1 1 1 0.1"
                }
                ,
            }
            , LayerReward, "Image");
            var image = itemSettings.Command != null ? itemSettings.Url : itemSettings.ShortName;
            container.Add(new CuiElement {
                Parent = "Image", Components = {
                    new CuiRawImageComponent {
                        Png = (string) ImageLibrary.Call("GetImage", image)
                    }
                    , 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 = $"{items.Amount}шт. ", Color = "1 1 1 1", Align = TextAnchor.LowerRight, FontSize = 12, Font = "robotocondensed-regular.ttf"
                }
            }
            , "Image");
            container.Add(new CuiButton {
                RectTransform = {
                    AnchorMin = "0.45 0.4", AnchorMax = "0.55 0.435", OffsetMax = "0 0"
                }
                , Button = {
                    Color = "1 1 1 0.1", Close = LayerReward
                }
                , Text = {
                    Text = "ПРИНЯТЬ НАГРАДУ", Color = "1 1 1 1", Font = "robotocondensed-regular.ttf", FontSize = 12, Align = TextAnchor.MiddleCenter
                }
            }
            , LayerReward);
            CuiHelper.AddUi(player, container);
        }
#endregion
#region Инвентарь
        private void InventoryUI(BasePlayer player, int page = 0) {
            CuiHelper.DestroyUi(player, LayerInventory);
            CuiElementContainer container = new CuiElementContainer();
            int ItemCount = PlayerInventories[player.userID].Inventory.Count(), CountItem = 0, Count = 8;
            float Position = 0.5f, Width = 0.1f, Height = 0.155f, Margin = 0.005f, MinHeight = 0.668f;
            if (ItemCount >= Count) Position = 0.5f - Count / 2f * Width - (Count - 1) / 2f * Margin;
            else Position = 0.5f - ItemCount / 2f * Width - (ItemCount - 1) / 2f * Margin;
            ItemCount -= Count;
            container.Add(new CuiPanel {
                CursorEnabled = true, RectTransform = {
                    AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"
                }
                , Image = {
                    Color = "0 0 0 0.9"
                }
                ,
            }
            , "Overlay", LayerInventory);
            container.Add(new CuiButton {
                RectTransform = {
                    AnchorMin = "-2 -2", AnchorMax = "2 2", OffsetMax = "0 0"
                }
                , Button = {
                    Color = "0 0 0 0.9", Close = LayerInventory
                }
                , Text = {
                    Text = ""
                }
            }
            , LayerInventory);
            container.Add(new CuiButton {
                RectTransform = {
                    AnchorMin = PlayerInventories[player.userID].Inventory.Count() == 0 ? "0 0" : "0 0.9", AnchorMax = $"1 1", OffsetMax = "0 0"
                }
                , Button = {
                    Color = "0 0 0 0", Close = LayerInventory
                }
                , Text = {
                    Text = PlayerInventories[player.userID].Inventory.Count() == 0 ? $"ИНВЕНТАРЬ ПУСТ" : "ИНВЕНТАРЬ", Color = "1 1 1 1", Font = "robotocondensed-bold.ttf", FontSize = PlayerInventories[player.userID].Inventory.Count() == 0 ? 60 : 40, Align = TextAnchor.MiddleCenter
                }
            }
            , LayerInventory);
            if (page != 0) {
                container.Add(new CuiButton {
                    RectTransform = {
                        AnchorMin = "0 0.45", AnchorMax = $"0.06 0.55", OffsetMax = "0 0"
                    }
                    , Button = {
                        Color = "0 0 0 0", Command = $"case skip {page - 1}"
                    }
                    , Text = {
                        Text = $"<", Color = "1 1 1 1", Font = "robotocondensed-bold.ttf", FontSize = 60, Align = TextAnchor.MiddleCenter
                    }
                }
                , LayerInventory);
            }
            if ((float)PlayerInventories[player.userID].Inventory.Count > (page + 1) * 32) {
                container.Add(new CuiButton {
                    RectTransform = {
                        AnchorMin = "0.94 0.45", AnchorMax = $"1 0.55", OffsetMax = "0 0"
                    }
                    , Button = {
                        Color = "0 0 0 0", Command = $"case skip {page + 1}"
                    }
                    , Text = {
                        Text = $">", Color = "1 1 1 1", Font = "robotocondensed-bold.ttf", FontSize = 60, Align = TextAnchor.MiddleCenter
                    }
                }
                , LayerInventory);
            }
            var list = PlayerInventories[player.userID].Inventory.Skip(page * 32).Take(32);
            foreach (var check in list.Select((i, t) => new {
                A = i, B = t
            }
            )) {
                container.Add(new CuiButton {
                    RectTransform = {
                        AnchorMin = $"{Position} {MinHeight}", AnchorMax = $"{Position + Width} {MinHeight + Height}", OffsetMax = "0 0"
                    }
                    , Button = {
                        Color = "1 1 1 0.1"
                    }
                    , Text = {
                        Text = ""
                    }
                }
                , LayerInventory, $"{check.B}");
                var image = check.A.Command != null ? check.A.Url : check.A.ShortName;
                container.Add(new CuiElement {
                    Parent = $"{check.B}", Components = {
                        new CuiRawImageComponent {
                            Png = (string) ImageLibrary.Call("GetImage", image)
                        }
                        , new CuiRectTransformComponent {
                            AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"
                        }
                    }
                }
                );
                container.Add(new CuiButton {
                    RectTransform = {
                        AnchorMin = "0 0", AnchorMax = $"1 1", OffsetMax = "0 0"
                    }
                    , Button = {
                        Color = "0 0 0 0", Command = $"case take {check.B + page * 32}"
                    }
                    , Text = {
                        Text = $"X{check.A.Amount} ", Color = "1 1 1 1", Font = "robotocondensed-regular.ttf", FontSize = 12, Align = TextAnchor.LowerRight
                    }
                }
                , $"{check.B}");
                CountItem += 1;
                if (CountItem % Count == 0) {
                    if (ItemCount > Count) {
                        Position = 0.5f - Count / 2f * Width - (Count - 1) / 2f * Margin;
                        ItemCount -= Count;
                    }
                    else {
                        Position = 0.5f - ItemCount / 2f * Width - (ItemCount - 1) / 2f * Margin;
                    }
                    MinHeight -= ((Margin * 2) + Height);
                }
                else {
                    Position += (Width + Margin);
                }
            }
            CuiHelper.AddUi(player, container);
        }
#endregion
#endregion
#region Хелпер
        private static string HexToUiColor(string hex) {
            if (string.IsNullOrEmpty(hex)) {
                hex = "#FFFFFFFF";
            }
            var str = hex.Trim('#');
            if (str.Length == 6) str += "FF";
            if (str.Length != 8) {
                throw new Exception(hex);
                throw new InvalidOperationException("Cannot convert a wrong format.");
            }
            var r = byte.Parse(str.Substring(0, 2), NumberStyles.HexNumber);
            var g = byte.Parse(str.Substring(2, 2), NumberStyles.HexNumber);
            var b = byte.Parse(str.Substring(4, 2), NumberStyles.HexNumber);
            var a = byte.Parse(str.Substring(6, 2), NumberStyles.HexNumber);
            Color color = new Color32(r, g, b, a);
            return $"{color.r:F2} {color.g:F2} {color.b:F2} {color.a:F2}";
        }
#endregion
    }
}

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