47 lines
1.5 KiB
C#
47 lines
1.5 KiB
C#
using Godot;
|
|
|
|
public partial class WaveProgress : TextureProgressBar
|
|
{
|
|
private TextureRect head;
|
|
private Tween tween;
|
|
private PackedScene flagScene = ResourceLoader.Load<PackedScene>("uid://drobbh5x1v7mi");
|
|
[Export] private double progressTime = 2.0f;
|
|
[Signal] public delegate void HugeWaveInitiatedEventHandler(int waveNumber);
|
|
|
|
public override void _Ready()
|
|
{
|
|
head = GetNode<TextureRect>("Head");
|
|
}
|
|
public void OnWaveChanged(int to)
|
|
{
|
|
if (Visible == false) Visible = true;
|
|
if (tween != null) tween.Kill();
|
|
tween = CreateTween().SetParallel(true).SetTrans(Tween.TransitionType.Cubic).SetEase(Tween.EaseType.Out);
|
|
tween.TweenProperty(this, "value", to + 1, progressTime);
|
|
tween.TweenProperty(head, "anchor_right", 1.0 - (float)(to + 1.0f) / MaxValue, progressTime);
|
|
tween.TweenProperty(head, "anchor_left", 1.0 - (float)(to + 1.0f) / MaxValue, progressTime);
|
|
}
|
|
public void SetLevelData(AdventureLevelResource resource)
|
|
{
|
|
MaxValue = resource.waves.Count;
|
|
for (int i = 0; i < resource.waves.Count; i++)
|
|
{
|
|
if (resource.waves[i].isHugeWave)
|
|
{
|
|
var flag = flagScene.Instantiate<WaveFlag>();
|
|
AddChild(flag);
|
|
flag.AnchorTop = 0.5f;
|
|
flag.AnchorBottom = 0.5f;
|
|
flag.AnchorLeft = 1.0f - (float)(i + 1) / resource.waves.Count;
|
|
flag.AnchorRight = 1.0f - (float)(i + 1) / resource.waves.Count;
|
|
flag.anim_time = progressTime;
|
|
flag.waveIndex = i;
|
|
HugeWaveInitiated += flag.HugeWaveApproached;
|
|
}
|
|
}
|
|
}
|
|
public void OnHugeWaveApproached(int what)
|
|
{
|
|
EmitSignal(SignalName.HugeWaveInitiated, what);
|
|
}
|
|
}
|