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

FREE WMenu : 1.0.0 1.0.0

Нет прав для скачивания
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using UnityEngine;
namespace Oxide.Plugins {
    [Info("WMenu", "WOLF#4002", "1.0.0")]
    [Description("Modal Menu")]
    class WMenu : RustPlugin {
        private class MenuPoint {
            [JsonProperty("NAME BUTTONS")]
            public string DisplayName;
            [JsonProperty("COMMAND")]
            public string DrawMethod;
        }
        private class ECO {
            [JsonProperty("NAME PLUGINS")]
            public string NAME;
            [JsonProperty("API - HOOK")]
            public string HOOK;
        }
        private class Configuration {
            [JsonProperty("LOGO")]
            public string Logo;
            [JsonProperty("SOUND EFFECT")]
            public string Sound;
            [JsonProperty("INACTIVE BUTTONS")]
            public string InActive;
            [JsonProperty("ACTIVE BUTTONS")]
            public string Active;
            [JsonProperty("ECONOMICS SETTINGS FIND BALANCE")]
            private ECO Eco = new ECO();
            [JsonProperty("POINTS")]
            public List<MenuPoint> Points = new List<MenuPoint>();
            public static Configuration Generate() {
                return new Configuration {
                    Logo = "https://i.imgur.com/mNLcOjc.jpg", Sound = "assets/bundled/prefabs/fx/notice/stack.world.fx.prefab", InActive = "0.929 0.882 0.847 0.2", Active = "0.929 0.882 0.847 1", Eco = new ECO {
                        NAME = "UniversalShop", HOOK = "API_ShopGetBalance",
                    }
                    , Points = new List<MenuPoint> {
                        new MenuPoint {
                            DisplayName = "SHOP", DrawMethod = "chat.say /shop",
                        }
                        , new MenuPoint {
                            DisplayName = "KIT", DrawMethod = "chat.say /KIT"
                        }
                        , new MenuPoint {
                            DisplayName = "REPORT", DrawMethod = "chat.say /report",
                        }
                        , new MenuPoint {
                            DisplayName = "КАЛЕНДАРЬ", DrawMethod = "chat.say /wipe"
                        }
                        , new MenuPoint {
                            DisplayName = "КАЛЕНДА", DrawMethod = "chat.say /wipe"
                        }
                        ,
                    }
                }
                ;
            }
        }
        private static Configuration Settings = null;
        protected override void LoadConfig() {
            base.LoadConfig();
            try {
                Settings = Config.ReadObject<Configuration>();
            }
            catch {
                PrintWarning($"Error reading config, creating one new config!");
                LoadDefaultConfig();
            }
            SaveConfig();
        }
        protected override void LoadDefaultConfig() => Settings = Configuration.Generate();
        protected override void SaveConfig() => Config.WriteObject(Settings);
        private string In = "Menu";
        private string Internal = "WMenu";
        private string Point = "W";
        [PluginReference]
        private Plugin ImageLibrary;
        void OnServerInitialized() {
            ImageLibrary.Call("AddImage", Settings.Logo, "logo");
            ImageLibrary.Call("AddImage", "https://i.imgur.com/tHzAex5.png", "on");
            ImageLibrary.Call("AddImage", "https://i.imgur.com/2IcjgUn.png", "off");
            ImageLibrary.Call("AddImage", "https://i.imgur.com/5DhNOcP.png", "time");
            ImageLibrary.Call("AddImage", "https://i.imgur.com/pXbsTaL.png", "bal");
            ImageLibrary.Call("AddImage", "https://i.imgur.com/uPBySg9.png", "close");
            BasePlayer.activePlayerList.ToList().ForEach(OnPlayerConnected);
        }
        void Unload() {
            foreach (BasePlayer player in BasePlayer.activePlayerList) {
                CuiHelper.DestroyUi(player, In);
                CuiHelper.DestroyUi(player, Internal);
                CuiHelper.DestroyUi(player, Point);
                CuiHelper.DestroyUi(player, "fff");
            }
        }
        void OnPlayerConnected(BasePlayer player) {
            DrawMenu(player);
            Points1(player);
        }
        void DrawMenu(BasePlayer player) {
            CuiHelper.DestroyUi(player, In);
            CuiElementContainer container = new CuiElementContainer();
            container.Add(new CuiPanel {
                CursorEnabled = true, RectTransform = {
                    AnchorMin = "0 0", AnchorMax = "1 1"
                }
                , Image = {
                    Color = "0 0 0 0.8", Material = "assets/content/ui/uibackgroundblur-ingamemenu.mat"
                }
            }
            , "Overlay", In);
            container.Add(new CuiPanel {
                RectTransform = {
                    AnchorMin = "0 0", AnchorMax = "0.15 1"
                }
                , Image = {
                    Color = "0 0 0 0"
                }
            }
            , In, Point);
            container.Add(new CuiElement {
                Parent = Point, Components = {
                    new CuiRawImageComponent {
                        Png = (string) ImageLibrary.Call("GetImage", "logo")
                    }
                    , new CuiRectTransformComponent {
                        AnchorMin = "0 0.9", AnchorMax = "1 0.98"
                    }
                }
            }
            );
            container.Add(new CuiPanel {
                RectTransform = {
                    AnchorMin = "0.15 0.92", AnchorMax = "1 1"
                }
                , Image = {
                    Color = "0 0 1 0"
                }
            }
            , In, In + "l");
            container.Add(new CuiElement {
                Parent = In + "l", Name = In + "close", Components = {
                    new CuiRawImageComponent {
                        Png = (string) ImageLibrary.Call("GetImage", "close")
                    }
                    , new CuiRectTransformComponent {
                        AnchorMin = "0.952 0", AnchorMax = "1 1"
                    }
                }
            }
            );
            container.Add(new CuiButton {
                RectTransform = {
                    AnchorMin = "0 0", AnchorMax = "1 1"
                }
                , Button = {
                    Color = "1 1 1 0", Command = "Menu close"
                }
                , Text = {
                    Text = "", Color = "0.929 0.882 0.847 0.05", Align = TextAnchor.LowerCenter, Font = "robotocondensed-regular.ttf", FontSize = 14
                }
            }
            , In + "close");
            CuiHelper.AddUi(player, container);
            DrawMenuPoints(player);
            DrawInfo(player);
            DrawSocial(player);
        }
        void DrawSocial(BasePlayer player) {
            CuiElementContainer container = new CuiElementContainer();
            CuiHelper.AddUi(player, container);
        }
        void DrawInfo(BasePlayer player) {
            CuiHelper.DestroyUi(player, In + "online");
            CuiHelper.DestroyUi(player, In + "time");
            CuiHelper.DestroyUi(player, In + "balans");
            CuiHelper.DestroyUi(player, In + "offline");
            CuiElementContainer container = new CuiElementContainer();
            container.Add(new CuiPanel {
                RectTransform = {
                    AnchorMin = "0.01 0.5", AnchorMax = "0.1 1"
                }
                , Image = {
                    Color = "0.55 0.78 0.24 0"
                }
            }
            , In + "l", In + "online");
            container.Add(new CuiElement {
                Parent = In + "online", Components = {
                    new CuiRawImageComponent {
                        Png = (string) ImageLibrary.Call("GetImage", "on")
                    }
                    , new CuiRectTransformComponent {
                        AnchorMin = "0 0.15", AnchorMax = "0.2 0.82"
                    }
                }
            }
            );
            container.Add(new CuiElement {
                Parent = In + "online", Components = {
                    new CuiTextComponent {
                        Text = $"{BasePlayer.activePlayerList.ToList().Count} / {ServerMgr.Instance.connectionQueue.joining.Count} / {ServerMgr.Instance.connectionQueue.queue.Count}", Align = TextAnchor.MiddleCenter, FontSize = 13, Font = "robotocondensed-bold.ttf", Color = "0.55 0.78 0.24 1"
                    }
                    , new CuiRectTransformComponent {
                        AnchorMin = "0.2 0", AnchorMax = "1 1"
                    }
                    , new CuiOutlineComponent {
                        Color = "0 0 0 1", Distance = "1 1"
                    }
                }
            }
            );
            container.Add(new CuiPanel {
                RectTransform = {
                    AnchorMin = "0.01 0", AnchorMax = "0.1 0.5"
                }
                , Image = {
                    Color = "0.8 0.28 0.2 0"
                }
            }
            , In + "l", In + "time");
            container.Add(new CuiElement {
                Parent = In + "time", Components = {
                    new CuiRawImageComponent {
                        Png = (string) ImageLibrary.Call("GetImage", "time")
                    }
                    , new CuiRectTransformComponent {
                        AnchorMin = "0 0.15", AnchorMax = "0.2 0.82"
                    }
                }
            }
            );
            container.Add(new CuiElement {
                Parent = In + "time", Components = {
                    new CuiTextComponent {
                        Text = $"{covalence.Server.Time.ToShortTimeString()}", Align = TextAnchor.MiddleCenter, FontSize = 13, Font = "robotocondensed-bold.ttf", Color = "1 1 1 1"
                    }
                    , new CuiRectTransformComponent {
                        AnchorMin = "0.2 0", AnchorMax = "1 1"
                    }
                    , new CuiOutlineComponent {
                        Color = "0 0 0 1", Distance = "1 1"
                    }
                }
            }
            );
            container.Add(new CuiPanel {
                RectTransform = {
                    AnchorMin = "0.11 0", AnchorMax = "0.2 0.5"
                }
                , Image = {
                    Color = "0.55 0.78 0.24 0"
                }
            }
            , In + "l", In + "balans");
            container.Add(new CuiElement {
                Parent = In + "balans", Components = {
                    new CuiRawImageComponent {
                        Png = (string) ImageLibrary.Call("GetImage", "bal")
                    }
                    , new CuiRectTransformComponent {
                        AnchorMin = "0 0.15", AnchorMax = "0.2 0.82"
                    }
                }
            }
            );
            var balic = (int)plugins.Find("UniversalShop").CallHook("API_ShopGetBalance", player.userID);
            container.Add(new CuiElement {
                Parent = In + "balans", Components = {
                    new CuiTextComponent {
                        Text = $"{balic}", Align = TextAnchor.MiddleCenter, FontSize = 13, Font = "robotocondensed-bold.ttf", Color = "1 1 1 1"
                    }
                    , new CuiRectTransformComponent {
                        AnchorMin = "0.2 0", AnchorMax = "1 1"
                    }
                    , new CuiOutlineComponent {
                        Color = "0 0 0 1", Distance = "1 1"
                    }
                }
            }
            );
            container.Add(new CuiPanel {
                RectTransform = {
                    AnchorMin = "0.11 0.5", AnchorMax = "0.2 1"
                }
                , Image = {
                    Color = "0.8 0.28 0.2 0"
                }
            }
            , In + "l", In + "offline");
            container.Add(new CuiElement {
                Parent = In + "offline", Components = {
                    new CuiRawImageComponent {
                        Png = (string) ImageLibrary.Call("GetImage", "off")
                    }
                    , new CuiRectTransformComponent {
                        AnchorMin = "0 0.15", AnchorMax = "0.2 0.82"
                    }
                }
            }
            );
            container.Add(new CuiElement {
                Parent = In + "offline", Components = {
                    new CuiTextComponent {
                        Text = $"{BasePlayer.sleepingPlayerList.Count.ToString()}", Align = TextAnchor.MiddleCenter, FontSize = 13, Font = "robotocondensed-bold.ttf", Color = "0.8 0.28 0.2 1"
                    }
                    , new CuiRectTransformComponent {
                        AnchorMin = "0.2 0", AnchorMax = "1 1"
                    }
                    , new CuiOutlineComponent {
                        Color = "0 0 0 1", Distance = "1 1"
                    }
                }
            }
            );
            CuiHelper.AddUi(player, container);
        }
        void DrawMenuPoints(BasePlayer player, MenuPoint choosed = null) {
            CuiElementContainer container = new CuiElementContainer();
            float marginTop = -120;
            float originalHeight = 30;
            float freeHeight = 20;
            float padding = 5;
            foreach (var point in Settings.Points) {
                CuiHelper.DestroyUi(player, Point + Settings.Points.IndexOf(point));
                string color = point == choosed ? Settings.Active : Settings.InActive;
                float elementHeight = point.DisplayName.Length > 0 ? originalHeight : freeHeight;
                container.Add(new CuiButton {
                    RectTransform = {
                        AnchorMin = "0 1", AnchorMax = "0 1", OffsetMin = $"10 {marginTop - elementHeight}", OffsetMax = $"180 {marginTop}"
                    }
                    , Button = {
                        Command = $"Menu choose {Settings.Points.IndexOf(point)}", Color = "1 0 0 0"
                    }
                    , Text = {
                        Text = "", Align = TextAnchor.MiddleLeft, Font = "robotocondensed-bold.ttf", FontSize = 26, Color = color
                    }
                }
                , Point, Point + Settings.Points.IndexOf(point));
                container.Add(new CuiElement {
                    Parent = Point + Settings.Points.IndexOf(point), Components = {
                        new CuiTextComponent {
                            Text = point.DisplayName, Align = TextAnchor.MiddleCenter, FontSize = 26, Font = "robotocondensed-bold.ttf", Color = color
                        }
                        , new CuiRectTransformComponent {
                            AnchorMin = "0 0", AnchorMax = "1 1"
                        }
                        , new CuiOutlineComponent {
                            Color = "0 0 0 1", Distance = "1 1"
                        }
                    }
                }
                );
                marginTop -= elementHeight + padding;
            }
            CuiHelper.AddUi(player, container);
        }
        [ChatCommand("menu")]
        private void Open(BasePlayer player) {
            DrawMenu(player);
        }
        void Points1(BasePlayer player) {
            CuiElementContainer container = new CuiElementContainer();
            CuiHelper.DestroyUi(player, "fff");
            container.Add(new CuiPanel {
                RectTransform = {
                    AnchorMin = "0.8375 0", AnchorMax = "0.986 0.018"
                }
                , Image = {
                    Color = "0 0 0 0.8"
                }
            }
            , "Overlay", "fff");
            container.Add(new CuiButton {
                RectTransform = {
                    AnchorMin = "0 0", AnchorMax = "1 1"
                }
                , Button = {
                    Command = "chat.say /menu", Color = "0.8 0.28 0.2 1", Material = "assets/content/ui/uibackgroundblur.mat"
                }
                , Text = {
                    Text = "MENU", Align = TextAnchor.MiddleCenter, FontSize = 12
                }
            }
            , "fff");
            CuiHelper.AddUi(player, container);
        }
        [ConsoleCommand("Menu")]
        private void CmdConsoleRustMenu(ConsoleSystem.Arg args) {
            var player = args.Player();
            if (player == null || !args.HasArgs(1)) return;
            switch (args.Args[0].ToLower()) {
                case "close" : {
                    CuiHelper.DestroyUi(player, In);
                    CuiHelper.DestroyUi(player, Internal);
                    CuiHelper.DestroyUi(player, Point);
                    break;
                }
                case "choose" : {
                    int chooseIndex = -1;
                    if (!int.TryParse(args.Args[1], out chooseIndex)) return;
                    var chooseElement = Settings.Points.ElementAtOrDefault(chooseIndex);
                    if (chooseElement == null) return;
                    CuiHelper.DestroyUi(player, Internal);
                    CuiElementContainer container = new CuiElementContainer();
                    container.Add(new CuiPanel {
                        RectTransform = {
                            AnchorMin = "0.16 0", AnchorMax = "1 0.92"
                        }
                        , Image = {
                            Color = "0 1 0 0"
                        }
                    }
                    , "Overlay", Internal);
                    CuiHelper.AddUi(player, container);
                    player.SendConsoleCommand(chooseElement.DrawMethod);
                    DrawMenuPoints(player, chooseElement);
                    DrawInfo(player);
                    Effect effect = new Effect(Settings.Sound, player, 0, new Vector3(), new Vector3());
                    EffectNetwork.Send(effect, player.Connection);
                    break;
                }
            }
        }
    }
}

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