-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMenu.cpp
More file actions
1412 lines (1129 loc) · 66.2 KB
/
Menu.cpp
File metadata and controls
1412 lines (1129 loc) · 66.2 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 "Menu.h"
#include <sstream>
#include <dirent.h>
#include <fstream>
#include <OVR_LogUtils.h>
#include <VrApi_SystemUtils.h>
#include <VirtualBoyGo/Src/main.h>
#include "drawHelper.h"
#include "layerBuilder.h"
#include "emulator.h"
#include "Audio/OpenSLWrap.h"
#include "FontMaster.h"
#include "TextureLoader.h"
#include "MenuHelper.h"
#include "Global.h"
#include "ButtonMapping.h"
#define OPEN_MENU_SPEED 0.15f
#define MENU_TRANSITION_SPEED 0.15f
#define MAPPING_OVERLAY_SPEED 0.15f
#define MAX_SAVE_SLOTS 10
#define RotateSpeed 0.5
#define MoveSpeed 0.03125f
#define ZoomSpeed 0.0625f
#define MIN_DISTANCE 0.5f
#define MAX_DISTANCE 10.0f
using namespace OVRFW;
const int batteryColorCount = 5;
const ovrVector4f BatteryColors[] = {{0.745F, 0.114F, 0.176F, 1.0F},
{0.92F, 0.361F, 0.176F, 1.0F},
{0.976F, 0.69F, 0.255F, 1.0F},
{0.545F, 0.769F, 0.247F, 1.0F},
{0.545F, 0.769F, 0.247F, 1.0F},
{0.0F, 0.78F, 0.078F, 1.0F},
{0.0F, 0.78F, 0.078F, 1.0F}};
const std::string strMove[] = {"Follow Head: Yes", "Follow Head: No"};
template<typename T>
static std::string ToString(T value) {
std::ostringstream os;
os << value;
return os.str();
}
void MenuGo::Free() {
vrapi_DestroyTextureSwapChain(MenuSwapChain);
}
void MenuGo::Init(Emulator *_emulator, LayerBuilder *_layerBuilder, DrawHelper *_drawHelper, FontManager *_fontManager,
const ovrJava *_java, jclass *_clsData) {
emulator = _emulator;
layerBuilder = _layerBuilder;
drawHelper = _drawHelper;
fontManager = _fontManager;
emulator->OnRomLoaded = std::bind(&MenuGo::ResetMenuState, this);
java = _java;
clsData = _clsData;
getVal = java->Env->GetMethodID(*clsData, "GetBatteryLevel", "()I");
}
void MenuGo::SetUpMenu() {
OVR_LOG_WITH_TAG("Menu", "Set up Menu");
int bigGap = 10;
int smallGap = 5;
OVR_LOG_WITH_TAG("Menu", "got emulator");
ovrVirtualBoyGo::global.menuItemSize = (ovrVirtualBoyGo::global.fontMenu.FontSize + 4);
{
OVR_LOG_WITH_TAG("Menu", "Set up rom selection menu");
emulator->InitRomSelectionMenu(0, 0, romSelectionMenu);
romSelectionMenu.CurrentSelection = 0;
romSelectionMenu.BackPress = std::bind(&MenuGo::OnBackPressedRomList, this);
romSelectionMenu.Init();
}
{
OVR_LOG_WITH_TAG("Menu", "Set up bottom bar");
// TODO: now that the menu button can be mapped to ever button not so sure what to do with this
// menuHelp = new MenuButton(&fontBottom, buttonMappingMenu.Buttons[0].Button == EmuButton_X ? textureButtonXIconId : textureButtonYIconId,
// "Close Menu", 7, MENU_HEIGHT - BOTTOM_HEIGHT, 0, BOTTOM_HEIGHT, nullptr, nullptr, nullptr);
// menuHelp->Color = MenuBottomColor;
// bottomBar.MenuItems.push_back(menuHelp);
backHelp = std::make_unique<MenuButton>(&ovrVirtualBoyGo::global.fontBottom,
ovrVirtualBoyGo::global.SwappSelectBackButton ? ovrVirtualBoyGo::global.textureButtonAIconId
: ovrVirtualBoyGo::global.textureButtonBIconId,
"Back", emulator->MENU_WIDTH - 210, emulator->MENU_HEIGHT - emulator->BOTTOM_HEIGHT, 0, emulator->BOTTOM_HEIGHT,
nullptr, nullptr, nullptr);
backHelp->Color = ovrVirtualBoyGo::global.MenuBottomColor;
bottomBar.MenuItems.push_back(backHelp);
selectHelp = std::make_unique<MenuButton>(&ovrVirtualBoyGo::global.fontBottom,
ovrVirtualBoyGo::global.SwappSelectBackButton ? ovrVirtualBoyGo::global.textureButtonBIconId
: ovrVirtualBoyGo::global.textureButtonAIconId,
"Select", emulator->MENU_WIDTH - 110, emulator->MENU_HEIGHT - emulator->BOTTOM_HEIGHT, 0,
emulator->BOTTOM_HEIGHT, nullptr,
nullptr, nullptr);
selectHelp->Color = ovrVirtualBoyGo::global.MenuBottomColor;
bottomBar.MenuItems.push_back(selectHelp);
currentBottomBar = &bottomBar;
}
int posX = 20;
int posY = emulator->HEADER_HEIGHT + 20;
using namespace std::placeholders;
// -- main menu page --
auto buttonResumeGame = std::make_shared<MenuButton>(&ovrVirtualBoyGo::global.fontMenu, ovrVirtualBoyGo::global.textureResumeId,
"Resume Game",
posX, posY, std::bind(&MenuGo::OnClickResumGame, this, _1), nullptr, nullptr);
mainMenu.MenuItems.push_back(buttonResumeGame);
auto buttonResetGame = std::make_shared<MenuButton>(&ovrVirtualBoyGo::global.fontMenu, ovrVirtualBoyGo::global.textureResetIconId,
"Reset Game", posX,
posY += ovrVirtualBoyGo::global.menuItemSize,
std::bind(&MenuGo::OnClickResetGame, this, _1), nullptr, nullptr);
mainMenu.MenuItems.push_back(buttonResetGame);
slotButton = std::make_shared<MenuButton>(&ovrVirtualBoyGo::global.fontMenu, ovrVirtualBoyGo::global.textureSaveSlotIconId, "", posX,
posY += ovrVirtualBoyGo::global.menuItemSize + 10,
std::bind(&MenuGo::OnClickSaveSlotRight, this, _1),
std::bind(&MenuGo::OnClickSaveSlotLeft, this, _1),
std::bind(&MenuGo::OnClickSaveSlotRight, this, _1));
slotButton->ScrollTimeH = 0.1;
ChangeSaveSlot(slotButton.get(), 0);
mainMenu.MenuItems.push_back(slotButton);
OVR_LOG_WITH_TAG("Menu", "Set up Main Menu");
emulator->InitMainMenu(posX, posY, mainMenu);
OVR_LOG_WITH_TAG("Menu", "Set up Main Menu3");
mainMenu.MenuItems.push_back(std::make_shared<MenuButton>(&ovrVirtualBoyGo::global.fontMenu, ovrVirtualBoyGo::global.textureSaveIconId, "Save",
posX, posY += ovrVirtualBoyGo::global.menuItemSize,
std::bind(&MenuGo::OnClickSaveGame, this, _1), nullptr, nullptr));
mainMenu.MenuItems.push_back(std::make_shared<MenuButton>(&ovrVirtualBoyGo::global.fontMenu, ovrVirtualBoyGo::global.textureLoadIconId, "Load",
posX, posY += ovrVirtualBoyGo::global.menuItemSize,
std::bind(&MenuGo::OnClickLoadGame, this, _1), nullptr, nullptr));
mainMenu.MenuItems.push_back(std::make_shared<MenuButton>(&ovrVirtualBoyGo::global.fontMenu, ovrVirtualBoyGo::global.textureLoadRomIconId, "Load Rom", posX,
posY += ovrVirtualBoyGo::global.menuItemSize + 10,
std::bind(&MenuGo::OnClickLoadRomGame, this, _1), nullptr, nullptr));
mainMenu.MenuItems.push_back(std::make_shared<MenuButton>(&ovrVirtualBoyGo::global.fontMenu, ovrVirtualBoyGo::global.textureResetViewIconId,
"Reset View", posX, posY += ovrVirtualBoyGo::global.menuItemSize,
std::bind(&MenuGo::OnClickResetView, this, _1), nullptr, nullptr));
mainMenu.MenuItems.push_back(std::make_shared<MenuButton>(&ovrVirtualBoyGo::global.fontMenu, ovrVirtualBoyGo::global.textureSettingsId,
"Settings", posX,
posY += ovrVirtualBoyGo::global.menuItemSize,
std::bind(&MenuGo::OnClickSettingsGame, this, _1), nullptr, nullptr));
mainMenu.MenuItems.push_back(std::make_shared<MenuButton>(&ovrVirtualBoyGo::global.fontMenu, ovrVirtualBoyGo::global.textureExitIconId, "Exit",
posX, posY += ovrVirtualBoyGo::global.menuItemSize + 10,
std::bind(&MenuGo::OnClickExit, this, _1), nullptr, nullptr));
mainMenu.Init();
OVR_LOG_WITH_TAG("Menu", "Set up Main Menu2");
mainMenu.BackPress = std::bind(&MenuGo::OnClickBackMainMenu, this);
// -- settings page --
OVR_LOG_WITH_TAG("Menu", "Set up Settings Menu");
posY = emulator->HEADER_HEIGHT + 20;
buttonSettingsMenuMapping = std::make_unique<MenuButton>(&ovrVirtualBoyGo::global.fontMenu, ovrVirtualBoyGo::global.textureMappingIconId,
"Menu Button Mapping",
posX, posY,
std::bind(&MenuGo::OnClickMenuMappingScreen, this, _1), nullptr, nullptr);
buttonSettingsEmulatorMapping = std::make_unique<MenuButton>(&ovrVirtualBoyGo::global.fontMenu, ovrVirtualBoyGo::global.textureMappingIconId,
"Emulator Button Mapping",
posX, posY += ovrVirtualBoyGo::global.menuItemSize,
std::bind(&MenuGo::OnClickEmulatorMappingScreen, this, _1), nullptr, nullptr);
buttonSettingsMoveScreen = std::make_unique<MenuButton>(&ovrVirtualBoyGo::global.fontMenu, ovrVirtualBoyGo::global.textureMoveIconId, "Move Screen", posX,
posY += ovrVirtualBoyGo::global.menuItemSize,
std::bind(&MenuGo::OnClickMoveScreen, this, _1), nullptr, nullptr);
buttonSettingsFollowHead = std::make_unique<MenuButton>(&ovrVirtualBoyGo::global.fontMenu, ovrVirtualBoyGo::global.textureFollowHeadIconId,
strMove[ovrVirtualBoyGo::global.followHead ? 0 : 1], posX,
posY += ovrVirtualBoyGo::global.menuItemSize + bigGap,
std::bind(&MenuGo::OnClickFollowMode, this, _1),
std::bind(&MenuGo::OnClickFollowMode, this, _1),
std::bind(&MenuGo::OnClickFollowMode, this, _1));
settingsMenu.MenuItems.push_back(buttonSettingsMenuMapping);
settingsMenu.MenuItems.push_back(buttonSettingsEmulatorMapping);
settingsMenu.MenuItems.push_back(buttonSettingsMoveScreen);
settingsMenu.MenuItems.push_back(buttonSettingsFollowHead);
emulator->InitSettingsMenu(posX, posY, settingsMenu);
settingsMenu.MenuItems.push_back(
std::make_unique<MenuButton>(&ovrVirtualBoyGo::global.fontMenu, ovrVirtualBoyGo::global.textureBackIconId, "Save and Back", posX,
posY += ovrVirtualBoyGo::global.menuItemSize + bigGap,
std::bind(&MenuGo::OnClickBackAndSave, this, _1), nullptr, nullptr));
// version number at the bottom
settingsMenu.MenuItems.push_back(
std::make_unique<MenuLabel>(&ovrVirtualBoyGo::global.fontVersion, emulator->STR_VERSION, emulator->MENU_WIDTH - 70,
emulator->MENU_HEIGHT - emulator->BOTTOM_HEIGHT - 50 + 10, 70, 50, ovrVirtualBoyGo::global.textColorVersion));
settingsMenu.BackPress = std::bind(&MenuGo::OnBackPressedSettings, this);
settingsMenu.Init();
// -- menu button mapping --
posY = emulator->HEADER_HEIGHT + 20;
auto swapButton = std::make_shared<MenuButton>(&ovrVirtualBoyGo::global.fontMenu, ovrVirtualBoyGo::global.textureLoadRomIconId, "", posX, posY,
std::bind(&MenuGo::SwapButtonSelectBack, this, _1),
std::bind(&MenuGo::SwapButtonSelectBack, this, _1),
std::bind(&MenuGo::SwapButtonSelectBack, this, _1));
swapButton->UpdateFunction = std::bind(&MenuGo::UpdateButtonMapping, this, _1, _2, _3);
buttonMenuMapMenu.MenuItems.push_back(swapButton);
posY += ovrVirtualBoyGo::global.menuItemSize;
// buttons
auto menuMappingButton = std::make_shared<MenuButton>(&ovrVirtualBoyGo::global.fontMenu, ovrVirtualBoyGo::global.textureLoadRomIconId, "menu mapped to:",
posX,
posY,
nullptr, nullptr, nullptr);
menuMappingButton->Selectable = false;
buttonMenuMapMenu.MenuItems.push_back(menuMappingButton);
// first button
auto menuMappingButton0 = std::make_shared<MenuButton>(&ovrVirtualBoyGo::global.fontMenu, 0, "", 250, posY,
(emulator->MENU_WIDTH - 250 - 20) / 2, ovrVirtualBoyGo::global.menuItemSize,
std::bind(&MenuGo::OnClickChangeMenuButtonEnter, this, _1), nullptr,
std::bind(&MenuGo::OnClickMenuMappingButtonRight, this, _1));
menuMappingButton0->Tag = 0;
SetMappingText(menuMappingButton0.get(), &buttonMappingMenu.Buttons[0]);
buttonMenuMapMenu.MenuItems.push_back(menuMappingButton0);
// second button
auto menuMappingButton1 = std::make_shared<MenuButton>(&ovrVirtualBoyGo::global.fontMenu, 0, "",
250 + (emulator->MENU_WIDTH - 250 - 20) / 2, posY,
(emulator->MENU_WIDTH - 250 - 20) / 2, ovrVirtualBoyGo::global.menuItemSize,
std::bind(&MenuGo::OnClickChangeMenuButtonEnter, this, _1),
std::bind(&MenuGo::OnClickMenuMappingButtonLeft, this, _1), nullptr);
menuMappingButton1->Tag = 1;
SetMappingText(menuMappingButton1.get(), &buttonMappingMenu.Buttons[1]);
menuMappingButton1->OnSelectFunction = std::bind(&MenuGo::OnMenuMappingButtonSelect, this, _1, _2);
buttonMenuMapMenu.MenuItems.push_back(menuMappingButton1);
SwapButtonSelectBack(swapButton.get());
SwapButtonSelectBack(swapButton.get());
buttonMenuMapMenu.MenuItems.push_back(
std::make_shared<MenuButton>(&ovrVirtualBoyGo::global.fontMenu, ovrVirtualBoyGo::global.textureBackIconId, "Back", posX,
posY += ovrVirtualBoyGo::global.menuItemSize + bigGap,
std::bind(&MenuGo::OnClickBackMove, this, _1), nullptr, nullptr));
buttonMenuMapMenu.BackPress = std::bind(&MenuGo::OnBackPressedMove, this);
buttonMenuMapMenu.Init();
// -- emulator button mapping --
posY = emulator->HEADER_HEIGHT + 10;
for (int i = 0; i < emulator->buttonCount; ++i) {
OVR_LOG_WITH_TAG("Menu", "Set up mapping for %i", i);
// MenuLabel *newButtonLabel = new MenuLabel(&fontMenu, "A Button",
// posX, posY, 150, menuItemSize,
// {0.9f, 0.9f, 0.9f, 0.9f});
// image of the button
auto newButtonImage = std::make_shared<MenuImage>(*emulator->button_icons[emulator->buttonOrder[i]],
80 / 2 - ovrVirtualBoyGo::global.menuItemSize / 2, posY, ovrVirtualBoyGo::global.menuItemSize,
ovrVirtualBoyGo::global.menuItemSize, ovrVector4f{0.9F, 0.9F, 0.9F, 0.9F});
buttonEmulatorMapMenu.MenuItems.push_back(newButtonImage);
int mappingButtonWidth = (emulator->MENU_WIDTH - 80 - 20) / 2;
auto newButtonLeft = std::make_shared<MenuButton>(&ovrVirtualBoyGo::global.fontMenu, 0, "abc", 80, posY, mappingButtonWidth,
ovrVirtualBoyGo::global.menuItemSize,
std::bind(&MenuGo::OnClickChangeButtonMappingEnter, this, _1), nullptr,
std::bind(&MenuGo::OnClickMappingButtonRight, this, _1));
// left button
// @hack: this is only done because the menu currently only really supports lists
if (i != 0)
newButtonLeft->OnSelectFunction = std::bind(&MenuGo::OnMappingButtonSelect, this, _1, _2);
newButtonLeft->Tag = i;
newButtonLeft->Tag2 = 0;
UpdateButtonMappingText(newButtonLeft.get());
if (i == 0)
newButtonLeft->UpdateFunction = std::bind(&MenuGo::UpdateButtonMapping, this, _1, _2, _3);
// right button
auto newButtonRight = std::make_shared<MenuButton>(&ovrVirtualBoyGo::global.fontMenu, 0, "abc", 80 + mappingButtonWidth, posY, mappingButtonWidth,
ovrVirtualBoyGo::global.menuItemSize,
std::bind(&MenuGo::OnClickChangeButtonMappingEnter, this, _1),
std::bind(&MenuGo::OnClickMappingButtonLeft, this, _1), nullptr);
// @hack: this is only done because the menu currently only really supports lists
newButtonRight->OnSelectFunction = std::bind(&MenuGo::OnMappingButtonSelect, this, _1, _2);
newButtonRight->Tag = i;
newButtonRight->Tag2 = 1;
UpdateButtonMappingText(newButtonRight.get());
buttonMapping.push_back(newButtonLeft);
buttonMapping.push_back(newButtonRight);
posY += ovrVirtualBoyGo::global.menuItemSize;
}
// select the first element
buttonEmulatorMapMenu.CurrentSelection = (int) buttonEmulatorMapMenu.MenuItems.size();
// button mapping page
for (int i = 0; i < emulator->buttonCount * 2; ++i)
buttonEmulatorMapMenu.MenuItems.push_back(buttonMapping.at(i));
buttonEmulatorMapMenu.MenuItems.push_back(
std::make_shared<MenuButton>(&ovrVirtualBoyGo::global.fontMenu, ovrVirtualBoyGo::global.textureResetViewIconId, "Reset Mapping", posX,
posY += bigGap,
std::bind(&MenuGo::OnClickResetEmulatorMapping, this, _1), nullptr, nullptr));
buttonEmulatorMapMenu.MenuItems.push_back(
std::make_shared<MenuButton>(&ovrVirtualBoyGo::global.fontMenu, ovrVirtualBoyGo::global.textureBackIconId, "Back", posX,
posY += ovrVirtualBoyGo::global.menuItemSize - 3, std::bind(&MenuGo::OnClickBackMove, this, _1), nullptr, nullptr));
buttonEmulatorMapMenu.BackPress = std::bind(&MenuGo::OnBackPressedMove, this);
buttonEmulatorMapMenu.Init();
// -- button mapping overlay --
buttonMappingOverlay.MenuItems.push_back(
std::make_shared<MenuImage>(ovrVirtualBoyGo::global.textureWhiteId, 0, 0, emulator->MENU_WIDTH, emulator->MENU_HEIGHT,
ovrVector4f{0.0F, 0.0F, 0.0F, 0.8F}));
int overlayWidth = 250;
int overlayHeight = 80;
int margin = 15;
buttonMappingOverlay.MenuItems.push_back(
std::make_shared<MenuImage>(ovrVirtualBoyGo::global.textureWhiteId, emulator->MENU_WIDTH / 2 - overlayWidth / 2,
emulator->MENU_HEIGHT / 2 - overlayHeight / 2 - margin, overlayWidth,
overlayHeight + margin * 2, ovrVector4f{0.05F, 0.05F, 0.05F, 0.3F}));
mappingButtonLabel = std::make_unique<MenuLabel>(&ovrVirtualBoyGo::global.fontMenu, "A Button", emulator->MENU_WIDTH / 2 - overlayWidth / 2,
emulator->MENU_HEIGHT / 2 - overlayHeight / 2, overlayWidth, overlayHeight / 3,
ovrVector4f{0.9F, 0.9F, 0.9F, 0.9F});
possibleMappingLabel = std::make_unique<MenuLabel>(&ovrVirtualBoyGo::global.fontMenu, "(A, B, X, Y)", emulator->MENU_WIDTH / 2 - overlayWidth / 2,
emulator->MENU_HEIGHT / 2 + overlayHeight / 2 - overlayHeight / 3, overlayWidth, overlayHeight / 3,
ovrVector4f{0.9F, 0.9F, 0.9F, 0.9F});
pressButtonLabel = std::make_unique<MenuLabel>(&ovrVirtualBoyGo::global.fontMenu, "Press Button", emulator->MENU_WIDTH / 2 - overlayWidth / 2,
emulator->MENU_HEIGHT / 2 - overlayHeight / 2 + overlayHeight / 3,
overlayWidth, overlayHeight / 3, ovrVector4f{0.9F, 0.9F, 0.9F, 0.9F});
buttonMappingOverlay.MenuItems.push_back(mappingButtonLabel);
buttonMappingOverlay.MenuItems.push_back(pressButtonLabel);
buttonMappingOverlay.MenuItems.push_back(possibleMappingLabel);
// -- move menu page --
posY = emulator->HEADER_HEIGHT + 20;
yawButton = std::make_unique<MenuButton>(&ovrVirtualBoyGo::global.fontMenu, ovrVirtualBoyGo::global.texuterLeftRightIconId, "", posX, posY,
std::bind(&MenuGo::OnClickYaw, this, _1),
std::bind(&MenuGo::OnClickMoveScreenYawLeft, this, _1),
std::bind(&MenuGo::OnClickMoveScreenYawRight, this, _1));
yawButton->ScrollTimeH = 0.025;
pitchButton = std::make_unique<MenuButton>(&ovrVirtualBoyGo::global.fontMenu, ovrVirtualBoyGo::global.textureUpDownIconId, "", posX,
posY += ovrVirtualBoyGo::global.menuItemSize,
std::bind(&MenuGo::OnClickPitch, this, _1),
std::bind(&MenuGo::OnClickMoveScreenPitchLeft, this, _1),
std::bind(&MenuGo::OnClickMoveScreenPitchRight, this, _1));
pitchButton->ScrollTimeH = 0.025;
rollButton = std::make_unique<MenuButton>(&ovrVirtualBoyGo::global.fontMenu, ovrVirtualBoyGo::global.textureResetIconId, "", posX,
posY += ovrVirtualBoyGo::global.menuItemSize,
std::bind(&MenuGo::OnClickRoll, this, _1),
std::bind(&MenuGo::OnClickMoveScreenRollLeft, this, _1),
std::bind(&MenuGo::OnClickMoveScreenRollRight, this, _1));
rollButton->ScrollTimeH = 0.025;
distanceButton = std::make_unique<MenuButton>(&ovrVirtualBoyGo::global.fontMenu, ovrVirtualBoyGo::global.textureDistanceIconId, "", posX,
posY += ovrVirtualBoyGo::global.menuItemSize,
std::bind(&MenuGo::OnClickDistance, this, _1),
std::bind(&MenuGo::OnClickMoveScreenDistanceLeft, this, _1),
std::bind(&MenuGo::OnClickMoveScreenDistanceRight, this, _1));
distanceButton->ScrollTimeH = 0.025;
scaleButton = std::make_unique<MenuButton>(&ovrVirtualBoyGo::global.fontMenu, ovrVirtualBoyGo::global.textureScaleIconId, "", posX,
posY += ovrVirtualBoyGo::global.menuItemSize,
std::bind(&MenuGo::OnClickScale, this, _1),
std::bind(&MenuGo::OnClickMoveScreenScaleLeft, this, _1),
std::bind(&MenuGo::OnClickMoveScreenScaleRight, this, _1));
scaleButton->ScrollTimeH = 0.025;
moveMenu.MenuItems.push_back(yawButton);
moveMenu.MenuItems.push_back(pitchButton);
moveMenu.MenuItems.push_back(rollButton);
moveMenu.MenuItems.push_back(distanceButton);
moveMenu.MenuItems.push_back(scaleButton);
moveMenu.MenuItems.push_back(
std::make_shared<MenuButton>(&ovrVirtualBoyGo::global.fontMenu, ovrVirtualBoyGo::global.textureResetViewIconId, "Reset View", posX,
posY += ovrVirtualBoyGo::global.menuItemSize + smallGap,
std::bind(&MenuGo::OnClickResetViewSettings, this, _1), nullptr, nullptr));
moveMenu.MenuItems.push_back(std::make_shared<MenuButton>(&ovrVirtualBoyGo::global.fontMenu, ovrVirtualBoyGo::global.textureBackIconId, "Back", posX,
posY += ovrVirtualBoyGo::global.menuItemSize + bigGap,
std::bind(&MenuGo::OnClickBackMove, this, _1), nullptr, nullptr));
moveMenu.BackPress = std::bind(&MenuGo::OnBackPressedMove, this);
moveMenu.Init();
currentMenu = &romSelectionMenu;
// updates the visible values
MoveYaw(yawButton.get(), 0);
MovePitch(pitchButton.get(), 0);
MoveRoll(rollButton.get(), 0);
ChangeDistance(distanceButton.get(), 0);
ChangeScale(scaleButton.get(), 0);
}
void MenuGo::StartTransition(Menu *next, int dir) {
if (isTransitioning) return;
isTransitioning = true;
transitionMoveDir = dir;
nextMenu = next;
}
void MenuGo::OnClickResumGame(MenuItem *item) {
OVR_LOG_WITH_TAG("Menu", "Pressed RESUME GAME");
if (loadedRom) ovrVirtualBoyGo::global.menuOpen = false;
}
void MenuGo::OnClickResetGame(MenuItem *item) {
OVR_LOG_WITH_TAG("Menu", "RESET GAME");
if (loadedRom) {
emulator->ResetGame();
ovrVirtualBoyGo::global.menuOpen = false;
}
}
void MenuGo::OnClickSaveGame(MenuItem *item) {
OVR_LOG_WITH_TAG("Menu", "on click save game");
if (loadedRom) {
emulator->SaveState(ovrVirtualBoyGo::global.saveSlot);
ovrVirtualBoyGo::global.menuOpen = false;
}
}
void MenuGo::OnClickLoadGame(MenuItem *item) {
if (loadedRom) {
emulator->LoadState(ovrVirtualBoyGo::global.saveSlot);
ovrVirtualBoyGo::global.menuOpen = false;
}
}
void MenuGo::OnClickLoadRomGame(MenuItem *item) { StartTransition(&romSelectionMenu, -1); }
void MenuGo::OnClickSettingsGame(MenuItem *item) { StartTransition(&settingsMenu, 1); }
void MenuGo::OnClickResetView(MenuItem *item) { resetView = true; }
void MenuGo::OnClickBackAndSave(MenuItem *item) {
StartTransition(&mainMenu, -1);
MenuGo::SaveSettings();
}
void MenuGo::OnBackPressedRomList() { StartTransition(&mainMenu, 1); }
void MenuGo::OnBackPressedSettings() {
StartTransition(&mainMenu, -1);
MenuGo::SaveSettings();
}
void MenuGo::OnClickBackMove(MenuItem *item) {
StartTransition(&settingsMenu, -1);
}
void MenuGo::ChangeSaveSlot(MenuItem *item, int dir) {
ovrVirtualBoyGo::global.saveSlot += dir;
if (ovrVirtualBoyGo::global.saveSlot < 0)
ovrVirtualBoyGo::global.saveSlot = MAX_SAVE_SLOTS - 1;
if (ovrVirtualBoyGo::global.saveSlot >= MAX_SAVE_SLOTS)
ovrVirtualBoyGo::global.saveSlot = 0;
emulator->UpdateStateImage(ovrVirtualBoyGo::global.saveSlot);
((MenuButton *) item)->Text = "Save Slot: " + ToString(ovrVirtualBoyGo::global.saveSlot);
}
void MenuGo::OnClickSaveSlotLeft(MenuItem *item) {
ChangeSaveSlot(item, -1);
MenuGo::SaveSettings();
}
void MenuGo::OnClickSaveSlotRight(MenuItem *item) {
ChangeSaveSlot(item, 1);
SaveSettings();
}
void MenuGo::SwapButtonSelectBack(MenuItem *item) {
ovrVirtualBoyGo::global.SwappSelectBackButton = !ovrVirtualBoyGo::global.SwappSelectBackButton;
((MenuButton *) item)->Text = "Swap Select and Back: ";
((MenuButton *) item)->Text.append((ovrVirtualBoyGo::global.SwappSelectBackButton ? "Yes" : "No"));
selectHelp->IconId = ovrVirtualBoyGo::global.SwappSelectBackButton ? ovrVirtualBoyGo::global.textureButtonBIconId
: ovrVirtualBoyGo::global.textureButtonAIconId;
backHelp->IconId = ovrVirtualBoyGo::global.SwappSelectBackButton ? ovrVirtualBoyGo::global.textureButtonAIconId
: ovrVirtualBoyGo::global.textureButtonBIconId;
}
uint MenuGo::GetPressedButton(uint &_buttonState, uint &_lastButtonState) {
return _buttonState & ~_lastButtonState;
}
void MenuGo::SetMappingText(MenuButton *Button, ButtonMapper::MappedButton *Mapping) {
Button->SetText(Mapping->IsSet ? ButtonMapper::MapButtonStr[Mapping->InputDevice * 32 + Mapping->ButtonIndex] : "-");
}
// mapping functions
void MenuGo::UpdateButtonMappingText(MenuItem *item) {
OVR_LOG_WITH_TAG("Menu", "Update mapping text for %i", item->Tag);
SetMappingText(((MenuButton *) item), &emulator->buttonMapping[emulator->buttonOrder[item->Tag]].Buttons[item->Tag2]);
}
void MenuGo::UpdateMenuMapping() {
mappedButton->SetText(ButtonMapper::MapButtonStr[buttonMappingMenu.Buttons[mappedButton->Tag].InputDevice * 32 +
buttonMappingMenu.Buttons[mappedButton->Tag].ButtonIndex]);
}
void MenuGo::UpdateEmulatorMapping() {
// emulator->UpdateButtonMapping();
SetMappingText(mappedButton, remapButton);
}
void MenuGo::OnMenuMappingButtonSelect(MenuItem *item, int direction) {
buttonMenuMapMenu.MoveSelection(direction, false);
}
void MenuGo::OnClickMenuMappingButtonLeft(MenuItem *item) {
buttonMenuMapMenu.CurrentSelection--;
}
void MenuGo::OnClickMenuMappingButtonRight(MenuItem *item) {
buttonMenuMapMenu.CurrentSelection++;
}
void MenuGo::OnMappingButtonSelect(MenuItem *item, int direction) {
buttonEmulatorMapMenu.MoveSelection(direction, false);
}
void MenuGo::OnClickMappingButtonLeft(MenuItem *item) {
buttonEmulatorMapMenu.CurrentSelection--;
}
void MenuGo::OnClickMappingButtonRight(MenuItem *item) {
buttonEmulatorMapMenu.CurrentSelection++;
}
void MenuGo::OnClickChangeMenuButtonEnter(MenuItem *item) {
UpdateMapping = true;
UpdateMappingUseTimer = false;
remapButton = &buttonMappingMenu.Buttons[item->Tag];
mappedButton = (MenuButton *) item;
updateMappingText = std::bind(&MenuGo::UpdateMenuMapping, this);
mappingButtonLabel->SetText("Menu Button");
possibleMappingLabel->SetText("(A, B, X, Y,...)");
}
void MenuGo::OnClickChangeButtonMappingEnter(MenuItem *item) {
UpdateMapping = true;
UpdateMappingUseTimer = true;
UpdateMappingTimer = 4.0f;
remapButton = &emulator->buttonMapping[emulator->buttonOrder[item->Tag]].Buttons[item->Tag2];
mappedButton = buttonMapping.at(item->Tag * 2 + item->Tag2).get();
updateMappingText = std::bind(&MenuGo::UpdateEmulatorMapping, this);
mappingButtonLabel->SetText("Button");
possibleMappingLabel->SetText("(A, B, X, Y,...)");
}
void MenuGo::UpdateButtonMapping(MenuItem *item, uint *_buttonStates, uint *_lastButtonStates) {
if (!UpdateMapping)
return;
for (uint i = 0; i < 3; ++i) {
// get the buttons that are newly pressed
uint newButtonState = GetPressedButton(_buttonStates[i], _lastButtonStates[i]);
if (newButtonState) {
for (uint j = 0; j < ButtonMapper::EmuButtonCount; ++j) {
if (newButtonState & ButtonMapper::ButtonMapping[j]) {
OVR_LOG_WITH_TAG("Menu", "mapped to %i from device %i", j, i);
UpdateMapping = false;
remapButton->InputDevice = i;
remapButton->ButtonIndex = j;
remapButton->IsSet = true;
updateMappingText();
break;
}
}
break;
}
}
// ignore button press
for (int i = 0; i < 3; ++i) {
_buttonStates[i] = 0;
_lastButtonStates[i] = 0;
}
}
void MenuGo::OnClickExit(MenuItem *item) {
emulator->SaveRam();
showExitDialog = true;
}
void MenuGo::OnClickBackMainMenu() {
if (loadedRom) ovrVirtualBoyGo::global.menuOpen = false;
}
void MenuGo::OnClickFollowMode(MenuItem *item) {
ovrVirtualBoyGo::global.followHead = !ovrVirtualBoyGo::global.followHead;
((MenuButton *) item)->Text = strMove[ovrVirtualBoyGo::global.followHead ? 0 : 1];
}
void MenuGo::OnClickMoveScreen(MenuItem *item) { StartTransition(&moveMenu, 1); }
void MenuGo::OnClickMenuMappingScreen(MenuItem *item) { StartTransition(&buttonMenuMapMenu, 1); }
void MenuGo::OnClickEmulatorMappingScreen(MenuItem *item) {
StartTransition(&buttonEmulatorMapMenu, 1);
}
void MenuGo::OnBackPressedMove() {
StartTransition(&settingsMenu, -1);
}
float ToDegree(float radian) { return (int) (180.0 / VRAPI_PI * radian * 10) / 10.0F; }
void MenuGo::MoveYaw(MenuItem *item, float dir) {
layerBuilder->screenYaw += dir;
((MenuButton *) item)->Text = "Yaw: " + ToString(layerBuilder->screenYaw) + "°";
}
void MenuGo::MovePitch(MenuItem *item, float dir) {
layerBuilder->screenPitch += dir;
((MenuButton *) item)->Text = "Pitch: " + ToString(layerBuilder->screenPitch) + "°";
}
void MenuGo::ChangeDistance(MenuItem *item, float dir) {
layerBuilder->radiusMenuScreen -= dir;
if (layerBuilder->radiusMenuScreen < MIN_DISTANCE)
layerBuilder->radiusMenuScreen = MIN_DISTANCE;
if (layerBuilder->radiusMenuScreen > MAX_DISTANCE)
layerBuilder->radiusMenuScreen = MAX_DISTANCE;
((MenuButton *) item)->Text = "Distance: " + ToString(layerBuilder->radiusMenuScreen);
}
void MenuGo::ChangeScale(MenuItem *item, float dir) {
layerBuilder->screenSize -= dir;
if (layerBuilder->screenSize < 0.25F) layerBuilder->screenSize = 0.25F;
if (layerBuilder->screenSize > 2.5F) layerBuilder->screenSize = 2.5F;
((MenuButton *) item)->Text = "Scale: " + ToString(layerBuilder->screenSize);
}
void MenuGo::MoveRoll(MenuItem *item, float dir) {
layerBuilder->screenRoll += dir;
((MenuButton *) item)->Text = "Roll: " + ToString(layerBuilder->screenRoll) + "°";
}
void MenuGo::OnClickResetEmulatorMapping(MenuItem *item) {
emulator->ResetButtonMapping();
for (int i = 0; i < emulator->buttonCount * 2; ++i) {
UpdateButtonMappingText(buttonMapping.at(i).get());
}
}
void MenuGo::OnClickResetViewSettings(MenuItem *item) {
layerBuilder->ResetValues();
// updates the visible values
MoveYaw(yawButton.get(), 0);
MovePitch(pitchButton.get(), 0);
MoveRoll(rollButton.get(), 0);
ChangeDistance(distanceButton.get(), 0);
ChangeScale(scaleButton.get(), 0);
}
void MenuGo::OnClickYaw(MenuItem *item) {
layerBuilder->screenYaw = 0;
MoveYaw(yawButton.get(), 0);
}
void MenuGo::OnClickPitch(MenuItem *item) {
layerBuilder->screenPitch = 0;
MovePitch(pitchButton.get(), 0);
}
void MenuGo::OnClickRoll(MenuItem *item) {
layerBuilder->screenRoll = 0;
MoveRoll(rollButton.get(), 0);
}
void MenuGo::OnClickDistance(MenuItem *item) {
layerBuilder->radiusMenuScreen = 5.5F;
ChangeDistance(distanceButton.get(), 0);
}
void MenuGo::OnClickScale(MenuItem *item) {
layerBuilder->screenSize = 1.0F;
ChangeScale(scaleButton.get(), 0);
}
void MenuGo::OnClickMoveScreenYawLeft(MenuItem *item) { MoveYaw(item, RotateSpeed); }
void MenuGo::OnClickMoveScreenYawRight(MenuItem *item) { MoveYaw(item, -RotateSpeed); }
void MenuGo::OnClickMoveScreenPitchLeft(MenuItem *item) { MovePitch(item, -RotateSpeed); }
void MenuGo::OnClickMoveScreenPitchRight(MenuItem *item) { MovePitch(item, RotateSpeed); }
void MenuGo::OnClickMoveScreenRollLeft(MenuItem *item) { MoveRoll(item, -RotateSpeed); }
void MenuGo::OnClickMoveScreenRollRight(MenuItem *item) { MoveRoll(item, RotateSpeed); }
void MenuGo::OnClickMoveScreenDistanceLeft(MenuItem *item) { ChangeDistance(item, ZoomSpeed); }
void MenuGo::OnClickMoveScreenDistanceRight(MenuItem *item) {
ChangeDistance(item, -ZoomSpeed);
}
void MenuGo::OnClickMoveScreenScaleLeft(MenuItem *item) { ChangeScale(item, MoveSpeed); }
void MenuGo::OnClickMoveScreenScaleRight(MenuItem *item) { ChangeScale(item, -MoveSpeed); }
void MenuGo::ResetMenuState() {
SaveSettings();
ovrVirtualBoyGo::global.saveSlot = 0;
ChangeSaveSlot(slotButton.get(), 0);
currentMenu = &mainMenu;
ovrVirtualBoyGo::global.menuOpen = false;
loadedRom = true;
}
int MenuGo::UpdateBatteryLevel() {
jint bLevel = java->Env->CallIntMethod(java->ActivityObject, getVal);
int returnValue = (int) bLevel;
return returnValue;
}
void MenuGo::CreateScreen() {
// menu layer
MenuSwapChain = vrapi_CreateTextureSwapChain(VRAPI_TEXTURE_TYPE_2D, VRAPI_TEXTURE_FORMAT_8888_sRGB, emulator->MENU_WIDTH, emulator->MENU_HEIGHT, 1, false);
textureIdMenu = vrapi_GetTextureSwapChainHandle(MenuSwapChain, 0);
glBindTexture(GL_TEXTURE_2D, textureIdMenu);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, emulator->MENU_WIDTH, emulator->MENU_HEIGHT, GL_RGBA, GL_UNSIGNED_BYTE,
nullptr);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
GLfloat borderColor[] = {0.0F, 0.0F, 0.0F, 0.0F};
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
glBindTexture(GL_TEXTURE_2D, 0);
// create hte framebuffer for the menu texture
glGenFramebuffers(1, &MenuFrameBuffer);
glBindFramebuffer(GL_FRAMEBUFFER, MenuFrameBuffer);
// Set "renderedTexture" as our colour attachement #0
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, (GLuint) textureIdMenu, 0);
// Set the list of draw buffers.
GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT0};
glDrawBuffers(1, DrawBuffers); // "1" is the size of DrawBuffers
glBindFramebuffer(GL_FRAMEBUFFER, 0);
OVR_LOG_WITH_TAG("Menu", "finished creating screens");
}
void MenuGo::SaveSettings() {
std::ofstream saveFile(ovrVirtualBoyGo::global.saveFilePath, std::ios::trunc | std::ios::binary);
saveFile.write(reinterpret_cast<const char *>(&emulator->SAVE_FILE_VERSION), sizeof(int));
emulator->SaveEmulatorSettings(&saveFile);
saveFile.write(reinterpret_cast<const char *>(&ovrVirtualBoyGo::global.followHead), sizeof(bool));
saveFile.write(reinterpret_cast<const char *>(&layerBuilder->screenPitch), sizeof(float));
saveFile.write(reinterpret_cast<const char *>(&layerBuilder->screenYaw), sizeof(float));
saveFile.write(reinterpret_cast<const char *>(&layerBuilder->screenRoll), sizeof(float));
saveFile.write(reinterpret_cast<const char *>(&layerBuilder->radiusMenuScreen), sizeof(float));
saveFile.write(reinterpret_cast<const char *>(&layerBuilder->screenSize), sizeof(float));
saveFile.write(reinterpret_cast<const char *>(&buttonMappingMenu.Buttons[0].InputDevice), sizeof(int));
saveFile.write(reinterpret_cast<const char *>(&buttonMappingMenu.Buttons[0].ButtonIndex), sizeof(int));
saveFile.write(reinterpret_cast<const char *>(&buttonMappingMenu.Buttons[1].InputDevice), sizeof(int));
saveFile.write(reinterpret_cast<const char *>(&buttonMappingMenu.Buttons[1].ButtonIndex), sizeof(int));
saveFile.write(reinterpret_cast<const char *>(&ovrVirtualBoyGo::global.SwappSelectBackButton), sizeof(bool));
saveFile.close();
OVR_LOG_WITH_TAG("Menu", "saved settings");
}
void MenuGo::LoadSettings() {
// default menu buttons
buttonMappingMenu.Buttons[0].IsSet = true;
buttonMappingMenu.Buttons[0].InputDevice = ButtonMapper::DeviceGamepad;
buttonMappingMenu.Buttons[0].ButtonIndex = ButtonMapper::EmuButton_Y;
// menu button on the left touch controller
buttonMappingMenu.Buttons[1].IsSet = true;
buttonMappingMenu.Buttons[1].InputDevice = ButtonMapper::DeviceLeftTouch;
buttonMappingMenu.Buttons[1].ButtonIndex = ButtonMapper::EmuButton_Enter;
std::ifstream loadFile(ovrVirtualBoyGo::global.saveFilePath, std::ios::in | std::ios::binary | std::ios::ate);
if (loadFile.is_open()) {
loadFile.seekg(0, std::ios::beg);
int saveFileVersion = 0;
loadFile.read((char *) &saveFileVersion, sizeof(int));
// only load if the save versions are compatible
if (saveFileVersion == emulator->SAVE_FILE_VERSION) {
emulator->LoadEmulatorSettings(&loadFile);
loadFile.read((char *) &ovrVirtualBoyGo::global.followHead, sizeof(bool));
loadFile.read((char *) &layerBuilder->screenPitch, sizeof(float));
loadFile.read((char *) &layerBuilder->screenYaw, sizeof(float));
loadFile.read((char *) &layerBuilder->screenRoll, sizeof(float));
loadFile.read((char *) &layerBuilder->radiusMenuScreen, sizeof(float));
loadFile.read((char *) &layerBuilder->screenSize, sizeof(float));
loadFile.read((char *) &buttonMappingMenu.Buttons[0].InputDevice, sizeof(int));
loadFile.read((char *) &buttonMappingMenu.Buttons[0].ButtonIndex, sizeof(int));
loadFile.read((char *) &buttonMappingMenu.Buttons[1].InputDevice, sizeof(int));
loadFile.read((char *) &buttonMappingMenu.Buttons[1].ButtonIndex, sizeof(int));
loadFile.read((char *) &ovrVirtualBoyGo::global.SwappSelectBackButton, sizeof(bool));
}
// TODO: reset all loaded settings
if (loadFile.fail())
OVR_LOG_WITH_TAG("Menu", "failed loading settings");
else
OVR_LOG_WITH_TAG("Menu", "settings loaded");
loadFile.close();
}
}
void MenuGo::ScanDirectory() {
DIR *dir;
struct dirent *ent;
std::string strFullPath;
if ((dir = opendir(ovrVirtualBoyGo::global.romFolderPath.c_str())) != nullptr) {
while ((ent = readdir(dir)) != nullptr) {
strFullPath = "";
strFullPath.append(ovrVirtualBoyGo::global.romFolderPath);
strFullPath.append(ent->d_name);
if (ent->d_type == 8) {
std::string strFilename = ent->d_name;
// check if the filetype is supported by the emulator
bool supportedFile = false;
for (const auto &supportedFileName : emulator->supportedFileNames) {
if (strFilename.find(supportedFileName) !=
std::string::npos) {
supportedFile = true;
break;
}
}
if (supportedFile) {
emulator->AddRom(strFullPath, strFilename);
}
}
}
closedir(dir);
emulator->SortRomList();
} else {
OVR_LOG_WITH_TAG("Menu", "could not open folder");
}
OVR_LOG_WITH_TAG("Menu", "scanned directory");
}
void MenuGo::SetTimeString(std::string &timeString) {
struct timespec res{};
clock_gettime(CLOCK_REALTIME, &res);
time_t t = res.tv_sec; // just in case types aren't the same
tm tmv{};
localtime_r(&t, &tmv); // populate tmv with local time info
timeString.clear();
if (tmv.tm_hour < 10)
timeString.append("0");
timeString.append(ToString(tmv.tm_hour));
timeString.append(":");
if (tmv.tm_min < 10)
timeString.append("0");
timeString.append(ToString(tmv.tm_min));
time_string_width = FontManager::GetWidth(ovrVirtualBoyGo::global.fontTime, timeString);
}
void MenuGo::GetBattryString(std::string &batteryString) {
batteryLevel = UpdateBatteryLevel();
batteryString.clear();
batteryString.append(ToString(batteryLevel));
batteryString.append("%");
batter_string_width = FontManager::GetWidth(ovrVirtualBoyGo::global.fontBattery, batteryString);
}
void MenuGo::Update(OVRFW::ovrAppl &app, const OVRFW::ovrApplFrameIn &in, OVRFW::ovrRendererOutput &out) {
deltaSeconds = in.DeltaSeconds;
for (int i = 0; i < 3; ++i)
lastButtonStates[i] = buttonStatesReal[i];
// UpdateInput(app);
UpdateInputDevices(app, in);
// update button mapping timer
if (UpdateMapping && UpdateMappingUseTimer) {
UpdateMappingTimer -= in.DeltaSeconds;
mappingButtonLabel->SetText(ToString((int) UpdateMappingTimer));
if ((int) UpdateMappingTimer <= 0) {
UpdateMapping = false;
remapButton->IsSet = false;
updateMappingText();
}
}
if (!ovrVirtualBoyGo::global.menuOpen) {
if (transitionPercentage > 0)
transitionPercentage -= deltaSeconds / OPEN_MENU_SPEED;
if (transitionPercentage < 0)
transitionPercentage = 0;
emulator->Update(in, buttonStates, lastButtonStates);
} else {
if (transitionPercentage < 1)
transitionPercentage += deltaSeconds / OPEN_MENU_SPEED;
if (transitionPercentage > 1)
transitionPercentage = 1;
UpdateCurrentMenu(in.DeltaSeconds);
}
// open/close menu
if (loadedRom &&
((buttonStates[buttonMappingMenu.Buttons[0].InputDevice] & ButtonMapper::ButtonMapping[buttonMappingMenu.Buttons[0].ButtonIndex] &&
!(lastButtonStates[buttonMappingMenu.Buttons[0].InputDevice] & ButtonMapper::ButtonMapping[buttonMappingMenu.Buttons[0].ButtonIndex])) ||
(buttonStates[buttonMappingMenu.Buttons[1].InputDevice] & ButtonMapper::ButtonMapping[buttonMappingMenu.Buttons[1].ButtonIndex] &&
!(lastButtonStates[buttonMappingMenu.Buttons[1].InputDevice] & ButtonMapper::ButtonMapping[buttonMappingMenu.Buttons[1].ButtonIndex])))) {
ovrVirtualBoyGo::global.menuOpen = !ovrVirtualBoyGo::global.menuOpen;
}
layerBuilder->UpdateDirection(in);
emulator->DrawScreenLayer(in, out);
if (transitionPercentage > 0) {
// menu layer
if (ovrVirtualBoyGo::global.menuOpen)
DrawGUI();
float transitionP = sinf((transitionPercentage) * MATH_FLOAT_PIOVER2);
out.Layers[out.NumLayers].Cylinder = layerBuilder->BuildSettingsCylinderLayer(
MenuSwapChain, emulator->MENU_WIDTH, emulator->MENU_HEIGHT, &in.Tracking, ovrVirtualBoyGo::global.followHead, transitionP);
out.Layers[out.NumLayers].Cylinder.Header.Flags |= VRAPI_FRAME_LAYER_FLAG_CHROMATIC_ABERRATION_CORRECTION;
out.Layers[out.NumLayers].Cylinder.Header.Flags |= VRAPI_FRAME_LAYER_FLAG_INHIBIT_SRGB_FRAMEBUFFER;
out.Layers[out.NumLayers].Cylinder.Header.ColorScale = {transitionP, transitionP, transitionP, transitionP};
out.Layers[out.NumLayers].Cylinder.Header.SrcBlend = VRAPI_FRAME_LAYER_BLEND_SRC_ALPHA;
out.Layers[out.NumLayers].Cylinder.Header.DstBlend = VRAPI_FRAME_LAYER_BLEND_ONE_MINUS_SRC_ALPHA;
out.NumLayers++;
}
if (resetView) {
layerBuilder->ResetForwardDirection(out);
resetView = false;
}
if (showExitDialog) {
OVR_LOG("Open menu");
showExitDialog = false;
vrapi_ShowSystemUI(java, VRAPI_SYS_UI_CONFIRM_QUIT_MENU);
}
}