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

FREE ClubQuests : 1.0.0 1.0.0

Нет прав для скачивания
C#:
using Oxide.Core;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

namespace Oxide.Plugins
{
    /*ПЛАГИН БЫЛ ПОФИКШЕН С ПОМОЩЬЮ ПРОГРАММЫ СКАЧАНОЙ С https://discord.gg/dNGbxafuJn */ [Info("ClubQuests", "https://discord.gg/dNGbxafuJn", "1.0.0")]
    [Description("ClubQuests")]
    class ClubQuests : RustPlugin
    {
        #region Classes

        private class PluginConfig
        {
            public int QuestLimit = 3;
            public double QuestUpdateTime = 24.0;
            public List<Quest> quests;
        }

        private class PluginData
        {
            public Dictionary<ulong, PlayerData> playerData = new Dictionary<ulong, PlayerData>();
            public float TimeToUpdate = 0;
        }

        private class PlayerData
        {
            public bool needToUpdate = true;
            public List<string> currectQuests = new List<string>();
            public List<QuestSelect> selectedQuests = new List<QuestSelect>();
            public List<string> doneQuests = new List<string>();
            public List<string> completedQuests = new List<string>();
        }
   
        private class QuestSelect
        {
            public string Name = "";
            public List<MissionPlayer> missions;
        }

        private class Quest
        {
            public string Name = "";
            public string Decription = "";
           // public string Group = ""; // group: loot, find, kill,  farm,   
            public List<PrizeItem> prizeItems;
            public List<Mission> missions;
        }

        private class PrizeItem
        {
            public string ShortName = "";
            public string Image = "";
            public string Command = "";
            public int Value = 0;
            public ulong Skin = 0;
            public PrizeItem(string name = "", string image = "", string command = "", int max = 10)
            {
                ShortName = name; Image = image; Command = command; Value = max;
            }
        }

        private class Mission
        {
            public string Type = "";
            public int Amount = 0;
            public string What = "";
            public Mission(string type, int a, string what)
            {
                Type = type; Amount = a; What = what;
            }
        }

        private class MissionPlayer : Mission
        {
            public int AmountNeed = 0;
            public MissionPlayer(string type, int a, string what, int need) : base(type, a, what)
            {
                AmountNeed = need;
            }
        }
        
        private class PlayerItems
        {
            public string ShortName = "";
            public string Image = "";
            public int Amount = 0;
            public ulong Skin = 0;
            public PlayerItems(string name = "", string image = "", int a = 1, ulong skin = 0)
            {
                ShortName = name; Image = image; Amount = a; Skin = skin;
            }
        }
        #endregion

        #region Variables
        [PluginReference]
        Plugin ImageLibrary;
        
        private PluginConfig config;

        private Dictionary<string, string> customImages;

        private PluginData pluginData;

        string UI_Layer = "UI_Quests";

        string EffectButton = "assets/prefabs/weapons/semi auto rifle/effects/dryfire.prefab";
        //string EffectInventory = "assets/prefabs/tools/binoculars/effects/deploy.prefab";
        //string EffectAvailible = "assets/prefabs/locks/keypad/effects/lock.code.updated.prefab";

        Dictionary<ulong, Timer> timerUpdator;
        private List<ulong> Looters;
        Timer pluginTimer;
        #endregion
        
        #region Oxide

        #region MainHooks
        private void Init()
        {
            config = Config.ReadObject<PluginConfig>();
        }

        void OnServerInitialized()
        {
            pluginData = new PluginData();
            if (Interface.Oxide.DataFileSystem.ExistsDatafile("Quests/Data"))
                pluginData = Interface.Oxide.DataFileSystem.ReadObject<PluginData>("Quests/Data");
            

            customImages = new Dictionary<string, string>()
            {
                ["mainback"] = "https://i.imgur.com/1lDYVuc.png",
                ["questback"] = "https://i.imgur.com/hzQdIFA.png",
                ["questmainbtn"] = "https://i.imgur.com/wJTdc9Z.png",
                ["questsecbnt"] = "https://i.imgur.com/dWJeqr5.png",
                ["questbackbtn"] = "https://i.imgur.com/bEEg4Aa.png"
            };

            if (ImageLibrary != null)
                LoadImages();
            else PrintWarning("ImageLibrary not found! Plugin won't work!");


            pluginTimer = timer.Every(10f, () => 
            {
                pluginData.TimeToUpdate -= 10;
                if (pluginData.TimeToUpdate <= 0)
                {
                    pluginData.TimeToUpdate = (float)config.QuestUpdateTime * 3600;
                    foreach(var plr in pluginData.playerData)
                        plr.Value.needToUpdate = true;
                   
                }
            });

            BasePlayer.activePlayerList.ToList().ForEach((BasePlayer player) => { UpdateData(player); });

            timerUpdator = new Dictionary<ulong, Timer>();
            Looters = new List<ulong>();
            Interface.Oxide.DataFileSystem.WriteObject("Quests/Data", pluginData);
            PrintWarning("Plugin loaded! Author: BadMandarin!");
        }

        void OnPlayerConnected(BasePlayer player)
        {
            if (player == null) return;
            if (player.HasPlayerFlag(BasePlayer.PlayerFlags.ReceivingSnapshot))
            {
                timer.Once(2f, () => OnPlayerConnected(player));
                return;
            }
            if (!player.IsConnected)
            {
                return;
            }

            UpdateData(player);
        }

        void OnPlayerDisconnected(BasePlayer player, string reason)
        {
            if (timerUpdator.ContainsKey(player.userID))
            {
                timerUpdator[player.userID].Destroy();
                timerUpdator.Remove(player.userID);
            }
        }

        void Unload()
        {
            if(!pluginTimer.Destroyed) pluginTimer.Destroy();
            BasePlayer.activePlayerList.ToList().ForEach((BasePlayer player) => 
            {
                if (timerUpdator.ContainsKey(player.userID))
                {
                    timerUpdator[player.userID].Destroy();
                    timerUpdator.Remove(player.userID);
                }
            });
            Interface.Oxide.DataFileSystem.WriteObject("Quests/Data", pluginData);
            PrintWarning("Plugin unloaded! Author: BadMandarin!");
        }
        #endregion

        #region OtherHooks
        void OnEntityDeath(BaseCombatEntity entity, HitInfo info)
        {
            var player = info?.InitiatorPlayer;
            if (player == null) return; 
            if (!pluginData.playerData.ContainsKey(player.userID)) return;
            var data = pluginData.playerData[player.userID];
            if (data.selectedQuests == null || data.selectedQuests.Count() < 1) return; 
            string name = entity?.ShortPrefabName;
            if (string.IsNullOrEmpty(name)) return; 
            data.selectedQuests.ToList().ForEach((QuestSelect q) =>
            {
                var mission = q.missions.FindAll(m => m.Type == "kill");
                if (mission == null || mission.Count() < 1) return;
                
                mission.ForEach((MissionPlayer mis) => {
                    if (name.Contains(mis.What)) mis.AmountNeed++;
                });
                if (IsCompleted(player, mission))
                {
                    data.selectedQuests.Remove(q);
                    data.doneQuests.Add(q.Name);
                    SendReply(player, $"Вы выполнили квест: {q.Name}!");
                }
            }); 
        }

        object OnDispenserGather(ResourceDispenser dispenser, BaseEntity entity, Item item)
        {
            BasePlayer player = entity.ToPlayer();
            if (player == null) return null;
            if (!pluginData.playerData.ContainsKey(player.userID)) return null;
            var data = pluginData.playerData[player.userID];
            if (data.selectedQuests == null || data.selectedQuests.Count() < 1) return null;
            string name = item.info.shortname;
            if (string.IsNullOrEmpty(name)) return null;
            data.selectedQuests.ToList().ForEach((QuestSelect q) =>
            {
                var mission = q.missions.FindAll(m => m.Type == "farm");
                if (mission == null || mission.Count() < 1) return;

                mission.ForEach((MissionPlayer mis) => {
                    if (name.Contains(mis.What)) mis.AmountNeed += item.amount;
                });
                if (IsCompleted(player, mission))
                {
                    data.selectedQuests.Remove(q);
                    data.doneQuests.Add(q.Name);
                    SendReply(player, $"Вы выполнили квест: {q.Name}!");
                }
            });
            return null;
        }

