Add Drop item cmd, default drop with quantity is 1

This commit is contained in:
HungDK
2025-10-02 14:16:00 +07:00
parent 21a31f4746
commit f72c3287cd
2 changed files with 100 additions and 1 deletions
@@ -29,6 +29,7 @@ namespace PerfectWorld.Scripts.Managers
[SerializeField] private TextOutlet crcText;
[SerializeField] private TextOutlet contentLenText;
[SerializeField] private Button equipButton;
[SerializeField] private Button dropButton;
[Header("Inventory Settings")]
[SerializeField] private bool autoRefresh = true;
@@ -151,6 +152,30 @@ namespace PerfectWorld.Scripts.Managers
}
}
public void OnDropButtonClicked()
{
if (currentSelectedItem == null)
{
Debug.LogWarning("[InventoryUI] No item selected for drop operation");
return;
}
if (currentSelectedPackage == PKG_INVENTORY)
{
// Dropping from inventory
DropInventoryItem();
}
else if (currentSelectedPackage == PKG_EQUIPMENT)
{
// Dropping from equipment
DropEquipItem();
}
else
{
Debug.LogWarning($"[InventoryUI] Drop not supported for package {currentSelectedPackage}");
}
}
private void EquipItem()
{
if (currentSelectedItem == null) return;
@@ -198,6 +223,30 @@ namespace PerfectWorld.Scripts.Managers
});
}
private void DropInventoryItem()
{
if (currentSelectedItem == null) return;
// Call RequestDropIvrtItem with slot index and amount
UnityGameSession.RequestDropIvrtItem((byte)currentSelectedSlot, 1);
Debug.Log($"[InventoryUI] Drop request sent for inventory item {currentSelectedItem.TemplateId} from slot {currentSelectedSlot} with amount {currentSelectedItem.Count}");
// Refresh inventory after drop
RefreshAll();
}
private void DropEquipItem()
{
if (currentSelectedItem == null) return;
// Call RequestDropEquipItem with slot index
UnityGameSession.RequestDropEquipItem((byte)currentSelectedSlot);
Debug.Log($"[InventoryUI] Drop request sent for equipment item {currentSelectedItem.TemplateId} from slot {currentSelectedSlot}");
// Refresh inventory after drop
RefreshAll();
}
private int FindEmptyInventorySlot()
{
@@ -351,8 +400,9 @@ namespace PerfectWorld.Scripts.Managers
crcText?.Set(item.Crc.ToString());
contentLenText?.Set((item.Content?.Length ?? 0).ToString());
// Setup equip button
// Setup equip and drop buttons
SetupEquipButton(package, item);
SetupDropButton(package, item);
ShowDetailPanel(true);
}
@@ -407,6 +457,46 @@ namespace PerfectWorld.Scripts.Managers
}
}
private void SetupDropButton(byte package, InventoryItemData 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);
}
}
}
private static string GetPackageName(byte pkg)
{
switch (pkg)
@@ -10,6 +10,7 @@ using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;
namespace BrewMonster.Network
@@ -138,7 +139,15 @@ namespace BrewMonster.Network
{
Instance._gameSession.RequestEquipItem(iIvtrIdx, iEquipIdx, callback);
}
public static void RequestDropIvrtItem(byte index, int amount)
{
Instance._gameSession.RequestDropIvtrItem(index, amount);
}
public static void RequestDropEquipItem(byte index)
{
Instance._gameSession.RequestDropEquipItem(index);
}
public static void RequestAllInventoriesAsync(Action callback = null, params byte[] packages)
{
if (packages == null || packages.Length == 0)