205 lines
6 KiB
C#
205 lines
6 KiB
C#
using System;
|
|
using TMPro;
|
|
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 GameObject cursorObject;
|
|
[Header("Main UI")]
|
|
[SerializeField] private GameObject actionUI;
|
|
[SerializeField] private TextMeshProUGUI actionText;
|
|
public bool opened;
|
|
[Header("Info UI")]
|
|
[SerializeField] private GameObject infoUI;
|
|
[SerializeField] private TextMeshProUGUI nameLabel;
|
|
[SerializeField] private TextMeshProUGUI classLabel;
|
|
[SerializeField] private Image unitPortrait;
|
|
[SerializeField] private TextMeshProUGUI weaponLabel;
|
|
[SerializeField] private TextMeshProUGUI attackLabel;
|
|
[SerializeField] private TextMeshProUGUI speedLabel;
|
|
[SerializeField] private Transform healthBar;
|
|
[SerializeField] private TextMeshProUGUI healthText;
|
|
[Header("Action Buttons")]
|
|
[SerializeField] private Button moveButton;
|
|
[SerializeField] private Button attackButton;
|
|
[SerializeField] private Button reloadButton;
|
|
[SerializeField] private Button switchButton;
|
|
[SerializeField] private Button officerAbilityButton;
|
|
|
|
[Header("Weapon Switcher")]
|
|
[SerializeField] private RectTransform weaponUIPanel;
|
|
[SerializeField] private Button templateWeaponButton;
|
|
[SerializeField] private float templateButtonHeight;
|
|
|
|
//500 if statements in this script lol
|
|
|
|
public void ShowUI(PlayerEntity target)
|
|
{
|
|
opened = true;
|
|
possibleRanged = null;
|
|
selectedEntity = target;
|
|
|
|
actionUI.SetActive(true);
|
|
actionText.gameObject.SetActive(true);
|
|
infoUI.SetActive(true);
|
|
UpdateUI();
|
|
}
|
|
|
|
public void UpdateUI()
|
|
{
|
|
if (selectedEntity.currentWeapon.TryGetComponent(out RangedWeapon isRanged))
|
|
{
|
|
possibleRanged = isRanged;
|
|
}
|
|
if (!isRanged || !isRanged.fired)
|
|
{
|
|
attackButton.gameObject.SetActive(true);
|
|
reloadButton.gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
attackButton.gameObject.SetActive(false);
|
|
if (isRanged && isRanged.fired && selectedEntity.actions >= isRanged.reloadActionUsage)
|
|
{
|
|
{
|
|
reloadButton.gameObject.SetActive(true);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
reloadButton.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
officerAbilityButton.gameObject.SetActive(false);
|
|
if (selectedEntity.officerInstance)
|
|
{
|
|
officerAbilityButton.gameObject.SetActive(true);
|
|
}
|
|
moveButton.gameObject.SetActive(true);
|
|
switchButton.gameObject.SetActive(true);
|
|
actionText.text = $"Remaining Actions: {selectedEntity.actions}";
|
|
UpdateInfo();
|
|
if (selectedEntity.actions == 0)
|
|
{
|
|
HideUI();
|
|
}
|
|
}
|
|
|
|
public void UpdateInfo()
|
|
{
|
|
healthBar.localScale = new Vector3(selectedEntity.health / selectedEntity.maxHealth,1,1);
|
|
classLabel.text = selectedEntity.selectedClass.ToString();
|
|
weaponLabel.text = $"Weapon: {selectedEntity.currentWeapon.weaponName}";
|
|
healthText.text = $"{selectedEntity.health}/{selectedEntity.maxHealth}";
|
|
attackLabel.text = $"Attack: {selectedEntity.currentWeapon.damage}";
|
|
speedLabel.text = $"Speed: {selectedEntity.maxMovement}";
|
|
}
|
|
public void HideUI()
|
|
{
|
|
opened = false;
|
|
foreach (Transform uiObject in transform)
|
|
{
|
|
uiObject.gameObject.SetActive(false);
|
|
}
|
|
infoUI.SetActive(false);
|
|
}
|
|
|
|
public void ReloadGun()
|
|
{
|
|
possibleRanged.Reload();
|
|
UpdateActions(possibleRanged.reloadActionUsage);
|
|
UpdateUI();
|
|
}
|
|
|
|
public void Attack()
|
|
{
|
|
selectedEntity.Attack();
|
|
cursorObject.SetActive(true);
|
|
HideUI();
|
|
}
|
|
|
|
public void ActivateOfficer()
|
|
{
|
|
selectedEntity.officerInstance.ActivateAbility();
|
|
}
|
|
public void SkipTurn()
|
|
{
|
|
selectedEntity.SkipTurn();
|
|
HideUI();
|
|
}
|
|
public void MoveEntity()
|
|
{
|
|
HideUI();
|
|
PlayerEntityMovement.instance.SelectEntity(selectedEntity);
|
|
}
|
|
|
|
public void ShowWeaponList()
|
|
{
|
|
foreach (Transform oldButton in weaponUIPanel)
|
|
{
|
|
Destroy(oldButton.gameObject);
|
|
}
|
|
if (weaponUIPanel.gameObject.activeSelf)
|
|
{
|
|
HideWeaponList();
|
|
return;
|
|
}
|
|
weaponUIPanel.gameObject.SetActive(true);
|
|
weaponUIPanel.sizeDelta = new Vector2(weaponUIPanel.sizeDelta.x, templateButtonHeight * selectedEntity.weaponInstances.Count);
|
|
foreach (Weapon weapon in selectedEntity.weaponInstances)
|
|
{
|
|
Button newButton = Instantiate(templateWeaponButton, weaponUIPanel);
|
|
newButton.gameObject.SetActive(true);
|
|
if (weapon != selectedEntity.currentWeapon)
|
|
{
|
|
newButton.onClick.AddListener(() => SelectWeapon(weapon));
|
|
newButton.GetComponentInChildren<TextMeshProUGUI>().text = weapon.weaponName;
|
|
}
|
|
else
|
|
{
|
|
newButton.GetComponentInChildren<TextMeshProUGUI>().text = $"{weapon.weaponName} (Equipped)";
|
|
}
|
|
}
|
|
}
|
|
|
|
public void SelectWeapon(Weapon weaponSelected)
|
|
{
|
|
UpdateActions(1);
|
|
selectedEntity.SwitchWeapon(weaponSelected);
|
|
HideWeaponList();
|
|
UpdateUI();
|
|
}
|
|
|
|
public void UpdateActions(int amount)
|
|
{
|
|
selectedEntity.actions -= amount;
|
|
if (selectedEntity.actions == 0)
|
|
{
|
|
selectedEntity.debugDoneObject.SetActive(true);
|
|
}
|
|
}
|
|
|
|
private void HideWeaponList()
|
|
{
|
|
weaponUIPanel.gameObject.SetActive(false);
|
|
}
|
|
}
|