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 PvZ_Fusion_Translator.AssetStore;
|
||||
using UnityEngine;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace PvZ_Fusion_Translator.Patches.GameObjects.MinorObjects
|
||||
{
|
||||
|
|
@ -10,15 +8,40 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects.MinorObjects
|
|||
public static class Plant_Patch
|
||||
{
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(nameof(Plant.UpdateHealthText))]
|
||||
private static void UpdateHealthText(Plant __instance)
|
||||
[HarmonyPatch(nameof(Plant.Awake))]
|
||||
private static void Awake(Plant __instance)
|
||||
{
|
||||
Transform healthTransform = __instance.transform.Find("health");
|
||||
if (healthTransform != null)
|
||||
{
|
||||
StringStore.TranslateTextTransform(__instance.transform);
|
||||
if (!(__instance.thePlantType == PlantType.SuperMachineNut || __instance.thePlantType == PlantType.MachineNut))
|
||||
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)
|
||||
{
|
||||
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