Files
test/Assets/PerfectWorld/Scripts/UI/Dialogs/DlgPetList.cs
T
2026-03-05 17:40:09 +07:00

458 lines
17 KiB
C#

using BrewMonster.Network;
using BrewMonster.Scripts.Pet;
using CSNetwork.GPDataType;
using ModelRenderer.Scripts.GameData;
using System;
using System.Collections.Generic;
using System.IO;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
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;
[Header("Prefab Setup")]
[SerializeField] private DlgPetListBox m_prefabPetSlot;
[SerializeField] private Transform m_container;
[Header("Button")]
[SerializeField] private Button m_btnClose;
[SerializeField] private Button m_btnHome;
[SerializeField] private Button m_btnOut;
[Header("References")]
[SerializeField] private DlgPetDetail m_dlgPetDetail;
private List<DlgPetListBox> m_spawnedSlots = new List<DlgPetListBox>();
private int m_nPageIndex = 0;
private int m_currentSelectSlotIndex = -1;
public void OnInitDialog()
{
if (!IsShow()) Show(true);
m_btnClose.onClick.RemoveAllListeners();
m_btnClose.onClick.AddListener(() => Show(false));
if (m_btnHome != null)
{
m_btnHome.onClick.RemoveAllListeners();
m_btnHome.onClick.AddListener(() =>
{
if (m_currentSelectSlotIndex >= 0)
{
OnCommandRecall();
}
});
}
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();
}
public void UpdateList()
{
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 actualSlotIndex = i + (m_nPageIndex * CDLGPETLIST_SLOT_MAX);
CECPetData pPet = pPetCorral.GetPetData(actualSlotIndex);
bool isActivePet = (pPetCorral.GetActivePetIndex() == actualSlotIndex);
m_spawnedSlots[i].SetData(
pPet,
actualSlotIndex,
isActivePet,
operatingState,
OnSlotClicked
);
}
}
private void OnSlotClicked(int slotIndex, bool isActivePet)
{
CECPetCorral pPetCorral = GetHostPlayer()?.GetPetCorral();
if(pPetCorral == null)
return;
CECPetData pPetData = pPetCorral.GetPetData(slotIndex);
if (pPetData != null)
{
m_currentSelectSlotIndex = slotIndex;
UpdateButtonStates();
if (m_dlgPetDetail != null)
{
m_dlgPetDetail.UpdatePet(slotIndex);
}
}
}
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;
GetHostPlayer().SummonPet(nSlot);
}
public void OnCommandRecall()
{
GetHostPlayer().RecallPet();
}
}
}