diff --git a/Config.cs b/Config/GeneralConfig.cs similarity index 70% rename from Config.cs rename to Config/GeneralConfig.cs index 5817a4e..73d8af6 100644 --- a/Config.cs +++ b/Config/GeneralConfig.cs @@ -1,41 +1,17 @@ using Exiled.API.Enums; -using Exiled.API.Interfaces; -using HintServiceMeow.UITemplates; using PlayerRoles; using Respawning; - using System; using System.Collections.Generic; using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; -namespace HintServiceMeow +namespace HintServiceMeow.Config { - public class Config:IConfig + public class GeneralConfig { - public static Config instance; - - public bool IsEnabled { get; set; } = true; - public bool Debug { get; set; } = false; - - [Description("All of the following configs are used for PlayerUI")] - public bool EnablePlayerUI { get; set; } = true; - - [Description("The text displayed for different ammo/armor status")] - public string NoArmor { get; set; } = "没有装甲"; - public string NoAmmo { get; set; } = "没有备弹"; - public string AmmoHint { get; set; } = "{Ammo}共{NumOfAmmo}发"; - public string AmmoHint2 { get; set; } = "各种备弹共{NumOfAmmo}发"; - - [Description("The config for different templates")] - - public GeneralHumanTemplateConfig generalHumanTemplateConfig { get; private set; } = new GeneralHumanTemplateConfig(); - - public SCPTemplateConfig scpTemplateConfig { get; private set; } = new SCPTemplateConfig(); - - public CustomHumanTemplateConfig customHumanTemplate { get; private set; } = new CustomHumanTemplateConfig(); - - public CustomSCPTemplateConfig customSCPTemplate { get; private set; } = new CustomSCPTemplateConfig(); - [Description("Translation of different role types")] public Dictionary RoleName { get; private set; } = new Dictionary() { @@ -165,35 +141,5 @@ public class Config:IConfig {WarheadStatus.Detonated, "已被引爆" }, {WarheadStatus.InProgress, "正在倒计时" }, }; - - [Description("RespawnTimer: Time interval between each hint")] - public int HintDisplayInterval { get; set; } = 10; - - [Description("RespawnTimer: A list of hints you want to display")] - public List Hints { get; private set; } = new List() { "Some hints", "Some other hints" }; - } - - public class GeneralHumanTemplateConfig - { - public string TopBar { get; set; } = "TPS:{TPS} | {PlayerName}"; - public string BottomBar { get; set; } = "{PlayerNickname}|{Role}|{AmmoInfo}|{ArmorInfo}|Meow"; - } - - public class SCPTemplateConfig - { - public string TopBar { get; set; } = "TPS:{TPS} | {PlayerName}"; - public string BottomBar { get; set; } = "{PlayerNickname}|{Role}|剩余{TeammateCount}队友|Meow"; - } - - public class CustomHumanTemplateConfig - { - public string TopBar { get; set; } = "TPS:{TPS} | {PlayerName}"; - public string BottomBar { get; set; } = "{PlayerNickname}|{Role}|{AmmoInfo}|{ArmorInfo}|Meow"; - } - - public class CustomSCPTemplateConfig - { - public string TopBar { get; set; } = "TPS:{TPS} | {PlayerName}"; - public string BottomBar { get; set; } = "{PlayerNickname}|{Role}|剩余{TeammateCount}队友|{AmmoInfo}|{ArmorInfo}|Meow"; } } diff --git a/Config/PlayerDisplayConfig.cs b/Config/PlayerDisplayConfig.cs new file mode 100644 index 0000000..bfc451b --- /dev/null +++ b/Config/PlayerDisplayConfig.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HintServiceMeow.Config +{ + public class PlayerDisplayConfig + { + [Description("The minimum time between each updates for player displays. 0.5 is experimental value.")] + public TimeSpan MinUpdateInterval = TimeSpan.FromMilliseconds(500); + + [Description("The minimum time wait before each update, you can shorten it if you're confident with your server's performance, count in miliseconds")] + public float MinTimeDelayBeforeUpdate = 50f; + } +} diff --git a/Config/PlayerUIConfig.cs b/Config/PlayerUIConfig.cs new file mode 100644 index 0000000..1cd6c92 --- /dev/null +++ b/Config/PlayerUIConfig.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HintServiceMeow.Config +{ + public class PlayerUIConfig + { + [Description("Enable or disable common hints. Changing this option might cause error if other plugins are using CommonHints")] + public bool EnableCommonHints { get; set; } = true; + + [Description("Enable or disable player effects. Changing this option might cause error if other plugins are using Effects")] + public bool EnableEffects { get; set; } = true; + + [Description("Enable or disable playerUITemplate")] + public bool EnableUITemplates { get; set; } = true; + } +} diff --git a/Config/PlayerUITemplateConfigs.cs b/Config/PlayerUITemplateConfigs.cs new file mode 100644 index 0000000..6743a80 --- /dev/null +++ b/Config/PlayerUITemplateConfigs.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HintServiceMeow.Config +{ + public class GeneralHumanTemplateConfig + { + public string TopBar { get; set; } = "TPS:{TPS} | {PlayerName}"; + public string BottomBar { get; set; } = "{PlayerNickname}|{Role}|{AmmoInfo}|{ArmorInfo}|Meow"; + } + + public class SCPTemplateConfig + { + public string TopBar { get; set; } = "TPS:{TPS} | {PlayerName}"; + public string BottomBar { get; set; } = "{PlayerNickname}|{Role}|剩余{TeammateCount}队友|Meow"; + } + + public class CustomHumanTemplateConfig + { + public string TopBar { get; set; } = "TPS:{TPS} | {PlayerName}"; + public string BottomBar { get; set; } = "{PlayerNickname}|{Role}|{AmmoInfo}|{ArmorInfo}|Meow"; + } + + public class CustomSCPTemplateConfig + { + public string TopBar { get; set; } = "TPS:{TPS} | {PlayerName}"; + public string BottomBar { get; set; } = "{PlayerNickname}|{Role}|剩余{TeammateCount}队友|{AmmoInfo}|{ArmorInfo}|Meow"; + } + + public class SpectatorTemplateConfig + { + [Description("RespawnTimer: Time interval between each hint")] + public int HintDisplayInterval { get; set; } = 10; + + [Description("RespawnTimer: A list of hints you want to display")] + public List Hints { get; private set; } = new List() { "Some hints", "Some other hints" }; + } +} diff --git a/Config/PlayerUIToolConfig.cs b/Config/PlayerUIToolConfig.cs new file mode 100644 index 0000000..323ac95 --- /dev/null +++ b/Config/PlayerUIToolConfig.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HintServiceMeow.Config +{ + + public class PlayerUIToolsConfig + { + [Description("Message template when the player has no armor")] + public string NoArmor { get; set; } = "没有装甲"; + + [Description("Message template when the player has no ammo")] + public string NoAmmo { get; set; } = "没有备弹"; + + [Description("Message template when the player has 1 type of ammo")] + public string AmmoHint1 { get; set; } = "{Ammo}共{NumOfAmmo}发"; + + [Description("Message template when the player has multiple types of ammo")] + public string AmmoHint2 { get; set; } = "各种备弹共{NumOfAmmo}发"; + } +} diff --git a/Config/PluginConfig.cs b/Config/PluginConfig.cs new file mode 100644 index 0000000..de79b71 --- /dev/null +++ b/Config/PluginConfig.cs @@ -0,0 +1,51 @@ +using Exiled.API.Enums; +using Exiled.API.Interfaces; +using HintServiceMeow.UITemplates; +using PlayerRoles; +using Respawning; + +using System; +using System.Collections.Generic; +using System.ComponentModel; + +namespace HintServiceMeow.Config +{ + public class PluginConfig:IConfig + { + public static PluginConfig instance; + + public bool IsEnabled { get; set; } = true; + public bool Debug { get; set; } = false; + + [Description("Configs for PlayerDisplay. Changing these configs might leads to errors")] + public PlayerDisplayConfig PlayerDisplayConfig { get; set; } = new PlayerDisplayConfig(); + + + [Description("The config for general names")] + public GeneralConfig GeneralConfig { get; set; } = new GeneralConfig(); + + [Description("All of the following configs are used for PlayerUI")] + public bool EnablePlayerUI { get; set; } = true; + + [Description("The config for PlayerUI")] + public PlayerUIConfig PlayerUIConfig { get; set; } = new PlayerUIConfig(); + + [Description("The config for PlayerUITools, will affect multiple templates")] + public PlayerUIToolsConfig PlayerUIToolsConfig { get; private set; } = new PlayerUIToolsConfig(); + + [Description("The config for general human tempalte")] + public GeneralHumanTemplateConfig GeneralHumanTemplateConfig { get; private set; } = new GeneralHumanTemplateConfig(); + + [Description("The config for scp tempalte")] + public SCPTemplateConfig ScpTemplateConfig { get; private set; } = new SCPTemplateConfig(); + + [Description("The config for custom human tempalte")] + public CustomHumanTemplateConfig CustomHumanTemplate { get; private set; } = new CustomHumanTemplateConfig(); + + [Description("The config for custom scp tempalte")] + public CustomSCPTemplateConfig CustomSCPTemplate { get; private set; } = new CustomSCPTemplateConfig(); + + [Description("The config for spectator tempalte")] + public SpectatorTemplateConfig SpectatorTemplateConfig { get; private set; } = new SpectatorTemplateConfig(); + } +} diff --git a/PlayerDisplay/HintClass.cs b/PlayerDisplay/Hints/HintClass.cs similarity index 100% rename from PlayerDisplay/HintClass.cs rename to PlayerDisplay/Hints/HintClass.cs diff --git a/PlayerDisplay/HintParameters .cs b/PlayerDisplay/Hints/HintParameters .cs similarity index 100% rename from PlayerDisplay/HintParameters .cs rename to PlayerDisplay/Hints/HintParameters .cs diff --git a/PlayerDisplay/PlayerDisplay.cs b/PlayerDisplay/PlayerDisplay.cs index a8dfedc..82034e7 100644 --- a/PlayerDisplay/PlayerDisplay.cs +++ b/PlayerDisplay/PlayerDisplay.cs @@ -65,7 +65,7 @@ internal bool UpdatedRecently() } //Update Rate Management stuff - private TimeSpan UpdateInterval { get; } = TimeSpan.FromMilliseconds(500); //By experiment, the fastest update rate is 2 times per second. + private TimeSpan UpdateInterval { get; } = Config.PluginConfig.instance.PlayerDisplayConfig.MinUpdateInterval; //By experiment, the fastest update rate is 2 times per second. internal DateTime lastTimeUpdate { get; set; } = DateTime.MinValue; private bool plannedUpdate { get; set; } = false; // Tells whether a update had been planned @@ -78,7 +78,8 @@ internal void UpdateWhenReady() plannedUpdate = true; var TimeToWait = (float)((lastTimeUpdate + UpdateInterval) - DateTime.Now).TotalMilliseconds; - TimeToWait = TimeToWait < 50f ? 50f : TimeToWait; //0.05f to make sure that all of the changes are updated beofre the next update + var MinDelay = Config.PluginConfig.instance.PlayerDisplayConfig.MinTimeDelayBeforeUpdate; + TimeToWait = TimeToWait < MinDelay ? MinDelay : TimeToWait; //Having a min delay to make sure that all of the changes are updated beofre the next update Timing.CallDelayed(TimeToWait/1000, () => { diff --git a/PlayerUI/Effects.cs b/PlayerUI/Effects/Effects.cs similarity index 95% rename from PlayerUI/Effects.cs rename to PlayerUI/Effects/Effects.cs index 7ac10bd..279546d 100644 --- a/PlayerUI/Effects.cs +++ b/PlayerUI/Effects/Effects.cs @@ -5,9 +5,9 @@ using System.Text; using System.Threading.Tasks; -namespace HintServiceMeow +namespace HintServiceMeow.Effect { - //Not implemented + //Not implemented yet public abstract class UIEffectBase { Player player; diff --git a/PlayerUI/PlayerUI.cs b/PlayerUI/PlayerUI.cs index e32ffb3..7f6212d 100644 --- a/PlayerUI/PlayerUI.cs +++ b/PlayerUI/PlayerUI.cs @@ -1,11 +1,14 @@ using Exiled.API.Features; -using HintServiceMeow.UITemplates; using MEC; using PlayerRoles; +using HintServiceMeow.Effect; +using HintServiceMeow.UITemplates; + using System; using System.Collections.Generic; using System.Linq; +using HintServiceMeow.Config; namespace HintServiceMeow { @@ -202,6 +205,39 @@ private void DestructCommonHints() playerDisplay.RemoveHints(otherHints); } + //Static common hints methods + public static void BroadcastOtherHint(string hint) + { + foreach(PlayerUI ui in playerUIs) + { + ui.ShowOtherHint(hint); + } + } + + public static void BroadcastOtherHint(string[] hints) + { + foreach (PlayerUI ui in playerUIs) + { + ui.ShowOtherHint(hints); + } + } + + public static void BroadcastOtherHints(string hint, int time) + { + foreach (PlayerUI ui in playerUIs) + { + ui.ShowOtherHint(hint, time); + } + } + + public static void BroadcastOtherHints(string[] hints, int time) + { + foreach (PlayerUI ui in playerUIs) + { + ui.ShowOtherHint(hints, time); + } + } + //Public Common Item Hints Methods public void ShowItemHint(string itemName) { @@ -288,6 +324,11 @@ public void ShowRoleHint(string roleName, string[] description, int time) roleHints[0].message = roleName; roleHints[0].hide = false; + if(description.Count() >= roleHints.Length) + { + Log.Warn($"There's more than 3 descriptions passed into ShowRoleHint for: {roleName}, ShowRoleHint can handle at most 3 lines of description"); + } + for(int i = 0; i < description.Length; i++) { if(i >= roleHints.Length - 1) @@ -306,10 +347,12 @@ public void ShowOtherHint(string hint) public void ShowOtherHint(string hint, int time) { - ShowOtherHint(new string[] - { - hint, - }, time); + ShowOtherHint( + new string[] + { + hint + } + ,time); } public void ShowOtherHint(string[] hints) @@ -321,7 +364,12 @@ public void ShowOtherHint(string[] hints, int time) { otherHintTimeToRemove = Round.ElapsedTime + TimeSpan.FromSeconds(time); - for(int i = 0; i < otherHints.Length; i++) + if (hints.Count() >= otherHints.Length) + { + Log.Warn($"There's more than 4 hints passed into ShowOtherHints. ShowOtherHints can handle at most 4 lines of hints"); + } + + for (int i = 0; i < otherHints.Length; i++) { otherHints[i].message = hints.Length > i ? hints[i] : string.Empty; otherHints[i].hide = otherHints[i].message == string.Empty; @@ -335,9 +383,9 @@ private void SetTemplate() template?.DestructTemplate(); - if(UICommonTools.IsCustomRole(player)) + if(PlayerUICommonTools.IsCustomRole(player)) { - if(UICommonTools.IsSCP(player)) + if(PlayerUICommonTools.IsSCP(player)) { template = new CustomSCPTemplate(player); } @@ -366,16 +414,23 @@ private void SetTemplate() } } + template?.SetUpTemplate(); StartTemplateCoroutine(); } + private void DestructTemplate() + { + StopTemplateCoroutine(); + template?.DestructTemplate(); + } + private bool CheckTemplate() { bool isCorrectType; - if (UICommonTools.IsCustomRole(player)) + if (PlayerUICommonTools.IsCustomRole(player)) { - if (UICommonTools.IsSCP(player)) + if (PlayerUICommonTools.IsSCP(player)) { isCorrectType = template?.type == PlayerUITemplateBase.PlayerUITemplateType.CustomSCP; } @@ -436,15 +491,19 @@ private IEnumerator TemplateUpdateCoroutineMethod() private void StartTemplateCoroutine() { + if (templateUpdateCoroutine.IsRunning) + Timing.KillCoroutines(templateUpdateCoroutine); + templateUpdateCoroutine = Timing.RunCoroutine(TemplateUpdateCoroutineMethod()); } private void StopTemplateCoroutine() { - Timing.KillCoroutines(templateUpdateCoroutine); + if(templateUpdateCoroutine.IsRunning) + Timing.KillCoroutines(templateUpdateCoroutine); } - //Private PlayerUI methods + //internal PlayerUI methods internal PlayerUI(Player player) { if(playerUIs.Any(x => x.player == player)) @@ -455,22 +514,22 @@ internal PlayerUI(Player player) this.player = player; this.playerDisplay = PlayerDisplay.Get(player); + //effect - SetUpEffect(); + if(PluginConfig.instance.PlayerUIConfig.EnableEffects) + SetUpEffect(); + //common hints - SetUpCommonHints(); + if (PluginConfig.instance.PlayerUIConfig.EnableCommonHints) + SetUpCommonHints(); + //template - SetTemplate(); - StartTemplateCoroutine(); + if (PluginConfig.instance.PlayerUIConfig.EnableUITemplates) + SetTemplate(); playerUIs.Add(this); } - internal static void RemovePlayerUI(Player player) - { - playerUIs.Find(x => x.player == player)?.Destruct(); - } - internal void Destruct() { //Effects @@ -480,13 +539,17 @@ internal void Destruct() DestructCommonHints(); //Template - StopTemplateCoroutine(); - template?.DestructTemplate(); + DestructTemplate(); playerUIs.Remove(this); } - internal static void ClearAllPlayerUI() + internal static void RemovePlayerUI(Player player) + { + playerUIs.Find(x => x.player == player)?.Destruct(); + } + + internal static void ClearPlayerUI() { foreach (PlayerUI ui in playerUIs) { diff --git a/PlayerUI/UITemplates/AliveTemplates.cs b/PlayerUI/UITemplates/AliveTemplates.cs index 15722aa..63ed803 100644 --- a/PlayerUI/UITemplates/AliveTemplates.cs +++ b/PlayerUI/UITemplates/AliveTemplates.cs @@ -10,10 +10,11 @@ using System.Threading.Tasks; using Exiled.API.Features; using Exiled.API.Features.Roles; +using HintServiceMeow.Config; namespace HintServiceMeow.UITemplates { - public abstract class AliveTemplate : PlayerUITemplateBase + internal abstract class AliveTemplate : PlayerUITemplateBase { //Top Bar public Hint TopBar = new Hint(0, HintAlignment.Center, "", "TopBar1", true).setFontSize(15); @@ -63,7 +64,7 @@ public override void DestructTemplate() protected virtual void UpdateSpectatorHints() { - var spectatingPlayers = UICommonTools.GetSpectatorInfo(player); + var spectatingPlayers = PlayerUICommonTools.GetSpectatorInfo(player); spectatorTip.hide = true; spectatorHints.ForEach(x => x.hide = true); @@ -87,8 +88,7 @@ protected virtual void UpdateSpectatorHints() } } - - public class GeneralHumanTemplate : AliveTemplate + internal class GeneralHumanTemplate : AliveTemplate { public override PlayerUITemplateType type { get; } = PlayerUITemplateType.GeneralHuman; @@ -99,22 +99,22 @@ public GeneralHumanTemplate(Player player) : base(player) protected override void UpdateTopBar() { - string template = Config.instance.generalHumanTemplateConfig.TopBar; + string template = PluginConfig.instance.GeneralHumanTemplateConfig.TopBar; - TopBar.message = UICommonTools.GetContent(template, player); + TopBar.message = PlayerUICommonTools.GetContent(template, player); TopBar.hide = false; } protected override void UpdateBottomBar() { - string template = Config.instance.generalHumanTemplateConfig.BottomBar; + string template = PluginConfig.instance.GeneralHumanTemplateConfig.BottomBar; - BottomBar.message = UICommonTools.GetContent(template, player); + BottomBar.message = PlayerUICommonTools.GetContent(template, player); BottomBar.hide = false; } } - public class SCPTemplate : AliveTemplate + internal class SCPTemplate : AliveTemplate { public override PlayerUITemplateType type { get; } = PlayerUITemplateType.SCP; @@ -135,17 +135,17 @@ public SCPTemplate(Player player) : base(player) protected override void UpdateTopBar() { - string template = Config.instance.scpTemplateConfig.TopBar; + string template = PluginConfig.instance.ScpTemplateConfig.TopBar; - TopBar.message = UICommonTools.GetContent(template, player); + TopBar.message = PlayerUICommonTools.GetContent(template, player); TopBar.hide = false; } protected override void UpdateBottomBar() { - string template = Config.instance.scpTemplateConfig.BottomBar; + string template = PluginConfig.instance.ScpTemplateConfig.BottomBar; - BottomBar.message = UICommonTools.GetContent(template, player); + BottomBar.message = PlayerUICommonTools.GetContent(template, player); BottomBar.hide = false; } @@ -211,20 +211,20 @@ protected void OnHurting(HurtEventArgs ev) { try { - if (UICommonTools.IsSCP(ev.Player) && ev.Player.Role.Type != RoleTypeId.Scp0492 && ev.Player.Health <= ev.Player.MaxHealth * 0.2) + if (PlayerUICommonTools.IsSCP(ev.Player) && ev.Player.Role.Type != RoleTypeId.Scp0492 && ev.Player.Health <= ev.Player.MaxHealth * 0.2) { if (lastTimeHurtInformed.ContainsKey(ev.Player)) { if (Round.ElapsedTime - lastTimeHurtInformed[ev.Player] > TimeSpan.FromSeconds(40)) { - SCPInformations.Insert(0, new SCPEventHint(SCPEventHint.SCPEventType.SCPLowHP, $"{Config.instance.RoleName[ev.Player.Role.Type]}的血量较低|血量:{(int)ev.Player.Health}", Round.ElapsedTime)); + SCPInformations.Insert(0, new SCPEventHint(SCPEventHint.SCPEventType.SCPLowHP, $"{PluginConfig.instance.GeneralConfig.RoleName[ev.Player.Role.Type]}的血量较低|血量:{(int)ev.Player.Health}", Round.ElapsedTime)); lastTimeHurtInformed[ev.Player] = Round.ElapsedTime; } } else { lastTimeHurtInformed.Add(ev.Player, Round.ElapsedTime); - SCPInformations.Insert(0, new SCPEventHint(SCPEventHint.SCPEventType.SCPLowHP, $"{Config.instance.RoleName[ev.Player.Role.Type]}的血量较低|血量:{(int)ev.Player.Health}", Round.ElapsedTime)); + SCPInformations.Insert(0, new SCPEventHint(SCPEventHint.SCPEventType.SCPLowHP, $"{PluginConfig.instance.GeneralConfig.RoleName[ev.Player.Role.Type]}的血量较低|血量:{(int)ev.Player.Health}", Round.ElapsedTime)); } } } @@ -238,9 +238,9 @@ protected void OnChangingRole(ChangingRoleEventArgs ev) { try { - if (UICommonTools.IsSCP(ev.Player) && ev.Player.Role.Type != RoleTypeId.Scp0492 && ev.NewRole == RoleTypeId.Spectator) + if (PlayerUICommonTools.IsSCP(ev.Player) && ev.Player.Role.Type != RoleTypeId.Scp0492 && ev.NewRole == RoleTypeId.Spectator) { - SCPInformations.Insert(0, new SCPEventHint(SCPEventHint.SCPEventType.SCPDeath, $"{Config.instance.RoleName[ev.Player.Role.Type]}已死亡", Round.ElapsedTime)); + SCPInformations.Insert(0, new SCPEventHint(SCPEventHint.SCPEventType.SCPDeath, $"{PluginConfig.instance.GeneralConfig.RoleName[ev.Player.Role.Type]}已死亡", Round.ElapsedTime)); } }catch(Exception ex) { @@ -257,7 +257,7 @@ protected void CheckVisionInfo() { foreach (Player player in Player.List) { - if (!UICommonTools.IsSCP(player)) + if (!PlayerUICommonTools.IsSCP(player)) continue; foreach (Player target in Player.List) @@ -272,14 +272,14 @@ protected void CheckVisionInfo() { if (Round.ElapsedTime - lastTimeSpotted[player] > TimeSpan.FromSeconds(40)) { - SCPInformations.Insert(0, new SCPEventHint(SCPEventHint.SCPEventType.SpotHuman, $"{Config.instance.RoleName[player.Role.Type]}在{Config.instance.ZoneName[player.Zone]}找到了一个人类", Round.ElapsedTime)); + SCPInformations.Insert(0, new SCPEventHint(SCPEventHint.SCPEventType.SpotHuman, $"{PluginConfig.instance.GeneralConfig.RoleName[player.Role.Type]}在{PluginConfig.instance.GeneralConfig.ZoneName[player.Zone]}找到了一个人类", Round.ElapsedTime)); lastTimeSpotted[player] = Round.ElapsedTime; } } else { lastTimeSpotted.Add(player, Round.ElapsedTime); - SCPInformations.Insert(0, new SCPEventHint(SCPEventHint.SCPEventType.SCPDeath, $"{Config.instance.RoleName[player.Role.Type]}在{Config.instance.ZoneName[player.Zone]}找到了一个人类", Round.ElapsedTime)); + SCPInformations.Insert(0, new SCPEventHint(SCPEventHint.SCPEventType.SCPDeath, $"{PluginConfig.instance.GeneralConfig.RoleName[player.Role.Type]}在{PluginConfig.instance.GeneralConfig.ZoneName[player.Zone]}找到了一个人类", Round.ElapsedTime)); } } } @@ -288,7 +288,7 @@ protected void CheckVisionInfo() { foreach (Player player in Player.List) { - if (!UICommonTools.IsSCP(player)) + if (!PlayerUICommonTools.IsSCP(player)) continue; List targets = new List(); @@ -316,7 +316,7 @@ protected void CheckVisionInfo() if (targets.Count >= 4) { - SCPInformations.Insert(0, new SCPEventHint(SCPEventHint.SCPEventType.SpotHuman2, $"⚪{Config.instance.RoleName[player.Role.Type]}在{player.Zone}找到了大量人类", Round.ElapsedTime)); + SCPInformations.Insert(0, new SCPEventHint(SCPEventHint.SCPEventType.SpotHuman2, $"⚪{PluginConfig.instance.GeneralConfig.RoleName[player.Role.Type]}在{player.Zone}找到了大量人类", Round.ElapsedTime)); foreach (Player target in targets) { if (lastTimeSpotted.ContainsKey(target)) diff --git a/PlayerUI/UITemplates/Base.cs b/PlayerUI/UITemplates/Base.cs index efe0885..48d0cb0 100644 --- a/PlayerUI/UITemplates/Base.cs +++ b/PlayerUI/UITemplates/Base.cs @@ -1,4 +1,5 @@ using Exiled.API.Features; +using HintServiceMeow.UITemplates; using System; using System.Collections.Generic; using System.Linq; @@ -7,7 +8,14 @@ namespace HintServiceMeow.UITemplates { - public abstract class PlayerUITemplateBase + internal interface IPlayerUITemplate + { + void UpdateTemplate(); + void SetUpTemplate(); + void DestructTemplate(); + } + + internal abstract class PlayerUITemplateBase: IPlayerUITemplate { public enum PlayerUITemplateType { @@ -26,8 +34,6 @@ public PlayerUITemplateBase(Player player) { this.player = player; this.playerDisplay = PlayerDisplay.Get(player); - - SetUpTemplate(); } public abstract void UpdateTemplate(); diff --git a/PlayerUI/UITemplates/CustomRoleTemplates.cs b/PlayerUI/UITemplates/CustomRoleTemplates.cs index 6d5a6ff..1fc9b89 100644 --- a/PlayerUI/UITemplates/CustomRoleTemplates.cs +++ b/PlayerUI/UITemplates/CustomRoleTemplates.cs @@ -1,5 +1,6 @@ using Exiled.API.Features; using Exiled.CustomRoles.API.Features; +using HintServiceMeow.Config; using System; using System.Collections.Generic; using System.Linq; @@ -8,7 +9,7 @@ namespace HintServiceMeow.UITemplates { - public class CustomSCPTemplate : SCPTemplate + internal class CustomSCPTemplate : SCPTemplate { public override PlayerUITemplateType type { get; } = PlayerUITemplateType.CustomSCP; @@ -18,22 +19,22 @@ public CustomSCPTemplate(Player player) : base(player) protected override void UpdateTopBar() { - string template = Config.instance.customSCPTemplate.TopBar; + string template = PluginConfig.instance.CustomSCPTemplate.TopBar; - TopBar.message = UICommonTools.GetContent(template, player); + TopBar.message = PlayerUICommonTools.GetContent(template, player); TopBar.hide = false; } protected override void UpdateBottomBar() { - string template = Config.instance.customSCPTemplate.BottomBar; + string template = PluginConfig.instance.CustomSCPTemplate.BottomBar; - BottomBar.message = UICommonTools.GetContent(template, player); + BottomBar.message = PlayerUICommonTools.GetContent(template, player); BottomBar.hide = false; } } - public class CustomHumanTemplate : GeneralHumanTemplate + internal class CustomHumanTemplate : GeneralHumanTemplate { public override PlayerUITemplateType type { get; } = PlayerUITemplateType.CustomHuman; @@ -43,17 +44,17 @@ public CustomHumanTemplate(Player player) : base(player) protected override void UpdateTopBar() { - string template = Config.instance.customHumanTemplate.TopBar; + string template = PluginConfig.instance.CustomHumanTemplate.TopBar; - TopBar.message = UICommonTools.GetContent(template, player); + TopBar.message = PlayerUICommonTools.GetContent(template, player); TopBar.hide = false; } protected override void UpdateBottomBar() { - string template = Config.instance.customHumanTemplate.BottomBar; + string template = PluginConfig.instance.CustomHumanTemplate.BottomBar; - BottomBar.message = UICommonTools.GetContent(template, player); + BottomBar.message = PlayerUICommonTools.GetContent(template, player); BottomBar.hide = false; } } diff --git a/PlayerUI/UITemplates/OtherTemplates.cs b/PlayerUI/UITemplates/OtherTemplates.cs index 6544b0f..88307ff 100644 --- a/PlayerUI/UITemplates/OtherTemplates.cs +++ b/PlayerUI/UITemplates/OtherTemplates.cs @@ -9,7 +9,7 @@ namespace HintServiceMeow.UITemplates { - public class SpectatorTemplate : PlayerUITemplateBase + internal class SpectatorTemplate : PlayerUITemplateBase { public override PlayerUITemplateType type { get; } = PlayerUITemplateType.Spectator; @@ -113,7 +113,7 @@ public static string GetRespawnTimer() message = template .Replace("{RespawnMinute}", Respawn.TimeUntilSpawnWave.ToString("mm"))//Respawn Time .Replace("{RespawnSecond}", Respawn.TimeUntilSpawnWave.ToString("ss"))//Respawn Time - .Replace("{RespawnTeam}", Plugin.instance.Config.RespawnTeamDictionary[Respawn.NextKnownTeam]);//Team + .Replace("{RespawnTeam}", Config.PluginConfig.instance.GeneralConfig.RespawnTeamDictionary[Respawn.NextKnownTeam]);//Team } else { @@ -136,13 +136,13 @@ public static string GetWarheadStatus() if (Warhead.Status == Exiled.API.Enums.WarheadStatus.InProgress) { message = template - .Replace("{WarheadStatus}", Plugin.instance.Config.WarheadStatusDictionary[Warhead.Status]) + .Replace("{WarheadStatus}", Config.PluginConfig.instance.GeneralConfig.WarheadStatusDictionary[Warhead.Status]) .Replace("{TimeRemaining}", "" + ((int)Warhead.DetonationTimer).ToString() + "秒" + ""); } else { message = template - .Replace("{WarheadStatus}", Plugin.instance.Config.WarheadStatusDictionary[Warhead.Status]) + .Replace("{WarheadStatus}", Config.PluginConfig.instance.GeneralConfig.WarheadStatusDictionary[Warhead.Status]) .Replace("{TimeRemaining}", String.Empty); } @@ -235,7 +235,7 @@ public static string GetCITicketInformation() private static int hintIndex = 0; private static TimeSpan lastTimeRefresh = TimeSpan.Zero; - private static TimeSpan timeToRefresh = TimeSpan.FromSeconds(Plugin.instance.Config.HintDisplayInterval); + private static TimeSpan timeToRefresh = TimeSpan.FromSeconds(Config.PluginConfig.instance.SpectatorTemplateConfig.HintDisplayInterval); public static string GetHint() { var TimeInterval = Round.ElapsedTime - lastTimeRefresh; @@ -244,7 +244,7 @@ public static string GetHint() //If need refresh lastTimeRefresh = Round.ElapsedTime; - if (hintIndex == Plugin.instance.Config.Hints.Count() - 1) + if (hintIndex == Config.PluginConfig.instance.SpectatorTemplateConfig.Hints.Count() - 1) { hintIndex = 0; } @@ -254,9 +254,8 @@ public static string GetHint() } } - return Plugin.instance.Config.Hints[hintIndex]; + return Config.PluginConfig.instance.SpectatorTemplateConfig.Hints[hintIndex]; } } } - } diff --git a/PlayerUI/UITemplates/UITools.cs b/PlayerUI/UITools.cs similarity index 82% rename from PlayerUI/UITemplates/UITools.cs rename to PlayerUI/UITools.cs index 480bb85..e7deda1 100644 --- a/PlayerUI/UITemplates/UITools.cs +++ b/PlayerUI/UITools.cs @@ -4,6 +4,7 @@ using Exiled.API.Features.Items; using Exiled.API.Features.Roles; using Exiled.CustomRoles.API.Features; +using HintServiceMeow.Config; using PlayerRoles; using System; using System.Collections.Generic; @@ -11,9 +12,9 @@ using System.Text; using System.Threading.Tasks; -namespace HintServiceMeow.UITemplates +namespace HintServiceMeow { - public static class UICommonTools + public static class PlayerUICommonTools { /// /// This code return a value that indicate whether a player is a scp, this include custom roles that include "SCP" in their name @@ -60,10 +61,10 @@ public static string GetArmorInfo(Player player) { if (player.CurrentArmor != null) { - return Plugin.instance.Config.ItemName[player.CurrentArmor.Type]; + return PluginConfig.instance.GeneralConfig.ItemName[player.CurrentArmor.Type]; } - return Plugin.instance.Config.NoArmor; + return PluginConfig.instance.PlayerUIToolsConfig.NoArmor; } public static string GetAmmoInfo(Player player) @@ -82,12 +83,12 @@ public static string GetAmmoInfo(Player player) if (!ammos.ContainsKey(itemType) || ammos[itemType] == 0) { - ammoStatus = Plugin.instance.Config.NoAmmo; + ammoStatus = PluginConfig.instance.PlayerUIToolsConfig.NoAmmo; } else { - ammoStatus = Plugin.instance.Config.AmmoHint - .Replace("{Ammo}", Plugin.instance.Config.AmmoName[ammoType]) + ammoStatus = PluginConfig.instance.PlayerUIToolsConfig.AmmoHint1 + .Replace("{Ammo}", PluginConfig.instance.GeneralConfig.AmmoName[ammoType]) .Replace("{NumOfAmmo}", ammos[itemType].ToString()); } } @@ -97,12 +98,12 @@ public static string GetAmmoInfo(Player player) if (numOfAmmoTypes <= 0) { - ammoStatus = Plugin.instance.Config.NoAmmo; + ammoStatus = PluginConfig.instance.PlayerUIToolsConfig.NoAmmo; } else if (numOfAmmoTypes <= 1) { - ammoStatus = Plugin.instance.Config.AmmoHint - .Replace("{Ammo}", Plugin.instance.Config.ItemName[ammos.First().Key]) + ammoStatus = PluginConfig.instance.PlayerUIToolsConfig.AmmoHint1 + .Replace("{Ammo}", PluginConfig.instance.GeneralConfig.ItemName[ammos.First().Key]) .Replace("{NumOfAmmo}", ammos.First().Value.ToString()); } else @@ -114,7 +115,7 @@ public static string GetAmmoInfo(Player player) totalAmmos += numOfAmmo; } - ammoStatus = Plugin.instance.Config.AmmoHint2 + ammoStatus = PluginConfig.instance.PlayerUIToolsConfig.AmmoHint2 .Replace("{NumOfAmmo}", totalAmmos.ToString()); } } @@ -126,16 +127,16 @@ public static string GetContent(String template, Player player) //replace the te { //player nickname, actual name, role, rolecolor, ammo, armor, team, //TPS, - Config config = Plugin.instance.Config; + PluginConfig config = PluginConfig.instance; template = template //Player Name .Replace("{PlayerNickname}", player.CustomName) .Replace("{PlayerName}", player.Nickname) //Roles - .Replace("{Role}", GetCustomRole(player)?.Name ?? config.RoleName[player.Role.Type]) + .Replace("{Role}", GetCustomRole(player)?.Name ?? config.GeneralConfig.RoleName[player.Role.Type]) .Replace("{RoleColor}", player.Role.Color.ToHex()) - .Replace("{Team}", config.TeamName[player.Role.Team]) + .Replace("{Team}", config.GeneralConfig.TeamName[player.Role.Team]) .Replace("{TeammateCount}", (Player.List.Count(x => player.LeadingTeam == x.LeadingTeam) - 1).ToString()) //Ammo/Armor info .Replace("{AmmoInfo}", GetAmmoInfo(player)) diff --git a/Plugin.cs b/Plugin.cs index 1710e6f..629130e 100644 --- a/Plugin.cs +++ b/Plugin.cs @@ -6,42 +6,46 @@ using Hints; using HarmonyLib; using HintServiceMeow; - - -//*V1.0.0 -//* V1.0.1 -//* Update the display based on hint's updation -// * V2.0.0 -// * Support Dynamic Hint -// * Limit maximum update rate to 0.5/second -// * Fixed some bugs -// *V2.1.0 -// * Add Common Hints -// *V2.1.1 -// * Fix some bugs -// *v2.2.0 -// * Use the event to update the player display, increase stability, and decrease costs -// *v3.0.0 -// * Player UI is separated from PlayerDisplay and extended for more methods -// *v3.0.1 -// * Fix some bugs -// *V3.0.2 -// * Fix the bug that crush the PlayerDisplay when there's no hint displayed on the screen -// *V3.1.0 -// * Add PlayerUI Config -// * TODO: ADD configs for spectator template, scp extra info, spectator info, etc. -// *V3.1.1 -// * bug fixing -// *V3.1.2 -// * Use patch to block all the hints from other plugins +using HintServiceMeow.Config; + + +// * V1.0.0 +// * V1.0.1 +// * Update the display based on hint's updation +// * V2.0.0 +// * Support Dynamic Hint +// * Limit maximum update rate to 0.5/second +// * Fixed some bugs +// * V2.1.0 +// * Add Common Hints +// * V2.1.1 +// * Fix some bugs +// * V2.2.0 +// * Use the event to update the player display, increase stability, and decrease costs +// * V3.0.0 +// * Player UI is separated from PlayerDisplay and extended for more methods +// * V3.0.1 +// * Fix some bugs +// * V3.0.2 +// * Fix the bug that crush the PlayerDisplay when there's no hint displayed on the screen +// * V3.1.0 +// * Add PlayerUI Config +// * TODO: ADD configs for spectator template, scp extra info, spectator info, etc. +// * V3.1.1 +// * bug fixing +// * V3.1.2 +// * Use patch to block all the hints from other plugins +// * V3.2.0 +// * Organized config +// * Make PlayerUI more customizable namespace HintServiceMeow { - class Plugin : Plugin + class Plugin : Plugin { public override string Name => "HintServiceMeow"; public override string Author => "MeowServerOwner"; - public override Version Version => new Version(3, 1, 2); + public override Version Version => new Version(3, 2, 0); public override PluginPriority Priority => PluginPriority.First; @@ -52,7 +56,7 @@ class Plugin : Plugin public override void OnEnabled() { instance = this; - Config.instance = Config; + PluginConfig.instance = Config; _harmony = new Harmony("HintServiceMeowHarmony"); _harmony.PatchAll(); @@ -66,7 +70,7 @@ public override void OnEnabled() public override void OnDisabled() { instance = null; - Config.instance = null; + PluginConfig.instance = null; _harmony.UnpatchAll(); _harmony = null; @@ -85,7 +89,7 @@ private static void OnVerified(VerifiedEventArgs ev) if (ev.Player.IsNPC) return; var pd = new PlayerDisplay(ev.Player); - if(Config.instance.EnablePlayerUI) + if(PluginConfig.instance.EnablePlayerUI) new PlayerUI(ev.Player); EventHandler.InvokeNewPlayerEvent(pd); @@ -99,7 +103,7 @@ private static void OnLeft(LeftEventArgs ev) private static void OnDisable() { - PlayerUI.ClearAllPlayerUI(); + PlayerUI.ClearPlayerUI(); PlayerDisplay.ClearPlayerDisplay(); } }