-
Notifications
You must be signed in to change notification settings - Fork 0
/
Menu.cs
58 lines (52 loc) · 1.65 KB
/
Menu.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
using Godot;
using System;
public partial class Menu : Node
{
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
GetNode<AnimationPlayer>("/root/RootScene/Menu/LOGO/AnimationPlayer").Play("LOGO Animation");
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
}
private void StartGame(bool IsControledByMouse=true)
{
var scene = GD.Load<PackedScene>("res://GameScene.tscn");
GetNode<Node>("/root/RootScene/Menu").QueueFree();
GetNode<Node>("/root/RootScene/").AddChild(scene.Instantiate());
GetNode<Node>("/root/RootScene/GameScene").GetTree().Paused = true;
GetNode<Plane>("/root/RootScene/GameScene/Plane").IsControledByMouse = IsControledByMouse;
}
private void _on_btn_mouse_pressed()
{
int sel = GetNode<OptionButton>("/root/RootScene/Menu/OptionButton").Selected;
Levels.SelectedLevel = (Levels.Lvl)sel;
StartGame(IsControledByMouse: true);
}
private void _on_btn_keyboard_pressed()
{
int sel = GetNode<OptionButton>("/root/RootScene/Menu/OptionButton").Selected;
Levels.SelectedLevel = (Levels.Lvl)sel;
StartGame(IsControledByMouse: false);
}
private void _on_option_sound_item_selected(long index)
{
if (index == 0) {
AudioServer.SetBusVolumeDb(AudioServer.GetBusIndex("Master"), 0);
}
else {
AudioServer.SetBusVolumeDb(AudioServer.GetBusIndex("Master"), -80);
}
}
private void _on_option_sfx_item_selected(long index)
{
if (index == 0) {
AudioServer.SetBusVolumeDb(AudioServer.GetBusIndex("SFX"), 0);
}
else {
AudioServer.SetBusVolumeDb(AudioServer.GetBusIndex("SFX"), -80);
}
}
}