-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathMainMenu.cs
503 lines (487 loc) · 21.6 KB
/
MainMenu.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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
using System;
using System.IO;
using System.Threading;
using System.Xml;
using Hacknet.Effects;
using Hacknet.Gui;
using Hacknet.Misc;
using Hacknet.PlatformAPI.Storage;
using Hacknet.UIUtils;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace Hacknet
{
internal class MainMenu : GameScreen
{
public static string OSVersion = "v3.017";
public static string AccumErrors = "";
private readonly AttractModeMenuScreen attractModeScreen = new AttractModeMenuScreen();
private Color buttonColor;
private bool canLoad;
private Color exitButtonColor;
private int framecount;
private bool hasSentErrorEmail;
private HexGridBackground hexBackground;
private readonly SavefileLoginScreen loginScreen = new SavefileLoginScreen();
private MainMenuState State;
private string testSuiteResult;
private Color titleColor;
private SpriteFont titleFont;
public MainMenu()
{
TransitionOffTime = TimeSpan.FromSeconds(0.5);
}
public override void LoadContent()
{
buttonColor = new Color(124, 137, 149);
exitButtonColor = new Color(105, 82, 82);
titleColor = new Color(190, 190, 190, 0);
titleFont = ScreenManager.Game.Content.Load<SpriteFont>("Kremlin");
canLoad = SaveFileManager.StorageMethods[0].GetSaveManifest().LastLoggedInUser.Username != null;
hexBackground = new HexGridBackground(ScreenManager.Game.Content);
HookUpCreationEvents();
}
private void HookUpCreationEvents()
{
loginScreen.RequestGoBack += () => State = MainMenuState.Normal;
loginScreen.StartNewGameForUsernameAndPass += (username, pass) =>
{
if (SaveFileManager.AddUser(username, pass))
{
var filePathForLogin = SaveFileManager.GetFilePathForLogin(username, pass);
ExitScreen();
resetOS();
if (!Settings.soundDisabled)
ScreenManager.playAlertSound();
try
{
ScreenManager.AddScreen(new OS
{
SaveGameUserName = filePathForLogin,
SaveUserAccountName = username
}, ScreenManager.controllingPlayer);
}
catch (Exception ex)
{
UpdateUIForSaveCreationFailed(ex);
}
}
else
{
loginScreen.ResetForNewAccount();
loginScreen.WriteToHistory(" ERROR: Username invalid or already in use.");
}
};
loginScreen.LoadGameForUserFileAndUsername += (userFile, username) =>
{
ExitScreen();
resetOS();
OS.WillLoadSave = SaveFileManager.StorageMethods[0].FileExists(userFile);
var os = new OS();
os.SaveGameUserName = userFile;
os.SaveUserAccountName = username;
try
{
ScreenManager.AddScreen(os, ScreenManager.controllingPlayer);
}
catch (XmlException ex)
{
UpdateUIForSaveCorruption(userFile, ex);
}
catch (FormatException ex)
{
UpdateUIForSaveCorruption(userFile, ex);
}
catch (NullReferenceException ex)
{
UpdateUIForSaveCorruption(userFile, ex);
}
catch (FileNotFoundException ex)
{
UpdateUIForSaveMissing(userFile, ex);
}
};
attractModeScreen.Start += () =>
{
try
{
ExitScreen();
resetOS();
ScreenManager.playAlertSound();
ScreenManager.AddScreen(new OS(), ScreenManager.controllingPlayer);
}
catch (Exception ex)
{
Utils.writeToFile("OS Load Error: " + ex + "\n\n" + ex.StackTrace, "crashLog.txt");
}
};
}
private void UpdateUIForSaveCorruption(string saveName, Exception ex)
{
State = MainMenuState.Normal;
AccumErrors = AccumErrors + "ACCOUNT FILE CORRUPTION: Account " + saveName +
" appears to be corrupted, and will not load. Reported Error:\r\n" +
Utils.GenerateReportFromException(ex) + "\r\n";
if (hasSentErrorEmail)
return;
new Thread(() => Utils.SendErrorEmail(ex, "Save Corruption ", ""))
{
IsBackground = true,
Name = "SaveCorruptErrorReportThread"
}.Start();
hasSentErrorEmail = true;
}
private void UpdateUIForSaveMissing(string saveName, Exception ex)
{
State = MainMenuState.Normal;
AccumErrors = AccumErrors + "ACCOUNT FILE NOT FOUND: Account " + saveName +
" appears to be missing. It may have been moved or deleted. Reported Error:\r\n" +
Utils.GenerateReportFromException(ex) + "\r\n";
if (hasSentErrorEmail)
return;
new Thread(() => Utils.SendErrorEmail(ex, "Save Missing ", ""))
{
IsBackground = true,
Name = "SaveMissingErrorReportThread"
}.Start();
hasSentErrorEmail = true;
}
private void UpdateUIForSaveCreationFailed(Exception ex)
{
State = MainMenuState.Normal;
AccumErrors = AccumErrors + "CRITICAL ERROR CREATING ACCOUNT: Reported Error:\r\n" +
Utils.GenerateReportFromException(ex) + "\r\n";
if (hasSentErrorEmail)
return;
new Thread(() => Utils.SendErrorEmail(ex, "Account Creation Error ", ""))
{
IsBackground = true,
Name = "SaveAccCreationErrorReportThread"
}.Start();
hasSentErrorEmail = true;
}
public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
{
base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
++framecount;
hexBackground.Update((float) gameTime.ElapsedGameTime.TotalSeconds);
}
public override void HandleInput(InputState input)
{
base.HandleInput(input);
GuiData.doInput(input);
}
public static void resetOS()
{
if (Settings.isSpecialTestBuild)
return;
TextBox.cursorPosition = 0;
Settings.initShowsTutorial = Settings.osStartsWithTutorial;
Settings.IsInAdventureMode = false;
ScrollablePanel.ClearCache();
}
public override void Draw(GameTime gameTime)
{
base.Draw(gameTime);
try
{
PostProcessor.begin();
ScreenManager.FadeBackBufferToBlack(byte.MaxValue);
GuiData.startDraw();
var dest1 = new Rectangle(0, 0, ScreenManager.GraphicsDevice.Viewport.Width,
ScreenManager.GraphicsDevice.Viewport.Height);
var destinationRectangle = new Rectangle(-20, -20, ScreenManager.GraphicsDevice.Viewport.Width + 40,
ScreenManager.GraphicsDevice.Viewport.Height + 40);
var dest2 = new Rectangle(dest1.X + dest1.Width/4, dest1.Height/4, dest1.Width/2, dest1.Height/4);
GuiData.spriteBatch.Draw(Utils.white, destinationRectangle, Color.Black);
hexBackground.Draw(dest1, GuiData.spriteBatch, Color.Transparent,
Settings.lighterColorHexBackground ? new Color(20, 20, 20) : new Color(10, 10, 10, 0),
HexGridBackground.ColoringAlgorithm.NegaitiveSinWash, 0.0f);
TextItem.DrawShadow = false;
switch (State)
{
case MainMenuState.NewUser:
DrawLoginScreen(dest2, true);
break;
case MainMenuState.Login:
DrawLoginScreen(dest2, false);
break;
default:
if (Settings.isLockedDemoMode)
{
attractModeScreen.Draw(dest1, GuiData.spriteBatch);
break;
}
FlickeringTextEffect.DrawLinedFlickeringText(new Rectangle(180, 120, 340, 100), "HACKNET", 7f,
0.55f, titleFont, null, titleColor, 2);
TextItem.doFontLabel(new Vector2(520f, 178f), "OS " + OSVersion, GuiData.smallfont,
titleColor*0.5f, 600f, 26f);
var canRun = true;
if (Settings.IsExpireLocked)
{
var timeSpan = Settings.ExpireTime - DateTime.Now;
string text;
if (timeSpan.TotalSeconds < 1.0)
{
text = "TEST BUILD EXPIRED - EXECUTION DISABLED";
canRun = false;
}
else
text = "Test Build : Expires in " + timeSpan;
TextItem.doFontLabel(new Vector2(180f, 105f), text, GuiData.smallfont, Color.Red*0.8f, 600f,
26f);
}
if (Settings.isLockedDemoMode)
{
drawDemoModeButtons(canRun);
break;
}
drawMainMenuButtons(canRun);
if (Settings.testingMenuItemsEnabled)
{
drawTestingMainMenuButtons(canRun);
}
break;
}
GuiData.endDraw();
PostProcessor.end();
ScreenManager.FadeBackBufferToBlack(byte.MaxValue - TransitionAlpha);
}
catch (ObjectDisposedException ex)
{
if (hasSentErrorEmail)
throw ex;
var body =
string.Concat(
Utils.GenerateReportFromException(ex) + "\r\n Font:" + titleFont +
"\r\n White:" + Utils.white + "\r\n WhiteDisposed:" + Utils.white.IsDisposed +
"\r\n SmallFont:" + GuiData.smallfont + "\r\n TinyFont:" + GuiData.tinyfont +
"\r\n LineEffectTarget:" + FlickeringTextEffect.GetReportString() + "\r\n PostProcessort stuff:" +
PostProcessor.GetStatusReportString(), "\r\nRESOLUTION:\r\n ",
Game1.getSingleton().GraphicsDevice.PresentationParameters.BackBufferWidth, "x") +
Game1.getSingleton().GraphicsDevice.PresentationParameters.BackBufferHeight + "\r\nFullscreen: " +
(Game1.getSingleton().graphics.IsFullScreen ? "true" : "false") + "\r\n Adapter: " +
Game1.getSingleton().GraphicsDevice.Adapter.Description + "\r\n Device Name: " +
Game1.getSingleton().GraphicsDevice.Adapter.DeviceName + "\r\n Status: " +
Game1.getSingleton().GraphicsDevice.GraphicsDeviceStatus;
Utils.SendRealWorldEmail(
"Hackent " + OSVersion + " Crash " + DateTime.Now.ToShortDateString() + " " +
DateTime.Now.ToShortTimeString(), "[email protected]", body);
hasSentErrorEmail = true;
SettingsLoader.writeStatusFile();
}
}
private void DrawLoginScreen(Rectangle dest, bool needsNewUser = false)
{
loginScreen.Draw(GuiData.spriteBatch, dest);
}
private void drawDemoModeButtons(bool canRun)
{
if (Button.doButton(1, 180, 200, 450, 50, "New Session", buttonColor))
{
if (canRun)
{
try
{
ExitScreen();
resetOS();
ScreenManager.playAlertSound();
ScreenManager.AddScreen(new OS(), ScreenManager.controllingPlayer);
}
catch (Exception ex)
{
Utils.writeToFile("OS Load Error: " + ex + "\n\n" + ex.StackTrace, "crashLog.txt");
}
}
}
if (Button.doButton(11, 180, 265, 450, 50, "Load Session", canLoad ? buttonColor : Color.Black))
{
if (canLoad)
{
try
{
if (canRun)
{
ExitScreen();
resetOS();
OS.WillLoadSave = true;
ScreenManager.AddScreen(new OS(), ScreenManager.controllingPlayer);
}
}
catch (Exception ex)
{
Utils.writeToFile("OS Load Error: " + ex + "\n\n" + ex.StackTrace, "crashLog.txt");
}
}
}
if (!Button.doButton(15, 180, 330, 450, 28, "Exit", exitButtonColor))
return;
MusicManager.stop();
Game1.threadsExiting = true;
Game1.getSingleton().Exit();
}
private void drawTestingMainMenuButtons(bool canRun)
{
if (Button.doButton(8801, 634, 200, 225, 23, "New Test Session", buttonColor) && canRun)
{
ExitScreen();
resetOS();
if (!Settings.soundDisabled)
ScreenManager.playAlertSound();
var os = new OS();
ScreenManager.AddScreen(os, ScreenManager.controllingPlayer);
os.delayer.RunAllDelayedActions();
os.threadedSaveExecute();
ScreenManager.RemoveScreen(os);
OS.WillLoadSave = true;
resetOS();
ScreenManager.AddScreen(new OS(), ScreenManager.controllingPlayer);
}
if (Button.doButton(8803, 634, 225, 225, 23, "New Entropy Accelerated Session", buttonColor) && canRun)
{
ExitScreen();
resetOS();
if (!Settings.soundDisabled)
ScreenManager.playAlertSound();
var os1 = new OS();
os1.SaveGameUserName = "entropyTest";
os1.SaveUserAccountName = "entropyTest";
ScreenManager.AddScreen(os1, ScreenManager.controllingPlayer);
os1.Flags.AddFlag("TutorialComplete");
os1.delayer.RunAllDelayedActions();
os1.threadedSaveExecute();
ScreenManager.RemoveScreen(os1);
OS.WillLoadSave = true;
resetOS();
Settings.initShowsTutorial = false;
var os2 = new OS();
ScreenManager.AddScreen(os2, ScreenManager.controllingPlayer);
MissionFunctions.runCommand(0, "EntropyFastFowardSetup");
os2.delayer.Post(ActionDelayer.Wait(1.0), () => Game1.getSingleton().IsMouseVisible = true);
}
if (Button.doButton(8806, 634, 250, 225, 23, "Run Test Suite", buttonColor))
testSuiteResult = TestSuite.TestSaveLoadOnFile(ScreenManager);
if (Button.doButton(8809, 634, 275, 225, 23, "Export Animation", buttonColor))
{
var TitleFill = new Rectangle(0, 0, 300, 100);
AnimatedSpriteExporter.ExportAnimation("OutNowAnim", "OutNow", TitleFill.Width, TitleFill.Height, 24f,
40f, GuiData.spriteBatch.GraphicsDevice, t => new OS
{
highlightColor = new Color(166, byte.MaxValue, 215)
}.timer += t, (sb, dest) =>
{
sb.Draw(Utils.white, dest, new Color(13, 13, 13));
FlickeringTextEffect.DrawFlickeringText(TitleFill, "OUT NOW", 8f, 0.7f, titleFont, null,
new Color(216, 216, 216));
}, 1);
}
if (Button.doButton(8812, 634, 300, 225, 23, "New CSEC Accel Session", buttonColor) && canRun)
{
ExitScreen();
resetOS();
if (!Settings.soundDisabled)
ScreenManager.playAlertSound();
var os1 = new OS();
ScreenManager.AddScreen(os1, ScreenManager.controllingPlayer);
os1.Flags.AddFlag("TutorialComplete");
os1.delayer.RunAllDelayedActions();
os1.threadedSaveExecute();
ScreenManager.RemoveScreen(os1);
OS.WillLoadSave = true;
resetOS();
Settings.initShowsTutorial = false;
var os2 = new OS();
ScreenManager.AddScreen(os2, ScreenManager.controllingPlayer);
MissionFunctions.runCommand(0, "CSECFastFowardSetup");
os2.delayer.Post(ActionDelayer.Wait(1.0), () => Game1.getSingleton().IsMouseVisible = true);
}
if (testSuiteResult == null)
return;
TextItem.doFontLabel(new Vector2(635f, 325f),
Utils.SuperSmartTwimForWidth(testSuiteResult, 600, GuiData.tinyfont), GuiData.tinyfont,
testSuiteResult.Length > 250 ? Utils.AddativeRed : Utils.AddativeWhite, float.MaxValue, float.MaxValue);
}
private void drawMainMenuButtons(bool canRun)
{
var num1 = 135;
int num2;
if (Button.doButton(1, 180, num2 = num1 + 65, 450, 50, "New Session", buttonColor) && canRun)
{
State = MainMenuState.NewUser;
loginScreen.ResetForNewAccount();
}
int num3;
if (
Button.doButton(1102, 180, num3 = num2 + 65, 450, 28,
canLoad
? "Continue with account [" + SaveFileManager.LastLoggedInUser.Username + "]"
: "No Accounts", canLoad ? buttonColor : Color.Black) && canLoad)
loginScreen.LoadGameForUserFileAndUsername(SaveFileManager.LastLoggedInUser.FileUsername,
SaveFileManager.LastLoggedInUser.Username);
int num4;
if (Button.doButton(11, 180, num4 = num3 + 39, 450, 50, "Login", canLoad ? buttonColor : Color.Black))
{
if (canLoad)
{
try
{
State = MainMenuState.Login;
loginScreen.ResetForLogin();
}
catch (Exception ex)
{
Utils.writeToFile("OS Load Error: " + ex + "\n\n" + ex.StackTrace, "crashLog.txt");
}
}
}
int num5;
if (Button.doButton(3, 180, num5 = num4 + 65, 450, 50, "Settings", buttonColor))
ScreenManager.AddScreen(new OptionsMenu(), ScreenManager.controllingPlayer);
int num6;
var y = num6 = num5 + 65;
if (Settings.isServerMode)
{
if (Button.doButton(4, 180, y, 450, 50, "Start Relay Server", buttonColor))
ScreenManager.AddScreen(new ServerScreen(), ScreenManager.controllingPlayer);
y += 65;
}
if (Settings.AllowAdventureMode)
{
if (Button.doButton(5, 180, y, 450, 50, "Adventure Session", buttonColor))
{
ExitScreen();
resetOS();
Settings.IsInAdventureMode = true;
if (!Settings.soundDisabled)
ScreenManager.playAlertSound();
ScreenManager.AddScreen(new OS(), ScreenManager.controllingPlayer);
}
y += 65;
}
if (Button.doButton(15, 180, y, 450, 28, "Exit", exitButtonColor))
{
MusicManager.stop();
Game1.threadsExiting = true;
Game1.getSingleton().Exit();
}
var num7 = y + 30;
if (!PlatformAPISettings.RemoteStorageRunning)
{
TextItem.doFontLabel(new Vector2(180f, num7), "WARNING: Error connecting to Steam Cloud",
GuiData.smallfont, Color.DarkRed, float.MaxValue, float.MaxValue);
num7 += 20;
}
if (string.IsNullOrWhiteSpace(AccumErrors))
return;
TextItem.doFontLabel(new Vector2(180f, num7), AccumErrors, GuiData.smallfont, Color.DarkRed, float.MaxValue,
float.MaxValue);
var num8 = num7 + 20;
}
private enum MainMenuState
{
Normal,
NewUser,
Login
}
}
}