        object OnDispenserBonus(ResourceDispenser dispenser, BasePlayer player, Item item)
        {
            if (player == null) return null;
            if (!pluginData.playerData.ContainsKey(player.userID)) return null;
            var data = pluginData.playerData[player.userID];
            if (data.selectedQuests == null || data.selectedQuests.Count() < 1) return null;
            string name = item.info.shortname;
            if (string.IsNullOrEmpty(name)) return null;
            data.selectedQuests.ToList().ForEach((QuestSelect q) =>
            {
                var mission = q.missions.FindAll(m => m.Type == "farm");
                if (mission == null || mission.Count() < 1) return;

                mission.ForEach((MissionPlayer mis) => {
                    if (name.Contains(mis.What)) mis.AmountNeed += item.amount;
                });
                if (IsCompleted(player, mission))
                {
                    data.selectedQuests.Remove(q);
                    data.doneQuests.Add(q.Name);
                    SendReply(player, $"Вы выполнили квест: {q.Name}!");
                }
            });
            return null;
        }

        object OnCollectiblePickup(Item item, BasePlayer player)
        {
            if (player == null) return null;
            if (!pluginData.playerData.ContainsKey(player.userID)) return null;
            var data = pluginData.playerData[player.userID];
            if (data.selectedQuests == null || data.selectedQuests.Count() < 1) return null;
            string name = item.info.shortname;
            if (string.IsNullOrEmpty(name)) return null;
            data.selectedQuests.ToList().ForEach((QuestSelect q) =>
            {
                var mission = q.missions.FindAll(m => m.Type == "farm");
                if (mission == null || mission.Count() < 1) return;

                mission.ForEach((MissionPlayer mis) => {
                    if (name.Contains(mis.What)) mis.AmountNeed += item.amount;
                });
                if (IsCompleted(player, mission))
                {
                    data.selectedQuests.Remove(q);
                    data.doneQuests.Add(q.Name);
                    SendReply(player, $"Вы выполнили квест: {q.Name}!");
                }
            });
            return null;
        }

        void OnLootEntityEnd(BasePlayer player, BaseCombatEntity entity)
        {
            if (player == null || entity == null) return;
            var container = entity as LootContainer;
            if (container == null || container.inventory.itemList == null || container.OwnerID != 0 || container.flags.HasFlag(BaseEntity.Flags.Reserved8)) return;
            if (!pluginData.playerData.ContainsKey(player.userID)) return;
            var data = pluginData.playerData[player.userID];
            if (data.selectedQuests == null || data.selectedQuests.Count() < 1) return;
            string name = container?.ShortPrefabName;
            if (string.IsNullOrEmpty(name)) return;
            data.selectedQuests.ToList().ForEach((QuestSelect q) =>
            {
                var mission = q.missions.FindAll(m => m.Type == "loot");
                if (mission == null || mission.Count() < 1) return;

                mission.ForEach((MissionPlayer mis) => {
                    if (name.Contains(mis.What)) { mis.AmountNeed++; }
                });
                if (IsCompleted(player, mission))
                {
                    data.selectedQuests.Remove(q);
                    data.doneQuests.Add(q.Name);
                    SendReply(player, $"Вы выполнили квест: {q.Name}!");
                }
            });
            container.SetFlag(BaseEntity.Flags.Reserved8, true);
        }
        //Loot
        void OnItemAddedToContainer(ItemContainer container, Item item)
        {
            if (Looters != null && Looters.Contains(item.uid.Value))
            {
                Looters.Remove(item.uid.Value);
                BasePlayer player = container?.playerOwner;
                if (player == null) return;
                if (!pluginData.playerData.ContainsKey(player.userID)) return;
                var data = pluginData.playerData[player.userID];
                if (data.selectedQuests == null || data.selectedQuests.Count() < 1) return;
                string name = item?.info?.shortname;
                if (string.IsNullOrEmpty(name)) return;
                data.selectedQuests.ToList().ForEach((QuestSelect q) =>
                {
                    var mission = q.missions.FindAll(m => m.Type == "find");
                    if (mission == null || mission.Count() < 1) return;

                    mission.ForEach((MissionPlayer mis) => {
                        if (name.Contains(mis.What)) { mis.AmountNeed+=item.amount; }
                    });
                    if (IsCompleted(player, mission))
                    {
                        data.selectedQuests.Remove(q);
                        data.doneQuests.Add(q.Name);
                        SendReply(player, $"Вы выполнили квест: {q.Name}!");
                    }
                });
            }
        }
        void OnItemRemovedFromContainer(ItemContainer container, Item item)
        {
           if(Looters != null && container.playerOwner == null)
           {
                Looters.Add(item.uid.Value);
           }
        }
        #endregion

        #endregion

