From 4666393214a83f5c66429f265506b87f72bcab6f Mon Sep 17 00:00:00 2001 From: VuNgocHaiC7 Date: Thu, 5 Mar 2026 15:37:00 +0700 Subject: [PATCH] update code dlgPetList --- .../Scripts/UI/Dialogs/DlgPetList.cs | 144 ++++++++++++++---- .../Scripts/UI/Dialogs/DlgPetListBox.cs | 10 +- Assets/PerfectWorld/UI/Pet/DlgPetList.prefab | 23 +-- Assets/PerfectWorld/UI/Pet/box_pet.prefab | 45 ++++++ 4 files changed, 178 insertions(+), 44 deletions(-) diff --git a/Assets/PerfectWorld/Scripts/UI/Dialogs/DlgPetList.cs b/Assets/PerfectWorld/Scripts/UI/Dialogs/DlgPetList.cs index 838ac1a57b..6db5ce3a51 100644 --- a/Assets/PerfectWorld/Scripts/UI/Dialogs/DlgPetList.cs +++ b/Assets/PerfectWorld/Scripts/UI/Dialogs/DlgPetList.cs @@ -1,4 +1,4 @@ -using BrewMonster.Network; +using BrewMonster.Network; using BrewMonster.Scripts.Pet; using CSNetwork.GPDataType; using ModelRenderer.Scripts.GameData; @@ -282,7 +282,7 @@ namespace BrewMonster.UI // CECPetCorral pPetCorral = GetHostPlayer().GetPetCorral(); // int nSlot = slot - 1; // nSlot += m_nPageIndex* CDLGPETLIST_SLOT_MAX; - // // - + // // ·ÉÐÐ-¡·Æï³Ë // if (GetHostPlayer().GetActionSwitcher() != null && GetHostPlayer().GetActionSwitcher().OnFlyToRideAction(nSlot)) // return; @@ -311,34 +311,60 @@ namespace BrewMonster.UI [SerializeField] private DlgPetListBox m_prefabPetSlot; [SerializeField] private Transform m_container; - [Header("Common UI")] - [SerializeField] private Button m_pBtnClose; - [SerializeField] private Button[] m_pBtn_Tab; - [SerializeField] private GameObject[] m_mask_off_pBtn_Tab; + [Header("Button")] + [SerializeField] private Button m_btnClose; + [SerializeField] private Button m_btnHome; + [SerializeField] private Button m_btnOut; + + [Header("Pet Decs")] + [SerializeField] private Image m_iconPet; + [SerializeField] private TMP_Text m_namePet; + [SerializeField] private TMP_Text m_levelPet; + [SerializeField] private TMP_Text m_expPet; + [SerializeField] private Sprite m_spriteDefault_Icon; + private List m_spawnedSlots = new List(); private int m_nPageIndex = 0; + private CECPetData m_currentSelectedPet; + private int m_currentSelectSlotIndex; public void OnInitDialog() { if (!IsShow()) Show(true); - m_pBtnClose.onClick.RemoveAllListeners(); - m_pBtnClose.onClick.AddListener(() => Show(false)); + m_btnClose.onClick.RemoveAllListeners(); + m_btnClose.onClick.AddListener(() => Show(false)); - for (int i = 0; i < m_pBtn_Tab.Length; i++) + if (m_btnHome != null) { - int index = i; - m_pBtn_Tab[i].onClick.RemoveAllListeners(); - m_pBtn_Tab[i].onClick.AddListener(() => OnClickBtnTab(index)); + m_btnHome.onClick.RemoveAllListeners(); + m_btnHome.onClick.AddListener(() => + { + if (m_currentSelectSlotIndex >= 0) + { + OnCommandRecall(); + } + }); } - OnClickBtnTab(0); + if(m_btnOut != null) + { + m_btnOut.onClick.RemoveAllListeners(); + m_btnOut.onClick.AddListener(() => + { + if (m_currentSelectSlotIndex >= 0) + { + OnCommandSummon(m_currentSelectSlotIndex); + } + }); + } } public override bool Render() { UpdateList(); + UpdateButtonStates(); return base.Render(); } @@ -375,18 +401,89 @@ namespace BrewMonster.UI private void OnSlotClicked(int slotIndex, bool isActivePet) { - if (isActivePet) + CECPetCorral pPetCorral = GetHostPlayer()?.GetPetCorral(); + if(pPetCorral == null) + return; + CECPetData pPetData = pPetCorral.GetPetData(slotIndex); + if (pPetData != null) { - OnCommandRecall(); + m_currentSelectSlotIndex = slotIndex; + UpdatePetDetails(pPetData); + UpdateButtonStates(); + } + } + + private void UpdatePetDetails(CECPetData pPet) + { + if (pPet == null) + { + m_namePet.text = "___"; + m_levelPet.text = "___"; + m_expPet.text = "___"; + if(m_spriteDefault_Icon != null) + m_iconPet.sprite = m_spriteDefault_Icon; + return; + } + + m_currentSelectedPet = pPet; + m_namePet.text = pPet.GetName(); + m_levelPet.text = $"Cấp {pPet.GetLevel()}"; + int currentExp = pPet.GetExp(); + int maxExp = pPet.GetMaxExp(); + m_expPet.text = $"EXP: {currentExp} / {maxExp}"; + + UpdatePetIcon(pPet.GetTemplateID()); + } + + private void UpdatePetIcon(int templateID) + { + var pDB = ElementDataManProvider.GetElementDataMan(); + DATA_TYPE dataType = new DATA_TYPE(); + object pDBEssence = pDB.get_data_ptr((uint)templateID, ID_SPACE.ID_SPACE_ESSENCE, ref dataType); + + if (pDBEssence != null) + { + PET_ESSENCE pPET = (PET_ESSENCE)pDBEssence; + string strFile = Path.GetFileNameWithoutExtension(pPET.FileIcon).ToLower(); + m_iconPet.sprite = EC_Game.GetGameRun().GetUIManager().GetSpriteInListIvtr(strFile); } else { - OnCommandSummon(slotIndex); + if(m_spriteDefault_Icon != null) + m_iconPet.sprite = m_spriteDefault_Icon; } } + private void UpdateButtonStates() + { + if (m_currentSelectSlotIndex < 0) + { + if(m_btnHome != null) + m_btnHome.interactable = false; + if(m_btnOut != null) + m_btnOut.interactable = false; + return; + } + + CECPetCorral pPetCorral = GetHostPlayer()?.GetPetCorral(); + if(pPetCorral == null) + return; + + int operatingState = GetHostPlayer().IsOperatingPet(); + bool isActivePet = (pPetCorral.GetActivePetIndex() == m_currentSelectSlotIndex); + bool canOperate = (operatingState == 0); + + if(m_btnHome != null) + m_btnHome.interactable = isActivePet && canOperate; + if(m_btnOut != null) + m_btnOut.interactable = !isActivePet && canOperate; + } + public void OnCommandSummon(int nSlot) { + if(nSlot < 0) + return; + var actionSwitcher = GetHostPlayer().GetActionSwitcher(); if (actionSwitcher != null && actionSwitcher.OnFlyToRideAction(nSlot)) return; @@ -398,20 +495,5 @@ namespace BrewMonster.UI { GetHostPlayer().RecallPet(); } - - public void OnClickBtnTab(int index) - { - m_nPageIndex = index; - - for (int i = 0; i < m_pBtn_Tab.Length; i++) - { - if (i < m_mask_off_pBtn_Tab.Length) - { - m_mask_off_pBtn_Tab[i].SetActive(i != m_nPageIndex); - } - } - - UpdateList(); - } } } diff --git a/Assets/PerfectWorld/Scripts/UI/Dialogs/DlgPetListBox.cs b/Assets/PerfectWorld/Scripts/UI/Dialogs/DlgPetListBox.cs index f8b3798af6..f8f290e6c4 100644 --- a/Assets/PerfectWorld/Scripts/UI/Dialogs/DlgPetListBox.cs +++ b/Assets/PerfectWorld/Scripts/UI/Dialogs/DlgPetListBox.cs @@ -22,17 +22,18 @@ namespace BrewMonster private bool m_isActivePet; private int m_operatingState; private Action m_onClickCallback; + private CECPetData m_petData; public void SetData(CECPetData pPet, int actualSlot, bool isActivePet, int operatingState, Action onClickSlot) { if (pPet == null) { - Show(false); + Show(false); return; } Show(true); - + m_slotIndex = actualSlot; m_isActivePet = isActivePet; m_operatingState = operatingState; @@ -76,5 +77,10 @@ namespace BrewMonster m_iconPet.sprite = m_spriteDefault_Icon; } } + + public CECPetData GetPetData() + { + return m_petData; + } } } \ No newline at end of file diff --git a/Assets/PerfectWorld/UI/Pet/DlgPetList.prefab b/Assets/PerfectWorld/UI/Pet/DlgPetList.prefab index c8a8b17b6d..d892ebe4bd 100644 --- a/Assets/PerfectWorld/UI/Pet/DlgPetList.prefab +++ b/Assets/PerfectWorld/UI/Pet/DlgPetList.prefab @@ -353,7 +353,7 @@ MonoBehaviour: m_OnCullStateChanged: m_PersistentCalls: m_Calls: [] - m_text: "C\u1EA5p 10" + m_text: ___ m_isRightToLeft: 0 m_fontAsset: {fileID: 11400000, guid: 369c2e14814cc9a4b8e3ad4e37769134, type: 2} m_sharedMaterial: {fileID: 9092487103257209053, guid: 369c2e14814cc9a4b8e3ad4e37769134, type: 2} @@ -565,7 +565,7 @@ MonoBehaviour: m_OnCullStateChanged: m_PersistentCalls: m_Calls: [] - m_text: EXP 3/50 + m_text: ___ m_isRightToLeft: 0 m_fontAsset: {fileID: 11400000, guid: 369c2e14814cc9a4b8e3ad4e37769134, type: 2} m_sharedMaterial: {fileID: 9092487103257209053, guid: 369c2e14814cc9a4b8e3ad4e37769134, type: 2} @@ -592,7 +592,7 @@ MonoBehaviour: m_faceColor: serializedVersion: 2 rgba: 4294967295 - m_fontSize: 35.05 + m_fontSize: 39.15 m_fontSizeBase: 36 m_fontWeight: 400 m_enableAutoSizing: 1 @@ -1466,13 +1466,14 @@ MonoBehaviour: imageProgress: {fileID: 0} m_prefabPetSlot: {fileID: 4659787501825667672, guid: 1f24da0ec1a703b4e9650d69ec4ceff2, type: 3} m_container: {fileID: 6146182060371184350} - m_pBtnClose: {fileID: 8122086289517642079} - m_pBtn_Tab: - - {fileID: 0} - - {fileID: 0} - m_mask_off_pBtn_Tab: - - {fileID: 0} - - {fileID: 0} + m_btnClose: {fileID: 8122086289517642079} + m_btnHome: {fileID: 2385823678917970113} + m_btnOut: {fileID: 3388903545038814812} + m_iconPet: {fileID: 3806612095625030478} + m_namePet: {fileID: 3493020700139178670} + m_levelPet: {fileID: 7602645980480065390} + m_expPet: {fileID: 1618158093982489839} + m_spriteDefault_Icon: {fileID: 21300000, guid: a5366f3bce011c046902e39b6bd3a077, type: 3} --- !u!1 &5447703489185023651 GameObject: m_ObjectHideFlags: 0 @@ -2122,7 +2123,7 @@ MonoBehaviour: m_OnCullStateChanged: m_PersistentCalls: m_Calls: [] - m_text: "T\u1EED S\u1EAFc Linh H\u1ED3 " + m_text: ___ m_isRightToLeft: 0 m_fontAsset: {fileID: 11400000, guid: 369c2e14814cc9a4b8e3ad4e37769134, type: 2} m_sharedMaterial: {fileID: 9092487103257209053, guid: 369c2e14814cc9a4b8e3ad4e37769134, type: 2} diff --git a/Assets/PerfectWorld/UI/Pet/box_pet.prefab b/Assets/PerfectWorld/UI/Pet/box_pet.prefab index 2587fd8ba3..88a65959c6 100644 --- a/Assets/PerfectWorld/UI/Pet/box_pet.prefab +++ b/Assets/PerfectWorld/UI/Pet/box_pet.prefab @@ -12,6 +12,7 @@ GameObject: - component: {fileID: 7165189893168129209} - component: {fileID: 1118867773330876107} - component: {fileID: 4659787501825667672} + - component: {fileID: 7552159391515501642} m_Layer: 5 m_Name: box_pet m_TagString: Untagged @@ -97,6 +98,50 @@ MonoBehaviour: m_textPetName: {fileID: 5449806950497928055} m_textLevel: {fileID: 8984627373247379662} m_spriteDefault_Icon: {fileID: 21300000, guid: a5366f3bce011c046902e39b6bd3a077, type: 3} +--- !u!114 &7552159391515501642 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 348038655157736426} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Navigation: + m_Mode: 3 + m_WrapAround: 0 + m_SelectOnUp: {fileID: 0} + m_SelectOnDown: {fileID: 0} + m_SelectOnLeft: {fileID: 0} + m_SelectOnRight: {fileID: 0} + m_Transition: 1 + m_Colors: + m_NormalColor: {r: 1, g: 1, b: 1, a: 1} + m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} + m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1} + m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} + m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608} + m_ColorMultiplier: 1 + m_FadeDuration: 0.1 + m_SpriteState: + m_HighlightedSprite: {fileID: 0} + m_PressedSprite: {fileID: 0} + m_SelectedSprite: {fileID: 0} + m_DisabledSprite: {fileID: 0} + m_AnimationTriggers: + m_NormalTrigger: Normal + m_HighlightedTrigger: Highlighted + m_PressedTrigger: Pressed + m_SelectedTrigger: Selected + m_DisabledTrigger: Disabled + m_Interactable: 1 + m_TargetGraphic: {fileID: 1118867773330876107} + m_OnClick: + m_PersistentCalls: + m_Calls: [] --- !u!1 &2001492326850316061 GameObject: m_ObjectHideFlags: 0