-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathBuyMenuGUI.cpp
More file actions
2459 lines (2138 loc) · 95.5 KB
/
BuyMenuGUI.cpp
File metadata and controls
2459 lines (2138 loc) · 95.5 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
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
#include "BuyMenuGUI.h"
#include "CameraMan.h"
#include "WindowMan.h"
#include "FrameMan.h"
#include "PresetMan.h"
#include "ActivityMan.h"
#include "UInputMan.h"
#include "MetaMan.h"
#include "SettingsMan.h"
#include "GUI.h"
#include "AllegroBitmap.h"
#include "AllegroScreen.h"
#include "GUIInputWrapper.h"
#include "GUIControlManager.h"
#include "GUICollectionBox.h"
#include "GUITab.h"
#include "GUIListBox.h"
#include "GUITextBox.h"
#include "GUIButton.h"
#include "GUILabel.h"
#include "DataModule.h"
#include "Controller.h"
#include "SceneObject.h"
#include "MovableObject.h"
#include "MOSprite.h"
#include "MOSRotating.h"
#include "HeldDevice.h"
#include "AHuman.h"
#include "ACraft.h"
#include "System.h"
using namespace RTE;
BITMAP* BuyMenuGUI::s_pCursor = 0;
const std::string BuyMenuGUI::c_DefaultBannerImagePath = "Base.rte/GUIs/BuyMenu/BuyMenuBanner.png";
const std::string BuyMenuGUI::c_DefaultLogoImagePath = "Base.rte/GUIs/BuyMenu/BuyMenuLogo.png";
BuyMenuGUI::BuyMenuGUI() {
Clear();
}
BuyMenuGUI::~BuyMenuGUI() {
Destroy();
}
void BuyMenuGUI::Clear() {
m_pController = 0;
m_pGUIScreen = 0;
m_pGUIInput = 0;
m_pGUIController = 0;
m_MenuEnabled = DISABLED;
m_MenuFocus = OK;
m_FocusChange = false;
m_MenuCategory = CRAFT;
m_MenuSpeed = 8.0;
m_ListItemIndex = 0;
m_DraggedItemIndex = -1;
m_IsDragging = false;
m_LastHoveredMouseIndex = 0;
m_BlinkTimer.Reset();
m_BlinkMode = NOBLINK;
m_MenuTimer.Reset();
m_RepeatStartTimer.Reset();
m_RepeatTimer.Reset();
m_pParentBox = 0;
m_pPopupBox = 0;
m_pPopupText = 0;
m_Banner = nullptr;
m_Logo = nullptr;
for (int i = 0; i < CATEGORYCOUNT; ++i) {
m_pCategoryTabs[i] = 0;
m_CategoryItemIndex[i] = 0;
}
m_MetaPlayer = Players::NoPlayer;
m_NativeTechModule = 0;
m_ForeignCostMult = 4.0;
int moduleCount = g_PresetMan.GetTotalModuleCount();
m_aExpandedModules = new bool[moduleCount];
for (int i = 0; i < moduleCount; ++i)
m_aExpandedModules[i] = i == 0 ? true : false;
m_pShopList = 0;
m_pCartList = 0;
m_pCraftBox = 0;
m_pCraftCollectionBox = 0;
m_pCraftNameLabel = 0;
m_pCraftPriceLabel = 0;
m_pCraftPassengersCaptionLabel = 0;
m_pCraftPassengersLabel = 0;
m_pCraftMassCaptionLabel = 0;
m_pCraftMassLabel = 0;
m_pSelectedCraft = 0;
m_DeliveryWidth = 0;
m_pCostLabel = 0;
m_pBuyButton = 0;
m_ClearOrderButton = nullptr;
m_pSaveButton = 0;
m_pDeleteButton = 0;
m_Loadouts.clear();
m_SelectedLoadoutIndex = -1;
m_PurchaseMade = false;
m_EnforceMaxPassengersConstraint = true;
m_EnforceMaxMassConstraint = true;
m_OnlyShowOwnedItems = false;
m_AllowedItems.clear();
m_AlwaysAllowedItems.clear();
m_OwnedItems.clear();
m_SelectingEquipment = false;
m_LastVisitedEquipmentTab = GUNS;
m_LastVisitedMainTab = BODIES;
m_LastEquipmentScrollPosition = -1;
m_LastMainScrollPosition = -1;
m_FirstMainTab = CRAFT;
m_LastMainTab = LOADOUTS;
m_FirstEquipmentTab = TOOLS;
m_LastEquipmentTab = SHIELDS;
}
int BuyMenuGUI::Create(Controller* pController) {
RTEAssert(pController, "No controller sent to BuyMenyGUI on creation!");
m_pController = pController;
if (!m_pGUIScreen)
m_pGUIScreen = new AllegroScreen(g_FrameMan.GetBackBuffer8());
if (!m_pGUIInput)
m_pGUIInput = new GUIInputWrapper(pController->GetPlayer());
if (!m_pGUIController)
m_pGUIController = new GUIControlManager();
if (!m_pGUIController->Create(m_pGUIScreen, m_pGUIInput, "Base.rte/GUIs/Skins", "DefaultSkin.ini")) {
RTEAbort("Failed to create GUI Control Manager and load it from Base.rte/GUIs/Skins/DefaultSkin.ini");
}
m_pGUIController->Load("Base.rte/GUIs/BuyMenuGUI.ini");
m_pGUIController->EnableMouse(pController->IsMouseControlled());
if (!s_pCursor) {
ContentFile cursorFile("Base.rte/GUIs/Skins/Cursor.png");
s_pCursor = cursorFile.GetAsBitmap();
}
// Stretch the invisible root box to fill the screen
dynamic_cast<GUICollectionBox*>(m_pGUIController->GetControl("base"))->SetSize(g_WindowMan.GetResX(), g_WindowMan.GetResY());
// Make sure we have convenient points to teh containing GUI colleciton boxes that we will manipulate the positions of
if (!m_pParentBox) {
m_pParentBox = dynamic_cast<GUICollectionBox*>(m_pGUIController->GetControl("BuyGUIBox"));
m_pParentBox->SetDrawBackground(true);
m_pParentBox->SetDrawType(GUICollectionBox::Color);
m_Banner = dynamic_cast<GUICollectionBox*>(m_pGUIController->GetControl("CatalogHeader"));
SetBannerImage(c_DefaultBannerImagePath);
m_Logo = dynamic_cast<GUICollectionBox*>(m_pGUIController->GetControl("CatalogLogo"));
SetLogoImage(c_DefaultLogoImagePath);
}
m_pParentBox->SetPositionAbs(-m_pParentBox->GetWidth(), 0);
m_pParentBox->SetEnabled(false);
m_pParentBox->SetVisible(false);
if (!m_pPopupBox) {
m_pPopupBox = dynamic_cast<GUICollectionBox*>(m_pGUIController->GetControl("BuyGUIPopup"));
m_pPopupText = dynamic_cast<GUILabel*>(m_pGUIController->GetControl("PopupText"));
m_pPopupBox->SetDrawType(GUICollectionBox::Panel);
m_pPopupBox->SetDrawBackground(true);
// Never enable the popup, because it steals focus and cuases other windows to think teh cursor left them
m_pPopupBox->SetEnabled(false);
m_pPopupBox->SetVisible(false);
// Set the font
m_pPopupText->SetFont(m_pGUIController->GetSkin()->GetFont("FontSmall.png"));
}
m_pCategoryTabs[CRAFT] = dynamic_cast<GUITab*>(m_pGUIController->GetControl("CraftTab"));
m_pCategoryTabs[BODIES] = dynamic_cast<GUITab*>(m_pGUIController->GetControl("BodiesTab"));
m_pCategoryTabs[MECHA] = dynamic_cast<GUITab*>(m_pGUIController->GetControl("MechaTab"));
m_pCategoryTabs[TOOLS] = dynamic_cast<GUITab*>(m_pGUIController->GetControl("ToolsTab"));
m_pCategoryTabs[GUNS] = dynamic_cast<GUITab*>(m_pGUIController->GetControl("GunsTab"));
m_pCategoryTabs[BOMBS] = dynamic_cast<GUITab*>(m_pGUIController->GetControl("BombsTab"));
m_pCategoryTabs[SHIELDS] = dynamic_cast<GUITab*>(m_pGUIController->GetControl("ShieldsTab"));
m_pCategoryTabs[LOADOUTS] = dynamic_cast<GUITab*>(m_pGUIController->GetControl("LoadoutsTab"));
RefreshTabDisabledStates();
m_pShopList = dynamic_cast<GUIListBox*>(m_pGUIController->GetControl("CatalogLB"));
m_pCartList = dynamic_cast<GUIListBox*>(m_pGUIController->GetControl("OrderLB"));
m_pCraftLabel = dynamic_cast<GUILabel*>(m_pGUIController->GetControl("CraftLabel"));
m_pCraftBox = dynamic_cast<GUITextBox*>(m_pGUIController->GetControl("CraftTB"));
m_pCraftCollectionBox = dynamic_cast<GUICollectionBox*>(m_pGUIController->GetControl("CraftCollection"));
m_pCraftNameLabel = dynamic_cast<GUILabel*>(m_pGUIController->GetControl("CraftNameLabel"));
m_pCraftPriceLabel = dynamic_cast<GUILabel*>(m_pGUIController->GetControl("CraftPriceLabel"));
m_pCraftPassengersCaptionLabel = dynamic_cast<GUILabel*>(m_pGUIController->GetControl("CraftPassengersCaptionLabel"));
m_pCraftPassengersLabel = dynamic_cast<GUILabel*>(m_pGUIController->GetControl("CraftPassengersLabel"));
m_pCraftMassCaptionLabel = dynamic_cast<GUILabel*>(m_pGUIController->GetControl("CraftMassCaptionLabel"));
m_pCraftMassLabel = dynamic_cast<GUILabel*>(m_pGUIController->GetControl("CraftMassLabel"));
m_pCostLabel = dynamic_cast<GUILabel*>(m_pGUIController->GetControl("TotalLabel"));
m_pBuyButton = dynamic_cast<GUIButton*>(m_pGUIController->GetControl("BuyButton"));
m_ClearOrderButton = dynamic_cast<GUIButton*>(m_pGUIController->GetControl("OrderClearButton"));
m_pSaveButton = dynamic_cast<GUIButton*>(m_pGUIController->GetControl("SaveButton"));
m_pDeleteButton = dynamic_cast<GUIButton*>(m_pGUIController->GetControl("DeleteButton"));
m_pSaveButton->SetVisible(false);
m_pDeleteButton->SetVisible(false);
// If we're not split screen horizontally, then stretch out the layout for all the relevant controls
int stretchAmount = g_WindowMan.GetResY() / 2;
if (!g_FrameMan.GetHSplit()) {
m_pParentBox->SetSize(m_pParentBox->GetWidth(), m_pParentBox->GetHeight() + stretchAmount);
m_pShopList->SetSize(m_pShopList->GetWidth(), m_pShopList->GetHeight() + stretchAmount);
m_pCartList->SetSize(m_pCartList->GetWidth(), m_pCartList->GetHeight() + stretchAmount);
m_pCraftLabel->SetPositionAbs(m_pCraftLabel->GetXPos(), m_pCraftLabel->GetYPos() + stretchAmount);
m_pCraftBox->SetPositionAbs(m_pCraftBox->GetXPos(), m_pCraftBox->GetYPos() + stretchAmount);
m_pCraftCollectionBox->SetPositionAbs(m_pCraftCollectionBox->GetXPos(), m_pCraftCollectionBox->GetYPos() + stretchAmount);
m_pCostLabel->SetPositionAbs(m_pCostLabel->GetXPos(), m_pCostLabel->GetYPos() + stretchAmount);
m_pBuyButton->SetPositionAbs(m_pBuyButton->GetXPos(), m_pBuyButton->GetYPos() + stretchAmount);
}
m_pShopList->SetAlternateDrawMode(true);
m_pCartList->SetAlternateDrawMode(true);
m_pShopList->SetMultiSelect(false);
m_pCartList->SetMultiSelect(false);
// Do this manually with the MoseMoved notifications
// m_pShopList->SetHotTracking(true);
// m_pCartList->SetHotTracking(true);
m_pCraftBox->SetLocked(true);
m_pShopList->EnableScrollbars(false, true);
m_pShopList->SetScrollBarThickness(13);
m_pCartList->EnableScrollbars(false, true);
m_pCartList->SetScrollBarThickness(13);
// Load the loadouts initially.. this might be done again later as well by Activity scripts after they set metaplayer etc
LoadAllLoadoutsFromFile();
// Set initial focus, category list, and label settings
m_MenuFocus = OK;
m_FocusChange = true;
m_MenuCategory = CRAFT;
CategoryChange();
UpdateTotalCostLabel(m_pController->GetTeam());
UpdateTotalPassengersLabel(dynamic_cast<const ACraft*>(m_pSelectedCraft), m_pCraftPassengersLabel);
UpdateTotalMassLabel(dynamic_cast<const ACraft*>(m_pSelectedCraft), m_pCraftMassLabel);
// Reset repeat timers
m_RepeatStartTimer.Reset();
m_RepeatTimer.Reset();
return 0;
}
void BuyMenuGUI::Destroy() {
delete m_pGUIController;
delete m_pGUIInput;
delete m_pGUIScreen;
delete[] m_aExpandedModules;
Clear();
}
void BuyMenuGUI::SetBannerImage(const std::string& imagePath) {
ContentFile bannerFile((imagePath.empty() ? c_DefaultBannerImagePath : imagePath).c_str());
m_Banner->SetDrawImage(new AllegroBitmap(bannerFile.GetAsBitmap()));
m_Banner->SetDrawType(GUICollectionBox::Image);
}
void BuyMenuGUI::SetLogoImage(const std::string& imagePath) {
ContentFile logoFile((imagePath.empty() ? c_DefaultLogoImagePath : imagePath).c_str());
m_Logo->SetDrawImage(new AllegroBitmap(logoFile.GetAsBitmap()));
m_Logo->SetDrawType(GUICollectionBox::Image);
}
void BuyMenuGUI::ClearCartList() {
m_pCartList->ClearList();
m_ListItemIndex = 0;
}
void BuyMenuGUI::AddCartItem(const std::string& name, const std::string& rightText, GUIBitmap* pBitmap, const Entity* pEntity, const int extraIndex) {
m_pCartList->AddItem(name, rightText, pBitmap, pEntity, extraIndex);
UpdateItemNestingLevels();
}
void BuyMenuGUI::DuplicateCartItem(const int itemIndex) {
if (m_pCartList->GetItemList()->empty()) {
return;
}
std::vector<GUIListPanel::Item*> addedItems;
auto addDuplicateItemAtEnd = [&](const GUIListPanel::Item* itemToCopy) {
GUIBitmap* pItemBitmap = new AllegroBitmap(dynamic_cast<AllegroBitmap*>(itemToCopy->m_pBitmap)->GetBitmap());
m_pCartList->AddItem(itemToCopy->m_Name, itemToCopy->m_RightText, pItemBitmap, itemToCopy->m_pEntity, itemToCopy->m_ExtraIndex);
return m_pCartList->GetItem(m_pCartList->GetItemList()->size() - 1);
};
bool copyingActorWithInventory = m_pCartList->GetItem(itemIndex)->m_pEntity->GetClassName() == "AHuman";
int currentIndex = itemIndex;
do {
GUIListPanel::Item* newItem = addDuplicateItemAtEnd(*(m_pCartList->GetItemList()->begin() + currentIndex));
newItem->m_ID = currentIndex;
addedItems.push_back(newItem);
currentIndex++;
} while (copyingActorWithInventory &&
currentIndex < m_pCartList->GetItemList()->size() - addedItems.size() &&
dynamic_cast<const HeldDevice*>(m_pCartList->GetItem(currentIndex)->m_pEntity));
// Fix up the IDs of the items we're about to shift.
for (auto itr = m_pCartList->GetItemList()->begin() + itemIndex, itr_end = m_pCartList->GetItemList()->end() - addedItems.size(); itr < itr_end; ++itr) {
(*itr)->m_ID += addedItems.size();
}
// Now shift all items up to make space.
std::copy(m_pCartList->GetItemList()->begin() + itemIndex, m_pCartList->GetItemList()->end() - addedItems.size(), m_pCartList->GetItemList()->begin() + itemIndex + addedItems.size());
// And copy our new items into place.
std::copy(addedItems.begin(), addedItems.end(), m_pCartList->GetItemList()->begin() + itemIndex);
// Reselect the item, so our selection doesn't move.
m_pCartList->SetSelectedIndex(itemIndex);
}
bool BuyMenuGUI::LoadAllLoadoutsFromFile() {
// First clear out all loadouts
m_Loadouts.clear();
m_SelectedLoadoutIndex = -1;
// Try to load the player's loadout settings from file, if there is one
char loadoutPath[256];
// A metagame player
if (m_MetaPlayer != Players::NoPlayer) {
// Start loading any additional stuff from the custom user file
std::snprintf(loadoutPath, sizeof(loadoutPath), "%s%s - LoadoutsMP%d.ini", (System::GetUserdataDirectory() + c_UserConquestSavesModuleName + "/").c_str(), g_MetaMan.GetGameName().c_str(), m_MetaPlayer + 1);
if (!System::PathExistsCaseSensitive(loadoutPath)) {
// If the file doesn't exist, then we're not loading it, are we?
loadoutPath[0] = 0;
}
}
// Not a metagame player, just a regular scenario player
else {
std::snprintf(loadoutPath, sizeof(loadoutPath), "%sLoadoutsP%d.ini", System::GetUserdataDirectory().c_str(), m_pController->GetPlayer() + 1);
}
// Open the file
Reader loadoutFile(loadoutPath, false, nullptr, true, true);
// Read any and all loadout presets from file
while (loadoutFile.ReaderOK() && loadoutFile.NextProperty()) {
Loadout newLoad;
loadoutFile >> newLoad;
// If we successfully found everything this loadout requires, add it to the preset menu
// Why be picky?
if (!newLoad.GetCargoList()->empty()) // newLoad.IsComplete())
m_Loadouts.push_back(newLoad);
}
if (m_NativeTechModule > 0) {
// Then try to get the different standard Loadouts for this' player's native tech module if it's not -All-
const Loadout* pDefaultLoadoutPreset = dynamic_cast<const Loadout*>(g_PresetMan.GetEntityPreset("Loadout", "Default", m_NativeTechModule));
// Add it to the Loadout list - it will be copied inside so no worry about passing in a preset instance
if (pDefaultLoadoutPreset)
m_Loadouts.push_back(*pDefaultLoadoutPreset);
// Attempt to do it for all the other standard loadout types as well
if (pDefaultLoadoutPreset = dynamic_cast<const Loadout*>(g_PresetMan.GetEntityPreset("Loadout", "Infantry Light", m_NativeTechModule)))
m_Loadouts.push_back(*pDefaultLoadoutPreset);
if (pDefaultLoadoutPreset = dynamic_cast<const Loadout*>(g_PresetMan.GetEntityPreset("Loadout", "Infantry Heavy", m_NativeTechModule)))
m_Loadouts.push_back(*pDefaultLoadoutPreset);
if (pDefaultLoadoutPreset = dynamic_cast<const Loadout*>(g_PresetMan.GetEntityPreset("Loadout", "Infantry CQB", m_NativeTechModule)))
m_Loadouts.push_back(*pDefaultLoadoutPreset);
if (pDefaultLoadoutPreset = dynamic_cast<const Loadout*>(g_PresetMan.GetEntityPreset("Loadout", "Infantry Grenadier", m_NativeTechModule)))
m_Loadouts.push_back(*pDefaultLoadoutPreset);
if (pDefaultLoadoutPreset = dynamic_cast<const Loadout*>(g_PresetMan.GetEntityPreset("Loadout", "Infantry Sniper", m_NativeTechModule)))
m_Loadouts.push_back(*pDefaultLoadoutPreset);
if (pDefaultLoadoutPreset = dynamic_cast<const Loadout*>(g_PresetMan.GetEntityPreset("Loadout", "Infantry Engineer", m_NativeTechModule)))
m_Loadouts.push_back(*pDefaultLoadoutPreset);
if (pDefaultLoadoutPreset = dynamic_cast<const Loadout*>(g_PresetMan.GetEntityPreset("Loadout", "Mecha", m_NativeTechModule)))
m_Loadouts.push_back(*pDefaultLoadoutPreset);
if (pDefaultLoadoutPreset = dynamic_cast<const Loadout*>(g_PresetMan.GetEntityPreset("Loadout", "Turret", m_NativeTechModule)))
m_Loadouts.push_back(*pDefaultLoadoutPreset);
}
// If no file was found, try to load a Tech module-specified loadout defaults!
if (m_Loadouts.empty()) {
// Try to get the default Loadout for this' player's native tech module
const Loadout* pDefaultLoadoutPreset = dynamic_cast<const Loadout*>(g_PresetMan.GetEntityPreset("Loadout", "Default", m_NativeTechModule));
// Add it to the Loadout list - it will be copied inside so no worry about passing in a preset instance
if (pDefaultLoadoutPreset)
m_Loadouts.push_back(*pDefaultLoadoutPreset);
}
/* This is dangerous, crash prone and unneccessary
// If there were no loadouts to load, or no file present, or default Presets defined, set up a single failsafe default one
if (m_Loadouts.empty())
{
Loadout defaultLoadout;
// Default craft
defaultLoadout.SetDeliveryCraft(dynamic_cast<const ACraft *>(g_PresetMan.GetEntityPreset("ACRocket", "Rocket MK1")));
// Default passenger
defaultLoadout.AddToCargoList(dynamic_cast<const AHuman *>(g_PresetMan.GetEntityPreset("AHuman", "Robot 1")));
// Default primary weapon
defaultLoadout.AddToCargoList(dynamic_cast<const MOSprite *>(g_PresetMan.GetEntityPreset("HDFirearm", "SMG")));
// Default tool
defaultLoadout.AddToCargoList(dynamic_cast<const MOSprite *>(g_PresetMan.GetEntityPreset("HDFirearm", "Medium Digger")));
// Add to list
if (defaultLoadout.IsComplete())
m_Loadouts.push_back(defaultLoadout);
}
*/
// Load the first loadout preset into the cart by default
DeployLoadout(0);
// Refresh all views so we see the new sets if we're in the preset category
CategoryChange();
return true;
}
bool BuyMenuGUI::SaveAllLoadoutsToFile() {
// Nothing to save
if (m_Loadouts.empty())
return true;
char loadoutPath[256];
// A metagame player
if (m_MetaPlayer != Players::NoPlayer) {
// If a new metagame, then just save over the metagame autosave instead of to the new game save
// Since the players of a new game are likely to have different techs and therefore different default loadouts
// So we should start fresh with new loadouts loaded from tech defaults for each player
if (g_MetaMan.GetGameName() == DEFAULTGAMENAME)
std::snprintf(loadoutPath, sizeof(loadoutPath), "%s%s - LoadoutsMP%d.ini", (System::GetUserdataDirectory() + c_UserConquestSavesModuleName + "/").c_str(), AUTOSAVENAME, m_MetaPlayer + 1);
else
std::snprintf(loadoutPath, sizeof(loadoutPath), "%s%s - LoadoutsMP%d.ini", (System::GetUserdataDirectory() + c_UserConquestSavesModuleName + "/").c_str(), g_MetaMan.GetGameName().c_str(), m_MetaPlayer + 1);
} else
std::snprintf(loadoutPath, sizeof(loadoutPath), "%sLoadoutsP%d.ini", System::GetUserdataDirectory().c_str(), m_pController->GetPlayer() + 1);
// Open the file
Writer loadoutFile(loadoutPath, false);
// Write out all the loadouts that are user made.
for (const Loadout& loadoutEntry: m_Loadouts) {
// Don't write out preset references, they'll be read first from PresetMan on load anyway
if (loadoutEntry.GetPresetName() == "None") {
loadoutFile.NewPropertyWithValue("AddLoadout", loadoutEntry);
}
}
return true;
}
void BuyMenuGUI::SetEnabled(bool enable) {
if (enable && m_MenuEnabled != ENABLED && m_MenuEnabled != ENABLING) {
// If we're not split screen horizontally, then stretch out the layout for all the relevant controls
int stretchAmount = g_FrameMan.GetPlayerScreenHeight() - m_pParentBox->GetHeight();
if (stretchAmount != 0) {
m_pParentBox->SetSize(m_pParentBox->GetWidth(), m_pParentBox->GetHeight() + stretchAmount);
m_pShopList->SetSize(m_pShopList->GetWidth(), m_pShopList->GetHeight() + stretchAmount);
m_pCartList->SetSize(m_pCartList->GetWidth(), m_pCartList->GetHeight() + stretchAmount);
m_pCraftLabel->SetPositionAbs(m_pCraftLabel->GetXPos(), m_pCraftLabel->GetYPos() + stretchAmount);
m_pCraftBox->SetPositionAbs(m_pCraftBox->GetXPos(), m_pCraftBox->GetYPos() + stretchAmount);
m_pCraftCollectionBox->SetPositionAbs(m_pCraftCollectionBox->GetXPos(), m_pCraftCollectionBox->GetYPos() + stretchAmount);
m_pCostLabel->SetPositionAbs(m_pCostLabel->GetXPos(), m_pCostLabel->GetYPos() + stretchAmount);
m_pBuyButton->SetPositionAbs(m_pBuyButton->GetXPos(), m_pBuyButton->GetYPos() + stretchAmount);
}
m_MenuEnabled = ENABLING;
// Reset repeat timers
m_RepeatStartTimer.Reset();
m_RepeatTimer.Reset();
// Set the mouse cursor free
g_UInputMan.TrapMousePos(false, m_pController->GetPlayer());
// Move the mouse cursor to the middle of the player's screen
int mouseOffX, mouseOffY;
m_pGUIInput->GetMouseOffset(mouseOffX, mouseOffY);
Vector mousePos(-mouseOffX + (g_FrameMan.GetPlayerFrameBufferWidth(m_pController->GetPlayer()) / 2), -mouseOffY + (g_FrameMan.GetPlayerFrameBufferHeight(m_pController->GetPlayer()) / 2));
g_UInputMan.SetMousePos(mousePos, m_pController->GetPlayer());
// Default focus to the menu button
m_LastHoveredMouseIndex = 0;
m_MenuFocus = OK;
m_FocusChange = true;
UpdateTotalCostLabel(m_pController->GetTeam());
UpdateTotalPassengersLabel(dynamic_cast<const ACraft*>(m_pSelectedCraft), m_pCraftPassengersLabel);
UpdateTotalMassLabel(dynamic_cast<const ACraft*>(m_pSelectedCraft), m_pCraftMassLabel);
g_GUISound.EnterMenuSound()->Play(m_pController->GetPlayer());
} else if (!enable && m_MenuEnabled != DISABLED && m_MenuEnabled != DISABLING) {
EnableEquipmentSelection(false);
m_MenuEnabled = DISABLING;
// Trap the mouse cursor again
g_UInputMan.TrapMousePos(true, m_pController->GetPlayer());
// Only play switching away sound
// if (!m_PurchaseMade)
g_GUISound.ExitMenuSound()->Play(m_pController->GetPlayer());
}
}
void BuyMenuGUI::SetPosOnScreen(int newPosX, int newPosY) {
m_pGUIController->SetPosOnScreen(newPosX, newPosY);
}
void BuyMenuGUI::SetMetaPlayer(int metaPlayer) {
if (metaPlayer >= Players::PlayerOne && metaPlayer < g_MetaMan.GetPlayerCount()) {
m_MetaPlayer = metaPlayer;
SetNativeTechModule(g_MetaMan.GetPlayer(m_MetaPlayer)->GetNativeTechModule());
SetForeignCostMultiplier(g_MetaMan.GetPlayer(m_MetaPlayer)->GetForeignCostMultiplier());
}
}
void BuyMenuGUI::SetNativeTechModule(int whichModule) {
if (whichModule >= 0 && whichModule < g_PresetMan.GetTotalModuleCount()) {
m_NativeTechModule = whichModule;
SetModuleExpanded(m_NativeTechModule);
DeployLoadout(0);
if (!g_SettingsMan.FactionBuyMenuThemesDisabled() && m_NativeTechModule > 0) {
if (const DataModule* techModule = g_PresetMan.GetDataModule(whichModule); techModule->IsFaction()) {
const DataModule::BuyMenuTheme& techBuyMenuTheme = techModule->GetFactionBuyMenuTheme();
if (!techBuyMenuTheme.SkinFilePath.empty()) {
// Not specifying the skin file directory allows us to load image files from the whole working directory in the skin file instead of just the specified directory.
m_pGUIController->ChangeSkin("", techBuyMenuTheme.SkinFilePath);
// Popup box text is GUILabel so we need to override the "Label" section font with the "DescriptionBoxText" section font so we can use a different font without screwing with all the other labels.
std::string themeDescriptionBoxTextFont;
m_pGUIController->GetSkin()->GetValue("DescriptionBoxText", "Font", &themeDescriptionBoxTextFont);
m_pPopupText->SetFont(m_pGUIController->GetSkin()->GetFont(themeDescriptionBoxTextFont));
}
if (techBuyMenuTheme.BackgroundColorIndex >= 0) {
m_pParentBox->SetDrawColor(std::clamp(techBuyMenuTheme.BackgroundColorIndex, 0, 255));
}
SetBannerImage(techBuyMenuTheme.BannerImagePath);
SetLogoImage(techBuyMenuTheme.LogoImagePath);
}
}
}
}
void BuyMenuGUI::SetModuleExpanded(int whichModule, bool expanded) {
int moduleCount = g_PresetMan.GetTotalModuleCount();
if (whichModule > 0 && whichModule < moduleCount) {
m_aExpandedModules[whichModule] = expanded;
// Refresh the item view with the newly expanded module items
CategoryChange(false);
}
// If base module (0), or out of range module, then affect all
else {
for (int m = 0; m < moduleCount; ++m)
m_aExpandedModules[m] = expanded;
}
}
bool BuyMenuGUI::GetOrderList(std::list<const SceneObject*>& listToFill) const {
if (m_pCartList->GetItemList()->empty())
return false;
const SceneObject* pSObject = 0;
for (std::vector<GUIListPanel::Item*>::iterator itr = m_pCartList->GetItemList()->begin(); itr != m_pCartList->GetItemList()->end(); ++itr) {
if (pSObject = dynamic_cast<const SceneObject*>((*itr)->m_pEntity))
listToFill.push_back(pSObject);
}
return true;
}
bool BuyMenuGUI::CommitPurchase(std::string presetName) {
if (m_OwnedItems.size() > 0) {
if (m_OwnedItems.find(presetName) != m_OwnedItems.end() && m_OwnedItems[presetName] > 0) {
m_OwnedItems[presetName] -= 1;
return true;
} else
return false;
}
return false;
}
float BuyMenuGUI::GetTotalCost(bool includeDelivery) const {
float totalCost = 0;
if (m_OwnedItems.size() > 0) {
std::map<std::string, int> orderedItems;
for (std::vector<GUIListPanel::Item*>::iterator itr = m_pCartList->GetItemList()->begin(); itr != m_pCartList->GetItemList()->end(); ++itr) {
bool needsToBePaid = true;
std::string presetName = (*itr)->m_pEntity->GetModuleAndPresetName();
if (orderedItems.find(presetName) != orderedItems.end())
orderedItems[presetName] = 1;
else
orderedItems[presetName] += 1;
auto itrFound = m_OwnedItems.find(presetName);
if (itrFound != m_OwnedItems.end() && itrFound->second >= orderedItems[presetName])
needsToBePaid = false;
if (needsToBePaid) {
totalCost += dynamic_cast<const MOSprite*>((*itr)->m_pEntity)->GetGoldValue(m_NativeTechModule, m_ForeignCostMult);
}
}
if (m_pSelectedCraft && includeDelivery) {
bool needsToBePaid = true;
std::string presetName = m_pSelectedCraft->GetModuleAndPresetName();
if (orderedItems.find(presetName) != orderedItems.end())
orderedItems[presetName] = 1;
else
orderedItems[presetName] += 1;
auto itrFound = m_OwnedItems.find(presetName);
if (itrFound != m_OwnedItems.end() && itrFound->second >= orderedItems[presetName])
needsToBePaid = false;
if (needsToBePaid) {
totalCost += dynamic_cast<const MOSprite*>(m_pSelectedCraft)->GetGoldValue(m_NativeTechModule, m_ForeignCostMult);
}
}
} else {
for (std::vector<GUIListPanel::Item*>::iterator itr = m_pCartList->GetItemList()->begin(); itr != m_pCartList->GetItemList()->end(); ++itr)
totalCost += dynamic_cast<const MOSprite*>((*itr)->m_pEntity)->GetGoldValue(m_NativeTechModule, m_ForeignCostMult);
// Add the delivery craft's cost
if (m_pSelectedCraft && includeDelivery) {
totalCost += dynamic_cast<const MOSprite*>(m_pSelectedCraft)->GetGoldValue(m_NativeTechModule, m_ForeignCostMult);
}
}
return totalCost;
}
float BuyMenuGUI::GetTotalOrderMass() const {
float totalMass = 0.0F;
for (const GUIListPanel::Item* cartItem: *m_pCartList->GetItemList()) {
const MovableObject* itemAsMO = dynamic_cast<const MovableObject*>(cartItem->m_pEntity);
if (itemAsMO) {
totalMass += itemAsMO->GetMass();
} else {
RTEAbort("Found a non-MO object in the cart and tried to add it's mass to order total!");
}
}
return totalMass;
}
float BuyMenuGUI::GetCraftMass() {
float totalMass = 0;
// Add the delivery craft's mass
if (m_pSelectedCraft)
totalMass += dynamic_cast<const MOSprite*>(m_pSelectedCraft)->GetMass();
return totalMass;
}
int BuyMenuGUI::GetTotalOrderPassengers() const {
int passengers = 0;
for (std::vector<GUIListPanel::Item*>::iterator itr = m_pCartList->GetItemList()->begin(); itr != m_pCartList->GetItemList()->end(); ++itr) {
const Actor* passenger = dynamic_cast<const Actor*>((*itr)->m_pEntity);
if (passenger) {
passengers += passenger->GetPassengerSlots();
}
}
return passengers;
}
void BuyMenuGUI::EnableEquipmentSelection(bool enabled) {
if (enabled != m_SelectingEquipment && g_SettingsMan.SmartBuyMenuNavigationEnabled()) {
m_SelectingEquipment = enabled;
RefreshTabDisabledStates();
if (m_SelectingEquipment) {
m_LastVisitedMainTab = static_cast<MenuCategory>(m_MenuCategory);
m_LastMainScrollPosition = m_pShopList->GetScrollVerticalValue();
m_MenuCategory = m_LastVisitedEquipmentTab;
} else {
m_LastVisitedEquipmentTab = static_cast<MenuCategory>(m_MenuCategory);
m_LastEquipmentScrollPosition = m_pShopList->GetScrollVerticalValue();
m_MenuCategory = m_LastVisitedMainTab;
}
CategoryChange();
m_pShopList->ScrollTo(m_SelectingEquipment ? m_LastEquipmentScrollPosition : m_LastMainScrollPosition);
m_MenuFocus = ITEMS;
m_FocusChange = 1;
g_GUISound.SelectionChangeSound()->Play(m_pController->GetPlayer());
}
}
void BuyMenuGUI::UpdateItemNestingLevels() {
const int ownedDeviceOffsetX = 8;
int nextHeldDeviceBelongsToAHuman = false;
for (GUIListPanel::Item* cartItem: (*m_pCartList->GetItemList())) {
if (dynamic_cast<const AHuman*>(cartItem->m_pEntity)) {
nextHeldDeviceBelongsToAHuman = true;
} else if (!dynamic_cast<const HeldDevice*>(cartItem->m_pEntity)) {
nextHeldDeviceBelongsToAHuman = false;
} else {
cartItem->m_OffsetX = nextHeldDeviceBelongsToAHuman ? ownedDeviceOffsetX : 0;
}
}
m_pCartList->BuildBitmap(false, true);
}
void BuyMenuGUI::RefreshTabDisabledStates() {
bool smartBuyMenuNavigationDisabled = !g_SettingsMan.SmartBuyMenuNavigationEnabled();
m_pCategoryTabs[CRAFT]->SetEnabled(smartBuyMenuNavigationDisabled || !m_SelectingEquipment);
m_pCategoryTabs[BODIES]->SetEnabled(smartBuyMenuNavigationDisabled || !m_SelectingEquipment);
m_pCategoryTabs[MECHA]->SetEnabled(smartBuyMenuNavigationDisabled || !m_SelectingEquipment);
m_pCategoryTabs[TOOLS]->SetEnabled(smartBuyMenuNavigationDisabled || m_SelectingEquipment);
m_pCategoryTabs[GUNS]->SetEnabled(smartBuyMenuNavigationDisabled || m_SelectingEquipment);
m_pCategoryTabs[BOMBS]->SetEnabled(smartBuyMenuNavigationDisabled || m_SelectingEquipment);
m_pCategoryTabs[SHIELDS]->SetEnabled(smartBuyMenuNavigationDisabled || m_SelectingEquipment);
m_pCategoryTabs[LOADOUTS]->SetEnabled(smartBuyMenuNavigationDisabled || !m_SelectingEquipment);
}
void BuyMenuGUI::Update() {
// Enable mouse input if the controller allows it
m_pGUIController->EnableMouse(m_pController->IsMouseControlled());
// Reset the purchasing indicator
m_PurchaseMade = false;
// Popup box is hidden by default
m_pPopupBox->SetVisible(false);
////////////////////////////////////////////////////////////////////////
// Animate the menu into and out of view if enabled or disabled
if (m_MenuEnabled == ENABLING) {
// Make sure that nobody can hoard focus away from us
m_pGUIController->GetManager()->ReleaseMouse();
m_pParentBox->SetEnabled(true);
m_pParentBox->SetVisible(true);
Vector position, occlusion;
float toGo = -std::floor((float)m_pParentBox->GetXPos());
float goProgress = m_MenuSpeed * m_MenuTimer.GetElapsedRealTimeS();
if (goProgress > 1.0)
goProgress = 1.0;
position.m_X = m_pParentBox->GetXPos() + std::ceil(toGo * goProgress);
occlusion.m_X = m_pParentBox->GetWidth() + m_pParentBox->GetXPos();
// If not split screened, then make the menu scroll in diagonally instead of straight from the side
// Tie it to the (X) horizontal position
// EDIT: nah, just make the menu larger, but do change the occlusion, looks better
if (!g_FrameMan.GetHSplit()) {
// position.m_Y = -m_pParentBox->GetHeight() * fabs(position.m_X / m_pParentBox->GetWidth());
// occlusion.m_Y = m_pParentBox->GetHeight() + m_pParentBox->GetYPos();
occlusion.m_Y = m_pParentBox->GetHeight() / 2;
}
m_pParentBox->SetPositionAbs(position.m_X, position.m_Y);
g_CameraMan.SetScreenOcclusion(occlusion, g_ActivityMan.GetActivity()->ScreenOfPlayer(m_pController->GetPlayer()));
if (m_pParentBox->GetXPos() >= 0) {
m_MenuEnabled = ENABLED;
CategoryChange();
}
}
// Animate the menu out of view
else if (m_MenuEnabled == DISABLING) {
float toGo = -std::ceil(((float)m_pParentBox->GetWidth() + (float)m_pParentBox->GetXPos()));
float goProgress = m_MenuSpeed * m_MenuTimer.GetElapsedRealTimeS();
if (goProgress > 1.0)
goProgress = 1.0;
m_pParentBox->SetPositionAbs(m_pParentBox->GetXPos() + std::floor(toGo * goProgress), 0);
g_CameraMan.SetScreenOcclusion(Vector(m_pParentBox->GetWidth() + m_pParentBox->GetXPos(), 0), g_ActivityMan.GetActivity()->ScreenOfPlayer(m_pController->GetPlayer()));
m_pPopupBox->SetVisible(false);
if (m_pParentBox->GetXPos() <= -m_pParentBox->GetWidth()) {
m_pParentBox->SetEnabled(false);
m_pParentBox->SetVisible(false);
m_MenuEnabled = DISABLED;
}
} else if (m_MenuEnabled == ENABLED) {
m_pParentBox->SetEnabled(true);
m_pParentBox->SetVisible(true);
} else if (m_MenuEnabled == DISABLED) {
m_pParentBox->SetEnabled(false);
m_pParentBox->SetVisible(false);
m_pPopupBox->SetVisible(false);
}
// Reset the menu animation timer so we can measure how long it takes till next frame
m_MenuTimer.Reset();
// Quit now if we aren't enabled
if (m_MenuEnabled != ENABLED && m_MenuEnabled != ENABLING)
return;
// Update the user controller
// m_pController->Update();
// Gotto update this all the time because other players may have bought stuff and changed the funds available to the team
UpdateTotalCostLabel(m_pController->GetTeam());
UpdateTotalPassengersLabel(dynamic_cast<const ACraft*>(m_pSelectedCraft), m_pCraftPassengersLabel);
UpdateTotalMassLabel(dynamic_cast<const ACraft*>(m_pSelectedCraft), m_pCraftMassLabel);
/////////////////////////////////////////////////////
// Mouse cursor logic
int mousePosX;
int mousePosY;
m_pGUIInput->GetMousePosition(&mousePosX, &mousePosY);
////////////////////////////////////////////
// Notification blinking logic
if (m_BlinkMode == NOFUNDS) {
m_pCostLabel->SetVisible(m_BlinkTimer.AlternateSim(250));
} else if (m_BlinkMode == NOCRAFT) {
bool blink = m_BlinkTimer.AlternateSim(250);
m_pCraftLabel->SetVisible(blink);
m_pCraftBox->SetVisible(blink);
m_pCraftCollectionBox->SetVisible(blink);
} else if (m_BlinkMode == MAXMASS) {
m_pCraftMassLabel->SetVisible(m_BlinkTimer.AlternateSim(250));
m_pCraftMassCaptionLabel->SetVisible(m_BlinkTimer.AlternateSim(250));
} else if (m_BlinkMode == MAXPASSENGERS) {
m_pCraftPassengersLabel->SetVisible(m_BlinkTimer.AlternateSim(250));
m_pCraftPassengersCaptionLabel->SetVisible(m_BlinkTimer.AlternateSim(250));
}
// Time out the blinker
if (m_BlinkMode != NOBLINK && m_BlinkTimer.IsPastSimMS(1500)) {
m_pCostLabel->SetVisible(true);
m_pCraftLabel->SetVisible(true);
m_pCraftBox->SetVisible(true);
m_pCraftCollectionBox->SetVisible(true);
m_pCraftMassCaptionLabel->SetVisible(true);
m_pCraftMassLabel->SetVisible(true);
m_pCraftPassengersCaptionLabel->SetVisible(true);
m_pCraftPassengersLabel->SetVisible(true);
m_BlinkMode = NOBLINK;
}
/////////////////////////////////////////////
// Repeating input logic
bool isKeyboardControlled = !m_pController->IsMouseControlled() && !m_pController->IsGamepadControlled();
bool pressLeft = m_pController->IsState(PRESS_LEFT);
bool pressRight = m_pController->IsState(PRESS_RIGHT);
bool pressUp = m_pController->IsState(PRESS_UP);
bool pressDown = m_pController->IsState(PRESS_DOWN);
bool pressScrollUp = m_pController->IsState(SCROLL_UP);
bool pressScrollDown = m_pController->IsState(SCROLL_DOWN);
bool pressNextActor = m_pController->IsState(ACTOR_NEXT);
bool pressPrevActor = m_pController->IsState(ACTOR_PREV);
// If no direciton is held down, then cancel the repeating
if (!(m_pController->IsState(MOVE_RIGHT) || m_pController->IsState(MOVE_LEFT) || m_pController->IsState(MOVE_UP) || m_pController->IsState(MOVE_DOWN) || m_pController->IsState(ACTOR_NEXT_PREP) || m_pController->IsState(ACTOR_PREV_PREP))) {
m_RepeatStartTimer.Reset();
m_RepeatTimer.Reset();
}
// Check if any direction has been held for the starting amount of time to get into repeat mode
if (m_RepeatStartTimer.IsPastRealMS(350)) {
// Check for the repeat interval
if (m_RepeatTimer.IsPastRealMS(125)) {
if (m_pController->IsState(MOVE_RIGHT)) {
pressRight = true;
} else if (m_pController->IsState(MOVE_LEFT)) {
pressLeft = true;
} else if (m_pController->IsState(MOVE_UP)) {
pressUp = true;
} else if (m_pController->IsState(MOVE_DOWN)) {
pressDown = true;
} else if (m_pController->IsState(ACTOR_NEXT_PREP)) {
pressNextActor = true;
} else if (m_pController->IsState(ACTOR_PREV_PREP)) {
pressPrevActor = true;
}
m_RepeatTimer.Reset();
}
}
/////////////////////////////////////////////
// Change focus as the user directs
if (pressRight) {
m_MenuFocus++;
m_FocusChange = 1;
// Went too far. Don't allow focusing the clear order button by pressing right, will most definitely lead to accidental clearing and rage.
if (m_MenuFocus >= MenuFocus::CLEARORDER) {
m_MenuFocus = MenuFocus::CLEARORDER - 1;
m_FocusChange = 0;
g_GUISound.UserErrorSound()->Play(m_pController->GetPlayer());
}
// Skip categories if we're going sideways from the sets buttons
if (m_MenuFocus == CATEGORIES) {
m_MenuFocus++;
m_FocusChange++;
}
// Skip giving focus to the items list if it's empty
if (m_MenuFocus == ITEMS && m_pShopList->GetItemList()->empty()) {
m_MenuFocus++;
m_FocusChange++;
}
// Skip giving focus to the order list if it's empty
if (m_MenuFocus == ORDER && m_pCartList->GetItemList()->empty()) {
m_MenuFocus++;
m_FocusChange++;
}
} else if (pressLeft) {
m_MenuFocus--;
m_FocusChange = -1;
// Went too far
if (m_MenuFocus < 0) {
m_MenuFocus = 0;
g_GUISound.UserErrorSound()->Play(m_pController->GetPlayer());
}
// Skip giving focus to the order or item list if they're empty
if (m_MenuFocus == ORDER && m_pCartList->GetItemList()->empty()) {
m_MenuFocus--;
m_FocusChange--;
}
// Skip giving focus to the items list if it's empty
if (m_MenuFocus == ITEMS && m_pShopList->GetItemList()->empty()) {
m_MenuFocus--;
m_FocusChange--;
}
}
// Play focus change sound, if applicable
if (m_FocusChange && m_MenuEnabled != ENABLING)
g_GUISound.FocusChangeSound()->Play(m_pController->GetPlayer());
/* Blah, should control whatever is currently focused
// Mouse wheel only controls the categories, so switch to it and make the category go up or down
if (m_pController->IsState(SCROLL_UP) || m_pController->IsState(SCROLL_DOWN))
{
m_FocusChange = CATEGORIES - m_MenuFocus;
m_MenuFocus = CATEGORIES;
}
*/
/////////////////////////////////////////
// Change Category directly
if (pressNextActor || pressPrevActor) {
bool smartBuyMenuNavigationEnabled = g_SettingsMan.SmartBuyMenuNavigationEnabled();
if (pressNextActor) {
m_MenuCategory++;
if (!smartBuyMenuNavigationEnabled) {
m_MenuCategory = m_MenuCategory >= MenuCategory::CATEGORYCOUNT ? 0 : m_MenuCategory;
} else if (m_SelectingEquipment && m_MenuCategory > m_LastEquipmentTab) {
m_MenuCategory = m_FirstEquipmentTab;
} else if (!m_SelectingEquipment) {
if (m_MenuCategory > m_LastMainTab) {
m_MenuCategory = m_FirstMainTab;
} else if (m_MenuCategory == m_FirstEquipmentTab) {
m_MenuCategory = m_LastMainTab;
}
}
} else if (pressPrevActor) {
m_MenuCategory--;
if (!smartBuyMenuNavigationEnabled) {
m_MenuCategory = m_MenuCategory < 0 ? MenuCategory::CATEGORYCOUNT - 1 : m_MenuCategory;
} else if (m_SelectingEquipment && m_MenuCategory < m_FirstEquipmentTab) {
m_MenuCategory = m_LastEquipmentTab;
} else if (!m_SelectingEquipment) {
if (m_MenuCategory < m_FirstMainTab) {
m_MenuCategory = m_LastMainTab;
} else if (m_MenuCategory == m_LastEquipmentTab) {
m_MenuCategory = m_FirstEquipmentTab - 1;
}
}
}
CategoryChange();
g_GUISound.SelectionChangeSound()->Play(m_pController->GetPlayer());
m_MenuFocus = ITEMS;
m_FocusChange = 1;
}
/////////////////////////////////////////
// Scroll buy menu