Merge branch 'feature/inventories' into develop

This commit is contained in:
HungDK
2025-10-27 15:45:29 +07:00
6 changed files with 118 additions and 20 deletions
@@ -60,6 +60,13 @@ namespace BrewMonster.Scripts.Managers
private float lastRefreshTime;
// Pending currency cache for when UI is not yet active
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;
private InventoryModel model;
private InventoryView view;
@@ -186,8 +193,16 @@ namespace BrewMonster.Scripts.Managers
{
ShowDetailPanel(false);
}
// Apply any pending currency values captured before the UI became active
ApplyPendingCurrency();
}
private void OnEnable()
{
// Ensure cached values are pushed when the UI is enabled
ApplyPendingCurrency();
}
private void Update()
{
if (autoRefresh && Time.time - lastRefreshTime >= refreshInterval)
@@ -259,6 +274,60 @@ namespace BrewMonster.Scripts.Managers
}
}
// Public static entry points to cache values when UI is unavailable
public static void CacheMoney(ulong amount, ulong maxAmount)
{
s_pendingMoneyAmount = amount;
s_pendingMoneyMaxAmount = maxAmount;
s_hasPendingMoney = 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;
}
}
}
}
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)
{
UnityGameSession.RequestCheckSecurityPassWd("");
@@ -144,9 +144,11 @@ namespace BrewMonster.UI
await Task.Delay(2000);
// Request all known packages: 0=Inventory,1=Equipment,2=Task
UnityGameSession.RequestAllInventoriesAsync(() => { /*BMLogger.Log("Sent Inventory Detail Requests (all packs)");*/ }, 0, 1, 2);
await Task.Delay(1000);
UnityGameSession.RequestCheckSecurityPassWd("");
await Task.Delay(10000);
UnityGameSession.RequesrQueryPlayerCash();
await Task.Delay(2000);
await Task.Delay(1000);
UnityGameSession.c2s_CmdGetAllData(true, true, false);
EC_Game.Init();
}
-13
View File
@@ -10033,7 +10033,6 @@ GameObject:
- component: {fileID: 6612065338353497036}
- component: {fileID: 8351850713118243030}
- component: {fileID: 6001081573770107384}
- component: {fileID: 2043904448860146935}
m_Layer: 5
m_Name: InventoryUI
m_TagString: Untagged
@@ -10239,18 +10238,6 @@ MonoBehaviour:
- {fileID: 776624419558043962}
cashTextsLegacy: []
cashTextsTMP: []
--- !u!114 &2043904448860146935
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5910006447059157136}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 24000eb1448ca674888f256f5508cadd, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &5959049729314796227
GameObject:
m_ObjectHideFlags: 0
+2 -2
View File
@@ -5607,7 +5607,7 @@ MonoBehaviour:
shopDetailPanel: {fileID: 3673391532679430468}
itemContainer: {fileID: 720995613977598853}
itemPanelPrefab: {fileID: 2085383389330444610, guid: 438dede7c7090e94384225a82bb31396, type: 3}
itemPanelPool: {fileID: 0}
itemPanelPool: {fileID: 5246174072855755290}
useObjectPooling: 1
categoryButtons:
- {fileID: 8868854500554754372}
@@ -5621,7 +5621,7 @@ MonoBehaviour:
detailItemIcon: {fileID: 8621596851870483689}
detailItemPrice: {fileID: 3507052010254865497}
detailItemQuantity: {fileID: 0}
buyButton: {fileID: 0}
buyButton: {fileID: 780999421718195231}
closeDetailButton: {fileID: 0}
closeShopButton: {fileID: 0}
--- !u!114 &8660700033567669795
+2 -2
View File
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:893ee0e3d76e7cc3849bda644773269b6a3a79ea39ce3d9d1782e530b2819c95
size 33056317
oid sha256:292fc339a785b907a90f53e15f2ebe5c91f1591e016d682d17e976fee348c820
size 33045641
+42 -2
View File
@@ -682,11 +682,31 @@ public class CECHostPlayer : CECPlayer
try
{
var money = GPDataTypeHelper.FromBytes<CSNetwork.GPDataType.cmd_get_own_money>(data);
var ui = GameObject.FindFirstObjectByType<EC_InventoryUI>();
var ui = GameObject.FindFirstObjectByType<BrewMonster.Scripts.Managers.EC_InventoryUI>();
if (ui == null)
{
var all = Resources.FindObjectsOfTypeAll<BrewMonster.Scripts.Managers.EC_InventoryUI>();
if (all != null)
{
for (int i = 0; i < all.Length; i++)
{
var candidate = all[i];
if (candidate != null && candidate.gameObject.scene.IsValid())
{
ui = candidate;
break;
}
}
}
}
if (ui != null)
{
ui.UpdateMoney(money.amount, money.max_amount);
}
else
{
BrewMonster.Scripts.Managers.EC_InventoryUI.CacheMoney(money.amount, money.max_amount);
}
}
catch (Exception ex)
{
@@ -702,11 +722,31 @@ public class CECHostPlayer : CECPlayer
try
{
var cash = GPDataTypeHelper.FromBytes<CSNetwork.GPDataType.player_cash>(data);
var ui = GameObject.FindFirstObjectByType<EC_InventoryUI>();
var ui = GameObject.FindFirstObjectByType<BrewMonster.Scripts.Managers.EC_InventoryUI>();
if (ui == null)
{
var all = Resources.FindObjectsOfTypeAll<BrewMonster.Scripts.Managers.EC_InventoryUI>();
if (all != null)
{
for (int i = 0; i < all.Length; i++)
{
var candidate = all[i];
if (candidate != null && candidate.gameObject.scene.IsValid())
{
ui = candidate;
break;
}
}
}
}
if (ui != null)
{
ui.UpdateCash(cash.cash_amount);
}
else
{
BrewMonster.Scripts.Managers.EC_InventoryUI.CacheCash(cash.cash_amount);
}
}
catch (Exception ex)
{