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

FREE TopCrosshair : 7.0.0 7.0.0

Нет прав для скачивания
C#:
using UnityEngine;
using UnityEngine.UI;
using Oxide.Game.Rust.Cui;
using Newtonsoft.Json;
using System.Linq;
using System;
using Oxide.Core;
using Oxide.Core.Configuration;
using Oxide.Core.Plugins;
using Oxide.Core.Libraries;
using System;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
namespace Oxide.Plugins {
    [Info("TopCrosshair", "https://topplugin.ru/", "7.0.0")]
    class TopCrosshair : RustPlugin {
        [PluginReference]
        private Plugin ImageLibrary;
        protected const string OverGUI = "TCOverUI";
        protected const string MainGUI = "TCElementsUI";
        protected const string CrossGUI = "TCCrosshairUI";
#region Configuration
        private Configuration config;
        private class Configuration {
            [JsonProperty("Настройки оформления", Order = 0)]
            public GUISettings GUI = new GUISettings();
            [JsonProperty("Изображения иконок прицела", Order = 1)]
            public Configuration.CrosshairImages CrossImages = new Configuration.CrosshairImages();
            [JsonProperty("Цвета прицела", Order = 2)]
            public Configuration.CrosshairColors CrossColors = new Configuration.CrosshairColors();
            [JsonProperty("Размер прицела в пикселях", Order = 3)]
            public Configuration.CrosshairSizes CrossSizes = new Configuration.CrosshairSizes();
            [JsonProperty("Пермишен для доступа", Order = 4)]
            public string Perm = "topcrosshair.use";
            [JsonProperty("Команда для доступа", Order = 5)]
            public string Command = "cross";
            public static Configuration GetNewConfig() {
                Configuration newConfig = new Configuration() {
                    GUI = new GUISettings() {
                        HeaderText = "[ НАСТРОЙКА ПРИЦЕЛА ]", OverlayColor = "#000000AA", BgColor = "#284655AA", PanelColor = "#363940A0", ActiveBorder = "#363940D0", NotActiveBorder = "#7878786a", BackgroundElement = "#5A5E6A5A"
                    }
                    , CrossImages = new Configuration.CrosshairImages() {
                        Image1="https://i.ibb.co/R34bJv2/1.png", Image2="https://i.ibb.co/VBWywgK/2.png", Image3="https://i.ibb.co/F4sx0TL/3.png", Image4="https://i.ibb.co/Dfnq5bs/4.png"
                    }
                    , CrossColors = new Configuration.CrosshairColors() {
                        Color1="#ec0618", Color2="#ba0ac6", Color3="#320bc6", Color4="#0bb2c6", Color5="#0bc722"
                    }
                    , CrossSizes = new Configuration.CrosshairSizes() {
                        Size1 = 16, Size2 = 20, Size3 = 24, Size4 = 32, Size5 = 48
                    }
                    , Perm = "topcrosshair.use", Command = "cross"
                }
                ;
                return newConfig;
            }
            public class GUISettings {
                [JsonProperty("Заголовок окна", Order = 0)]
                public string HeaderText = "[ НАСТРОЙКА ПРИЦЕЛА ]";
                [JsonProperty("Цвет заднего фона (затенение)", Order = 1)]
                public string OverlayColor = "#000000AA";
                [JsonProperty("Цвет заднего фона окна настроек", Order = 2)]
                public string BgColor = "#284655AA";
                [JsonProperty("Цвет панелек категорий", Order = 3)]
                public string PanelColor = "#363940A0";
                [JsonProperty("Цвет рамки активного элемента", Order = 4)]
                public string ActiveBorder = "#363940D0";
                [JsonProperty("Цвет рамки неактивного элемента", Order = 5)]
                public string NotActiveBorder = "#7878786a";
                [JsonProperty("Цвет элемента", Order = 6)]
                public string BackgroundElement = "#5A5E6A5A";
            }
            public class CrosshairImages {
                [JsonProperty("Изображение 1", Order = 0)]
                public string Image1 = "https://i.ibb.co/R34bJv2/1.png";
                [JsonProperty("Изображение 2", Order = 1)]
                public string Image2 = "https://i.ibb.co/VBWywgK/2.png";
                [JsonProperty("Изображение 3", Order = 2)]
                public string Image3 = "https://i.ibb.co/F4sx0TL/3.png";
                [JsonProperty("Изображение 4", Order = 3)]
                public string Image4 = "https://i.ibb.co/Dfnq5bs/4.png";
            }
            public class CrosshairColors {
                [JsonProperty("Цвет 1", Order = 0)]
                public string Color1 = "#ec0618";
                [JsonProperty("Цвет 2", Order = 1)]
                public string Color2 = "#ba0ac6";
                [JsonProperty("Цвет 3", Order = 2)]
                public string Color3 = "#320bc6";
                [JsonProperty("Цвет 4", Order = 3)]
                public string Color4 = "#0bb2c6";
                [JsonProperty("Цвет 5", Order = 4)]
                public string Color5 = "#0bc722";
            }
            public class CrosshairSizes {
                [JsonProperty("Размер 1", Order = 0)]
                public int Size1 = 16;
                [JsonProperty("Размер 2", Order = 0)]
                public int Size2 = 20;
                [JsonProperty("Размер 3", Order = 0)]
                public int Size3 = 24;
                [JsonProperty("Размер 4", Order = 0)]
                public int Size4 = 32;
                [JsonProperty("Размер 5", Order = 0)]
                public int Size5 = 48;
            }
        }
        protected override void LoadConfig() {
            base.LoadConfig();
            try {
                config = Config.ReadObject<Configuration>();
                if (config.GUI==null || config.CrossImages==null || config.CrossColors ==null || config.CrossSizes == null || config.Command == null) LoadDefaultConfig();
            }
            catch {
                LoadDefaultConfig();
            }
            NextTick(SaveConfig);
        }
        protected override void LoadDefaultConfig() => config = Configuration.GetNewConfig();
        protected override void SaveConfig() => Config.WriteObject(config);
#endregion
#region Data
        public Dictionary<ulong, UserSettings> PlayerSettings = new Dictionary<ulong, UserSettings>();
        public class UserSettings {
            [JsonProperty("Выбранная иконка", Order = 1)]
            public int Image = 0;
            [JsonProperty("Выбранный цвет", Order = 2)]
            public int Color = 0;
            [JsonProperty("Выбранный размер", Order = 3)]
            public int Size = 0;
        }
        void LoadPlayerSettings() {
            Puts("Load cross data");
            try {
                PlayerSettings = Oxide.Core.Interface.Oxide.DataFileSystem.ReadObject <Dictionary<ulong, UserSettings>>("TopCrosshair");
                if (PlayerSettings==null) PlayerSettings = new Dictionary<ulong, UserSettings>();
            }
            catch {
                PlayerSettings = new Dictionary<ulong, UserSettings>();
            }
        }
        //При сохранении данных
        void OnServerSave() {
            Oxide.Core.Interface.Oxide.DataFileSystem.WriteObject("TopCrosshair", PlayerSettings);
        }
        void OnServerShutdown() {
            Oxide.Core.Interface.Oxide.DataFileSystem.WriteObject("TopCrosshair", PlayerSettings);
        }
#endregion
        void OnServerInitialized() {
            LoadPlayerSettings();
            //Регистрируем пермишены
            if (!string.IsNullOrEmpty(config.Perm)) permission.RegisterPermission(config.Perm, this);
            //cmd.AddChatCommand(config.Command, this, "CrossSettings");
            if (config.CrossImages == null) {
                PrintError("Plugin not configured");
                return;
            }
            if (ImageLibrary) {
                //Подгружаем изображения прицела
                ImageLibrary.Call("AddImage", "https://i.ibb.co/Jdtxtwv/image.png", "CrossImgNo");
                ImageLibrary.Call("AddImage", config.CrossImages.Image1, "CrossImgNo1");
                ImageLibrary.Call("AddImage", config.CrossImages.Image2, "CrossImgNo2");
                ImageLibrary.Call("AddImage", config.CrossImages.Image3, "CrossImgNo3");
                ImageLibrary.Call("AddImage", config.CrossImages.Image4, "CrossImgNo4");
            }
            foreach (BasePlayer player in BasePlayer.activePlayerList) {
                OnPlayerConnected(player);
            }
        }
        private void OnPlayerConnected(BasePlayer player) {
            if (player == null) return;
            if ((player is BaseNpc) || (player is ScientistNPC) || (player.IsNpc)) return;
            if (player.IsReceivingSnapshot) {
                NextTick(() => OnPlayerConnected(player));
                return;
            }
            //Получаем данные по игроку
            if (!PlayerSettings.ContainsKey(player.userID)) {
                PlayerSettings.Add(player.userID, new UserSettings());
            }
            NextTick(() =>ShowCrossUI(player));
        }
        void Unload() {
            //Сохраняем данные
            Oxide.Core.Interface.Oxide.DataFileSystem.WriteObject("TopCrosshair", PlayerSettings);
            foreach (BasePlayer player in BasePlayer.activePlayerList) {
                UnloadWindowGUI(player);
                UnloadCrossGUI(player);
            }
        }
        private void OnPlayerDisconnected(BasePlayer player) {
            UnloadWindowGUI(player);
            UnloadCrossGUI(player);
        }
        void UnloadWindowGUI(BasePlayer player) {
            CuiHelper.DestroyUi(player, OverGUI);
            CuiHelper.DestroyUi(player, MainGUI);
        }
        void UnloadCrossGUI(BasePlayer player) {
            CuiHelper.DestroyUi(player, CrossGUI);
        }
#region GUI
        void ShowCrossUI(BasePlayer player) {
            UnloadCrossGUI(player);
            if (player==null) return;
            //Получаем данные по игроку
            if (!PlayerSettings.ContainsKey(player.userID)) {
                PlayerSettings.Add(player.userID, new UserSettings());
            }
            UserSettings Sets = PlayerSettings[player.userID];
            if (Sets.Image==0) return;
            string image = config.CrossImages.Image1;
            switch(Sets.Image) {
                case 1 : image = "CrossImgNo1";
                break;
                case 2 : image = "CrossImgNo2";
                break;
                case 3 : image = "CrossImgNo3";
                break;
                case 4 : image = "CrossImgNo4";
                break;
            }
            int CSize = (int)(24/2);
            switch(Sets.Size) {
                case 1 : CSize = (int)(config.CrossSizes.Size1/2);
                break;
                case 2 : CSize = (int)(config.CrossSizes.Size2/2);
                break;
                case 3 : CSize = (int)(config.CrossSizes.Size3/2);
                break;
                case 4 : CSize = (int)(config.CrossSizes.Size4/2);
                break;
                case 5 : CSize = (int)(config.CrossSizes.Size5/2);
                break;
            }
            if (CSize>22) CSize=22;
            string color= config.CrossColors.Color1;
            switch(Sets.Color) {
                case 1 : color = config.CrossColors.Color1;
                break;
                case 2 : color = config.CrossColors.Color2;
                break;
                case 3 : color = config.CrossColors.Color3;
                break;
                case 4 : color = config.CrossColors.Color4;
                break;
                case 5 : color = config.CrossColors.Color5;
                break;
            }
            CuiElementContainer CrossContainer = new CuiElementContainer();
            AddHudPanelOffset(ref CrossContainer, CrossGUI, "0.5 0.5", "0.5 0.5", "-32 -32", "32 32", "#00000000", false);
            AddImageColorOffset(ref CrossContainer, CrossGUI, "0.5 0.5", "0.5 0.5", $"-{CSize} -{CSize}", $"{CSize} {CSize}", (string)(ImageLibrary?.CallHook("GetImage", image) ?? ""), color);
            CuiHelper.AddUi(player, CrossContainer);
        }
        void ShowCrossWindow(BasePlayer player, bool update = false) {
            if (!update) {
                UnloadWindowGUI(player);
            }
            else {
                CuiHelper.DestroyUi(player, MainGUI);
            }
            string bg=config.GUI.NotActiveBorder;
            //Получаем данные по игроку
            if (!PlayerSettings.ContainsKey(player.userID)) {
                PlayerSettings.Add(player.userID, new UserSettings());
            }
            if ((!permission.UserHasPermission(player.UserIDString, config.Perm)&& (!player.IsAdmin))) //
            {
                CuiElementContainer ElementsContainer2 = new CuiElementContainer();
                AddOverlayPanelOffset(ref ElementsContainer2, "Menu_UI2", MainGUI, "0.5 0.5", "0.5 0.5", "-350 -110", "350 110", "#00000000");
                AddLabel(ref ElementsContainer2, MainGUI, MainGUI, "0 0", "1 1", " У вас нет доступа для выбора прицела", 24, TextAnchor.MiddleCenter, "#bbc2c8DD");
                CuiHelper.AddUi(player, ElementsContainer2);
                return;
            }
            UserSettings Sets = PlayerSettings[player.userID];
            int CSize = (int)(24/2);
            switch(Sets.Size) {
                case 1 : CSize = (int)(config.CrossSizes.Size1/2);
                break;
                case 2 : CSize = (int)(config.CrossSizes.Size2/2);
                break;
                case 3 : CSize = (int)(config.CrossSizes.Size3/2);
                break;
                case 4 : CSize = (int)(config.CrossSizes.Size4/2);
                break;
                case 5 : CSize = (int)(config.CrossSizes.Size5/2);
                break;
            }
            if (CSize>22) CSize=22;
            string color= config.CrossColors.Color1;
            switch(Sets.Color) {
                case 1 : color = config.CrossColors.Color1;
                break;
                case 2 : color = config.CrossColors.Color2;
                break;
                case 3 : color = config.CrossColors.Color3;
                break;
                case 4 : color = config.CrossColors.Color4;
                break;
                case 5 : color = config.CrossColors.Color5;
                break;
            }
            /*
			if (!update){
			//Подложка
				CuiElementContainer OverContainer = new CuiElementContainer();
				AddOverlayPanel(ref OverContainer, OverGUI, "0 0","1 1", config.GUI.OverlayColor, true);
				AddButton(ref OverContainer,OverGUI, "0 0", "1 1", "#00000000","closeMainGUI","",15,TextAnchor.MiddleCenter, "#FFFFFF00");
				AddElementOffset(ref OverContainer, OverGUI+"_main", OverGUI, "0.5 0.5","0.5 0.5", "-150 -105", "150 110", config.GUI.BgColor,"");
				AddLabel(ref OverContainer, "HEADER", OverGUI+"_main", "0 0.88", "1 1", config.GUI.HeaderText, 14, TextAnchor.MiddleCenter, "#bbc2c8FD");
				CuiHelper.AddUi(player, OverContainer);
			}*/
            //СОДЕРЖИМОЕ
            CuiElementContainer ElementsContainer = new CuiElementContainer();
            AddOverlayPanelOffset(ref ElementsContainer, "Menu_UI2", MainGUI, "0.5 0.5", "0.5 0.5", "-150 -110", "150 110", "#00000000");
            //ПАНЕЛЬКА ИКОНОК
            AddElementOffset(ref ElementsContainer, MainGUI+"_images", MainGUI, "0 1", "1 1", "0 -100", "0 -25", config.GUI.PanelColor);
            AddLabel(ref ElementsContainer, "HEADER", MainGUI+"_images", "0 0.75", "1 1", "Выберите вид прицела:", 11, TextAnchor.MiddleCenter, "#bbc2c8DD");
            //ИКОНКА 0
            if (Sets.Image==0) {
                bg = config.GUI.ActiveBorder;
            }
            else {
                bg=config.GUI.NotActiveBorder;
            }
            AddElementOffset(ref ElementsContainer, MainGUI+"_images_0", MainGUI+"_images", "0 0", "0 0", "10 5", "60 55", bg);
            AddElement(ref ElementsContainer, MainGUI+"_images_0_inner", MainGUI+"_images_0", "0.05 0.05", "0.94 0.94", config.GUI.BackgroundElement);
            AddLabel(ref ElementsContainer, "NO", MainGUI+"_images_0_inner", "0 0", "1 1", "[ВЫКЛ]", 12, TextAnchor.MiddleCenter, "#bbc2c8DD");
            //AddImage(ref ElementsContainer, MainGUI+"_images_0_inner", "0.05 0.05", "0.95 0.95", (string)(ImageLibrary?.CallHook("GetImage", "CrossImgNo") ?? "https://i.ibb.co/Jdtxtwv/image.png"));
            AddButton(ref ElementsContainer, MainGUI+"_images_0", "0.05 0.05", "0.95 0.95", "#00000000", "SetCross image 0", "", 15, TextAnchor.MiddleCenter, "#FFFFFF00");
            //ИКОНКА 1
            if (Sets.Image==1) {
                bg = config.GUI.ActiveBorder;
            }
            else {
                bg=config.GUI.NotActiveBorder;
            }
            AddElementOffset(ref ElementsContainer, MainGUI+"_images_1", MainGUI+"_images", "0 0", "0 0", "67 5", "117 55", bg);
            AddElement(ref ElementsContainer, MainGUI+"_images_1_inner", MainGUI+"_images_1", "0.05 0.05", "0.94 0.94", config.GUI.BackgroundElement);
            AddImageColorOffset(ref ElementsContainer, MainGUI+"_images_1_inner", "0.5 0.5", "0.5 0.5", $"-{CSize} -{CSize}", $"{CSize} {CSize}", (string)(ImageLibrary?.CallHook("GetImage", "CrossImgNo1") ?? "https://i.ibb.co/Jdtxtwv/image.png"), color);
            AddButton(ref ElementsContainer, MainGUI+"_images_1", "0.05 0.05", "0.95 0.95", "#00000000", "SetCross image 1", "", 15, TextAnchor.MiddleCenter, "#FFFFFF00");
            //ИКОНКА 2
            if (Sets.Image==2) {
                bg = config.GUI.ActiveBorder;
            }
            else {
                bg=config.GUI.NotActiveBorder;
            }
            AddElementOffset(ref ElementsContainer, MainGUI+"_images_2", MainGUI+"_images", "0 0", "0 0", "124 5", "174 55", bg);
            AddElement(ref ElementsContainer, MainGUI+"_images_2_inner", MainGUI+"_images_2", "0.05 0.05", "0.94 0.94", config.GUI.BackgroundElement);
            AddImageColorOffset(ref ElementsContainer, MainGUI+"_images_2_inner", "0.5 0.5", "0.5 0.5", $"-{CSize} -{CSize}", $"{CSize} {CSize}", (string)(ImageLibrary?.CallHook("GetImage", "CrossImgNo2") ?? "https://i.ibb.co/Jdtxtwv/image.png"), color);
            AddButton(ref ElementsContainer, MainGUI+"_images_2", "0.05 0.05", "0.95 0.95", "#00000000", "SetCross image 2", "", 15, TextAnchor.MiddleCenter, "#FFFFFF00");
            //ИКОНКА 3
            if (Sets.Image==3) {
                bg = config.GUI.ActiveBorder;
            }
            else {
                bg=config.GUI.NotActiveBorder;
            }
            AddElementOffset(ref ElementsContainer, MainGUI+"_images_3", MainGUI+"_images", "0 0", "0 0", "181 5", "231 55", bg);
            AddElement(ref ElementsContainer, MainGUI+"_images_3_inner", MainGUI+"_images_3", "0.05 0.05", "0.94 0.94", config.GUI.BackgroundElement);
            AddImageColorOffset(ref ElementsContainer, MainGUI+"_images_3_inner", "0.5 0.5", "0.5 0.5", $"-{CSize} -{CSize}", $"{CSize} {CSize}", (string)(ImageLibrary?.CallHook("GetImage", "CrossImgNo3") ?? "https://i.ibb.co/Jdtxtwv/image.png"), color);
            AddButton(ref ElementsContainer, MainGUI+"_images_3", "0.05 0.05", "0.95 0.95", "#00000000", "SetCross image 3", "", 15, TextAnchor.MiddleCenter, "#FFFFFF00");
            //ИКОНКА 4
            if (Sets.Image==4) {
                bg = config.GUI.ActiveBorder;
            }
            else {
                bg=config.GUI.NotActiveBorder;
            }
            AddElementOffset(ref ElementsContainer, MainGUI+"_images_4", MainGUI+"_images", "0 0", "0 0", "238 5", "288 55", bg);
            AddElement(ref ElementsContainer, MainGUI+"_images_4_inner", MainGUI+"_images_4", "0.05 0.05", "0.94 0.94", config.GUI.BackgroundElement);
            AddImageColorOffset(ref ElementsContainer, MainGUI+"_images_4_inner", "0.5 0.5", "0.5 0.5", $"-{CSize} -{CSize}", $"{CSize} {CSize}", (string)(ImageLibrary?.CallHook("GetImage", "CrossImgNo4") ?? "https://i.ibb.co/Jdtxtwv/image.png"), color);
            AddButton(ref ElementsContainer, MainGUI+"_images_4", "0.05 0.05", "0.95 0.95", "#00000000", "SetCross image 4", "", 15, TextAnchor.MiddleCenter, "#FFFFFF00");
            //ПАНЕЛЬКА ЦВЕТА
            AddElementOffset(ref ElementsContainer, MainGUI+"_colors", MainGUI, "0 1", "1 1", "0 -155", "0 -105", config.GUI.PanelColor);
            AddLabel(ref ElementsContainer, "HEADER2", MainGUI+"_colors", "0 0.7", "1 1", "Выберите цвет прицела:", 11, TextAnchor.MiddleCenter, "#bbc2c8DD");
            //ЦВЕТ 1
            if (Sets.Color==1) {
                bg = config.GUI.ActiveBorder;
            }
            else {
                bg=config.GUI.NotActiveBorder;
            }
            AddElementOffset(ref ElementsContainer, MainGUI+"_colors_0", MainGUI+"_colors", "0 0", "0 0", "10 5", "60 30", bg);
            AddElement(ref ElementsContainer, MainGUI+"_colors_0_inner", MainGUI+"_colors_0", "0.05 0.1", "0.94 0.9", config.CrossColors.Color1);
            AddButton(ref ElementsContainer, MainGUI+"_colors_0", "0.05 0.05", "0.95 0.95", "#00000000", "SetCross color 1", "", 15, TextAnchor.MiddleCenter, "#FFFFFF00");
            //ЦВЕТ 2
            if (Sets.Color==2) {
                bg = config.GUI.ActiveBorder;
            }
            else {
                bg=config.GUI.NotActiveBorder;
            }
            AddElementOffset(ref ElementsContainer, MainGUI+"_colors_1", MainGUI+"_colors", "0 0", "0 0", "67 5", "117 30", bg);
            AddElement(ref ElementsContainer, MainGUI+"_colors_1_inner", MainGUI+"_colors_1", "0.05 0.1", "0.94 0.9", config.CrossColors.Color2);
            AddButton(ref ElementsContainer, MainGUI+"_colors_1", "0.05 0.05", "0.95 0.95", "#00000000", "SetCross color 2", "", 15, TextAnchor.MiddleCenter, "#FFFFFF00");
            //ЦВЕТ 3
            if (Sets.Color==3) {
                bg = config.GUI.ActiveBorder;
            }
            else {
                bg=config.GUI.NotActiveBorder;
            }
            AddElementOffset(ref ElementsContainer, MainGUI+"_colors_2", MainGUI+"_colors", "0 0", "0 0", "124 5", "174 30", bg);
            AddElement(ref ElementsContainer, MainGUI+"_colors_2_inner", MainGUI+"_colors_2", "0.05 0.1", "0.94 0.9", config.CrossColors.Color3);
            AddButton(ref ElementsContainer, MainGUI+"_colors_2", "0.05 0.05", "0.95 0.95", "#00000000", "SetCross color 3", "", 15, TextAnchor.MiddleCenter, "#FFFFFF00");
            //ЦВЕТ 4
            if (Sets.Color==4) {
                bg = config.GUI.ActiveBorder;
            }
            else {
                bg=config.GUI.NotActiveBorder;
            }
            AddElementOffset(ref ElementsContainer, MainGUI+"_colors_3", MainGUI+"_colors", "0 0", "0 0", "181 5", "231 30", bg);
            AddElement(ref ElementsContainer, MainGUI+"_colors_3_inner", MainGUI+"_colors_3", "0.05 0.1", "0.94 0.9", config.CrossColors.Color4);
            AddButton(ref ElementsContainer, MainGUI+"_colors_3", "0.05 0.05", "0.95 0.95", "#00000000", "SetCross color 4", "", 15, TextAnchor.MiddleCenter, "#FFFFFF00");
            //ЦВЕТ 5
            if (Sets.Color==5) {
                bg = config.GUI.ActiveBorder;
            }
            else {
                bg=config.GUI.NotActiveBorder;
            }
            AddElementOffset(ref ElementsContainer, MainGUI+"_colors_4", MainGUI+"_colors", "0 0", "0 0", "238 5", "288 30", bg);
            AddElement(ref ElementsContainer, MainGUI+"_colors_4_inner", MainGUI+"_colors_4", "0.05 0.1", "0.94 0.9", config.CrossColors.Color5);
            AddButton(ref ElementsContainer, MainGUI+"_colors_4", "0.05 0.05", "0.95 0.95", "#00000000", "SetCross color 5", "", 15, TextAnchor.MiddleCenter, "#FFFFFF00");
            //ПАНЕЛЬКА РАЗМЕРА
            AddElementOffset(ref ElementsContainer, MainGUI+"_sizes", MainGUI, "0 1", "1 1", "0 -213", "0 -160", config.GUI.PanelColor);
            AddLabel(ref ElementsContainer, "HEADER3", MainGUI+"_sizes", "0 0.7", "1 1", "Выберите размер прицела:", 11, TextAnchor.MiddleCenter, "#bbc2c8DD");
            //РАЗМЕР 1
            if (Sets.Size==1) {
                bg = config.GUI.ActiveBorder;
            }
            else {
                bg=config.GUI.NotActiveBorder;
            }
            AddElementOffset(ref ElementsContainer, MainGUI+"_sizes_0", MainGUI+"_sizes", "0 0", "0 0", "10 5", "60 35", bg);
            AddElement(ref ElementsContainer, MainGUI+"_sizes_0_inner", MainGUI+"_sizes_0", "0.05 0.068", "0.94 0.912", config.GUI.BackgroundElement);
            AddLabel(ref ElementsContainer, "HEADER3", MainGUI+"_sizes_0", "0 0", "1 1", $"{config.CrossSizes.Size1} x {config.CrossSizes.Size1}", 11, TextAnchor.MiddleCenter, "#bbc2c8DD");
            AddButton(ref ElementsContainer, MainGUI+"_sizes_0", "0.05 0.05", "0.95 0.95", "#00000000", "SetCross size 1", "", 15, TextAnchor.MiddleCenter, "#FFFFFF00");
            //РАЗМЕР 2
            if (Sets.Size==2) {
                bg = config.GUI.ActiveBorder;
            }
            else {
                bg=config.GUI.NotActiveBorder;
            }
            AddElementOffset(ref ElementsContainer, MainGUI+"_sizes_1", MainGUI+"_sizes", "0 0", "0 0", "67 5", "117 35", bg);
            AddElement(ref ElementsContainer, MainGUI+"_sizes_1_inner", MainGUI+"_sizes_1", "0.05 0.068", "0.94 0.912", config.GUI.BackgroundElement);
            AddLabel(ref ElementsContainer, "HEADER3", MainGUI+"_sizes_1", "0 0", "1 1", $"{config.CrossSizes.Size2} x {config.CrossSizes.Size2}", 11, TextAnchor.MiddleCenter, "#bbc2c8DD");
            AddButton(ref ElementsContainer, MainGUI+"_sizes_1", "0.05 0.05", "0.95 0.95", "#00000000", "SetCross size 2", "", 15, TextAnchor.MiddleCenter, "#FFFFFF00");
            //РАЗМЕР 3
            if (Sets.Size==3) {
                bg = config.GUI.ActiveBorder;
            }
            else {
                bg=config.GUI.NotActiveBorder;
            }
            AddElementOffset(ref ElementsContainer, MainGUI+"_sizes_2", MainGUI+"_sizes", "0 0", "0 0", "124 5", "174 35", bg);
            AddElement(ref ElementsContainer, MainGUI+"_sizes_2_inner", MainGUI+"_sizes_2", "0.05 0.068", "0.94 0.912", config.GUI.BackgroundElement);
            AddLabel(ref ElementsContainer, "HEADER3", MainGUI+"_sizes_2", "0 0", "1 1", $"{config.CrossSizes.Size3} x {config.CrossSizes.Size3}", 11, TextAnchor.MiddleCenter, "#bbc2c8DD");
            AddButton(ref ElementsContainer, MainGUI+"_sizes_2", "0.05 0.05", "0.95 0.95", "#00000000", "SetCross size 3", "", 15, TextAnchor.MiddleCenter, "#FFFFFF00");
            //РАЗМЕР 4
            if (Sets.Size==4) {
                bg = config.GUI.ActiveBorder;
            }
            else {
                bg=config.GUI.NotActiveBorder;
            }
            AddElementOffset(ref ElementsContainer, MainGUI+"_sizes_3", MainGUI+"_sizes", "0 0", "0 0", "181 5", "231 35", bg);
            AddElement(ref ElementsContainer, MainGUI+"_sizes_3_inner", MainGUI+"_sizes_3", "0.05 0.068", "0.94 0.912", config.GUI.BackgroundElement);
            AddLabel(ref ElementsContainer, "HEADER3", MainGUI+"_sizes_3", "0 0", "1 1", $"{config.CrossSizes.Size4} x {config.CrossSizes.Size4}", 11, TextAnchor.MiddleCenter, "#bbc2c8DD");
            AddButton(ref ElementsContainer, MainGUI+"_sizes_3", "0.05 0.05", "0.95 0.95", "#00000000", "SetCross size 4", "", 15, TextAnchor.MiddleCenter, "#FFFFFF00");
            //РАЗМЕР 5
            if (Sets.Size==5) {
                bg = config.GUI.ActiveBorder;
            }
            else {
                bg=config.GUI.NotActiveBorder;
            }
            AddElementOffset(ref ElementsContainer, MainGUI+"_sizes_4", MainGUI+"_sizes", "0 0", "0 0", "238 5", "288 35", bg);
            AddElement(ref ElementsContainer, MainGUI+"_sizes_4_inner", MainGUI+"_sizes_4", "0.05 0.068", "0.94 0.912", config.GUI.BackgroundElement);
            AddLabel(ref ElementsContainer, "HEADER3", MainGUI+"_sizes_4", "0 0", "1 1", $"{config.CrossSizes.Size5} x {config.CrossSizes.Size5}", 11, TextAnchor.MiddleCenter, "#bbc2c8DD");
            AddButton(ref ElementsContainer, MainGUI+"_sizes_4", "0.05 0.05", "0.95 0.95", "#00000000", "SetCross size 5", "", 15, TextAnchor.MiddleCenter, "#FFFFFF00");
            CuiHelper.AddUi(player, ElementsContainer);
        }
        private void CrossSettings(BasePlayer player, string command, string[] args) {
            if (player == null) return;
            if ((!permission.UserHasPermission(player.UserIDString, config.Perm)) && (!player.IsAdmin)) {
                PrintToChat(player, "Недостаточно полномочий для использования прицела");
                return;
            }
            ShowCrossWindow(player);
        }
        [ConsoleCommand("closeMainGUI" )]
        void CloseMainGUI(ConsoleSystem.Arg Args) {
            BasePlayer player = Args.Player();
            if (player == null) return;
            UnloadWindowGUI(player);
            ShowCrossUI(player);
        }
        [ConsoleCommand("SetCross" )]
        void SetCrossCmd(ConsoleSystem.Arg args) {
            BasePlayer player = args.Player();
            if (player == null) return;
            if (!args.HasArgs(2)) {
                PrintError($"No params");
                return;
            }
            string command = args.Args[0];
            int val=0;
            if (!int.TryParse(args.Args[1], out val)) {
                PrintError("not int. set 0");
                val=0;
            }
            //Получаем данные по игроку
            if (!PlayerSettings.ContainsKey(player.userID)) {
                PlayerSettings.Add(player.userID, new UserSettings());
            }
            switch (command) {
                case "image" : PlayerSettings[player.userID].Image=val;
                break;
                case "color" : PlayerSettings[player.userID].Color=val;
                break;
                case "size" : PlayerSettings[player.userID].Size=val;
                break;
                default : PrintError("SetCross default");
                break;
            }
            Effect.server.Run("assets/prefabs/tools/flashlight/effects/turn_on.prefab", player.transform.position);
            ShowCrossWindow(player, true);
            ShowCrossUI(player);
            return;
        }
#endregion
#region GUI_FUNCTIONS
        private static void AddHudPanelOffset(ref CuiElementContainer container, string Parent, string AMin, string AMax, string OMin, string OMax, string color, bool cursor=true) {
            container.Add(new CuiPanel {
                Image = {
                    Color = HexToCuiColor(color)
                }
                ,  //FadeOut = 1.0f,
                RectTransform = {
                    AnchorMin = AMin, AnchorMax = AMax, OffsetMin = OMin, OffsetMax = OMax
                }
                , CursorEnabled = cursor
            }
            , "Hud", Parent);
        }
        private static void AddOverlayPanelOffset(ref CuiElementContainer container, string Parent, string Name, string AMin, string AMax, string OMin, string OMax, string color, bool cursor=true) {
            container.Add(new CuiPanel {
                Image = {
                    Color = HexToCuiColor(color)
                }
                ,  //FadeOut = 1.0f,
                RectTransform = {
                    AnchorMin = AMin, AnchorMax = AMax, OffsetMin = OMin, OffsetMax = OMax
                }
                , CursorEnabled = cursor
            }
            , Parent, Name);
        }
        /*
		private static void AddOverlayPanel(ref CuiElementContainer container,string Parent,string Name, string AMin, string AMax, string color, bool cursor=true) {
            container.Add(new CuiPanel {
				//FadeOut = 1.0f,
                Image = {Color = HexToCuiColor(color),FadeIn = 0.5f}, 
				RectTransform = {AnchorMin = AMin, AnchorMax = AMax}, 
				CursorEnabled = cursor
            }, Parent, Name);
        }*/
        public static void AddButton(ref CuiElementContainer container, string Parent, string aMin, string aMax, string bgcolor, string command, string text, int fontsize, TextAnchor align = TextAnchor.MiddleCenter, string labelColor = "") {
            container.Add(new CuiButton {
                //FadeOut = 1.0f,
                Button = {
                    Color = HexToCuiColor(bgcolor), Command = command
                }
                , RectTransform = {
                    AnchorMin = aMin, AnchorMax = aMax
                }
                , Text = {
                    Text = text, FontSize = fontsize, Align = align, Color = HexToCuiColor(labelColor), Font = "robotocondensed-regular.ttf"
                }
            }
            , Parent);
        }
        public static void AddButtonOffset(ref CuiElementContainer container, string Parent, string aMin, string aMax, string OMin, string OMax, string bgcolor, string command, string text, int fontsize, TextAnchor align = TextAnchor.MiddleCenter, string labelColor = "") {
            container.Add(new CuiButton {
                //FadeOut = 1.0f,
                Button = {
                    Color = HexToCuiColor(bgcolor), Command = command
                }
                , RectTransform = {
                    AnchorMin = aMin, AnchorMax = aMax, OffsetMin = OMin, OffsetMax = OMax
                }
                , Text = {
                    Text = text, FontSize = fontsize, Align = align, Color = HexToCuiColor(labelColor), Font = "robotocondensed-regular.ttf"
                }
            }
            , Parent);
        }
        private static void AddLabel(ref CuiElementContainer container, string Name, string Parent, string AMin, string AMax, string text, int fontsize, TextAnchor align, string labelColor) {
            container.Add(new CuiLabel {
                //FadeOut = 1.0f,
                Text = {
                    FontSize = fontsize, Align = align, Text = text, Font = "robotocondensed-regular.ttf", Color = HexToCuiColor(labelColor)
                }
                , RectTransform = {
                    AnchorMin = AMin, AnchorMax = AMax
                }
            }
            , Parent , Name);
        }
        static public void AddImage(ref CuiElementContainer container, string Parent, string aMin, string aMax, string img) {
            if (img.StartsWith("http") || img.StartsWith("www")) {
                container.Add(new CuiElement {
                    //FadeOut = 1.0f,
                    Parent = Parent, Components = {
                        new CuiRawImageComponent {
                            Url = img, Sprite = "assets/content/textures/generic/fulltransparent.tga"
                        }
                        , new CuiRectTransformComponent {
                            AnchorMin = aMin, AnchorMax = aMax
                        }
                    }
                }
                );
            }
            else container.Add(new CuiElement {
                Parent = Parent,  //FadeOut = 1.0f,
                Components = {
                    new CuiRawImageComponent {
                        Png = img, Sprite = "assets/content/textures/generic/fulltransparent.tga"
                    }
                    , new CuiRectTransformComponent {
                        AnchorMin = aMin, AnchorMax = aMax
                    }
                }
            }
            );
        }
        static public void AddImageColorOffset(ref CuiElementContainer container, string Parent, string aMin, string aMax, string oMin, string oMax, string img, string color, string material = "") {
            CuiRawImageComponent ImgComp = new CuiRawImageComponent {
                Color = HexToCuiColor(color), Sprite = "assets/content/textures/generic/fulltransparent.tga"
            }
            ;
            if (img.StartsWith("http") || img.StartsWith("www")) {
                ImgComp.Url = img;
            }
            else ImgComp.Png = img;
            if (!string.IsNullOrEmpty(material)) ImgComp.Material=material;
            //			{Url = img, ;
            container.Add(new CuiElement {
                //FadeOut = 1.0f,
                Parent = Parent, Components = {
                    ImgComp, new CuiRectTransformComponent {
                        AnchorMin = aMin, AnchorMax = aMax, OffsetMin = oMin, OffsetMax = oMax
                    }
                }
            }
            );
        }
        static public void AddImageColor(ref CuiElementContainer container, string Parent, string aMin, string aMax, string img, string color) {
            if (img.StartsWith("http") || img.StartsWith("www")) {
                container.Add(new CuiElement {
                    //FadeOut = 1.0f,
                    Parent = Parent, Components = {
                        new CuiRawImageComponent {
                            Url = img, Color = HexToCuiColor(color), Sprite = "assets/content/textures/generic/fulltransparent.tga"
                        }
                        , new CuiRectTransformComponent {
                            AnchorMin = aMin, AnchorMax = aMax
                        }
                    }
                }
                );
            }
            else container.Add(new CuiElement {
                Parent = Parent,  //FadeOut = 1.0f,
                Components = {
                    new CuiRawImageComponent {
                        Png = img, Color = HexToCuiColor(color), Sprite = "assets/content/textures/generic/fulltransparent.tga"
                    }
                    , new CuiRectTransformComponent {
                        AnchorMin = aMin, AnchorMax = aMax
                    }
                }
            }
            );
        }
        static public void AddElement(ref CuiElementContainer container, string Name, string Parent, string aMin, string aMax, string color, string material = "") {
            CuiImageComponent imgComp = new CuiImageComponent {
                Color = HexToCuiColor(color)
            }
            ;
            if (!string.IsNullOrEmpty(material)) imgComp.Material=material;
            container.Add(new CuiElement {
                Parent = Parent, Name = Name,  //FadeOut = 1.0f,
                Components = {
                    imgComp, new CuiRectTransformComponent {
                        AnchorMin = aMin, AnchorMax = aMax
                    }
                }
            }
            );
        }
        static public void AddElementOffset(ref CuiElementContainer container, string Name, string Parent, string aMin, string aMax, string oMin, string oMax, string color, string material = "") {
            CuiImageComponent imgComp = new CuiImageComponent {
                Color = HexToCuiColor(color)
            }
            ;
            if (!string.IsNullOrEmpty(material)) imgComp.Material=material;
            container.Add(new CuiElement {
                Parent = Parent, Name = Name,  //FadeOut = 1.0f,
                Components = {
                    imgComp, new CuiRectTransformComponent {
                        AnchorMin = aMin, AnchorMax = aMax, OffsetMin = oMin, OffsetMax = oMax
                    }
                }
            }
            );
        }
#endregion GUI_FUNCTIONS
#region Helper
        private static string HexToCuiColor(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 оценок
Сверху