Update shop and inventory

This commit is contained in:
HungDK
2026-03-24 15:17:29 +07:00
parent 5f97ad0bc8
commit 2ef8ec179a
7 changed files with 355 additions and 362 deletions
@@ -43,9 +43,11 @@ namespace BrewMonster.Scripts.Managers
[SerializeField] private List<UnityEngine.UI.Text> moneyTextsLegacy = new List<UnityEngine.UI.Text>();
[SerializeField] private List<TMPro.TextMeshProUGUI> moneyTextsTMP = new List<TMPro.TextMeshProUGUI>();
[Header("Cash UI (assign any text fields to mirror cash amount)")]
[SerializeField] private List<UnityEngine.UI.Text> cashTextsLegacy = new List<UnityEngine.UI.Text>();
[SerializeField] private List<TMPro.TextMeshProUGUI> cashTextsTMP = new List<TMPro.TextMeshProUGUI>();
[Header("Character UI (assign in Inspector)")]
[SerializeField] private UnityEngine.UI.Text characterNameTextLegacy;
[SerializeField] private TMPro.TextMeshProUGUI characterNameTextTMP;
[SerializeField] private UnityEngine.UI.Text characterLevelTextLegacy;
[SerializeField] private TMPro.TextMeshProUGUI characterLevelTextTMP;
private float lastRefreshTime;
@@ -53,8 +55,6 @@ namespace BrewMonster.Scripts.Managers
private static bool s_hasPendingMoney;
private static ulong s_pendingMoneyAmount;
private static ulong s_pendingMoneyMaxAmount;
private static bool s_hasPendingCash;
private static int s_pendingCashAmount;
// Flags to prevent log spam for extended description warnings
// 防止扩展描述警告日志刷屏的标志
@@ -128,6 +128,7 @@ namespace BrewMonster.Scripts.Managers
{
// Ensure cached values are pushed when the UI is enabled
ApplyPendingCurrency();
UpdateCharacterInfo();
ShowDetailPanel(false);
}
@@ -207,6 +208,7 @@ namespace BrewMonster.Scripts.Managers
view.RenderPackage(inventoryPackButtons, invItems, PKG_INVENTORY, OnInventoryButtonClicked, GetDisplayTextForItem);
view.RenderPackage(equipmentPackButtons, eqpItems, PKG_EQUIPMENT, OnInventoryButtonClicked, GetDisplayTextForItem);
view.RenderPackage(fashionPackButtons, fshItems, PKG_FASHION, OnInventoryButtonClicked, GetDisplayTextForItem);
UpdateCharacterInfo();
}
/// <summary>
@@ -238,31 +240,26 @@ namespace BrewMonster.Scripts.Managers
}
}
/// <summary>
/// Update all configured cash text components with the current boutique cash amount.
/// Call this when PLAYER_CASH arrives.
/// </summary>
public void UpdateCash(int amount)
private void UpdateCharacterInfo()
{
s_pendingCashAmount = amount;
s_hasPendingCash = true;
string text = amount.ToString();
if (cashTextsLegacy != null)
var host = CECGameRun.Instance?.GetHostPlayer();
string characterName = string.Empty;
string characterLevel = string.Empty;
if (host != null)
{
for (int i = 0; i < cashTextsLegacy.Count; i++)
{
var t = cashTextsLegacy[i];
if (t != null) t.text = text;
}
}
if (cashTextsTMP != null)
{
for (int i = 0; i < cashTextsTMP.Count; i++)
{
var t = cashTextsTMP[i];
if (t != null) t.text = text;
}
characterName = host.GetName() ?? string.Empty;
characterLevel = host.GetBasicProps().iLevel.ToString();
}
if (characterNameTextLegacy != null)
characterNameTextLegacy.text = characterName;
if (characterNameTextTMP != null)
characterNameTextTMP.text = characterName;
if (characterLevelTextLegacy != null)
characterLevelTextLegacy.text = characterLevel;
if (characterLevelTextTMP != null)
characterLevelTextTMP.text = characterLevel;
}
// Public static entry points to cache values when UI is unavailable
@@ -287,36 +284,12 @@ namespace BrewMonster.Scripts.Managers
}
}
public static void CacheCash(int amount)
{
s_pendingCashAmount = amount;
s_hasPendingCash = true;
// If an instance exists (even inactive), push immediately so the value is ready
var all = Resources.FindObjectsOfTypeAll<EC_InventoryUI>();
if (all != null)
{
for (int i = 0; i < all.Length; i++)
{
var ui = all[i];
if (ui != null && ui.gameObject.scene.IsValid())
{
ui.ApplyPendingCurrency();
break;
}
}
}
}
private void ApplyPendingCurrency()
{
if (s_hasPendingMoney)
{
UpdateMoney(s_pendingMoneyAmount, s_pendingMoneyMaxAmount);
}
if (s_hasPendingCash)
{
UpdateCash(s_pendingCashAmount);
}
}
private void OnInventoryButtonClicked(byte package, int slot)