-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMenuScene.cs
291 lines (259 loc) · 12.1 KB
/
MenuScene.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
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
using System.Numerics;
using System.Reflection;
using System.Runtime.CompilerServices;
using Walgelijk;
using Walgelijk.Onion;
using Walgelijk.Onion.Controls;
using Walgelijk.Onion.Decorators;
using Walgelijk.SimpleDrawing;
namespace MadnessMicroactive;
public static class MenuScene
{
private static readonly string VersionText =
$"Walgelijk v{typeof(Component).Assembly!.GetName()!.Version} | " +
$"Madness Microactive v{Assembly.GetEntryAssembly()!.GetName()!.Version}";
public enum Screen
{
None,
Character,
Credits
}
public static Scene Create(Game game)
{
var scene = new Scene(game);
scene.ShouldBeDisposedOnSceneChange = true;
scene.AddSystem(new OnionSystem());
scene.AddSystem(new MainMenuSystem());
scene.AddSystem(new MusicSystem());
return scene;
}
public class MainMenuSystem : Walgelijk.System
{
public static Screen CurrentScreen;
public override void Update()
{
Draw.Reset();
Draw.ScreenSpace = true;
Draw.Colour = new Color(76, 76, 76);
Draw.Quad(new Rect(0, 0, Window.Width, Window.Height));
Ui.Theme.Padding(32).OutlineColour(Colors.Black).OutlineWidth(8).Rounding(16).Once();
Ui.Layout.Width(300).FitHeight().StickTop().StickLeft();
Ui.Decorate(new HeaderDecorator("Main Menu"));
Ui.StartGroup(true);
{
Ui.Theme.Padding(20).Once();
Ui.Layout.FitContainer().StickTop().StickLeft().VerticalLayout();
Ui.StartScrollView();
{
Ui.Layout.FitWidth().Scale(-20, 0).Height(78).StickLeft();
if (MainMenuButton.Start(PersistentData.Instance.LevelIndex == 0 ? "New Game" : "Continue", Resources.Load<Texture>("ui_newgame.png")))
{
Game.Scene = LevelScene.Create(Game, Levels.Campaign[PersistentData.Instance.LevelIndex]);
return;
}
Ui.Layout.FitWidth().Scale(-20, 0).Height(78).StickLeft();
if (MainMenuButton.Start("Character", Resources.Load<Texture>("ui_character.png")))
CurrentScreen = CurrentScreen == Screen.Character ? Screen.None : Screen.Character;
Ui.Layout.FitWidth().Scale(-20, 0).Height(78).StickLeft();
if (MainMenuButton.Start("Experiment", Resources.Load<Texture>("ui_experiment.png")))
{
Game.Scene = ExperimentScene.Create(Game);
return;
}
Ui.Layout.FitWidth().Scale(-20, 0).Height(78).StickLeft();
if (MainMenuButton.Start("Credits", Resources.Load<Texture>("ui_credits.png")))
CurrentScreen = CurrentScreen == Screen.Credits ? Screen.None : Screen.Credits;
Ui.Layout.FitWidth().Scale(-20, 0).Height(78).StickLeft();
if (MainMenuButton.Start("Quit", Resources.Load<Texture>("ui_close.png")))
{
Window.IsVisible = false;
Game.Stop();
}
}
Ui.End();
}
Ui.End();
if (CurrentScreen is not Screen.None)
{
Ui.Theme.Padding(32).OutlineColour(Colors.Black).OutlineWidth(8).Rounding(16).Once();
Ui.Layout.FitContainer().Scale(-332, 0).StickTop().StickRight();
Ui.Decorate(new HeaderDecorator(CurrentScreen.ToString()));
Ui.StartGroup(true);
{
Ui.Theme.Padding(20).Once();
Ui.Layout.FitContainer().StickTop().StickLeft().VerticalLayout();
Ui.StartScrollView();
{
switch (CurrentScreen)
{
case Screen.Character:
CharacterEditor();
break;
case Screen.Credits:
Ui.Layout.FitContent().FitWidth().Scale(-20, 0).StickLeft().StickTop();
Ui.StartGroup(false);
{
Ui.Layout.FitContainer(0.5f, null, false).PreferredSize().StickLeft(false).StickTop(false);
Ui.TextRect("<color=#af0000>Krinkels\nMax Abernethy\n\nMModule\nCheshyre\n\nzooi", HorizontalTextAlign.Left, VerticalTextAlign.Top);
Ui.Layout.FitContainer(0.5f, null, false).PreferredSize().StickRight(false).StickTop(false);
Ui.TextRect("Original concept\n\n\nMusic\n\n\nProgramming, Art", HorizontalTextAlign.Left, VerticalTextAlign.Top);
}
Ui.End();
break;
}
}
Ui.End();
}
Ui.End();
}
else
{
Ui.Layout.Size(Window.Width - 332, Window.Height).Move(332, 0);
Ui.Theme.Font(Resources.Load<Font>("impact.wf")).FontSize(60).Text(Colors.White).Once();
Ui.TextRect("Madness Microactive", HorizontalTextAlign.Right, VerticalTextAlign.Middle);
Ui.Layout.FitWidth().Height(32).StickRight().StickBottom();
Ui.TextRect(VersionText, HorizontalTextAlign.Right, VerticalTextAlign.Bottom);
}
}
private static void CharacterEditor()
{
var t = Game.Main.State.Time.SecondsSinceSceneChange * 0.06f;
Ui.Theme.Padding(8);
{
var player = Outfits.Player;
Ui.Layout.Size(150, 210).CenterHorizontal().StickTop();
Ui.Theme.Foreground(new(new Color(76, 76, 76))).Rounding(16).Once();
Ui.StartGroup(); // draw avatar with UI elements lmfao
{
var pose = CharacterPoses.Idle;
pose.Head.Translation += 4 * Noise2D(t, 1, 0);
pose.Body.Translation += 2 * Noise2D(t, 2, 0);
pose.Hand1.Translation += 3 * Noise2D(t, 3, 0);
pose.Hand2.Translation += 3 * Noise2D(t, 4, 0);
var head = Resources.Load<Texture>("character/head.png");
var body = Resources.Load<Texture>("character/body.png");
var hand = Resources.Load<Texture>("character/hand.png");
var foot = Resources.Load<Texture>("character/foot.png");
int v = 1;
foreach (var item in player.Head)
{
img(item.Texture, pose.Head.Translation + item.Offset, v, item.GetHashCode());
v++;
}
img(head, pose.Head.Translation, 0);
img(hand, pose.Hand1.Translation, 0);
img(body, pose.Body.Translation, -20);
v = -19;
foreach (var item in player.Body)
{
img(item.Texture, pose.Body.Translation + item.Offset, v, item.GetHashCode());
v++;
}
img(hand, pose.Hand2.Translation, -21);
img(foot, pose.Foot1.Translation - Vector2.UnitX * 5, -21);
img(foot, pose.Foot2.Translation - Vector2.UnitX * 5, -23);
void img(IReadableTexture tex, Vector2 offset, int order, [CallerLineNumber] int site = 0)
{
Ui.Layout.Size(tex.Width, tex.Height).Center().MoveAbs(0, 85).MoveAbs(offset.X, -offset.Y).Order(order);
Ui.Image(tex, ImageContainmentMode.Center, site);
}
}
Ui.End();
Ui.Label("Head");
Ui.Layout.FitWidth().Scale(-15, 0).Height(100).StickLeft().HorizontalLayout();
Ui.Theme.Foreground(new(new Color(110, 110, 110))).Once();
Ui.StartScrollView(true);
{
foreach (var item in Apparel.HeadClothes)
{
var equipped = player.Head.Contains(item);
Ui.Layout.FitHeight().Width(90).StickTop();
Ui.Theme.Foreground(new(new Color(110, 110, 110)));
Ui.Decorators.Tooltip(item.Name);
if (equipped)
Ui.Decorate(new SelectedApparelDecorator());
if (Ui.ImageButton(item.Texture, ImageContainmentMode.Contain, identity: item.GetHashCode()))
{
if (equipped)
player.Head.Remove(item);
else
player.Head.Add(item);
}
}
}
Ui.End();
Ui.Spacer(15);
Ui.Label("Body");
Ui.Layout.FitWidth().Scale(-15, 0).Height(100).StickLeft().HorizontalLayout();
Ui.Theme.Foreground(new(new Color(110, 110, 110))).Once();
Ui.StartScrollView(true);
{
foreach (var item in Apparel.BodyClothes)
{
var equipped = player.Body.Contains(item);
Ui.Layout.FitHeight().Width(90).StickTop();
Ui.Theme.Foreground(new(new Color(110, 110, 110)));
Ui.Decorators.Tooltip(item.Name);
if (equipped)
Ui.Decorate(new SelectedApparelDecorator());
if (Ui.ImageButton(item.Texture, ImageContainmentMode.Contain, identity: item.GetHashCode()))
{
if (equipped)
player.Body.Remove(item);
else
player.Body.Add(item);
}
}
}
Ui.End();
}
Ui.Theme.Pop();
}
}
public static Vector2 Noise2D(float x, float y, float z)
{
return new Vector2(
Noise.GetValue(x, y, z),
Noise.GetValue(-x, -z, -y)
);
}
public readonly struct SelectedApparelDecorator : IDecorator
{
public void RenderBefore(in ControlParams p) { }
public void RenderAfter(in ControlParams p)
{
Draw.Colour = default;
Draw.OutlineWidth = 8;
Draw.OutlineColour = new Color(147, 179, 72).WithAlpha(0.9f);
Draw.ResetTexture();
//Draw.ResetDrawBounds();
Draw.Quad(p.Instance.Rects.Rendered.Expand(Utilities.MapRange(-1, 1, 0, 2, MathF.Sin(p.GameState.Time.SecondsSinceLoad * 4))));
}
}
public readonly struct HeaderDecorator : IDecorator
{
public readonly string Text;
public HeaderDecorator(string text)
{
Text = text;
}
public void RenderBefore(in ControlParams p) { }
public void RenderAfter(in ControlParams p)
{
Draw.Font = p.Theme.Font;
Draw.FontSize = p.Theme.FontSize.Default;
var r = new Rect(0, 0, Draw.CalculateTextWidth(Text ?? string.Empty) + 30, 40);
r = r.Translate(p.Instance.Rects.ComputedGlobal.BottomLeft);
r = r.Translate(32, r.Height / -2);
Draw.Colour = new Color("#93B348");
Draw.OutlineColour = Colors.Black;
Draw.OutlineWidth = 8;
Draw.ResetTexture();
Draw.ResetDrawBounds();
Draw.Quad(r, 0);
Draw.Colour = p.Theme.Text.Default;
if (!string.IsNullOrEmpty(Text))
Draw.Text(Text, r.GetCenter(), Vector2.One, HorizontalTextAlign.Center, VerticalTextAlign.Middle);
}
}
}