Update logic to show the split button on item have quantity bigger than 2 or equal 2

This commit is contained in:
HungDK
2026-04-07 09:24:05 +07:00
parent 7fdfffc306
commit bed971ebb4
@@ -211,6 +211,8 @@ namespace BrewMonster.Scripts.Managers
{
if (splitPanelRoot != null)
splitPanelRoot.SetActive(show);
if (IsSplitCloseButtonOnModal() && splitCloseButton != null)
splitCloseButton.gameObject.SetActive(show);
}
/// <summary>
@@ -1197,6 +1199,50 @@ namespace BrewMonster.Scripts.Managers
private void ShowDetailPanel(bool show)
{
EC_UIUtility.ShowPanel(detailPanelRoot.gameObject, show);
if (!show)
RefreshSplitControlsVisibility(0, null);
}
/// <summary>
/// Split affordance only for main bag stacks (same as <see cref="SeparateSelectedStack"/>).
/// If <c>splitCloseButton</c> is parented under <c>splitPanelRoot</c>, its visibility follows the modal (not this rule).
/// </summary>
private bool IsSplitCloseButtonOnModal()
{
return splitPanelRoot != null && splitCloseButton != null &&
splitCloseButton.transform.IsChildOf(splitPanelRoot.transform);
}
private bool CanShowSplitControls(byte package, EC_IvtrItem item)
{
if (item == null)
return false;
if (package != PKG_INVENTORY)
return false;
int n = item.GetCount();
if (n < 2 && item.m_iCount >= 2)
n = item.m_iCount;
return n >= 2;
}
/// <summary>
/// <c>splitOpenButton</c>: show only when a splittable main-bag stack is selected (detail panel).
/// <c>splitCloseButton</c>: if it lives on the split modal, show only when modal is open; else same as open (detail-placed cancel).
/// </summary>
private void RefreshSplitControlsVisibility(byte package, EC_IvtrItem item)
{
bool canSplit = CanShowSplitControls(package, item);
if (splitOpenButton != null)
splitOpenButton.gameObject.SetActive(canSplit);
if (splitCloseButton != null)
{
if (IsSplitCloseButtonOnModal())
splitCloseButton.gameObject.SetActive(splitPanelRoot != null && splitPanelRoot.activeSelf);
else
splitCloseButton.gameObject.SetActive(canSplit);
}
}
private Button GetButtonForSlot(byte package, int slot)
@@ -1297,6 +1343,8 @@ namespace BrewMonster.Scripts.Managers
// Show panel first
// 先显示面板
ShowDetailPanel(true);
// After detail root is active so child buttons actually appear (fixes split controls under inactive parents).
RefreshSplitControlsVisibility(package, item);
//Refresh the position of the description text. Used for UI logic purpose.
descriptionText.tmp.gameObject.GetComponent<ItemInfoText>()?.RefreshLayout();