From e33adda85f004201fda815f48e76a12e174dcf74 Mon Sep 17 00:00:00 2001 From: VuNgocHaiC7 Date: Wed, 4 Mar 2026 17:35:19 +0700 Subject: [PATCH] change UI DlgPetList and code test for dlg --- .../Scripts/UI/Dialogs/DlgPetList.cs | 598 +++++++++++------- .../Scripts/UI/Dialogs/DlgPetListBox.cs | 80 +++ .../Scripts/UI/Dialogs/DlgPetListBox.cs.meta | 2 + Assets/PerfectWorld/UI/Pet/DlgPetList.prefab | 541 +--------------- Assets/PerfectWorld/UI/Pet/box_pet.prefab | 446 +++++++++++++ .../PerfectWorld/UI/Pet/box_pet.prefab.meta | 7 + Assets/Scripts/CECHostPlayer.Party.cs | 20 + 7 files changed, 912 insertions(+), 782 deletions(-) create mode 100644 Assets/PerfectWorld/Scripts/UI/Dialogs/DlgPetListBox.cs create mode 100644 Assets/PerfectWorld/Scripts/UI/Dialogs/DlgPetListBox.cs.meta create mode 100644 Assets/PerfectWorld/UI/Pet/box_pet.prefab create mode 100644 Assets/PerfectWorld/UI/Pet/box_pet.prefab.meta diff --git a/Assets/PerfectWorld/Scripts/UI/Dialogs/DlgPetList.cs b/Assets/PerfectWorld/Scripts/UI/Dialogs/DlgPetList.cs index 9a37420569..838ac1a57b 100644 --- a/Assets/PerfectWorld/Scripts/UI/Dialogs/DlgPetList.cs +++ b/Assets/PerfectWorld/Scripts/UI/Dialogs/DlgPetList.cs @@ -3,6 +3,7 @@ using BrewMonster.Scripts.Pet; using CSNetwork.GPDataType; using ModelRenderer.Scripts.GameData; using System; +using System.Collections.Generic; using System.IO; using TMPro; using UnityEngine; @@ -12,170 +13,327 @@ namespace BrewMonster.UI { public class CDlgPetList : AUIDialog { - public const int CDLGPETLIST_SLOT_MAX = 10; - public const int CDLGPETLIST_PAGE_MAX = 2; + //public const int CDLGPETLIST_SLOT_MAX = 10; + //public const int CDLGPETLIST_PAGE_MAX = 2; - [SerializeField] private Button[] m_pBtn_Summon = new Button[CDLGPETLIST_SLOT_MAX]; - [SerializeField] private Button[] m_pBtn_Recall = new Button[CDLGPETLIST_SLOT_MAX]; - [SerializeField] private Button[] m_pBtn_Detail = new Button[CDLGPETLIST_SLOT_MAX]; - [SerializeField] private Button[] m_pBtn_Banish = new Button[CDLGPETLIST_SLOT_MAX]; - [SerializeField] private Button[] m_pBtn_Evolution = new Button[CDLGPETLIST_SLOT_MAX]; - [SerializeField] private Image[] m_pImg_Icon = new Image[CDLGPETLIST_SLOT_MAX]; - [SerializeField] private TextMeshProUGUI[] m_pLab_Name = new TextMeshProUGUI[CDLGPETLIST_SLOT_MAX]; - [SerializeField] private TextMeshProUGUI[] m_pLab_Level = new TextMeshProUGUI[CDLGPETLIST_SLOT_MAX]; - [SerializeField] private TextMeshProUGUI[] m_pTxt_Name = new TextMeshProUGUI[CDLGPETLIST_SLOT_MAX]; - [SerializeField] private TextMeshProUGUI[] m_pTxt_Level = new TextMeshProUGUI[CDLGPETLIST_SLOT_MAX]; + //[SerializeField] private Button[] m_pBtn_Summon = new Button[CDLGPETLIST_SLOT_MAX]; + //[SerializeField] private Button[] m_pBtn_Recall = new Button[CDLGPETLIST_SLOT_MAX]; + //[SerializeField] private Button[] m_pBtn_Detail = new Button[CDLGPETLIST_SLOT_MAX]; + //[SerializeField] private Button[] m_pBtn_Banish = new Button[CDLGPETLIST_SLOT_MAX]; + //[SerializeField] private Button[] m_pBtn_Evolution = new Button[CDLGPETLIST_SLOT_MAX]; + //[SerializeField] private Image[] m_pImg_Icon = new Image[CDLGPETLIST_SLOT_MAX]; + //[SerializeField] private TextMeshProUGUI[] m_pLab_Name = new TextMeshProUGUI[CDLGPETLIST_SLOT_MAX]; + //[SerializeField] private TextMeshProUGUI[] m_pLab_Level = new TextMeshProUGUI[CDLGPETLIST_SLOT_MAX]; + //[SerializeField] private TextMeshProUGUI[] m_pTxt_Name = new TextMeshProUGUI[CDLGPETLIST_SLOT_MAX]; + //[SerializeField] private TextMeshProUGUI[] m_pTxt_Level = new TextMeshProUGUI[CDLGPETLIST_SLOT_MAX]; + //[SerializeField] private Button m_pBtnClose; + //[SerializeField] private Sprite m_spriteDefault_Icon; + //[SerializeField] private Button[] m_pBtn_Tab; + //[SerializeField] private GameObject[] m_mask_off_pBtn_Tab; + //int m_nPageIndex; + //string strFile = ""; + //string strText = ""; + //CECPetCorral pPetCorral; + //elementdataman pDB; + //DATA_TYPE DataType = new DATA_TYPE(); + + //public void OnInitDialog() + //{ + // //string szText = ""; + // //int i; + // //for (i = 0; i < CDLGPETLIST_SLOT_MAX; i++) + // //{ + // // szText = string.Format("Img_Icon{0}", i + 1); + // // m_pImg_Icon[i] = (PAUIIMAGEPICTURE)GetDlgItem(szText); + // // sprintf(szText, "Lab_Name%d", i + 1); + // // m_pLab_Name[i] = (PAUILABEL)GetDlgItem(szText); + // // sprintf(szText, "Lab_Level%d", i + 1); + // // m_pLab_Level[i] = (PAUILABEL)GetDlgItem(szText); + // // sprintf(szText, "Txt_Name%d", i + 1); + // // m_pTxt_Name[i] = (PAUILABEL)GetDlgItem(szText); + // // sprintf(szText, "Txt_Level%d", i + 1); + // // m_pTxt_Level[i] = (PAUILABEL)GetDlgItem(szText); + // // sprintf(szText, "Btn_Recall%d", i + 1); + // // m_pBtn_Recall[i] = (PAUIIMAGEPICTURE)GetDlgItem(szText); + // // sprintf(szText, "Btn_Summon%d", i + 1); + // // m_pBtn_Summon[i] = (PAUIIMAGEPICTURE)GetDlgItem(szText); + // // sprintf(szText, "Btn_Detail%d", i + 1); + // // m_pBtn_Detail[i] = (PAUIIMAGEPICTURE)GetDlgItem(szText); + // // sprintf(szText, "Btn_Banish%d", i + 1); + // // m_pBtn_Banish[i] = (PAUIIMAGEPICTURE)GetDlgItem(szText); + // // sprintf(szText, "Btn_P%d", i + 1); + // // m_pBtn_Evolution[i] = (PAUIIMAGEPICTURE)GetDlgItem(szText); + // //} + // //for (i = 0; i < CDLGPETLIST_PAGE_MAX; i++) + // //{ + // // m_pBtn_Page[i] = NULL; + // // DDX_Control(AString().Format("Btn_Page%d", i + 1), m_pBtn_Page[i]); + // // m_pBtn_Page[i].SetPushed(false); + // //} + // m_nPageIndex = 0; + // //m_pBtn_Page[0].SetPushed(true); + // int index = 0; + // if (!IsShow()) Show(true); + // for (int i = 0; i < m_pBtn_Summon.Length; i++) + // { + // index = i; + // m_pBtn_Summon[index].onClick.RemoveAllListeners(); + // if(i == 0) + // { + // m_pBtn_Summon[i].onClick.AddListener(() => + // { + // OnCommandSummon(1); + // }); + // } + // else if(i == 1) + // { + // m_pBtn_Summon[i].onClick.AddListener(() => + // { + // OnCommandSummon(2); + // }); + // } + // else if (i == 2) + // { + // m_pBtn_Summon[i].onClick.AddListener(() => + // { + // OnCommandSummon(3); + // }); + // } + // else if (i == 3) + // { + // m_pBtn_Summon[i].onClick.AddListener(() => + // { + // OnCommandSummon(4); + // }); + // } + // else if (i == 5) + // { + // m_pBtn_Summon[i].onClick.AddListener(() => + // { + // OnCommandSummon(6); + // }); + // } + // else if (i == 6) + // { + // m_pBtn_Summon[i].onClick.AddListener(() => + // { + // OnCommandSummon(7); + // }); + // } + // else if (i == 7) + // { + // m_pBtn_Summon[i].onClick.AddListener(() => + // { + // OnCommandSummon(8); + // }); + // } + // else if (i == 9) + // { + // m_pBtn_Summon[i].onClick.AddListener(() => + // { + // OnCommandSummon(10); + // }); + // } + // } + // for (int i = 0; i < m_pBtn_Recall.Length; i++) + // { + // index = i; + // m_pBtn_Recall[index].onClick.RemoveAllListeners(); + // m_pBtn_Recall[index].onClick.AddListener(() => + // { + // OnCommandRecall(); + // }); + // } + // m_pBtnClose.onClick.RemoveAllListeners(); + // m_pBtnClose.onClick.AddListener(() => + // { + // Show(false); + // }); + // for(int i = 0; i < m_pBtn_Tab.Length; i++) + // { + // m_pBtn_Tab[i].onClick.RemoveAllListeners(); + // if(i == 0) + // { + // m_pBtn_Tab[i].onClick.AddListener(() => + // { + // OnClickBtnTab(0); + // }); + // } + // else if(i == 1) + // { + // m_pBtn_Tab[i].onClick.AddListener(() => + // { + // OnClickBtnTab(1); + // }); + // } + // } + // OnClickBtnTab(0); + //} + + //bool IsPetDye(int nSlot) + //{ + // return false; + // //TO DO: fix later + // //return nSlot >= 0 + // // && GetGameUIMan().m_pDlgPetDye.IsShow() + // // && GetGameUIMan().m_pDlgPetDye.GetPetSlot() == nSlot; + //} + + //public override bool Render() + //{ + // UpdateList(); + // return base.Render(); + //} + + //public void UpdateList() + //{ + // strText = ""; + // pPetCorral = GetHostPlayer().GetPetCorral(); + // pDB = ElementDataManProvider.GetElementDataMan(); + // DataType = new DATA_TYPE(); + // for (int i = 0; i < CDLGPETLIST_SLOT_MAX; i++) + // { + // int nPetSlot = i + m_nPageIndex * CDLGPETLIST_SLOT_MAX; + // if (nPetSlot < pPetCorral.GetPetSlotNum()) + // { + // m_pLab_Level[i].color = new Color(255f / 255f, 203f / 255f, 74f / 255f); + // m_pLab_Name[i].color = new Color(255f / 255f, 203f / 255f, 74f / 255f); + // } + // else + // { + // m_pLab_Level[i].color = new Color(128f / 128f, 128f / 128f, 128f / 128f); + // m_pLab_Name[i].color = new Color(128f / 128f, 128f / 128f, 128f / 128f); + // } + // CECPetData pPet = pPetCorral.GetPetData(nPetSlot); + // if (pPet != null) + // { + // bool bEnable = (pPetCorral.GetActivePetIndex() == nPetSlot && GetHostPlayer().IsOperatingPet() == 0); + // m_pBtn_Recall[i].interactable = (bEnable); + + // bEnable = (pPetCorral.GetActivePetIndex() != nPetSlot && GetHostPlayer().IsOperatingPet() == 0); + // m_pBtn_Summon[i].interactable = (bEnable); + + // m_pBtn_Detail[i].interactable = (true); + + // strText = string.Format(GetStringFromTable(801).Replace("%d", "{0}"), pPet.GetLevel()); + // m_pTxt_Level[i].SetText(strText); + // m_pTxt_Name[i].SetText(pPet.GetName()); + // if ((pPet.GetClass() == (int)GP_PET_TYPE.GP_PET_CLASS_COMBAT || pPet.GetClass() == (int)GP_PET_TYPE.GP_PET_CLASS_EVOLUTION) && pPet.GetHPFactor() == 0.0f || IsPetDye(nPetSlot)) + // m_pImg_Icon[i].color = new Color(128f/ 255f, 128f / 255f, 128f / 255f); + // else + // m_pImg_Icon[i].color = new Color(255f/ 255f, 255f / 255f, 255f / 255f); + // //m_pImg_Icon[i].SetData(1); + // //m_pImg_Icon[i].SetDataPtr((void*)1); + // object pDBEssence = pDB.get_data_ptr((uint)pPet.GetTemplateID(), + // ID_SPACE.ID_SPACE_ESSENCE, ref DataType); + + // if (pDBEssence != null) + // { + // PET_ESSENCE pET = (PET_ESSENCE)pDBEssence; + // af_GetFileTitle(pET.FileIcon,out strFile); + // strFile.ToLower(); + // if(m_pImg_Icon[i].sprite == null || m_pImg_Icon[i].sprite.Equals(m_spriteDefault_Icon) || !m_pImg_Icon[i].sprite.name.Equals(strFile)) + // { + // m_pImg_Icon[i].sprite = EC_Game.GetGameRun().GetUIManager().GetSpriteInListIvtr(strFile); + // } + // } + // else + // { + // m_pImg_Icon[i].sprite = m_spriteDefault_Icon; + // //m_pImg_Icon[i].SetHint(_AL("")); + // } + + // if(m_pBtn_Evolution[i] != null) + // m_pBtn_Evolution[i].interactable = (pPet.GetClass() == (int)GP_PET_TYPE.GP_PET_CLASS_COMBAT || pPet.GetClass() == (int)GP_PET_TYPE.GP_PET_CLASS_EVOLUTION); + // } + // else + // { + // m_pBtn_Summon[i].interactable = (false); + // m_pBtn_Recall[i].interactable = (false); + // m_pBtn_Detail[i].interactable = (false); + // //m_pBtn_Evolution[i].gameObject.SetActive(false); + // // m_pBtn_Banish[i].Enable(false); + // //m_pImg_Icon[i].SetDataPtr(NULL); + // m_pTxt_Level[i].text = ""; + // m_pTxt_Name[i].text = ""; + // m_pImg_Icon[i].sprite = m_spriteDefault_Icon; + // //m_pImg_Icon[i].SetHint(_AL("")); + // //m_pImg_Icon[i].SetData(0); + // } + // } + //} + + //public bool af_GetFileTitle(string lpszFile, out string lpszTitle) + //{ + // lpszTitle = string.Empty; + + // if (string.IsNullOrEmpty(lpszFile)) + // return lpszFile != null; + + // if (lpszFile.EndsWith("\\") || lpszFile.EndsWith("/")) + // return false; + + // lpszTitle = Path.GetFileNameWithoutExtension(lpszFile); + // return true; + //} + + //public void OnCommandSummon(int slot) + //{ + // CECPetCorral pPetCorral = GetHostPlayer().GetPetCorral(); + // int nSlot = slot - 1; + // nSlot += m_nPageIndex* CDLGPETLIST_SLOT_MAX; + // // ·ÉÐÐ-¡·Æï³Ë + // if (GetHostPlayer().GetActionSwitcher() != null && GetHostPlayer().GetActionSwitcher().OnFlyToRideAction(nSlot)) + // return; + + // //UpdateList(); + // GetHostPlayer().SummonPet(nSlot); + //} + + //public void OnCommandRecall() + //{ + // GetHostPlayer().RecallPet(); + //} + + //public void OnClickBtnTab(int index) + //{ + // m_nPageIndex = index; + // for(int i = 0; i < m_pBtn_Tab.Length; i++) + // { + // m_mask_off_pBtn_Tab[i].SetActive(i != m_nPageIndex); + // } + // UpdateList(); + //} + + public const int CDLGPETLIST_SLOT_MAX = 10; + + [Header("Prefab Setup")] + [SerializeField] private DlgPetListBox m_prefabPetSlot; + [SerializeField] private Transform m_container; + + [Header("Common UI")] [SerializeField] private Button m_pBtnClose; - [SerializeField] private Sprite m_spriteDefault_Icon; [SerializeField] private Button[] m_pBtn_Tab; [SerializeField] private GameObject[] m_mask_off_pBtn_Tab; - int m_nPageIndex; - string strFile = ""; - string strText = ""; - CECPetCorral pPetCorral; - elementdataman pDB; - DATA_TYPE DataType = new DATA_TYPE(); + + private List m_spawnedSlots = new List(); + private int m_nPageIndex = 0; public void OnInitDialog() { - //string szText = ""; - //int i; - //for (i = 0; i < CDLGPETLIST_SLOT_MAX; i++) - //{ - // szText = string.Format("Img_Icon{0}", i + 1); - // m_pImg_Icon[i] = (PAUIIMAGEPICTURE)GetDlgItem(szText); - // sprintf(szText, "Lab_Name%d", i + 1); - // m_pLab_Name[i] = (PAUILABEL)GetDlgItem(szText); - // sprintf(szText, "Lab_Level%d", i + 1); - // m_pLab_Level[i] = (PAUILABEL)GetDlgItem(szText); - // sprintf(szText, "Txt_Name%d", i + 1); - // m_pTxt_Name[i] = (PAUILABEL)GetDlgItem(szText); - // sprintf(szText, "Txt_Level%d", i + 1); - // m_pTxt_Level[i] = (PAUILABEL)GetDlgItem(szText); - // sprintf(szText, "Btn_Recall%d", i + 1); - // m_pBtn_Recall[i] = (PAUIIMAGEPICTURE)GetDlgItem(szText); - // sprintf(szText, "Btn_Summon%d", i + 1); - // m_pBtn_Summon[i] = (PAUIIMAGEPICTURE)GetDlgItem(szText); - // sprintf(szText, "Btn_Detail%d", i + 1); - // m_pBtn_Detail[i] = (PAUIIMAGEPICTURE)GetDlgItem(szText); - // sprintf(szText, "Btn_Banish%d", i + 1); - // m_pBtn_Banish[i] = (PAUIIMAGEPICTURE)GetDlgItem(szText); - // sprintf(szText, "Btn_P%d", i + 1); - // m_pBtn_Evolution[i] = (PAUIIMAGEPICTURE)GetDlgItem(szText); - //} - //for (i = 0; i < CDLGPETLIST_PAGE_MAX; i++) - //{ - // m_pBtn_Page[i] = NULL; - // DDX_Control(AString().Format("Btn_Page%d", i + 1), m_pBtn_Page[i]); - // m_pBtn_Page[i].SetPushed(false); - //} - m_nPageIndex = 0; - //m_pBtn_Page[0].SetPushed(true); - int index = 0; if (!IsShow()) Show(true); - for (int i = 0; i < m_pBtn_Summon.Length; i++) - { - index = i; - m_pBtn_Summon[index].onClick.RemoveAllListeners(); - if(i == 0) - { - m_pBtn_Summon[i].onClick.AddListener(() => - { - OnCommandSummon(1); - }); - } - else if(i == 1) - { - m_pBtn_Summon[i].onClick.AddListener(() => - { - OnCommandSummon(2); - }); - } - else if (i == 2) - { - m_pBtn_Summon[i].onClick.AddListener(() => - { - OnCommandSummon(3); - }); - } - else if (i == 3) - { - m_pBtn_Summon[i].onClick.AddListener(() => - { - OnCommandSummon(4); - }); - } - else if (i == 5) - { - m_pBtn_Summon[i].onClick.AddListener(() => - { - OnCommandSummon(6); - }); - } - else if (i == 6) - { - m_pBtn_Summon[i].onClick.AddListener(() => - { - OnCommandSummon(7); - }); - } - else if (i == 7) - { - m_pBtn_Summon[i].onClick.AddListener(() => - { - OnCommandSummon(8); - }); - } - else if (i == 9) - { - m_pBtn_Summon[i].onClick.AddListener(() => - { - OnCommandSummon(10); - }); - } - } - for (int i = 0; i < m_pBtn_Recall.Length; i++) - { - index = i; - m_pBtn_Recall[index].onClick.RemoveAllListeners(); - m_pBtn_Recall[index].onClick.AddListener(() => - { - OnCommandRecall(); - }); - } - m_pBtnClose.onClick.RemoveAllListeners(); - m_pBtnClose.onClick.AddListener(() => - { - Show(false); - }); - for(int i = 0; i < m_pBtn_Tab.Length; i++) - { - m_pBtn_Tab[i].onClick.RemoveAllListeners(); - if(i == 0) - { - m_pBtn_Tab[i].onClick.AddListener(() => - { - OnClickBtnTab(0); - }); - } - else if(i == 1) - { - m_pBtn_Tab[i].onClick.AddListener(() => - { - OnClickBtnTab(1); - }); - } - } - OnClickBtnTab(0); - } - bool IsPetDye(int nSlot) - { - return false; - //TO DO: fix later - //return nSlot >= 0 - // && GetGameUIMan().m_pDlgPetDye.IsShow() - // && GetGameUIMan().m_pDlgPetDye.GetPetSlot() == nSlot; + m_pBtnClose.onClick.RemoveAllListeners(); + m_pBtnClose.onClick.AddListener(() => Show(false)); + + for (int i = 0; i < m_pBtn_Tab.Length; i++) + { + int index = i; + m_pBtn_Tab[i].onClick.RemoveAllListeners(); + m_pBtn_Tab[i].onClick.AddListener(() => OnClickBtnTab(index)); + } + + OnClickBtnTab(0); } public override bool Render() @@ -186,106 +344,53 @@ namespace BrewMonster.UI public void UpdateList() { - strText = ""; - pPetCorral = GetHostPlayer().GetPetCorral(); - pDB = ElementDataManProvider.GetElementDataMan(); - DataType = new DATA_TYPE(); + CECPetCorral pPetCorral = GetHostPlayer()?.GetPetCorral(); + if (pPetCorral == null) return; + + int operatingState = GetHostPlayer().IsOperatingPet(); + int totalPetNum = pPetCorral.GetPetSlotNum(); + + while (m_spawnedSlots.Count < CDLGPETLIST_SLOT_MAX) + { + DlgPetListBox newSlot = Instantiate(m_prefabPetSlot, m_container); + m_spawnedSlots.Add(newSlot); + } + for (int i = 0; i < CDLGPETLIST_SLOT_MAX; i++) { - int nPetSlot = i + m_nPageIndex * CDLGPETLIST_SLOT_MAX; - if (nPetSlot < pPetCorral.GetPetSlotNum()) - { - m_pLab_Level[i].color = new Color(255f / 255f, 203f / 255f, 74f / 255f); - m_pLab_Name[i].color = new Color(255f / 255f, 203f / 255f, 74f / 255f); - } - else - { - m_pLab_Level[i].color = new Color(128f / 128f, 128f / 128f, 128f / 128f); - m_pLab_Name[i].color = new Color(128f / 128f, 128f / 128f, 128f / 128f); - } - CECPetData pPet = pPetCorral.GetPetData(nPetSlot); - if (pPet != null) - { - bool bEnable = (pPetCorral.GetActivePetIndex() == nPetSlot && GetHostPlayer().IsOperatingPet() == 0); - m_pBtn_Recall[i].interactable = (bEnable); + int actualSlotIndex = i + (m_nPageIndex * CDLGPETLIST_SLOT_MAX); - bEnable = (pPetCorral.GetActivePetIndex() != nPetSlot && GetHostPlayer().IsOperatingPet() == 0); - m_pBtn_Summon[i].interactable = (bEnable); + CECPetData pPet = pPetCorral.GetPetData(actualSlotIndex); + bool isActivePet = (pPetCorral.GetActivePetIndex() == actualSlotIndex); - m_pBtn_Detail[i].interactable = (true); - - strText = string.Format(GetStringFromTable(801).Replace("%d", "{0}"), pPet.GetLevel()); - m_pTxt_Level[i].SetText(strText); - m_pTxt_Name[i].SetText(pPet.GetName()); - if ((pPet.GetClass() == (int)GP_PET_TYPE.GP_PET_CLASS_COMBAT || pPet.GetClass() == (int)GP_PET_TYPE.GP_PET_CLASS_EVOLUTION) && pPet.GetHPFactor() == 0.0f || IsPetDye(nPetSlot)) - m_pImg_Icon[i].color = new Color(128f/ 255f, 128f / 255f, 128f / 255f); - else - m_pImg_Icon[i].color = new Color(255f/ 255f, 255f / 255f, 255f / 255f); - //m_pImg_Icon[i].SetData(1); - //m_pImg_Icon[i].SetDataPtr((void*)1); - object pDBEssence = pDB.get_data_ptr((uint)pPet.GetTemplateID(), - ID_SPACE.ID_SPACE_ESSENCE, ref DataType); - - if (pDBEssence != null) - { - PET_ESSENCE pET = (PET_ESSENCE)pDBEssence; - af_GetFileTitle(pET.FileIcon,out strFile); - strFile.ToLower(); - if(m_pImg_Icon[i].sprite == null || m_pImg_Icon[i].sprite.Equals(m_spriteDefault_Icon) || !m_pImg_Icon[i].sprite.name.Equals(strFile)) - { - m_pImg_Icon[i].sprite = EC_Game.GetGameRun().GetUIManager().GetSpriteInListIvtr(strFile); - } - } - else - { - m_pImg_Icon[i].sprite = m_spriteDefault_Icon; - //m_pImg_Icon[i].SetHint(_AL("")); - } - - if(m_pBtn_Evolution[i] != null) - m_pBtn_Evolution[i].interactable = (pPet.GetClass() == (int)GP_PET_TYPE.GP_PET_CLASS_COMBAT || pPet.GetClass() == (int)GP_PET_TYPE.GP_PET_CLASS_EVOLUTION); - } - else - { - m_pBtn_Summon[i].interactable = (false); - m_pBtn_Recall[i].interactable = (false); - m_pBtn_Detail[i].interactable = (false); - //m_pBtn_Evolution[i].gameObject.SetActive(false); - // m_pBtn_Banish[i].Enable(false); - //m_pImg_Icon[i].SetDataPtr(NULL); - m_pTxt_Level[i].text = ""; - m_pTxt_Name[i].text = ""; - m_pImg_Icon[i].sprite = m_spriteDefault_Icon; - //m_pImg_Icon[i].SetHint(_AL("")); - //m_pImg_Icon[i].SetData(0); - } + m_spawnedSlots[i].SetData( + pPet, + actualSlotIndex, + isActivePet, + operatingState, + OnSlotClicked + ); } } - public bool af_GetFileTitle(string lpszFile, out string lpszTitle) + private void OnSlotClicked(int slotIndex, bool isActivePet) { - lpszTitle = string.Empty; - - if (string.IsNullOrEmpty(lpszFile)) - return lpszFile != null; - - if (lpszFile.EndsWith("\\") || lpszFile.EndsWith("/")) - return false; - - lpszTitle = Path.GetFileNameWithoutExtension(lpszFile); - return true; + if (isActivePet) + { + OnCommandRecall(); + } + else + { + OnCommandSummon(slotIndex); + } } - public void OnCommandSummon(int slot) + public void OnCommandSummon(int nSlot) { - CECPetCorral pPetCorral = GetHostPlayer().GetPetCorral(); - int nSlot = slot - 1; - nSlot += m_nPageIndex* CDLGPETLIST_SLOT_MAX; - // ·ÉÐÐ-¡·Æï³Ë - if (GetHostPlayer().GetActionSwitcher() != null && GetHostPlayer().GetActionSwitcher().OnFlyToRideAction(nSlot)) + var actionSwitcher = GetHostPlayer().GetActionSwitcher(); + if (actionSwitcher != null && actionSwitcher.OnFlyToRideAction(nSlot)) return; - //UpdateList(); GetHostPlayer().SummonPet(nSlot); } @@ -297,10 +402,15 @@ namespace BrewMonster.UI public void OnClickBtnTab(int index) { m_nPageIndex = index; - for(int i = 0; i < m_pBtn_Tab.Length; i++) + + for (int i = 0; i < m_pBtn_Tab.Length; i++) { - m_mask_off_pBtn_Tab[i].SetActive(i != m_nPageIndex); + 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 new file mode 100644 index 0000000000..f8b3798af6 --- /dev/null +++ b/Assets/PerfectWorld/Scripts/UI/Dialogs/DlgPetListBox.cs @@ -0,0 +1,80 @@ +using BrewMonster.Network; +using BrewMonster.Scripts.Pet; +using BrewMonster.UI; +using CSNetwork.GPDataType; +using ModelRenderer.Scripts.GameData; +using System; +using System.IO; +using TMPro; +using UnityEngine; +using UnityEngine.UI; + +namespace BrewMonster +{ + public class DlgPetListBox : AUIDialog + { + [SerializeField] private Image m_iconPet; + [SerializeField] private TMP_Text m_textPetName; + [SerializeField] private TMP_Text m_textLevel; + [SerializeField] private Sprite m_spriteDefault_Icon; + + private int m_slotIndex; + private bool m_isActivePet; + private int m_operatingState; + private Action m_onClickCallback; + + public void SetData(CECPetData pPet, int actualSlot, bool isActivePet, int operatingState, Action onClickSlot) + { + if (pPet == null) + { + Show(false); + return; + } + + Show(true); + + m_slotIndex = actualSlot; + m_isActivePet = isActivePet; + m_operatingState = operatingState; + m_onClickCallback = onClickSlot; + + m_textPetName.text = pPet.GetName(); + m_textLevel.text = $"Cấp {pPet.GetLevel()}"; + + m_textPetName.color = isActivePet ? new Color(1f, 0.8f, 0.3f) : Color.white; + + bool isDead = (pPet.GetClass() == (int)GP_PET_TYPE.GP_PET_CLASS_COMBAT || + pPet.GetClass() == (int)GP_PET_TYPE.GP_PET_CLASS_EVOLUTION) && + pPet.GetHPFactor() == 0.0f; + + m_iconPet.color = isDead ? new Color(0.5f, 0.5f, 0.5f) : Color.white; + UpdateIcon(pPet.GetTemplateID()); + + Button btn = GetComponent