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

FREE RustPanel : 1.0.2 1.0.2

Нет прав для скачивания
C#:
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq;
using Oxide.Core;
using Oxide.Core.Configuration;
using Oxide.Core.Plugins;
using Rust;
using System;
using System.Collections.Generic;
using System.Globalization;
using UnityEngine;
using Oxide.Game.Rust.Cui;
using Facepunch;
using UnityEngine.SceneManagement;
using Rust.Workshop;
using System.Collections;
namespace Oxide.Plugins {
    [Info("RustPanel", "Skuli Dropek", "1.0.2")]
    public class RustPanel : RustPlugin {
        static class RustStore {
            /// <summary>
            ///
            /// </summary>
            /// <param name="SteamID"></param>
            /// <param name="count"></param>
            /// <param name="responce">If all good - retorn "SUCCESS"</param>
            public static void APIChangeUserBalance(ulong SteamID, int count, Action<string> responce) => _plugin.plugins.Find("RustStore").CallHook("APIChangeUserBalance", SteamID, count, responce);
        }
        static string DefaultColor = "0.882 0.882 0.882 0.8";
        static string BackgroundColor = "0.969 0.922 0.882 0.035";
        static string ActiveColor = "1 0.647 0 0.8";
        static string FieldRaidBlockColor = "0.858 0.058 0 0.8";
        static string FieldRadHouseColor = "0.584 0.868 0.282 0.8";
        //"0 0.784 0 0.8";
        static string FieldRemoveColor = "1 0.647 0 0.8";
        static string FieldBuildingUpgradeColor = "1 0.647 0 0.8";
        static string FieldMultiEventColor = "0.584 0.868 0.282 0.8";
        static string FieldJoinColor = "0 0.519 1 0.8";
        static string FieldDefaultColor = "1 0.647 0 0.8";
        static string FieldBackgroundColor = "0.165 0.165 0.165 0.8";
        static bool IsLoadedServer = false;
        static void MSGAdmin(BasePlayer player, string message) {
            if (!player.IsAdmin) return;
            player.SendConsoleCommand($"echo {message}");
        }
        void OnPlayerInit(BasePlayer player) {
            MSGAdmin(player, "OnPlayerInit");
            Interface.Oxide.NextTick(() => RustPanelData.GetOrAdd(player));
        }
        void OnPlayerDisconnected(BasePlayer player, string reason) => player?.GetComponent<RustPanelData>()?.Destroy();
        static string _GUI_RP => $"{_plugin.Title}.{_plugin.Author}.{_plugin.Version}.RP";
        [PluginReference("ImageLibrary")]
        public Core.Plugins.Plugin ImageLibrary;
        public static class IMGLibrary {
            public static bool AddImage(string url, string imageName, ulong imageId = 0, Action callback = null) => (bool)_plugin.ImageLibrary.Call("AddImage", url, imageName, imageId, callback);
            public static bool AddImageData(string imageName, byte[] array, ulong imageId = 0, Action callback = null) => (bool)_plugin.ImageLibrary.Call("AddImageData", imageName, array, imageId, callback);
            public static string GetImageURL(string imageName, ulong imageId = 0) => (string)_plugin.ImageLibrary.Call("GetImageURL", imageName, imageId);
            public static string GetImage(string imageName, ulong imageId = 0, bool returnUrl = false) => (string)_plugin.ImageLibrary.Call("GetImage", imageName, imageId, returnUrl);
            public static List<ulong> GetImageList(string name) => (List<ulong>)_plugin.ImageLibrary.Call("GetImageList", name);
            public static Dictionary<string, object> GetSkinInfo(string name, ulong id) => (Dictionary<string, object>)_plugin.ImageLibrary.Call("GetSkinInfo", name, id);
            public static bool HasImage(string imageName, ulong imageId) => (bool)_plugin.ImageLibrary.Call("HasImage", imageName, imageId);
            public static bool IsInStorage(uint crc) => (bool)_plugin.ImageLibrary.Call("IsInStorage", crc);
            public static bool IsReady() => (bool)_plugin.ImageLibrary.Call("IsReady");
            public static void ImportImageList(string title, Dictionary<string, string> imageList, ulong imageId = 0, bool replace = false, Action callback = null) => _plugin.ImageLibrary.Call("ImportImageList", title, imageList, imageId, replace, callback);
            public static void ImportItemList(string title, Dictionary<string, Dictionary<ulong, string>> itemList, bool replace = false, Action callback = null) => _plugin.ImageLibrary.Call("ImportItemList", title, itemList, replace, callback);
            public static void ImportImageData(string title, Dictionary<string, byte[]> imageList, ulong imageId = 0, bool replace = false, Action callback = null) => _plugin.ImageLibrary.Call("ImportImageData", title, imageList, imageId, replace, callback);
            public static void LoadImageList(string title, List<KeyValuePair<string, ulong>> imageList, Action callback = null) => _plugin.ImageLibrary.Call("LoadImageList", title, imageList, callback);
            public static void RemoveImage(string imageName, ulong imageId) => _plugin?.ImageLibrary?.Call("RemoveImage", imageName, imageId);
        }
        public static RustPanel _plugin = null;
        public class ConfigData {
            public static string Image_Clock {
                get {
                    return GetConfig("Image", "Clock", $"Clock.png").Replace("/", "\\");
                }
                set {
                    SetConfig(true, "Image", "Clock", value);
                }
            }
            public static string Image_Players {
                get {
                    return GetConfig("Image", "Players", $"Players.png").Replace("/", "\\");
                }
                set {
                    SetConfig(true, "Image", "Players", value);
                }
            }
            public static string Image_Cargo {
                get {
                    return GetConfig("Image", "Cargo", $"Cargo.png").Replace("/", "\\");
                }
                set {
                    SetConfig(true, "Image", "Cargo", value);
                }
            }
            public static string Image_Ship {
                get {
                    return GetConfig("Image", "Ship", $"Ship.png").Replace("/", "\\");
                }
                set {
                    SetConfig(true, "Image", "Ship", value);
                }
            }
            public static string Image_Plane {
                get {
                    return GetConfig("Image", "Plane", $"Plane.png").Replace("/", "\\");
                }
                set {
                    SetConfig(true, "Image", "Plane", value);
                }
            }
            public static string Image_Heli {
                get {
                    return GetConfig("Image", "Heli", $"Heli.png").Replace("/", "\\");
                }
                set {
                    SetConfig(true, "Image", "Heli", value);
                }
            }
            public static string Image_ArrowLeft {
                get {
                    return GetConfig("Image", "ArrowLeft", $"ArrowLeft.png").Replace("/", "\\");
                }
                set {
                    SetConfig(true, "Image", "ArrowLeft", value);
                }
            }
            public static string Image_ArrowRight {
                get {
                    return GetConfig("Image", "ArrowRight", $"ArrowRight.png").Replace("/", "\\");
                }
                set {
                    SetConfig(true, "Image", "ArrowRight", value);
                }
            }
            public static string Image_Pistol {
                get {
                    return GetConfig("Image", "Pistol", $"Pistol.png").Replace("/", "\\");
                }
                set {
                    SetConfig(true, "Image", "Pistol", value);
                }
            }
            public static string Image_RaidBlock {
                get {
                    return GetConfig("Image", "RaidBlock", $"RaidBlock.png").Replace("/", "\\");
                }
                set {
                    SetConfig(true, "Image", "RaidBlock", value);
                }
            }
            public static string Image_RadHouse {
                get {
                    return GetConfig("Image", "RadHouse", $"RadHouse.png").Replace("/", "\\");
                }
                set {
                    SetConfig(true, "Image", "RadHouse", value);
                }
            }
            public static string Image_BuildingUpgrade {
                get {
                    return GetConfig("Image", "BuildingUpgrade", $"BuildingUpgrade.png").Replace("/", "\\");
                }
                set {
                    SetConfig(true, "Image", "BuildingUpgrade", value);
                }
            }
            public static string Image_Remove {
                get {
                    return GetConfig("Image", "Remove", $"Remove.png").Replace("/", "\\");
                }
                set {
                    SetConfig(true, "Image", "Remove", value);
                }
            }
            public static string Image_MultiEvent {
                get {
                    return GetConfig("Image", "MultiEvent", $"MultiEvent.png").Replace("/", "\\");
                }
                set {
                    SetConfig(true, "Image", "MultiEvent", value);
                }
            }
            public static void LoadAndSaveAll() {
                IEnumerator enumerator = typeof(ConfigData).GetProperties(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public).GetEnumerator();
                while (enumerator.MoveNext()) {
                    System.Reflection.PropertyInfo propertyInfo = (System.Reflection.PropertyInfo)enumerator.Current;
                    propertyInfo.SetValue(null, propertyInfo.GetValue(null));
                }
            }
            public static void SetConfig(bool replace, string group, string key, object value) {
                if (replace || _plugin.Config.Get(group, key) == null) _plugin.Config.Set(group, key, value);
                _plugin.Config.Save();
            }
            public static T GetConfig<T>(string group, string key, T defaultVal) {
                if (_plugin.Config.Get(group, key) == null) {
                    SetConfig(false, group, key, defaultVal);
                    return defaultVal;
                }
                try {
                    return _plugin.Config.Get<T>(group, key);
                }
                catch {
                    return _plugin.Config.Get<JToken>(group, key).ToObject<T>();
                }
            }
            static string Vector3ToString(Vector3 pos) => $"{pos.x} {pos.y} {pos.z}";
            static Vector3 StringToVector3(string pos) => new Vector3(Convert.ToSingle(pos.Split(' ')[0]), Convert.ToSingle(pos.Split(' ')[1]), Convert.ToSingle(pos.Split(' ')[2]));
        }
        new void LoadDefaultConfig() => PrintError("No config file found, generating a new one.");
        new void LoadConfig() {
            ConfigData.LoadAndSaveAll();
            SaveConfig();
        }
        void OnServerInitialized() => timer.Once(1, () => {
            CheckInvokeTime(() => {
                ImageLibrary = ImageLibrary ?? plugins.Find("ImageLibrary") ?? plugins.Find("Image Library");
                LoadConfig();
                if (ImageLibrary == null) throw new Exception($"[{this.Title}] Plugin 'ImageLibrary' not found!..");
                Dictionary<string, string> loadImages = new Dictionary<string, string>() {
                    ["IMG.RP-Clock"]
                    = Interface.GetMod().DataDirectory + System.IO.Path.DirectorySeparatorChar + "panel" + System.IO.Path.DirectorySeparatorChar + ConfigData.Image_Clock, ["IMG.RP-Players"] = Interface.GetMod().DataDirectory + System.IO.Path.DirectorySeparatorChar + "panel" + System.IO.Path.DirectorySeparatorChar + ConfigData.Image_Players, ["IMG.RP-Cargo"] = Interface.GetMod().DataDirectory + System.IO.Path.DirectorySeparatorChar + "panel" + System.IO.Path.DirectorySeparatorChar + ConfigData.Image_Cargo, ["IMG.RP-Ship"] = Interface.GetMod().DataDirectory + System.IO.Path.DirectorySeparatorChar + "panel" + System.IO.Path.DirectorySeparatorChar + ConfigData.Image_Ship, ["IMG.RP-Plane"] = Interface.GetMod().DataDirectory + System.IO.Path.DirectorySeparatorChar + "panel" + System.IO.Path.DirectorySeparatorChar + ConfigData.Image_Plane, ["IMG.RP-Heli"] = Interface.GetMod().DataDirectory + System.IO.Path.DirectorySeparatorChar + "panel" + System.IO.Path.DirectorySeparatorChar + ConfigData.Image_Heli, ["IMG.RP-ArrowLeft"] = Interface.GetMod().DataDirectory + System.IO.Path.DirectorySeparatorChar + "panel" + System.IO.Path.DirectorySeparatorChar + ConfigData.Image_ArrowLeft, ["IMG.RP-ArrowRight"] = Interface.GetMod().DataDirectory + System.IO.Path.DirectorySeparatorChar + "panel" + System.IO.Path.DirectorySeparatorChar + ConfigData.Image_ArrowRight, ["IMG.RP-Pistol"] = Interface.GetMod().DataDirectory + System.IO.Path.DirectorySeparatorChar + "panel" + System.IO.Path.DirectorySeparatorChar + ConfigData.Image_Pistol, ["IMG.RP-RaidBlock"] = Interface.GetMod().DataDirectory + System.IO.Path.DirectorySeparatorChar + "panel" + System.IO.Path.DirectorySeparatorChar + ConfigData.Image_RaidBlock, ["IMG.RP-RadHouse"] = Interface.GetMod().DataDirectory + System.IO.Path.DirectorySeparatorChar + "panel" + System.IO.Path.DirectorySeparatorChar + ConfigData.Image_RadHouse, ["IMG.RP-BuildingUpgrade"] = Interface.GetMod().DataDirectory + System.IO.Path.DirectorySeparatorChar + "panel" + System.IO.Path.DirectorySeparatorChar + ConfigData.Image_BuildingUpgrade, ["IMG.RP-Remove"] = Interface.GetMod().DataDirectory + System.IO.Path.DirectorySeparatorChar + "panel" + System.IO.Path.DirectorySeparatorChar + ConfigData.Image_Remove, ["IMG.RP-MultiEvent"] = Interface.GetMod().DataDirectory + System.IO.Path.DirectorySeparatorChar + "panel" + System.IO.Path.DirectorySeparatorChar + ConfigData.Image_MultiEvent,  //BuildingUpgrade
                    //Remove
                }
                ;
                foreach (var loadImage in loadImages) {
                    if (IMGLibrary.HasImage(loadImage.Key, 0)) IMGLibrary.RemoveImage(loadImage.Key, 0);
                    if ((loadImage.Value ?? "") == "") {
                        throw new Exception($"[{this.Title}] Image '{loadImage.Key}' not setted!");
                    }
                    try {
                        System.Drawing.Image image = System.Drawing.Image.FromFile(loadImage.Value);
                        using (var ms = new System.IO.MemoryStream()) {
                            image.Save(ms, image.RawFormat);
                            IMGLibrary.AddImageData(loadImage.Key, ms.ToArray());
                            ms.Dispose();
                        }
                    }
                    catch (Exception e) {
                        if (e.ToString().Contains("FileNotFoundException")) throw new Exception($"[{this.Title}] File '{loadImage.Value}' not found!\n{e}");
                        else Debug.LogError(e);
                        return;
                    }
                }
            }
            , "[LoadImages] void RustPanel.OnServerInitialized()");
            /*CheckInvokeTime(() =>
            {
                EntityEvent.AddRange(BaseNetworkable.serverEntities, BaseNetworkable.serverEntities.Count);
            }, "[EntityEvent.AddRange] void RustPanel.OnServerInitialized()");*/
            timer.Repeat(1.5f, 0, UpdateUIAll);
            IsLoadedServer = true;
        }
        );
        static string Time = "";
        static string Players = "";
        static bool Plane = false;
        static bool Heli = false;
        static bool Cargo = false;
        static bool Ship = false;
        public static void UpdateUIAll() {
            int i = (Time == CurrentTime) ? 0 : 1;
            i += (Players == $"{CurrentPlayers}/{MaxPlayers}") ? 0 : 1;
            i += (Plane == EventPlane.Active) ? 0 : 1;
            i += (Heli == EventHeli.Active) ? 0 : 1;
            i += (Cargo == EventCargo.Active) ? 0 : 1;
            i += (Ship == EventShip.Active) ? 0 : 1;
            if (i == 0) return;
            Time = CurrentTime;
            Players = $"{CurrentPlayers}/{MaxPlayers}";
            Plane = EventPlane.Active;
            Heli = EventHeli.Active;
            Cargo = EventCargo.Active;
            Ship = EventShip.Active;
            for (int pIndex = 0; pIndex < BasePlayer.activePlayerList.Count; pIndex++) {
                BasePlayer player = BasePlayer.activePlayerList[pIndex];
                RustPanelData panelData = RustPanelData.GetOrAdd(player);
                if (panelData.See) panelData.UpdateUI(CreateGUI(panelData, Time, Plane ? ActiveColor : DefaultColor, Heli ? ActiveColor : DefaultColor, Cargo ? ActiveColor : DefaultColor, Ship ? ActiveColor : DefaultColor, Players, ((CurrentPlayers * 1f) / MaxPlayers), (SingletonComponent<ServerMgr>.Instance.connectionQueue.joining.Count * 1f) / MaxPlayers));
            }
        }
        static UIPanel GetPanel(BasePlayer player, int index, float value, string color, string imgPNG, string name, Action<bool> isAdded) {
            //if (player.displayName.ToLower() == "Lime".ToLower()) _plugin.Player.Message(player, $"[{index}] {name} => {value}");
            if (value <= 0) {
                isAdded.Invoke(false);
                return null;
            }
            isAdded.Invoke(true);
            return new UIPanel(new UITransform(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(-89f, 29f + index * 28f), new Vector2(89f, 55f + index * 28f)), false, new UIImage(BackgroundColor, null, null)) {
                new UIPanel(new UITransform(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(-88f, -12f), new Vector2(-64f, 12f)), false, new UIImage(DefaultColor, imgPNG, null)), new UIFieldBar(new UITransform(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(-61f, -10f), new Vector2(86f, 10f)), value, new UIText(name, DefaultColor, 15, TextAnchor.MiddleCenter), new UIImage(FieldBackgroundColor, null, null, null, "assets/content/ui/uibackgroundblur.mat"), new UIImage(color, null, null, null, "assets/content/ui/uibackgroundblur.mat")),
            }
            ;
        }
        static string CreateGUI(RustPanelData panel, string Time, string PlaneColor, string HeliColor, string CargoColor, string ShipColor, string Players, float Value, float Value2) {
            string ret = "";
            //Value = 0.1f;
            //Value2 = 0.5f;
            CheckInvokeTime(() => {
                if (panel.See) {
                    UIPanel uipanel = new UIPanel(new UITransform(new Vector2(1f, 0f), new Vector2(1f, 0f), new Vector2(-388f, 16f), new Vector2(-210f, 70f)), false, new UIImage("1 1 1 0", null, null)) {
                        new UIPanel(new UITransform(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(-89f, 1f), new Vector2(-23f, 27f)), false, new UIImage(BackgroundColor, null, null, null, "assets/content/ui/uibackgroundblur.mat")) {
                            new UIPanel(new UITransform(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(-32f, -12f), new Vector2(-8f, 12f)), false, new UIImage(DefaultColor, IMGLibrary.GetImage("IMG.RP-Clock"), null)), new UIPanel(new UITransform(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(-5f, -10f), new Vector2(30f, 10f)), false, new UIImage(FieldDefaultColor, null, null, null, "assets/content/ui/uibackgroundblur.mat")) {
                                new UILabel(new UITransform(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(-17.5f, -10f), new Vector2(17.5f, 10f)), new UIText(Time, DefaultColor, 13, TextAnchor.MiddleCenter)),
                            }
                            ,
                        }
                        , new UIPanel(new UITransform(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(-21f, 1f), new Vector2(5f, 27f)), false, new UIImage(BackgroundColor, null, null, null, "assets/content/ui/uibackgroundblur.mat")) {
                            new UIPanel(new UITransform(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(-12f, -12f), new Vector2(12f, 12f)), false, new UIImage(PlaneColor, IMGLibrary.GetImage("IMG.RP-Plane"), null)),
                        }
                        , new UIPanel(new UITransform(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(7f, 1f), new Vector2(33f, 27f)), false, new UIImage(BackgroundColor, null, null, null, "assets/content/ui/uibackgroundblur.mat")) {
                            new UIPanel(new UITransform(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(-12f, -12f), new Vector2(12f, 12f)), false, new UIImage(HeliColor, IMGLibrary.GetImage("IMG.RP-Heli"), null)),
                        }
                        , new UIPanel(new UITransform(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(35f, 1f), new Vector2(61f, 27f)), false, new UIImage(BackgroundColor, null, null, null, "assets/content/ui/uibackgroundblur.mat")) {
                            new UIPanel(new UITransform(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(-12f, -12f), new Vector2(12f, 12f)), false, new UIImage(CargoColor, IMGLibrary.GetImage("IMG.RP-Cargo"), null)),
                        }
                        , new UIPanel(new UITransform(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(63f, 1f), new Vector2(89f, 27f)), false, new UIImage(BackgroundColor, null, null, null, "assets/content/ui/uibackgroundblur.mat")) {
                            new UIPanel(new UITransform(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(-12f, -12f), new Vector2(12f, 12f)), false, new UIImage(ShipColor, IMGLibrary.GetImage("IMG.RP-Ship"), null)),
                        }
                        , new UIPanel(new UITransform(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(-89f, -27f), new Vector2(33f, -1f)), false, new UIImage(BackgroundColor, null, null, null, "assets/content/ui/uibackgroundblur.mat")) {
                            new UIPanel(new UITransform(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(-60f, -12f), new Vector2(-36f, 12f)), false, new UIImage(DefaultColor, IMGLibrary.GetImage("IMG.RP-Players"), null)), Value2 == 0 ? (UIElement)new UIFieldBar(new UITransform(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(-33f, -10f), new Vector2(57.5f, 10f)), Value, new UIText(Players, DefaultColor, 14, TextAnchor.MiddleCenter), new UIImage(FieldBackgroundColor, null, null, null, "assets/content/ui/uibackgroundblur.mat"), new UIImage(FieldDefaultColor, null, null, null, "assets/content/ui/uibackgroundblur.mat")) : new UIDoubleFieldBar(new UITransform(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(-33f, -10f), new Vector2(57.5f, 10f)), Value, Value2, new UIText(Players, DefaultColor, 14, TextAnchor.MiddleCenter), new UIImage(FieldBackgroundColor, null, null, null, "assets/content/ui/uibackgroundblur.mat"), new UIImage(FieldDefaultColor, null, null, null, "assets/content/ui/uibackgroundblur.mat"), new UIImage(FieldJoinColor, null, null, null, "assets/content/ui/uibackgroundblur.mat")),
                        }
                        , new UIPanel(new UITransform(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(35f, -27f), new Vector2(61f, -1f)), false, new UIImage(BackgroundColor, null, null, null, "assets/content/ui/uibackgroundblur.mat")) {
                            new UIButton(new UITransform(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(-12f, -12f), new Vector2(12f, 12f)), "chat.say /block", new UIImage(DefaultColor, IMGLibrary.GetImage("IMG.RP-Pistol"), null)),
                        }
                        , new UIPanel(new UITransform(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(63f, -27f), new Vector2(89f, -1f)), false, new UIImage(BackgroundColor, null, null, null, "assets/content/ui/uibackgroundblur.mat")) {
                            new UIButton(new UITransform(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(-12f, -12f), new Vector2(12f, 12f)), "rp.on.off", new UIImage(DefaultColor, IMGLibrary.GetImage("IMG.RP-ArrowRight"), null)),
                        }
                    }
                    ;
                    int index = 0;
                    float value = (float)(_plugin?.plugins?.Find("NoEscape")?.CallHook("GetTimeValue", panel.GetComponent<BasePlayer>()) ?? -1f);
                    uipanel.Add(GetPanel(panel.GetComponent<BasePlayer>(), index, (float)(_plugin?.plugins?.Find("NoEscape")?.CallHook("GetTimeValue", panel.GetComponent<BasePlayer>()) ?? -1f), FieldRaidBlockColor, IMGLibrary.GetImage("IMG.RP-RaidBlock"), "RaidBlock", (val) => index = index + (val ? 1 : 0)));
                    uipanel.Add(GetPanel(panel.GetComponent<BasePlayer>(), index, (float)(_plugin?.plugins?.Find("RadHouse120")?.CallHook("GetTimeValue") ?? -1f), FieldRadHouseColor, IMGLibrary.GetImage("IMG.RP-RadHouse"), "RadHouse", (val) => index = index + (val ? 1 : 0)));
                    uipanel.Add(GetPanel(panel.GetComponent<BasePlayer>(), index, (float)(_plugin?.plugins?.Find("Remove")?.CallHook("GetTimeValue", panel.GetComponent<BasePlayer>()) ?? -1f), FieldRemoveColor, IMGLibrary.GetImage("IMG.RP-Remove"), "Remove", (val) => index = index + (val ? 1 : 0)));
                    uipanel.Add(GetPanel(panel.GetComponent<BasePlayer>(), index, (float)(_plugin?.plugins?.Find("BuildingUpgrade")?.CallHook("GetTimeValue", panel.GetComponent<BasePlayer>()) ?? -1f), FieldBuildingUpgradeColor, IMGLibrary.GetImage("IMG.RP-BuildingUpgrade"), $"UP: {_plugin?.plugins?.Find("BuildingUpgrade")?.CallHook("GetTypeValue", panel.GetComponent<BasePlayer>()) ?? "None"}", (val) => index = index + (val ? 1 : 0)));
                    uipanel.Add(GetPanel(panel.GetComponent<BasePlayer>(), index, (float)(_plugin?.plugins?.Find("MultiEvent")?.CallHook("GetTimeValue") ?? -1f), FieldMultiEventColor, IMGLibrary.GetImage("IMG.RP-MultiEvent"), $"Перехват груза", (val) => index = index + (val ? 1 : 0)));
                    //uipanel.Add(GetPanel(index, (float)(_plugin?.plugins?.Find("NoEscape")?.CallHook("GetTimeValue", panel.GetComponent<BasePlayer>()) ?? -1f), FieldRaidBlockColor, IMGLibrary.GetImage("IMG.RP-RaidBlock"), "RaidBlock", (val) => index = index + (val ? 1 : 0)));
                    ret = uipanel.ToContainer(_GUI_RP + (panel.add ? ".1" : ".2"), UIParent.Hud).ToJson();
                }
                else {
                    UIContainer cuis = new UIPanel(new UITransform(new Vector2(1f, 0f), new Vector2(1f, 0f), new Vector2(-388f, 16f), new Vector2(-210f, 70f)), false, new UIImage("1 1 1 0", null, null)) {
                        new UIPanel(new UITransform(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(63f, -27f), new Vector2(89f, -1f)), false, new UIImage(BackgroundColor, null, null, null, "assets/content/ui/uibackgroundblur.mat")) {
                            new UIButton(new UITransform(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(-12f, -12f), new Vector2(12f, 12f)), "rp.on.off", new UIImage(DefaultColor, IMGLibrary.GetImage("IMG.RP-ArrowLeft"), null)),
                        }
                        ,
                    }
                    .ToContainer(_GUI_RP + (panel.add ? ".1" : ".2"), UIParent.Hud);
                    ret = cuis.ToJson();
                }
            }
            , "string RustPanel.CreateGUI(RustPanelData, string, string, string, string, string, string, float)");
            return ret;
        }
        static void CheckInvokeTime(System.Action action, string methodText) {
            long long1 = DateTime.Now.Ticks;
            action.Invoke();
            Interface.CallHook("OnInvokeTimer", (float)new TimeSpan(DateTime.Now.Ticks - long1).TotalSeconds, "CustomCheck: " + methodText);
        }
        void Loaded() {
            _plugin = this;
        }
        void Unload() {
            RustPanelData.DestroyAll();
            Dictionary<string, string>.Enumerator loadImages = new Dictionary<string, string>() {
                ["IMG.RP-Clock"]
                = Interface.GetMod().DataDirectory + System.IO.Path.DirectorySeparatorChar + "panel" + System.IO.Path.DirectorySeparatorChar + ConfigData.Image_Clock, ["IMG.RP-Players"] = Interface.GetMod().DataDirectory + System.IO.Path.DirectorySeparatorChar + "panel" + System.IO.Path.DirectorySeparatorChar + ConfigData.Image_Players, ["IMG.RP-Cargo"] = Interface.GetMod().DataDirectory + System.IO.Path.DirectorySeparatorChar + "panel" + System.IO.Path.DirectorySeparatorChar + ConfigData.Image_Cargo, ["IMG.RP-Ship"] = Interface.GetMod().DataDirectory + System.IO.Path.DirectorySeparatorChar + "panel" + System.IO.Path.DirectorySeparatorChar + ConfigData.Image_Ship, ["IMG.RP-Plane"] = Interface.GetMod().DataDirectory + System.IO.Path.DirectorySeparatorChar + "panel" + System.IO.Path.DirectorySeparatorChar + ConfigData.Image_Plane, ["IMG.RP-Heli"] = Interface.GetMod().DataDirectory + System.IO.Path.DirectorySeparatorChar + "panel" + System.IO.Path.DirectorySeparatorChar + ConfigData.Image_Heli, ["IMG.RP-ArrowLeft"] = Interface.GetMod().DataDirectory + System.IO.Path.DirectorySeparatorChar + "panel" + System.IO.Path.DirectorySeparatorChar + ConfigData.Image_ArrowLeft, ["IMG.RP-ArrowRight"] = Interface.GetMod().DataDirectory + System.IO.Path.DirectorySeparatorChar + "panel" + System.IO.Path.DirectorySeparatorChar + ConfigData.Image_ArrowRight, ["IMG.RP-Pistol"] = Interface.GetMod().DataDirectory + System.IO.Path.DirectorySeparatorChar + "panel" + System.IO.Path.DirectorySeparatorChar + ConfigData.Image_Pistol, ["IMG.RP-RaidBlock"] = Interface.GetMod().DataDirectory + System.IO.Path.DirectorySeparatorChar + "panel" + System.IO.Path.DirectorySeparatorChar + ConfigData.Image_RaidBlock, ["IMG.RP-RadHouse"] = Interface.GetMod().DataDirectory + System.IO.Path.DirectorySeparatorChar + "panel" + System.IO.Path.DirectorySeparatorChar + ConfigData.Image_RadHouse, ["IMG.RP-BuildingUpgrade"] = Interface.GetMod().DataDirectory + System.IO.Path.DirectorySeparatorChar + "panel" + System.IO.Path.DirectorySeparatorChar + ConfigData.Image_BuildingUpgrade, ["IMG.RP-Remove"] = Interface.GetMod().DataDirectory + System.IO.Path.DirectorySeparatorChar + "panel" + System.IO.Path.DirectorySeparatorChar + ConfigData.Image_Remove, ["IMG.RP-MultiEvent"] = Interface.GetMod().DataDirectory + System.IO.Path.DirectorySeparatorChar + "panel" + System.IO.Path.DirectorySeparatorChar + ConfigData.Image_MultiEvent,
            }
            .GetEnumerator();
            while (loadImages.MoveNext()) {
                KeyValuePair<string, string> img = loadImages.Current;
                if (!IMGLibrary.HasImage(img.Key, 0)) continue;
                IMGLibrary.RemoveImage(img.Key, 0);
            }
        }
        public static EntityEvent<CargoPlane> EventPlane = new EntityEvent<CargoPlane>();
        public static EntityEvent<BaseHelicopter> EventHeli = new EntityEvent<BaseHelicopter>();
        public static EntityEvent<CH47Helicopter> EventCargo = new EntityEvent<CH47Helicopter>();
        public static EntityEvent<CargoShip> EventShip = new EntityEvent<CargoShip>();
        public static string CurrentTime => (((DateTime?)_plugin?.plugins?.Find("TimeManager")?.CallHook("GetNowTime")) ?? TOD_Sky.Instance.Cycle.DateTime).ToString("HH:mm", CultureInfo.InvariantCulture);
        public static int CurrentPlayers => BasePlayer.activePlayerList.Count;
        public static int MaxPlayers => ConVar.Server.maxplayers;
        public static class EntityEvent {
            public static bool Add(BaseNetworkable entity) {
                if (entities.Contains(entity)) return false;
                entities.Add(entity);
                return true;
            }
            public static bool Remove(BaseNetworkable entity) {
                if (!entities.Contains(entity)) return false;
                entities.Remove(entity);
                return true;
            }
            public static void AddRange(IEnumerable<BaseNetworkable> entities, int maxcount) {
                IEnumerator<BaseNetworkable> enumerator = null;
                enumerator = entities.GetEnumerator();
                int count = 0;
                long start = DateTime.Now.Ticks;
                while (enumerator.MoveNext()) {
                    if (TimeSpan.FromTicks(DateTime.Now.Ticks - start).TotalSeconds >= 5) {
                        Debug.Log($"{count}/{maxcount}");
                        start = DateTime.Now.Ticks;
                    }
                    count++;
                }
            }
            public static int Count<T>()where T : BaseNetworkable {
                int count = 0;
                List<int> removeIndex = new List<int>();
                for (int i = 0; i < entities.Count; i++) {
                    BaseNetworkable entity = entities[i];
                    if (entity == null) {
                        removeIndex.Add(i);
                        continue;
                    }
                    if (entity is T) count++;
                }
                for (int i = removeIndex.Count - 1; i >= 0; i--) entities.RemoveAt(removeIndex[i]);
                return count;
            }
            static List<BaseNetworkable> entities = new List<BaseNetworkable>();
        }
        public class EntityEvent<T>where T : BaseEntity {
            public bool Active => EntityEvent.Count<T>() > 0;
        }
        void OnEntitySpawned(BaseNetworkable entity) {
            if (IsLoadedServer) EntityEvent.Add(entity);
        }
        void OnEntityDeath(BaseCombatEntity entity, HitInfo info) => EntityEvent.Remove(entity);
        static void PlayerInvoke(ConsoleSystem.Arg arg, Action<BasePlayer> action) {
            if (arg?.Player() != null) action?.Invoke(arg.Player());
        }
        [ConsoleCommand("rp.on.off")]
        void ConsoleCommand_RP_On_Off(ConsoleSystem.Arg arg) => PlayerInvoke(arg, (player) => player?.GetComponent<RustPanelData>()?.RefSee());
        public abstract class Remover<T> : MonoBehaviour where T : Remover<T> {
            static List<Remover<T>> list = new List<Remover<T>>();
            public Remover() {
                list.Add(this);
            }
            public abstract void Destroy();
            public static void DestroyAll() {
                IEnumerator<Remover<T>> enumerator = list.GetEnumerator();
                while (enumerator.MoveNext()) enumerator.Current?.Destroy();
            }
        }
        public class RustPanelData : Remover<RustPanelData> {
            public bool add = false;
            public bool See = true;
            public BasePlayer player => GetComponent<BasePlayer>();
            public void RefSee() {
                See = !See;
                UpdateUI(CreateGUI(this, Time, Plane ? ActiveColor : DefaultColor, Heli ? ActiveColor : DefaultColor, Cargo ? ActiveColor : DefaultColor, Ship ? ActiveColor : DefaultColor, Players, ((CurrentPlayers * 1f) / MaxPlayers), (SingletonComponent<ServerMgr>.Instance.connectionQueue.joining.Count * 1f) / MaxPlayers));
            }
            public void UpdateUI(string JSON) {
                CuiHelper.DestroyUi(player, _GUI_RP + (add ? ".1" : ".2"));
                CuiHelper.AddUi(player, JSON);
                CuiHelper.DestroyUi(player, _GUI_RP + (!add ? ".1" : ".2"));
                add = !add;
            }
            public override void Destroy() => Destroy(this);
            public static RustPanelData GetOrAdd<T>(T monoBehaviour) where T : MonoBehaviour => GetOrAdd(monoBehaviour.gameObject);
            public static RustPanelData GetOrAdd(GameObject monoBehaviour) {
                //MSGAdmin(monoBehaviour.GetComponent<BasePlayer>(), "GetOrAdd");
                RustPanelData ret = monoBehaviour.GetComponent<RustPanelData>();
                if (ret != null) return ret;
                IEnumerator enumerator = monoBehaviour.GetComponents<MonoBehaviour>().GetEnumerator();
                while (enumerator.MoveNext()) if (((MonoBehaviour)enumerator.Current).GetType().ToString() == typeof(RustPanelData).ToString()) Destroy((MonoBehaviour)enumerator.Current);
                MSGAdmin(monoBehaviour.GetComponent<BasePlayer>(), "Added new!");
                return monoBehaviour.AddComponent<RustPanelData>();
            }
        }
#region UI
        public abstract class UIElement : IEnumerable<UIElement>, IEnumerable<IEnumerable<UIElement>> {
            public UITransform _transform;
            public List<UIElement> childs = new List<UIElement>();
            void TryAdd(UIElement element) {
                if (element != null) childs.Add(element);
            }
            void TryAddRange(IEnumerable<UIElement> elements) {
                IEnumerator<UIElement> enumerator = elements.GetEnumerator();
                while (enumerator.MoveNext()) TryAdd(enumerator.Current);
            }
            public void Add(UIElement element) => TryAdd(element);
            public void Add(params UIElement[] elements) => TryAddRange(elements);
            public void Add(IEnumerable<UIElement> elements) => TryAddRange(elements);
            public List<CuiElement> CuiElements(UIParent parent = UIParent.Hud, string name = null) => CuiElements(parent.ToString(), name);
            public UIContainer ToContainer(string name, UIParent type) => new UIContainer(this, name, type);
            public abstract List<CuiElement> CuiElements(string parent, string name = null);
            public IEnumerator<UIElement> GetEnumerator() => childs.GetEnumerator();
            IEnumerator IEnumerable.GetEnumerator() => childs.GetEnumerator();
            IEnumerator<IEnumerable<UIElement>> IEnumerable<IEnumerable<UIElement>>.GetEnumerator() => new List<List<UIElement>> {
                childs
            }
            .GetEnumerator();
        }
        public class UITransform {
            public Vector2 _aMin = new Vector2(0.0f, 0.0f);
            public Vector2 _aMax = new Vector2(1.0f, 1.0f);
            public Vector2 _oMin = new Vector2(0.0f, 0.0f);
            public Vector2 _oMax = new Vector2(0.0f, 0.0f);
            public UITransform() {
            }
            public UITransform(Vector2 aMin, Vector2 aMax, Vector2 oMin, Vector2 oMax) {
                _aMin = aMin;
                _aMax = aMax;
                _oMin = oMin;
                _oMax = oMax;
            }
            static string ToRT(Vector2 v2) => $"{v2.x} {v2.y}";
            public CuiRectTransformComponent RectTransform => new CuiRectTransformComponent() {
                AnchorMin = ToRT(_aMin), AnchorMax = ToRT(_aMax), OffsetMin = ToRT(_oMin), OffsetMax = ToRT(_oMax)
            }
            ;
        }
        public class UIText {
            public TextAnchor _align = TextAnchor.MiddleCenter;
            public string _color;
            public int _size = 14;
            public string _font = "RobotoCondensed-Bold.ttf";
            public string _text;
            public UIText(string text, string color, int size = 14, TextAnchor align = TextAnchor.MiddleCenter, string font = "RobotoCondensed-Bold.ttf") {
                _align = align;
                _color = color;
                _size = size;
                _font = font;
                _text = text;
            }
            public CuiTextComponent Text => new CuiTextComponent() {
                Align = _align, Color = _color, Font = _font, FontSize = _size, Text = _text
            }
            ;
            public static explicit operator UIText(string text) => new UIText(text, "0 0 0 1");
        }
        public class UICountdown {
            public int _startTime;
            public int _endTime;
            public int _step;
            public string _command;
            public UICountdown(int startTime, int endTime, int step, string command) {
                _startTime = startTime;
                _endTime = endTime;
                _step = step;
                _command = command;
            }
            public CuiCountdownComponent CountDown => new CuiCountdownComponent() {
                StartTime = _startTime, EndTime = _endTime, Step = _step, Command = _command
            }
            ;
            public class CuiCountdownComponent : ICuiComponent {
                public string Type => "Countdown";
                [JsonProperty("startTime")]
                public int StartTime {
                    get;
                    set;
                }
                [JsonProperty("endTime")]
                public int EndTime {
                    get;
                    set;
                }
                [JsonProperty("step")]
                public int Step {
                    get;
                    set;
                }
                [JsonProperty("command")]
                public string Command {
                    get;
                    set;
                }
            }
        }
        public class UIImage {
            public string _png = null;
            public string _url = null;
            public string _sprite = null;
            public string _material = null;
            public string _color;
            public UnityEngine.UI.Image.Type _imageType = UnityEngine.UI.Image.Type.Simple;
            public UIImage(string color, string png = null, string url = null, string sprite = null, string material = null, UnityEngine.UI.Image.Type imageType = UnityEngine.UI.Image.Type.Simple) {
                _png = png;
                _sprite = sprite;
                _material = material;
                _color = color;
                _imageType = imageType;
                _url = url;
            }
            public ICuiComponent Image => _url == null ? (ICuiComponent)new CuiImageComponent() {
                Color = _color, Material = _material ?? "Assets/Icons/IconMaterial.mat", Png = _png, Sprite = _sprite ?? "Assets/Content/UI/UI.Background.Tile.psd"
            }
            : new CuiRawImageComponent() {
                Color = _color, Material = _material, Png = _png, Sprite = _sprite ?? "Assets/Icons/rust.png", Url = _url
            }
            ;
            public static explicit operator UIImage(string color) => new UIImage(color);
        }
        public enum UIParent {
            Hud, Overlay,
        }
        public class UINone : UIElement {
            Action<string> uiName;
            public UINone(Action<string> uiName) {
                this.uiName = uiName;
            }
            public override List<CuiElement> CuiElements(string parent, string name = null) {
                List<CuiElement> list = new List<CuiElement>();
                name = (string.IsNullOrEmpty(name)) ? CuiHelper.GetGuid() : name;
                uiName.Invoke(name);
                list.Add(new CuiElement {
                    Name = name, Parent = parent, Components = {
                        new CuiRectTransformComponent()
                    }
                }
                );
                for (int i = 0; i < childs.Count; i++) {
                    UIElement child = childs[i];
                    if (child != this) list.AddRange(child.CuiElements(name, name + $"[{i}]"));
                }
                return list;
            }
        }
        /*public class UIReplace: UIElement
        {
            public static string ComponentsCreator(UIElement element, string parent, string name)
            {
                return JsonConvert.SerializeObject(element.CuiElements(parent, name).FirstOrDefault().Components, Formatting.None, new JsonSerializerSettings() { DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore }).Replace("\\n", "\n");
            }
            public string Components;
            public UIReplace(string components) { Components = components; }
            public override List<CuiElement> CuiElements(string parent, string name = null)
            {
                List<CuiElement> list = new List<CuiElement>();
                name = (string.IsNullOrEmpty(name)) ? CuiHelper.GetGuid() : name;
                list.Add(new CuiReplace
                {
                    Name = name,
                    Parent = parent,
                    components = Components,
                });
                for (int i = 0; i < childs.Count; i++)
                {
                    UIElement child = childs[i];
                    if (child != this)
                        list.AddRange(child.CuiElements(name, name + $"[{i}]"));
                }
                return list;
            }
            [JsonObject(MemberSerialization.OptOut)]
            public class CuiReplace: CuiElement
            {
                [JsonProperty("name")] public new string Name { get; set; } = "AddUI CreatedPanel";
                [JsonProperty("parent")] public new string Parent { get; set; } = "Hud";
                public string components { get; set; }
                [JsonIgnore] public new List<ICuiComponent> Components { get; }
                [JsonProperty("fadeOut")] public new float FadeOut { get; set; }
            }
        }*/
        public class UIButton : UIElement {
            public string _command;
            public string _close = null;
            public UIImage _image;
            public UIText _text;
            public UIButton(UITransform transform, string command, UIImage image, UIText text = null, string close = null) {
                _command = command;
                _close = close;
                _image = image;
                _text = text;
                _transform = transform;
            }
            public UIButton(Vector2 aMin, Vector2 aMax, Vector2 oMin, Vector2 oMax, string command, UIText text, string color, string png = null, string url = null, string sprite = "Assets/Content/UI/UI.Background.Tile.psd", string material = "Assets/Icons/IconMaterial.mat", UnityEngine.UI.Image.Type imageType = UnityEngine.UI.Image.Type.Simple, string close = null) {
                _command = command;
                _close = close;
                _image = new UIImage(color, png, url, sprite, material, imageType);
                _text = text;
                _transform = new UITransform(aMin, aMax, oMin, oMax);
            }
            public override List<CuiElement> CuiElements(string parent, string name = null) {
                List<CuiElement> list = new List<CuiElement>();
                name = (string.IsNullOrEmpty(name)) ? CuiHelper.GetGuid() : name;
                list.Add(new CuiElement {
                    Name = name, Parent = parent, Components = {
                        new CuiButtonComponent() {
                            Close = _close, Command = _command, Color = "0 0 0 0"
                        }
                        , _transform.RectTransform
                    }
                }
                );
                if (_image != null) {
                    list.Add(new CuiElement {
                        Parent = name, Components = {
                            _image.Image, new CuiRectTransformComponent()
                        }
                    }
                    );
             
// ... [Code preview truncated due to length. Full source in attached file] ...

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

Другие ресурсы пользователя 15FPS

Сверху