86 lines
2.8 KiB
C#
86 lines
2.8 KiB
C#
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<int, bool> m_onClickCallback;
|
|
private CECPetData m_petData;
|
|
|
|
public void SetData(CECPetData pPet, int actualSlot, bool isActivePet, int operatingState, Action<int, bool> 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 ? 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) &&
|
|
pPet.GetHPFactor() == 0.0f;
|
|
|
|
m_iconPet.color = isDead ? new Color(0.5f, 0.5f, 0.5f) : Color.white;
|
|
UpdateIcon(pPet.GetTemplateID());
|
|
|
|
Button btn = GetComponent<Button>();
|
|
if (btn != null)
|
|
{
|
|
btn.interactable = (m_operatingState == 0);
|
|
btn.onClick.RemoveAllListeners();
|
|
btn.onClick.AddListener(() => m_onClickCallback?.Invoke(m_slotIndex, m_isActivePet));
|
|
}
|
|
}
|
|
|
|
private void UpdateIcon(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 pET = (PET_ESSENCE)pDBEssence;
|
|
string strFile = Path.GetFileNameWithoutExtension(pET.FileIcon).ToLower();
|
|
m_iconPet.sprite = EC_Game.GetGameRun().GetUIManager().GetSpriteInListIvtr(strFile);
|
|
}
|
|
else
|
|
{
|
|
m_iconPet.sprite = m_spriteDefault_Icon;
|
|
}
|
|
}
|
|
|
|
public CECPetData GetPetData()
|
|
{
|
|
return m_petData;
|
|
}
|
|
}
|
|
} |