Added basic action animation
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
[gd_scene load_steps=10 format=3 uid="uid://cjshlwk8ajpnp"]
|
[gd_scene load_steps=11 format=3 uid="uid://cjshlwk8ajpnp"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://cnhpnn8o0gybd" path="res://scripts/CSharp/Common/Fight/FightHappeningSceneSetup.cs" id="1_fiutj"]
|
[ext_resource type="Script" uid="uid://cnhpnn8o0gybd" path="res://scripts/CSharp/Common/Fight/FightHappeningSceneSetup.cs" id="1_fiutj"]
|
||||||
[ext_resource type="Script" uid="uid://c76mhhqyk4lgh" path="res://scripts/CSharp/Common/Fight/FightHappening.cs" id="1_gsk03"]
|
[ext_resource type="Script" uid="uid://c76mhhqyk4lgh" path="res://scripts/CSharp/Common/Fight/FightHappening.cs" id="1_gsk03"]
|
||||||
|
[ext_resource type="Script" uid="uid://dtf4ejct4m682" path="res://scripts/CSharp/Common/Fight/ActionAnimationController.cs" id="2_7kjgs"]
|
||||||
[ext_resource type="Script" uid="uid://dwsqst8fhhqlc" path="res://scripts/CSharp/Common/Fight/AllFightersVisual.cs" id="2_lu4y4"]
|
[ext_resource type="Script" uid="uid://dwsqst8fhhqlc" path="res://scripts/CSharp/Common/Fight/AllFightersVisual.cs" id="2_lu4y4"]
|
||||||
[ext_resource type="PackedScene" uid="uid://bcld43daavmrn" path="res://prefabs/fight/fight_scene_switcher.tscn" id="2_phrlx"]
|
[ext_resource type="PackedScene" uid="uid://bcld43daavmrn" path="res://prefabs/fight/fight_scene_switcher.tscn" id="2_phrlx"]
|
||||||
[ext_resource type="PackedScene" uid="uid://7jsxokx67gpq" path="res://prefabs/fight/fighterVisuals/vesna_fighter_visual.tscn" id="4_qo0gi"]
|
[ext_resource type="PackedScene" uid="uid://7jsxokx67gpq" path="res://prefabs/fight/fighterVisuals/vesna_fighter_visual.tscn" id="4_qo0gi"]
|
||||||
@@ -15,6 +16,14 @@
|
|||||||
[node name="FightHappening" type="Node" parent="."]
|
[node name="FightHappening" type="Node" parent="."]
|
||||||
script = ExtResource("1_gsk03")
|
script = ExtResource("1_gsk03")
|
||||||
|
|
||||||
|
[node name="ActionAnimationController" type="Node" parent="." node_paths=PackedStringArray("_allFightersVisual")]
|
||||||
|
script = ExtResource("2_7kjgs")
|
||||||
|
_allFightersVisual = NodePath("../FightVisuals")
|
||||||
|
|
||||||
|
[node name="StateReactionActionAnimation" type="Node" parent="ActionAnimationController"]
|
||||||
|
script = ExtResource("4_ydj1i")
|
||||||
|
_fightState = 10
|
||||||
|
|
||||||
[node name="Camera2D" type="Camera2D" parent="."]
|
[node name="Camera2D" type="Camera2D" parent="."]
|
||||||
|
|
||||||
[node name="FightSetup" type="Node2D" parent="."]
|
[node name="FightSetup" type="Node2D" parent="."]
|
||||||
@@ -159,20 +168,31 @@ text = "This text explains the currently hovered button"
|
|||||||
script = ExtResource("4_ydj1i")
|
script = ExtResource("4_ydj1i")
|
||||||
_fightState = 6
|
_fightState = 6
|
||||||
|
|
||||||
[node name="StateMachineDebugger" type="Node" parent="." node_paths=PackedStringArray("_label")]
|
[node name="StateMachineDebugger" type="Node" parent="." node_paths=PackedStringArray("_label", "_current")]
|
||||||
script = ExtResource("8_tv7cl")
|
script = ExtResource("8_tv7cl")
|
||||||
_label = NodePath("Label")
|
_label = NodePath("Label")
|
||||||
|
_current = NodePath("Current")
|
||||||
|
|
||||||
[node name="Label" type="Label" parent="StateMachineDebugger"]
|
[node name="Label" type="Label" parent="StateMachineDebugger"]
|
||||||
offset_left = -973.0
|
offset_left = -982.0
|
||||||
offset_top = -500.0
|
offset_top = -497.0
|
||||||
offset_right = -523.0
|
offset_right = -893.0
|
||||||
offset_bottom = 444.0
|
offset_bottom = -474.0
|
||||||
|
text = "Hello world"
|
||||||
|
|
||||||
|
[node name="Current" type="Label" parent="StateMachineDebugger"]
|
||||||
|
offset_left = 705.0
|
||||||
|
offset_top = -495.0
|
||||||
|
offset_right = 794.0
|
||||||
|
offset_bottom = -472.0
|
||||||
text = "Hello world"
|
text = "Hello world"
|
||||||
|
|
||||||
[connection signal="SignalTransitionState" from="FightHappening" to="FightVisuals" method="FightHappeningStateChange"]
|
[connection signal="SignalTransitionState" from="FightHappening" to="FightVisuals" method="FightHappeningStateChange"]
|
||||||
[connection signal="SignalTransitionState" from="FightHappening" to="ActionSelect/StateReactionInputActionSelect" method="FightHappeningStateTransitioned"]
|
[connection signal="SignalTransitionState" from="FightHappening" to="ActionSelect/StateReactionInputActionSelect" method="FightHappeningStateTransitioned"]
|
||||||
[connection signal="SignalTransitionState" from="FightHappening" to="StateMachineDebugger" method="StateChange"]
|
[connection signal="SignalTransitionState" from="FightHappening" to="StateMachineDebugger" method="StateChange"]
|
||||||
|
[connection signal="SignalTransitionState" from="FightHappening" to="ActionAnimationController/StateReactionActionAnimation" method="FightHappeningStateTransitioned"]
|
||||||
|
[connection signal="OnStateEntered" from="ActionAnimationController/StateReactionActionAnimation" to="ActionAnimationController" method="StateEnter"]
|
||||||
|
[connection signal="OnStateExited" from="ActionAnimationController/StateReactionActionAnimation" to="ActionAnimationController" method="StateExit"]
|
||||||
[connection signal="pressed" from="ActionSelect/BottomPanel/VBoxContainer/MarginContainer/HBoxContainer/MarginContainer/AttackButton" to="ActionSelect" method="SelectAction" binds= [1]]
|
[connection signal="pressed" from="ActionSelect/BottomPanel/VBoxContainer/MarginContainer/HBoxContainer/MarginContainer/AttackButton" to="ActionSelect" method="SelectAction" binds= [1]]
|
||||||
[connection signal="pressed" from="ActionSelect/BottomPanel/VBoxContainer/MarginContainer/HBoxContainer/MarginContainer2/Summon Button" to="ActionSelect" method="SelectAction" binds= [2]]
|
[connection signal="pressed" from="ActionSelect/BottomPanel/VBoxContainer/MarginContainer/HBoxContainer/MarginContainer2/Summon Button" to="ActionSelect" method="SelectAction" binds= [2]]
|
||||||
[connection signal="pressed" from="ActionSelect/BottomPanel/VBoxContainer/MarginContainer/HBoxContainer/MarginContainer3/Talk Button" to="ActionSelect" method="SelectAction" binds= [3]]
|
[connection signal="pressed" from="ActionSelect/BottomPanel/VBoxContainer/MarginContainer/HBoxContainer/MarginContainer3/Talk Button" to="ActionSelect" method="SelectAction" binds= [3]]
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
using Godot;
|
||||||
|
|
||||||
|
namespace Babushka.scripts.CSharp.Common.Fight;
|
||||||
|
|
||||||
|
public partial class ActionAnimationController : Node
|
||||||
|
{
|
||||||
|
#region Shortcuts
|
||||||
|
|
||||||
|
private FightWorld.FightHappeningData HappeningData => FightWorld.Instance.fightHappeningData ?? throw new NoFightHappeningException();
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
[Export] private AllFightersVisual _allFightersVisual = null!;
|
||||||
|
|
||||||
|
|
||||||
|
public void StateEnter()
|
||||||
|
{
|
||||||
|
_ = HappeningData.actionStaging!.AnimateAction(_allFightersVisual);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void StateExit()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
uid://dtf4ejct4m682
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Babushka.scripts.CSharp.Common.Fight.ActionDetails;
|
using Babushka.scripts.CSharp.Common.Fight.ActionDetails;
|
||||||
using Babushka.scripts.CSharp.Common.Util;
|
using Babushka.scripts.CSharp.Common.Util;
|
||||||
using Godot;
|
using Godot;
|
||||||
@@ -43,4 +44,17 @@ public class AllyAttackAction : FighterAction
|
|||||||
{
|
{
|
||||||
targetSelect.GetTarget().AddHealth(-5);
|
targetSelect.GetTarget().AddHealth(-5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override async Task AnimateAction(AllFightersVisual allFightersVisual)
|
||||||
|
{
|
||||||
|
var currentFighter = HappeningData.fighterStack.Current;
|
||||||
|
var targetFighter = targetSelect.GetTarget();
|
||||||
|
|
||||||
|
var currentFighterVisual = allFightersVisual.GetVisualForFighter(currentFighter);
|
||||||
|
var targetFighterVisual = allFightersVisual.GetVisualForFighter(targetFighter);
|
||||||
|
|
||||||
|
await currentFighterVisual.AnimatePosToTarget(targetFighterVisual);
|
||||||
|
_ = targetFighterVisual.AnimateHit();
|
||||||
|
await currentFighterVisual.AnimatePosToBase();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -122,4 +122,11 @@ public partial class AllFightersVisual : Node
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
public FighterVisual GetVisualForFighter(FightWorld.Fighter fighter)
|
||||||
|
{
|
||||||
|
return _fighterVisuals.TryGetValue(fighter, out var visual)
|
||||||
|
? visual
|
||||||
|
: throw new InvalidOperationException("No visual for this fighter");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -7,10 +7,13 @@ public partial class FightHappeningStateDebugger : Node
|
|||||||
{
|
{
|
||||||
[Export] private Label _label;
|
[Export] private Label _label;
|
||||||
|
|
||||||
|
[Export] private Label _current;
|
||||||
|
|
||||||
private FightWorld.FightHappeningData Data => FightWorld.Instance.fightHappeningData!;
|
private FightWorld.FightHappeningData Data => FightWorld.Instance.fightHappeningData!;
|
||||||
|
|
||||||
public void StateChange(FightHappening.FightState from, FightHappening.FightState to)
|
public void StateChange(FightHappening.FightState from, FightHappening.FightState to)
|
||||||
{
|
{
|
||||||
|
_current.Text = $"{to}";
|
||||||
_label.Text += $"State changed from {from} to {to}\n";
|
_label.Text += $"State changed from {from} to {to}\n";
|
||||||
switch (to)
|
switch (to)
|
||||||
{
|
{
|
||||||
@@ -49,5 +52,6 @@ public partial class FightHappeningStateDebugger : Node
|
|||||||
default:
|
default:
|
||||||
throw new ArgumentOutOfRangeException(nameof(to), to, null);
|
throw new ArgumentOutOfRangeException(nameof(to), to, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,8 @@ public abstract class FighterAction
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Animates the action.
|
/// Animates the action.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual async Task AnimateAction()
|
/// <param name="allFightersVisual"></param>
|
||||||
|
public virtual async Task AnimateAction(AllFightersVisual allFightersVisual)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Babushka.scripts.CSharp.Common.Fight.ActionDetails;
|
using Babushka.scripts.CSharp.Common.Fight.ActionDetails;
|
||||||
using Godot;
|
using Godot;
|
||||||
using Godot.Collections;
|
using Godot.Collections;
|
||||||
@@ -67,31 +68,55 @@ public partial class FighterVisual : Node2D
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Animations
|
// Animations
|
||||||
public void AttackAnimation(FightAttack attack)
|
//public void AttackAnimation(FightAttack attack)
|
||||||
|
//{
|
||||||
|
// EmitSignalAttacking();
|
||||||
|
// var tween = GetTree().CreateTween();
|
||||||
|
// tween.TweenProperty(this, "global_position", attack.target.GlobalPosition, 0.15);
|
||||||
|
// tween.TweenCallback(Callable.From(() => attack.target?.HitAnimation(attack)));
|
||||||
|
// tween.TweenProperty(this, "position", new Vector2(0, 0), 0.7)
|
||||||
|
// .SetTrans(Tween.TransitionType.Cubic).SetEase(Tween.EaseType.Out);
|
||||||
|
//}
|
||||||
|
|
||||||
|
public async Task AnimatePosToTarget(FighterVisual targetVisual, double duration = 0.15)
|
||||||
{
|
{
|
||||||
EmitSignalAttacking();
|
|
||||||
var tween = GetTree().CreateTween();
|
var tween = GetTree().CreateTween();
|
||||||
tween.TweenProperty(this, "global_position", attack.target.GlobalPosition, 0.15);
|
tween.TweenProperty(_visualParent, "global_position", targetVisual.GlobalPosition, 0.15);
|
||||||
tween.TweenCallback(Callable.From(() => attack.target?.HitAnimation(attack)));
|
await ToSignal(tween, "finished");
|
||||||
tween.TweenProperty(this, "position", new Vector2(0, 0), 0.7)
|
|
||||||
.SetTrans(Tween.TransitionType.Cubic).SetEase(Tween.EaseType.Out);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HitAnimation(FightAttack attack)
|
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()
|
||||||
{
|
{
|
||||||
EmitSignalDamageTaken();
|
|
||||||
var tween = GetTree().CreateTween();
|
var tween = GetTree().CreateTween();
|
||||||
tween.TweenProperty(this, "scale", new Vector2(1.4f, 0.6f), 0.15);
|
tween.TweenProperty(this, "scale", new Vector2(1.4f, 0.6f), 0.15);
|
||||||
tween.TweenProperty(this, "scale", new Vector2(1, 1), 0.4)
|
tween.TweenProperty(this, "scale", new Vector2(1, 1), 0.4)
|
||||||
.SetTrans(Tween.TransitionType.Cubic).SetEase(Tween.EaseType.Out);
|
.SetTrans(Tween.TransitionType.Cubic).SetEase(Tween.EaseType.Out);
|
||||||
|
await ToSignal(tween, "finished");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void HealAnimation()
|
//private void HitAnimation(FightAttack attack)
|
||||||
{
|
//{
|
||||||
EmitSignalHealed();
|
// EmitSignalDamageTaken();
|
||||||
var tween = GetTree().CreateTween();
|
// var tween = GetTree().CreateTween();
|
||||||
tween.TweenProperty(this, "scale", new Vector2(0.6f, 1.4f), 0.15);
|
// tween.TweenProperty(this, "scale", new Vector2(1.4f, 0.6f), 0.15);
|
||||||
tween.TweenProperty(this, "scale", new Vector2(1, 1), 0.4)
|
// tween.TweenProperty(this, "scale", new Vector2(1, 1), 0.4)
|
||||||
.SetTrans(Tween.TransitionType.Cubic).SetEase(Tween.EaseType.Out);
|
// .SetTrans(Tween.TransitionType.Cubic).SetEase(Tween.EaseType.Out);
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
|
//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);
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user