add stack ui logic

This commit is contained in:
NguyenVanDat
2026-03-05 09:48:47 +07:00
parent 46bf9156ae
commit 8cfab19cf6
4 changed files with 141 additions and 8 deletions
@@ -355,5 +355,10 @@ namespace BrewMonster.UI
{
m_bUpdateRenderTarget = false;
}
public virtual void CloseDialogue()
{
CECUIManager.Instance.HideCurrentUIInStack();
}
}
}
@@ -589,7 +589,7 @@ namespace BrewMonster
var host = GetHostPlayer();
host?.EndNPCService();
host?.GetPack(InventoryConst.IVTRTYPE_PACK).UnfreezeAllItems();
gameObject.SetActive(false);
CloseDialogue();
}
@@ -654,5 +654,10 @@ namespace BrewMonster
}
}
}
public void ShowTest(bool isStack)
{
CECUIManager.Instance.ShowUI("Win_Disenchase",isStack);
}
}
}
@@ -3411,8 +3411,9 @@ namespace BrewMonster.UI
{
uint npcID = pCurNPCEssence.Value.id;
var dlgInstall =GetGameUIMan().GetDialog("Win_Enchase");
dlgInstall.Show(true);
// var dlgInstall =GetGameUIMan().GetDialog("Win_Enchase");
// dlgInstall.Show(true);
CECUIManager.Instance.ShowUI("Win_Enchase",true);
}
//pShow1 = m_pAUIManager.GetDialog("Win_Enchase");
//pShow2 = m_pAUIManager.GetDialog("Win_Inventory");
+127 -5
View File
@@ -12,7 +12,10 @@ public class CECUIManager : MonoSingleton<CECUIManager>
[SerializeField] private TMP_Text _fpsText;
[SerializeField] private List<GameObject> uiPrefabs; // drag các prefab UI vào đây
private readonly Dictionary<System.Type, GameObject> _spawnedUIs = new();
private readonly Dictionary<Type, GameObject> _spawnedUIs = new();
/// <summary>Stack of dialog names (front = index 0 = top / currently on top).</summary>
private readonly List<string> _uiStack = new();
[SerializeField] private HUDNPC npsUI;
@@ -135,19 +138,138 @@ public class CECUIManager : MonoSingleton<CECUIManager>
}
/// <summary>
/// Show UI by name of component ("DlgTask", "EC_InventoryUI")
/// Show UI by name of component ("DlgTask", "EC_InventoryUI"). When isStack is true, pushes the dialog onto the UI stack (brings to front and tracks for Pop).
/// </summary>
/// <param name="componentName">name of component ("DlgTask", "EC_InventoryUI")</param>
public void ShowUI(string componentName)
/// <param name="componentName">Name of component ("DlgTask", "EC_InventoryUI")</param>
/// <param name="isStack">If true, push onto stack (show + SetAsLastSibling + track); if false, just show.</param>
/// <param name="hideCurrentUI">just hide current ui- not pop</param>
public void ShowUI(string componentName, bool isStack = true, bool hideCurrentUI = true)
{
if (string.IsNullOrEmpty(componentName) || canvasDlg == null)
{
if (canvasDlg == null) Debug.LogError("canvasDlg chưa được gán");
return;
}
if (hideCurrentUI)
{
var currentDialogue = GetCurrentDialog();
if(currentDialogue !=null)
{
currentDialogue.Show(false);
}
}
GetInGameUIMan().GetDialog(componentName).Show(true);
if (isStack)
{
Push(componentName);
return;
}
var dialogue = GetInGameUIMan().GetDialog(componentName);
dialogue.Show(true);
dialogue.transform.SetAsLastSibling();
}
public void HideCurrentUIInStack()
{
var currentDialogue = GetCurrentDialog();
Debug.Log(_uiStack.Count);
Pop();
Debug.Log(_uiStack.Count);
//show next one
currentDialogue = GetCurrentDialog();
if(currentDialogue !=null)
{
currentDialogue.Show(true);
}
}
/// <summary>
/// Push a dialog onto the UI stack: show it, add to front of stack, and SetAsLastSibling so it draws on top. If already in stack, moves it to front.
/// </summary>
private void Push(string componentName)
{
if (string.IsNullOrEmpty(componentName) || canvasDlg == null) return;
_uiStack.Remove(componentName);
var dlg = GetInGameUIMan().GetDialog(componentName);
if (dlg == null) return;
dlg.Show(true);
_uiStack.Insert(0, componentName);
dlg.transform.SetAsLastSibling();
}
/// <summary>
/// Pop the top dialog off the stack: hide it and bring the new top (if any) to front. Returns true if something was popped.
/// </summary>
private bool Pop()
{
if (_uiStack.Count == 0) return false;
string top = _uiStack[0];
_uiStack.RemoveAt(0);
var dlg = GetInGameUIMan().GetDialog(top);
if (dlg != null)
dlg.Show(false);
if (_uiStack.Count > 0)
{
var newTop = GetInGameUIMan().GetDialog(_uiStack[0]);
if (newTop != null)
newTop.transform.SetAsLastSibling();
}
return true;
}
/// <summary>Returns the name of the dialog currently on top of the stack, or null if stack is empty.</summary>
public string GetCurrentUI()
{
if (_uiStack.Count == 0) return null;
return _uiStack[0];
}
/// <summary>Returns the dialog instance currently on top of the stack, or null if stack is empty.</summary>
public AUIDialog GetCurrentDialog()
{
var name = GetCurrentUI();
if (name == null) return null;
return GetInGameUIMan().GetDialog(name);
}
/// <summary>Returns the number of dialogs in the stack (0 when empty).</summary>
public int GetStackCount() => _uiStack.Count;
/// <summary>Returns true if the given dialog name is in the stack.</summary>
public bool IsInStack(string componentName)
{
return !string.IsNullOrEmpty(componentName) && _uiStack.Contains(componentName);
}
/// <summary>Returns the dialog name at the given index (0 = top) without removing. Returns null if index is out of range.</summary>
public string PeekStack(int index = 0)
{
if (index < 0 || index >= _uiStack.Count) return null;
return _uiStack[index];
}
/// <summary>Clears the entire stack. If hideAll is true, hides every dialog in the stack before clearing.</summary>
public void ClearStack(bool hideAll = true)
{
if (hideAll)
{
var gui = GetInGameUIMan();
foreach (string name in _uiStack)
{
var dlg = gui?.GetDialog(name);
if (dlg != null) dlg.Show(false);
}
}
_uiStack.Clear();
}
public CDlgMessageBox ShowMessageBox(MessageBoxData messageBoxData)
{
var msgBox = GetInGameUIMan().GetDialog("DlgMessageBox") as CDlgMessageBox;