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

FREE MainMenu : 1.0.0 1.0.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("MainMenu", "XAVIER", "1.0.0")]
    public class MainMenu : RustPlugin
    {
        [PluginReference] private Plugin ImageLibrary;



        void OnServerInitialized()
        {
            if (ImageLibrary == null || !ImageLibrary.IsLoaded)
            {
                PrintError("IMAGE LIBRARY IS NOT INSTALLED!");
            }
            else
            {
                var imagesList = new Dictionary<string, string>();
                
                if (!imagesList.ContainsKey(config.Logo))
                    imagesList.Add(config.Logo, config.Logo);
                if (!imagesList.ContainsKey(config.LogoMoney))
                    imagesList.Add(config.LogoMoney, config.LogoMoney);
                
                if (!imagesList.ContainsKey("https://i.imgur.com/MNaI53C.png"))
                    imagesList.Add("https://i.imgur.com/MNaI53C.png", "https://i.imgur.com/MNaI53C.png");


                ImageLibrary?.Call("ImportImageList", Title, imagesList, 0UL, true);
            }
        }
        
        
        public string HexToCuiColor(string HEX, float Alpha = 100)
        {
            if (string.IsNullOrEmpty(HEX)) HEX = "#FFFFFF";

            var str = HEX.Trim('#');
            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);

            return $"{(double) r / 255} {(double) g / 255} {(double) b / 255} {Alpha / 100}";
        }

        [PluginReference] private Plugin ShopSystem;


        public string Layer = "UI_MenuLayer";


        [ChatCommand("menu")]
        void OpenMain(BasePlayer player, string command, string[] args)
        {
            CuiHelper.DestroyUi(player, Layer);
            CuiElementContainer container = new CuiElementContainer();
            container.Add(new CuiPanel
            {
                CursorEnabled = true,
                RectTransform = { AnchorMin = "0 0", AnchorMax = "1 1"},
                Image =
                {
                    Color = HexToCuiColor("#19191C", 50)
                }
            }, "Overlay", Layer);
            
            
            container.Add(new CuiElement
            {
                Parent = Layer,
                Components =
                {
                    new CuiRawImageComponent
                        {FadeIn = 0.3f, Png = (string)ImageLibrary.Call("GetImage", "https://i.imgur.com/MNaI53C.png")},
                    new CuiRectTransformComponent
                        {AnchorMin = "0.125 0.08333331", AnchorMax = "0.875 0.9166667"}
                }
            });
            
            
            container.Add(new CuiElement
            {
                Parent = Layer,
                Components =
                {
                    new CuiRawImageComponent
                        {FadeIn = 0.3f, Png = (string)ImageLibrary.Call("GetImage", config.Logo)},
                    new CuiRectTransformComponent
                        {AnchorMin = "0.125 0.8314815", AnchorMax = "0.1671875 0.9166667"}
                }
            });
            container.Add(new CuiElement
            {
                Parent = Layer,
                Components =
                {
                    new CuiRawImageComponent
                        {FadeIn = 0.3f, Png = (string)ImageLibrary.Call("GetImage", config.LogoMoney)},
                    new CuiRectTransformComponent
                        {AnchorMin = "0.7625 0.862963", AnchorMax = "0.775 0.8851852"}
                }
            });
            
            container.Add(new CuiLabel
            {
                Text = { Text = $"{ShopSystem?.Call("GetCoin", player.userID)}",Font = "robotocondensed-regular.ttf", FontSize = 14, Color = HexToCuiColor("#BFBFBF"), Align = TextAnchor.MiddleLeft},
                RectTransform = { AnchorMin = $"0.7791666 0.862963", AnchorMax = $"0.8145833 0.8851852" },
            }, Layer);
            
            container.Add(new CuiButton
            {
                RectTransform = { AnchorMin = "0.8328053 0.8314815", AnchorMax = "0.8749916 0.9166667", OffsetMax = "0 0" },
                Button = { Color = "0 0 0 0", Close = Layer},
                Text = { Text = "X",Font = "robotocondensed-regular.ttf", FontSize = 23, Color = HexToCuiColor("#BFBFBF"), Align = TextAnchor.MiddleCenter }
            }, Layer);

            CuiHelper.AddUi(player, container);
            
            OpenListButton(player, "");

            OpenStartInfo(player);
        }

        void OpenStartInfo(BasePlayer player)
        {
            CuiHelper.DestroyUi(player, "StaticMenu");
            CuiElementContainer container = new CuiElementContainer();
            container.Add(new CuiElement 
            {
                Parent = Layer,
                Name = "StaticMenu",
                Components =
                {
                    new CuiImageComponent { Color = "0 0 0 0"},
                    new CuiRectTransformComponent {AnchorMin = "0.125 0.08333331", AnchorMax = "0.8755208 0.8324074"}
                }
            });
            
            container.Add(new CuiButton
            {
                RectTransform =
                {
                    AnchorMin =
                        "0 0",
                    AnchorMax =
                       "1 1",
                    OffsetMax = "0 0"
                },
                Button =
                {
                    Color = "0 0 0 0",
                    Command = $"",
                },
                Text =
                {
                    Text = config.StatInfo, Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf",
                    FontSize = 16, Color = HexToCuiColor($"#FBFBFF", 40),
                }
            }, "StaticMenu");

            CuiHelper.AddUi(player, container);
        }


        void OpenListButton(BasePlayer player, string button)
        {
            CuiElementContainer container = new CuiElementContainer();

            for (int i = 0; i < config._listButton.Count; i++)
            {
                CuiHelper.DestroyUi(player, Layer + $".{i}.ListButton");
            }

            foreach (var check in config._listButton.Select((i, t) => new { A = i, B = t }))
            {
                container.Add(new CuiButton
                {
                    RectTransform =
                    {
                        AnchorMin =
                            $"{0.1921875 + check.B * 0.0600 - Math.Floor((double) check.B / 9) * 9 * 0.0600} {0.8314815 - Math.Floor((double) check.B / 9) * 0.305}",
                        AnchorMax =
                            $"{0.2510417 + check.B * 0.0600 - Math.Floor((double) check.B / 9) * 9 * 0.0600} {0.9166667 - Math.Floor((double) check.B / 9) * 0.305}",
                        OffsetMax = "0 0"
                    },
                    Button =
                    {
                        Color = "0 0 0 0",
                        Command = button == check.A.Key ? "" : $"main.menu {check.A.Key}"
                    },
                    Text =
                    {
                        Color = button == check.A.Key ? HexToCuiColor("#FBFBFF") : HexToCuiColor($"#FBFBFF", 50),
                        Text = check.A.Key, Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf", FontSize = 12
                    }
                }, Layer, Layer + $".{check.B}.ListButton");
                
                container.Add(new CuiButton
                {
                    RectTransform =
                    {
                        AnchorMin = "0 0", AnchorMax = "1 0.01086855"
                    },
                    Button =
                    { 
                        Color = button == check.A.Key ? HexToCuiColor($"#FBFBFF") : HexToCuiColor($"#FBFBFF", 0),
                    },
                    Text =
                    {
                        Text = $"", Align = TextAnchor.LowerRight, Font = "robotocondensed-bold.ttf", FontSize = 15
                    }
                }, Layer + $".{check.B}.ListButton");
            }

            CuiHelper.AddUi(player, container);
        }


        [ConsoleCommand("main.menu")]
        void AcceptConsoleCommand(ConsoleSystem.Arg args)
        {
            BasePlayer player = args.Player();
            string name = args.Args[0];
            player.SendConsoleCommand(config._listButton[name]);
            OpenListButton(player, name);
        }
        
        
        
        
        
        #region Configuration

        
        private PluginConfig config;

        protected override void LoadDefaultConfig()
        {
            config = PluginConfig.DefaultConfig();
        }
        protected override void LoadConfig()
        {
            base.LoadConfig();
            config = Config.ReadObject<PluginConfig>();

            if (config.PluginVersion < Version)
                UpdateConfigValues();

            Config.WriteObject(config, true);
        }

        private void UpdateConfigValues()
        {
            PluginConfig baseConfig = PluginConfig.DefaultConfig();
            if (config.PluginVersion < new VersionNumber(1, 0, 8))
            {
                PrintWarning("Config update detected! Updating config values...");
                PrintWarning("Config update completed!");
            }
            config.PluginVersion = Version;
        }

        protected override void SaveConfig()
        {
            Config.WriteObject(config);
        }
        



        private class PluginConfig
        {
            [JsonProperty("Настройка кнопок")]
            public Dictionary<string, string> _listButton = new Dictionary<string, string>();

            [JsonProperty("Логотип")]
            public string Logo;

            [JsonProperty("Иконка монеты")] 
            public string LogoMoney;

            [JsonProperty("Статическое описание сервера")]
            public string StatInfo;


            [JsonProperty("Verison Configuration")]
            public VersionNumber PluginVersion = new VersionNumber();

            public static PluginConfig DefaultConfig()
            {
                return new PluginConfig()
                {
                    StatInfo = "<b>Описание сервера</b>\n\nтутутутут\nтутуту",
                    _listButton = new Dictionary<string, string>()
                    {
                        ["Информация"] = "open.infotab",
                        ["Магазин"] = "open.shoptab",
                        ["Вайпблок"] = "open.blocktab",
                        ["Игроки"] = "report.opentab",
                        ["Пропуск"] = "serverpass.opentab",
                        ["Скиллы"] = "skill",
                    },
                    Logo = "https://i.imgur.com/KNq3lRk.png",
                    LogoMoney = "https://i.imgur.com/XKkbCY1.png",
                    PluginVersion = new VersionNumber(),
                };
            }
        }

        #endregion
    }
}

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