Files
H3VR-TNH-Quality-of-Life-Im…/Assets/_Scripts/HoldCounter.cs
T

60 lines
1.5 KiB
C#
Raw Normal View History

2022-01-26 01:23:39 -08:00
using System.Reflection;
using HarmonyLib;
2022-01-22 20:13:49 -08:00
using UnityEngine;
using UnityEngine.UI;
using FistVR;
namespace TNHQoLImprovements
{
public static class HoldCounterPatch
{
public static void Patch(Harmony harmony)
{
var original = typeof(TNH_Manager).GetMethod("HoldPointCompleted", BindingFlags.Public | BindingFlags.Instance);
var patch = typeof(HoldCounter).GetMethod("OnHoldEnd");
harmony.Patch(original, postfix: new HarmonyMethod(patch));
}
}
public class HoldCounter : MonoBehaviour
2022-01-22 20:13:49 -08:00
{
2022-01-26 01:23:39 -08:00
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>";
public static void OnHoldEnd(TNH_HoldPoint p, bool success)
{
if (success)
winLose[0]++;
else
winLose[1]++;
2022-01-22 23:41:31 -08:00
}
2022-01-22 20:13:49 -08:00
void Start()
{
transform.localPosition = new Vector3(-333, 0, -450);
2022-01-22 23:41:31 -08:00
2022-01-26 01:23:39 -08:00
lblHoldCount = transform.GetChild(1).GetComponent<Text>();
lblWinLose = transform.GetChild(2).GetComponent<Text>();
winLose[0] = 0;
winLose[1] = 0;
2022-01-22 20:13:49 -08:00
}
void Update()
{
2022-01-26 01:23:39 -08:00
// Total hold count
2022-01-22 20:13:49 -08:00
string display = "";
if (InPlay.tnhManager.ProgressionMode == TNHSetting_ProgressionType.Marathon)
2022-01-22 23:41:31 -08:00
display = InPlay.tnhManager.m_level.ToString() + " / ∞";
2022-01-22 20:13:49 -08:00
else
display = string.Format("{0} / {1}", InPlay.tnhManager.m_level, InPlay.tnhManager.m_maxLevels);
2022-01-26 01:23:39 -08:00
lblHoldCount.text = display;
2022-01-22 20:13:49 -08:00
2022-01-26 01:23:39 -08:00
// Win/Lost holds
lblWinLose.text = string.Format(WIN_LOSE_TEXT, winLose[0], winLose[1]);
2022-01-22 20:13:49 -08:00
}
}
}