use item but cooldown don't active
This commit is contained in:
@@ -134,6 +134,71 @@ namespace BrewMonster.Scripts.Managers
|
||||
{
|
||||
RefreshAll();
|
||||
}
|
||||
|
||||
UpdateCooldownOverlays();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update all cooldown overlays
|
||||
/// 更新所有冷却遮罩
|
||||
/// </summary>
|
||||
public void UpdateCooldownOverlays()
|
||||
{
|
||||
// Update inventory pack cooldowns
|
||||
// 更新背包冷却
|
||||
UpdatePackageCooldowns(inventoryPackButtons, PKG_INVENTORY);
|
||||
|
||||
// Equipment pack doesn't typically have cooldowns but update anyway
|
||||
// 装备栏通常没有冷却但也更新
|
||||
UpdatePackageCooldowns(equipmentPackButtons, PKG_EQUIPMENT);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update cooldown overlays for a specific package
|
||||
/// 更新特定包裹的冷却遮罩
|
||||
/// </summary>
|
||||
private void UpdatePackageCooldowns(List<Button> buttons, byte package)
|
||||
{
|
||||
if (buttons == null)
|
||||
{
|
||||
Debug.LogWarning($"[UpdatePackageCooldowns] Buttons list is null for package {package}");
|
||||
return;
|
||||
}
|
||||
|
||||
var items = model.GetInventoryData(package);
|
||||
if (items == null)
|
||||
{
|
||||
Debug.LogWarning($"[UpdatePackageCooldowns] Items dictionary is null for package {package}");
|
||||
return;
|
||||
}
|
||||
|
||||
Debug.Log($"[UpdatePackageCooldowns] Updating package {package} with {buttons.Count} buttons and {items.Count} items");
|
||||
|
||||
for (int slot = 0; slot < buttons.Count; slot++)
|
||||
{
|
||||
var button = buttons[slot];
|
||||
if (button == null)
|
||||
continue;
|
||||
|
||||
// Get item at this slot
|
||||
// 获取此槽位的物品
|
||||
EC_IvtrItem itemData = null;
|
||||
bool hasItem = items.TryGetValue(slot, out itemData) && itemData != null;
|
||||
|
||||
if (hasItem)
|
||||
{
|
||||
Debug.Log($"[UpdatePackageCooldowns] Package {package}, Slot {slot}: Found item {itemData.m_tid}");
|
||||
// Use InventoryView's method to update cooldown
|
||||
// 使用 InventoryView 的方法更新冷却
|
||||
view.UpdateCooldownOverlay(button, itemData);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Hide overlay for empty slots
|
||||
// 空槽位隐藏遮罩
|
||||
view.HideCooldownOverlay(button);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void RefreshAll()
|
||||
@@ -335,14 +400,23 @@ namespace BrewMonster.Scripts.Managers
|
||||
{
|
||||
if (currentSelectedItem == null)
|
||||
{
|
||||
Debug.LogWarning("[InventoryUI] No item selected for equip/unequip operation");
|
||||
Debug.LogWarning("[InventoryUI] No item selected for operation");
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentSelectedPackage == PKG_INVENTORY)
|
||||
{
|
||||
// Equipping from inventory
|
||||
EquipItem();
|
||||
// Check if item is equipment
|
||||
if (currentSelectedItem.IsEquipment())
|
||||
{
|
||||
// Equipping from inventory
|
||||
EquipItem();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Use item from inventory
|
||||
UseItem();
|
||||
}
|
||||
}
|
||||
else if (currentSelectedPackage == PKG_EQUIPMENT)
|
||||
{
|
||||
@@ -351,7 +425,56 @@ namespace BrewMonster.Scripts.Managers
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning($"[InventoryUI] Equip/Unequip not supported for package {currentSelectedPackage}");
|
||||
Debug.LogWarning($"[InventoryUI] Operation not supported for package {currentSelectedPackage}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use the currently selected item from inventory
|
||||
/// </summary>
|
||||
private void UseItem()
|
||||
{
|
||||
if (currentSelectedItem == null)
|
||||
{
|
||||
Debug.LogWarning("[InventoryUI] No item selected for use");
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentSelectedPackage != PKG_INVENTORY)
|
||||
{
|
||||
Debug.LogWarning("[InventoryUI] Can only use items from inventory package");
|
||||
return;
|
||||
}
|
||||
|
||||
Debug.Log($"[UseItem] Attempting to use item {currentSelectedItem.m_tid} from slot {currentSelectedSlot}");
|
||||
|
||||
// Get host player to call UseItemInPack
|
||||
var host = CECGameRun.Instance?.GetHostPlayer();
|
||||
if (host == null)
|
||||
{
|
||||
Debug.LogError("[InventoryUI] Cannot get host player");
|
||||
return;
|
||||
}
|
||||
|
||||
// Call UseItemInPack with current package and slot
|
||||
bool success = host.UseItemInPack(currentSelectedPackage, currentSelectedSlot, true);
|
||||
|
||||
if (success)
|
||||
{
|
||||
Debug.Log($"[UseItem] Successfully used item {currentSelectedItem.m_tid} from slot {currentSelectedSlot}");
|
||||
|
||||
// Close detail panel after using item
|
||||
ShowDetailPanel(false);
|
||||
|
||||
// Refresh inventory to reflect changes
|
||||
RefreshAll();
|
||||
|
||||
Debug.Log($"[UseItem] Calling UpdateCooldownOverlays after item use");
|
||||
UpdateCooldownOverlays();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning($"[UseItem] Failed to use item {currentSelectedItem.m_tid} from slot {currentSelectedSlot}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -598,6 +721,8 @@ namespace BrewMonster.Scripts.Managers
|
||||
{
|
||||
private static readonly Dictionary<Image, Sprite> _defaultSprites = new Dictionary<Image, Sprite>();
|
||||
|
||||
private static readonly Dictionary<Button, Image> _overlayImages = new Dictionary<Button, Image>();
|
||||
|
||||
public void RenderPackage(List<Button> buttons, Dictionary<int, EC_IvtrItem> items, byte package, System.Action<byte, int> onClick, System.Func<int, EC_IvtrItem, string> getDisplayText)
|
||||
{
|
||||
if (buttons == null)
|
||||
@@ -615,34 +740,41 @@ namespace BrewMonster.Scripts.Managers
|
||||
|
||||
EC_IvtrItem itemData = null;
|
||||
bool hasItem = items != null && items.TryGetValue(slot, out itemData);
|
||||
|
||||
button.onClick.RemoveAllListeners();
|
||||
int capturedSlot = slot;
|
||||
button.onClick.AddListener(() => onClick(package, capturedSlot));
|
||||
// Optional visual tweaks based on state/count
|
||||
|
||||
// Update icon and count
|
||||
var image = button.GetComponent<Image>();
|
||||
if (image != null)
|
||||
{
|
||||
// Store the default sprite if we haven't seen this image before
|
||||
// Store default sprite
|
||||
if (!_defaultSprites.ContainsKey(image))
|
||||
{
|
||||
_defaultSprites[image] = image.sprite;
|
||||
}
|
||||
|
||||
// Set icon sprite based on item TemplateId
|
||||
// Set icon sprite based on item
|
||||
if (hasItem && itemData != null && itemData.m_iCount > 0)
|
||||
{
|
||||
var sprite = EC_IvtrItemUtils.Instance.ResolveItemIconSprite(itemData.m_tid);
|
||||
image.sprite = sprite;
|
||||
image.enabled = true;
|
||||
|
||||
UpdateItemCountText(button, itemData.m_iCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Restore the default sprite instead of setting to null
|
||||
// Restore default sprite
|
||||
image.sprite = _defaultSprites[image];
|
||||
image.enabled = true;
|
||||
|
||||
UpdateItemCountText(button, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// Setup drag-drop events
|
||||
var eventTrigger = button.GetComponent<EventTrigger>();
|
||||
if (eventTrigger == null)
|
||||
eventTrigger = button.gameObject.AddComponent<EventTrigger>();
|
||||
@@ -662,6 +794,175 @@ namespace BrewMonster.Scripts.Managers
|
||||
AddEvent(EventTriggerType.Drop, (data) => ((EC_InventoryUI)button.GetComponentInParent<EC_InventoryUI>()).OnDrop((PointerEventData)data));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update cooldown overlay for item
|
||||
/// 更新物品冷却遮罩
|
||||
/// </summary>
|
||||
public void UpdateCooldownOverlay(Button button, EC_IvtrItem itemData)
|
||||
{
|
||||
if (button == null || itemData == null)
|
||||
{
|
||||
Debug.LogWarning("[UpdateCooldownOverlay] Button or itemData is null");
|
||||
return;
|
||||
}
|
||||
|
||||
Debug.Log($"[UpdateCooldownOverlay] Checking item {itemData.m_tid} in button {button.name}");
|
||||
|
||||
// Find or cache overlay image
|
||||
// 查找或缓存遮罩图片
|
||||
Image overlay = null;
|
||||
if (_overlayImages.TryGetValue(button, out overlay))
|
||||
{
|
||||
if (overlay == null)
|
||||
{
|
||||
// Cached but destroyed, remove and search again
|
||||
// 已缓存但被销毁,移除并重新查找
|
||||
Debug.LogWarning($"[UpdateCooldownOverlay] Cached overlay was destroyed for button {button.name}");
|
||||
_overlayImages.Remove(button);
|
||||
}
|
||||
}
|
||||
|
||||
if (overlay == null)
|
||||
{
|
||||
// Find image_overlay in button's children
|
||||
// 在按钮子物体中查找 image_overlay
|
||||
var overlayTransform = button.transform.Find("image_overlay");
|
||||
if (overlayTransform != null)
|
||||
{
|
||||
overlay = overlayTransform.GetComponent<Image>();
|
||||
if (overlay != null)
|
||||
{
|
||||
Debug.Log($"[UpdateCooldownOverlay] Found image_overlay for button {button.name}");
|
||||
_overlayImages[button] = overlay;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning($"[UpdateCooldownOverlay] Found transform but no Image component on image_overlay for button {button.name}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning($"[UpdateCooldownOverlay] Cannot find image_overlay child in button {button.name}");
|
||||
}
|
||||
}
|
||||
|
||||
if (overlay == null)
|
||||
{
|
||||
Debug.LogWarning($"[UpdateCooldownOverlay] Overlay is null after search for button {button.name}");
|
||||
return;
|
||||
}
|
||||
|
||||
// Get cooldown info from item
|
||||
// 从物品获取冷却信息
|
||||
int? maxCooldown = null;
|
||||
int currentCooldown = itemData.GetCoolTime(out maxCooldown);
|
||||
|
||||
Debug.Log($"[UpdateCooldownOverlay] Item {itemData.m_tid}: currentCooldown={currentCooldown}, maxCooldown={maxCooldown}");
|
||||
|
||||
if (currentCooldown > 0 && maxCooldown > 0)
|
||||
{
|
||||
// Show overlay and set fill amount
|
||||
// 显示遮罩并设置填充量
|
||||
overlay.gameObject.SetActive(true);
|
||||
|
||||
// Calculate fill amount (1 = full cooldown, 0 = ready)
|
||||
// 计算填充量(1=完全冷却,0=就绪)
|
||||
float fillAmount = (float)currentCooldown / maxCooldown.Value;
|
||||
overlay.fillAmount = fillAmount;
|
||||
|
||||
// Set semi-transparent black color like original code
|
||||
// 设置半透明黑色,与原始代码相同
|
||||
overlay.color = new Color(0, 0, 0, 0.5f); // A3DCOLORRGBA(0, 0, 0, 128)
|
||||
|
||||
Debug.Log($"[UpdateCooldownOverlay] Showing overlay for item {itemData.m_tid} with fillAmount={fillAmount}, overlay active={overlay.gameObject.activeSelf}");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Hide overlay when not in cooldown
|
||||
// 不在冷却时隐藏遮罩
|
||||
overlay.gameObject.SetActive(false);
|
||||
Debug.Log($"[UpdateCooldownOverlay] Hiding overlay for item {itemData.m_tid} (no cooldown)");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hide cooldown overlay
|
||||
/// 隐藏冷却遮罩
|
||||
/// </summary>
|
||||
public void HideCooldownOverlay(Button button)
|
||||
{
|
||||
if (button == null)
|
||||
return;
|
||||
|
||||
Image overlay = null;
|
||||
if (_overlayImages.TryGetValue(button, out overlay) && overlay != null)
|
||||
{
|
||||
overlay.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update or create text component to show item count on the button
|
||||
/// </summary>
|
||||
/// <param name="button">The inventory button</param>
|
||||
/// <param name="count">Item count (0 to hide)</param>
|
||||
private void UpdateItemCountText(Button button, int count)
|
||||
{
|
||||
if (button == null) return;
|
||||
|
||||
TMPro.TextMeshProUGUI tmpText = null;
|
||||
Text legacyText = null;
|
||||
|
||||
// Find text component
|
||||
var textTransform = button.transform.Find("text_quality");
|
||||
|
||||
if (textTransform != null)
|
||||
{
|
||||
tmpText = textTransform.GetComponent<TMPro.TextMeshProUGUI>();
|
||||
legacyText = textTransform.GetComponent<Text>();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Fallback: find any text in children
|
||||
tmpText = button.GetComponentInChildren<TMPro.TextMeshProUGUI>();
|
||||
if (tmpText == null)
|
||||
{
|
||||
legacyText = button.GetComponentInChildren<Text>();
|
||||
}
|
||||
}
|
||||
|
||||
// Update text
|
||||
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
|
||||
{
|
||||
// Hide when count <= 1
|
||||
if (tmpText != null)
|
||||
{
|
||||
tmpText.text = "";
|
||||
tmpText.gameObject.SetActive(false);
|
||||
}
|
||||
else if (legacyText != null)
|
||||
{
|
||||
legacyText.text = "";
|
||||
legacyText.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// === Detail Panel Helpers ===
|
||||
|
||||
Reference in New Issue
Block a user