-
-
Notifications
You must be signed in to change notification settings - Fork 453
/
Copy pathCMainMenu.cpp
1244 lines (1053 loc) · 43.7 KB
/
CMainMenu.cpp
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
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*****************************************************************************
*
* PROJECT: Multi Theft Auto v1.0
* LICENSE: See LICENSE in the top level directory
* FILE: core/CMainMenu.cpp
* PURPOSE: 2D Main menu graphical user interface
*
* Multi Theft Auto is available from http://www.multitheftauto.com/
*
*****************************************************************************/
#include "StdInc.h"
#include <game/CGame.h>
#include "CNewsBrowser.h"
#include "CLanguageSelector.h"
#include "CDiscordRichPresence.h"
#define NATIVE_RES_X 1280.0f
#define NATIVE_RES_Y 1024.0f
#define NATIVE_BG_X 1280.0f
#define NATIVE_BG_Y 649.0f
#define NATIVE_LOGO_X 1058.0f
#define NATIVE_LOGO_Y 540.0f
#define CORE_MTA_MENUITEMS_START_X 0.168
#define CORE_MTA_BG_MAX_ALPHA 1.00f //ACHTUNG: Set to 1 for now due to GTA main menu showing through (no delay inserted between Entering game... and loading screen)
#define CORE_MTA_BG_INGAME_ALPHA 0.90f
#define CORE_MTA_FADER 0.05f // 1/20
#define CORE_MTA_FADER_CREDITS 0.01f
#define CORE_MTA_HOVER_SCALE 1.0f
#define CORE_MTA_NORMAL_SCALE 0.6f
#define CORE_MTA_HOVER_ALPHA 1.0f
#define CORE_MTA_NORMAL_ALPHA 0.6f
#define CORE_MTA_HIDDEN_ALPHA 0.0f
#define CORE_MTA_DISABLED_ALPHA 0.4f
#define CORE_MTA_ENABLED_ALPHA 1.0f
#define CORE_MTA_ANIMATION_TIME 200
#define CORE_MTA_MOVE_ANIM_TIME 600
#define CORE_MTA_STATIC_BG "cgui\\images\\background.png"
#define CORE_MTA_LOGO "cgui\\images\\background_logo.png"
#define CORE_MTA_FILLER "cgui\\images\\mta_filler.png"
#define CORE_MTA_VERSION "cgui\\images\\version.png"
static int WaitForMenu = 0;
static const SColor headlineColors[] = {SColorRGBA(233, 234, 106, 255), SColorRGBA(233 / 6 * 4, 234 / 6 * 4, 106 / 6 * 4, 255),
SColorRGBA(233 / 7 * 3, 234 / 7 * 3, 106 / 7 * 3, 255)};
// Improve alignment with magical mystery values!
static const int BODGE_FACTOR_1 = -5;
static const int BODGE_FACTOR_2 = 5;
static const int BODGE_FACTOR_3 = -5;
static const int BODGE_FACTOR_4 = 5;
static const CVector2D BODGE_FACTOR_5(0, -50);
static const CVector2D BODGE_FACTOR_6(0, 100);
CMainMenu::CMainMenu(CGUI* pManager)
{
m_pNewsBrowser = new CNewsBrowser();
ulPreviousTick = GetTickCount32();
m_pHoveredItem = NULL;
m_iMoveStartPos = 0;
// Initialize
m_pManager = pManager;
m_bIsVisible = false;
m_bIsFullyVisible = false;
m_bIsIngame = true;
// m_bIsInSubWindow = false;
m_bStarted = false;
m_fFader = 0;
m_ucFade = FADE_INVISIBLE;
m_bCursorAlphaReset = false;
// Adjust window size to resolution
CVector2D ScreenSize = m_pManager->GetResolution();
m_ScreenSize = ScreenSize;
int iBackgroundX = 0;
int iBackgroundY = 0;
int iBackgroundSizeX = ScreenSize.fX;
int iBackgroundSizeY;
// First let's work out our x and y offsets
if (ScreenSize.fX > ScreenSize.fY) // If the monitor is a normal landscape one
{
float iRatioSizeY = ScreenSize.fY / NATIVE_RES_Y;
m_iMenuSizeX = NATIVE_RES_X * iRatioSizeY;
m_iMenuSizeY = ScreenSize.fY;
m_iXOff = (ScreenSize.fX - m_iMenuSizeX) * 0.5f;
m_iYOff = 0;
float iRatioSizeX = ScreenSize.fX / NATIVE_RES_X;
iBackgroundSizeX = ScreenSize.fX;
iBackgroundSizeY = NATIVE_BG_Y * iRatioSizeX;
}
else // Otherwise our monitor is in a portrait resolution, so we cant fill the background by y
{
float iRatioSizeX = ScreenSize.fX / NATIVE_RES_X;
m_iMenuSizeY = NATIVE_RES_Y * iRatioSizeX;
m_iMenuSizeX = ScreenSize.fX;
m_iXOff = 0;
m_iYOff = (ScreenSize.fY - m_iMenuSizeY) * 0.5f;
iBackgroundY = m_iYOff;
iBackgroundSizeX = m_iMenuSizeX;
iBackgroundSizeY = NATIVE_BG_Y * iRatioSizeX;
}
// First create our filler black background image, which covers the whole screen
m_pFiller = reinterpret_cast<CGUIStaticImage*>(pManager->CreateStaticImage());
m_pFiller->LoadFromFile(CORE_MTA_FILLER);
m_pFiller->SetVisible(false);
m_pFiller->MoveToBack();
m_pFiller->SetZOrderingEnabled(false);
m_pFiller->SetAlwaysOnTop(true);
m_pFiller->MoveToBack();
m_pFiller->SetSize(CVector2D(ScreenSize.fX, iBackgroundY), false);
// Background image
m_pBackground = reinterpret_cast<CGUIStaticImage*>(pManager->CreateStaticImage());
m_pBackground->LoadFromFile(CORE_MTA_STATIC_BG);
m_pBackground->SetProperty("InheritsAlpha", "False");
m_pBackground->SetPosition(CVector2D(iBackgroundX, iBackgroundY), false);
m_pBackground->SetSize(CVector2D(iBackgroundSizeX, iBackgroundSizeY), false);
m_pBackground->SetZOrderingEnabled(false);
m_pBackground->SetAlwaysOnTop(true);
m_pBackground->MoveToBack();
m_pBackground->SetAlpha(0);
m_pBackground->SetVisible(false);
m_pFiller2 = reinterpret_cast<CGUIStaticImage*>(pManager->CreateStaticImage());
m_pFiller2->LoadFromFile(CORE_MTA_FILLER);
m_pFiller2->SetVisible(false);
m_pFiller2->SetZOrderingEnabled(false);
m_pFiller2->SetAlwaysOnTop(true);
m_pFiller2->MoveToBack();
m_pFiller2->SetPosition(CVector2D(0, iBackgroundY + iBackgroundSizeY));
m_pFiller2->SetSize(ScreenSize, false);
m_pCanvas = reinterpret_cast<CGUIScrollPane*>(pManager->CreateScrollPane());
m_pCanvas->SetProperty("ContentPaneAutoSized", "False");
m_pCanvas->SetPosition(CVector2D(m_iXOff, m_iYOff), false);
m_pCanvas->SetSize(CVector2D(m_iMenuSizeX, m_iMenuSizeY), false);
m_pCanvas->SetZOrderingEnabled(false);
m_pCanvas->SetAlwaysOnTop(true);
m_pCanvas->MoveToBack();
m_pCanvas->SetVisible(false);
// Create our MTA logo
CVector2D logoSize = CVector2D((NATIVE_LOGO_X / NATIVE_RES_X) * m_iMenuSizeX, (NATIVE_LOGO_Y / NATIVE_RES_Y) * m_iMenuSizeY);
m_pLogo = reinterpret_cast<CGUIStaticImage*>(pManager->CreateStaticImage(m_pCanvas));
m_pLogo->LoadFromFile(CORE_MTA_LOGO);
m_pLogo->SetProperty("InheritsAlpha", "False");
m_pLogo->SetSize(logoSize, false);
m_pLogo->SetPosition(CVector2D(0.5f * m_iMenuSizeX - logoSize.fX / 2, 0.365f * m_iMenuSizeY - logoSize.fY / 2), false);
m_pLogo->SetZOrderingEnabled(false);
// Create the image showing the version number
m_pVersion = reinterpret_cast<CGUIStaticImage*>(pManager->CreateStaticImage());
m_pVersion->LoadFromFile(CORE_MTA_VERSION);
m_pVersion->SetParent(m_pCanvas);
m_pVersion->SetPosition(CVector2D(0.855f, 0.512f), true);
m_pVersion->SetSize(CVector2D((32 / NATIVE_RES_X) * m_iMenuSizeX, (32 / NATIVE_RES_Y) * m_iMenuSizeY), false);
m_pVersion->SetProperty("InheritsAlpha", "False");
float fBase = 0.613f;
float fGap = 0.043f;
// Our disconnect item is shown/hidden dynamically, so we store it seperately
m_pDisconnect = CreateItem(MENU_ITEM_DISCONNECT, "menu_disconnect.png", CVector2D(0.168f, fBase + fGap * 0));
m_pDisconnect->image->SetVisible(false);
// Create the menu items
// Filepath, Relative position, absolute native size
// And the font for the graphics is ?
m_menuItems.push_back(CreateItem(MENU_ITEM_QUICK_CONNECT, "menu_quick_connect.png", CVector2D(0.168f, fBase + fGap * 0)));
m_menuItems.push_back(CreateItem(MENU_ITEM_BROWSE_SERVERS, "menu_browse_servers.png", CVector2D(0.168f, fBase + fGap * 1)));
m_menuItems.push_back(CreateItem(MENU_ITEM_HOST_GAME, "menu_host_game.png", CVector2D(0.168f, fBase + fGap * 2)));
m_menuItems.push_back(CreateItem(MENU_ITEM_MAP_EDITOR, "menu_map_editor.png", CVector2D(0.168f, fBase + fGap * 3)));
m_menuItems.push_back(CreateItem(MENU_ITEM_SETTINGS, "menu_settings.png", CVector2D(0.168f, fBase + fGap * 4)));
m_menuItems.push_back(CreateItem(MENU_ITEM_ABOUT, "menu_about.png", CVector2D(0.168f, fBase + fGap * 5)));
m_menuItems.push_back(CreateItem(MENU_ITEM_QUIT, "menu_quit.png", CVector2D(0.168f, fBase + fGap * 6)));
// We store the position of the top item, and the second item. These will be useful later
float fFirstItemSize = m_menuItems.front()->image->GetSize(false).fY;
float fSecondItemSize = m_menuItems[1]->image->GetSize(false).fY;
m_iFirstItemCentre = (m_menuItems.front()->image)->GetPosition().fY + fFirstItemSize * 0.5f;
m_iSecondItemCentre = (m_menuItems[1]->image)->GetPosition().fY + fSecondItemSize * 0.5f;
// Store some mouse over bounding box positions
m_menuAX = (0.168f * m_iMenuSizeX) + m_iXOff; // Left side of the items
m_menuAY = m_iFirstItemCentre - fFirstItemSize * (CORE_MTA_HOVER_SCALE / CORE_MTA_NORMAL_SCALE) * 0.5f; // Top side of the items
m_menuBX = m_menuAX + ((390 / NATIVE_RES_X) * m_iMenuSizeX); // Right side of the items. We add the longest picture (browse_servers)
m_menuAY += BODGE_FACTOR_1;
m_pMenuArea = reinterpret_cast<CGUIStaticImage*>(pManager->CreateStaticImage(m_pCanvas));
m_pMenuArea->LoadFromFile(CORE_MTA_FILLER);
m_pMenuArea->SetPosition(CVector2D(m_menuAX - m_iXOff, m_menuAY - m_iYOff) + BODGE_FACTOR_5, false);
m_pMenuArea->SetSize(CVector2D(m_menuBX - m_menuAX, m_menuBY - m_menuAY) + BODGE_FACTOR_6, false);
m_pMenuArea->SetAlpha(0);
m_pMenuArea->SetZOrderingEnabled(false);
m_pMenuArea->SetClickHandler(GUI_CALLBACK_MOUSE(&CMainMenu::OnMenuClick, this));
m_pMenuArea->SetMouseEnterHandler(GUI_CALLBACK(&CMainMenu::OnMenuEnter, this));
m_pMenuArea->SetMouseLeaveHandler(GUI_CALLBACK(&CMainMenu::OnMenuExit, this));
m_pLatestNews = reinterpret_cast<CGUIStaticImage*>(pManager->CreateStaticImage());
if (!m_pLatestNews->LoadFromFile(PathJoin(g_pCore->GetLocalization()->GetLanguageDirectory(), "latest_news.png")))
{
// Load en_US if no localization is available
auto pLanguage = g_pLocalization->GetLanguage("en_US");
m_pLatestNews->LoadFromFile(PathJoin(g_pCore->GetLocalization()->GetLanguageDirectory(pLanguage), "latest_news.png"));
}
m_pLatestNews->SetParent(m_pCanvas);
m_pLatestNews->SetProperty("InheritsAlpha", "False");
CVector2D vecNativeSize;
m_pLatestNews->GetNativeSize(vecNativeSize);
float fDrawSizeX = (vecNativeSize.fX / NATIVE_RES_X) * m_iMenuSizeX;
float fDrawSizeY = (vecNativeSize.fY / NATIVE_RES_Y) * m_iMenuSizeY;
m_pLatestNews->SetSize(CVector2D(fDrawSizeX, fDrawSizeY), false);
float fDrawPosX = 0.83f * m_iMenuSizeX - fDrawSizeX; // Right aligned
float fDrawPosY = 0.61f * m_iMenuSizeY;
m_pLatestNews->SetPosition(CVector2D(fDrawPosX, fDrawPosY), false);
m_pLatestNews->SetVisible(false);
// Create news item stuff
fDrawPosX -= 25;
fDrawPosY += fDrawSizeY + 3;
for (uint i = 0; i < CORE_MTA_NEWS_ITEMS; i++)
{
fDrawPosY += 20;
// Create our shadow and item
CGUILabel* pItemShadow = reinterpret_cast<CGUILabel*>(m_pManager->CreateLabel(m_pCanvas, " "));
CGUILabel* pItem = reinterpret_cast<CGUILabel*>(m_pManager->CreateLabel(m_pCanvas, " "));
pItem->SetFont("sans");
pItemShadow->SetFont("sans");
pItem->SetHorizontalAlign(CGUI_ALIGN_RIGHT);
pItemShadow->SetHorizontalAlign(CGUI_ALIGN_RIGHT);
pItem->SetSize(CVector2D(fDrawSizeX, 14), false);
pItemShadow->SetSize(CVector2D(fDrawSizeX, 15), false);
pItem->SetPosition(CVector2D(fDrawPosX, fDrawPosY), false);
pItemShadow->SetPosition(CVector2D(fDrawPosX + 1, fDrawPosY + 1), false);
pItemShadow->SetTextColor(112, 112, 112);
// Set the handlers
pItem->SetClickHandler(GUI_CALLBACK(&CMainMenu::OnNewsButtonClick, this));
// Store the item in the array
m_pNewsItemLabels[i] = pItem;
m_pNewsItemShadowLabels[i] = pItemShadow;
// Create our date label
fDrawPosY += 15;
CGUILabel* pItemDate = reinterpret_cast<CGUILabel*>(m_pManager->CreateLabel(m_pCanvas, " "));
pItemDate->SetFont("default-small");
pItemDate->SetHorizontalAlign(CGUI_ALIGN_RIGHT);
pItemDate->SetSize(CVector2D(fDrawSizeX, 13), false);
pItemDate->SetPosition(CVector2D(fDrawPosX, fDrawPosY), false);
m_pNewsItemDateLabels[i] = pItemDate;
// Create 'NEW' sticker
CGUILabel*& pLabel = m_pNewsItemNEWLabels[i];
pLabel = reinterpret_cast<CGUILabel*>(pManager->CreateLabel(m_pCanvas, "NEW"));
pLabel->SetFont("default-small");
pLabel->SetTextColor(255, 0, 0);
pLabel->AutoSize(pLabel->GetText().c_str());
pLabel->SetAlpha(0.7f);
pLabel->SetVisible(false);
}
m_pLogo->MoveToBack();
// Submenus
m_ServerBrowser.SetVisible(false);
m_ServerInfo.Hide();
m_Settings.SetVisible(false);
m_Credits.SetVisible(false);
m_pNewsBrowser->SetVisible(false);
m_pLanguageSelector = new CLanguageSelector(m_pCanvas);
// We're not ingame
SetIsIngame(false);
// Discord
if (g_pCore->GetCVars()->GetValue("allow_discord_rpc", false))
{
auto discord = g_pCore->GetDiscord();
if (!discord->IsDiscordRPCEnabled())
discord->SetDiscordRPCEnabled(true);
discord->SetPresenceState(_("Main menu"), false);
discord->SetPresenceStartTimestamp(0);
}
// Store the pointer to the graphics subsystem
m_pGraphics = CGraphics::GetSingletonPtr();
// Load the server lists
CXMLNode* pConfig = CCore::GetSingletonPtr()->GetConfig();
m_ServerBrowser.LoadServerList(pConfig->FindSubNode(CONFIG_NODE_SERVER_FAV), CONFIG_FAVOURITE_LIST_TAG, m_ServerBrowser.GetFavouritesList());
m_ServerBrowser.LoadServerList(pConfig->FindSubNode(CONFIG_NODE_SERVER_REC), CONFIG_RECENT_LIST_TAG, m_ServerBrowser.GetRecentList());
m_ServerBrowser.LoadServerList(pConfig->FindSubNode(CONFIG_NODE_SERVER_HISTORY), CONFIG_HISTORY_LIST_TAG, m_ServerBrowser.GetHistoryList());
// Remove unused node
if (CXMLNode* pOldNode = pConfig->FindSubNode(CONFIG_NODE_SERVER_INT))
pConfig->DeleteSubNode(pOldNode);
#ifdef CI_BUILD
// Add feature branch alert
m_pFeatureBranchAlertTexture.reset(reinterpret_cast<CGUITexture*>(m_pManager->CreateTexture()));
std::int32_t buffer = 0xFFFF0000;
m_pFeatureBranchAlertTexture->LoadFromMemory(&buffer, 1, 1); // HACK: Load red dot
m_pFeatureBranchAlertImage.reset(reinterpret_cast<CGUIStaticImage*>(m_pManager->CreateStaticImage(m_pBackground)));
m_pFeatureBranchAlertImage->LoadFromTexture(m_pFeatureBranchAlertTexture.get());
m_pFeatureBranchAlertImage->SetPosition({0.0f, 0.0f}, false);
m_pFeatureBranchAlertImage->SetSize({ScreenSize.fX, 35.0f});
m_pFeatureBranchAlertLabel.reset(reinterpret_cast<CGUILabel*>(m_pManager->CreateLabel(m_pFeatureBranchAlertImage.get())));
m_pFeatureBranchAlertLabel->SetText(
_("You are using a feature-branch build! This is a test build only which cannot be used to connect to public servers!"));
m_pFeatureBranchAlertLabel->SetPosition({0.0f, 0.0f}, false);
m_pFeatureBranchAlertLabel->SetSize({ScreenSize.fX, 35.0f});
m_pFeatureBranchAlertLabel->SetFont("clear-normal");
m_pFeatureBranchAlertLabel->SetHorizontalAlign(CGUI_ALIGN_HORIZONTALCENTER);
m_pFeatureBranchAlertLabel->SetVerticalAlign(CGUI_ALIGN_VERTICALCENTER);
#endif
#if _WIN32_WINNT <= _WIN32_WINNT_WINXP
// Add annonying alert
m_pAlertTexture.reset(reinterpret_cast<CGUITexture*>(m_pManager->CreateTexture()));
std::int32_t buffer = 0xFFFF0000;
m_pAlertTexture->LoadFromMemory(&buffer, 1, 1); // HACK: Load red dot
m_pAlertImage.reset(reinterpret_cast<CGUIStaticImage*>(m_pManager->CreateStaticImage(m_pBackground)));
m_pAlertImage->LoadFromTexture(m_pAlertTexture.get());
m_pAlertImage->SetPosition({0.0f, 0.0f}, false);
m_pAlertImage->SetSize({ScreenSize.fX, 20.0f});
#define XP_VISTA_WARNING _("MTA will not receive updates on XP/Vista after July 2019.\n\nUpgrade Windows to play on the latest servers.")
m_pAlertLabel.reset(reinterpret_cast<CGUILabel*>(m_pManager->CreateLabel(m_pAlertImage.get(), XP_VISTA_WARNING)));
m_pAlertLabel->SetPosition({0.0f, 2.0f}, false);
m_pAlertLabel->SetSize({ScreenSize.fX, 20.0f});
m_pAlertLabel->SetHorizontalAlign(CGUI_ALIGN_HORIZONTALCENTER);
#endif
}
CMainMenu::~CMainMenu()
{
// Destroy GUI items
delete m_pBackground;
delete m_pCanvas;
delete m_pFiller;
delete m_pFiller2;
delete m_pLogo;
delete m_pLatestNews;
delete m_pVersion;
delete m_pMenuArea;
// Destroy the menu items. Note: The disconnect item isn't always in the
// list of menu items (it's only in there when we're in game). This means we
// don't delete it when we iterate the list and delete it separately - the
// menu item itself still exists even when it's no in the list of menu
// items. Perhaps there should be a separate list of loaded items really.
for (std::deque<sMenuItem*>::iterator it = m_menuItems.begin(); it != m_menuItems.end(); ++it)
{
if ((*it) != m_pDisconnect)
{
delete (*it)->image;
delete (*it);
}
}
delete m_pDisconnect->image;
delete m_pDisconnect;
delete m_pLanguageSelector;
}
void CMainMenu::SetMenuVerticalPosition(int iPosY)
{
if (m_pHoveredItem)
{
m_unhoveredItems.insert(m_pHoveredItem);
m_pHoveredItem = NULL;
}
float fFirstItemSize = m_menuItems.front()->image->GetSize(false).fY;
int iMoveY = iPosY - m_menuItems.front()->image->GetPosition(false).fY - fFirstItemSize * 0.5f;
std::deque<sMenuItem*>::iterator it = m_menuItems.begin();
for (it; it != m_menuItems.end(); it++)
{
CVector2D vOrigPos = (*it)->image->GetPosition(false);
(*it)->drawPositionY = (*it)->drawPositionY + iMoveY;
(*it)->image->SetPosition(CVector2D(vOrigPos.fX, vOrigPos.fY + iMoveY), false);
}
m_menuAY = m_menuAY + iMoveY;
m_menuBY = m_menuBY + iMoveY;
m_pMenuArea->SetPosition(CVector2D(m_menuAX - m_iXOff, m_menuAY - m_iYOff) + BODGE_FACTOR_5, false);
m_pMenuArea->SetSize(CVector2D(m_menuBX - m_menuAX, m_menuBY - m_menuAY) + BODGE_FACTOR_6, false);
}
void CMainMenu::SetMenuUnhovered() // Dehighlight all our items
{
if (m_bIsIngame) // CEGUI hack
{
float fAlpha = m_pDisconnect->image->GetAlpha();
m_pDisconnect->image->SetAlpha(0.35f);
m_pDisconnect->image->SetAlpha(fAlpha);
SetItemHoverProgress(m_pDisconnect, 0, false);
}
m_pHoveredItem = NULL;
std::deque<sMenuItem*>::iterator it = m_menuItems.begin();
for (it; it != m_menuItems.end(); it++)
{
SetItemHoverProgress((*it), 0, false);
}
}
void CMainMenu::Update()
{
if (g_pCore->GetDiagnosticDebug() == EDiagnosticDebug::JOYSTICK_0000)
{
m_pFiller->SetVisible(false);
m_pFiller2->SetVisible(false);
m_pBackground->SetVisible(false);
m_bHideGame = false;
}
if (m_bFrameDelay)
{
m_bFrameDelay = false;
return;
}
// Get the game interface and the system state
CGame* pGame = CCore::GetSingleton().GetGame();
eSystemState SystemState = pGame->GetSystemState();
m_Credits.Update();
m_Settings.Update();
unsigned long ulCurrentTick = GetTickCount32();
unsigned long ulTimePassed = ulCurrentTick - ulPreviousTick;
if (m_bHideGame)
m_pGraphics->DrawRectangle(0, 0, m_ScreenSize.fX, m_ScreenSize.fY, 0xFF000000);
if (m_bIsIngame) // CEGUI hack
{
float fAlpha = m_pDisconnect->image->GetAlpha();
m_pDisconnect->image->SetAlpha(0.35f);
m_pDisconnect->image->SetAlpha(fAlpha);
}
if (m_bIsFullyVisible)
{
// Grab our cursor position
tagPOINT cursor;
GetCursorPos(&cursor);
HWND hookedWindow = CCore::GetSingleton().GetHookedWindow();
tagPOINT windowPos = {0};
ClientToScreen(hookedWindow, &windowPos);
CVector2D vecResolution = CCore::GetSingleton().GetGUI()->GetResolution();
cursor.x -= windowPos.x;
cursor.y -= windowPos.y;
if (cursor.x < 0)
cursor.x = 0;
else if (cursor.x > (long)vecResolution.fX)
cursor.x = (long)vecResolution.fX;
if (cursor.y < 0)
cursor.y = 0;
else if (cursor.y > (long)vecResolution.fY)
cursor.y = (long)vecResolution.fY;
// If we're within our highlight bounding box
if (m_bMouseOverMenu && (cursor.x > m_menuAX) && (cursor.y > m_menuAY + BODGE_FACTOR_3) && (cursor.x < m_menuBX) &&
(cursor.y < m_menuBY + BODGE_FACTOR_4))
{
float fHoveredIndex = ((cursor.y - m_menuAY) / (float)(m_menuBY - m_menuAY) * m_menuItems.size());
fHoveredIndex = Clamp<float>(0, fHoveredIndex, m_menuItems.size() - 1);
sMenuItem* pItem = m_menuItems[(int)floor(fHoveredIndex)];
int iSizeX = (pItem->nativeSizeX / NATIVE_RES_X) * m_iMenuSizeX;
if (cursor.x < (iSizeX + m_menuAX))
{
if ((m_pHoveredItem) && (m_pHoveredItem != pItem))
{
m_unhoveredItems.insert(m_pHoveredItem);
m_pHoveredItem = pItem;
}
else
{
m_pHoveredItem = NULL;
}
m_pHoveredItem = pItem;
}
else if (m_pHoveredItem)
{
m_unhoveredItems.insert(m_pHoveredItem);
m_pHoveredItem = NULL;
}
if (m_pHoveredItem)
{
float fProgress = (m_pHoveredItem->image->GetAlpha() - CORE_MTA_NORMAL_ALPHA) / (CORE_MTA_HOVER_ALPHA - CORE_MTA_NORMAL_ALPHA);
// Let's work out what the target progress should be by working out the time passed
fProgress = ((float)ulTimePassed / CORE_MTA_ANIMATION_TIME) * (CORE_MTA_HOVER_ALPHA - CORE_MTA_NORMAL_ALPHA) + fProgress;
MapRemove(m_unhoveredItems, m_pHoveredItem);
SetItemHoverProgress(m_pHoveredItem, fProgress, true);
}
}
else if (m_pHoveredItem)
{
m_unhoveredItems.insert(m_pHoveredItem);
m_pHoveredItem = NULL;
}
// Let's unhover our recently un-moused over items
std::set<sMenuItem*>::iterator it = m_unhoveredItems.begin();
while (it != m_unhoveredItems.end())
{
float fProgress = ((*it)->image->GetAlpha() - CORE_MTA_NORMAL_ALPHA) / (CORE_MTA_HOVER_ALPHA - CORE_MTA_NORMAL_ALPHA);
// Let's work out what the target progress should be by working out the time passed
// Min of 0.5 progress fixes occasional graphical glitchekal
fProgress = fProgress - std::min(0.5f, ((float)ulTimePassed / CORE_MTA_ANIMATION_TIME) * (CORE_MTA_HOVER_ALPHA - CORE_MTA_NORMAL_ALPHA));
if (SetItemHoverProgress((*it), fProgress, false))
{
std::set<sMenuItem*>::iterator itToErase = it++;
m_unhoveredItems.erase(itToErase);
}
else
it++;
}
}
if (m_iMoveStartPos)
{
float fTickDifference = ulCurrentTick - m_ulMoveStartTick;
float fMoveTime = (fTickDifference / CORE_MTA_MOVE_ANIM_TIME);
fMoveTime = Clamp<float>(0, fMoveTime, 1);
// Use OutQuad easing to smoothen the movement
fMoveTime = -fMoveTime * (fMoveTime - 2);
SetMenuVerticalPosition(fMoveTime * (m_iMoveTargetPos - m_iMoveStartPos) + m_iMoveStartPos);
m_pDisconnect->image->SetAlpha(m_bIsIngame ? fMoveTime * CORE_MTA_NORMAL_ALPHA : (1 - fMoveTime) * CORE_MTA_NORMAL_ALPHA);
if (fMoveTime == 1)
{
m_iMoveStartPos = 0;
if (!m_bIsIngame)
m_pDisconnect->image->SetVisible(false);
else
{
m_menuItems.push_front(m_pDisconnect);
m_pDisconnect->image->SetVisible(true);
float fTopItemSize = m_pDisconnect->image->GetSize(false).fY;
float fTopItemCentre = m_pDisconnect->image->GetPosition(false).fY + fTopItemSize * 0.5f;
m_menuAY = fTopItemCentre - fTopItemSize * (CORE_MTA_HOVER_SCALE / CORE_MTA_NORMAL_SCALE) * 0.5f; // Top side of the items
m_menuAY += BODGE_FACTOR_1;
m_pMenuArea->SetPosition(CVector2D(m_menuAX - m_iXOff, m_menuAY - m_iYOff) + BODGE_FACTOR_5, false);
m_pMenuArea->SetSize(CVector2D(m_menuBX - m_menuAX, m_menuBY - m_menuAY) + BODGE_FACTOR_6, false);
}
}
}
// Fade in
if (m_ucFade == FADE_IN)
{
// Increment the fader (use the other define if we're fading to the credits)
m_fFader += CORE_MTA_FADER;
float fFadeTarget = m_bIsIngame ? CORE_MTA_BG_INGAME_ALPHA : CORE_MTA_BG_MAX_ALPHA;
m_pFiller->SetAlpha(Clamp<float>(0.f, m_fFader, CORE_MTA_BG_MAX_ALPHA));
m_pFiller2->SetAlpha(Clamp<float>(0.f, m_fFader, CORE_MTA_BG_MAX_ALPHA));
m_pCanvas->SetAlpha(Clamp<float>(0.f, m_fFader, CORE_MTA_BG_MAX_ALPHA));
m_pBackground->SetAlpha(Clamp<float>(0.f, m_fFader, CORE_MTA_BG_MAX_ALPHA));
if (m_fFader > 0.0f)
{
m_bIsVisible = true; // Make cursor appear faster
if (!m_bCursorAlphaReset)
{
CGUI* pGUI = g_pCore->GetGUI();
if (pGUI)
{
pGUI->ResetMenuCursorColor(); // Rest cursor menu color when we open up main menu
m_bCursorAlphaReset = true;
}
}
}
// If the fade is complete
if (m_fFader >= fFadeTarget)
{
m_ucFade = FADE_VISIBLE;
m_bIsVisible = true;
m_bIsFullyVisible = true;
}
}
// Fade out
else if (m_ucFade == FADE_OUT)
{
m_fFader -= CORE_MTA_FADER;
m_pFiller->SetAlpha(Clamp(0.f, m_fFader, CORE_MTA_BG_MAX_ALPHA));
m_pFiller2->SetAlpha(Clamp(0.f, m_fFader, CORE_MTA_BG_MAX_ALPHA));
m_pCanvas->SetAlpha(Clamp(0.f, m_fFader, CORE_MTA_BG_MAX_ALPHA));
m_pBackground->SetAlpha(Clamp(0.f, m_fFader, CORE_MTA_BG_MAX_ALPHA));
if (m_fFader < 1.0f)
{
m_bIsVisible = false; // Make cursor disappear faster
m_bCursorAlphaReset = false;
}
// If the fade is complete
if (m_fFader <= 0)
{
m_bIsFullyVisible = false;
m_ucFade = FADE_INVISIBLE;
m_bIsVisible = false;
// Turn the widgets invisible
m_pFiller->SetVisible(false);
m_pFiller2->SetVisible(false);
m_pCanvas->SetVisible(false);
m_pBackground->SetVisible(false);
}
}
// Force the mainmenu on if we're at GTA's mainmenu or not ingame
if ((SystemState == 7 || SystemState == 9) && !m_bIsIngame)
{
// Cope with early finish
if (pGame->HasCreditScreenFadedOut())
WaitForMenu = std::max(WaitForMenu, 250);
// Fade up
if (WaitForMenu >= 250)
{
m_bIsVisible = true;
m_bStarted = true;
}
// Create headlines while the screen is still black
if (WaitForMenu == 250)
m_pNewsBrowser->CreateHeadlines();
// Start updater after fade up is complete
if (WaitForMenu == 275)
GetVersionUpdater()->EnableChecking(true);
#if _WIN32_WINNT <= _WIN32_WINNT_WINXP
if (WaitForMenu == 275)
{
CCore::GetSingletonPtr()->ShowErrorMessageBox("", XP_VISTA_WARNING, "au-revoir-xp-vista");
}
#endif
if (WaitForMenu == 299)
{
if (!g_pCore->GetCVars()->GetValue("discord_rpc_share_data_firsttime", false)
&& g_pCore->GetCVars()->GetValue("allow_discord_rpc", false)
&& !g_pCore->GetCVars()->GetValue("discord_rpc_share_data", false))
{
m_Settings.ShowRichPresenceShareDataQuestionBox();
CVARS_SET("discord_rpc_share_data_firsttime", true);
}
else
CVARS_SET("discord_rpc_share_data_firsttime", true);
}
if (WaitForMenu < 300)
WaitForMenu++;
}
// If we're visible
if (m_bIsVisible && SystemState != 8)
{
// If we're at the game's mainmenu, or ingame when m_bIsIngame is true show the background
if (SystemState == 7 || // GS_FRONTEND
SystemState == 9 && !m_bIsIngame) // GS_PLAYING_GAME
{
if (m_ucFade == FADE_INVISIBLE)
Show(false);
}
else
{
if (m_ucFade == FADE_INVISIBLE)
Show(true);
}
}
else
{
if (m_ucFade == FADE_VISIBLE)
Hide();
}
ulPreviousTick = GetTickCount32();
// Call subdialog pulses
m_ServerBrowser.Update();
m_ServerInfo.DoPulse();
m_pLanguageSelector->DoPulse();
}
void CMainMenu::Show(bool bOverlay)
{
SetVisible(true, bOverlay);
}
void CMainMenu::Hide()
{
SetVisible(false);
}
// When escape key pressed and not connected, hide these windows
void CMainMenu::OnEscapePressedOffLine()
{
m_ServerBrowser.SetVisible(false);
m_Credits.SetVisible(false);
m_pNewsBrowser->SetVisible(false);
}
void CMainMenu::SetVisible(bool bVisible, bool bOverlay, bool bFrameDelay)
{
CMultiplayer* pMultiplayer = CCore::GetSingleton().GetMultiplayer();
CQuestionBox* pQuestionBox = CCore::GetSingleton().GetLocalGUI()->GetMainMenu()->GetQuestionWindow();
pMultiplayer->DisablePadHandler(bVisible);
if ((m_ucFade == FADE_VISIBLE || m_ucFade == FADE_IN) && bVisible == false)
{
m_ucFade = FADE_OUT;
}
else if ((m_ucFade == FADE_INVISIBLE || m_ucFade == FADE_OUT) && bVisible == true)
{
m_ucFade = FADE_IN;
}
// If we're hiding, hide any subwindows we might've had (prevent escaping hiding mousecursor issue)
if (!bVisible)
{
m_bFrameDelay = bFrameDelay;
SetMenuUnhovered();
m_ServerBrowser.SetVisible(false);
m_Settings.SetVisible(false);
m_Credits.SetVisible(false);
m_pNewsBrowser->SetVisible(false);
if (GetIsIngame() && pQuestionBox->IsVisible())
{
pQuestionBox->Reset();
pQuestionBox->Hide();
}
// m_bIsInSubWindow = false;
}
else
{
m_bFrameDelay = bFrameDelay;
SetMenuUnhovered();
m_pFiller->SetVisible(true);
m_pFiller2->SetVisible(true);
m_pCanvas->SetVisible(true);
m_pBackground->SetVisible(true);
}
m_bHideGame = !bOverlay;
}
bool CMainMenu::IsVisible()
{
return m_bIsVisible;
}
void CMainMenu::SetIsIngame(bool bIsIngame)
{
// Save some performance by making sure we don't do all this if the new state == old
if (m_bIsIngame != bIsIngame)
{
m_bIsIngame = bIsIngame;
m_Settings.SetIsModLoaded(bIsIngame);
m_ulMoveStartTick = GetTickCount32();
if (bIsIngame)
{
m_iMoveTargetPos = m_iSecondItemCentre;
}
else
{
if (m_menuItems.front() == m_pDisconnect)
m_menuItems.pop_front();
float fTopItemSize = m_menuItems.front()->image->GetSize(false).fY;
float fTopItemCentre = m_menuItems.front()->image->GetPosition(false).fY + fTopItemSize * 0.5f;
m_menuAY = fTopItemCentre - fTopItemSize * (CORE_MTA_HOVER_SCALE / CORE_MTA_NORMAL_SCALE) * 0.5f;
m_menuAY += BODGE_FACTOR_1;
m_pMenuArea->SetPosition(CVector2D(m_menuAX - m_iXOff, m_menuAY - m_iYOff) + BODGE_FACTOR_5, false);
m_pMenuArea->SetSize(CVector2D(m_menuBX - m_menuAX, m_menuBY - m_menuAY) + BODGE_FACTOR_6, false);
m_iMoveTargetPos = m_iFirstItemCentre;
}
m_iMoveStartPos = m_menuAY;
}
}
bool CMainMenu::GetIsIngame()
{
return m_bIsIngame;
}
bool CMainMenu::OnMenuEnter(CGUIElement* pElement)
{
m_bMouseOverMenu = true;
return true;
}
bool CMainMenu::OnMenuExit(CGUIElement* pElement)
{
m_bMouseOverMenu = false;
return true;
}
bool CMainMenu::OnMenuClick(CGUIMouseEventArgs Args)
{
CGUIElement* pElement = Args.pWindow;
// Only handle all our clicks to the menu from here
if (!m_pHoveredItem)
return true;
if (Args.button != LeftButton && m_pHoveredItem->menuType != MENU_ITEM_QUICK_CONNECT)
return true;
// For detecting startup problems
WatchDogUserDidInteractWithMenu();
// Possible disconnect question for user
if (g_pCore->IsConnected())
{
switch (m_pHoveredItem->menuType)
{
case MENU_ITEM_HOST_GAME:
case MENU_ITEM_MAP_EDITOR:
AskUserIfHeWantsToDisconnect(m_pHoveredItem->menuType);
return true;
default:
break;
}
}
switch (m_pHoveredItem->menuType)
{
case MENU_ITEM_DISCONNECT:
OnDisconnectButtonClick(pElement);
break;
case MENU_ITEM_QUICK_CONNECT:
OnQuickConnectButtonClick(pElement, Args.button == LeftButton);
break;
case MENU_ITEM_BROWSE_SERVERS:
OnBrowseServersButtonClick(pElement);
break;
case MENU_ITEM_HOST_GAME:
OnHostGameButtonClick();
break;
case MENU_ITEM_MAP_EDITOR:
OnEditorButtonClick();
break;
case MENU_ITEM_SETTINGS:
OnSettingsButtonClick(pElement);
break;
case MENU_ITEM_ABOUT:
OnAboutButtonClick(pElement);
break;
case MENU_ITEM_QUIT:
OnQuitButtonClick(pElement);
break;
default:
break;
}
return true;
}
bool CMainMenu::OnQuickConnectButtonClick(CGUIElement* pElement, bool left)
{
// Return if we haven't faded in yet
if (m_ucFade != FADE_VISIBLE)
return false;
// If we're right clicking, execute special command
if (!left)
{
std::string command;
CVARS_GET("_beta_qc_rightclick_command", command);
g_pCore->GetCommands()->Execute(command.data());
return true;
}
m_ServerBrowser.SetVisible(true);
m_ServerBrowser.OnQuickConnectButtonClick();
return true;
}
bool CMainMenu::OnResumeButtonClick(CGUIElement* pElement)
{
// Return if we haven't faded in yet
if (m_ucFade != FADE_VISIBLE)
return false;
SetVisible(false);
return true;
}
bool CMainMenu::OnBrowseServersButtonClick(CGUIElement* pElement)
{
// Return if we haven't faded in yet
if (m_ucFade != FADE_VISIBLE)
return false;
// if ( !m_bIsInSubWindow )
{
m_ServerBrowser.SetVisible(true);
// m_bIsInSubWindow = true;
}
return true;
}
void CMainMenu::HideServerInfo()
{
m_ServerInfo.Hide();
}
bool CMainMenu::OnDisconnectButtonClick(CGUIElement* pElement)
{
// Return if we haven't faded in yet
if (m_ucFade != FADE_VISIBLE)
return false;
// Send "disconnect" command to the command handler
CCommands::GetSingleton().Execute("disconnect", "");
return true;
}
bool CMainMenu::OnHostGameButtonClick()
{
// Return if we haven't faded in yet
if (m_ucFade != FADE_VISIBLE)
return false;
// Load deathmatch, but with local play
CModManager::GetSingleton().RequestLoad("deathmatch", "local");
return true;
}
bool CMainMenu::OnEditorButtonClick()
{
// Return if we haven't faded in yet
if (m_ucFade != FADE_VISIBLE)
return false;
// Load deathmatch, but with local play
CModManager::GetSingleton().RequestLoad("deathmatch", "editor");
return true;
}
bool CMainMenu::OnSettingsButtonClick(CGUIElement* pElement)
{
// Return if we haven't faded in yet
if (m_ucFade != FADE_VISIBLE)
return false;