AceField/Scripts/UI/HUD.cs

54 lines
1.9 KiB
C#
Raw Normal View History

2024-08-08 09:10:48 +00:00
using AceField.Scripts.Logic;
using Godot;
namespace AceField.Scripts.UI;
public partial class HUD : Control
{
[Export] public World World;
private void ApplySize()
{
var screenSize = GetViewportRect().Size;
Position = new Vector2(0, 0);
Size = screenSize;
2024-08-08 18:20:56 +00:00
GetNode<HBoxContainer>("TopBox").Size = new Vector2(screenSize.X - 16 * 2, 16);
2024-08-08 09:10:48 +00:00
}
public override void _Process(double delta)
{
var roundBar = GetNode<ProgressBar>("BottomBox/ProgressBar");
roundBar.Value = World.RoundProgress * 100;
var roundLabel = GetNode<Label>("BottomBox/HBox/RoundLabel");
2024-08-09 07:45:40 +00:00
roundLabel.Text = $"Round {World.RoundCount:00}/{World.RoundTotalCount:00}";
2024-08-08 09:10:48 +00:00
var player = World.GetCurrentPlayer();
if (player == null) return;
2024-08-08 18:20:56 +00:00
2024-08-08 09:10:48 +00:00
var healthBar = GetNode<ProgressBar>("TopBox/HealthBox/Bar");
var healthLabel = GetNode<Label>("TopBox/HealthBox/Label");
healthBar.Value = player.Health / player.MaxHealth * 100;
healthLabel.Text = $"Health {player.Health}/{player.MaxHealth}";
2024-08-08 18:20:56 +00:00
2024-08-08 09:10:48 +00:00
var actionBar = GetNode<ProgressBar>("TopBox/ActionPointBox/Bar");
var actionLabel = GetNode<Label>("TopBox/ActionPointBox/Label");
actionBar.Value = player.ActionPoints / player.MaxActionPoints * 100;
actionLabel.Text = $"AP {player.ActionPoints}/{player.MaxActionPoints}";
2024-08-08 18:20:56 +00:00
2024-08-08 09:10:48 +00:00
var ammoBar = GetNode<ProgressBar>("TopBox/AmmoBox/Bar");
var ammoLabel = GetNode<Label>("TopBox/AmmoBox/Label");
2024-08-08 18:20:56 +00:00
ammoBar.Value = (float)player.AmmoAmount / player.MaxAmmoAmount * 100;
ammoLabel.Text = player.IsReloading
? $"Reloading... {player.TimeRemainingOfReload:F2}"
: $"Ammo {player.AmmoAmount}/{player.MaxAmmoAmount}";
var positionLabel = GetNode<Label>("BottomBox/HBox/PositionLabel");
positionLabel.Text = $"({player.Position.X:F2}, {player.Position.Y:F2})";
2024-08-09 05:49:04 +00:00
var scoreLabel = GetNode<Label>("BottomBox/HBox/ScoreLabel");
scoreLabel.Text = $"Score {World.Scoreboard.GetCurrentData()?.Score.ToString() ?? "-"}";
2024-08-08 09:10:48 +00:00
}
}