Update EC_InventoryUI.cs

This commit is contained in:
HungDK
2025-12-08 10:12:35 +07:00
parent 66dc12ef4a
commit 421bcfd6a6
@@ -28,23 +28,6 @@ namespace BrewMonster.Scripts.Managers
[SerializeField] private TextOutlet nameText;
[SerializeField] private TextOutlet descriptionText;
[SerializeField] private TextOutlet extendedDescText;
[SerializeField] private TextOutlet countText;
[SerializeField] private TextOutlet stateText;
[SerializeField] private TextOutlet expireText;
[SerializeField] private Button equipButton;
[SerializeField] private Button dropButton;
[Header("Equipment Details (assign in Inspector)")]
[SerializeField] private TextOutlet levelReqText;
[SerializeField] private TextOutlet statsReqText;
[SerializeField] private TextOutlet enduranceText;
[SerializeField] private TextOutlet repairCostText;
[SerializeField] private TextOutlet propertiesText;
[SerializeField] private TextOutlet refineText;
[SerializeField] private TextOutlet makerText;
[SerializeField] private TextOutlet priceText;
[SerializeField] private TextOutlet holesText;
[SerializeField] private TextOutlet suiteText;
[Header("Inventory Settings")]
[SerializeField] private bool autoRefresh = true;
@@ -807,359 +790,40 @@ namespace BrewMonster.Scripts.Managers
return;
}
// Get user-friendly text from string tables
// Get user-friendly name
string itemName = EC_IvtrItemUtils.Instance.ResolveItemName(item.m_tid);
string itemDescription = GetItemDescription(item.m_tid);
string itemExtendedDesc = GetItemExtendedDescription(item.m_tid);
// Display basic content
nameText?.Set(string.IsNullOrEmpty(itemName) ? $"Item {item.m_tid}" : itemName);
descriptionText?.Set(itemDescription ?? "No description available");
extendedDescText?.Set(itemExtendedDesc ?? "");
countText?.Set($"Count: {item.m_iCount}");
// Format state properly
string stateTextValue = GetItemStateText(item.State);
stateText?.Set(stateTextValue);
// Format expiration date properly
if (item.m_expire_date > 0)
{
DateTime expireDate = DateTimeOffset.FromUnixTimeSeconds(item.m_expire_date).DateTime;
expireText?.Set($"Expires: {expireDate:yyyy-MM-dd HH:mm}");
}
else
{
expireText?.Set("No expiration");
}
// Display equipment-specific information
// Centralised description:
// - For equipment, prefer EC_IvtrEquip description (includes stats, addons, sockets, etc.)
// - For other items, use EC_IvtrItem.GetDesc which reads from string tables.
string fullDesc = null;
if (showEquipmentDetails && currentSelectedEquipment != null)
{
FillEquipmentDetails();
fullDesc = currentSelectedEquipment.GetNormalDesc();
}
else
{
ClearEquipmentDetails();
fullDesc = item.GetDesc();
}
// Setup equip and drop buttons
SetupEquipButton(package, item);
SetupDropButton(package, item);
if (!string.IsNullOrEmpty(fullDesc))
{
// Replace C++ style "\r" line separators with real newlines for TMP
fullDesc = fullDesc.Replace("\\r", "\n");
descriptionText?.Set(fullDesc);
}
else
{
// 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 ?? "");
}
ShowDetailPanel(true);
}
/// <summary>
/// Fill equipment-specific details
/// </summary>
private void FillEquipmentDetails()
{
if (currentSelectedEquipment == null)
{
ClearEquipmentDetails();
return;
}
// Level Requirements
if (levelReqText != null)
{
string levelReq = "";
if (currentSelectedEquipment.LevelReq > 0)
{
levelReq = $"Level: {currentSelectedEquipment.LevelReq}";
}
if (currentSelectedEquipment.ProfReq > 0)
{
if (!string.IsNullOrEmpty(levelReq)) levelReq += "\\r";
levelReq += $"Profession: {currentSelectedEquipment.ProfReq}";
}
levelReqText.Set(levelReq);
}
// Stats Requirements
if (statsReqText != null)
{
List<string> reqs = new List<string>();
if (currentSelectedEquipment.StrengthReq > 0) reqs.Add($"Str: {currentSelectedEquipment.StrengthReq}");
if (currentSelectedEquipment.AgilityReq > 0) reqs.Add($"Agi: {currentSelectedEquipment.AgilityReq}");
if (currentSelectedEquipment.VitalityReq > 0) reqs.Add($"Vit: {currentSelectedEquipment.VitalityReq}");
if (currentSelectedEquipment.EnergyReq > 0) reqs.Add($"Ene: {currentSelectedEquipment.EnergyReq}");
if (currentSelectedEquipment.ReputationReq > 0) reqs.Add($"Rep: {currentSelectedEquipment.ReputationReq}");
statsReqText.Set(string.Join("\\r", reqs));
}
// Endurance
if (enduranceText != null)
{
if (currentSelectedEquipment.MaxEndurance > 0)
{
int curEndurance = EC_IvtrEquip.VisualizeEndurance(currentSelectedEquipment.CurEndurance);
int maxEndurance = EC_IvtrEquip.VisualizeEndurance(currentSelectedEquipment.MaxEndurance);
string endurance = $"Endurance: {curEndurance}/{maxEndurance}";
if (currentSelectedEquipment.IsDestroying())
{
endurance += " (DESTROYED)";
}
else if (currentSelectedEquipment.CurEndurance < currentSelectedEquipment.MaxEndurance)
{
endurance += " (Damaged)";
}
enduranceText.Set(endurance);
}
else
{
enduranceText.Set("Endurance: N/A");
}
}
// Repair Cost
if (repairCostText != null)
{
if (currentSelectedEquipment.IsRepairable())
{
int repairCost = currentSelectedEquipment.GetRepairCost();
repairCostText.Set($"Repair Cost: {repairCost}");
}
else
{
repairCostText.Set("Repair Cost: N/A");
}
}
// Properties + Base Stats + Engraved + Stones (more closely matching original)
if (propertiesText != null)
{
List<string> lines = new List<string>();
// Base stats decoded from element essence (damage/defense/speed/range/resists)
string baseStats = currentSelectedEquipment.GetBaseStatsForDisplay();
if (!string.IsNullOrEmpty(baseStats))
{
lines.Add(baseStats);
}
// Add-on properties from detail payload (non-embedded, non-suite, non-engraved)
if (currentSelectedEquipment.Props.Count > 0)
{
foreach (var prop in currentSelectedEquipment.Props)
{
if (!prop.Embed && !prop.Suite && !prop.Engraved)
{
string propDesc = currentSelectedEquipment.FormatPropDesc(prop);
if (!string.IsNullOrEmpty(propDesc))
{
lines.Add(propDesc);
}
}
}
// Engraved properties (displayed after normal add-ons)
foreach (var prop in currentSelectedEquipment.Props)
{
if (prop.Engraved)
{
string propDesc = currentSelectedEquipment.FormatPropDesc(prop);
if (!string.IsNullOrEmpty(propDesc))
{
lines.Add(propDesc);
}
}
}
}
// Socketed stones (show name and a basic description)
if (currentSelectedEquipment.Holes != null && currentSelectedEquipment.Holes.Count > 0)
{
foreach (int holeTid in currentSelectedEquipment.Holes)
{
if (holeTid == 0) continue;
string stoneName = EC_IvtrItemUtils.Instance.ResolveItemName(holeTid);
// Try to fetch a description from string tables; fallback to name if unavailable
string stoneDesc = GetItemDescription(holeTid) ?? stoneName;
if (!string.IsNullOrEmpty(stoneName))
{
lines.Add($"{stoneName}: {stoneDesc}");
}
}
}
string combined = string.Join("\\r", lines);
propertiesText.Set(combined);
}
// Refinement
if (refineText != null)
{
if (currentSelectedEquipment.RefineLvl > 0)
{
refineText.Set($"Refinement Level: +{currentSelectedEquipment.RefineLvl}");
}
else
{
refineText.Set("Refinement: None");
}
}
// Maker Information
if (makerText != null)
{
if (!string.IsNullOrEmpty(currentSelectedEquipment.Maker))
{
makerText.Set($"Maker: {currentSelectedEquipment.Maker}");
}
else
{
makerText.Set("Maker: Unknown");
}
}
// Price
if (priceText != null)
{
int scaledPrice = currentSelectedEquipment.GetScaledPrice();
priceText.Set($"Price: {scaledPrice}");
}
// Holes
if (holesText != null)
{
if (currentSelectedEquipment.Holes.Count > 0)
{
int emptyHoles = currentSelectedEquipment.GetEmptyHoleNum();
int totalHoles = currentSelectedEquipment.Holes.Count;
holesText.Set($"Holes: {totalHoles - emptyHoles}/{totalHoles} filled");
}
else
{
holesText.Set("Holes: None");
}
}
// Suite Information
if (suiteText != null)
{
int suiteId = currentSelectedEquipment.GetSuiteID();
if (suiteId > 0)
{
suiteText.Set($"Suite Equipment: {suiteId}");
}
else
{
suiteText.Set("Suite: None");
}
}
}
/// <summary>
/// Clear equipment details
/// </summary>
private void ClearEquipmentDetails()
{
levelReqText?.Set("");
statsReqText?.Set("");
enduranceText?.Set("");
repairCostText?.Set("");
propertiesText?.Set("");
refineText?.Set("");
makerText?.Set("");
priceText?.Set("");
holesText?.Set("");
suiteText?.Set("");
}
private void SetupEquipButton(byte package, EC_IvtrItem item)
{
if (equipButton == null) return;
// Clear previous listeners
equipButton.onClick.RemoveAllListeners();
equipButton.onClick.AddListener(OnEquipButtonClicked);
// Set button text and visibility based on package
var buttonText = equipButton.GetComponentInChildren<UnityEngine.UI.Text>();
if (buttonText == null)
{
var tmpText = equipButton.GetComponentInChildren<TMPro.TextMeshProUGUI>();
if (tmpText != null)
{
if (package == PKG_INVENTORY)
{
tmpText.text = "Equip";
equipButton.gameObject.SetActive(true);
}
else if (package == PKG_EQUIPMENT)
{
tmpText.text = "UnEquip";
equipButton.gameObject.SetActive(true);
}
else
{
equipButton.gameObject.SetActive(false);
}
}
}
else
{
if (package == PKG_INVENTORY)
{
buttonText.text = "Equip";
equipButton.gameObject.SetActive(true);
}
else if (package == PKG_EQUIPMENT)
{
buttonText.text = "UnEquip";
equipButton.gameObject.SetActive(true);
}
else
{
equipButton.gameObject.SetActive(false);
}
}
}
private void SetupDropButton(byte package, EC_IvtrItem item)
{
if (dropButton == null) return;
// Clear previous listeners
dropButton.onClick.RemoveAllListeners();
dropButton.onClick.AddListener(OnDropButtonClicked);
// Set button text and visibility based on package
var buttonText = dropButton.GetComponentInChildren<UnityEngine.UI.Text>();
if (buttonText == null)
{
var tmpText = dropButton.GetComponentInChildren<TMPro.TextMeshProUGUI>();
if (tmpText != null)
{
if (package == PKG_INVENTORY || package == PKG_EQUIPMENT)
{
tmpText.text = "Drop";
dropButton.gameObject.SetActive(true);
}
else
{
dropButton.gameObject.SetActive(false);
}
}
}
else
{
if (package == PKG_INVENTORY || package == PKG_EQUIPMENT)
{
buttonText.text = "Drop";
dropButton.gameObject.SetActive(true);
}
else
{
dropButton.gameObject.SetActive(false);
}
}
}
}