summaryrefslogtreecommitdiff
path: root/scripts/GUI/MainMenu.cs
blob: 4d89b36ef53ae3cc6bd5dec946f568d89a8d7faa (plain)
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
using Godot;

namespace TheLegendOfGustav.GUI;

public partial class MainMenu : Control
{
	private Button NewGameButton;
	private Button LoadGameButton;
	private Button QuitButton;

	[Signal]
	public delegate void GameRequestEventHandler(bool load);

	public override void _Ready()
	{
		base._Ready();

		NewGameButton = GetNode<Button>("VBoxContainer/CenterContainer/VBoxContainer/neogame");
		LoadGameButton = GetNode<Button>("VBoxContainer/CenterContainer/VBoxContainer/continue");
		QuitButton = GetNode<Button>("VBoxContainer/CenterContainer/VBoxContainer/quit");

		NewGameButton.Pressed += OnNewGameButtonPressed;
		LoadGameButton.Pressed += OnLoadGameButtonPressed;
		QuitButton.Pressed += OnQuitButtonPressed;

		NewGameButton.GrabFocus();
		bool hasSaveFile = FileAccess.FileExists("user://save.dat");
		LoadGameButton.Disabled = !hasSaveFile;
	}

	private void OnNewGameButtonPressed()
	{
		GD.Print("Signal EMIT!");
		EmitSignal(SignalName.GameRequest, false);
	}

	private void OnLoadGameButtonPressed()
	{
		EmitSignal(SignalName.GameRequest, true);
	}

	private void OnQuitButtonPressed()
	{
		GetTree().Quit();
	}
}