the ability to switch weapons

This commit is contained in:
reisenlol 2026-01-12 23:05:33 -08:00
parent 0722053b84
commit 533f137c48
No known key found for this signature in database
12 changed files with 928 additions and 15 deletions

View file

@ -1,3 +1,4 @@
using TMPro;
using UnityEngine;
using UnityEngine.UI;
@ -21,12 +22,20 @@ public class ActionUIHandler : MonoBehaviour
private PlayerEntity selectedEntity;
private RangedWeapon possibleRanged;
public bool opened;
[Header("UI")]
[Header("Main UI")]
[SerializeField] private Vector3 offset;
[SerializeField] private GameObject actionUI;
[Header("Action Buttons")]
[SerializeField] private Button moveButton;
[SerializeField] private Button attackButton;
[SerializeField] private Button reloadButton;
[SerializeField] private Button switchButton;
[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)
{
@ -48,27 +57,25 @@ public class ActionUIHandler : MonoBehaviour
}
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);
switchButton.gameObject.SetActive(true);
}
else
{
moveButton.gameObject.SetActive(false);
reloadButton.gameObject.SetActive(false);
}
if (selectedEntity.hasAttacked && selectedEntity.hasMoved)
@ -80,13 +87,14 @@ public class ActionUIHandler : MonoBehaviour
{
opened = false;
actionUI.SetActive(false);
weaponUIPanel.gameObject.SetActive(false);
}
public void ReloadGun()
{
possibleRanged.Reload();
selectedEntity.hasAttacked = true;
UpdateUI();
HideUI();
}
public void Attack()
@ -105,4 +113,56 @@ public class ActionUIHandler : MonoBehaviour
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)
{
MoveAction();
selectedEntity.currentWeapon = weaponSelected;
UpdateUI();
}
private void HideWeaponList()
{
weaponUIPanel.gameObject.SetActive(false);
}
private void MoveAction()
{
if (!selectedEntity.hasMoved)
{
selectedEntity.hasMoved = true;
}
else if (!selectedEntity.hasAttacked)
{
selectedEntity.hasAttacked = true;
}
}
}