From b2594243005ecac8c845ded38ee8ac9ddbfc352d Mon Sep 17 00:00:00 2001 From: msk <15199219+muskit@users.noreply.github.com> Date: Mon, 24 Jan 2022 01:48:22 -0800 Subject: [PATCH] stop searching for TNHLBPC after 120s, add option for hp text visibility --- Assets/MeatKit/BuildProfile.asset | 2 +- Assets/MeatKit/MeatKitPlugin.cs | 71 ++++++++++++++++++------------- Assets/_Scripts/InPlay.cs | 42 +++++++++--------- 3 files changed, 66 insertions(+), 49 deletions(-) diff --git a/Assets/MeatKit/BuildProfile.asset b/Assets/MeatKit/BuildProfile.asset index 5fbb613..eec7587 100644 --- a/Assets/MeatKit/BuildProfile.asset +++ b/Assets/MeatKit/BuildProfile.asset @@ -13,7 +13,7 @@ MonoBehaviour: m_EditorClassIdentifier: PackageName: TNH_Quality_of_Life_Improvements Author: muskit - Version: 1.0.0 + Version: 1.0.1 Icon: {fileID: 2800000, guid: 785b7946398f5314b95bf593d2d77d67, type: 3} ReadMe: {fileID: 102900000, guid: ab1d6dea017447a48ac348db588a6f35, type: 3} WebsiteURL: https://github.com/muskit/TNH-Quality-of-Life-Improvements diff --git a/Assets/MeatKit/MeatKitPlugin.cs b/Assets/MeatKit/MeatKitPlugin.cs index 0f5ff97..48e22e8 100644 --- a/Assets/MeatKit/MeatKitPlugin.cs +++ b/Assets/MeatKit/MeatKitPlugin.cs @@ -32,18 +32,18 @@ public class MeatKitPlugin : BaseUnityPlugin #pragma warning disable 414 private static readonly string BasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); #pragma warning restore 414 - - private bool lpcKilled = false; - public static AssetBundle bundle; - - public static ConfigEntry showHPBackground; - public static ConfigEntry hpBackgroundOpacity; - public static ConfigEntry showTokens; - public static ConfigEntry showHolds; - + public static ConfigEntry cfgSolidifyHPText; + public static ConfigEntry cfgShowHPBackground; + public static ConfigEntry cfgHPBackgroundOpacity; + public static ConfigEntry cfgShowTokens; + public static ConfigEntry cfgShowHolds; + private static InPlay instance; + private LeaderboardPlayerCountPatch lpc; + private bool lpcModGone = false; + private float lpcModSearchTimeEnd; private void SceneChanged(Scene from, Scene to) { @@ -66,35 +66,42 @@ public class MeatKitPlugin : BaseUnityPlugin LoadAssets(); // setup configuration - showHPBackground = Config.Bind("Health Counter", - "Background enabled", - true, - "Apply a background to the health text."); - hpBackgroundOpacity = Config.Bind("Health Counter", - "Background opacity", - 0.74f, - "Set opacity of health text's background (if enabled)."); - showTokens = Config.Bind("Game Info", - "Show Tokens", - true, - "Shows how many tokens the player has by their radar hand."); - showHolds = Config.Bind("Game Info", - "Show Holds", - true, - "Shows how many holds the player has completed by their radar hand."); + cfgShowHPBackground = Config.Bind("Health Counter", + "Background enabled", + true, + "Apply a background to the health text."); + cfgHPBackgroundOpacity = Config.Bind("Health Counter", + "Background opacity", + 0.74f, + "Set opacity of health text's background (if enabled)."); + cfgSolidifyHPText = Config.Bind("Health Counter", + "Solidify HP text", + true, + "Set opacity of HP text to full and give it a shadow."); + cfgShowTokens = Config.Bind("Game Info", + "Show Tokens", + true, + "Shows how many tokens the player has by their radar hand."); + cfgShowHolds = Config.Bind("Game Info", + "Show Holds", + true, + "Shows how many holds the player has completed by their radar hand."); - // patch the leaderboard + // patch leaderboard code lpc = new LeaderboardPlayerCountPatch(); + + // give 120 seconds to search for old mod + lpcModSearchTimeEnd = Time.realtimeSinceStartup + 120; } // DO NOT EDIT. private void LoadAssets() {} /// - /// Its only purpose: to kill TNH Leaderboard Player Count + /// Its only purpose: to kill the deprecated TNH Leaderboard Player Count mod. /// private void Update() { - if (lpcKilled) + if (lpcModGone) return; foreach (var plugin in Chainloader.PluginInfos) @@ -103,9 +110,15 @@ public class MeatKitPlugin : BaseUnityPlugin { Logger.LogWarning("TNH Leaderboard Player Count mod detected. Destroying it to avoid interference."); Destroy(plugin.Value.Instance); - lpcKilled = true; + lpcModGone = true; } } + + if (Time.realtimeSinceStartup >= lpcModSearchTimeEnd) + { + Logger.LogWarning("Stopping search for TNH Leaderboard Player Count mod after 120 seconds."); + lpcModGone = true; + } } } #endif \ No newline at end of file diff --git a/Assets/_Scripts/InPlay.cs b/Assets/_Scripts/InPlay.cs index b517b23..7ec7d97 100644 --- a/Assets/_Scripts/InPlay.cs +++ b/Assets/_Scripts/InPlay.cs @@ -19,33 +19,36 @@ namespace TNHQoLImprovements { var canvas = gObjHUD.GetComponent(); var gObjBG = new GameObject(); - var tranHPTitle = gObjHUD.transform.Find("Label_Title (1)"); - var tranHP = gObjHUD.transform.Find("Label_Title"); + Transform[] tranHPText = { + gObjHUD.transform.Find("Label_Title (1)"), + gObjHUD.transform.Find("Label_Title") + }; // apply background - if (MeatKitPlugin.showHPBackground.Value) + if (MeatKitPlugin.cfgShowHPBackground.Value) { gObjBG.transform.parent = gObjHUD.transform; gObjBG.transform.SetSiblingIndex(0); gObjBG.transform.localPosition = new Vector3(0, 1, 0); gObjBG.transform.localRotation = Quaternion.identity; - gObjBG.transform.localScale = tranHP.localScale; + gObjBG.transform.localScale = tranHPText[0].localScale; var rawImage = gObjBG.AddComponent(); - rawImage.color = new Color(0, 0, 0, MeatKitPlugin.hpBackgroundOpacity.Value); + rawImage.color = new Color(0, 0, 0, MeatKitPlugin.cfgHPBackgroundOpacity.Value); rawImage.rectTransform.SetWidth(100); rawImage.rectTransform.SetHeight(52); } - - // full text alphas - tranHPTitle.GetComponent().color = Color.white; - tranHP.GetComponent().color = Color.white; - // text shadows - var shadow = tranHPTitle.gameObject.AddComponent(); - shadow.effectColor = new Color(0, 0, 0, .95f); - shadow.effectDistance = new Vector2(0.5f, -0.5f); - shadow = tranHP.gameObject.AddComponent(); - shadow.effectColor = new Color(0, 0, 0, .95f); - shadow.effectDistance = new Vector2(0.5f, -0.5f); + if (MeatKitPlugin.cfgSolidifyHPText.Value) + { + foreach (var text in tranHPText) + { + // full alpha + text.GetComponent().color = Color.white; + // drop shadow + var shadow = text.gameObject.AddComponent(); + shadow.effectColor = new Color(0, 0, 0, .95f); + shadow.effectDistance = new Vector2(0.5f, -0.5f); + } + } } // Use this for initialization @@ -54,10 +57,11 @@ namespace TNHQoLImprovements tnhManager = GameObject.Find("_GameManager").GetComponent(); gObjHUD = GameObject.Find("HealthBar(Clone)/f"); - ImproveHPTextReadability(); - if (MeatKitPlugin.showTokens.Value) + if(MeatKitPlugin.cfgShowHPBackground.Value || MeatKitPlugin.cfgSolidifyHPText.Value) + ImproveHPTextReadability(); + if (MeatKitPlugin.cfgShowTokens.Value) Instantiate(MeatKitPlugin.bundle.LoadAsset("TokenCounter")); - if (MeatKitPlugin.showHolds.Value) + if (MeatKitPlugin.cfgShowHolds.Value) Instantiate(MeatKitPlugin.bundle.LoadAsset("HoldCounter")); } #endregion