Add ext description text

This commit is contained in:
HungDK
2025-12-08 16:15:01 +07:00
parent 892d0d3aef
commit 6392baf369
7 changed files with 722 additions and 67 deletions
@@ -53,6 +53,12 @@ namespace BrewMonster.Scripts.Managers
private static bool s_hasPendingCash;
private static int s_pendingCashAmount;
// Flags to prevent log spam for extended description warnings
// 防止扩展描述警告日志刷屏的标志
private static bool m_HasLoggedExtDescNull = false;
private static bool m_HasLoggedExtDescNotInit = false;
private static bool m_HasLoggedExtDescError = false;
private InventoryModel model;
private InventoryView view;
@@ -828,16 +834,81 @@ namespace BrewMonster.Scripts.Managers
{
// Fallback to legacy string-table description if centralised pipeline returns empty
string itemDescription = GetItemDescription(item.m_tid);
string itemExtendedDesc = GetItemExtendedDescription(item.m_tid);
descriptionText?.Set(itemDescription ?? "No description available");
extendedDescText?.Set(itemExtendedDesc ?? "");
}
// Get extended description exactly like C++ code: g_pGame->GetItemExtDesc(m_tid)
// C++ code doesn't check IsInitialized() - it just calls GetWideString() directly
// 完全按照C++代码获取扩展描述:g_pGame->GetItemExtDesc(m_tid)
// C++代码不检查IsInitialized() - 它直接调用GetWideString()
string szExtDesc = null;
try
{
var itemExtDescTab = EC_Game.GetItemExtDesc();
if (itemExtDescTab != null)
{
// First try to get mapped message ID (like TryGetItemExtDesc does)
// 首先尝试获取映射的消息ID(如TryGetItemExtDesc所做)
if (EC_Game.TryGetItemMsg(item.m_tid, out int messageId, out int displayMode))
{
szExtDesc = itemExtDescTab.GetWideString(messageId);
}
// Fallback: direct lookup using tid (exactly like C++: m_ItemExtDesc.GetWideString(tid))
// 回退:直接使用tid查找(完全像C++m_ItemExtDesc.GetWideString(tid)
if (string.IsNullOrEmpty(szExtDesc))
{
szExtDesc = itemExtDescTab.GetWideString(item.m_tid);
}
}
}
catch (System.Exception ex)
{
// Only log once to avoid spam
// 仅记录一次以避免垃圾日志
if (!m_HasLoggedExtDescError)
{
Debug.LogWarning($"[InventoryUI] Error getting extended description: {ex.Message}");
m_HasLoggedExtDescError = true;
}
}
// Display extended description if found (exactly like C++ checks: if (!szExtDesc || !szExtDesc[0]))
// 如果找到扩展描述则显示(完全像C++检查:if (!szExtDesc || !szExtDesc[0])
string displayText = !string.IsNullOrEmpty(szExtDesc)
? szExtDesc.Replace("\\r", "\n")
: "";
// Debug logging to diagnose issues
// 调试日志以诊断问题
if (string.IsNullOrEmpty(displayText))
{
Debug.Log($"[InventoryUI] Extended description is empty for tid={item.m_tid}. szExtDesc was null/empty.");
}
else
{
Debug.Log($"[InventoryUI] Found extended description for tid={item.m_tid}, length={displayText.Length}");
}
// Setup equip and drop buttons
SetupEquipButton(package, item);
SetupDropButton(package, item);
// Show panel first
// 先显示面板
ShowDetailPanel(true);
// Set text directly - if this causes rebuild issues, we'll use coroutine
// 直接设置文本 - 如果这导致重建问题,我们将使用协程
if (extendedDescText != null)
{
extendedDescText.Set(displayText);
Debug.Log($"[InventoryUI] Set extended description text, extendedDescText is {(extendedDescText == null ? "null" : "not null")}");
}
else
{
Debug.LogWarning("[InventoryUI] extendedDescText is null! Check Inspector assignment.");
}
}
private void SetupEquipButton(byte package, EC_IvtrItem item)