        #region Interface
        private void LoadMainBlock(BasePlayer player, int page = 0)
        {
            PlayerData data = null;
            if(!pluginData.playerData.TryGetValue(player.userID, out data))
            {
                UpdateData(player);
                LoadMainBlock(player);
                return;
            }
            
            CuiElementContainer container = new CuiElementContainer()
            {
                {
                    new CuiPanel
                    {
                        CursorEnabled = true,
                        RectTransform =
                        {
                            AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-350 -300", OffsetMax = "350 300"
                        },
                        Image = {Color = GetColor("#000000", 0f), Material = "assets/content/ui/uibackgroundblur.mat" }
                    }, "Overlay", UI_Layer
                },
                {
                    new CuiElement
                    {
                        Parent = UI_Layer,
                        Name = $"{UI_Layer}.Bgr",
                        Components =
                        {
                            new CuiRawImageComponent
                            {
                               Png = GetImage("mainback"), Color = GetColor("#0B3B2E", 0.95f)
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"0 0",
                                AnchorMax = $"1 1",
                                OffsetMin = "0 0",
                                OffsetMax = "0 0"
                            }
                        }
                    }
                },
                {
                    new CuiButton
                    {
                        RectTransform = { AnchorMin = "-100 -100", AnchorMax = "100 100" },
                        Button = { Color = "0 0 0 0", Command = "UI_QuestDestroy" },
                        Text = { Text = "" }
                    }, UI_Layer
                },
                {
                    new CuiElement
                    {
                        Parent = UI_Layer,
                        Name = $"{UI_Layer}.Header",
                        Components =
                        {
                            new CuiImageComponent
                            {
                                Color = GetColor("#0B3B2E", 0.95f)
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"0 1",
                                AnchorMax = $"1 1",
                                OffsetMin = "0 -25",
                                OffsetMax = "0 0"
                            }
                        }
                    }
                },
                {
                    new CuiElement
                    {
                        Parent = $"{UI_Layer}.Header",
                        Components =
                        {
                            new CuiTextComponent
                            {
                                Text = "Меню квестов", Align = TextAnchor.MiddleCenter, Font = "RobotoCondensed-Regular.ttf", FontSize = 16, Color = GetColor("#FFFFFF", 0.8f)
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"0 0",
                                AnchorMax = $"1 1",
                                OffsetMin = "0 0",
                                OffsetMax = "0 0"
                            }
                        }
                    }
                },

                {
                    new CuiElement
                    {
                        Parent = UI_Layer,
                        Name = $"{UI_Layer}.Bottom",
                        Components =
                        {
                            new CuiImageComponent
                            {
                                Color = GetColor("#0B3B2E", 0.95f)
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"0 0",
                                AnchorMax = $"1 0",
                                OffsetMin = "0 0",
                                OffsetMax = "0 45"
                            }
                        }
                    }
                },
                {
                    new CuiElement
                    {
                        Parent = UI_Layer,
                        Name = $"{UI_Layer}.Exit",
                        Components =
                        {
                            new CuiImageComponent
                            {
                                Color = GetColor("#161616", 0.95f)
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"1 0",
                                AnchorMax = $"1 0",
                                OffsetMin = "-110 10",
                                OffsetMax = "-10 35"
                            }
                        }
                    }
                },
                {
                    new CuiElement
                    {
                        Parent = $"{UI_Layer}.Exit",
                        Components =
                        {
                            new CuiTextComponent
                            {
                                Text = "ЗАКРЫТЬ", Align = TextAnchor.MiddleCenter, Font = "RobotoCondensed-Regular.ttf", FontSize = 16, Color = GetColor("#FFFFFF", 0.8f)
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"0 0",
                                AnchorMax = $"1 1",
                                OffsetMin = "0 0",
                                OffsetMax = "0 0"
                            }
                        }
                    }
                },
                {
                    new CuiButton
                    {
                        RectTransform = { AnchorMin = "0 0", AnchorMax = "1 1" },
                        Button = { Color = "0 0 0 0", Command = "UI_QuestDestroy" },
                        Text = { Text = "" }
                    }, $"{UI_Layer}.Exit"
                },

                {
                    new CuiElement
                    {
                        Parent = UI_Layer,
                        Name = $"{UI_Layer}.Pages",
                        Components =
                        {
                            new CuiImageComponent
                            {
                                Color = GetColor("#161616", 0.95f)
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"1 0",
                                AnchorMax = $"1 0",
                                OffsetMin = "-215 10",
                                OffsetMax = "-115 35"
                            }
                        }
                    }
                },
                {
                    new CuiElement
                    {
                        Parent = $"{UI_Layer}.Pages",
                        Components =
                        {
                            new CuiTextComponent
                            {
                                Text = $"{page+1}", Align = TextAnchor.MiddleCenter, Font = "RobotoCondensed-Regular.ttf", FontSize = 16, Color = GetColor("#FFFFFF", 0.8f)
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"0 0",
                                AnchorMax = $"1 1",
                                OffsetMin = "0 0",
                                OffsetMax = "0 0"
                            }
                        }
                    }
                },

                {
                    new CuiElement
                    {
                        Parent = $"{UI_Layer}.Pages",
                        Name = $"{UI_Layer}.PagesNext",
                        Components =
                        {
                            new CuiTextComponent
                            {
                                Text = $">", Align = TextAnchor.MiddleRight, Font = "RobotoCondensed-Regular.ttf", FontSize = 16, Color = GetColor("#FFFFFF", 0.8f)
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"0 0",
                                AnchorMax = $"1 1",
                                OffsetMin = "0 0",
                                OffsetMax = "-5 0"
                            }
                        }
                    }
                },

                {
                    new CuiElement
                    {
                        Parent = $"{UI_Layer}.Pages",
                        Name = $"{UI_Layer}.PagesBack",
                        Components =
                        {
                            new CuiTextComponent
                            {
                                Text = $"<", Align = TextAnchor.MiddleLeft, Font = "RobotoCondensed-Regular.ttf", FontSize = 16, Color = GetColor("#FFFFFF", 0.8f)
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"0 0",
                                AnchorMax = $"1 1",
                                OffsetMin = "5 0",
                                OffsetMax = "0 0"
                            }
                        }
                    }
                },
                {
                    new CuiElement
                    {
                        Parent = UI_Layer,
                        Name = $"{UI_Layer}.Timer",
                        Components =
                        {
                            new CuiImageComponent
                            {
                                Color = GetColor("#161616", 0.95f)
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"0 0",
                                AnchorMax = $"0 0",
                                OffsetMin = "200 10",
                                OffsetMax = "300 35"
                            }
                        }
                    }
                },
                {
                    new CuiElement
                    {
                        Parent = UI_Layer,
                        Components =
                        {
                            new CuiTextComponent
                            {
                                Text = "Задания обновятся через: ", Align = TextAnchor.MiddleLeft, Font = "RobotoCondensed-Regular.ttf", FontSize = 16, Color = GetColor("#FFFFFF", 0.8f)
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"0 0",
                                AnchorMax = $"0 0",
                                OffsetMin = "10 10",
                                OffsetMax = "250 35"
                            }
                        }
                    }
                },
            };

            if (page > 0)
            {
                container.Add(new CuiButton
                {
                    RectTransform = { AnchorMin = "0 0", AnchorMax = "0.2 1" },
                    Button = { Color = "0 0 0 0", Command = $"UI_QuestPages {page - 1}" },
                    Text = { Text = "" }
                }, $"{UI_Layer}.Pages");
            }

            if (data.currectQuests.Count() > 6 + 6*page)
            {
                container.Add(new CuiButton
                {
                    RectTransform = { AnchorMin = "0.8 0", AnchorMax = "1 1" },
                    Button = { Color = "0 0 0 0", Command = $"UI_QuestPages {page + 1}" },
                    Text = { Text = "" }
                }, $"{UI_Layer}.Pages");
            }

            int i = 0;
            for(int b = 0; b < 6; b++)
            {
                if (data.currectQuests.Count()-1 < b + 6 * page) break;
                var info = data.currectQuests.ElementAt(b + 6*page);
                var quest = config.quests.Find(x => x.Name == info);
                bool selected = data.selectedQuests.Find(x => x.Name == quest.Name) == null ? false : true;
                bool done = data.doneQuests.Contains(info) ? true : false;
                bool completed = data.completedQuests.Contains(info) ? true : false;
                container.Add(new CuiElement
                {
                    Parent = $"{UI_Layer}",
                    Name = $"{UI_Layer}.Quest.{i}",
                    Components =
                        {
                            new CuiRawImageComponent
                            {
                                Png = GetImage("questback"), Color = (completed || done) ? GetColor("#88de67", 0.2f) : GetColor("#161616", 0.9f)
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"0 1",
                                AnchorMax = $"1 1",
                                OffsetMin = $"15 {-115 - i*85}",
                                OffsetMax = $"-15 {-35 - i*85}"
                            }
                        }
                });
                container.Add(new CuiElement
                {
                    Parent = $"{UI_Layer}.Quest.{i}",
                    Components =
                        {
                            new CuiTextComponent
                            {
                                Text = quest.Name, Align = TextAnchor.MiddleCenter, Font = "RobotoCondensed-Regular.ttf", FontSize = 16, Color = GetColor((completed || done)?"#FFFFFF":selected?"#88de67":"#cf3333", 1f)
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"0 1",
                                AnchorMax = $"0 1",
                                OffsetMin = $"35 -25",
                                OffsetMax = $"200 0"
                            }
                        }
                });
                string descript = selected ? (string.Format(quest.Decription, data.selectedQuests.Find(x => x.Name == quest.Name).missions.ConvertAll(x => x.AmountNeed.ToString()).ToArray())) : quest.Decription.Replace("/", string.Empty);
                container.Add(new CuiElement
                {
                    Parent = $"{UI_Layer}.Quest.{i}",
                    Components =
                        {
                            new CuiTextComponent
                            {
                                Text = descript, Align = TextAnchor.MiddleLeft, Font = "RobotoCondensed-Regular.ttf", FontSize = 12, Color = GetColor("#FFFFFF", 1f)
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"0 0",
                                AnchorMax = $"1 1",
                                OffsetMin = $"35 25",
                                OffsetMax = $"-300 -25"
                            }
                        }
                });
                container.Add(new CuiElement
                {
                    Parent = $"{UI_Layer}.Quest.{i}",
                    Components =
                        {
                            new CuiImageComponent
                            {
                                Color = GetColor((completed || done)?"#88de67":selected?"#88de67":"#cf3333", 1f)
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"0 0",
                                AnchorMax = $"1 0",
                                OffsetMin = $"0 0",
                                OffsetMax = $"-28 2"
                            }
                        }
                });

                container.Add(new CuiElement
                {
                    Parent = $"{UI_Layer}.Quest.{i}",
                    Name = $"{UI_Layer}.Quest.{i}.Status",
                    Components =
                        {
                            new CuiRawImageComponent
                            {
                                Png = GetImage("questsecbnt"), Color = GetColor("#FFFFFF", 0.9f)
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"1 1",
                                AnchorMax = $"1 1",
                                OffsetMin = $"-330 -20",
                                OffsetMax = $"-220 0"
                            }
                        }
                });
                container.Add(new CuiElement
                {
                    Parent = $"{UI_Layer}.Quest.{i}.Status",
                    Components =
                        {
                            new CuiTextComponent
                            {
                                Text = (completed || done)?"ВЫПОЛНЕНО":selected?"ВЫПОЛНЯЕТСЯ":"НЕ НАЧАТО", Align = TextAnchor.MiddleCenter, Font = "RobotoCondensed-Regular.ttf", FontSize = 10, Color = GetColor("#FFFFFF", 1f)
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"0 0",
                                AnchorMax = $"1 1",
                                OffsetMin = $"0 0",
                                OffsetMax = $"0 0"
                            }
                        }
                });
                container.Add(new CuiElement
                {
                    Parent = $"{UI_Layer}.Quest.{i}",
                    Name = $"{UI_Layer}.Quest.{i}.Prize",
                    Components =
                        {
                            new CuiRawImageComponent
                            {
                                Png = GetImage("questbackbtn"), Color = GetColor("#FFFFFF", 0.9f)
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"1 0",
                                AnchorMax = $"1 1",
                                OffsetMin = $"-240 0",
                                OffsetMax = $"-90 0"
                            }
                        }
                });
                container.Add(new CuiElement
                {
                    Parent = $"{UI_Layer}.Quest.{i}.Prize",
                    Name = $"{UI_Layer}.Quest.{i}.Text",
                    Components =
                        {
                            new CuiRawImageComponent
                            {
                                Png = GetImage("questsecbnt"), Color = GetColor("#FFFFFF", 0.9f)
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"0 0.5",
                                AnchorMax = $"1 0.5",
                                OffsetMin = $"25 -10",
                                OffsetMax = $"-25 10"
                            }
                        }
                });
                container.Add(new CuiElement
                {
                    Parent = $"{UI_Layer}.Quest.{i}.Text",
                    Components =
                        {
                            new CuiTextComponent
                            {
                                Text = "НАЖМИ", Align = TextAnchor.MiddleCenter, Font = "RobotoCondensed-Bold.ttf", FontSize = 10, Color = GetColor("#FFFFFF", 1f)
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"0 0.5",
                                AnchorMax = $"1 0.5",
                                OffsetMin = $"25 -10",
                                OffsetMax = $"-25 10"
                            }
                        }
                });
                container.Add(new CuiButton
                {
                    RectTransform = { AnchorMin = "0 0", AnchorMax = "1 1" },
                    Button = { Color = "0 0 0 0", Command = $"UI_QuestPrizeInfo {i}" },
                    Text = { Text = "" }
                }, $"{UI_Layer}.Quest.{i}.Text");

                container.Add(new CuiElement
                {
                    Parent = $"{UI_Layer}.Quest.{i}.Prize",
                    Components =
                        {
                            new CuiTextComponent
                            {
                                Text = "НАГРАДА", Align = TextAnchor.MiddleCenter, Font = "RobotoCondensed-Bold.ttf", FontSize = 12, Color = GetColor("#88de67", 1f)
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"0 1",
                                AnchorMax = $"1 1",
                                OffsetMin = $"40 -25",
                                OffsetMax = $"-20 -5"
                            }
                        }
                });

                container.Add(new CuiElement
                {
                    Parent = $"{UI_Layer}.Quest.{i}",
                    Name = $"{UI_Layer}.Quest.{i}.MainBtn",
                    Components =
                        {
                            new CuiRawImageComponent
                            {
                                Png = GetImage("questmainbtn"), Color = GetColor("#FFFFFF", 1f)
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"1 0",
                                AnchorMax = $"1 1",
                                OffsetMin = $"-100 15",
                                OffsetMax = $"-20 -15"
                            }
                        }
                });

                container.Add(new CuiButton
                {
                    RectTransform = { AnchorMin = "0 0", AnchorMax = "1 1" },
                    Button = { Color = "0 0 0 0", Command = $"UI_QuestToggle {i}" },
                    Text = { Text = completed ? "ПОЛУЧЕН" : done ? "ЗАБРАТЬ" : selected ? "ОТМЕНА" : "НАЧАТЬ", Align = TextAnchor.MiddleCenter, Font = "RobotoCondensed-Bold.ttf", FontSize = 12, Color = GetColor("#161616", 1f) }
                }, $"{UI_Layer}.Quest.{i}.MainBtn");
                i++;
            }


            CuiHelper.DestroyUi(player, UI_Layer);
            CuiHelper.AddUi(player, container);
            Draw_UITimer(player);
        }

