From beaa50b9d7f9539cbd1df92f4ecfde5dc363c28a Mon Sep 17 00:00:00 2001 From: NguyenVanDat Date: Tue, 3 Mar 2026 10:59:00 +0700 Subject: [PATCH] add dialogue type --- .../PerfectWorld/Scripts/UI/CDlgMessageBox.cs | 4 +- .../Scripts/UI/Dialogs/AUIDialog.cs | 7 + Assets/Scripts/CECUIManager.cs | 188 +++++++++--------- 3 files changed, 100 insertions(+), 99 deletions(-) diff --git a/Assets/PerfectWorld/Scripts/UI/CDlgMessageBox.cs b/Assets/PerfectWorld/Scripts/UI/CDlgMessageBox.cs index 4357f3fb8b..b7a2fb30e0 100644 --- a/Assets/PerfectWorld/Scripts/UI/CDlgMessageBox.cs +++ b/Assets/PerfectWorld/Scripts/UI/CDlgMessageBox.cs @@ -30,7 +30,9 @@ namespace BrewMonster [SerializeField] private Button okButton; [SerializeField] private Button _noButton; [SerializeField] private Button _closeButton; - + + public override DialogueType DialogueType => DialogueType.MessageBox; + private MessageBoxData _messageData; public override void OnEnable() diff --git a/Assets/PerfectWorld/Scripts/UI/Dialogs/AUIDialog.cs b/Assets/PerfectWorld/Scripts/UI/Dialogs/AUIDialog.cs index e1a564978d..dc5311f2fe 100644 --- a/Assets/PerfectWorld/Scripts/UI/Dialogs/AUIDialog.cs +++ b/Assets/PerfectWorld/Scripts/UI/Dialogs/AUIDialog.cs @@ -6,6 +6,11 @@ using UnityEngine.UI; namespace BrewMonster.UI { + public enum DialogueType + { + Window, + MessageBox + } public class AUIDialog : MonoBehaviour { protected Dictionary m_StringTable = new Dictionary(); @@ -20,6 +25,8 @@ namespace BrewMonster.UI private bool m_bUpdateRenderTarget = false; [SerializeField] TextMeshProUGUI skillNameText; [SerializeField] Image imageProgress; + + public virtual DialogueType DialogueType => DialogueType.Window; public virtual void Show(bool value) { diff --git a/Assets/Scripts/CECUIManager.cs b/Assets/Scripts/CECUIManager.cs index c58d6f68b9..5a604306e5 100644 --- a/Assets/Scripts/CECUIManager.cs +++ b/Assets/Scripts/CECUIManager.cs @@ -12,6 +12,8 @@ using TMPro; public class CECUIManager : MonoSingleton { + [SerializeField] private GameObject _windowContainer; + [SerializeField] private GameObject _messageBoxContainer; [SerializeField] private TMP_Text _fpsText; [SerializeField] private List uiPrefabs; // drag các prefab UI vào đây @@ -150,16 +152,6 @@ public class CECUIManager : MonoSingleton } GetInGameUIMan().GetDialog(componentName).Show(true); - - return; - - var type = FindTypeByName(componentName); - - if (TryShowCachedUI(type)) return; - if (FindUIByName(componentName, type)) return; - if (FindUIByType(type)) return; - - Debug.LogWarning($"Không tìm thấy UI {componentName} đã spawn trong canvasDlg. Type found: {(type != null ? type.FullName : "null")}"); } public CDlgMessageBox ShowMessageBox(MessageBoxData messageBoxData) { @@ -330,86 +322,86 @@ public class CECUIManager : MonoSingleton return true; } - private System.Type FindTypeByName(string componentName) - { - string[] namespacePrefixes = { - "", // No namespace - "BrewMonster.Scripts.Task.UI.", - "BrewMonster.UI.", - "BrewMonster.Scripts.UI.", - "BrewMonster." - }; - - // Try with common namespace prefixes - foreach (var prefix in namespacePrefixes) - { - string fullTypeName = string.IsNullOrEmpty(prefix) ? componentName : prefix + componentName; - var type = System.Type.GetType(fullTypeName); - if (type != null) return type; - } - - // Search in all assemblies - foreach (var assembly in System.AppDomain.CurrentDomain.GetAssemblies()) - { - var type = assembly.GetType(componentName); - if (type != null) return type; - - foreach (var prefix in namespacePrefixes) - { - if (string.IsNullOrEmpty(prefix)) continue; - type = assembly.GetType(prefix + componentName); - if (type != null) return type; - } - } - - return null; - } - - private bool TryShowCachedUI(System.Type type) - { - if (type != null && _spawnedUIs.TryGetValue(type, out var uiGo)) - { - uiGo.SetActive(true); - return true; - } - return false; - } - - private bool FindUIByName(string componentName, System.Type type) - { - for (int i = 0; i < canvasDlg.transform.childCount; i++) - { - var child = canvasDlg.transform.GetChild(i); - if (!child.name.Contains(componentName) && child.name != componentName) continue; - - if (type != null) - { - var foundComponent = child.GetComponentInChildren(type, true); - if (foundComponent != null) - { - ActivateAndCacheUI(foundComponent.gameObject, type); - return true; - } - } - - ActivateAndCacheUI(child.gameObject, type); - return true; - } - return false; - } - - private bool FindUIByType(System.Type type) - { - if (type == null) return false; - - var foundComponent = canvasDlg.GetComponentInChildren(type, true); - if (foundComponent != null) - { - ActivateAndCacheUI(foundComponent.gameObject, type); - return true; - } - return false; - } + // private System.Type FindTypeByName(string componentName) + // { + // string[] namespacePrefixes = { + // "", // No namespace + // "BrewMonster.Scripts.Task.UI.", + // "BrewMonster.UI.", + // "BrewMonster.Scripts.UI.", + // "BrewMonster." + // }; + // + // // Try with common namespace prefixes + // foreach (var prefix in namespacePrefixes) + // { + // string fullTypeName = string.IsNullOrEmpty(prefix) ? componentName : prefix + componentName; + // var type = System.Type.GetType(fullTypeName); + // if (type != null) return type; + // } + // + // // Search in all assemblies + // foreach (var assembly in System.AppDomain.CurrentDomain.GetAssemblies()) + // { + // var type = assembly.GetType(componentName); + // if (type != null) return type; + // + // foreach (var prefix in namespacePrefixes) + // { + // if (string.IsNullOrEmpty(prefix)) continue; + // type = assembly.GetType(prefix + componentName); + // if (type != null) return type; + // } + // } + // + // return null; + // } + // + // private bool TryShowCachedUI(System.Type type) + // { + // if (type != null && _spawnedUIs.TryGetValue(type, out var uiGo)) + // { + // uiGo.SetActive(true); + // return true; + // } + // return false; + // } + // + // private bool FindUIByName(string componentName, System.Type type) + // { + // for (int i = 0; i < canvasDlg.transform.childCount; i++) + // { + // var child = canvasDlg.transform.GetChild(i); + // if (!child.name.Contains(componentName) && child.name != componentName) continue; + // + // if (type != null) + // { + // var foundComponent = child.GetComponentInChildren(type, true); + // if (foundComponent != null) + // { + // ActivateAndCacheUI(foundComponent.gameObject, type); + // return true; + // } + // } + // + // ActivateAndCacheUI(child.gameObject, type); + // return true; + // } + // return false; + // } + // + // private bool FindUIByType(System.Type type) + // { + // if (type == null) return false; + // + // var foundComponent = canvasDlg.GetComponentInChildren(type, true); + // if (foundComponent != null) + // { + // ActivateAndCacheUI(foundComponent.gameObject, type); + // return true; + // } + // return false; + // } private void ActivateAndCacheUI(GameObject uiGameObject, System.Type type) { @@ -421,14 +413,14 @@ public class CECUIManager : MonoSingleton /// /// Ẩn UI (disable thay vì destroy) /// - public void HideUI() where T : Component - { - var type = typeof(T); - if (_spawnedUIs.TryGetValue(type, out var uiGo)) - { - uiGo.SetActive(false); - } - } + // public void HideUI() where T : Component + // { + // var type = typeof(T); + // if (_spawnedUIs.TryGetValue(type, out var uiGo)) + // { + // uiGo.SetActive(false); + // } + // } /// /// Kiểm tra UI có đang active không