C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
using Newtonsoft.Json;
using Oxide.Core;
using Oxide.Core.Libraries.Covalence;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using Oxide.Core.Configuration;
using UnityEngine;
using UnityEngine.Networking;
using ProtoBuf;
namespace Oxide.Plugins
{
[Info("Server Info GUI", "Dana", "1.3.6")]
[Description("Shows various server information on modern looking Guis.")]
public class ServerInfoGui : CovalencePlugin
{
private PluginConfig _config;
[PluginReference] private Plugin ServerRewards;
[PluginReference] private Plugin Economics;
private static ServerInfoGui _plugin;
public const string PermissionUse = "serverinfogui.use";
public const string PlayerCountImagesPrefix = "PlayerLocationImage_State_";
public const string BalanceImagesPrefix = "PlayerBalance_State_";
private DynamicConfigFile _dataManager;
private PluginData _pluginData;
private ImageManagerBehaviour _imageManager;
private readonly Dictionary<ulong, BaseEntity> _chinookCrates = new Dictionary<ulong, BaseEntity>();
private readonly Dictionary<ulong, BaseEntity> _oilRigCrates = new Dictionary<ulong, BaseEntity>();
private readonly Dictionary<ulong, BaseEntity> _hackingOilRigCrates = new Dictionary<ulong, BaseEntity>();
private readonly Dictionary<ulong, BaseEntity> _hackingChinookCrates = new Dictionary<ulong, BaseEntity>();
private readonly Dictionary<ulong, BaseEntity> _patrolHelicopters = new Dictionary<ulong, BaseEntity>();
private readonly Dictionary<ulong, BaseEntity> _cargoShips = new Dictionary<ulong, BaseEntity>();
private readonly Dictionary<ulong, BaseEntity> _bradleyHostiles = new Dictionary<ulong, BaseEntity>();
private int _bradleyDestroyedCount = 0;
private readonly Dictionary<ulong, BaseEntity> _airDrops = new Dictionary<ulong, BaseEntity>();
private readonly Dictionary<ulong, BaseEntity> _supplyDrops = new Dictionary<ulong, BaseEntity>();
public delegate void UpdateUiEventHandler();
public event UpdateUiEventHandler OnUiEventUpdated;
private List<MonumentInfo> _oilRigs = new List<MonumentInfo>();
private bool _serverInitialized = false;
private int _lastServerMaxPlayersCount = 0;
private Dictionary<string, GuiConfig> _playerGuiConfigsCache { get; set; } = new Dictionary<string, GuiConfig>();
public static class ConsoleCommands
{
public const string ToggleLocationEnabled = "serverinfogui.toggle.location";
public const string ToggleWeatherEnabled = "serverinfogui.toggle.weather";
public const string ToggleEventsEnabled = "serverinfogui.toggle.events";
public const string TogglePlayersCountEnabled = "serverinfogui.toggle.players";
public const string ToggleBalanceEnabled = "serverinfogui.toggle.balance";
public const string SaveChanges = "serverinfogui.config.save";
public const string ResetChanges = "serverinfogui.config.reset";
}
public class WeatherData
{
public string Name { get; set; }
public float Value { get; set; }
public string ImageUrl { get; set; }
public string Text { get; set; }
public override bool Equals(object obj)
{
var weatherData = obj as WeatherData;
if (weatherData == null)
return false;
return weatherData.Name?.ToLower() == Name?.ToLower();
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}
public WeatherData GetWeatherData(BasePlayer player)
{
if (TOD_Sky.Instance.IsNight)
{
return new WeatherData { Text = "NIGHT", Name = nameof(GuiImages.WeatherNight), ImageUrl = _config.GuiImages.WeatherNight };
}
else
{
var position = player.transform.position;
var conditions = new List<WeatherData>
{
new WeatherData { Text = "RAINY", Name = nameof(GuiImages.WeatherRainy), Value = Climate.GetRain(position), ImageUrl = _config.GuiImages.WeatherRainy },
new WeatherData { Text = "FOGGY", Name = nameof(GuiImages.WeatherFoggy), Value = Climate.GetFog(position), ImageUrl = _config.GuiImages.WeatherFoggy },
new WeatherData { Text = "WINDY", Name = nameof(GuiImages.WeatherWindy), Value = Climate.GetWind(position), ImageUrl = _config.GuiImages.WeatherWindy },
new WeatherData { Text = "THUNDER", Name = nameof(GuiImages.WeatherThunder), Value = Climate.GetThunder(position), ImageUrl = _config.GuiImages.WeatherThunder },
new WeatherData { Text = "RAINBOW", Name = nameof(GuiImages.WeatherRainbow), Value = Climate.GetRainbow(position), ImageUrl = _config.GuiImages.WeatherRainbow }
};
if (conditions.All(c => c.Value <= 0))
return new WeatherData { Text = "SUNNY", Name = nameof(GuiImages.WeatherSunny), ImageUrl = _config.GuiImages.WeatherSunny };
var weather = conditions.Aggregate((c1, c2) => c1.Value > c2.Value ? c1 : c2);
return new WeatherData { Name = weather.Name, ImageUrl = weather.ImageUrl, Text = weather.Text };
}
}
#region Config
protected override void SaveConfig() => Config.WriteObject(_config, true);
protected override void LoadConfig()
{
base.LoadConfig();
_config = Config.ReadObject<PluginConfig>();
if (_config == null)
{
_config = new PluginConfig();
}
SaveConfig();
}
private void ApplyDefaultConfigForPlayer(IPlayer player)
{
GuiConfig guiConfig;
if (!_pluginData.PlayerGuiConfigs.TryGetValue(player.Id, out guiConfig) || guiConfig == null)
{
guiConfig = new GuiConfig();
_playerGuiConfigsCache[player.Id] = guiConfig;
_pluginData.PlayerGuiConfigs[player.Id] = guiConfig;
}
guiConfig.BalanceEnabled = true;
guiConfig.EventsEnabled = _config.EventAlertAirdropSpawn || _config.EventAlertAirdropSupplySignal
|| _config.EventAlertBradleyHostile || _config.EventAlertBradleyKill
|| _config.EventAlertCargoShipSpawn || _config.EventAlertChinookCrateDrop
|| _config.EventAlertChinookCrateHack || _config.EventAlertOilRigCrateHack
|| _config.EventAlertPatrolHelicopterSpawn;
guiConfig.LocationEnabled = _config.LocationOfPlayerEnabled;
guiConfig.PlayersEnabled = true;
guiConfig.WeatherEnabled = _config.WeatherInformationEnabled;
_playerGuiConfigsCache[player.Id] = guiConfig;
}
private void ApplyDefaultConfig()
{
_config = new PluginConfig
{
PlayerBalanceLocation = GetPlayerBalanceMargins(true),
PlayersCountLocation = GetPlayersCountMargins(true),
ChinookLocation = GetChinookMargins(true),
OilRigsLocation = GetOilRigMargins(true),
CargoShipLocation = GetCargoShipMargins(true),
HelicopterLocation = GetHelicopterMargins(true),
BradleyLocation = GetBradleyMargins(true),
AirDropLocation = GetAirDropMargins(true)
};
if (_config.GuiImages.PlayersCountImages == null || !_config.GuiImages.PlayersCountImages.Any())
_config.GuiImages.PlayersCountImages = new List<ProgressImage>
{
new ProgressImage{Value = 0,Url = "https://i.ibb.co/f4z0ydB/players-01.png"},
new ProgressImage{Value = 6,Url = "https://i.ibb.co/nz8pR8X/players-02.png"},
new ProgressImage{Value = 12,Url = "https://i.ibb.co/6ZKkRXc/players-03.png"},
new ProgressImage{Value = 18,Url = "https://i.ibb.co/2Mdg2XD/players-04.png"},
new ProgressImage{Value = 24,Url = "https://i.ibb.co/cwdpKbV/players-05.png"},
new ProgressImage{Value = 30,Url = "https://i.ibb.co/zSxv0Nz/players-06.png"},
new ProgressImage{Value = 36,Url = "https://i.ibb.co/8zvht6L/players-07.png"},
new ProgressImage{Value = 42,Url = "https://i.ibb.co/xDjZwKx/players-08.png"},
new ProgressImage{Value = 48,Url = "https://i.ibb.co/5kgP0dJ/players-09.png"},
new ProgressImage{Value = 54,Url = "https://i.ibb.co/LRGzmFP/players-10.png"},
new ProgressImage{Value = 60,Url = "https://i.ibb.co/K5DYN24/players-11.png"},
new ProgressImage{Value = 66,Url = "https://i.ibb.co/CMLbwJQ/players-12.png"},
new ProgressImage{Value = 72,Url = "https://i.ibb.co/Nry8yhM/players-13.png"},
new ProgressImage{Value = 78,Url = "https://i.ibb.co/gTHstdG/players-14.png"},
new ProgressImage{Value = 90,Url = "https://i.ibb.co/9NmmFZ0/players-15.png"},
new ProgressImage{Value = 100,Url = "https://i.ibb.co/jkp8Rtp/players-16.png"},
};
if (_config.GuiImages.BalanceImages == null || !_config.GuiImages.BalanceImages.Any())
_config.GuiImages.BalanceImages = new List<ProgressImage>
{
new ProgressImage{Value = 0,Url = "https://i.ibb.co/VmPZ504/balance-01.png"},
new ProgressImage{Value = 10,Url = "https://i.ibb.co/PcPRCyk/balance-02.png"},
new ProgressImage{Value = 20,Url = "https://i.ibb.co/GMh25P8/balance-03.png"},
new ProgressImage{Value = 30,Url = "https://i.ibb.co/4fN77G0/balance-04.png"},
new ProgressImage{Value = 40,Url = "https://i.ibb.co/PZ5xhTc/balance-05.png"},
new ProgressImage{Value = 50,Url = "https://i.ibb.co/wYsgBT7/balance-06.png"},
new ProgressImage{Value = 100,Url = "https://i.ibb.co/Jd9Ytyp/balance-07.png"},
new ProgressImage{Value = 500,Url = "https://i.ibb.co/HhmhKJD/balance-08.png"},
new ProgressImage{Value = 1000,Url = "https://i.ibb.co/JtX5qrx/balance-09.png"},
new ProgressImage{Value = 10000,Url = "https://i.ibb.co/xSWdjWn/balance-10.png"},
new ProgressImage{Value = 20000,Url = "https://i.ibb.co/F8bW96f/balance-11.png"},
new ProgressImage{Value = 50000,Url = "https://i.ibb.co/8ghZSFz/balance-12.png"},
new ProgressImage{Value = 100000,Url = "https://i.ibb.co/qpwDJWW/balance-13.png"},
new ProgressImage{Value = 200000,Url = "https://i.ibb.co/K94rb1C/balance-14.png"},
new ProgressImage{Value = 500000,Url = "https://i.ibb.co/j8kL6ds/balance-15.png"},
new ProgressImage{Value = 1000000,Url = "https://i.ibb.co/v3MmkYw/balance-16.png"}
};
}
protected override void LoadDefaultConfig()
{
if (_config == null)
{
ApplyDefaultConfig();
SaveConfig();
}
}
public class PluginConfig
{
[JsonProperty(PropertyName = "Config Menu Command")]
public string MenuCommand { get; set; } = "config";
[JsonProperty(PropertyName = "Game Time - Enabled")]
public bool GameTimeEnabled { get; set; } = true;
[JsonProperty(PropertyName = "Players Count - Online - Enabled")]
public bool ShowOnlineCount { get; set; } = true;
[JsonProperty(PropertyName = "Balance - Economics (Server Rewards = false)")]
public bool BalanceEconomicsEnabled { get; set; } = true;
[JsonProperty(PropertyName = "Server Rewards Symbol")]
public string ServerRewardsSymbol { get; set; } = "RP";
[JsonProperty(PropertyName = "Economics Symbol")]
public string EconomicsSymbol { get; set; } = "Money";
[JsonProperty(PropertyName = "Weather - Enabled")]
public bool WeatherInformationEnabled { get; set; } = true;
[JsonProperty(PropertyName = "Player Location - Grid - Enabled")]
public bool LocationOfPlayerEnabled { get; set; } = true;
[JsonProperty(PropertyName = "Event Alert - Bradley - Hostile")]
public bool EventAlertBradleyHostile { get; set; } = true;
[JsonProperty(PropertyName = "Event Alert - Bradley - Kill")]
public bool EventAlertBradleyKill { get; set; } = false;
[JsonProperty(PropertyName = "Event Alert - Patrol Helicopter - Spawn")]
public bool EventAlertPatrolHelicopterSpawn { get; set; } = true;
[JsonProperty(PropertyName = "Event Alert - Airdrop - Spawn")]
public bool EventAlertAirdropSpawn { get; set; } = true;
[JsonProperty(PropertyName = "Event Alert - Airdrop - Supply Signal")]
public bool EventAlertAirdropSupplySignal { get; set; } = true;
[JsonProperty(PropertyName = "Event Alert - Oil Rig - Crate Hack")]
public bool EventAlertOilRigCrateHack { get; set; } = true;
[JsonProperty(PropertyName = "Event Alert - Chinook - Crate Drop")]
public bool EventAlertChinookCrateDrop { get; set; } = true;
[JsonProperty(PropertyName = "Event Alert - Chinook - Crate Hack")]
public bool EventAlertChinookCrateHack { get; set; } = false;
[JsonProperty(PropertyName = "Event Alert - Cargo Ship - Spawn")]
public bool EventAlertCargoShipSpawn { get; set; } = true;
/*[JsonProperty(PropertyName = "Event Trigger Visibility Duration In Seconds")]
public float EventTriggerVisibilityDuration { get; set; } = 3f;*/
[JsonProperty(PropertyName = "Weather Info UI Update Interval In Seconds")]
public float WeatherInfoUiUpdateInterval { get; set; } = 3f;
[JsonProperty(PropertyName = "Player Location UI Update Interval In Seconds")]
public float PlayerLocationUiUpdateInterval { get; set; } = 3f;
[JsonProperty(PropertyName = "Player Location Show Coordinates")]
public bool PlayerLocationShowCoordinates { get; set; }
[JsonProperty(PropertyName = "Player Balance UI Update Interval In Seconds")]
public float PlayerBalanceUiUpdateInterval { get; set; } = 3f;
[JsonProperty(PropertyName = "Players Statistics UI Update Interval In Seconds")]
public float PlayersStatisticsUiUpdateInterval { get; set; } = 3f;
[JsonProperty(PropertyName = "Player Balance GUI Location")]
public Margin PlayerBalanceLocation { get; set; }
[JsonProperty(PropertyName = "Players Count GUI Location")]
public Margin PlayersCountLocation { get; set; }
[JsonProperty(PropertyName = "Chinook GUI Location")]
public Margin ChinookLocation { get; set; }
[JsonProperty(PropertyName = "Oil Rigs GUI Location")]
public Margin OilRigsLocation { get; set; }
[JsonProperty(PropertyName = "Cargo Ship GUI Location")]
public Margin CargoShipLocation { get; set; }
[JsonProperty(PropertyName = "Patrol Helicopter GUI Location")]
public Margin HelicopterLocation { get; set; }
[JsonProperty(PropertyName = "Bradley GUI Location")]
public Margin BradleyLocation { get; set; }
[JsonProperty(PropertyName = "Air Drop GUI Location")]
public Margin AirDropLocation { get; set; }
[JsonProperty(PropertyName = "GUI Images")]
public GuiImages GuiImages { get; set; } = new GuiImages();
}
public class Margin
{
public Margin(int top, int right, int bottom, int left)
{
Top = top;
Right = right;
Bottom = bottom;
Left = left;
}
public int Top { get; set; }
public int Right { get; set; }
public int Bottom { get; set; }
public int Left { get; set; }
public override string ToString() => $"Top: {Top}, Right: {Right}, Bottom: {Bottom}, Left: {Left}";
}
public class GuiImages
{
[JsonProperty(PropertyName = "Check Mark Icon")]
public string Checked { get; set; } = "https://i.ibb.co/CPCK3cs/check.png";
[JsonProperty(PropertyName = "Player Section Icon")]
public string PlayerSection { get; set; } = "https://i.ibb.co/Rps0JgG/player-location-3x.png";
[JsonProperty(PropertyName = "Player Coordinates Icon")]
public string PlayerCoordinates { get; set; } = "https://i.ibb.co/dbYZfv6/player-coordinates-3x.png";
#region Weather Images
[JsonProperty(PropertyName = "Weather - Sunny")]
public string WeatherSunny { get; set; } = "https://i.ibb.co/89QCpPX/weather-sunny-3x.png";
[JsonProperty(PropertyName = "Weather - Night")]
public string WeatherNight { get; set; } = "https://i.ibb.co/k84xm00/weather-night-3x.png";
[JsonProperty(PropertyName = "Weather - Rainy")]
public string WeatherRainy { get; set; } = "https://i.ibb.co/3kTKGmv/weather-rainy-3x.png";
[JsonProperty(PropertyName = "Weather - Foggy")]
public string WeatherFoggy { get; set; } = "https://i.ibb.co/s6PDXQB/weather-foggy-3x.png";
[JsonProperty(PropertyName = "Weather - Thunder")]
public string WeatherThunder { get; set; } = "https://i.ibb.co/4gxrvCF/weather-thunder-3x.png";
[JsonProperty(PropertyName = "Weather - Windy")]
public string WeatherWindy { get; set; } = "https://i.ibb.co/CMdNkkZ/weather-windy-3x.png";
[JsonProperty(PropertyName = "Weather - Rainbow")]
public string WeatherRainbow { get; set; } = "https://i.ibb.co/k3dNj3b/weather-rainbow-3x.png";
#endregion Weather Images
#region Events Images
[JsonProperty(PropertyName = "Events - Chinook Crate Drop - Active")]
public string EventsChinookDropActive { get; set; } = "https://i.imgur.com/rIPW6L9.png";
[JsonProperty(PropertyName = "Events - Chinook Crate Drop - Inactive")]
public string EventsChinookDropInactive { get; set; } = "https://i.imgur.com/IFbIr5l.png";
[JsonProperty(PropertyName = "Events - Locked Crate On Oil Rig - Active")]
public string EventsOilRigCrateActive { get; set; } = "https://i.imgur.com/TnOIJz5.png";
[JsonProperty(PropertyName = "Events - Locked Crate On Oil Rig - Inactive")]
public string EventsOilRigCrateInactive { get; set; } = "https://i.imgur.com/dv8uva9.png";
[JsonProperty(PropertyName = "Events - Spawn Cargo Ship - Active")]
public string EventsSpawnCargoShipActive { get; set; } = "https://i.imgur.com/2vCIes5.png";
[JsonProperty(PropertyName = "Events - Spawn Cargo Ship - Inactive")]
public string EventsSpawnCargoShipInactive { get; set; } = "https://i.imgur.com/KaQ1EO0.png";
[JsonProperty(PropertyName = "Events - Spawn Patrol Helicopter - Active")]
public string EventsSpawnPatrolHelicopterActive { get; set; } = "https://i.imgur.com/4CcJYBm.png";
[JsonProperty(PropertyName = "Events - Spawn Patrol Helicopter - Inactive")]
public string EventsSpawnPatrolHelicopterInactive { get; set; } = "https://i.imgur.com/hNixysj.png";
[JsonProperty(PropertyName = "Events - Destroy of Bradley on Launch Site - Active")]
public string EventsDestroyBradleyOnLaunchsiteActive { get; set; } = "https://i.imgur.com/Xvdobts.png";
[JsonProperty(PropertyName = "Events - Destroy of Bradley on Launch Site - Inactive")]
public string EventsDestroyBradleyOnLaunchsiteInactive { get; set; } = "https://i.imgur.com/xjWhr1J.png";
[JsonProperty(PropertyName = "Events - Server Airdrop Spawn - Active")]
public string EventsAirdropActive { get; set; } = "https://i.imgur.com/VrldJO7.png";
[JsonProperty(PropertyName = "Events - Server Airdrop Spawn - Inactive")]
public string EventsAirdropInactive { get; set; } = "https://i.imgur.com/UFY232k.pngg";
#endregion Events Images
#region Progress Images
[JsonProperty(PropertyName = "Players Count Progress Images")]
public List<ProgressImage> PlayersCountImages { get; set; } = new List<ProgressImage>();
[JsonProperty(PropertyName = "RP/Money Progress Images")]
public List<ProgressImage> BalanceImages { get; set; } = new List<ProgressImage>();
#endregion Players Count Images
}
public class ProgressImage
{
public double Value { get; set; }
public string Url { get; set; }
}
#endregion Config
#region Data
private void SaveData()
{
_dataManager.WriteObject(_pluginData);
}
private void LoadData()
{
try
{
_pluginData = _dataManager.ReadObject<PluginData>();
foreach (var data in _pluginData.PlayerGuiConfigs)
{
_playerGuiConfigsCache[data.Key] = data.Value;
}
}
catch (Exception exception)
{
PrintError("Data file is corrupt, error message:");
PrintError(exception.Message);
if (exception.InnerException != null)
{
PrintError($"Inner exception message: {exception.InnerException.Message}");
}
PrintWarning("New data file created");
_pluginData = new PluginData();
SaveData();
}
}
public class PluginData
{
[JsonProperty(PropertyName = "Players Gui Config")]
public Dictionary<string, GuiConfig> PlayerGuiConfigs { get; set; } = new Dictionary<string, GuiConfig>();
}
public class GuiConfig
{
public bool TimeEnabled { get; set; } = true;
public bool LocationEnabled { get; set; } = true;
public bool WeatherEnabled { get; set; } = true;
public bool EventsEnabled { get; set; } = true;
public bool PlayersEnabled { get; set; } = true;
public bool BalanceEnabled { get; set; } = true;
}
#endregion Data
#region Image Helpers
public class ImageData
{
public ImageData()
{
IsUrl = true;
Image = string.Empty;
}
public string Image { get; set; }
public bool IsUrl { get; set; }
}
public ImageData GetImage(string name, string url)
{
if (_imageManager == null)
{
_imageManager = new GameObject("ImageManagerGameObject").AddComponent<ImageManagerBehaviour>();
return new ImageData
{
Image = url,
IsUrl = true
};
}
var image = _imageManager.GetImage(name);
if (string.IsNullOrWhiteSpace(image))
{
ServerMgr.Instance.StartCoroutine(_imageManager.DownloadImage(name, url));
return new ImageData
{
Image = url,
IsUrl = true
};
}
return new ImageData
{
Image = image,
IsUrl = false
};
}
public ImageData GetWeatherImage(BasePlayer player)
{
var weather = GetWeatherData(player);
return GetImage(weather.Name, weather.ImageUrl);
}
public ImageData GetPlayerLocationImage()
{
return _config.PlayerLocationShowCoordinates ?
GetImage(nameof(GuiImages.PlayerCoordinates), _config.GuiImages.PlayerCoordinates) :
GetImage(nameof(GuiImages.PlayerSection), _config.GuiImages.PlayerSection);
}
public ImageData GetChinookImage()
{
if ((_config.EventAlertChinookCrateDrop && _chinookCrates.Count > 0)
|| (_config.EventAlertChinookCrateHack && _hackingChinookCrates.Count > 0))
return GetImage(nameof(GuiImages.EventsChinookDropActive), _config.GuiImages.EventsChinookDropActive);
return GetImage(nameof(GuiImages.EventsChinookDropInactive), _config.GuiImages.EventsChinookDropInactive);
}
public ImageData GetOilRigImage()
{
return _hackingOilRigCrates.Count > 0
? GetImage(nameof(GuiImages.EventsOilRigCrateActive), _config.GuiImages.EventsOilRigCrateActive)
: GetImage(nameof(GuiImages.EventsOilRigCrateInactive), _config.GuiImages.EventsOilRigCrateInactive);
}
public ImageData GetCargoShipImage()
{
return _cargoShips.Count > 0
? GetImage(nameof(GuiImages.EventsSpawnCargoShipActive), _config.GuiImages.EventsSpawnCargoShipActive)
: GetImage(nameof(GuiImages.EventsSpawnCargoShipInactive), _config.GuiImages.EventsSpawnCargoShipInactive);
}
public ImageData GetHelicopterImage()
{
return _patrolHelicopters.Count > 0
? GetImage(nameof(GuiImages.EventsSpawnPatrolHelicopterActive), _config.GuiImages.EventsSpawnPatrolHelicopterActive)
: GetImage(nameof(GuiImages.EventsSpawnPatrolHelicopterInactive), _config.GuiImages.EventsSpawnPatrolHelicopterInactive);
}
public ImageData GetBradleyImage()
{
if ((_config.EventAlertBradleyHostile && _bradleyHostiles.Count > 0)
|| (_config.EventAlertBradleyKill && _bradleyDestroyedCount > 0))
return GetImage(nameof(GuiImages.EventsDestroyBradleyOnLaunchsiteActive), _config.GuiImages.EventsDestroyBradleyOnLaunchsiteActive);
return GetImage(nameof(GuiImages.EventsDestroyBradleyOnLaunchsiteInactive), _config.GuiImages.EventsDestroyBradleyOnLaunchsiteInactive);
}
public ImageData GetAirdropImage()
{
if ((_config.EventAlertAirdropSpawn && _airDrops.Count > 0)
|| (_config.EventAlertAirdropSupplySignal && _supplyDrops.Count > 0))
return GetImage(nameof(GuiImages.EventsAirdropActive), _config.GuiImages.EventsAirdropActive);
return GetImage(nameof(GuiImages.EventsAirdropInactive), _config.GuiImages.EventsAirdropInactive);
}
public ImageData GetPlayersCountImage()
{
var activePlayersCount = BasePlayer.activePlayerList.Count;
var maxServerPlayers = server.MaxPlayers; ;
var percentage = (double)activePlayersCount * 100 / maxServerPlayers;
var image = _config.GuiImages.PlayersCountImages.OrderByDescending(x => x.Value).FirstOrDefault(x => x.Value <= percentage);
if (image == null)
{
return new ImageData();
}
return GetImage($"{PlayerCountImagesPrefix}{image.Value}", image.Url);
}
public ImageData GetBalanceImage(double balance)
{
var image = _config.GuiImages.BalanceImages.OrderByDescending(x => x.Value).FirstOrDefault(x => x.Value <= balance);
if (image == null)
{
return new ImageData();
}
return GetImage($"{BalanceImagesPrefix}{image.Value}", image.Url);
}
#endregion Image Helpers
#region Behaviors
public class GuiManager : MonoBehaviour
{
private BasePlayer _player;
private double _playerBalance = 0;
private float _deltaTimeWeather = 0;
private float _deltaTimePlayerLocation = 0;
private float _deltaTimeGameTime = 0;
private float _deltaTimeDownloadBootstraper = 0;
private float _deltaTimePlayerBalance = 0;
private float _deltaTimePlayersCount = 0;
private float _downloadBootstraperTime = 20f;
private WeatherData _lastWeatherData = new WeatherData();
private string _lastLocation = "";
public void ShowAll()
{
ShowBalance();
ShowPlayerLocationImage();
ShowPlayerLocation();
ShowGameTime();
ShowWeatherInfo();
ShowPlayersCount();
ShowEventsToolbar();
}
public void OnUiEventUpdated()
{
if (_plugin == null)
return;
ShowEventsToolbar();
}
private void Awake()
{
_player = GetComponent<BasePlayer>();
if (_player == null)
{
enabled = false;
return;
}
_plugin.OnUiEventUpdated += OnUiEventUpdated;
var balance = 0d;
if (!_plugin._config.BalanceEconomicsEnabled)
{
balance = _plugin.GetServerRewardPoints(_player.userID);
}
if (_plugin._config.BalanceEconomicsEnabled)
{
balance = _plugin.GetEconomicsBalance(_player.userID);
}
SetPlayerBalance(balance);
ShowAll();
}
private void Update()
{
if (_plugin == null)
return;
_deltaTimeWeather += Time.deltaTime;
_deltaTimePlayerBalance += Time.deltaTime;
_deltaTimePlayerLocation += Time.deltaTime;
_deltaTimeGameTime += Time.deltaTime;
_deltaTimeDownloadBootstraper += Time.deltaTime;
_deltaTimePlayersCount += Time.deltaTime;
if (_deltaTimeWeather >= _plugin._config.WeatherInfoUiUpdateInterval)
{
_deltaTimeWeather = 0;
var currentWeatherInfo = _plugin.GetWeatherData(_player);
if (!currentWeatherInfo.Equals(_lastWeatherData))
{
ShowWeatherInfo();
_lastWeatherData = currentWeatherInfo;
}
}
if (_deltaTimePlayerBalance >= _plugin._config.PlayerBalanceUiUpdateInterval)
{
_deltaTimePlayerBalance = 0;
var points = 0d;
if (_plugin._config.BalanceEconomicsEnabled)
points = _plugin.GetEconomicsBalance(_player.userID);
else
points = _plugin.GetServerRewardPoints(_player.userID);
SetPlayerBalance(points);
}
if (_deltaTimePlayerLocation >= _plugin._config.PlayerLocationUiUpdateInterval)
{
var currentLocation = _plugin.GetGrid(_player.ServerPosition);
_deltaTimePlayerLocation = 0;
if (_lastLocation != currentLocation)
{
_lastLocation = currentLocation;
ShowPlayerLocation();
ShowPlayerLocationImage();
}
}
if (_deltaTimeGameTime >= 1)
{
_deltaTimeGameTime = 0;
ShowGameTime();
}
if (_deltaTimeDownloadBootstraper >= 3 && _downloadBootstraperTime > 0)
{
_deltaTimeDownloadBootstraper = 0;
_downloadBootstraperTime -= 3;
ShowPlayersCount();
ShowEventsToolbar();
//ShowPlayerLocationImage();
}
if (_deltaTimePlayersCount >= _plugin._config.PlayersStatisticsUiUpdateInterval
&& _plugin._lastServerMaxPlayersCount != _plugin.server.MaxPlayers)
{
_plugin._lastServerMaxPlayersCount = _plugin.server.MaxPlayers;
_deltaTimePlayersCount = 0;
ShowPlayersCount();
}
}
public void ShowEventsToolbar()
{
if (!_plugin._config.EventAlertAirdropSpawn &&
!_plugin._config.EventAlertAirdropSupplySignal &&
!_plugin._config.EventAlertBradleyHostile &&
!_plugin._config.EventAlertBradleyKill &&
!_plugin._config.EventAlertCargoShipSpawn &&
!_plugin._config.EventAlertChinookCrateDrop &&
!_plugin._config.EventAlertChinookCrateHack &&
!_plugin._config.EventAlertOilRigCrateHack &&
!_plugin._config.EventAlertPatrolHelicopterSpawn)
{
CuiHelper.DestroyUi(_player, Ui.Panels.EventsToolbar.ToString());
return;
}
GuiConfig guiConfig;
if (_plugin._playerGuiConfigsCache.TryGetValue(_player.UserIDString, out guiConfig) && guiConfig != null)
{
if (!guiConfig.EventsEnabled)
{
CuiHelper.DestroyUi(_player, Ui.Panels.EventsToolbar.ToString());
return;
}
}
var mainContainer = Ui.Container(Ui.Panels.EventsToolbar, Ui.Color(Ui.ColorCode.Black, 0f), Ui.GetMin(0, 0), Ui.GetMax(0, 0), parent: Ui.Panels.Under);
//chinook image position
var chinookCrateImagePosition = new
{
Min = Ui.GetMin(_plugin._config.ChinookLocation.Left, _plugin._config.ChinookLocation.Bottom),
Max = Ui.GetMax(_plugin._config.ChinookLocation.Right, _plugin._config.ChinookLocation.Top)
};
//oil rig image position
var oilRigImagePosition = new
{
Min = Ui.GetMin(_plugin._config.OilRigsLocation.Left, _plugin._config.OilRigsLocation.Bottom),
Max = Ui.GetMax(_plugin._config.OilRigsLocation.Right, _plugin._config.OilRigsLocation.Top)
};
//cargo ship image position
var cargoShipImagePosition = new
{
Min = Ui.GetMin(_plugin._config.CargoShipLocation.Left, _plugin._config.CargoShipLocation.Bottom),
Max = Ui.GetMax(_plugin._config.CargoShipLocation.Right, _plugin._config.CargoShipLocation.Top)
};
//helicopter image position
var helicopterImagePosition = new
{
Min = Ui.GetMin(_plugin._config.HelicopterLocation.Left, _plugin._config.HelicopterLocation.Bottom),
Max = Ui.GetMax(_plugin._config.HelicopterLocation.Right, _plugin._config.HelicopterLocation.Top)
};
//Bradley image position
var bradleyImagePosition = new
{
Min = Ui.GetMin(_plugin._config.BradleyLocation.Left, _plugin._config.BradleyLocation.Bottom),
Max = Ui.GetMax(_plugin._config.BradleyLocation.Right, _plugin._config.BradleyLocation.Top)
};
//airdrop image position
var airDropImagePosition = new
{
Min = Ui.GetMin(_plugin._config.AirDropLocation.Left, _plugin._config.AirDropLocation.Bottom),
Max = Ui.GetMax(_plugin._config.AirDropLocation.Right, _plugin._config.AirDropLocation.Top)
};
//chinook crate
var chinookImage = _plugin.GetChinookImage();
Ui.Image(ref mainContainer,
Ui.Panels.EventsToolbar,
Ui.Color(Ui.ColorCode.White),
chinookImage.Image,
chinookImage.IsUrl,
chinookCrateImagePosition.Min,
chinookCrateImagePosition.Max);
//oil rig crate
var oilRigImage = _plugin.GetOilRigImage();
Ui.Image(ref mainContainer,
Ui.Panels.EventsToolbar,
Ui.Color(Ui.ColorCode.White),
oilRigImage.Image,
oilRigImage.IsUrl,
oilRigImagePosition.Min,
oilRigImagePosition.Max);
//cargo ship
var cargoShipImage = _plugin.GetCargoShipImage();
Ui.Image(ref mainContainer,
Ui.Panels.EventsToolbar,
Ui.Color(Ui.ColorCode.White),
cargoShipImage.Image,
cargoShipImage.IsUrl,
cargoShipImagePosition.Min,
cargoShipImagePosition.Max);
//helicopter
var helicopterImage = _plugin.GetHelicopterImage();
Ui.Image(ref mainContainer,
Ui.Panels.EventsToolbar,
Ui.Color(Ui.ColorCode.White),
helicopterImage.Image,
helicopterImage.IsUrl,
helicopterImagePosition.Min,
helicopterImagePosition.Max);
//Bradley
var bradleyImage = _plugin.GetBradleyImage();
Ui.Image(ref mainContainer,
Ui.Panels.EventsToolbar,
Ui.Color(Ui.ColorCode.White),
bradleyImage.Image,
bradleyImage.IsUrl,
bradleyImagePosition.Min,
bradleyImagePosition.Max);
//airdrop
var airdropImage = _plugin.GetAirdropImage();
Ui.Image(ref mainContainer,
Ui.Panels.EventsToolbar,
Ui.Color(Ui.ColorCode.White),
airdropImage.Image,
airdropImage.IsUrl,
airDropImagePosition.Min,
airDropImagePosition.Max);
CuiHelper.DestroyUi(_player, Ui.Panels.EventsToolbar.ToString());
CuiHelper.AddUi(_player, mainContainer);
}
public void ShowPlayersCount()
{
if (!_plugin._config.ShowOnlineCount)
return;
GuiConfig guiConfig;
if (_plugin._playerGuiConfigsCache.TryGetValue(_player.UserIDString, out guiConfig) && guiConfig != null)
{
if (!guiConfig.PlayersEnabled)
{
CuiHelper.DestroyUi(_player, Ui.Panels.PlayersStatistics.ToString());
return;
}
}
//players count image position
var playersCountImagePosition = new
{
Min = Ui.GetMin(_plugin._config.PlayersCountLocation.Left, _plugin._config.PlayersCountLocation.Bottom),
Max = Ui.GetMax(_plugin._config.PlayersCountLocation.Right, _plugin._config.PlayersCountLocation.Top)
};
var mainContainer = Ui.Container(Ui.Panels.PlayersStatistics, Ui.Color(Ui.ColorCode.Black, 0f),
playersCountImagePosition.Min,
playersCountImagePosition.Max,
parent: Ui.Panels.Under);
//players count
var playersCountImage = _plugin.GetPlayersCountImage();
Ui.Image(ref mainContainer,
Ui.Panels.PlayersStatistics,
Ui.Color(Ui.ColorCode.White),
playersCountImage.Image,
playersCountImage.IsUrl,
Ui.GetMin(0, 0),
Ui.GetMax(0, 0));
Ui.Label(ref mainContainer,
Ui.Panels.PlayersStatistics,
BasePlayer.activePlayerList.Count.ToString(),
24,
Ui.GetMin(8, 18, 120, 120),
Ui.GetMax(65, 74, 120, 120),
textColor: Ui.Color(Ui.ColorCode.AndroidGreen),
align: TextAnchor.LowerRight);
Ui.Label(ref mainContainer,
Ui.Panels.PlayersStatistics,
BasePlayer.sleepingPlayerList.Count.ToString(),
16,
Ui.GetMin(65, 20, 120, 120),
Ui.GetMax(23, 74, 120, 120),
textColor: Ui.Color(Ui.ColorCode.PaleSilver),
align: TextAnchor.LowerLeft);
CuiHelper.DestroyUi(_player, Ui.Panels.PlayersStatistics.ToString());
CuiHelper.AddUi(_player, mainContainer);
}
public void ShowBalance()
{
if (!_plugin._config.BalanceEconomicsEnabled && !_plugin.plugins.Exists(nameof(ServerRewards)))
{
CuiHelper.DestroyUi(_player, Ui.Panels.Balance.ToString());
return;
}
if (_plugin._config.BalanceEconomicsEnabled && !_plugin.plugins.Exists(nameof(Economics)))
{
CuiHelper.DestroyUi(_player, Ui.Panels.Balance.ToString());
return;
}
GuiConfig guiConfig;
if (_plugin._playerGuiConfigsCache.TryGetValue(_player.UserIDString, out guiConfig) && guiConfig != null)
{
if (!guiConfig.BalanceEnabled)
{
CuiHelper.DestroyUi(_player, Ui.Panels.Balance.ToString());
return;
}
}
//balance image position
var balanceImagePosition = new
{
Min = Ui.GetMin(_plugin._config.PlayerBalanceLocation.Left, _plugin._config.PlayerBalanceLocation.Bottom),
Max = Ui.GetMax(_plugin._config.PlayerBalanceLocation.Right, _plugin._config.PlayerBalanceLocation.Top)
};
var mainContainer = Ui.Container(Ui.Panels.Balance, Ui.Color(Ui.ColorCode.Black, 0f),
balanceImagePosition.Min,
balanceImagePosition.Max,
parent: Ui.Panels.Under);
//balance
var balanceImage = _plugin.GetBalanceImage(_playerBalance);
Ui.Image(ref mainContainer,
Ui.Panels.Balance,
Ui.Color(Ui.ColorCode.White),
balanceImage.Image,
balanceImage.IsUrl,
Ui.GetMin(0, 0),
Ui.GetMax(0, 0));
Ui.Label(ref mainContainer,
Ui.Panels.Balance,
_playerBalance.ToString("N0"),
18,
Ui.GetMin(18, 28, 120, 120),
Ui.GetMax(18, 70, 120, 120),
textColor: Ui.Color(Ui.ColorCode.Green));
Ui.Label(ref mainContainer,
Ui.Panels.Balance,
!_plugin._config.BalanceEconomicsEnabled ? _plugin._config.ServerRewardsSymbol : _plugin._config.EconomicsSymbol,
14,
Ui.GetMin(30, 15, 120, 120),
Ui.GetMax(30, 87, 120, 120),
textColor: Ui.Color(Ui.ColorCode.ChocolateWeb));
CuiHelper.DestroyUi(_player, Ui.Panels.Balance.ToString());
CuiHelper.AddUi(_player, mainContainer);
}
public void ShowPlayerLocationImage()
{
if (!_plugin._config.LocationOfPlayerEnabled)
{
CuiHelper.DestroyUi(_player, Ui.Panels.PlayerLocationImage.ToString());
return;
}
GuiConfig guiConfig;
if (_plugin._playerGuiConfigsCache.TryGetValue(_player.UserIDString, out guiConfig) && guiConfig != null)
{
if (!guiConfig.LocationEnabled)
{
CuiHelper.DestroyUi(_player, Ui.Panels.PlayerLocationImage.ToString());
return;
}
}
var mainContainer = Ui.Container(Ui.Panels.PlayerLocationImage, Ui.Color(Ui.ColorCode.Black, 0f), Ui.GetMin(0, 0), Ui.GetMax(0, 0), parent: Ui.Panels.Under);
//location
var locationImage = _plugin.GetPlayerLocationImage();
var playerLocationImagePosition = new
{
Min = Ui.GetMin(23, 915),
Max = Ui.GetMax(1798, 105)
};
if (_plugin._config.PlayerLocationShowCoordinates)
{
playerLocationImagePosition = new
{
Min = Ui.GetMin(23, 915),
Max = Ui.GetMax(1698, 105)
};
}
Ui.Image(ref mainContainer,
Ui.Panels.PlayerLocationImage,
Ui.Color(Ui.ColorCode.White),
locationImage?.Image,
locationImage != null ? locationImage.IsUrl : false,
playerLocationImagePosition.Min,
playerLocationImagePosition.Max);
CuiHelper.DestroyUi(_player, Ui.Panels.PlayerLocationImage.ToString());
CuiHelper.AddUi(_player, mainContainer);
}
public void ShowPlayerLocation()
{
if (!_plugin._config.LocationOfPlayerEnabled)
{
CuiHelper.DestroyUi(_player, Ui.Panels.PlayerLocationText.ToString());
return;
}
GuiConfig guiConfig;
if (_plugin._playerGuiConfigsCache.TryGetValue(_player.UserIDString, out guiConfig) && guiConfig != null)
{
if (!guiConfig.LocationEnabled)
{
CuiHelper.DestroyUi(_player, Ui.Panels.PlayerLocationText.ToString());
return;
}
}
var mainContainer = Ui.Container(Ui.Panels.PlayerLocationText, Ui.Color(Ui.ColorCode.Black, 0f), Ui.GetMin(0, 0), Ui.GetMax(0, 0), parent: Ui.Panels.Under);
//location
var playerLocationTextPosition = new
{
Min = Ui.GetMin
// ... [Code preview truncated due to length. Full source in attached file] ...