using System.Collections.Generic;
using ColdMint.scripts.debug;
using Godot;
namespace ColdMint.scripts.damage;
///
/// Node representing the damage number
/// 表示伤害数字的节点
///
public partial class DamageNumberNodeSpawn : Marker2D
{
private PackedScene _damageNumberPackedScene;
private Node2D _rootNode;
///
/// The horizontal velocity is in the X positive direction
/// 水平速度的X正方向
///
private int horizontalVelocityPositiveDirection;
///
/// Horizontal velocity in the negative X direction
/// 水平速度的X负方向
///
private int horizontalVelocityNegativeDirection;
///
/// vertical height
/// 垂直高度
///
private int verticalHeight;
///
/// 物理渐变色
/// physical Gradient
///
private Gradient physicalGradient;
///
/// 魔法渐变色
/// magic Gradient
///
private Gradient magicGradient;
///
/// 默认渐变色
/// default Gradient
///
private Gradient defaultGradient;
public override void _Ready()
{
base._Ready();
_damageNumberPackedScene = GD.Load("res://prefab/ui/DamageNumber.tscn") as PackedScene;
_rootNode = GetNode("/root/Game/DamageNumberContainer");
horizontalVelocityPositiveDirection = Config.CellSize * Config.HorizontalSpeedOfDamageNumbers;
horizontalVelocityNegativeDirection = -horizontalVelocityPositiveDirection;
verticalHeight = -Config.CellSize * Config.VerticalVelocityOfDamageNumbers;
physicalGradient = new Gradient();
//物理色 从OpenColor2 到 OpenColor6(红色)
physicalGradient.SetColor(0, new Color("#ffc9c9"));
physicalGradient.SetColor(1, new Color("#fa5252"));
magicGradient = new Gradient();
//魔法色 从OpenColor2 到 OpenColor6(紫色)
magicGradient.SetColor(0, new Color("#d0bfff"));
magicGradient.SetColor(1, new Color("#7950f2"));
defaultGradient = new Gradient();
//默认行为
defaultGradient.SetColor(0, new Color("#ff8787"));
defaultGradient.SetColor(1, new Color("#fa5252"));
}
///
/// Added a damage digital node
/// 添加伤害数字节点
///
///
private void AddDamageNumberNode(Node2D damageNumber)
{
_rootNode.AddChild(damageNumber);
}
///
/// Show damage
/// 显示伤害
///
///
public void Display(DamageTemplate damageTemplate)
{
if (_damageNumberPackedScene == null)
{
return;
}
if (_damageNumberPackedScene.Instantiate() is not DamageNumber damageNumber)
{
return;
}
CallDeferred("AddDamageNumberNode", damageNumber);
damageNumber.Position = GlobalPosition;
if (damageTemplate.MoveLeft)
{
damageNumber.SetVelocity(new Vector2(horizontalVelocityNegativeDirection, verticalHeight));
}
else
{
damageNumber.SetVelocity(new Vector2(horizontalVelocityPositiveDirection, verticalHeight));
}
var damageLabel = damageNumber.GetNode