108 lines
2.6 KiB
C#
108 lines
2.6 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class ActionUIHandler : MonoBehaviour
|
|
{
|
|
#region Statication
|
|
|
|
public static ActionUIHandler instance;
|
|
|
|
private void Awake()
|
|
{
|
|
if (instance != null && instance != this)
|
|
{
|
|
Destroy(gameObject);
|
|
return;
|
|
}
|
|
instance = this;
|
|
}
|
|
|
|
#endregion
|
|
private PlayerEntity selectedEntity;
|
|
private RangedWeapon possibleRanged;
|
|
public bool opened;
|
|
[Header("UI")]
|
|
[SerializeField] private Vector3 offset;
|
|
[SerializeField] private GameObject actionUI;
|
|
[SerializeField] private Button moveButton;
|
|
[SerializeField] private Button attackButton;
|
|
[SerializeField] private Button reloadButton;
|
|
//500 if statements in this script lol
|
|
public void ShowUI(PlayerEntity target)
|
|
{
|
|
opened = true;
|
|
possibleRanged = null;
|
|
selectedEntity = target;
|
|
transform.position = Input.mousePosition + offset;
|
|
actionUI.SetActive(true);
|
|
UpdateUI();
|
|
}
|
|
|
|
public void UpdateUI()
|
|
{
|
|
if (!selectedEntity.hasAttacked)
|
|
{
|
|
if (selectedEntity.currentWeapon.TryGetComponent(out RangedWeapon isRanged))
|
|
{
|
|
possibleRanged = isRanged;
|
|
}
|
|
if (!isRanged || !isRanged.fired)
|
|
{
|
|
reloadButton.gameObject.SetActive(false);
|
|
attackButton.gameObject.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
reloadButton.gameObject.SetActive(true);
|
|
attackButton.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
reloadButton.gameObject.SetActive(false);
|
|
attackButton.gameObject.SetActive(false);
|
|
}
|
|
if (!selectedEntity.hasMoved || !selectedEntity.hasAttacked)
|
|
{
|
|
moveButton.gameObject.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
moveButton.gameObject.SetActive(false);
|
|
}
|
|
|
|
if (selectedEntity.hasAttacked && selectedEntity.hasMoved)
|
|
{
|
|
HideUI();
|
|
}
|
|
}
|
|
public void HideUI()
|
|
{
|
|
opened = false;
|
|
actionUI.SetActive(false);
|
|
}
|
|
|
|
public void ReloadGun()
|
|
{
|
|
possibleRanged.Reload();
|
|
selectedEntity.hasAttacked = true;
|
|
UpdateUI();
|
|
}
|
|
|
|
public void Attack()
|
|
{
|
|
selectedEntity.Attack();
|
|
HideUI();
|
|
}
|
|
|
|
public void SkipTurn()
|
|
{
|
|
selectedEntity.SkipTurn();
|
|
HideUI();
|
|
}
|
|
public void MoveEntity()
|
|
{
|
|
HideUI();
|
|
PlayerEntityMovement.instance.SelectEntity(selectedEntity);
|
|
}
|
|
}
|