Move files and folders to new repo format to enable multi-project format
This commit is contained in:
90
Zennysoft.Game.Ma/src/ui/player_ui/PlayerInfoUI.cs
Normal file
90
Zennysoft.Game.Ma/src/ui/player_ui/PlayerInfoUI.cs
Normal file
@@ -0,0 +1,90 @@
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.GodotNodeInterfaces;
|
||||
using Chickensoft.Introspection;
|
||||
using Godot;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
public interface IPlayerInfoUI : IControl
|
||||
{
|
||||
public void DisplayMessage(string message);
|
||||
}
|
||||
|
||||
[Meta(typeof(IAutoNode))]
|
||||
public partial class PlayerInfoUI : Control, IPlayerInfoUI
|
||||
{
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
|
||||
private LabelSettings _labelSettings { get; set; }
|
||||
|
||||
#region Nodes
|
||||
[Node] public VBoxContainer PlayerInfo { get; set; } = default!;
|
||||
|
||||
[Node] public Label LevelNumber { get; set; } = default!;
|
||||
|
||||
[Node] public Label HPNumber { get; set; } = default!;
|
||||
|
||||
[Node] public Label VTNumber { get; set; } = default!;
|
||||
#endregion
|
||||
|
||||
[Dependency] public IPlayer Player => this.DependOn<IPlayer>();
|
||||
|
||||
public void OnResolved()
|
||||
{
|
||||
_labelSettings = GD.Load<LabelSettings>("res://src/ui/label_settings/InventoryFullAlertLabelSetting.tres");
|
||||
Player.Stats.CurrentHP.Sync += CurrentHP_Sync;
|
||||
Player.Stats.MaximumHP.Sync += MaximumHP_Sync;
|
||||
|
||||
Player.Stats.CurrentVT.Sync += CurrentVT_Sync;
|
||||
Player.Stats.MaximumVT.Sync += MaximumVT_Sync;
|
||||
|
||||
Player.Stats.CurrentLevel.Sync += CurrentLevel_Sync;
|
||||
}
|
||||
|
||||
private void CurrentLevel_Sync(int obj)
|
||||
{
|
||||
LevelNumber.Text = $"{obj}";
|
||||
}
|
||||
|
||||
private void MaximumVT_Sync(int obj)
|
||||
{
|
||||
VTNumber.Text = $"{Player.Stats.CurrentVT.Value}/{obj}";
|
||||
}
|
||||
|
||||
private void CurrentVT_Sync(int obj)
|
||||
{
|
||||
VTNumber.Text = $"{obj}/{Player.Stats.MaximumVT.Value}";
|
||||
}
|
||||
|
||||
private void MaximumHP_Sync(int obj)
|
||||
{
|
||||
HPNumber.Text = $"{Player.Stats.CurrentHP.Value}/{obj}";
|
||||
}
|
||||
|
||||
private void CurrentHP_Sync(int obj)
|
||||
{
|
||||
HPNumber.Text = $"{obj}/{Player.Stats.MaximumHP.Value}";
|
||||
}
|
||||
|
||||
public async void DisplayInventoryFullMessage(string rejectedItemName)
|
||||
{
|
||||
var newLabel = new Label() { Text = $"Could not pick up {rejectedItemName}.", LabelSettings = _labelSettings };
|
||||
PlayerInfo.AddChild(newLabel);
|
||||
|
||||
GetTree().CreateTimer(3f).Timeout += () =>
|
||||
{
|
||||
PlayerInfo.RemoveChild(newLabel);
|
||||
};
|
||||
}
|
||||
|
||||
public async void DisplayMessage(string message)
|
||||
{
|
||||
var newLabel = new Label() { Text = message, LabelSettings = _labelSettings };
|
||||
PlayerInfo.AddChild(newLabel);
|
||||
|
||||
GetTree().CreateTimer(3f).Timeout += () =>
|
||||
{
|
||||
PlayerInfo.RemoveChild(newLabel);
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user