C#:
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Oxide.Core;
using Oxide.Core.Plugins;
using Oxide.Game.Rust;
using Oxide.Game.Rust.Cui;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("InfoPanel", "https://topplugin.ru/", "1.0.0")]
[Description("A little panel with useful information.")]
public class InfoPanel : RustPlugin
{
#region DefaultConfigs
private static string DefaultFontColor = "1 1 1 1";
public bool IsReady;
#endregion
private Timer TestTimer;
private Dictionary<string, Dictionary<string, IPanel>> PlayerPanels = new Dictionary<string, Dictionary<string, IPanel>>();
private Dictionary<string, Dictionary<string, IPanel>> PlayerDockPanels = new Dictionary<string, Dictionary<string, IPanel>>();
private Dictionary<string, List<string>> LoadedPluginPanels = new Dictionary<string, List<string>>();
#region DefaultConfig
private static PluginConfig Settings;
private readonly List<string> TimeFormats = new List<string>
{
"H:mm",
"HH:mm",
"h:mm",
"h:mm tt",
};
PluginConfig DefaultConfig()
{
var DefaultConfig = new PluginConfig
{
ThirdPartyPanels = new Dictionary<string, Dictionary<string, PanelConfig>>(),
Messages = Messages,
TimeFormats = TimeFormats,
CompassDirections = new Dictionary<string, string>
{
{"n","North"},
{"ne","Northeast"},
{"e","East"},
{"se","Southeast"},
{"s","South"},
{"sw","Southwest"},
{"w","West"},
{"nw","Northwest"},
},
Docks = new Dictionary<string, DockConfig>
{
{ "BottomLeftDock", new DockConfig
{
Available = true,
Width = 0.18f,
Height = 0.03f,
AnchorX = "Left",
AnchorY = "Bottom",
Margin = "0.005 0.165 0.005 0.005",
BackgroundColor = "0 0 0 0.4",
}
},
{ "BottomRightDock", new DockConfig
{
Available = true,
Width = 0.19f,
Height = 0.03f,
AnchorX = "Right",
AnchorY = "Bottom",
Margin = "0.005 0.005 0.005 0.165",
BackgroundColor = "0 0 0 0.4",
}
},
{ "TopLeftDock", new DockConfig
{
Available = true,
Width = 0.175f,
Height = 0.03f,
AnchorX = "Left",
AnchorY = "Top",
Margin = "0.005 0.005 0.005 0.005",
BackgroundColor = "0 0 0 0.4",
}
},
{ "TopRightDock", new DockConfig
{
Available = true,
Width = 0.29f,
Height = 0.03f,
AnchorX = "Right",
AnchorY = "Top",
Margin = "0.005 0.005 0.005 0.005",
BackgroundColor = "0 0 0 0.4",
}
}
},
Panels = new Dictionary<string, PanelConfig>
{
{"Clock", new PanelConfig
{
Available = true,
Dock = "BottomLeftDock",
Order = 1,
AnchorX = "Left",
AnchorY = "Bottom",
Margin = "0 0 0 0.01",
Width = 0.2f,
Height = 0.95f,
BackgroundColor = "0.1 0.1 0.1 0",
Text = new PanelTextConfig
{
Align = TextAnchor.MiddleCenter,
FontColor = DefaultFontColor,
FontSize = 14,
Margin = "0 0.01 0 0.01",
},
PanelSettings = new Dictionary<string,object>
{
{ "ClockUpdateFrequency (seconds)" , ClockUpdateFrequency },
{ "TimeFormat", "HH:mm" }
}
}
},
{ "MessageBox", new PanelConfig
{
Available = true,
Dock = "TopRightDock",
Order = 7,
AnchorX = "Right",
AnchorY = "Bottom",
Margin = "0 0 0 0.005",
Width = 1f,
Height = 0.95f,
BackgroundColor = "0 0 0 0.4",
Text = new PanelTextConfig
{
Align = TextAnchor.MiddleCenter,
FontColor = DefaultFontColor,
FontSize = 14,
},
PanelSettings = new Dictionary<string,object>
{
{ "MessageUpdateFrequency (seconds)", MessageUpdateFrequency },
{ "MsgOrder","normal" }
}
}
},
{ "Balance", new PanelConfig
{
Available = true,
Dock = "BottomLeftDock",
Order = 7,
AnchorX = "Left",
AnchorY = "Bottom",
Margin = "0 0 0 0.01",
Width = 0.4f,
Height = 0.95f,
BackgroundColor = "0 0 0 0.4" ,
Image = new PanelImageConfig
{
Order = 1,
Width = 0.2f,
Height = 0.8f,
Margin = "0 0.01 0.1 0.01",
Url = "http://i.imgur.com/HhL5TvU.png",
},
Text = new PanelTextConfig
{
Order = 2,
Width = 0.848f,
Height = 1f,
Align = TextAnchor.MiddleCenter,
FontColor = DefaultFontColor,
FontSize = 12,
Margin = "0 0.02 0 0",
},
PanelSettings = new Dictionary<string,object>
{
{ "RefreshRate(s)", "5" },
}
}
},
{ "Points", new PanelConfig
{
Available = true,
Dock = "BottomLeftDock",
Order = 8,
AnchorX = "Left",
AnchorY = "Bottom",
Margin = "0 0 0 0.01",
Width = 0.4f,
Height = 0.95f,
BackgroundColor = "0 0 0 0.4" ,
Image = new PanelImageConfig
{
Order = 1,
Width = 0.2f,
Height = 0.8f,
Margin = "0 0.01 0.1 0.01",
Url = "http://i.imgur.com/dwzul4T.png",
},
Text = new PanelTextConfig
{
Order = 2,
Width = 0.848f,
Height = 1f,
Align = TextAnchor.MiddleCenter,
FontColor = DefaultFontColor,
FontSize = 12,
Margin = "0 0.02 0 0",
},
PanelSettings = new Dictionary<string,object>
{
{ "RefreshRate(s)", "5" },
}
}
},
{ "Coordinates", new PanelConfig
{
Available = true,
Dock = "TopLeftDock",
Order = 7,
AnchorX = "Left",
AnchorY = "Bottom",
Margin = "0 0 0 0.01",
Width = 0.5f,
Height = 0.95f,
BackgroundColor = "0 0 0 0.4" ,
Image = new PanelImageConfig
{
Order = 1,
Width = 0.13f,
Height = 0.8f,
Margin = "0 0.01 0.1 0.01",
Url = "http://i.imgur.com/Kr1pQ5b.png",
},
Text = new PanelTextConfig
{
Order = 2,
Width = 0.848f,
Height = 1f,
Align = TextAnchor.MiddleCenter,
FontColor = DefaultFontColor,
FontSize = 12,
Margin = "0 0.02 0 0",
},
PanelSettings = new Dictionary<string,object>
{
{ "RefreshRate(s)", "3" },
}
}
},
{ "Compass", new PanelConfig
{
Available = false,
Dock = "BottomRightDock",
Order = 8,
AnchorX = "Left",
AnchorY = "Bottom",
Margin = "0 0 0 0.01",
Width = 0.5f,
Height = 0.95f,
BackgroundColor = "0 0 0 0.4" ,
Image = new PanelImageConfig
{
Order = 1,
Width = 0.188f,
Height = 0.8f,
Margin = "0 0.01 0.1 0.03",
Url = "http://i.imgur.com/dG5nOOJ.png",
},
Text = new PanelTextConfig
{
Order = 2,
Width = 0.76f,
Height = 1f,
Align = TextAnchor.MiddleCenter,
FontColor = DefaultFontColor,
FontSize = 12,
Margin = "0 0.02 0 0",
},
PanelSettings = new Dictionary<string,object>
{
{ "RefreshRate(s)", "1" },
{ "TextOrAngle", "text" }
}
}
},
{ "OPlayers", new PanelConfig
{
Available = true,
Dock = "TopLeftDock",
Order = 2,
AnchorX = "Left",
AnchorY = "Bottom",
Margin = "0 0 0 0.01",
Width = 0.31f,
Height = 0.95f,
BackgroundColor = "0 0 0 0.4" ,
Image = new PanelImageConfig
{
Order = 1,
Width = 0.35f,
Height = 0.8f,
Margin = "0 0.05 0.1 0.05",
Url = "http://i.imgur.com/n9EYIWi.png",
},
Text = new PanelTextConfig
{
Order = 2,
Width = 0.68f,
Height = 1f,
Align = TextAnchor.MiddleCenter,
FontColor = DefaultFontColor,
FontSize = 14,
}
}
},
{ "Sleepers", new PanelConfig
{
Available = true,
Dock = "TopLeftDock",
Order = 3,
AnchorX = "Left",
AnchorY = "Bottom",
Margin = "0 0 0 0.01",
Width = 0.225f,
Height = 0.95f,
BackgroundColor = "0 0 0 0.4",
Image = new PanelImageConfig
{
Order = 1,
Width = 0.4f,
Height = 0.8f,
Margin = "0 0.05 0.1 0.05",
Url = "http://i.imgur.com/XIIZkqD.png",
},
Text = new PanelTextConfig
{
Order = 2,
Width = 0.63f,
Height = 1f,
Align = TextAnchor.MiddleCenter,
FontColor = DefaultFontColor,
FontSize = 14,
}
}
},
{ "AirdropEvent", new PanelConfig
{
Available = true,
Dock = "TopLeftDock",
Order = 4,
AnchorX = "Left",
AnchorY = "Bottom",
Margin = "0 0 0 0.01",
Width = 0.1f,
Height = 0.95f,
BackgroundColor = "0 0 0 0.4",
Image = new PanelImageConfig
{
Order = 1,
Width = 0.8f,
Height = 0.8f,
Margin = "0 0.1 0.1 0.1",
Url = "http://i.imgur.com/dble6vf.png",
},
PanelSettings = new Dictionary<string,object>
{
{ "InactiveColor", "1 1 1 0.1" },
{ "ActiveColor", "0 1 0 1" },
}
}
},
{ "HelicopterEvent", new PanelConfig
{
Available = true,
Dock = "TopLeftDock",
Order = 5,
AnchorX = "Left",
AnchorY = "Bottom",
Margin = "0 0 0 0.01",
Width = 0.1f,
Height = 0.95f,
BackgroundColor = "0 0 0 0.4",
Image = new PanelImageConfig
{
Order = 1,
Width = 0.75f,
Height = 0.8f,
Margin = "0 0.15 0.1 0.1",
Url = "http://i.imgur.com/hTTyTTx.png",
},
PanelSettings = new Dictionary<string,object>
{
{ "InactiveColor", "1 1 1 0.1" },
{ "ActiveColor", "0.7 0.2 0.2 1" },
}
}
},
{ "ChinookEvent", new PanelConfig
{
Available = true,
Dock = "TopLeftDock",
Order = 5,
AnchorX = "Left",
AnchorY = "Bottom",
Margin = "0 0 0 0.01",
Width = 0.1f,
Height = 0.95f,
BackgroundColor = "0 0 0 0.4",
Image = new PanelImageConfig
{
Order = 1,
Width = 0.75f,
Height = 0.8f,
Margin = "0 0.15 0.1 0.1",
Url = "https://i.imgur.com/49d8ZcK.png",
},
PanelSettings = new Dictionary<string,object>
{
{ "InactiveColor", "1 1 1 0.1" },
{ "ActiveColor", "0.7 0.2 0.2 1" },
}
}
},
{ "CargoShipEvent", new PanelConfig
{
Available = true,
Dock = "TopLeftDock",
Order = 5,
AnchorX = "Left",
AnchorY = "Bottom",
Margin = "0 0 0 0.01",
Width = 0.1f,
Height = 0.95f,
BackgroundColor = "0 0 0 0.4",
Image = new PanelImageConfig
{
Order = 1,
Width = 0.75f,
Height = 0.8f,
Margin = "0 0.15 0.1 0.1",
Url = "https://i.imgur.com/WQiNxyM.png",
},
PanelSettings = new Dictionary<string,object>
{
{ "InactiveColor", "1 1 1 0.1" },
{ "ActiveColor", "0 1 0 1" },
}
}
},
{ "Radiation", new PanelConfig
{
Available = false,
Dock = "TopLeftDock",
Order = 6,
AnchorX = "Left",
AnchorY = "Bottom",
Margin = "0 0 0 0.01",
Width = 0.1f,
Height = 0.95f,
BackgroundColor = "0 0 0 0.4",
Image = new PanelImageConfig
{
Order = 1,
Width = 0.75f,
Height = 0.8f,
Margin = "0 0.15 0.1 0.1",
Url = "http://i.imgur.com/owVdFsK.png",
},
PanelSettings = new Dictionary<string,object>
{
{ "InactiveColor", "1 1 1 0.1" },
{ "ActiveColor", "1 1 0 1" },
{ "RefreshRate(s)", "3"}
}
}
}
}
};
return DefaultConfig;
}
class PluginConfig
{
//public Dictionary<string, string> Settings { get; set; }
public Dictionary<string, DockConfig> Docks { get; set; }
public Dictionary<string, PanelConfig> Panels { get; set; }
public Dictionary<string, Dictionary<string, PanelConfig>> ThirdPartyPanels { get; set; }
public List<string> Messages { get; set; }
public List<string> TimeFormats { get; set; }
public Dictionary<string, string> CompassDirections { get; set; }
public T GetPanelSettingsValue<T>(string Panel, string Setting, T defaultValue)
{
PanelConfig panelConfig;
if (!Panels.TryGetValue(Panel, out panelConfig))
return defaultValue;
if (panelConfig.PanelSettings == null)
return defaultValue;
object value;
if (!panelConfig.PanelSettings.TryGetValue(Setting, out value))
return defaultValue;
return (T)Convert.ChangeType(value, typeof(T));
}
public bool CheckPanelAvailability(string Panel)
{
PanelConfig panelConfig;
if (!Panels.TryGetValue(Panel, out panelConfig))
return false;
if (!panelConfig.Available)
return false;
DockConfig dockConfig;
return Docks.TryGetValue(panelConfig.Dock, out dockConfig) && dockConfig.Available;
}
}
class DockConfig
{
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public bool Available { get; set; } = true;
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string AnchorX { get; set; } = "Left";
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string AnchorY { get; set; } = "Bottom";
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public float Width { get; set; } = 0.05f;
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public float Height { get; set; } = 0.95f;
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string BackgroundColor { get; set; } = "0 0 0 0.4";
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string Margin { get; set; } = "0 0 0 0.005";
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public PanelImageConfig Image { get; set; }
}
class BasePanelConfig
{
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public bool Available { get; set; } = true;
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string AnchorX { get; set; } = "Left";
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string AnchorY { get; set; } = "Bottom";
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public float Width { get; set; } = 0.05f;
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public float Height { get; set; } = 0.95f;
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public int Order { get; set; }
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string BackgroundColor { get; set; } = "0 0 0 0.4";
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string Margin { get; set; } = "0 0 0 0.005";
}
class PanelConfig : BasePanelConfig
{
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public bool Autoload { get; set; } = true;
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string Dock { get; set; } = "BottomLeftDock";
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public Dictionary<string, object> PanelSettings { get; set; }
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public PanelImageConfig Image { get; set; }
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public PanelTextConfig Text { get; set; }
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public float FadeOut { get; set; }
}
class PanelTextConfig : BasePanelConfig
{
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public new float Width { get; set; } = 1f;
[JsonConverter(typeof(StringEnumConverter))]
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public TextAnchor Align { get; set; } = TextAnchor.MiddleCenter;
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string FontColor { get; set; } = "1 1 1 1";
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public int FontSize { get; set; } = 14;
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string Content { get; set; } = "No Content";
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public float FadeIn { get; set; }
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public float FadeOut { get; set; }
}
class PanelImageConfig : BasePanelConfig
{
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public new float Width { get; set; } = 1f;
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string Url { get; set; }
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string Color { get; set; } = null;
}
protected void LoadConfigValues()
{
Settings = Config.ReadObject<PluginConfig>();
var UnOrderPanels = Settings.Panels.Where(p => p.Value.Order == 0).ToDictionary(s => s.Key, s => s.Value);
if (UnOrderPanels.Count == 0)
return;
PrintWarning("Reordering Panels.");
foreach (var PanelCfg in UnOrderPanels)
{
//int HighestSiblingOrder = Settings.Panels.Where(p => p.Value.Dock == Settings.Panels[PanelName].Dock && p.Value.AnchorX == Settings.Panels[PanelName].AnchorX).Max(m => m.Value.Order);
Settings.Panels[PanelCfg.Key].Order = PanelReOrder(PanelCfg.Value.Dock, PanelCfg.Value.AnchorX);
}
Config.WriteObject(Settings, true);
PrintWarning("Config Saved.");
}
int PanelReOrder(string DockName, string AnchorX)
{
var SiblingPanels = Settings.Panels.Where(p => p.Value.Dock == DockName && p.Value.AnchorX == AnchorX);
var Max = 0;
if (SiblingPanels.Any())
Max = SiblingPanels.Max(m => m.Value.Order);
foreach (var pPanelCfg in Settings.ThirdPartyPanels)
{
if (pPanelCfg.Value.Count == 0) { continue; }
var SiblingPluginPAnels = pPanelCfg.Value.Where(p => p.Value.Dock == DockName && p.Value.AnchorX == AnchorX);
if (SiblingPluginPAnels.Any())
{
var PluginMax = pPanelCfg.Value.Where(p => p.Value.Dock == DockName && p.Value.AnchorX == AnchorX).Max(m => m.Value.Order);
if (PluginMax > Max)
Max = PluginMax;
}
}
return Max + 1;
}
#endregion
#region Hooks
protected override void LoadDefaultConfig()
{
Config.Clear();
Config.WriteObject(DefaultConfig(), true);
PrintWarning("Default configuration file created.");
}
void Init()
{
LoadConfigValues();
LoadData();
}
void OnServerInitialized()
{
Clock = new Watch
(
Settings.GetPanelSettingsValue("Clock", "ClockUpdateFrequency (seconds)", ClockUpdateFrequency),
Settings.CheckPanelAvailability("Clock")
);
MessageBox = new Messenger
(
Settings.Messages,
Settings.GetPanelSettingsValue("MessageBox", "MessageUpdateFrequency (seconds)", MessageUpdateFrequency),
Settings.GetPanelSettingsValue("MessageBox", "MsgOrder", "normal")
);
Airplane = new AirplaneEvent();
Helicopter = new HelicopterEvent();
Cargoship = new CargoshipEvent();
Chinook = new ChinookEvent();
CompassObj = new Compass
(
Settings.GetPanelSettingsValue("Compass", "RefreshRate(s)", 1)
);
Rad = new Radiation
(
Settings.GetPanelSettingsValue("Radiation", "RefreshRate(s)", 3)
);
Poi = new Points
(
Settings.GetPanelSettingsValue("Points", "RefreshRate(s)", 3)
);
Bala = new Balance
(
Settings.GetPanelSettingsValue("Balance", "RefreshRate(s)", 3)
);
Coord = new Coordinates
(
Settings.GetPanelSettingsValue("Coordinates", "RefreshRate(s)", 3)
);
foreach (var player in BasePlayer.activePlayerList)
{
LoadPanels(player);
InitializeGUI(player);
}
if (Settings.CheckPanelAvailability("Radiation"))
{
RadiationUpdater = timer.Repeat(Rad.RefreshRate, 0, () => Rad.Refresh(storedData, PlayerPanels));
}
if (Settings.CheckPanelAvailability("Points"))
{
PointsUpdater = timer.Repeat(Poi.RefreshRate, 0, () => Poi.Refresh(storedData, PlayerPanels));
}
if (Settings.CheckPanelAvailability("Balance"))
{
BalanceUpdater = timer.Repeat(Bala.RefreshRate, 0, () => Bala.Refresh(storedData, PlayerPanels));
}
if (Settings.CheckPanelAvailability("Coordinates"))
{
CoordUpdater = timer.Repeat(Coord.RefreshRate, 0, () => Coord.Refresh(storedData, PlayerPanels));
}
if (Settings.CheckPanelAvailability("MessageBox"))
{
MsgUpdater = timer.Repeat(MessageBox.RefreshRate, 0, () => MessageBox.Refresh(storedData, PlayerPanels));
}
if (Settings.CheckPanelAvailability("Clock"))
{
TimeUpdater = timer.Repeat(Clock.RefresRate, 0, () => Clock.Refresh(storedData, PlayerPanels));
}
if (Settings.CheckPanelAvailability("Compass"))
{
CompassUpdater = timer.Repeat(CompassObj.RefreshRate, 0, () => CompassObj.Refresh(storedData, PlayerPanels));
}
//TestTimer = timer.Repeat(5, 0, () => TestSH());
ActivePlanes = UnityEngine.Object.FindObjectsOfType<CargoPlane>().ToList();
if (ActivePlanes.Count > 0)
{
CheckAirplane();
}
else
{
Airplane.Refresh(storedData, PlayerPanels);
}
ActiveHelicopters = UnityEngine.Object.FindObjectsOfType<BaseHelicopter>().ToList();
if (ActiveHelicopters.Count > 0)
{
CheckHelicopter();
}
else
{
Helicopter.Refresh(storedData, PlayerPanels);
}
ActiveChinooks = UnityEngine.Object.FindObjectsOfType<CH47Helicopter>().ToList();
if (ActiveChinooks.Count > 0)
{
CheckChinook();
}
else
{
Chinook.Refresh(storedData, PlayerPanels);
}
ActiveCargoships = UnityEngine.Object.FindObjectsOfType<CargoShip>().ToList();
if (ActiveCargoships.Count > 0)
{
CheckCargoship();
}
else
{
Cargoship.Refresh(storedData, PlayerPanels);
}
IsReady = true;
}
void OnPlayerConnected(BasePlayer player)
{
if (player.HasPlayerFlag(BasePlayer.PlayerFlags.ReceivingSnapshot))
{
timer.Once(2, () => OnPlayerConnected(player));
return;
}
if (PlayerPanels.ContainsKey(player.UserIDString))
{
PlayerPanels.Remove(player.UserIDString);
}
if (PlayerDockPanels.ContainsKey(player.UserIDString))
{
PlayerDockPanels.Remove(player.UserIDString);
}
timer.In(1, () => GUITimerInit(player));
}
void OnPlayerDisconnected(BasePlayer player)
{
PlayerPanels.Remove(player.UserIDString);
PlayerDockPanels.Remove(player.UserIDString);
timer.Once(2, RefreshOnlinePlayers);
timer.Once(2, RefreshSleepers);
}
void OnPlayerSleepEnded(BasePlayer player)
{
timer.Once(2, RefreshSleepers);
}
private void OnEntitySpawned(BaseEntity Entity)
{
if (!IsReady)
{
timer.In(10, () => OnEntitySpawned(Entity));
return;
}
if (Entity == null) return;
if (Entity is BaseHelicopter && Settings.Panels["HelicopterEvent"].Available)
{
ActiveHelicopters.Add((BaseHelicopter) Entity);
if (HelicopterTimer == false)
{
CheckHelicopter();
}
}
if (Entity is CargoPlane && Settings.Panels["AirdropEvent"].Available)
{
ActivePlanes.Add((CargoPlane) Entity);
if (AirplaneTimer == false)
{
CheckAirplane();
}
}
if (Entity is CargoShip && Settings.Panels["CargoShipEvent"].Available)
{
ActiveCargoships.Add((CargoShip)Entity);
if (CargoshipTimer == false)
{
CheckCargoship();
}
}
if (Entity is CH47Helicopter && Settings.Panels["ChinookEvent"].Available)
{
ActiveChinooks.Add((CH47Helicopter)Entity);
if (ChinookTimer == false)
{
CheckChinook();
}
}
}
private void Unload()
{
foreach (var player in BasePlayer.activePlayerList)
DestroyGUI(player);
SaveData();
PlayerPanels.Clear();
PlayerDockPanels.Clear();
Err.Clear();
ErrD.Clear();
ErrB.Clear();
ErrA.Clear();
storedData = null;
Settings = null;
}
void OnPluginUnloaded(Plugin plugin)
{
if (!Settings.ThirdPartyPanels.ContainsKey(plugin.Title)) return;
var PluginPanels = LoadedPluginPanels[plugin.Title];
foreach(var PanelName in PluginPanels)
{
foreach (var pair in PlayerPanels)
{
pair.Value[PanelName].DestroyPanel();
pair.Value[PanelName].Remover();
}
}
LoadedPluginPanels.Remove(plugin.Title);
}
void OnServerSave()
{
SaveData();
}
void OnServerShutdown()
{
SaveData();
}
#endregion
#region PanelLoad
/// <summary>
/// </summary>
/// <param name="Player"></param>
private void LoadPanels(BasePlayer Player)
{
foreach(var Docks in Settings.Docks)
{
if (!Settings.Docks[Docks.Key].Available)
continue;
LoadDockPanel(Docks.Key, Player);
}
var playerDockPanel = PlayerDockPanels[Player.UserIDString];
foreach (var grouppedByDock in Settings.Panels.GroupBy(g => g.Value.Dock).ToDictionary(gd => gd.Key, gd => gd.Select(p => p).ToDictionary(gk => gk.Key, gk => gk.Value)))
{
if (!Settings.Docks[grouppedByDock.Key].Available)
continue;
foreach (var panelCfg in grouppedByDock.Value)
{
if (!Settings.CheckPanelAvailability(panelCfg.Key))
continue;
LoadPanel(playerDockPanel[grouppedByDock.Key], panelCfg.Key, panelCfg.Value);
}
}
foreach(var loadedPluginPanel in LoadedPluginPanels)
{
foreach(var panelName in loadedPluginPanel.Value)
{
Dictionary<string, PanelConfig> panelConfigs;
PanelConfig panelConfig;
if (!Settings.ThirdPartyPanels.TryGetValue(loadedPluginPanel.Key, out panelConfigs)
|| !panelConfigs.TryGetValue(panelName, out panelConfig)
|| !panelConfig.Available)
continue;
LoadPanel(playerDockPanel[panelConfig.Dock], panelName, panelConfig);
}
}
}
private IPanel LoadDockPanel(string DockName, BasePlayer Player)
{
var dockConfig = Settings.Docks[DockName];
var DockPanel = new IPanel(DockName, Player, PlayerPanels, PlayerDockPanels)
{
Width = dockConfig.Width,
Height = dockConfig.Height,
AnchorX = dockConfig.AnchorX,
AnchorY = dockConfig.AnchorY,
Margin = Vector4Parser(dockConfig.Margin),
BackgroundColor = ColorEx.Parse(dockConfig.BackgroundColor),
IsDock = true
};
//LoadedDocks.Add(DockName, DockPanel);
Dictionary<string, IPanel> panels;
if(!PlayerDockPanels.TryGetValue(Player.UserIDString, out panels))
PlayerDockPanels.Add(Player.UserIDString, panels = new Dictionary<string, IPanel>());
panels.Add(DockName, DockPanel);
return DockPanel;
}
private void LoadPanel(IPanel Dock, string PanelName, PanelConfig PCfg)
{
var Panel = Dock.AddPanel(PanelName);
Panel.Width = PCfg.Width;
Panel.Height = PCfg.Height;
Panel.AnchorX = PCfg.AnchorX;
Panel.AnchorY = PCfg.AnchorY;
Panel.Margin = Vector4Parser(PCfg.Margin);
Panel.BackgroundColor = ColorEx.Parse(PCfg.BackgroundColor);
Panel.Order = PCfg.Order;
Panel.Autoload = PCfg.Autoload;
Panel.IsPanel = true;
Panel.DockName = Dock.Name;
Panel.FadeOut = Dock.FadeOut;
if (PCfg.Text != null)
{
var Text = Panel.AddText(PanelName + "Text");
Text.Width = PCfg.Text.Width;
Text.Height = PCfg.Text.Height;
Text.Margin = Vector4Parser(PCfg.Text.Margin);
Text.Content = PCfg.Text.Content;
Text.FontColor = ColorEx.Parse(PCfg.Text.FontColor);
Text.FontSize = PCfg.Text.FontSize;
Text.Font = "robotocondensed-regular.ttf";
Text.Align = PCfg.Text.Align;
Text.Order = PCfg.Text.Order;
Text.FadeOut = PCfg.Text.FadeOut;
Text.TextComponent.FadeIn = PCfg.Text.FadeIn;
}
if (PCfg.Image != null)
{
var Image = Panel.AddImage(PanelName + "Image");
Image.Width = PCfg.Image.Width;
Image.Height = PCfg.Image.Height;
Image.Margin = Vector4Parser(PCfg.Image.Margin);
Image.Url = PCfg.Image.Url;
Image.Order = PCfg.Image.Order;
if (PCfg.Image.Color != null)
Image.Color = ColorEx.Parse(PCfg.Image.Color);
}
}
#endregion
#region Clock
private Watch Clock;
private int ClockUpdateFrequency = 4;
private Timer TimeUpdater;
public class Watch
{
string ClockFormat = "HH:mm";
public int RefresRate = 4;
public bool Available = true;
TOD_Sky Sky = TOD_Sky.Instance;
public Watch(int RefreshRate, bool Available)
{
RefresRate = RefreshRate;
this.Available = Available;
}
public string GetServerTime(string PlayerID, StoredData storedData)
{
return DateTime.Now.AddHours(storedData.GetPlayerPanelSettings(PlayerID, "Clock", "Offset", 0)).ToString(storedData.GetPlayerPanelSettings(PlayerID, "Clock", "TimeFormat", ClockFormat), CultureInfo.InvariantCulture);
}
public string GetSkyTime(string PlayerID, StoredData storedData)
{
return Sky.Cycle.DateTime.ToString(storedData.GetPlayerPanelSettings(PlayerID, "Clock", "TimeFormat", ClockFormat), CultureInfo.InvariantCulture);
}
public string ShowTime(string PlayerID, StoredData storedData)
{
if (storedData.GetPlayerPanelSettings(PlayerID, "Clock", "Type", "Game") == "Server")
return GetServerTime(PlayerID, storedData);
return GetSkyTime(PlayerID, storedData);
}
public void Refresh(StoredData storedData, Dictionary<string, Dictionary<string, IPanel>> panels)
{
if (!Settings.CheckPanelAvailability("Clock"))
return;
foreach (var panel in panels)
{
IPanel iPanel;
if (!panel.Value.TryGetValue("ClockText", out iPanel)) continue;
var showTime = ShowTime(panel.Key, storedData);
var panelText = (IPanelText)iPanel;
if (!showTime.Equals(panelText.Content))
{
panelText.Content = showTime;
panelText.Refresh();
}
}
}
}
#endregion
#region MessageBox
private Messenger MessageBox;
private Timer MsgUpdater;
private int MessageUpdateFrequency = 20;
private List<string> Messages = new List<string> { "Welcome!", "Beware! You Are Not Alone!", "Leeeeeeeeeeeroy Jenkins" };
private bool MessageBoxAvailable = true;
public class Messenger
{
List<string> Messages;
public int RefreshRate = 20;
private int Counter = 0;
private string MsgOrder = "normal";
public Messenger(List<string> msgs, int RefreshRate,string MsgOrder)
{
Messages = msgs;
this.RefreshRate = RefreshRate;
this.MsgOrder = MsgOrder;
if (MsgOrder == "random")
{
Counter = Core.Random.Range(0, Messages.Count - 1);
}
}
public string GetMessage()
{
return Messages[Counter];
}
private void RefreshCounter()
{
if (MsgOrder == "random")
{
var OldCounter = Counter;
var NewCounter = Core.Random.Range(0, Messages.Count - 1);
if(OldCounter == NewCounter)
{
if(NewCounter+1 <= Messages.Count-1)
{
Counter = NewCounter + 1;
return;
}
else if(NewCounter - 1 >= 0)
{
Counter = NewCounter - 1;
return;
}
}
Counter = NewCounter;
return;
}
Counter++;
// ... [Code preview truncated due to length. Full source in attached file] ...