cirnogodot/Scripts/UI/IntroScenePlayer.cs

74 lines
1.6 KiB
C#
Raw Normal View History

2025-02-19 17:38:54 +01:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Godot;
using Godot.Collections;
namespace Cirno.Scripts.UI;
public partial class IntroScenePlayer : CanvasLayer
{
2025-02-25 14:06:41 +01:00
[Export] public bool StartRunning { get; private set; }
2025-02-19 17:38:54 +01:00
[Export]
public Control PanelsHolder { get; private set; }
[Export]
public Array<Texture2D> Images { get; private set; }
[Export]
public float TransitionTime = 5f;
[Export]
public string NextSceneName { get; set; }
2025-02-25 14:06:41 +01:00
[Export]
public AnimationPlayer AnimationPlayer { get; private set; }
2025-02-19 17:38:54 +01:00
private int _currentPanelIndex;
private List<TextureRect> _panels = new ();
public TextureRect CurrentPanel => _panels[_currentPanelIndex];
private bool _running = false;
2025-02-25 14:06:41 +01:00
2025-02-25 18:17:24 +01:00
private bool _isEnding = false;
2025-02-25 14:06:41 +01:00
private void DeferredStartAnimation()
{
AnimationPlayer.Play("intro");
}
2025-02-19 17:38:54 +01:00
public override void _Ready()
{
2025-02-25 14:06:41 +01:00
_running = StartRunning;
2025-02-19 17:38:54 +01:00
2025-02-25 14:06:41 +01:00
DeferredStartAnimation();
}
public void Run()
{
2025-02-19 17:38:54 +01:00
var first = _panels.First();
first.Visible = true;
first.SetModulate(new Color(first.Modulate.R, first.Modulate.G, first.Modulate.B, 1f));
}
public override void _Process(double delta)
{
2025-02-25 18:17:24 +01:00
if (!_isEnding && Input.IsAnythingPressed())
2025-02-25 14:06:41 +01:00
{
Finished();
2025-02-19 17:38:54 +01:00
}
}
2025-02-25 18:17:24 +01:00
2025-02-19 17:38:54 +01:00
private void Finished()
{
2025-02-25 18:17:24 +01:00
if (_isEnding) return;
_isEnding = true;
GlobalState.Instance.GotoScene(NextSceneName);
//GetTree().ChangeSceneToFile(NextSceneName);
2025-02-19 17:38:54 +01:00
}
}