update clone code for DlgPetList

This commit is contained in:
VuNgocHaiC7
2026-03-12 17:13:31 +07:00
parent a41103c15d
commit 6243736c70
3 changed files with 53 additions and 322 deletions
@@ -31,6 +31,10 @@ namespace BrewMonster.UI
Show(true);
UpdatePetInternal();
}
else
{
ClearPetDetail();
}
}
private void UpdatePetInternal()
@@ -38,24 +42,32 @@ namespace BrewMonster.UI
var pDB = ElementDataManProvider.GetElementDataMan();
if(pDB == null)
{
ClearPetDetail();
return;
}
var host = CECGameRun.Instance?.GetHostPlayer();
if (host == null)
{
ClearPetDetail();
return;
}
var pPetCorral = host.GetPetCorral();
if(pPetCorral == null)
if (pPetCorral == null)
{
ClearPetDetail();
return;
}
var pPet = pPetCorral.GetPetData(m_nSlot);
if(pPet == null)
if (pPet == null)
{
ClearPetDetail();
return;
}
int nLevel = pPet.GetLevel();
m_textPetName.text = pPet.GetName();
m_textPetName.text = pPet.GetName();
m_textLevel.text = "Cấp " + nLevel.ToString();
m_textExp.text = "EXP " + $"{pPet.GetExp()} / {pPet.GetMaxExp()}";
@@ -445,7 +457,7 @@ namespace BrewMonster.UI
return GetStringFromTable(3611 + nHunger);
}
private void ClearPetDetail()
public void ClearPetDetail()
{
if(m_textPetName != null)
{
@@ -468,14 +480,5 @@ namespace BrewMonster.UI
m_descPet.text = "___";
}
}
//public override bool Render()
//{
// if (m_nSlot >= 0)
// {
// UpdatePetInternal();
// }
// return base.Render();
//}
}
}
@@ -13,299 +13,7 @@ namespace BrewMonster.UI
{
public class CDlgPetList : AUIDialog
{
//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_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;
public const int CDLGPETLIST_SLOT_MAX = 20;
[Header("Prefab Setup")]
[SerializeField] private DlgPetListBox m_prefabPetSlot;
@@ -322,6 +30,7 @@ namespace BrewMonster.UI
private List<DlgPetListBox> m_spawnedSlots = new List<DlgPetListBox>();
private int m_nPageIndex = 0;
private int m_currentSelectSlotIndex = -1;
private CECPetCorral m_cachedPetCorral;
public void OnInitDialog()
{
@@ -330,6 +39,7 @@ namespace BrewMonster.UI
m_btnClose.onClick.RemoveAllListeners();
m_btnClose.onClick.AddListener(() =>
{
m_dlgPetDetail.ClearPetDetail();
CloseDialogue();
});
@@ -356,22 +66,22 @@ namespace BrewMonster.UI
}
});
}
RefreshUI();
}
public override bool Render()
public void RefreshUI()
{
UpdateList();
UpdateButtonStates();
return base.Render();
}
public void UpdateList()
{
CECPetCorral pPetCorral = GetHostPlayer()?.GetPetCorral();
if (pPetCorral == null) return;
m_cachedPetCorral = GetHostPlayer()?.GetPetCorral();
if (m_cachedPetCorral == null) return;
int operatingState = GetHostPlayer().IsOperatingPet();
int totalPetNum = pPetCorral.GetPetSlotNum();
while (m_spawnedSlots.Count < CDLGPETLIST_SLOT_MAX)
{
@@ -383,8 +93,8 @@ namespace BrewMonster.UI
{
int actualSlotIndex = i + (m_nPageIndex * CDLGPETLIST_SLOT_MAX);
CECPetData pPet = pPetCorral.GetPetData(actualSlotIndex);
bool isActivePet = (pPetCorral.GetActivePetIndex() == actualSlotIndex);
CECPetData pPet = m_cachedPetCorral.GetPetData(actualSlotIndex);
bool isActivePet = (m_cachedPetCorral.GetActivePetIndex() == actualSlotIndex);
m_spawnedSlots[i].SetData(
pPet,
@@ -398,10 +108,15 @@ namespace BrewMonster.UI
private void OnSlotClicked(int slotIndex, bool isActivePet)
{
CECPetCorral pPetCorral = GetHostPlayer()?.GetPetCorral();
if(pPetCorral == null)
if (m_cachedPetCorral == null)
{
m_cachedPetCorral = GetHostPlayer()?.GetPetCorral();
}
if(m_cachedPetCorral == null)
return;
CECPetData pPetData = pPetCorral.GetPetData(slotIndex);
CECPetData pPetData = m_cachedPetCorral.GetPetData(slotIndex);
if (pPetData != null)
{
m_currentSelectSlotIndex = slotIndex;
@@ -426,12 +141,16 @@ namespace BrewMonster.UI
return;
}
CECPetCorral pPetCorral = GetHostPlayer()?.GetPetCorral();
if(pPetCorral == null)
if (m_cachedPetCorral == null)
{
m_cachedPetCorral = GetHostPlayer()?.GetPetCorral();
}
if(m_cachedPetCorral == null)
return;
int operatingState = GetHostPlayer().IsOperatingPet();
bool isActivePet = (pPetCorral.GetActivePetIndex() == m_currentSelectSlotIndex);
bool isActivePet = (m_cachedPetCorral.GetActivePetIndex() == m_currentSelectSlotIndex);
bool canOperate = (operatingState == 0);
if(m_btnHome != null)
@@ -442,7 +161,7 @@ namespace BrewMonster.UI
public void OnCommandSummon(int nSlot)
{
if(nSlot < 0)
if (nSlot < 0)
return;
var actionSwitcher = GetHostPlayer().GetActionSwitcher();
@@ -450,11 +169,20 @@ namespace BrewMonster.UI
return;
GetHostPlayer().SummonPet(nSlot);
CloseDialogue();
}
public void OnCommandRecall()
{
GetHostPlayer().RecallPet();
CloseDialogue();
}
public void OnPetDataChanged()
{
m_cachedPetCorral = null;
if(IsShow())
RefreshUI();
}
}
}
@@ -42,7 +42,7 @@ namespace BrewMonster
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;
m_textPetName.color = isActivePet ? Color.gray : Color.white;
bool isDead = (pPet.GetClass() == (int)GP_PET_TYPE.GP_PET_CLASS_COMBAT ||
pPet.GetClass() == (int)GP_PET_TYPE.GP_PET_CLASS_EVOLUTION) &&