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

FREE Logo : 0.0.1 0.0.1

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

namespace Oxide.Plugins
{
    [Info("Logo", "TopPlugin.ru", "0.0.1")]
    public class Logo : RustPlugin
    {
        #region Classess

        private class State
        {
            public bool IsOpened;
        }
        
        private class DataBase 
        { 
            [JsonProperty("Состояние игроков")]
            public Dictionary<ulong, State> States = new Dictionary<ulong, State>();
        }

        private class Button
        {
            public string ImageURL;
            public string Command;
        }

        private class Configuration
        {
            public List<Button> Buttons = new List<Button>();

            public static Configuration Generate()
            {
                return new Configuration
                {
                    Buttons = new List<Button>
                    {
                        new Button
                        {
                            ImageURL = "https://i.imgur.com/yhQSgLc.png",
                            Command  = "chat.say 1"
                        },
                        new Button
                        {
                            ImageURL = "https://i.imgur.com/yhQSgLc.png",
                            Command  = "chat.say 1"
                        },
                        new Button
                        {
                            ImageURL = "https://i.imgur.com/yhQSgLc.png",
                            Command  = "chat.say 1"
                        },
                        new Button
                        {
                            ImageURL = "https://i.imgur.com/yhQSgLc.png",
                            Command  = "chat.say 1"
                        },
                        new Button
                        {
                            ImageURL = "https://i.imgur.com/yhQSgLc.png",
                            Command  = "chat.say 1"
                        },
                        new Button
                        {
                            ImageURL = "https://i.imgur.com/yhQSgLc.png",
                            Command  = "chat.say 1"
                        },
                    }
                };
            }
        }
        
        #endregion

        #region Variables

        private DataBase Base = new DataBase();
        [PluginReference] private Plugin ImageLibrary;
        private static Configuration Settings;

        #endregion

        #region Initialization
        
        protected override void LoadConfig()
        {
            base.LoadConfig();
            try
            {
                Settings = Config.ReadObject<Configuration>();
            }
            catch
            {
                PrintWarning($"Error reading config, creating one new config!");
                LoadDefaultConfig();
            }

            SaveConfig();
        }

