RacesOfValheim/JotunnModStub/Trol/TrolFoodDebugUI.cs
2026-07-30 19:00:13 +02:00

67 lines
3 KiB
C#

using HarmonyLib;
using UnityEngine;
using UnityEngine.UI;
namespace RacesOfValheim
{
[HarmonyPatch]
public static class TrolFoodDebugUI
{
[HarmonyPatch(typeof(Player), "Update")]
[HarmonyPostfix]
public static void Update_Postfix(Player __instance)
{
if (__instance != Player.m_localPlayer) return;
if (Input.GetKeyDown(KeyCode.F8))
{
Jotunn.Logger.LogInfo("=== F8 TROL FOOD UI DEBUG ===");
Transform healthPanel = Hud.instance?.transform.Find("hudroot/healthpanel");
if (healthPanel != null)
{
Transform food3 = healthPanel.Find("TrolExtraFoodSlot");
if (food3 != null)
{
Transform timeT = food3.Find("time");
Jotunn.Logger.LogInfo($"Found TrolExtraFoodSlot! time transform found: {timeT != null}");
if (timeT != null)
{
Component[] comps = timeT.GetComponents<Component>();
Jotunn.Logger.LogInfo("Components on 'time' object:");
foreach(var c in comps) {
Jotunn.Logger.LogInfo(" - " + c.GetType().FullName);
}
Text timeText = timeT.GetComponent<Text>();
Jotunn.Logger.LogInfo($"UnityEngine.UI.Text component: {timeText != null}");
if (timeText != null) Jotunn.Logger.LogInfo($"Text value: '{timeText.text}'");
var tmpComp = timeT.GetComponent("TMPro.TMP_Text");
Jotunn.Logger.LogInfo($"TMPro.TMP_Text component: {tmpComp != null}");
if (tmpComp != null) {
var prop = tmpComp.GetType().GetProperty("text");
if (prop != null) {
Jotunn.Logger.LogInfo($"TMP value: '{prop.GetValue(tmpComp, null)}'");
}
}
}
}
else
{
Jotunn.Logger.LogInfo("TrolExtraFoodSlot NOT FOUND! (Did Awake_Postfix run?)");
}
}
if (TrolFoodManager.ExtraFoods.TryGetValue(__instance, out Player.Food extraFood) && extraFood != null)
{
Jotunn.Logger.LogInfo($"ExtraFoods Dictionary:");
Jotunn.Logger.LogInfo($" Name: {extraFood.m_item?.m_shared?.m_name}");
Jotunn.Logger.LogInfo($" Time: {extraFood.m_time} / {extraFood.m_item?.m_shared?.m_foodBurnTime}");
}
Jotunn.Logger.LogInfo("=============================");
}
}
}
}