summaryrefslogtreecommitdiff
path: root/scripts/GUI/MainMenu.cs
blob: 0d6c8c6ed94dff41826184f557344e3802f45c31 (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
47
48
49
50
51
52
53
54
55
56
57
using Godot;

namespace TheLegendOfGustav.GUI;

public partial class MainMenu : Control
{
	private Button newGameButton;
	private Button loadGameButton;
	private Button quitButton;
	private Button leaderboardButton;

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

	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");
		leaderboardButton = GetNode<Button>("VBoxContainer/CenterContainer/VBoxContainer/leaderboard");

		newGameButton.Pressed += OnNewGameButtonPressed;
		loadGameButton.Pressed += OnLoadGameButtonPressed;
		quitButton.Pressed += OnQuitButtonPressed;
		leaderboardButton.Pressed += OnLeaderBoardRequest;

		newGameButton.GrabFocus();
		bool hasSaveFile = FileAccess.FileExists("user://save_game.json");
		bool hasLeaderboard = FileAccess.FileExists("user://placar.json");
		loadGameButton.Disabled = !hasSaveFile;
		leaderboardButton.Disabled = !hasLeaderboard;
	}

	private void OnNewGameButtonPressed()
	{
		EmitSignal(SignalName.GameRequest, false);
	}

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

	private void OnLeaderBoardRequest()
	{
		EmitSignal(SignalName.LeaderboardRequest);
	}

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