        [ChatCommand("help")]
        private void CmdChatHelp(BasePlayer player, string command, string[] args)
        {
            string layer = "UI_LogoLayerыdsagdsag";
            CuiHelper.DestroyUi(player, layer);
            CuiElementContainer container = new CuiElementContainer();
            
            container.Add(new CuiPanel()
            {
                CursorEnabled = true,
                RectTransform = {AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"},
                Image         = {Color     = "0 0 0 0"}
            }, "Overlay", layer);

            container.Add(new CuiButton
            {
                RectTransform = {AnchorMin = "0 0", AnchorMax    = "1 1", OffsetMax                                       = "0 0"},
                Button        = {Color     = "0 0 0 1", Material = "assets/content/ui/uibackgroundblur-notice.mat", Close = layer, Command = "closemenu"},
                Text          = {Text      = ""}
            }, layer);

            container.Add(new CuiElement
            {
                Parent = layer,
                Components =
                {
                    new CuiRawImageComponent() {Png          = (string) ImageLibrary.Call("GetImage", "HelpING")},
                    new CuiRectTransformComponent {AnchorMin = $"0.5 0.5", AnchorMax = $"0.5 0.5", OffsetMin = $"-426 -240", OffsetMax = $"426 240" }
                }
            }); 

            CuiHelper.AddUi(player, container);
        }

        protected override void LoadDefaultConfig() => Settings = Configuration.Generate();
        protected override void SaveConfig()        => Config.WriteObject(Settings);

        private void OnServerInitialized()
        {
            ImageLibrary.Call("AddImage", "https://i.imgur.com/VcUKv24.png", "Button"); // 151 215 
            ImageLibrary.Call("AddImage", "https://i.imgur.com/2nPmiga.png", "LogoIcon"); // 151 215
            ImageLibrary.Call("AddImage", "https://i.imgur.com/d1lEGkx.png", "LogoBG"); // 151 215
            
            ImageLibrary.Call("AddImage", "https://i.imgur.com/G5Izc7m.png", "HelpING"); // 1280x720 - СЮДА КАРТИНКУ ССЫЛКУ ХУЯРЬТЕ
            
            foreach (var check in Settings.Buttons)
            {
                ImageLibrary.Call("AddImage", check.ImageURL, $"B.{Settings.Buttons.IndexOf(check)}");
            }
            
            BasePlayer.activePlayerList.ToList().ForEach(OnPlayerInit);
            timer.Every(10, () =>
            {
                BasePlayer.activePlayerList.ToList().ForEach(p =>
                {
                    if (!Base.States[p.userID].IsOpened) return;
                    
                    CuiHelper.DestroyUi(p, Layer + ".Online");
                    CuiElementContainer container = new CuiElementContainer();
                    
                    container.Add(new CuiLabel
                    {
                        RectTransform = {AnchorMin = "0 0", AnchorMax                                    = "1 0", OffsetMax              = "15 20"},
                        Text          = {Text      = BasePlayer.activePlayerList.Count.ToString(), Align = TextAnchor.MiddleCenter, Font = "robotocondensed-bold.ttf", FontSize = 14, Color = "1 1 1 0.4"}
                    }, Layer + ".BG", Layer + ".Online");
                    
                    container.Add(new CuiButton
                    {
                        RectTransform = {AnchorMin = "0 0", AnchorMax   = "1 1", OffsetMax = "0 0"},
                        Button        = {Color     = "0 0 0 0", Command = "menu_upload"},
                        Text          = {Text      = ""}
                    }, Layer + ".Online");  

                    CuiHelper.AddUi(p, container);
                });
            });
        }

        private void OnPlayerInit(BasePlayer player)
        { 
            if (player.IsReceivingSnapshot)
            {
                NextTick(() => OnPlayerInit(player));
                return;
            }
             

            if (!Base.States.ContainsKey(player.userID))
                Base.States.Add(player.userID, new State { IsOpened = false });
            
            InitializeLogo(player, false);
        }

        #endregion

        #region Commands 

        [ConsoleCommand("menu_upload")]
        private void CmdConsoleHandler(ConsoleSystem.Arg args) => InitializeLogo(args.Player(), !Base.States[args.Player().userID].IsOpened);

        #endregion
        
        #region Interface

        private static string Layer = "UI_LogoLayer";
        private void InitializeLogo(BasePlayer player, bool open = true)
        {
            CuiElementContainer container = new CuiElementContainer();
            Base.States[player.userID].IsOpened = open;
            
            if (!open)
            {
                CuiHelper.DestroyUi(player, Layer);
                container.Add(new CuiPanel
                {
                    RectTransform = { AnchorMin = "0 1", AnchorMax = "0 1", OffsetMin = $"0 -95", OffsetMax = $"73 0" },
                    Image         = { Color     = "0 0 0 0" }
                }, "Overlay", Layer);

                container.Add(new CuiElement()
                {
                    Name   = Layer + ".BG",
                    Parent = Layer,
                    Components =
                    {
                        new CuiRawImageComponent() {Png          = (string) ImageLibrary.Call("GetImage", "LogoBG"), Color = "1 1 1 0"},
                        new CuiRectTransformComponent {AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"}
                    }
                });

                container.Add(new CuiElement()
                {
                    Parent = Layer + ".BG",
                    Components =
                    {
                        new CuiRawImageComponent {Png            = (string) ImageLibrary.Call("GetImage", "LogoIcon")},
                        new CuiRectTransformComponent {AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = $"-34 -35", OffsetMax = $"46 45"},
                        new CuiOutlineComponent { Distance = "1 1", Color = "0 0 0 1"} 
                    }
                });
                
                container.Add(new CuiButton 
                {
                    RectTransform = {AnchorMin = "0 0", AnchorMax   = "1 1", OffsetMax = "0 0"},
                    Button        = {Color     = "0 0 0 0", Command = "menu_upload"},
                    Text          = {Text      = ""}
                }, Layer + ".BG");
            }
            else
            {
                CuiHelper.DestroyUi(player, Layer);
                container.Add(new CuiPanel
                {
                    RectTransform = { AnchorMin = "0 1", AnchorMax = "0 1", OffsetMin = $"0 -95", OffsetMax = $"73 0" },
                    Image         = { Color     = "0 0 0 0" }
                }, "Overlay", Layer);

                container.Add(new CuiElement()
                { 
                    Parent = Layer,
                    Components =
                    {
                        new CuiRawImageComponent() {Png          = (string) ImageLibrary.Call("GetImage", "LogoBG"), Color = "1 1 1 1"},
                        new CuiRectTransformComponent {AnchorMin = "0 0", AnchorMax                                        = "1 1", OffsetMin = "-7 -5", OffsetMax = "17 15"}
                    }
                });

                container.Add(new CuiElement()
                {
                    Name   = Layer + ".BG",
                    Parent = Layer,
                    Components =
                    {
                        new CuiRawImageComponent() {Png          = (string) ImageLibrary.Call("GetImage", "LogoBG"), Color = "1 1 1 0"},
                        new CuiRectTransformComponent {AnchorMin = "0 0", AnchorMax                                        = "1 1", OffsetMax = "0 0"}
                    }
                });

                container.Add(new CuiElement()
                {
                    Parent = Layer + ".BG",
                    Components =
                    {
                        new CuiRawImageComponent {Png            = (string) ImageLibrary.Call("GetImage", "LogoIcon")},
                        new CuiRectTransformComponent {AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = $"-34 -35", OffsetMax = $"46 45"},
                        new CuiOutlineComponent { Distance       = "1 1", Color         = "0 0 0 1"}  
                    }
                });
                
                container.Add(new CuiButton 
                {
                    RectTransform = {AnchorMin = "0 0", AnchorMax   = "1 1", OffsetMax = "0 0"},
                    Button        = {Color     = "0 0 0 0", Command = "menu_upload"},
                    Text          = {Text      = ""}
                }, Layer + ".BG");

                container.Add(new CuiLabel
                {
                    RectTransform = {AnchorMin = "0 0", AnchorMax                                    = "1 0", OffsetMax              = "15 20"},
                    Text          = {Text      = BasePlayer.activePlayerList.Count.ToString(), Align = TextAnchor.MiddleCenter, Font = "robotocondensed-bold.ttf", FontSize = 14, Color = "1 1 1 0.4"}
                }, Layer + ".BG", Layer + ".Online");
                
                container.Add(new CuiButton
                {
                    RectTransform = {AnchorMin = "0 0", AnchorMax   = "1 1", OffsetMax = "0 0"},
                    Button        = {Color     = "0 0 0 0", Command = "menu_upload"},
                    Text          = {Text      = ""}
                }, Layer + ".BG");
                
                float topAnchor = 0; 
                foreach (var check in Settings.Buttons)
                {
                    container.Add(new CuiElement()
                    {
                        Name   = Layer + Settings.Buttons.IndexOf(check) + ".BG",
                        Parent = Layer + ".BG",
                        Components = 
                        {
                            new CuiRawImageComponent() {Png          = (string) ImageLibrary.Call("GetImage", $"Button"), Color = "1 1 1 0"},
                            new CuiRectTransformComponent {AnchorMin = "0 0", AnchorMax = "1 0", OffsetMin = $"7 {-70 - topAnchor}", OffsetMax = $"-3 {0 - topAnchor}"}
                        } 
                    }); 
                    container.Add(new CuiElement()
                    {  
                        Parent = Layer + Settings.Buttons.IndexOf(check) + ".BG",
                        Components = 
                        { 
                            new CuiRawImageComponent() {FadeIn = 1f, Png          = (string) ImageLibrary.Call("GetImage", $"B.{Settings.Buttons.IndexOf(check)}") },
                            new CuiRectTransformComponent {AnchorMin = "0 0", AnchorMax = "1 1", OffsetMin = $"10 7", OffsetMax = $"0 -10"}
                        } 
                    }); 
                    
                    container.Add(new CuiButton
                    {
                        RectTransform = {AnchorMin = "0 0", AnchorMax   = "1 1", OffsetMax = "0 0"},
                        Button        = {Color     = "0 0 0 0", Command = check.Command}, 
                        Text          = {Text      = ""}
                    }, Layer + Settings.Buttons.IndexOf(check) + ".BG"); 
                    
                    topAnchor += 60;
                }
            }

            CuiHelper.AddUi(player, container);
        }

        #endregion
    }
}

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