MachineNut HP text patch
This commit is contained in:
parent
311086a845
commit
55e4d5b937
1 changed files with 43 additions and 20 deletions
|
|
@ -1,8 +1,6 @@
|
||||||
#if FIX
|
using HarmonyLib;
|
||||||
using HarmonyLib;
|
|
||||||
using Il2Cpp;
|
using Il2Cpp;
|
||||||
using PvZ_Fusion_Translator.AssetStore;
|
using System.Text.RegularExpressions;
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace PvZ_Fusion_Translator.Patches.GameObjects.MinorObjects
|
namespace PvZ_Fusion_Translator.Patches.GameObjects.MinorObjects
|
||||||
{
|
{
|
||||||
|
|
@ -10,15 +8,40 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects.MinorObjects
|
||||||
public static class Plant_Patch
|
public static class Plant_Patch
|
||||||
{
|
{
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
[HarmonyPatch(nameof(Plant.UpdateHealthText))]
|
[HarmonyPatch(nameof(Plant.Awake))]
|
||||||
private static void UpdateHealthText(Plant __instance)
|
private static void Awake(Plant __instance)
|
||||||
{
|
{
|
||||||
Transform healthTransform = __instance.transform.Find("health");
|
if (!(__instance.thePlantType == PlantType.SuperMachineNut || __instance.thePlantType == PlantType.MachineNut))
|
||||||
if (healthTransform != null)
|
return;
|
||||||
{
|
__instance.healthSlider.healthText.text = __instance.healthSlider.healthTextShadow.text = ChangeHPText(__instance.healthSlider.healthTextShadow.text);
|
||||||
StringStore.TranslateTextTransform(__instance.transform);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HarmonyPostfix]
|
||||||
|
[HarmonyPatch(nameof(Plant.UpdateText))]
|
||||||
|
private static void Update(Plant __instance)
|
||||||
|
{
|
||||||
|
if (!(__instance.thePlantType == PlantType.SuperMachineNut || __instance.thePlantType == PlantType.MachineNut))
|
||||||
|
return;
|
||||||
|
if (__instance.thePlantHealth < __instance.thePlantMaxHealth)
|
||||||
|
return;
|
||||||
|
__instance.healthSlider.healthText.text = __instance.healthSlider.healthTextShadow.text = ChangeHPText(__instance.healthSlider.healthTextShadow.text);
|
||||||
|
}
|
||||||
|
|
||||||
|
static string ChangeHPText(string originalText)
|
||||||
|
{
|
||||||
|
var regex = new Regex(@"(\d+)\d\d\d/(\d)000");
|
||||||
|
if (regex.IsMatch(originalText))
|
||||||
|
{
|
||||||
|
var match = regex.Match(originalText);
|
||||||
|
int groupCount = match.Groups.Count;
|
||||||
|
|
||||||
|
List<string> dynamicParts = new List<string>();
|
||||||
|
|
||||||
|
for (int i = 1; i < groupCount; i++)
|
||||||
|
dynamicParts.Add(match.Groups[i].Value);
|
||||||
|
return originalText = string.Format("{0}k/{1}k", [.. dynamicParts]);
|
||||||
|
}
|
||||||
|
return originalText;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
Loading…
Add table
Reference in a new issue