71 lines
1.8 KiB
C#
71 lines
1.8 KiB
C#
using BrewMonster;
|
|
using CSNetwork.Protocols.RPCData;
|
|
using System;
|
|
using System.Text;
|
|
using BrewMonster.Network;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class CharacterItemUI : MonoBehaviour
|
|
{
|
|
[SerializeField] private Button btnClick;
|
|
[SerializeField] private TextMeshProUGUI nameCharacter;
|
|
[SerializeField] private TextMeshProUGUI _labelDetailInfo;
|
|
[SerializeField] private GameObject _goFocusImage;
|
|
RoleInfo dataItem;
|
|
public RoleInfo RoleInfo => dataItem;
|
|
Action<CharacterItemUI> onClick;
|
|
|
|
private void OnEnable()
|
|
{
|
|
if(_goFocusImage!=null)
|
|
_goFocusImage.SetActive(false);
|
|
}
|
|
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
void Start()
|
|
{
|
|
btnClick.onClick.AddListener(OnClickBtn);
|
|
}
|
|
|
|
public void InitItem(RoleInfo role, Action<CharacterItemUI> action)
|
|
{
|
|
dataItem = role;
|
|
onClick = action;
|
|
string roleName = "(Error decoding name)";
|
|
if (role.name != null && role.name.ByteArray != null)
|
|
{
|
|
// Be careful with encoding, assume UTF8 is correct
|
|
roleName = Encoding.Unicode.GetString(
|
|
role.name.RawBuffer,
|
|
0,
|
|
role.name.Length
|
|
);
|
|
}
|
|
nameCharacter.text = roleName;
|
|
if (EC_Game.GetGameRun() != null)
|
|
{
|
|
_labelDetailInfo.text =$"{EC_Game.GetGameRun().GetProfName(role.occupation)} Cấp {role.level.ToString()}";
|
|
}
|
|
else
|
|
{
|
|
BMLogger.LogError("No game run found");
|
|
}
|
|
}
|
|
|
|
private void OnClickBtn()
|
|
{
|
|
onClick?.Invoke(this);
|
|
}
|
|
public void ForceClickBtn()
|
|
{
|
|
onClick?.Invoke(this);
|
|
}
|
|
|
|
public void SetFocus(bool focus)
|
|
{
|
|
_goFocusImage.SetActive(focus);
|
|
}
|
|
}
|