-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainScene.cs
155 lines (128 loc) · 4.48 KB
/
MainScene.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
using Godot;
using System;
using UIAppletAPI;
public class MainScene : Spatial
{
// Declare member variables here. Examples:
// private int a = 2;
// private string b = "text";
AnimationPlayer _animationPlayer;
PackedScene _mainUIScene;
AudioStreamPlayer _introSound;
Trigger _loadMenuTrigger;
Timer _timer;
int _lastTargetFPS = 0;
WorldEnvironment _worldEnvironment;
Viewport _backwaveViewport;
[Export]
public bool SkipIntro = false;
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
_mainUIScene = GD.Load<PackedScene>("res://UI/Main.tscn");
_animationPlayer = GetNode<AnimationPlayer>("AnimationPlayer");
_introSound = GetNode<AudioStreamPlayer>("IntroSound");
_loadMenuTrigger = GetNode<Trigger>("LoadMenuTrigger");
_worldEnvironment = GetNode<WorldEnvironment>("WorldEnvironment");
_backwaveViewport = GetNode<Viewport>("Viewport");
_loadMenuTrigger.Connect("triggered", this, nameof(LoadMenuTriggered));
_animationPlayer.Connect("animation_finished", this, nameof(OnAnimationFinished));
//_animationPlayer.Connect("animation_started", this, nameof(OnAnimationStarted));
if (SkipIntro)
{
GetNode<Label>("MenuLayer/WelcomeLabel").QueueFree();
LoadUIComponents();
}
else
{
_animationPlayer.Play("WelcomeAnimation");
// Loading test timer
_timer = new Timer();
AddChild(_timer);
_timer.WaitTime = 3f;
_timer.OneShot = true;
_timer.Connect("timeout", this, nameof(TestTimerTimeout));
}
// Adds support for glow in GLES 2
if (OS.GetCurrentVideoDriver() == OS.VideoDriver.Gles2)
{
_worldEnvironment.Environment.GlowHdrThreshold = 0.9f;
_worldEnvironment.Environment.GlowIntensity = 1.5f;
_worldEnvironment.Environment.GlowStrength = 1.3f;
//_worldEnvironment.Environment.GlowBlendMode = Godot.Environment.GlowBlendModeEnum.Softlight;
_backwaveViewport.World.Environment.GlowHdrThreshold = 0.9f;
_backwaveViewport.World.Environment.GlowIntensity = 1.4f;
_backwaveViewport.World.Environment.GlowStrength = 1.3f;
_backwaveViewport.World.Environment.GlowLevels__4 = false;
_backwaveViewport.Size = new Vector2(512, 512);
}
}
public override void _Notification(int what)
{
if (what == NotificationWmFocusOut)
{
Visible = false;
Engine.TargetFps = 10;
GetTree().Paused = true;
}
if (what == NotificationWmFocusIn)
{
GetTree().Paused = false;
Visible = true;
Engine.TargetFps = 0;
}
}
void TestTimerTimeout()
{
GD.Print("\"Loading complete\"");
try
{
LoadUIComponents();
_animationPlayer.Play(_animationPlayer.AssignedAnimation);
}
catch (Exception ex)
{
_animationPlayer.Play("ErrorAnimation");
GetNode<Label>("MenuLayer/WelcomeLabel").Text = "Error";
GD.Print("Error while loading UI");
}
}
void LoadUIComponents()
{
//throw new Exception("some error");
MainUI mainUI = _mainUIScene.Instance<MainUI>();
// Add default items
mainUI.MenuItems.Add(new MenuItem() { Title = "Home" });
mainUI.MenuItems.Add(new MenuItem() { Title = "Settings" });
for (int i = 0; i < 18; i++)
{
mainUI.MenuItems.Add(new MenuItem() { Title = Guid.NewGuid().ToString() });
}
GetNode<CanvasLayer>("MenuLayer").AddChild(mainUI);
}
void LoadMenuTriggered(bool triggerValue)
{
if (triggerValue)
{
_animationPlayer.Stop(false);
_timer.Start();
GD.Print("Load stuff - To do");
}
}
void OnAnimationFinished(string animationName)
{
if (animationName == "WelcomeAnimation")
{
Label welcomeLabel = GetNode<Label>("MenuLayer/WelcomeLabel");
if (welcomeLabel != null)
{
welcomeLabel.QueueFree();
}
}
}
// // Called every frame. 'delta' is the elapsed time since the previous frame.
// public override void _Process(float delta)
// {
//
// }
}