they do not call me the ui designer
This commit is contained in:
parent
daf3218043
commit
68af10bc4d
14 changed files with 1677 additions and 125 deletions
|
|
@ -1,3 +1,4 @@
|
|||
using System;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
|
@ -21,10 +22,19 @@ public class ActionUIHandler : MonoBehaviour
|
|||
#endregion
|
||||
private PlayerEntity selectedEntity;
|
||||
private RangedWeapon possibleRanged;
|
||||
public bool opened;
|
||||
[Header("Main UI")]
|
||||
[SerializeField] private Vector3 offset;
|
||||
[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 attackLabel;
|
||||
[SerializeField] private TextMeshProUGUI speedLabel;
|
||||
[SerializeField] private Transform healthBar;
|
||||
[SerializeField] private TextMeshProUGUI healthText;
|
||||
[Header("Action Buttons")]
|
||||
[SerializeField] private Button moveButton;
|
||||
[SerializeField] private Button attackButton;
|
||||
|
|
@ -37,13 +47,15 @@ public class ActionUIHandler : MonoBehaviour
|
|||
[SerializeField] private float templateButtonHeight;
|
||||
|
||||
//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);
|
||||
actionText.gameObject.SetActive(true);
|
||||
infoUI.SetActive(true);
|
||||
UpdateUI();
|
||||
}
|
||||
|
||||
|
|
@ -53,7 +65,7 @@ public class ActionUIHandler : MonoBehaviour
|
|||
{
|
||||
possibleRanged = isRanged;
|
||||
}
|
||||
if ((!isRanged || !isRanged.fired) && !selectedEntity.hasAttacked)
|
||||
if (!isRanged || !isRanged.fired)
|
||||
{
|
||||
attackButton.gameObject.SetActive(true);
|
||||
reloadButton.gameObject.SetActive(false);
|
||||
|
|
@ -63,7 +75,7 @@ public class ActionUIHandler : MonoBehaviour
|
|||
attackButton.gameObject.SetActive(false);
|
||||
if (isRanged && isRanged.fired)
|
||||
{
|
||||
if (selectedEntity.hasMoved || selectedEntity.hasAttacked)
|
||||
if (selectedEntity.actions < 2)
|
||||
{
|
||||
reloadButton.gameObject.SetActive(false);
|
||||
}
|
||||
|
|
@ -73,27 +85,37 @@ public class ActionUIHandler : MonoBehaviour
|
|||
}
|
||||
}
|
||||
}
|
||||
if (!selectedEntity.hasMoved || !selectedEntity.hasAttacked)
|
||||
{
|
||||
moveButton.gameObject.SetActive(true);
|
||||
switchButton.gameObject.SetActive(true);
|
||||
}
|
||||
if (selectedEntity.hasAttacked && selectedEntity.hasMoved)
|
||||
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);
|
||||
healthText.text = $"{selectedEntity.health}/{selectedEntity.maxHealth}";
|
||||
attackLabel.text = $"Attack: {selectedEntity.currentWeapon.damage}";
|
||||
speedLabel.text = $"Speed: {selectedEntity.maxMovement}";
|
||||
}
|
||||
public void HideUI()
|
||||
{
|
||||
opened = false;
|
||||
actionUI.SetActive(false);
|
||||
weaponUIPanel.gameObject.SetActive(false);
|
||||
foreach (Transform uiObject in transform)
|
||||
{
|
||||
uiObject.gameObject.SetActive(false);
|
||||
}
|
||||
infoUI.SetActive(false);
|
||||
}
|
||||
|
||||
public void ReloadGun()
|
||||
{
|
||||
possibleRanged.Reload();
|
||||
selectedEntity.hasAttacked = true;
|
||||
selectedEntity.actions -= 2;
|
||||
HideUI();
|
||||
}
|
||||
|
||||
|
|
@ -145,7 +167,7 @@ public class ActionUIHandler : MonoBehaviour
|
|||
|
||||
public void SelectWeapon(Weapon weaponSelected)
|
||||
{
|
||||
MoveAction();
|
||||
selectedEntity.actions--;
|
||||
selectedEntity.SwitchWeapon(weaponSelected);
|
||||
HideWeaponList();
|
||||
UpdateUI();
|
||||
|
|
@ -155,15 +177,4 @@ public class ActionUIHandler : MonoBehaviour
|
|||
{
|
||||
weaponUIPanel.gameObject.SetActive(false);
|
||||
}
|
||||
private void MoveAction()
|
||||
{
|
||||
if (!selectedEntity.hasMoved)
|
||||
{
|
||||
selectedEntity.hasMoved = true;
|
||||
}
|
||||
else if (!selectedEntity.hasAttacked)
|
||||
{
|
||||
selectedEntity.hasAttacked = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
17
Assets/Scripts/CameraController.cs
Normal file
17
Assets/Scripts/CameraController.cs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public class CameraController : MonoBehaviour
|
||||
{
|
||||
public float panSpeed;
|
||||
public bool canMoveCamera = true;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (canMoveCamera)
|
||||
{
|
||||
Vector2 moveDirection = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
|
||||
transform.Translate(moveDirection * (panSpeed * Time.deltaTime));
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/CameraController.cs.meta
Normal file
2
Assets/Scripts/CameraController.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bc0f858f3c02d522db5e0934da8c5766
|
||||
|
|
@ -17,7 +17,8 @@ public class Entity : MonoBehaviour
|
|||
public bool canMove = true;
|
||||
public bool invincible;
|
||||
|
||||
[Header("Animation")]
|
||||
[Header("Animation (assume sprites face right)")]
|
||||
private bool isFacingRight;
|
||||
[SerializeField] private SpriteRenderer[] spriteRenderers;
|
||||
[SerializeField] private float damageColorChangeSpeed;
|
||||
|
||||
|
|
@ -61,6 +62,19 @@ public class Entity : MonoBehaviour
|
|||
currentTile = pathToMove[currentTileList];
|
||||
currentState = 0;
|
||||
currentTileList++;
|
||||
if (currentTileList < pathToMove.Length)
|
||||
{
|
||||
float dotProduct = Vector3.Dot((pathToMove[currentTileList].transform.position - currentTile.transform.position), Vector3.right);
|
||||
if (dotProduct < 0 && !isFacingRight || dotProduct > 0 && isFacingRight)
|
||||
{
|
||||
isFacingRight = !isFacingRight;
|
||||
foreach (SpriteRenderer spriteRenderer in spriteRenderers)
|
||||
{
|
||||
spriteRenderer.gameObject.transform.eulerAngles = new Vector3(0, 0, -spriteRenderer.gameObject.transform.eulerAngles.z);
|
||||
spriteRenderer.flipX = !spriteRenderer.flipX; //quite the jank rotation code
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
yield return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ public class MeleeWeapon : Weapon
|
|||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
RaycastHit2D[] enemyList = Physics2D.BoxCastAll(transform.position, colliderSize, Vector3.Angle(transform.position, mouseWorldPos),
|
||||
PlayerEntityMovement.instance.mouseWorldPos, 100f, entityLayer);
|
||||
PlayerEntityMovement.instance.mouseWorldPos, 2, entityLayer);
|
||||
foreach (RaycastHit2D enemy in enemyList)
|
||||
{
|
||||
if (!enemy.transform.CompareTag(tag) && enemy.transform.TryGetComponent(out Entity isEntity))
|
||||
|
|
@ -28,7 +28,7 @@ public class MeleeWeapon : Weapon
|
|||
}
|
||||
}
|
||||
isAiming = false;
|
||||
thisEntity.hasAttacked = true;
|
||||
thisEntity.actions--;
|
||||
TurnHandler.instance.UpdateTurns();
|
||||
ActionUIHandler.instance.UpdateUI();
|
||||
debugColliderHitbox.gameObject.SetActive(false);
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@ using UnityEngine;
|
|||
|
||||
public class PlayerEntity : Entity
|
||||
{
|
||||
[Header("Player Flags")]
|
||||
public bool hasMoved = false;
|
||||
public bool hasAttacked = false;
|
||||
[Header("Player Flags")]
|
||||
public int actions = 2;
|
||||
public int maxActions = 2;
|
||||
[Header("Weaponry")]
|
||||
[SerializeField] private Weapon[] weapons;
|
||||
[HideInInspector] public List<Weapon> weaponInstances = new();
|
||||
|
|
@ -42,8 +42,7 @@ public class PlayerEntity : Entity
|
|||
|
||||
public void SkipTurn()
|
||||
{
|
||||
hasMoved = true;
|
||||
hasAttacked = true;
|
||||
actions = 0;
|
||||
TurnHandler.instance.UpdateTurns();
|
||||
}
|
||||
public void Attack()
|
||||
|
|
@ -68,7 +67,7 @@ public class PlayerEntity : Entity
|
|||
|
||||
private void OnMouseDown()
|
||||
{
|
||||
if ((!hasMoved || !hasAttacked) && !PlayerEntityMovement.instance.isMoving)
|
||||
if (actions > 0 && !PlayerEntityMovement.instance.isMoving)
|
||||
{
|
||||
ActionUIHandler.instance.ShowUI(this);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
public class PlayerEntityMovement : MonoBehaviour
|
||||
{
|
||||
|
|
@ -66,7 +67,14 @@ public class PlayerEntityMovement : MonoBehaviour
|
|||
requestedTile = newTile;
|
||||
foreach (TileObject tile in pathRequested)
|
||||
{
|
||||
tile.sprite.color = new Color(137, 137, 137, 255);
|
||||
if (!currentMovableTiles.Contains(tile))
|
||||
{
|
||||
tile.sprite.color = new Color32(137, 137, 137, 255);
|
||||
}
|
||||
else
|
||||
{
|
||||
tile.sprite.color = Color.green;
|
||||
}
|
||||
}
|
||||
PathfindToTarget();
|
||||
}
|
||||
|
|
@ -159,14 +167,7 @@ public class PlayerEntityMovement : MonoBehaviour
|
|||
StartCoroutine(selectedEntity.MoveToLocation(pathRequested.ToArray()));
|
||||
templateObject.SetActive(false);
|
||||
UncolorGrid();
|
||||
if (!selectedEntity.hasMoved)
|
||||
{
|
||||
selectedEntity.hasMoved = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
selectedEntity.hasAttacked = true;
|
||||
}
|
||||
selectedEntity.actions--;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ public class RangedWeapon : Weapon
|
|||
CreateProjectile(mousePos);
|
||||
fired = true;
|
||||
isAiming = false;
|
||||
thisEntity.hasAttacked = true;
|
||||
thisEntity.actions--;
|
||||
}
|
||||
else if (Input.GetMouseButtonDown(1))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ public class TurnHandler : MonoBehaviour
|
|||
{
|
||||
foreach (PlayerEntity player in playerEntities)
|
||||
{
|
||||
if (!player.hasMoved || !player.hasAttacked)
|
||||
if (player.actions > 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
@ -82,8 +82,7 @@ public class TurnHandler : MonoBehaviour
|
|||
currentGameState = GameState.PlayerTurn;
|
||||
foreach (PlayerEntity player in playerEntities)
|
||||
{
|
||||
player.hasMoved = false;
|
||||
player.hasAttacked = false;
|
||||
player.actions = player.maxActions;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -96,8 +95,7 @@ public class TurnHandler : MonoBehaviour
|
|||
{
|
||||
foreach (PlayerEntity player in playerEntities)
|
||||
{
|
||||
player.hasMoved = true;
|
||||
player.hasAttacked = true;
|
||||
player.actions = 0;
|
||||
}
|
||||
UpdateTurns();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue