121 lines
3.8 KiB
C#
121 lines
3.8 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using Godot;
|
|
|
|
namespace Milimoe.GodotGame;
|
|
|
|
public partial class SplashScreen : Node
|
|
{
|
|
[Export]
|
|
public TextureRect GodotLogo;
|
|
|
|
[Export]
|
|
public TextureRect Logo;
|
|
|
|
[Export]
|
|
public Label Label;
|
|
|
|
[Export]
|
|
public float FadeDuration = 0.5f; // 淡入/淡出持续时间 (秒)
|
|
|
|
[Export]
|
|
public float VisibleDuration = 2.0f; // 显示时间 (秒)
|
|
|
|
[Export]
|
|
public string TitleScenePath = "res://scenes/TitleScreen.tscn"; // 标题场景的路径
|
|
|
|
private Color _initialGodotColor;
|
|
private Color _initialLogoColor;
|
|
private Color _initialLabelColor;
|
|
|
|
public override void _Ready()
|
|
{
|
|
// 检查节点是否为空
|
|
if (GodotLogo == null || Logo == null || Label == null)
|
|
{
|
|
GD.PrintErr("请在编辑器中指定 GodotLogo, Logo, Label 节点!");
|
|
return;
|
|
}
|
|
|
|
// 保存初始颜色
|
|
_initialGodotColor = GodotLogo.SelfModulate;
|
|
_initialLogoColor = Logo.SelfModulate;
|
|
_initialLabelColor = Label.SelfModulate;
|
|
|
|
// 初始时,隐藏 Raincandy 和 Milimoe
|
|
Logo.SelfModulate = new Color(_initialLogoColor.R, _initialLogoColor.G, _initialLogoColor.B, 0.0f);
|
|
Label.SelfModulate = new Color(_initialLabelColor.R, _initialLabelColor.G, _initialLabelColor.B, 0.0f);
|
|
|
|
// 显示 Godot Logo
|
|
GodotLogo.SelfModulate = new Color(_initialGodotColor.R, _initialGodotColor.G, _initialGodotColor.B, 1.0f);
|
|
|
|
// 开始流程
|
|
StartSequence();
|
|
}
|
|
|
|
private async void StartSequence()
|
|
{
|
|
// 等待一段时间
|
|
await Task.Delay(TimeSpan.FromSeconds(VisibleDuration));
|
|
|
|
// 淡出 Godot Logo
|
|
await FadeOutGodot();
|
|
|
|
// 淡入 Raincandy Logo 和 Milimoe Label
|
|
await FadeInRaincandy();
|
|
|
|
// 等待一段时间
|
|
await Task.Delay(TimeSpan.FromSeconds(VisibleDuration));
|
|
|
|
// 淡出 Raincandy Logo 和 Milimoe Label
|
|
await FadeOutRaincandy();
|
|
}
|
|
|
|
private async Task FadeOutGodot()
|
|
{
|
|
Tween tween = CreateTween();
|
|
Color targetColor = new(_initialGodotColor.R, _initialGodotColor.G, _initialGodotColor.B, 0.0f);
|
|
tween.TweenProperty(GodotLogo, "self_modulate", targetColor, FadeDuration);
|
|
await ToSignal(tween, "finished");
|
|
}
|
|
|
|
private async Task FadeInRaincandy()
|
|
{
|
|
Tween tween = CreateTween();
|
|
|
|
// 淡入 Raincandy Logo
|
|
Color targetRaincandyColor = new(_initialLogoColor.R, _initialLogoColor.G, _initialLogoColor.B, 1.0f);
|
|
tween.TweenProperty(Logo, "self_modulate", targetRaincandyColor, FadeDuration);
|
|
|
|
// 同时淡入 Milimoe Label
|
|
Color targetMilimoeColor = new(_initialLabelColor.R, _initialLabelColor.G, _initialLabelColor.B, 1.0f);
|
|
tween.Parallel().TweenProperty(Label, "self_modulate", targetMilimoeColor, FadeDuration);
|
|
|
|
await ToSignal(tween, "finished");
|
|
}
|
|
|
|
private async Task FadeOutRaincandy()
|
|
{
|
|
Tween tween = CreateTween();
|
|
|
|
// 淡出 Raincandy Logo
|
|
Color targetRaincandyColor = new(_initialLogoColor.R, _initialLogoColor.G, _initialLogoColor.B, 0.0f);
|
|
tween.TweenProperty(Logo, "self_modulate", targetRaincandyColor, FadeDuration);
|
|
|
|
// 同时淡出 Milimoe Label
|
|
Color targetMilimoeColor = new(_initialLabelColor.R, _initialLabelColor.G, _initialLabelColor.B, 0.0f);
|
|
tween.Parallel().TweenProperty(Label, "self_modulate", targetMilimoeColor, FadeDuration);
|
|
|
|
tween.TweenProperty(GetNode<ColorRect>("ColorRect"), "self_modulate", new Color(0, 0, 0, 1), 0.5f);
|
|
|
|
await ToSignal(tween, "finished");
|
|
|
|
// 加载游戏常量
|
|
GameConstant.InitGame();
|
|
|
|
// 加载标题场景
|
|
GD.Print("LoadTitleScene!");
|
|
GetTree().ChangeSceneToFile(TitleScenePath);
|
|
}
|
|
}
|