Initial commit
This commit is contained in:
commit
c4a24c9fdf
142 changed files with 15491 additions and 0 deletions
110
JotunnModStub/Aswid/AswidExtraFoodUI.cs
Normal file
110
JotunnModStub/Aswid/AswidExtraFoodUI.cs
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
[HarmonyPatch]
|
||||
public static class AswidExtraFoodUI
|
||||
{
|
||||
private static GameObject AswidFoodUIBase;
|
||||
private static Image AswidFoodIcon;
|
||||
private static GameObject AswidFoodTimeObj;
|
||||
|
||||
[HarmonyPatch(typeof(Hud), "Awake")]
|
||||
[HarmonyPostfix]
|
||||
public static void Awake_Postfix(Hud __instance)
|
||||
{
|
||||
Transform healthPanel = __instance.transform.Find("hudroot/healthpanel");
|
||||
if (healthPanel == null) return;
|
||||
|
||||
Transform food1 = healthPanel.Find("food1");
|
||||
Transform food2 = healthPanel.Find("food2");
|
||||
|
||||
if (food1 == null || food2 == null) return;
|
||||
|
||||
// Clone food2
|
||||
GameObject food3 = UnityEngine.Object.Instantiate(food2.gameObject, healthPanel);
|
||||
food3.name = "AswidExtraFoodSlot";
|
||||
|
||||
// Calculate vertical offset (distance between slot 1 and 2)
|
||||
float offset = food2.localPosition.y - food1.localPosition.y;
|
||||
food3.transform.localPosition = food2.localPosition + new Vector3(0, offset, 0);
|
||||
|
||||
AswidFoodUIBase = food3;
|
||||
AswidFoodIcon = food3.transform.Find("foodicon2")?.GetComponent<Image>();
|
||||
if (AswidFoodIcon == null) AswidFoodIcon = food3.transform.Find("icon")?.GetComponent<Image>(); // Fallback
|
||||
AswidFoodTimeObj = food3.transform.Find("time")?.gameObject;
|
||||
AswidFoodUIBase.SetActive(false);
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Hud), "UpdateFood")]
|
||||
[HarmonyPostfix]
|
||||
public static void UpdateFood_Postfix(Hud __instance)
|
||||
{
|
||||
if (AswidFoodUIBase == null) return;
|
||||
|
||||
bool show4th = BossProgressionManager.GetCurrentProgressionState() >= 8;
|
||||
|
||||
if (Player.m_localPlayer == null || !AswidRace.IsAswid() || !show4th)
|
||||
{
|
||||
AswidFoodUIBase.SetActive(false);
|
||||
return;
|
||||
}
|
||||
|
||||
AswidFoodUIBase.SetActive(true);
|
||||
UpdateSlotUI(Player.m_localPlayer, AswidFoodManager.ExtraFoods, AswidFoodIcon, AswidFoodTimeObj);
|
||||
}
|
||||
|
||||
private static void UpdateSlotUI(Player player, System.Collections.Generic.Dictionary<Player, Player.Food> dict, Image icon, GameObject timeObj)
|
||||
{
|
||||
if (dict.TryGetValue(player, out Player.Food extraFood) && extraFood != null)
|
||||
{
|
||||
if (icon != null)
|
||||
{
|
||||
icon.sprite = extraFood.m_item.GetIcon();
|
||||
icon.gameObject.SetActive(true);
|
||||
|
||||
bool canEat = extraFood.m_time >= (extraFood.m_item.m_shared.m_foodBurnTime * 0.5f);
|
||||
if (canEat) icon.color = new Color(1f, 1f, 1f, Mathf.Sin(Time.time * 10f) * 0.5f + 0.5f);
|
||||
else icon.color = Color.white;
|
||||
}
|
||||
|
||||
if (timeObj != null)
|
||||
{
|
||||
timeObj.SetActive(true);
|
||||
float remaining = extraFood.m_item.m_shared.m_foodBurnTime - extraFood.m_time;
|
||||
if (remaining < 0) remaining = 0;
|
||||
|
||||
string timeStr = remaining < 60f ? Mathf.CeilToInt(remaining).ToString() + "s" : Mathf.CeilToInt(remaining / 60f).ToString() + "m";
|
||||
bool canEat = extraFood.m_time >= (extraFood.m_item.m_shared.m_foodBurnTime * 0.5f);
|
||||
Color timeCol = canEat ? new Color(1f, 0.5f, 0.5f, Mathf.Sin(Time.time * 10f) * 0.5f + 0.5f) : Color.white;
|
||||
UpdateTextComponent(timeObj, timeStr, timeCol);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (icon != null) icon.gameObject.SetActive(false);
|
||||
if (timeObj != null) timeObj.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
private static void UpdateTextComponent(GameObject obj, string text, Color color)
|
||||
{
|
||||
var unityText = obj.GetComponent<UnityEngine.UI.Text>();
|
||||
if (unityText != null)
|
||||
{
|
||||
unityText.text = text;
|
||||
unityText.color = color;
|
||||
}
|
||||
var tmpText = obj.GetComponent("TMPro.TMP_Text");
|
||||
if (tmpText != null)
|
||||
{
|
||||
var textProp = tmpText.GetType().GetProperty("text");
|
||||
if (textProp != null) textProp.SetValue(tmpText, text, null);
|
||||
var colorProp = tmpText.GetType().GetProperty("color");
|
||||
if (colorProp != null) colorProp.SetValue(tmpText, color, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue