Add quick sort item feature

This commit is contained in:
HungDK
2026-05-19 11:26:11 +07:00
parent 5376b6ad8c
commit 69575c9489
7 changed files with 357 additions and 8 deletions
@@ -58,6 +58,9 @@ namespace BrewMonster.Scripts.Managers
[Header("Stack combine — merge into another stack (C++ inventory drag-merge, assign in Inspector)")]
[SerializeField] private Button combineStackButton;
[Header("Sort / arrange pack (C++ DlgInventory arrange)")]
[SerializeField] private Button sortInventoryButton;
private int _splitAmount = 1;
private int _splitMaxAmount = 1;
@@ -137,6 +140,7 @@ namespace BrewMonster.Scripts.Managers
WireBagTabButtons();
WireSplitUI();
WireCombineUI();
WireSortInventoryUI();
//if (currentDragImage == null)
//{
@@ -228,6 +232,60 @@ namespace BrewMonster.Scripts.Managers
}
}
private void WireSortInventoryUI()
{
ResolveSortInventoryButton();
if (sortInventoryButton != null)
{
sortInventoryButton.onClick.RemoveAllListeners();
sortInventoryButton.onClick.AddListener(OnSortInventoryClicked);
}
}
private void ResolveSortInventoryButton()
{
if (sortInventoryButton != null)
return;
var buttons = GetComponentsInChildren<Button>(true);
for (int i = 0; i < buttons.Length; i++)
{
var btn = buttons[i];
if (btn == null)
continue;
string n = btn.name.ToLowerInvariant();
if (n.Contains("arrange") || n.Contains("sort") || n == "btn_arrange")
{
sortInventoryButton = btn;
break;
}
}
}
/// <summary>Arrange main inventory (IVTRTYPE_PACK). C++ CDlgInventory::OnCommand_arrange.</summary>
public void OnSortInventoryClicked()
{
if (_bagTab != InventoryBagTab.Item)
{
Debug.LogWarning("[InventoryUI] Sort pack: switch to Item tab first");
return;
}
var host = CECGameRun.Instance?.GetHostPlayer();
if (host == null)
return;
int cool = host.GetCoolTime((int)CoolTimeIndex.GP_CT_MULTI_EXCHANGE_ITEM, out _);
if (cool > 0)
{
EC_Game.GetGameRun()?.AddFixedMessage((int)FixedMsg.FIXMSG_CMD_INCOOLTIME);
return;
}
host.SortPack(InventoryConst.IVTRTYPE_PACK);
RefreshAll();
}
private void ShowSplitPanel(bool show)
{
if (splitPanelRoot != null)