193 lines
5.8 KiB
C#
193 lines
5.8 KiB
C#
using System.Collections.Generic;
|
|
using BrewMonster.Managers;
|
|
using BrewMonster.Network;
|
|
using BrewMonster.Scripts;
|
|
using BrewMonster.Scripts.Skills;
|
|
using BrewMonster.UI;
|
|
using CSNetwork.GPDataType;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace BrewMonster
|
|
{
|
|
public class HUDNPC : MonoBehaviour, ITickable
|
|
{
|
|
[SerializeField] private Button _NPCIconBtn;
|
|
[SerializeField] private TextMeshProUGUI _healthText;
|
|
[SerializeField] private TextMeshProUGUI _nameText;
|
|
[SerializeField] private TextMeshProUGUI _statText;
|
|
[SerializeField] private Image healthImage;
|
|
[SerializeField] private RawImage _avatarImage;
|
|
|
|
private List<AUIBuffIcon> _buffIcons;
|
|
[SerializeField] private AUIBuffIcon _buffIconPrefab;
|
|
|
|
private void Awake()
|
|
{
|
|
_buffIcons = new List<AUIBuffIcon>();
|
|
TickInvoker.Instance.RegisterTickable(this);
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
TickInvoker.Instance.UnregisterTickable(this);
|
|
}
|
|
|
|
public bool Tick(uint dwDeltaTime)
|
|
{
|
|
UpdateBuffIcons();
|
|
return true;
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
if (_NPCIconBtn != null)
|
|
{
|
|
_NPCIconBtn.onClick.AddListener(OnNPCIconBtnClick);
|
|
}
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
if (_NPCIconBtn != null)
|
|
{
|
|
_NPCIconBtn.onClick.RemoveListener(OnNPCIconBtnClick);
|
|
}
|
|
}
|
|
|
|
private void OnNPCIconBtnClick()
|
|
{
|
|
var host = EC_Game.GetGameRun()?.GetHostPlayer();
|
|
if (host == null)
|
|
return;
|
|
|
|
int id = host.GetSelectedTarget();
|
|
if (id == 0 || id == host.GetCharacterID() || !GPDataTypeHelper.ISPLAYERID(id))
|
|
return;
|
|
CECUIManager.Instance?.ShowPlayerOptionsDialog(id, _NPCIconBtn.transform.position);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Target buff/debuff row for the selected non-host entity (other player or NPC).
|
|
/// </summary>
|
|
private void UpdateBuffIcons()
|
|
{
|
|
if (!gameObject.activeInHierarchy)
|
|
{
|
|
SetAllBuffIconsActive(false);
|
|
return;
|
|
}
|
|
|
|
var host = EC_Game.GetGameRun()?.GetHostPlayer();
|
|
if (host == null)
|
|
{
|
|
SetAllBuffIconsActive(false);
|
|
return;
|
|
}
|
|
|
|
int targetId = host.GetSelectedTarget();
|
|
if (targetId == 0 || targetId == host.GetCharacterID())
|
|
{
|
|
SetAllBuffIconsActive(false);
|
|
return;
|
|
}
|
|
|
|
List<IconState> iconStates = null;
|
|
if (GPDataTypeHelper.ISPLAYERID(targetId))
|
|
{
|
|
var player = EC_ManMessageMono.Instance?.GetECManPlayer?.GetPlayer(targetId);
|
|
iconStates = player?.m_aIconStates;
|
|
}
|
|
else if (GPDataTypeHelper.ISNPCID(targetId))
|
|
{
|
|
var npc = EC_ManMessageMono.Instance?.CECNPCMan?.GetNPCFromAll(targetId);
|
|
iconStates = npc?.m_aIconStates;
|
|
}
|
|
|
|
if (iconStates == null || iconStates.Count == 0)
|
|
{
|
|
SetAllBuffIconsActive(false);
|
|
return;
|
|
}
|
|
|
|
if (_buffIconPrefab == null)
|
|
{
|
|
SetAllBuffIconsActive(false);
|
|
return;
|
|
}
|
|
|
|
var gameUIMan = CECUIManager.Instance?.GetInGameUIMan();
|
|
if (gameUIMan == null)
|
|
{
|
|
SetAllBuffIconsActive(false);
|
|
return;
|
|
}
|
|
|
|
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)
|
|
{
|
|
var teamState = GNET.QueryTeamState(iconStates[i].id);
|
|
if (teamState == null)
|
|
{
|
|
_buffIcons[i].gameObject.SetActive(false);
|
|
continue;
|
|
}
|
|
_buffIcons[i].gameObject.SetActive(true);
|
|
var szFile = teamState.GetIcon();
|
|
szFile = szFile.ToLower();
|
|
gameUIMan.SetCover(_buffIcons[i], szFile, EC_GAMEUI_ICONS.ICONS_STATE);
|
|
}
|
|
else
|
|
{
|
|
_buffIcons[i].gameObject.SetActive(false);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void SetAllBuffIconsActive(bool active)
|
|
{
|
|
if (_buffIcons == null) return;
|
|
for (int i = 0; i < _buffIcons.Count; i++)
|
|
{
|
|
if (_buffIcons[i] != null)
|
|
_buffIcons[i].gameObject.SetActive(active);
|
|
}
|
|
}
|
|
|
|
public void SetText(string healthText, string nameText, string statText)
|
|
{
|
|
_healthText.text = healthText;
|
|
_nameText.text = nameText;
|
|
_statText.text = statText;
|
|
}
|
|
public void SetHealthImage(float health)
|
|
{
|
|
healthImage.fillAmount = health;
|
|
}
|
|
|
|
public void SetAvatar(Texture tex)
|
|
{
|
|
if (_avatarImage == null) return;
|
|
_avatarImage.texture = tex;
|
|
_avatarImage.gameObject.SetActive(tex != null);
|
|
}
|
|
|
|
public void ShowAvatar(bool show)
|
|
{
|
|
if (_avatarImage != null)
|
|
_avatarImage.gameObject.SetActive(show);
|
|
}
|
|
}
|
|
}
|