MachineNut HP text patch

This commit is contained in:
Dakosha 2025-06-26 00:17:56 +03:00
parent 311086a845
commit 55e4d5b937

View file

@ -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);
}
[HarmonyPostfix]
[HarmonyPatch(nameof(Plant.UpdateText))]
private static void Update(Plant __instance)
{ {
StringStore.TranslateTextTransform(__instance.transform); 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