147 lines
5.3 KiB
C#
147 lines
5.3 KiB
C#
using System;
|
|
using BrewMonster.Network;
|
|
using BrewMonster.UI;
|
|
using CSNetwork.GPDataType;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using System.Collections.Generic;
|
|
using BrewMonster.Scripts.Skills;
|
|
using BrewMonster.Scripts;
|
|
namespace BrewMonster
|
|
{
|
|
public class HUDPlayer : MonoBehaviour,ITickable
|
|
{
|
|
public TextMeshProUGUI healthText;
|
|
public TextMeshProUGUI manaText;
|
|
public TextMeshProUGUI expText;
|
|
public TextMeshProUGUI nameText;
|
|
public TextMeshProUGUI levelText;
|
|
public TextMeshProUGUI spText;
|
|
public Image healthImage;
|
|
public Image manaImage;
|
|
public Image expImage;
|
|
public Image apImage;
|
|
public List<Toggle> apToggles;
|
|
private List<AUIBuffIcon> buffIcons;
|
|
[SerializeField] private AUIBuffIcon buffIconPrefab;
|
|
|
|
|
|
[Tooltip("Optional. Assign to make this area open the character dialog on click. If unset, nothing opens.")]
|
|
[SerializeField] private Button m_btnOpenCharacter;
|
|
|
|
public float neededExp;
|
|
private void Awake()
|
|
{
|
|
EventBus.Subscribe<cmd_self_info_00>(UpdateHostPlayerInfoUI);
|
|
EventBus.Subscribe<CECHostPlayer.InfoHostPlayer>(UpdateNameHostPlayer);
|
|
EventBus.Subscribe<CECHostPlayer.EXPToUpLevel>(UpdateNeededExp);
|
|
if (m_btnOpenCharacter != null)
|
|
m_btnOpenCharacter.onClick.AddListener(OnOpenCharacterClick);
|
|
buffIcons = new List<AUIBuffIcon>();
|
|
TickInvoker.Instance.RegisterTickable(this);
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
EventBus.Unsubscribe<cmd_self_info_00>(UpdateHostPlayerInfoUI);
|
|
EventBus.Unsubscribe<CECHostPlayer.InfoHostPlayer>(UpdateNameHostPlayer);
|
|
EventBus.Unsubscribe<CECHostPlayer.EXPToUpLevel>(UpdateNeededExp);
|
|
TickInvoker.Instance.UnregisterTickable(this);
|
|
}
|
|
|
|
public bool Tick(uint dwDeltaTime)
|
|
{
|
|
UpdateBuffIcons();
|
|
return true;
|
|
}
|
|
private void UpdateNeededExp(CECHostPlayer.EXPToUpLevel obj)
|
|
{
|
|
neededExp = obj.NeededExp;
|
|
}
|
|
|
|
private void UpdateNameHostPlayer(CECHostPlayer.InfoHostPlayer obj)
|
|
{
|
|
nameText.text = obj.NameHostPlayer;
|
|
}
|
|
|
|
private void UpdateHostPlayerInfoUI(cmd_self_info_00 obj)
|
|
{
|
|
healthText.text = $"{obj.iHP}/{obj.iMaxHP}";
|
|
manaText.text = $"{obj.iMP}/{obj.iMaxMP}";
|
|
expText.text = $"{((float)obj.iExp/neededExp)*100}%";
|
|
levelText.text = $"{obj.sLevel}";
|
|
spText.text = $"{obj.iAP%100}/100";
|
|
healthImage.fillAmount = (float)obj.iHP / (float)obj.iMaxHP;
|
|
manaImage.fillAmount = (float)obj.iMP / (float)obj.iMaxMP;
|
|
expImage.fillAmount = (float)obj.iExp / (float)neededExp;
|
|
apImage.fillAmount = (float)(obj.iAP%100) / (float)100;
|
|
|
|
int curAP = obj.iAP/100;
|
|
int maxAP = obj.iMaxAP/100;
|
|
|
|
for (int i = 0; i < apToggles.Count; i++)
|
|
{
|
|
if(i < maxAP)
|
|
{
|
|
apToggles[i].gameObject.SetActive(true);
|
|
apToggles[i].isOn = i < curAP;
|
|
}
|
|
else
|
|
{
|
|
apToggles[i].gameObject.SetActive(false);
|
|
}
|
|
}
|
|
}
|
|
private void UpdateBuffIcons()
|
|
{
|
|
var hostPlayer = EC_Game.GetGameRun().GetHostPlayer();
|
|
if(hostPlayer == null)
|
|
return;
|
|
var iconStates = hostPlayer.m_aIconStates;
|
|
if(buffIcons.Count < iconStates.Count)
|
|
{
|
|
for(int i = buffIcons.Count; i < iconStates.Count; i++)
|
|
{
|
|
var buffIcon = Instantiate(buffIconPrefab, buffIconPrefab.transform.parent);
|
|
buffIcons.Add(buffIcon);
|
|
}
|
|
}
|
|
for(int i = 0; i < buffIcons.Count; i++)
|
|
{
|
|
if(i < iconStates.Count)
|
|
{
|
|
buffIcons[i].gameObject.SetActive(true);
|
|
var gameUIMan = CECUIManager.Instance.GetInGameUIMan();
|
|
var szFile = GNET.QueryTeamState(iconStates[i].id).GetIcon();
|
|
szFile = szFile.ToLower();
|
|
gameUIMan.SetCover(buffIcons[i], szFile, EC_GAMEUI_ICONS.ICONS_STATE);
|
|
}
|
|
else
|
|
{
|
|
buffIcons[i].gameObject.SetActive(false);
|
|
}
|
|
}
|
|
}
|
|
private void OnOpenCharacterClick()
|
|
{
|
|
// var gameUIMan = EC_Game.GetGameRun()?.GetUIManager()?.GetInGameUIMan();
|
|
// if (gameUIMan == null) return;
|
|
// var dlg = CECUIManager.Instance.ShowUI("Win_Character");
|
|
// if (dlg == null) return;
|
|
// if (!dlg.IsShow())
|
|
// {
|
|
// UnityGameSession.c2s_SendCmdGetExtProps();
|
|
// dlg.ResetPoints();
|
|
// }
|
|
// dlg.Show(!dlg.IsShow());
|
|
|
|
var gameUIMan = EC_Game.GetGameRun()?.GetUIManager()?.GetInGameUIMan();
|
|
if (gameUIMan == null) return;
|
|
var dlg = CECUIManager.Instance.ShowUI("Win_Character");
|
|
UnityGameSession.c2s_SendCmdGetExtProps();
|
|
dlg.ResetPoints();
|
|
}
|
|
|
|
}
|
|
} |