mirror of
https://github.com/muskit/H3VR-TNH-Quality-of-Life-Improvements.git
synced 2026-06-02 20:24:26 -07:00
win/lose hold stats, hp crystal expiration
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using FistVR;
|
||||
@@ -8,37 +8,62 @@ namespace TNHQoLImprovements
|
||||
{
|
||||
public class HoldCounter : MonoBehaviour
|
||||
{
|
||||
private Text lblHoldCount;
|
||||
private Text lblWinLose;
|
||||
|
||||
public static int[] winLose = { -1, 1 };
|
||||
public const string WIN_LOSE_TEXT = "<color=#10ff10>{0}</color> <color=red>{1}</color>";
|
||||
|
||||
|
||||
private void OnDeath(bool _)
|
||||
{
|
||||
Debug.Log("I died!");
|
||||
// TODO: bind stats to controller hand
|
||||
}
|
||||
|
||||
// TODO: lose counter. patch postfix FistVR.TNH_Manager.HoldPointCompleted
|
||||
private void OnHoldLose()
|
||||
// TODO: win/lose counter. patch postfix FistVR.TNH_Manager.HoldPointCompleted
|
||||
public static void Patch(Harmony harmony)
|
||||
{
|
||||
|
||||
var original = typeof(TNH_Manager).GetMethod("HoldPointCompleted", BindingFlags.Public | BindingFlags.Instance);
|
||||
var patch = typeof(HoldCounter).GetMethod("OnHoldEnd");
|
||||
Debug.Log(string.Format("Original: {0} // Patch: {1}", original, patch));
|
||||
harmony.Patch(original, postfix: new HarmonyMethod(patch));
|
||||
}
|
||||
public static void OnHoldEnd(TNH_HoldPoint p, bool success)
|
||||
{
|
||||
if (success)
|
||||
winLose[0]++;
|
||||
else
|
||||
winLose[1]++;
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
//transform.parent = GameObject.Find("_NewTAHReticle/TAHReticle_HealthBar").transform;
|
||||
transform.parent = FindObjectOfType<TAH_Reticle>().transform.GetChild(3);
|
||||
transform.localPosition = new Vector3(-1f, 0, -.5f);
|
||||
transform.localRotation = Quaternion.Euler(90, 0, 0);
|
||||
transform.localScale = new Vector3(0.002f, 0.002f, 0.002f);
|
||||
|
||||
lblHoldCount = transform.GetChild(1).GetComponent<Text>();
|
||||
lblWinLose = transform.GetChild(2).GetComponent<Text>();
|
||||
|
||||
winLose[0] = 0;
|
||||
winLose[1] = 0;
|
||||
|
||||
FindObjectOfType<FVRSceneSettings>().PlayerDeathEvent += OnDeath;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
// Total hold count
|
||||
string display = "";
|
||||
if (InPlay.tnhManager.ProgressionMode == TNHSetting_ProgressionType.Marathon)
|
||||
display = InPlay.tnhManager.m_level.ToString() + " / ∞";
|
||||
else
|
||||
display = string.Format("{0} / {1}", InPlay.tnhManager.m_level, InPlay.tnhManager.m_maxLevels);
|
||||
lblHoldCount.text = display;
|
||||
|
||||
transform.GetChild(1).GetComponent<Text>().text = display;
|
||||
// Win/Lost holds
|
||||
lblWinLose.text = string.Format(WIN_LOSE_TEXT, winLose[0], winLose[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,10 +11,8 @@ namespace TNHQoLImprovements
|
||||
public class InPlay : MonoBehaviour
|
||||
{
|
||||
private GameObject gObjHUD;
|
||||
private GameObject gObjTokens;
|
||||
public static TNH_Manager tnhManager;
|
||||
|
||||
#region INITIALIZATION
|
||||
void ImproveHPTextReadability()
|
||||
{
|
||||
var canvas = gObjHUD.GetComponent<Canvas>();
|
||||
@@ -60,10 +58,9 @@ namespace TNHQoLImprovements
|
||||
if(MeatKitPlugin.cfgShowHPBackground.Value || MeatKitPlugin.cfgSolidifyHPText.Value)
|
||||
ImproveHPTextReadability();
|
||||
if (MeatKitPlugin.cfgShowTokens.Value)
|
||||
Instantiate(MeatKitPlugin.bundle.LoadAsset<GameObject>("TokenCounter"));
|
||||
Instantiate(MeatKitPlugin.bundle.LoadAsset<GameObject>("TokenCounter"), FindObjectOfType<TAH_Reticle>().transform.GetChild(3));
|
||||
if (MeatKitPlugin.cfgShowHolds.Value)
|
||||
Instantiate(MeatKitPlugin.bundle.LoadAsset<GameObject>("HoldCounter"));
|
||||
Instantiate(MeatKitPlugin.bundle.LoadAsset<GameObject>("HoldCounter"), FindObjectOfType<TAH_Reticle>().transform.GetChild(3));
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -15,22 +15,13 @@ namespace TNHQoLImprovements
|
||||
private bool tnhTweakerInstalled = false;
|
||||
|
||||
private string curID;
|
||||
private string loadingStr;
|
||||
|
||||
private TNH_ScoreDisplay scoreDisplay;
|
||||
private Text lblGlobalScores;
|
||||
private GameObject gObjLoading;
|
||||
|
||||
#region INITIALIZATION
|
||||
// public void Start()
|
||||
// {
|
||||
// Debug.Log("--- Installed BepInEx Plugins ---");
|
||||
// foreach (var plugin in Chainloader.PluginInfos)
|
||||
// {
|
||||
// Debug.Log(plugin.Key);
|
||||
// }
|
||||
// Debug.Log("--- End Plugins ---");
|
||||
//}
|
||||
|
||||
public void Init(TNH_ScoreDisplay tnhScore, Text scoreLabel, GameObject gObjLoading)
|
||||
{
|
||||
if (initialized)
|
||||
@@ -41,12 +32,13 @@ namespace TNHQoLImprovements
|
||||
this.lblGlobalScores.resizeTextForBestFit = true;
|
||||
this.lblGlobalScores.horizontalOverflow = HorizontalWrapMode.Overflow;
|
||||
this.gObjLoading = gObjLoading;
|
||||
loadingStr = gObjLoading.GetComponentInChildren<Text>().text;
|
||||
|
||||
var loadedAssemblies = System.AppDomain.CurrentDomain.GetAssemblies();
|
||||
if (Array.Exists<Assembly>(loadedAssemblies, x => x.GetName().Name == "TakeAndHoldTweaker"))
|
||||
{
|
||||
tnhTweakerInstalled = true;
|
||||
this.gObjLoading.transform.GetChild(0).GetComponent<Text>().text = "<color=lightblue>Online leaderboards player count is incompatible with TNHTweaker.</color>";
|
||||
this.gObjLoading.transform.GetChild(0).GetComponent<Text>().text = "<color=lightblue><size=30>Online player count is incompatible with TNHTweaker.</size></color>";
|
||||
this.gObjLoading.SetActive(true);
|
||||
}
|
||||
|
||||
@@ -66,23 +58,31 @@ namespace TNHQoLImprovements
|
||||
}
|
||||
|
||||
private void UpdatePlayerCountDisplay(string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
string playerCountText = Steamworks.SteamUserStats
|
||||
.GetLeaderboardEntryCount(HighScoreManager.Leaderboards[id])
|
||||
.ToString("N0");
|
||||
lblGlobalScores.text = "Global Scores: <color=lightblue>(" + playerCountText + " players)</color>";
|
||||
curID = id;
|
||||
{
|
||||
try
|
||||
{
|
||||
string playerCountText = Steamworks.SteamUserStats
|
||||
.GetLeaderboardEntryCount(HighScoreManager.Leaderboards[id])
|
||||
.ToString("N0");
|
||||
|
||||
lblGlobalScores.text = "Global Scores: <color=lightblue>(" + playerCountText + " players)</color>";
|
||||
curID = id;
|
||||
gObjLoading.SetActive(false);
|
||||
}
|
||||
catch (KeyNotFoundException e)
|
||||
{
|
||||
lblGlobalScores.text = "Global Scores:";
|
||||
}
|
||||
catch (KeyNotFoundException e)
|
||||
{
|
||||
lblGlobalScores.text = "Global Scores:";
|
||||
gObjLoading.GetComponentInChildren<Text>().text = loadingStr;
|
||||
gObjLoading.SetActive(true);
|
||||
curID = null;
|
||||
curID = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
gObjLoading.GetComponentInChildren<Text>().text = string.Format("<color=lightblue><size=30>Unknown error occured trying to retrieve online player count.</size></color>\n\n" +
|
||||
"<color=red>{0}</color>", e);
|
||||
gObjLoading.SetActive(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -1,25 +1,24 @@
|
||||
using HarmonyLib;
|
||||
using System.Reflection;
|
||||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using FistVR;
|
||||
|
||||
namespace TNHQoLImprovements
|
||||
{
|
||||
[HarmonyPatch]
|
||||
public class LeaderboardPlayerCountPatch
|
||||
public static class LeaderboardPlayerCountPatch
|
||||
{
|
||||
Harmony harmony;
|
||||
private static GameObject gObjLoading;
|
||||
private static Text uiGlobalText;
|
||||
|
||||
public LeaderboardPlayerCountPatch()
|
||||
public static void Patch(Harmony harmony)
|
||||
{
|
||||
harmony = new Harmony("me.muskit.TNHQualityOfLifeImprovements.LeaderboardPlayerCount");
|
||||
harmony.PatchAll();
|
||||
var original = typeof(TNH_ScoreDisplay).GetMethod("Start", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
var newfunc = typeof(LeaderboardPlayerCountPatch).GetMethod("Setup");
|
||||
|
||||
harmony.Patch(original, postfix: new HarmonyMethod(newfunc));
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(TNH_ScoreDisplay), "Start")]
|
||||
public static void Setup(TNH_ScoreDisplay __instance)
|
||||
{
|
||||
GameObject gObjLeaderboard = null;
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TNHQoLImprovements
|
||||
{
|
||||
/// <summary>
|
||||
/// Flash attached MeshRenderer the timer runs out.
|
||||
/// </summary>
|
||||
public class MeshRendererFlicker : MonoBehaviour
|
||||
{
|
||||
private bool initialized = false;
|
||||
|
||||
private float beginTime;
|
||||
private float onLength;
|
||||
private float offLength;
|
||||
private float stateChangeTime = 0;
|
||||
private bool visible = true;
|
||||
|
||||
private MeshRenderer mesh;
|
||||
|
||||
void Start()
|
||||
{
|
||||
mesh = GetComponent<MeshRenderer>();
|
||||
}
|
||||
|
||||
public void Init(float interval, float onToOffRatio = 0.5f, float beginAfter = 0)
|
||||
{
|
||||
beginTime = Time.time + beginAfter;
|
||||
onLength = interval * onToOffRatio;
|
||||
offLength = interval * (1 - onToOffRatio);
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (!initialized || Time.time < beginTime)
|
||||
return;
|
||||
|
||||
if (Time.time >= stateChangeTime)
|
||||
{
|
||||
visible = !visible;
|
||||
mesh.enabled = visible;
|
||||
|
||||
if (visible) // set time to stay on
|
||||
{
|
||||
stateChangeTime = Time.time + onLength;
|
||||
}
|
||||
else // set time to stay off
|
||||
{
|
||||
stateChangeTime = Time.time + offLength;
|
||||
}
|
||||
}
|
||||
|
||||
//if (Time.time >= stateChangeTime)
|
||||
// {
|
||||
// stateChangeTime = Time.time + interval;
|
||||
// visible = !visible;
|
||||
// mesh.enabled = visible;
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 41ced368c613e2444bdbb07051989499
|
||||
timeCreated: 1643160950
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,57 @@
|
||||
using System.Reflection;
|
||||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
using FistVR;
|
||||
|
||||
namespace TNHQoLImprovements
|
||||
{
|
||||
/// <summary>
|
||||
/// If KillAfter is attached to a HealthCrystal, show visual representation of expiration.
|
||||
/// </summary>
|
||||
public static class TimedHealthCrystalPatch
|
||||
{
|
||||
private static GameObject timerAsset;
|
||||
public const int VISUAL_APPROACH = 2;
|
||||
|
||||
public static void Patch(Harmony harmony)
|
||||
{
|
||||
timerAsset = MeatKitPlugin.bundle.LoadAsset<GameObject>("HealthCrystalTimer");
|
||||
|
||||
var original = typeof(KillAfter).GetMethod("Start", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
var newfunc = typeof(TimedHealthCrystalPatch).GetMethod("Setup");
|
||||
|
||||
harmony.Patch(original, postfix: new HarmonyMethod(newfunc));
|
||||
}
|
||||
|
||||
public static void Setup(KillAfter __instance)
|
||||
{
|
||||
// only work with Health Crystals
|
||||
if (__instance.transform.GetComponentInChildren<HealthPickUp>() == null)
|
||||
return;
|
||||
|
||||
Debug.Log("KillAfter will expire in " + __instance.DieTime + " seconds.");
|
||||
|
||||
GameObject timer;
|
||||
Transform healthCrystal = __instance.transform.Find("HealthCrystal");
|
||||
switch (VISUAL_APPROACH)
|
||||
{
|
||||
case 0: // ring above
|
||||
timer = GameObject.Instantiate<GameObject>(timerAsset, healthCrystal);
|
||||
timer.GetComponent<UIRingTimer>().Init(__instance.DieTime);
|
||||
timer.transform.localScale = new Vector2(0.001f, 0.001f);
|
||||
timer.transform.localPosition = new Vector3(0, .9f, 0);
|
||||
break;
|
||||
case 1: // ring around
|
||||
timer = GameObject.Instantiate<GameObject>(timerAsset, healthCrystal);
|
||||
timer.GetComponent<UIRingTimer>().Init(__instance.DieTime);
|
||||
timer.transform.localScale = new Vector2(0.0035f, 0.0035f);
|
||||
timer.transform.localPosition = Vector3.zero;
|
||||
break;
|
||||
case 2: // flashing crystal
|
||||
var flicker = healthCrystal.gameObject.AddComponent<MeshRendererFlicker>();
|
||||
flicker.Init(.4f, 0.6f, __instance.DieTime - 3f);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e2d8d57a4a90c704da061837b5f7b16a
|
||||
timeCreated: 1643082249
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -9,8 +9,6 @@ namespace TNHQoLImprovements
|
||||
{
|
||||
void Start()
|
||||
{
|
||||
//transform.parent = GameObject.Find("_NewTAHReticle/TAHReticle_HealthBar").transform;
|
||||
transform.parent = FindObjectOfType<TAH_Reticle>().transform.GetChild(3);
|
||||
transform.localPosition = new Vector3(1, 0, -.5f);
|
||||
transform.localRotation = Quaternion.Euler(90, 0, 0);
|
||||
transform.localScale = new Vector3(0.002f, 0.002f, 0.002f);
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class UIRingTimer : MonoBehaviour {
|
||||
|
||||
private bool initialized = false;
|
||||
private float endTime;
|
||||
private float length;
|
||||
|
||||
private Image ringImg;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
ringImg = GetComponentInChildren<Image>();
|
||||
}
|
||||
|
||||
public void Init(float timeInSeconds)
|
||||
{
|
||||
length = timeInSeconds;
|
||||
endTime = Time.time + length;
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
void Update () {
|
||||
if (!initialized)
|
||||
return;
|
||||
|
||||
float amount = (endTime - Time.time) / length;
|
||||
ringImg.fillAmount = Mathf.Clamp01(amount);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c0cc182175a3417499d53e43378f028c
|
||||
timeCreated: 1643099834
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user