using System; using BrewMonster.Network; using BrewMonster.UI; using CSNetwork.GPDataType; using TMPro; using UnityEngine; using UnityEngine.UI; namespace BrewMonster { public class HUDPlayer : MonoBehaviour { public TextMeshProUGUI healthText; public TextMeshProUGUI manaText; public TextMeshProUGUI expText; public TextMeshProUGUI nameText; public TextMeshProUGUI levelText; public Image healthImage; public Image manaImage; public Image expImage; [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(UpdateHostPlayerInfoUI); EventBus.Subscribe(UpdateNameHostPlayer); EventBus.Subscribe(UpdateNeededExp); if (m_btnOpenCharacter != null) m_btnOpenCharacter.onClick.AddListener(OnOpenCharacterClick); } private void OnDestroy() { EventBus.Unsubscribe(UpdateHostPlayerInfoUI); EventBus.Unsubscribe(UpdateNameHostPlayer); EventBus.Unsubscribe(UpdateNeededExp); } 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}"; healthImage.fillAmount = (float)obj.iHP / (float)obj.iMaxHP; manaImage.fillAmount = (float)obj.iMP / (float)obj.iMaxMP; expImage.fillAmount = (float)obj.iExp / (float)neededExp; } private void OnOpenCharacterClick() { var gameUIMan = EC_Game.GetGameRun()?.GetUIManager()?.GetInGameUIMan(); if (gameUIMan == null) return; var dlg = gameUIMan.GetDialog("Win_Character"); if (dlg == null) return; if (!dlg.IsShow()) { UnityGameSession.c2s_SendCmdGetExtProps(); dlg.ResetPoints(); } dlg.Show(!dlg.IsShow()); } } }