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

FREE XPanelPlus : 1.0.101 1.0.101

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

namespace Oxide.Plugins
{
    [Info("XPanelPlus", "private discord.gg/bRbcQ6nJuA", "1.0.101")]
    class XPanelPlus : RustPlugin
    {
		
				
		
        private PanelConfig config;
		public bool PanelP2;
		protected override void LoadDefaultConfig() => config = PanelConfig.GetNewConfiguration();
		
		private void UIPanelEvent(BasePlayer player)
		{
			CuiHelper.DestroyUi(player, ".XPanelEvent");
            CuiElementContainer container = new CuiElementContainer();

			container.Add(new CuiPanel
            {
                RectTransform = { AnchorMin = config.GUI.AnchorMinE, AnchorMax = config.GUI.AnchorMaxE, OffsetMin = config.GUI.OffsetMinE, OffsetMax = config.GUI.OffsetMaxE },
                Image = { Color = "0 0 0 0" }
            }, "Hud", ".XPanelEvent");
			
			int x = 0;
			
			foreach(var e in config.Events)
			{
				container.Add(new CuiPanel
				{
					RectTransform = { AnchorMin = "0.5 0", AnchorMax = "0.5 1", OffsetMin = $"{-96 + (x * 28)} 0", OffsetMax = $"{-70  + (x * 28)} 0" },
					Image = { Color = "0.9686275 0.9176471 0.8784314 0.02921569", Material = "assets/icons/greyout.mat" }
				}, ".XPanelEvent", ".XPanel_Event");
				
				container.Add(new CuiPanel
				{
					RectTransform = { AnchorMin = "0 0", AnchorMax = "1 1", OffsetMin = "2.5 2.5", OffsetMax = "-2.5 -2.5" },
					Image = { Png = (string) ImageLibrary.Call("GetImage", $".{e.Key}"), Color = _activeevents[e.Key] ? e.Value.EventAColor : e.Value.EventDColor }
				}, ".XPanel_Event");
				
				x++;
			}
			
			container.Add(new CuiPanel
			{
				RectTransform = { AnchorMin = "0.5 0", AnchorMax = "0.5 1", OffsetMin = "44 0", OffsetMax = "96 0" },
				Image = { Color = "0.9686275 0.9176471 0.8784314 0.02921569", Material = "assets/icons/greyout.mat" }
			}, ".XPanelEvent", ".XPanel_Time");
			
			container.Add(new CuiLabel
            {
                RectTransform = { AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0" },
                Text = { Text = time, Align = TextAnchor.MiddleCenter, FontSize = config.GUI.TimeSize, Color = "1 1 1 0.6" }
            }, ".XPanel_Time");
			
			CuiHelper.AddUi(player, container);
		}
		
		private void UIPanelInfo(BasePlayer player)
		{
			CuiHelper.DestroyUi(player, ".XPanelInfo");
            CuiElementContainer container = new CuiElementContainer();
			
			container.Add(new CuiPanel
			{
				RectTransform = { AnchorMin = config.GUI.AnchorMinI, AnchorMax = config.GUI.AnchorMaxI, OffsetMin = config.GUI.OffsetMinI, OffsetMax = config.GUI.OffsetMaxI },
				Image = { Color = "0.9686275 0.9176471 0.8784314 0.02921569", Material = "assets/icons/greyout.mat" }
			}, "Hud", ".XPanelInfo");
			
			container.Add(new CuiLabel
            {
                RectTransform = { AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0" },
                Text = { Text = config.Setting.ListMessage[message], Align = TextAnchor.MiddleCenter, FontSize = 13, Color = "1 1 1 0.6" }
            }, ".XPanelInfo");
			
			CuiHelper.AddUi(player, container);
		}		
		
		private void UpdatePanel()
		{
			maxplayers = ConVar.Server.maxplayers;
			online = config.Setting.FakeOnline == 1 && IQFakeActive ? FakeOnline : config.Setting.FakeOnline == 2 && FGS ? BasePlayer.activePlayerList.Count + (int)FGS?.CallHook("getFakes") : BasePlayer.activePlayerList.Count;
			joining = ServerMgr.Instance.connectionQueue.Joining;
			
			PanelP = 1.0 / maxplayers * online;
			PanelJ = 1.0 / maxplayers * (online + joining);
			PanelP2 = PanelP > 1.0;
			
			foreach(BasePlayer player in BasePlayer.activePlayerList.Where(x => !_players.Contains(x)))
			    UIPanel(player);
			
			timer.Once(config.Setting.IntervalPanel, UpdatePanel);
		}		

        		
				
		[ConsoleCommand("xpanel")]
		void cmdCloseGUI(ConsoleSystem.Arg args)
		{
			BasePlayer player = args.Player();
			
			if(player == null) return;
			
			if(_players.Contains(player))
			{
				_players.Remove(player);
				
				OnPlayerConnected(player);
			}
			else
			{
				_players.Add(player);
				
				CuiHelper.DestroyUi(player, ".XPanel");
				CuiHelper.DestroyUi(player, ".XPanelEvent");
				CuiHelper.DestroyUi(player, ".XPanelInfo");
				
				SHUPPanel(player);
			}
			
			EffectNetwork.Send(new Effect("assets/bundled/prefabs/fx/notice/loot.drag.grab.fx.prefab", player, 0, new Vector3(), new Vector3()), player.Connection);
		}
		
		public List<BaseNetworkable> _events = new List<BaseNetworkable>();
		public double PanelP, PanelJ;
		public Dictionary<string, bool> _activeevents = new Dictionary<string, bool>
		{
			["CargoPlane"] = false,
			["BaseHelicopter"] = false,
			["CargoShip"] = false,
			["CH47Helicopter"] = false,
			["BradleyAPC"] = false
		};
		   		 		  						  	   		  	 	 		  	   		  	  			  	 		
		protected override void LoadConfig()
        {
            base.LoadConfig(); 
			 
			try
			{
				config = Config.ReadObject<PanelConfig>();
			}
			catch  
			{
				PrintWarning("Ошибка чтения конфигурации! Создание дефолтной конфигурации!");
				LoadDefaultConfig();
			}
			
			SaveConfig();
        }
		
		private void OnEntityKill(BaseNetworkable entity)
		{
			if (entity is CargoShip)
			{
				_events.Remove(entity);
				
				if(_events.Where(x => x is CargoShip).Count() == 0)
					_activeevents["CargoShip"] = false;
			}
			if (entity is CargoPlane)
			{
				_events.Remove(entity);
				
				if(_events.Where(x => x is CargoPlane).Count() == 0)
					_activeevents["CargoPlane"] = false;
			}
			if (entity is BradleyAPC)
			{
				_events.Remove(entity);
				
				if(_events.Where(x => x is BradleyAPC).Count() == 0)
					_activeevents["BradleyAPC"] = false;
			}
			if (entity is BaseHelicopter)
			{
				_events.Remove(entity);
				
				if(_events.Where(x => x is BaseHelicopter).Count() == 0)
					_activeevents["BaseHelicopter"] = false;
			}
			if (entity is CH47Helicopter)
			{
				_events.Remove(entity);
				
				if(_events.Where(x => x is CH47Helicopter).Count() == 0)
					_activeevents["CH47Helicopter"] = false;
			}
		}
		
		private void UIPanelInfo2(BasePlayer player)
		{
			CuiHelper.DestroyUi(player, ".XPanelInfo");
            CuiElementContainer container = new CuiElementContainer();
			
			container.Add(new CuiElement
            {
                Parent = "Hud", 
				Name = ".XPanelInfo",
                Components =
                {
			        new CuiTextComponent { Text = config.Setting.ListMessage[message], Align = TextAnchor.MiddleCenter, FontSize = 12, Color = "1 1 1 0.6" },
                    new CuiRectTransformComponent { AnchorMin = "0.5 0", AnchorMax = "0.5 0", OffsetMin = "-244.5 0", OffsetMax = "225.5 17.5" },
					new CuiOutlineComponent { Color = "0 0 0 1", Distance = "0.5 0.5" }
                }
            });
			
			CuiHelper.AddUi(player, container);
		}
		
				
				
		private void OnServerInitialized()
        {

			foreach (var image in config.Events)
			    ImageLibrary.Call("AddImage", image.Value.EventURL, $".{image.Key}");
		   		 		  						  	   		  	 	 		  	   		  	  			  	 		
			foreach (var entity in BaseNetworkable.serverEntities)
			{
				if (entity is CargoShip)
				{
					_activeevents["CargoShip"] = true;
					_events.Add(entity);
				}
				
				if (entity is CargoPlane)
				{
					_activeevents["CargoPlane"] = true;
					_events.Add(entity);
				}
				if (entity is BradleyAPC)
				{
					_activeevents["BradleyAPC"] = true;
					_events.Add(entity);
				}
				if (entity is BaseHelicopter)
				{
					_activeevents["BaseHelicopter"] = true;
					_events.Add(entity);
				}
				if (entity is CH47Helicopter)
				{
					_activeevents["CH47Helicopter"] = true;
					_events.Add(entity);
				}
			}
			
			foreach (BasePlayer player in BasePlayer.activePlayerList)
				SHUPPanel(player);
			
            if(config.Setting.ValidePanel) 
				UpdatePanel();
			if(config.Setting.ValidePanelEvent) 
				UpdatePanelEvent();
			if(config.Setting.ValidePanelInfo) 
				UpdatePanelInfo();
        }
		
		private void OnPlayerConnected(BasePlayer player)
		{
			if (player.IsReceivingSnapshot)
            {
                NextTick(() => OnPlayerConnected(player));
                return;
            }
			
			if(config.Setting.ValidePanel) 
				UIPanel(player);
			if(config.Setting.ValidePanelEvent) 
				UIPanelEvent(player);
			if(config.Setting.ValidePanelInfo)
				if(config.Setting.PositionPanelInfo)
					UIPanelInfo(player);
				else
					UIPanelInfo2(player);
			SHUPPanel(player);
		}
		
		public int maxplayers, online, joining, message = 0;
		
		private void UpdatePanelInfo()
		{
			if(config.Setting.PositionPanelInfo)
				foreach(BasePlayer player in BasePlayer.activePlayerList.Where(x => !_players.Contains(x)))
					UIPanelInfo(player);
			else
				foreach(BasePlayer player in BasePlayer.activePlayerList.Where(x => !_players.Contains(x)))
					UIPanelInfo2(player);
				
			int count = config.Setting.ListMessage.Count;
			
			message++;
			if(message >= count--)
				message = 0;
			
			timer.Once(config.Setting.IntervalPanelInfo, UpdatePanelInfo);
		}

        private class PanelConfig
        {
			internal class GeneralSetting
			{
				[JsonProperty("Интервал обновления панели с UI сообщениями")] public float IntervalPanelInfo;
				[JsonProperty("Интервал обновления панели с онлайном")] public float IntervalPanel;
				[JsonProperty("Интервал обновления панели с ивентами и временем")] public float IntervalPanelEvent;
				[JsonProperty("Включить панель с UI сообщениями")] public bool ValidePanelInfo;
				[JsonProperty("Формат времени - [ HH:mm - 24:00 | hh:mm tt - 12:00 ]")] public string TimeFormat;
				[JsonProperty("Включить панель с онлайном")] public bool ValidePanel;
				[JsonProperty("Список UI сообщений")] public List<string> ListMessage;
				[JsonProperty("Фейк онлайн от плагина - [ Default - 0 | IQFakeActive - 1 | FGS - 2]")] public int FakeOnline;
				[JsonProperty("Расположения UI сообщений - [ True - в панели над ивентами | False - под быстрыми слотами ]")] public bool PositionPanelInfo;
				[JsonProperty("Включить панель с ивентами и временем")] public bool ValidePanelEvent;
			}
			[JsonProperty("Настройка ивентов")]
            public Dictionary<string, EventSetting> Events;
			
			internal class GUISetting
			{
				[JsonProperty("AnchorMin - панель онлайн")] public string AnchorMinO;
				[JsonProperty("AnchorMax - панель онлайн")] public string AnchorMaxO;
				[JsonProperty("OffsetMin - панель онлайн")] public string OffsetMinO;
				[JsonProperty("OffsetMax - панель онлайн")] public string OffsetMaxO;				
				[JsonProperty("AnchorMin - панель ивенты")] public string AnchorMinE;
				[JsonProperty("AnchorMax - панель ивенты")] public string AnchorMaxE;
				[JsonProperty("OffsetMin - панель ивенты")] public string OffsetMinE;
				[JsonProperty("OffsetMax - панель ивенты")] public string OffsetMaxE;				
				[JsonProperty("AnchorMin - панель информация")] public string AnchorMinI;
				[JsonProperty("AnchorMax - панель информация")] public string AnchorMaxI;
				[JsonProperty("OffsetMin - панель информация")] public string OffsetMinI;
				[JsonProperty("OffsetMax - панель информация")] public string OffsetMaxI;				
				[JsonProperty("AnchorMin - кнопка сворачивания")] public string AnchorMinB;
				[JsonProperty("AnchorMax - кнопка сворачивания")] public string AnchorMaxB;
				[JsonProperty("OffsetMin - кнопка сворачивания")] public string OffsetMinB;
				[JsonProperty("OffsetMax - кнопка сворачивания")] public string OffsetMaxB;
				[JsonProperty("Цвет прогресса онлайна")] public string ColorOnline;
				[JsonProperty("Цвет прогресса подключающихся")] public string ColorJoining;
				[JsonProperty("Размер текста времени")] public int TimeSize;
			}
			
			[JsonProperty("Общие настройки")]
            public GeneralSetting Setting;
			[JsonProperty("Настройки GUI")]
            public GUISetting GUI = new GUISetting();
			
			public static PanelConfig GetNewConfiguration()
            {
                return new PanelConfig
                {
					Setting = new GeneralSetting
					{
						ValidePanelInfo = true,
						PositionPanelInfo = true,
						ValidePanelEvent = true,
						ValidePanel = true,
						ListMessage = new List<string>
						{
							"INFO-0 INFO-0 INFO-0 INFO-0",
							"INFO-1 INFO-1 INFO-1 INFO-1",
							"INFO-2 INFO-2 INFO-2 INFO-2"
						},
						IntervalPanelInfo = 7.5f,
						IntervalPanelEvent = 20.0f,
						IntervalPanel = 12.5f,
						TimeFormat = "HH:mm",
						FakeOnline = 0
					},
					GUI = new GUISetting
					{
						AnchorMinO = "1 0",
						AnchorMaxO = "1 0",
						OffsetMinO = "-402 16",
						OffsetMaxO = "-238 42",
						AnchorMinE = "1 0",
						AnchorMaxE = "1 0",
						OffsetMinE = "-402 44",
						OffsetMaxE = "-210 70",						
						AnchorMinI = "1 0",
						AnchorMaxI = "1 0",
						OffsetMinI = "-402 72",
						OffsetMaxI = "-210 98",
						AnchorMinB = "1 0",
						AnchorMaxB = "1 0",
						OffsetMinB = "-236 16",
						OffsetMaxB = "-210 42",
						ColorOnline = "0.7886275 0.4476471 0.2184314 0.92921569",
						ColorJoining = "0.2986275 0.6076471 0.8384314 0.92921569",
						TimeSize = 13
					},
					Events = new Dictionary<string, EventSetting>
					{
						["CargoPlane"] = new EventSetting
						{
							EventURL = "https://i.imgur.com/UctMlPy.png",
							EventAColor = "1 0.5 0.5 0.6",
							EventDColor = "0.9 0.9 0.9 0.6"
						},
						["BaseHelicopter"] = new EventSetting
						{
							EventURL = "https://i.imgur.com/BrJrI8Q.png",
							EventAColor = "1 0.5 1 0.6",
							EventDColor = "0.9 0.9 0.9 0.6"
						},
				        ["CargoShip"] = new EventSetting
						{
						    EventURL = "https://i.imgur.com/ff7ZCBI.png",
						    EventAColor = "0.5 0.5 1 0.6",
							EventDColor = "0.9 0.9 0.9 0.6"
						},
						["CH47Helicopter"] = new EventSetting
						{
						   	EventURL = "https://i.imgur.com/2PkTyzw.png",
						   	EventAColor = "0.5 1 1 0.6",
						   	EventDColor = "0.9 0.9 0.9 0.6"
						},							
						["BradleyAPC"] = new EventSetting
						{
							EventURL = "https://i.imgur.com/Hzu44wb.png",
							EventAColor = "1 1 0.5 0.6",
							EventDColor = "0.9 0.9 0.9 0.6"
						}												
					}
				};
			}
			
		    internal class EventSetting
			{
				[JsonProperty("Ссылка на картинку ивента")] public string EventURL;
				[JsonProperty("Цвет активного ивента")] public string EventAColor;
				[JsonProperty("Цвет неактивного ивента")] public string EventDColor;
			}
        }
		public string time = "00:00";
		
				
				
		int FakeOnline => (int)IQFakeActive?.Call("GetOnline");
		
		private void UpdatePanelEvent()
		{
			time = TOD_Sky.Instance.Cycle.DateTime.ToString(config.Setting.TimeFormat);
			foreach(BasePlayer player in BasePlayer.activePlayerList.Where(x => !_players.Contains(x)))
			    UIPanelEvent(player);
			
			timer.Once(config.Setting.IntervalPanelEvent, UpdatePanelEvent);
		}		
		
				
				
		private void SHUPPanel(BasePlayer player)
		{
			CuiHelper.DestroyUi(player, ".SH");
            CuiElementContainer container = new CuiElementContainer();
			
			if (_players.Contains(player)) 
				container.Add(new CuiButton
				{
					RectTransform = { AnchorMin = config.GUI.AnchorMinB, AnchorMax = config.GUI.AnchorMaxB, OffsetMin = config.GUI.OffsetMinB, OffsetMax = config.GUI.OffsetMaxB },
					Button = { Color = "0.9686275 0.9176471 0.8784314 0.02921569", Material = "assets/icons/greyout.mat", Command = "xpanel" },
					Text = { Text = "<<", Align = TextAnchor.MiddleCenter, FontSize = 13, Color = "1 1 1 0.6" }
				}, "Overlay", ".SH");
			else 
				container.Add(new CuiButton
				{
					RectTransform = { AnchorMin = config.GUI.AnchorMinB, AnchorMax = config.GUI.AnchorMaxB, OffsetMin = config.GUI.OffsetMinB, OffsetMax = config.GUI.OffsetMaxB },
					Button = { Color = "0.9686275 0.9176471 0.8784314 0.02921569", Material = "assets/icons/greyout.mat", Command = "xpanel" },
					Text = { Text = ">>", Align = TextAnchor.MiddleCenter, FontSize = 13, Color = "1 1 1 0.6" }
				}, "Overlay", ".SH");
			
			CuiHelper.AddUi(player, container);
		}
		
		private void Unload()
		{
			foreach (BasePlayer player in BasePlayer.activePlayerList)
			{
				CuiHelper.DestroyUi(player, ".XPanel");
				CuiHelper.DestroyUi(player, ".XPanelEvent");
				CuiHelper.DestroyUi(player, ".XPanelInfo");
				CuiHelper.DestroyUi(player, ".SH");
			}
		}
        protected override void SaveConfig() => Config.WriteObject(config);
		public List<BasePlayer> _players = new List<BasePlayer>();
		
				
		[PluginReference] private Plugin ImageLibrary, IQFakeActive, FGS;
		
		private void OnEntitySpawned(BaseNetworkable entity)
		{
			if (entity is CargoShip)
			{
				_activeevents["CargoShip"] = true;
				_events.Add(entity);
			}
			if (entity is CargoPlane)
			{
				_activeevents["CargoPlane"] = true;
				_events.Add(entity);
			}
			if (entity is BradleyAPC)
			{
				_activeevents["BradleyAPC"] = true;
				_events.Add(entity);
			}
			if (entity is BaseHelicopter)
			{
				_activeevents["BaseHelicopter"] = true;
				_events.Add(entity);
			}
			if (entity is CH47Helicopter)
			{
				_activeevents["CH47Helicopter"] = true;
				_events.Add(entity);
			}
		}
		
		void SyncReservedFinish()
        {
            PrintWarning($"{Name} - успешно синхронизирована с IQFakeActive");
            PrintWarning("=============SYNC==================");
        }
		
		private void UIPanel(BasePlayer player)
        {
            CuiHelper.DestroyUi(player, ".XPanel");
            CuiElementContainer container = new CuiElementContainer();
		   		 		  						  	   		  	 	 		  	   		  	  			  	 		
			container.Add(new CuiPanel
            {
                RectTransform = { AnchorMin = config.GUI.AnchorMinO, AnchorMax = config.GUI.AnchorMaxO, OffsetMin = config.GUI.OffsetMinO, OffsetMax = config.GUI.OffsetMaxO },
                Image = { Color = "0.9686275 0.9176471 0.8784314 0.02921569", Material = "assets/icons/greyout.mat" }
            }, "Hud", ".XPanel");
			
			container.Add(new CuiPanel
            {
                RectTransform = { AnchorMin = "0 0", AnchorMax = "1 1", OffsetMin = "25 3", OffsetMax = "-4 -3" },
                Image = { Color = "0 0 0 0" }
            }, ".XPanel", ".XPanel_Progress");
		   		 		  						  	   		  	 	 		  	   		  	  			  	 		
			container.Add(new CuiButton
            {
                RectTransform = { AnchorMin = "0 0", AnchorMax = "0 1", OffsetMin = "4 5", OffsetMax = "20 -5" },
                Button = { Color = "0.90004359 0.90004359 0.90004359 0.6", Sprite = "assets/icons/broadcast.png" },
                Text = { Text = "" }
            }, ".XPanel");
		   		 		  						  	   		  	 	 		  	   		  	  			  	 		
			container.Add(new CuiPanel
            {
                RectTransform = { AnchorMin = $"PanelP2 ? 1 : PanelP 0", AnchorMax = PanelJ <= 1 ? $"{PanelJ} 1" : "1 1", OffsetMax = "0 0" },
                Image = { Color = config.GUI.ColorJoining, Material = "assets/icons/greyout.mat" }
            }, ".XPanel_Progress");				
			
			container.Add(new CuiPanel
            {
                RectTransform = { AnchorMin = "0 0", AnchorMax = $"PanelP2 ? 1 : PanelP 1", OffsetMax = "0 0" },
                Image = { Color = config.GUI.ColorOnline, Material = "assets/icons/greyout.mat" }
            }, ".XPanel_Progress");			

			container.Add(new CuiLabel
            {
                RectTransform = { AnchorMin = "0 0", AnchorMax = "1 1", OffsetMin = "7 0", OffsetMax = "0 0" },
                Text = { Text = $"{online}/{maxplayers}", Align = TextAnchor.MiddleLeft, FontSize = 13, Color = "1 1 1 0.6" }
            }, ".XPanel_Progress");			
			
			if(joining != 0)
				container.Add(new CuiLabel
				{
					RectTransform = { AnchorMin = "0 0", AnchorMax = "1 1", OffsetMin = "0 0", OffsetMax = "-7 0" },
					Text = { Text = $"+{joining}", Align = TextAnchor.MiddleRight, FontSize = 13, Color = "1 1 1 0.6" }
				}, ".XPanel_Progress");
			
			CuiHelper.AddUi(player, container);
		}
		
			}
}

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