using Rust; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Oxide.Core; using Oxide.Core.Configuration; using Oxide.Core.Libraries.Covalence; using Oxide.Core.Plugins; using Oxide.Game.Rust.Cui; using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; using UnityEngine; using Facepunch; namespace Oxide.Plugins { [Info("Purge Info", "Krungh Crow", "1.0.3")] [Description("Info panel GUI on command with purge and wipe info")] #region Changelogs and ToDo /******************************************************************************* * * 1.0.1 : Repositioned the wipe, purge ,info text blocks * 1.0.2 : Added GUIannouncements section * 1.0.3 : Some code optimisations * : Added missing Prefix * * Todo * * + Add a icon when purge is active (incl config settings) * + Add a purge is active text ui (incl cfg settings) * ********************************************************************************/ #endregion class PurgeInfo : CovalencePlugin { [PluginReference] Plugin GUIAnnouncements; #region Variables const string Info_Perm = "purgeinfo.info"; #endregion #region Configuration void OnServerInitialized() { if (GUIAnnouncements != null) Puts("GUIAnnouncements found."); if (configData.PUIA.PUIAUse == true) { timer.Repeat((configData.PUIA.PUIATimer * 60), 0, () => { GUIAnnouncements?.Call("CreateAnnouncement", configData.PUIAM.PUIGAM[new System.Random().Next(configData.PUIAM.PUIGAM.Count())], "blue", "yellow"); //Puts($"test trigger for annoucement pre purge"); }); } else if (configData.PUIA.PUIAUPUse == true) { timer.Repeat((configData.PUIA.PUIAPTimer * 60), 0, () => { GUIAnnouncements?.Call("CreateAnnouncement", configData.PUIAM.PUIGAPM[new System.Random().Next(configData.PUIAM.PUIGAPM.Count())], "blue", "yellow"); //Puts($"test trigger for annoucement during purge"); }); } } void Init() { if (!LoadConfigVariables()) { Puts("Config file issue detected. Please delete file, or check syntax and fix."); return; } //permission.RegisterPermission(Admin_Perm, this); permission.RegisterPermission(Info_Perm, this); } private ConfigData configData; class ConfigData { [JsonProperty(PropertyName = "GUI Info Settings")] public UISettings PUI = new UISettings(); [JsonProperty(PropertyName = "Icon Settings")] public IconSettings PUIcon = new IconSettings(); [JsonProperty(PropertyName = "Wipe Info Settings")] public WipeSettings PUIW = new WipeSettings(); [JsonProperty(PropertyName = "Purge Info Settings")] public PurgeSettings PUIP = new PurgeSettings(); [JsonProperty(PropertyName = "Info Block")] public InfoSettings PUIT = new InfoSettings(); [JsonProperty(PropertyName = "Announcements")] public AnnounceSettings PUIA = new AnnounceSettings(); [JsonProperty(PropertyName = "GUIAnnouncements messages")] public AnnounceMessages PUIAM = new AnnounceMessages(); } class UISettings { [JsonProperty(PropertyName = "Banner Image")] public bool PUIBGImageUse = true; [JsonProperty(PropertyName = "Banner Image Url")] public string PUIBGImage = "https://i.ibb.co/6YbWnxW/purge-info.png"; [JsonProperty(PropertyName = "Banner Image Transparrency (0-1)")] public double BGAlpha = 0.9; [JsonProperty(PropertyName = "Welcome text color (RGBA)")] public string WelcomTextClr { get; set; } = "1 1 1 1"; [JsonProperty(PropertyName = "Version text color (RGBA)")] public string VTextClr { get; set; } = "1 1 1 1"; [JsonProperty(PropertyName = "Wipe text color (RGBA)")] public string WipeTextClr { get; set; } = "1 1 1 1"; [JsonProperty(PropertyName = "Purge text color (RGBA)")] public string PurgeTextClr { get; set; } = "1 1 1 1"; [JsonProperty(PropertyName = "Info Text color (RGBA)")] public string InfoTextClr { get; set; } = "1 1 1 1"; [JsonProperty(PropertyName = "Info Text size (Default = 18)")] public int InfoTextSize { get; set; } = 18; [JsonProperty(PropertyName = "Close Button Text")] public string BtnCloseText { get; set; } = "Close this window"; [JsonProperty(PropertyName = "Close Button color (RGBA)")] public string BtnCloseClr { get; set; } = "0 0 0 0.85"; [JsonProperty(PropertyName = "Close Button Text color (RGBA)")] public string BtnCloseTextClr { get; set; } = "1 1 1 1"; } class IconSettings { [JsonProperty(PropertyName = "Icon Image")] public bool PUIBGIconUse = true; [JsonProperty(PropertyName = "Icon Image Url")] public string PUIBGIcon = "https://i.ibb.co/6YbWnxW/purge-info.png"; [JsonProperty(PropertyName = "Icon Image Transparrency (0-1)")] public double BGAlpha = 0.9; } class WipeSettings { [JsonProperty(PropertyName = "Wipe cycle (weekly biweekly monthly")] public string PUIWipeCycle { get; set; } = "Biweekly"; [JsonProperty(PropertyName = "Wipe day (mon tue fri etc..")] public string PUIWipeDay { get; set; } = "Thursdays"; [JsonProperty(PropertyName = "Wipe time (example 19:00)")] public string PUIWipeTime { get; set; } = "19:00 UTC"; } class PurgeSettings { [JsonProperty(PropertyName = "Purge day (mon tue fri etc..")] public string PUIPurgeDay { get; set; } = "Wednesday"; [JsonProperty(PropertyName = "Purge start time (example 19:00)")] public string PUIPurgeSTime { get; set; } = "19:00 UTC"; [JsonProperty(PropertyName = "Purge end time (example 18:00)")] public string PUIPurgeETime { get; set; } = "18:00 UTC"; } class InfoSettings { [JsonProperty(PropertyName = "Info text")] public string PUIInfo { get; set; } = "Purge info By Krungh Crow"; } class AnnounceSettings { [JsonProperty(PropertyName = "Use Pre Purge GUIAnnouncements")] public bool PUIAUse { get; set; } = false; [JsonProperty(PropertyName = "Pre Purge GUIAnnouncements Cycle time (minutes)")] public float PUIATimer { get; set; } = 10f; [JsonProperty(PropertyName = "Use During Purge GUIAnnouncements")] public bool PUIAUPUse { get; set; } = false; [JsonProperty(PropertyName = "During Purge GUIAnnouncements Cycle time (minutes)")] public float PUIAPTimer { get; set; } = 10f; } class AnnounceMessages { [JsonProperty(PropertyName = "Pre Purge Announcement messages")] public List PUIGAM = new List(); [JsonProperty(PropertyName = "During Purge Announcement messages")] public List PUIGAPM = new List(); } private bool LoadConfigVariables() { try { configData = Config.ReadObject(); } catch { return false; } SaveConf(); return true; } protected override void LoadDefaultConfig() { Puts("Fresh install detected Creating a new config file."); configData = new ConfigData(); SaveConf(); } void SaveConf() => Config.WriteObject(configData, true); #endregion #region LanguageAPI protected override void LoadDefaultMessages() { lang.RegisterMessages(new Dictionary { ["InvalidInput"] = "Please enter a valid command!", ["Prefix"] = "[PurgeInfo] ", }, this); } #endregion #region Commands [Command("purge")] private void Purge(IPlayer player, string command, string[] args) { if (player.IsServer) { return; } string prefix = lang.GetMessage("Prefix", this, player.Id); if (args.Length < 1) { player.Reply(prefix + lang.GetMessage("InvalidInput", this, player.Id)); return; } var commandArg = (string)args[0]; if (string.IsNullOrEmpty(commandArg)) { return; } switch (args[0]) { case "info": { if (permission.UserHasPermission(player.Id, Info_Perm)) PurgeUI(player.Object as BasePlayer); PurgeIcon(player.Object as BasePlayer); break; } default: player.Reply(prefix + lang.GetMessage("InvalidInput", this, player.Id)); break; } } #endregion #region CUI void Unload() { foreach (BasePlayer player in BasePlayer.activePlayerList) DestroyMenu(player); } void OnPlayerDisconnected(BasePlayer player) { DestroyMenu(player); } void OnPlayerDeath(BasePlayer player, HitInfo info) { DestroyMenu(player); } void DestroyMenu(BasePlayer player) { CuiHelper.DestroyUi(player, "PurgeUI"); CuiHelper.DestroyUi(player, "PurgeIcon"); } [Command("PUIClose")] private void PUIClose(IPlayer player, string command, string[] args) { if (player == null) return; DestroyMenu(player.Object as BasePlayer); } void PurgeUI(BasePlayer player) { DestroyMenu(player); var elements = new CuiElementContainer(); var mainName = elements.Add(new CuiPanel { Image = { Color = $"0.1 0.1 0.1 0.2", Material = "assets/content/ui/uibackgroundblur.mat" }, RectTransform = { AnchorMin = "0.3 0.2", AnchorMax = "0.7 0.8" }, CursorEnabled = false, FadeOut = 0f }, "Overlay", "PurgeUI"); if (configData.PUI.PUIBGImageUse == true) { elements.Add(new CuiElement { Parent = "PurgeUI", Components = { new CuiRawImageComponent { Url = $"{configData.PUI.PUIBGImage}", Color = string.Format($"1 1 1 {configData.PUI.BGAlpha}"), FadeIn = 0f }, new CuiRectTransformComponent { AnchorMin = $"0 0.8", AnchorMax = $"1 1" } } }); } else if (configData.PUI.PUIBGImageUse == false) { elements.Add(new CuiLabel { Text = { Text = "Purge Info", Color = $"1 1 1 1", FontSize = 42, Align = TextAnchor.MiddleCenter }, RectTransform = { AnchorMin = $"0 0.8", AnchorMax = $"1 1" } }, mainName); } // welcome message elements.Add(new CuiLabel { Text = { Text = $"welcome {player.displayName}", Color = $"{configData.PUI.WelcomTextClr}", FontSize = 18, Align = TextAnchor.MiddleCenter }, RectTransform = { AnchorMin = "0.28 0.74", AnchorMax = "1 0.79" } }, mainName); // version number elements.Add(new CuiLabel { Text = { Text = $"Version : {this.Version.ToString()}", Color = $"{configData.PUI.VTextClr}", FontSize = 12, Align = TextAnchor.MiddleRight }, RectTransform = { AnchorMin = "0.80 0.79", AnchorMax = "0.99 0.84" } }, mainName); // Current time Block elements.Add(new CuiLabel { Text = { Text = $"Current Time : {DateTime.Now:h:mm:ss tt} ", Color = $"{configData.PUI.WipeTextClr}", FontSize = 13, Align = TextAnchor.MiddleLeft}, RectTransform = { AnchorMin = "0.05 0.65", AnchorMax = "0.25 0.70" } }, mainName); // Wipe Info Block elements.Add(new CuiLabel { Text = { Text = $"Wipe cycle : {configData.PUIW.PUIWipeCycle}", Color = $"{configData.PUI.WipeTextClr}", FontSize = 13, Align = TextAnchor.MiddleLeft }, RectTransform = { AnchorMin = "0.05 0.52", AnchorMax = "0.25 0.57" } }, mainName); elements.Add(new CuiLabel { Text = { Text = $"Wipe day : {configData.PUIW.PUIWipeDay}", Color = $"{configData.PUI.WipeTextClr}", FontSize = 13, Align = TextAnchor.MiddleLeft }, RectTransform = { AnchorMin = "0.05 0.46", AnchorMax = "0.25 0.51" } }, mainName); elements.Add(new CuiLabel { Text = { Text = $"Wipe time : {configData.PUIW.PUIWipeTime}", Color = $"{configData.PUI.WipeTextClr}", FontSize = 13, Align = TextAnchor.MiddleLeft }, RectTransform = { AnchorMin = "0.05 0.40", AnchorMax = "0.25 0.45" } }, mainName); // Purge info block elements.Add(new CuiLabel { Text = { Text = $"Purge day : {configData.PUIP.PUIPurgeDay}", Color = $"{configData.PUI.PurgeTextClr}", FontSize = 13, Align = TextAnchor.MiddleLeft }, RectTransform = { AnchorMin = "0.05 0.27", AnchorMax = "0.25 0.32" } }, mainName); elements.Add(new CuiLabel { Text = { Text = $"Purge start : {configData.PUIP.PUIPurgeSTime}", Color = $"{configData.PUI.PurgeTextClr}", FontSize = 13, Align = TextAnchor.MiddleLeft }, RectTransform = { AnchorMin = "0.05 0.21", AnchorMax = "0.25 0.26" } }, mainName); elements.Add(new CuiLabel { Text = { Text = $"Purge end : {configData.PUIP.PUIPurgeETime}", Color = $"{configData.PUI.PurgeTextClr}", FontSize = 13, Align = TextAnchor.MiddleLeft }, RectTransform = { AnchorMin = "0.05 0.15", AnchorMax = "0.25 0.20" } }, mainName); // Info Text elements.Add(new CuiLabel { Text = { Text = $"{configData.PUIT.PUIInfo}", Color = $"{configData.PUI.InfoTextClr}", FontSize = configData.PUI.InfoTextSize, Align = TextAnchor.MiddleCenter/*UpperLeft*/}, RectTransform = { AnchorMin = "0.28 0.06", AnchorMax = "1 0.70" } }, mainName); // Close button elements.Add(new CuiButton { Button = { Command = "PUIClose", Color = $"{configData.PUI.BtnCloseClr}" }, RectTransform = { AnchorMin = "0 0", AnchorMax = "1 0.05" }, Text = { Text = $"{configData.PUI.BtnCloseText}", Color = $"{configData.PUI.BtnCloseTextClr}", FontSize = 14, Align = TextAnchor.MiddleCenter } }, mainName); CuiHelper.AddUi(player, elements); } void PurgeIcon(BasePlayer player) { //DestroyMenu(player); var elementsIcon = new CuiElementContainer(); var mainNameIcon = elementsIcon.Add(new CuiPanel { Image = { Color = $"0.1 0.1 0.1 0.2", Material = "assets/content/ui/uibackgroundblur.mat" }, RectTransform = { AnchorMin = "0.45 0.1", AnchorMax = "0.55 0.15" }, CursorEnabled = true, FadeOut = 0f }, "Overlay", "PurgeIcon"); if (configData.PUIcon.PUIBGIconUse == true) { elementsIcon.Add(new CuiElement { Parent = "PurgeIcon", Components = { new CuiRawImageComponent { Url = $"{configData.PUIcon.PUIBGIcon}", Color = string.Format($"1 1 1 {configData.PUIcon.BGAlpha}"), FadeIn = 0f }, new CuiRectTransformComponent { AnchorMin = $"0 0", AnchorMax = $"1 1" } } }); } else if (configData.PUIcon.PUIBGIconUse == false) { elementsIcon.Add(new CuiLabel { Text = { Text = "Purge Info", Color = $"1 1 1 1", FontSize = 42, Align = TextAnchor.MiddleCenter }, RectTransform = { AnchorMin = $"0 0.8", AnchorMax = $"1 1" } }, mainNameIcon); } CuiHelper.AddUi(player, elementsIcon); } #endregion } }