-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainMenu.cs
More file actions
131 lines (95 loc) · 2.99 KB
/
MainMenu.cs
File metadata and controls
131 lines (95 loc) · 2.99 KB
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
using Attack.Game;
using Attack.Options;
using Attack.Util;
using Godot;
using Serilog;
using System;
using System.Collections.Generic;
using System.Linq;
public partial class MainMenu : Control
{
private GameMaster _gameMaster;
private VBoxContainer _container;
private Button _back;
private PanelContainer _loadPanel;
private GridContainer _grid;
private List<GameInstance> _games;
private List<Node> _loadGameNodes = new List<Node>();
public override void _Ready()
{
Log.Information("Loading main menu");
_container = GetNode<VBoxContainer>("VBoxContainer");
_gameMaster = GetNode<GameMaster>("/root/GameMaster");
_back = GetNode<Button>("BackButton");
_loadPanel = GetNode<PanelContainer>("PanelContainer");
_grid = GetNode<GridContainer>("PanelContainer/GridContainer");
if (_gameMaster.CanLoadGames())
{
Log.Debug("Can load games");
var continueButton = GetNode<Button>("VBoxContainer/ContinueButton");
var loadButton = GetNode<Button>("VBoxContainer/LoadGameButton");
continueButton.Disabled = false;
loadButton.Disabled = false;
}
_container.GetChildren()
.OfType<Button>()
.First(c => !c.Disabled)
.GrabFocus();
_games = _gameMaster.ListLoadableGames();
OptionsManager.Load();
Log.Debug("Main menu loaded");
}
public void OnContinuePressed()
{
Log.Debug("Continue");
_gameMaster.Continue();
}
public void OnLoadGamePressed()
{
Log.Debug("LoadGame");
LoadGameNodes();
ToggleLoadVisibility();
}
public void OnNewGamePressed()
{
Log.Debug("NewGame");
_gameMaster.New();
}
public void OnOptionsPressed()
{
Log.Debug("Options");
GetTree().ChangeSceneToFile("res://options_menu.tscn");
}
public void OnQuitPressed()
{
Log.Information("Quitting via button");
GetTree().Root.PropagateNotification((int)NotificationWMCloseRequest);
}
public void OnBackPressed()
{
Log.Debug("Back pressed");
ToggleLoadVisibility();
_loadGameNodes.ForEach(n => n.QueueFree());
}
private void ToggleLoadVisibility ()
{
_container.GetChildren()
.OfType<Button>()
.ToList()
.ForEach(c => c.Visible = !c.Visible);
_back.Visible = !_back.Visible;
_loadPanel.Visible = !_loadPanel.Visible;
}
private void LoadGameNodes()
{
foreach (var game in _games)
{
var updated = new Label() { Text = game.UpdateDate?.ToString(Constants.DateStringFormat) };
var button = new Button() { Text = "Load" };
button.Pressed += () => _gameMaster.Load(game.Id);
_loadGameNodes.Add(updated);
_loadGameNodes.Add(button);
}
_loadGameNodes.ForEach(n => _grid.AddChild(n));
}
}