using TMPro; using UnityEngine; using UnityEngine.UI; namespace BrewMonster.Scripts.Managers { /// Shared stack count label lookup for inventory / storage slot buttons. public static class EC_SlotStackCountDisplay { public static int ResolveStackCount(EC_IvtrItem item) { if (item == null) return 0; int n = item.GetCount(); if (n < 2 && item.m_iCount >= 2) n = item.m_iCount; return n; } public static void UpdateButton(Button button, EC_IvtrItem item) { UpdateButton(button, ResolveStackCount(item)); } public static void UpdateButton(Button button, int count) { if (button == null) return; TMPro.TextMeshProUGUI tmpText = null; Text legacyText = null; var textTransform = FindStackCountTextTransform(button.transform); if (textTransform != null) { tmpText = textTransform.GetComponent(); legacyText = textTransform.GetComponent(); } if (tmpText == null && legacyText == null) { tmpText = button.GetComponentInChildren(); if (tmpText == null) legacyText = button.GetComponentInChildren(); } if (count > 1) { string countText = count.ToString(); if (tmpText != null) { tmpText.text = countText; tmpText.gameObject.SetActive(true); } else if (legacyText != null) { legacyText.text = countText; legacyText.gameObject.SetActive(true); } } else { if (tmpText != null) { tmpText.text = ""; tmpText.gameObject.SetActive(false); } else if (legacyText != null) { legacyText.text = ""; legacyText.gameObject.SetActive(false); } } } static Transform FindStackCountTextTransform(Transform root) { if (root == null) return null; string[] names = { "Txt_Count", "text_quality", "text_quatity", "text_quantity", "image_amount" }; for (int n = 0; n < names.Length; n++) { var t = root.Find(names[n]); if (t != null) return t; } return null; } } }