General UI Work
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.GodotNodeInterfaces;
|
||||
using Chickensoft.Introspection;
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Zennysoft.Game.Ma;
|
||||
using Zennysoft.Ma.Adapter;
|
||||
|
||||
[Meta(typeof(IAutoNode))]
|
||||
public partial class LoadNextLevel : Control, IFloorClearMenu
|
||||
{
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
|
||||
[Dependency] protected IPlayer _player => this.DependOn(() => GetParent().GetChildren().OfType<IPlayer>().Single());
|
||||
|
||||
[Dependency] public IMap _map => this.DependOn<IMap>();
|
||||
|
||||
[Node] public IAnimationPlayer AnimationPlayer { get; set; } = default!;
|
||||
|
||||
[Node] public Button ContinueButton { get; set; }
|
||||
[Node] public Button ExitButton { get; set; }
|
||||
[Node] public Label LevelLabel { get; set; }
|
||||
[Node] public Label EXPLabel { get; set; }
|
||||
[Node] public Label HPLabel { get; set; }
|
||||
[Node] public Label VTLabel { get; set; }
|
||||
[Node] public Label ATKLabel { get; set; }
|
||||
[Node] public Label DEFLabel { get; set; }
|
||||
[Node] public Label FloorNumber { get; set; }
|
||||
|
||||
public void FadeIn() => AnimationPlayer.Play("fade_in");
|
||||
|
||||
public void FadeOut() => AnimationPlayer.Play("fade_out");
|
||||
|
||||
public event Action GoToNextFloor;
|
||||
|
||||
public event Action Exit;
|
||||
|
||||
public event Action TransitionCompleted;
|
||||
|
||||
public void OnResolved()
|
||||
{
|
||||
_player.ExperiencePointsComponent.Level.Sync += Level_Sync;
|
||||
_player.ExperiencePointsComponent.CurrentExp.Sync += Exp_Sync;
|
||||
_player.ExperiencePointsComponent.ExpToNextLevel.Sync += Exp_Sync;
|
||||
_player.HealthComponent.CurrentHP.Sync += HP_Sync;
|
||||
_player.HealthComponent.MaximumHP.Sync += HP_Sync;
|
||||
_player.VTComponent.CurrentVT.Sync += VT_Sync;
|
||||
_player.VTComponent.MaximumVT.Sync += VT_Sync;
|
||||
_player.AttackComponent.CurrentAttack.Sync += Attack_Sync;
|
||||
_player.AttackComponent.MaximumAttack.Sync += Attack_Sync;
|
||||
_player.DefenseComponent.CurrentDefense.Sync += Defense_Sync;
|
||||
_player.DefenseComponent.MaximumDefense.Sync += Defense_Sync;
|
||||
_player.EquipmentComponent.EquipmentChanged += EquipmentComponent_EquipmentChanged;
|
||||
_map.CurrentFloorNumber.Sync += CurrentFloorNumber_Sync;
|
||||
|
||||
AnimationPlayer.AnimationFinished += AnimationPlayer_AnimationFinished;
|
||||
AnimationPlayer.AnimationStarted += AnimationPlayer_AnimationStarted;
|
||||
ContinueButton.Pressed += ContinueButton_Pressed;
|
||||
ExitButton.Pressed += ExitButton_Pressed;
|
||||
}
|
||||
|
||||
private void CurrentFloorNumber_Sync(int _) => FloorNumber.Text = _map.CurrentFloorNumber.Value.ToString("D2");
|
||||
|
||||
private void EquipmentComponent_EquipmentChanged(EquipableItem obj)
|
||||
{
|
||||
Attack_Sync(0);
|
||||
Defense_Sync(0);
|
||||
}
|
||||
|
||||
private void Attack_Sync(int _) => ATKLabel.Text = $"{_player.AttackComponent.CurrentAttack.Value}/{_player.AttackComponent.MaximumAttack.Value}+{_player.EquipmentComponent.BonusAttack}";
|
||||
private void Defense_Sync(int _) => DEFLabel.Text = $"{_player.DefenseComponent.CurrentDefense.Value}/{_player.DefenseComponent.MaximumDefense.Value}+{_player.EquipmentComponent.BonusDefense}";
|
||||
private void HP_Sync(int _) => HPLabel.Text = $"{_player.HealthComponent.CurrentHP.Value}/{_player.HealthComponent.MaximumHP.Value}";
|
||||
private void VT_Sync(int _) => VTLabel.Text = $"{_player.VTComponent.CurrentVT.Value}/{_player.VTComponent.MaximumVT.Value}";
|
||||
private void Exp_Sync(int _) => EXPLabel.Text = $"{_player.ExperiencePointsComponent.CurrentExp.Value}/{_player.ExperiencePointsComponent.ExpToNextLevel.Value}";
|
||||
private void Level_Sync(int _) => LevelLabel.Text = _player.ExperiencePointsComponent.Level.Value.ToString("D2");
|
||||
|
||||
|
||||
private void ExitButton_Pressed()
|
||||
{
|
||||
ContinueButton.Disabled = true;
|
||||
ExitButton.Disabled = true;
|
||||
FadeOut();
|
||||
Exit?.Invoke();
|
||||
}
|
||||
|
||||
private void ContinueButton_Pressed()
|
||||
{
|
||||
ContinueButton.Disabled = true;
|
||||
ExitButton.Disabled = true;
|
||||
GoToNextFloor?.Invoke();
|
||||
}
|
||||
|
||||
private void AnimationPlayer_AnimationStarted(StringName animName)
|
||||
{
|
||||
if (animName == "fade_in")
|
||||
ContinueButton.CallDeferred(MethodName.GrabFocus);
|
||||
if (animName == "fade_out")
|
||||
CallDeferred(MethodName.ReleaseFocus);
|
||||
}
|
||||
|
||||
private void AnimationPlayer_AnimationFinished(StringName animName)
|
||||
{
|
||||
if (animName == "fade_in")
|
||||
{
|
||||
ContinueButton.Disabled = false;
|
||||
ExitButton.Disabled = false;
|
||||
}
|
||||
if (animName == "fade_out")
|
||||
TransitionCompleted?.Invoke();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user