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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
|
using System.Diagnostics;
using Celesteia.Game.ECS;
using Celesteia.Resources;
using Celesteia.Screens;
using Celesteia.UI;
using Celesteia.UI.Elements;
using Celesteia.UI.Properties;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
namespace Celesteia.GUIs {
public class MainMenu : GUI {
public MainMenu(GameInstance game) : base(game, Rect.ScreenFull) {}
private Texture2D logo;
private Texture2D buttonTexture;
private IContainer MainScreen;
private IContainer OptionsScreen;
private IContainer NewWorldScreen;
private IContainer LogoPivot;
private Label Progress;
private Button buttonTemplate;
private float buttonRow(int number) => number * (buttonHeight + buttonSpacing);
private float buttonHeight = 56f;
private float buttonSpacing = 10f;
public override void LoadContent(ContentManager Content) {
logo = Game.Content.Load<Texture2D>("celesteia/logo");
buttonTexture = Game.Content.Load<Texture2D>("sprites/ui/button");
buttonTemplate = new Button(new Rect(
AbsoluteUnit.WithValue(0f),
AbsoluteUnit.WithValue(buttonRow(0)),
AbsoluteUnit.WithValue(250f),
AbsoluteUnit.WithValue(56f)
))
.SetPivotPoint(new Vector2(.5f))
.SetTexture(buttonTexture)
.MakePatches(4)
.SetTextProperties(new TextProperties()
.SetColor(Color.White)
.SetFont(ResourceManager.Fonts.GetFontType("Hobo"))
.SetFontSize(24f)
.SetTextAlignment(TextAlignment.Center))
.SetColorGroup(new ButtonColorGroup(Color.White, Color.Black, Color.Violet, Color.DarkViolet));
// Load all the screens.
LoadMainScreen();
LoadOptionsScreen();
LoadNewWorldScreen();
LoadGlobals();
base.LoadContent(Content);
}
private void LoadMainScreen() {
Root.AddChild(MainScreen = new Container(Rect.ScreenFull));
MainScreen.SetEnabled(true);
IContainer menu = new Container(new Rect(
new ScreenSpaceUnit(.5f, ScreenSpaceUnit.ScreenSpaceOrientation.Horizontal),
new ScreenSpaceUnit(.5f, ScreenSpaceUnit.ScreenSpaceOrientation.Vertical),
AbsoluteUnit.WithValue(250f),
AbsoluteUnit.WithValue(0f)
));
menu.AddChild(LogoPivot = new Container(new Rect(
AbsoluteUnit.WithValue(0f),
new ScreenSpaceUnit(-.25f, ScreenSpaceUnit.ScreenSpaceOrientation.Vertical),
AbsoluteUnit.WithValue(0f),
AbsoluteUnit.WithValue(0f)
)));
float logoRatio = logo.Height / (float) logo.Width;
LogoPivot.AddChild(
new Image(new Rect(
AbsoluteUnit.WithValue(0f),
AbsoluteUnit.WithValue(0f),
new ScreenSpaceUnit(.4f, ScreenSpaceUnit.ScreenSpaceOrientation.Horizontal),
new ScreenSpaceUnit(.4f * logoRatio, ScreenSpaceUnit.ScreenSpaceOrientation.Horizontal)
))
.SetTexture(logo)
.SetColor(Color.White)
.SetPivotPoint(new Vector2(.5f))
);
menu.AddChild(
buttonTemplate.Clone()
.SetNewRect(buttonTemplate.GetRect()
.SetY(AbsoluteUnit.WithValue(buttonRow(0)))
.SetWidth(new RelativeUnit(1f, menu.GetRect(), RelativeUnit.Orientation.Horizontal))
)
.SetOnMouseUp(async (button, position) => {
ShowNewWorldScreen();
Debug.WriteLine("Generating world...");
GameWorld _gameWorld = await Game.Worlds.LoadNewWorld((progressReport) => {
Progress.SetText(progressReport);
Debug.WriteLine(" " + progressReport);
});
Game.LoadScreen(
new GameplayScreen(Game, _gameWorld),
new MonoGame.Extended.Screens.Transitions.FadeTransition(Game.GraphicsDevice, Color.Black)
);
})
.SetText("Start Game")
);
menu.AddChild(
buttonTemplate.Clone()
.SetNewRect(buttonTemplate.GetRect()
.SetY(AbsoluteUnit.WithValue(buttonRow(1)))
.SetWidth(new RelativeUnit(1f, menu.GetRect(), RelativeUnit.Orientation.Horizontal))
)
.SetOnMouseUp((button, position) => { ShowOptionsScreen(); })
.SetText("Options")
);
menu.AddChild(
buttonTemplate.Clone()
.SetNewRect(buttonTemplate.GetRect()
.SetY(AbsoluteUnit.WithValue(buttonRow(2)))
.SetWidth(new RelativeUnit(1f, menu.GetRect(), RelativeUnit.Orientation.Horizontal))
)
.SetOnMouseUp((button, position) => { Game.Exit(); })
.SetText("Quit Game")
.SetColorGroup(new ButtonColorGroup(Color.White, Color.Black, Color.Red, Color.DarkRed))
);
MainScreen.AddChild(menu);
}
private void ShowMainScreen() {
MainScreen.SetEnabled(true);
OptionsScreen.SetEnabled(false);
NewWorldScreen.SetEnabled(false);
}
private void LoadOptionsScreen() {
Root.AddChild(OptionsScreen = new Container(Rect.ScreenFull));
OptionsScreen.SetEnabled(false);
IContainer menu = new Container(new Rect(
new ScreenSpaceUnit(.5f, ScreenSpaceUnit.ScreenSpaceOrientation.Horizontal),
new ScreenSpaceUnit(.5f, ScreenSpaceUnit.ScreenSpaceOrientation.Vertical),
AbsoluteUnit.WithValue(450f),
AbsoluteUnit.WithValue(0f)
));
menu.AddChild(
buttonTemplate.Clone()
.SetNewRect(buttonTemplate.GetRect()
.SetY(AbsoluteUnit.WithValue(buttonRow(0)))
.SetWidth(new RelativeUnit(1f, menu.GetRect(), RelativeUnit.Orientation.Horizontal))
)
.SetOnMouseUp((button, position) => { ShowMainScreen(); })
.SetText("Back to Main Menu")
);
OptionsScreen.AddChild(menu);
}
private void ShowOptionsScreen() {
MainScreen.SetEnabled(false);
OptionsScreen.SetEnabled(true);
NewWorldScreen.SetEnabled(false);
}
private void LoadNewWorldScreen() {
Root.AddChild(NewWorldScreen = new Container(Rect.ScreenFull));
NewWorldScreen.SetEnabled(false);
NewWorldScreen.AddChild(Progress = new Label(
new Rect(
new ScreenSpaceUnit(.5f, ScreenSpaceUnit.ScreenSpaceOrientation.Horizontal),
new ScreenSpaceUnit(.5f, ScreenSpaceUnit.ScreenSpaceOrientation.Vertical),
AbsoluteUnit.WithValue(200),
AbsoluteUnit.WithValue(50)
))
.SetPivotPoint(new Vector2(0.5f, 0.5f))
.SetTextProperties(new TextProperties()
.SetColor(Color.White)
.SetFont(ResourceManager.Fonts.DEFAULT)
.SetFontSize(24f)
.SetTextAlignment(TextAlignment.Center)
)
.SetText("")
);
}
private void ShowNewWorldScreen() {
MainScreen.SetEnabled(false);
OptionsScreen.SetEnabled(false);
NewWorldScreen.SetEnabled(true);
}
private void LoadGlobals() {
Container copyPivot = new Container(new Rect(
new RelativeUnit(.5f, Root.GetRect(), RelativeUnit.Orientation.Horizontal),
new RelativeUnit(1f, Root.GetRect(), RelativeUnit.Orientation.Vertical),
AbsoluteUnit.WithValue(0f),
AbsoluteUnit.WithValue(12f)
));
copyPivot.SetPivot(new Vector2(.5f, 1f));
Root.AddChild(copyPivot);
copyPivot.AddChild(new Label(
new Rect(
AbsoluteUnit.WithValue(12f),
AbsoluteUnit.WithValue(0f),
new RelativeUnit(1f, Root.GetRect(), RelativeUnit.Orientation.Horizontal),
new RelativeUnit(1f, copyPivot.GetRect(), RelativeUnit.Orientation.Vertical)
)
)
.SetTextProperties(new TextProperties()
.SetFont(ResourceManager.Fonts.DEFAULT)
.SetColor(Color.White)
.SetFontSize(12f)
.SetTextAlignment(TextAlignment.Bottom | TextAlignment.Center)
)
.SetText("(c) leafal.io 2022-2023, all rights reserved.")
.SetPivotPoint(new Vector2(0.5f, 1f)));
}
}
}
|