You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
98 lines
3.2 KiB
98 lines
3.2 KiB
using System;
|
|
using System.Threading.Tasks;
|
|
using Babushka.scripts.CSharp.Common.Fight.ActionDetails;
|
|
using Babushka.scripts.CSharp.Common.Fight.UI;
|
|
using Godot;
|
|
using Godot.Collections;
|
|
|
|
namespace Babushka.scripts.CSharp.Common.Fight;
|
|
|
|
|
|
public partial class FighterVisual : Node2D
|
|
{
|
|
#region Shortcuts
|
|
|
|
private FightWorld.FightHappeningData HappeningData =>
|
|
FightWorld.Instance.fightHappeningData ?? throw new NoFightHappeningException();
|
|
|
|
#endregion
|
|
|
|
[ExportCategory("References")]
|
|
[Export] private Node2D _visualParent = null!;
|
|
[Export] private Node2D _targetSelectionParent = null!;
|
|
[Export] public FighterHealthBarVisual healthBarVisual = null!;
|
|
|
|
|
|
private FightWorld.Fighter _boundFighter;
|
|
|
|
public void Initialize(FightWorld.Fighter fighter)
|
|
{
|
|
_boundFighter = fighter;
|
|
UpdateMirrorState();
|
|
UpdateHealthBar();
|
|
}
|
|
|
|
/// <summary>
|
|
/// fighter visuals should always look to the right in the scene.
|
|
/// This function flips the sprites horizontally, when the fighter is an enemy.
|
|
/// </summary>
|
|
private void UpdateMirrorState()
|
|
{
|
|
_visualParent.Scale = new Vector2(_boundFighter.IsInFormation(HappeningData.enemyFighterFormation) ? -1 : 1, 1);
|
|
}
|
|
|
|
public void UpdateHealthBar()
|
|
{
|
|
healthBarVisual.UpdateHealth(_boundFighter.GetHealth(), _boundFighter.maxHealth);
|
|
}
|
|
|
|
public void SetTargetSelectionActive(bool value)
|
|
{
|
|
_targetSelectionParent.Visible = value;
|
|
_targetSelectionParent.ProcessMode = value ? ProcessModeEnum.Inherit : ProcessModeEnum.Disabled;
|
|
}
|
|
|
|
// listen from inside
|
|
public void ClickedTarget()
|
|
{
|
|
if (HappeningData.actionStaging!.CurrentDetail() is not TargetSelectActionDetail targetDetail)
|
|
throw new InvalidOperationException("No target selection needed right now");
|
|
|
|
targetDetail.SetTarget(_boundFighter);
|
|
FightHappening.Instance.DetailFilled();
|
|
}
|
|
|
|
// Animations
|
|
public async Task AnimatePosToTarget(FighterVisual targetVisual, double duration = 0.15)
|
|
{
|
|
var tween = GetTree().CreateTween();
|
|
tween.TweenProperty(_visualParent, "global_position", targetVisual.GlobalPosition, 0.15);
|
|
await ToSignal(tween, "finished");
|
|
}
|
|
|
|
public async Task AnimatePosToBase(double duration = 0.7)
|
|
{
|
|
var tween = GetTree().CreateTween();
|
|
tween.TweenProperty(_visualParent, "position", new Vector2(0, 0), 0.15);
|
|
await ToSignal(tween, "finished");
|
|
}
|
|
|
|
public async Task AnimateHit()
|
|
{
|
|
var tween = GetTree().CreateTween();
|
|
tween.TweenProperty(this, "scale", new Vector2(1.4f, 0.6f), 0.15);
|
|
tween.TweenProperty(this, "scale", new Vector2(1, 1), 0.4)
|
|
.SetTrans(Tween.TransitionType.Cubic).SetEase(Tween.EaseType.Out);
|
|
await ToSignal(tween, "finished");
|
|
}
|
|
|
|
// Keep for reference for new Heal animation
|
|
//public void HealAnimation()
|
|
//{
|
|
// EmitSignalHealed();
|
|
// var tween = GetTree().CreateTween();
|
|
// tween.TweenProperty(this, "scale", new Vector2(0.6f, 1.4f), 0.15);
|
|
// tween.TweenProperty(this, "scale", new Vector2(1, 1), 0.4)
|
|
// .SetTrans(Tween.TransitionType.Cubic).SetEase(Tween.EaseType.Out);
|
|
//}
|
|
} |