mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:15:33 +00:00
107 lines
No EOL
2.6 KiB
C#
107 lines
No EOL
2.6 KiB
C#
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
|
|
{
|
|
[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; }
|
|
|
|
private int _currentPanelIndex;
|
|
|
|
private List<TextureRect> _panels = new ();
|
|
|
|
public TextureRect CurrentPanel => _panels[_currentPanelIndex];
|
|
|
|
private double _timer = 0f;
|
|
|
|
private bool _running = false;
|
|
|
|
public override void _Ready()
|
|
{
|
|
_timer = 0;
|
|
_running = true;
|
|
|
|
foreach (var image in Images)
|
|
{
|
|
var panel = new TextureRect();
|
|
panel.Texture = image;
|
|
panel.ExpandMode = TextureRect.ExpandModeEnum.KeepSize;
|
|
panel.StretchMode = TextureRect.StretchModeEnum.KeepAspectCentered;
|
|
panel.Visible = false;
|
|
panel.SetModulate(new Color(panel.Modulate.R, panel.Modulate.G, panel.Modulate.B, 0f));
|
|
|
|
PanelsHolder.CallDeferred("add_child", panel);
|
|
|
|
_panels.Add(panel);
|
|
}
|
|
|
|
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)
|
|
{
|
|
if (!_running) return;
|
|
|
|
_timer += delta;
|
|
|
|
if (_timer >= TransitionTime)
|
|
{
|
|
_timer = 0;
|
|
_currentPanelIndex++;
|
|
|
|
if (_currentPanelIndex >= _panels.Count)
|
|
{
|
|
_running = false;
|
|
Finished();
|
|
return;
|
|
}
|
|
|
|
_running = false;
|
|
|
|
_ = Transition();
|
|
}
|
|
}
|
|
|
|
private void Finished()
|
|
{
|
|
GetTree().ChangeSceneToFile(NextSceneName);
|
|
}
|
|
|
|
private async Task Transition()
|
|
{
|
|
TextureRect previousPanel = _panels[_currentPanelIndex-1];
|
|
|
|
CurrentPanel.Visible = true;
|
|
|
|
var tween = GetTree().CreateTween();
|
|
tween.SetEase(Tween.EaseType.InOut);
|
|
tween.SetTrans(Tween.TransitionType.Linear);
|
|
tween.TweenProperty(previousPanel, "modulate:a", 0f, 1f);
|
|
|
|
tween.TweenProperty(CurrentPanel, "modulate:a", 1f, 1f);
|
|
|
|
await ToSignal(tween, "finished");
|
|
|
|
previousPanel.Visible = false;
|
|
|
|
_running = true;
|
|
}
|
|
} |