        private void Draw_UITimer(BasePlayer player)
        {
            CuiElementContainer container = new CuiElementContainer()
            {
                {
                    new CuiPanel
                    {
                        CursorEnabled = false,
                        RectTransform =
                        {
                            AnchorMin = "0 0", AnchorMax = "1 1"
                        },
                        Image = {Color = "0 0 0 0" }
                    }, $"{UI_Layer}.Timer", $"{UI_Layer}.Timer.Text"
                },
                {
                    new CuiElement
                    {
                        Parent = $"{UI_Layer}.Timer.Text",
                        Components =
                        {
                            new CuiTextComponent
                            {
                                Text = FormatTime(TimeSpan.FromSeconds(pluginData.TimeToUpdate)), Align = TextAnchor.MiddleCenter, Font = "RobotoCondensed-Regular.ttf", FontSize = 16, Color = GetColor("#FFFFFF", 0.8f)
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"0 0",
                                AnchorMax = $"1 1",
                                OffsetMin = "0 0",
                                OffsetMax = "0 0"
                            }
                        }
                    }
                },
            };

            CuiHelper.DestroyUi(player, $"{UI_Layer}.Timer.Text");
            CuiHelper.AddUi(player, container);
        }
        
        private void Draw_UIItemTake(BasePlayer player, List<PlayerItems> itmgiven)
        {
            int blockwidth = 140;
            int distance = 10;
            int mainblockwidth = GetBlockWidth(itmgiven.Count(), distance, blockwidth);
            CuiElementContainer container = new CuiElementContainer()
            {
                {
                    new CuiPanel
                    {
                        CursorEnabled = true,
                        RectTransform =
                        {
                            AnchorMin = "0 0", AnchorMax = "1 1"
                        },
                        Image = {Color = GetColor("#161616", 0.95f) }
                    }, "Overlay", $"{UI_Layer}.TakeBlock"
                },
                {
                    new CuiButton
                    {
                        RectTransform = { AnchorMin = "0 0", AnchorMax = "1 1" },
                        Button = { Color = "0 0 0 0", Close = $"{UI_Layer}.TakeBlock" },
                        Text = { Text = "" }
                    }, $"{UI_Layer}.TakeBlock"
                },
                {
                    new CuiElement
                    {
                        Parent = $"{UI_Layer}.TakeBlock",
                        Name = $"{UI_Layer}.TakeBlock.Main",
                        Components =
                        {
                            new CuiImageComponent
                            {
                                Color = GetColor("#FFFFFF", 0.6f)
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"0.5 0.5",
                                AnchorMax = $"0.5 0.5",
                                OffsetMin = $"{mainblockwidth/-2} -100",
                                OffsetMax = $"{mainblockwidth/2} 100"
                            }
                        }
                    }
                },
                {
                    new CuiElement
                    {
                        Parent = $"{UI_Layer}.TakeBlock.Main",
                        Components =
                        {
                            new CuiTextComponent
                            {
                                Text = $"НАГРАДА ЗА КВЕСТ", Align = TextAnchor.UpperCenter, Font = "RobotoCondensed-Bold.ttf", FontSize = 18
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"0 0",
                                AnchorMax = $"1 1",
                                OffsetMax = "0 -5"
                            }
                        }
                    }
                },
                {
                    new CuiButton
                    {
                        RectTransform = { AnchorMin = "0.5 0", AnchorMax = "0.5 0", OffsetMin = "-70 5", OffsetMax = "70 25" },
                        Button = { Color = GetColor("#161616", 0.95f), Close = $"{UI_Layer}.TakeBlock" },
                        Text = { Text = $"ЗАКРЫТЬ", Align = TextAnchor.MiddleCenter, Font = "RobotoCondensed-Regular.ttf", FontSize = 16 }
                    }, $"{UI_Layer}.TakeBlock.Main"
                },
            };
            int counter = 0;
            int last = itmgiven.Count()-1;
            foreach (var itm in itmgiven)
            {
                container.Add(new CuiElement
                {
                    Parent = $"{UI_Layer}.TakeBlock.Main",
                    Name = $"{UI_Layer}.TakeBlock.Main.{counter}",
                    Components =
                            {
                                new CuiImageComponent
                                {
                                    Color = GetColor("#000000", 0f)
                                },
                                new CuiRectTransformComponent
                                {
                                    AnchorMin = $"0 0.5",
                                    AnchorMax = $"0 0.5",
                                    OffsetMin = $"{10 + counter*145} -70",
                                    OffsetMax = $"{145+(last==counter?5:0) + counter*145} 70"
                                }
                            }
                });

                container.Add(new CuiElement
                {
                    Parent = $"{UI_Layer}.TakeBlock.Main.{counter}",
                    Components =
                            {
                                new CuiRawImageComponent
                                {
                                    Png = string.IsNullOrEmpty(itm.Image)?GetImage(itm.ShortName):GetImage(GetNameByURL(itm.Image))
                                },
                                new CuiRectTransformComponent
                                {
                                    AnchorMin = $"0 0",
                                    AnchorMax = $"1 1"
                                }
                            }
                });
                container.Add(new CuiElement
                {
                    Parent = $"{UI_Layer}.TakeBlock.Main.{counter}",
                    Components =
                            {
                                new CuiTextComponent
                                {
                                    Text = $"x{itm.Amount}", Align = TextAnchor.LowerCenter, Font = "RobotoCondensed-Bold.ttf", FontSize = 26
                                },
                                new CuiRectTransformComponent
                                {
                                    AnchorMin = $"0 0",
                                    AnchorMax = $"1 1",
                                },
                                new CuiOutlineComponent { Distance = "0.5 -0.5", Color = GetColor("#000000", 1f)}
                            }
                });
                if(last != counter && last > 0)
                {
                    container.Add(new CuiElement
                    {
                        Parent = $"{UI_Layer}.TakeBlock.Main.{counter}",
                        Components =
                            {
                                new CuiImageComponent
                                {
                                    Color = GetColor("#FFFFFF", 1f)
                                },
                                new CuiRectTransformComponent
                                {
                                    AnchorMin = $"1 0",
                                    AnchorMax = $"1 1",
                                    OffsetMin = $"3 20",
                                    OffsetMax = $"5 -20"
                                }
                            }
        
// ... [Code preview truncated due to length. Full source in attached file] ...

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