-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenu.cpp
More file actions
1300 lines (1094 loc) · 45.6 KB
/
Menu.cpp
File metadata and controls
1300 lines (1094 loc) · 45.6 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 "SFML/Graphics.hpp"
#include "SFML/Audio.hpp"
#include <string>
#include <array>
#include "ClassMenu.hpp"
#include <fstream>
#include "System.hpp"
#include "TutorialMain.hpp"
#include "main.hpp"
void launch_options(std::fstream& file, const std::array<int, 3>& colors_read, const sf::Texture& menu_background, const sf::Sound& over, const sf::Sound& press, const sf::Font& font);
void launch_options_colors(std::fstream& file, const std::array<int, 3>& colors_read, const sf::Texture& menu_background, const sf::Sound& over, const sf::Sound& press, const sf::Font& font);
void launch_options_language(std::fstream& file, const sf::Texture& menu_background, const sf::Sound& over, const sf::Sound& press, const sf::Font& font);
void launch_options_controls(std::fstream& file, const sf::Texture& menu_background, const sf::Sound& over, const sf::Sound& press, const sf::Font& font);
void launch_options_configure_mouse(std::fstream& file, const sf::Texture& menu_background, const sf::Sound& over, const sf::Sound& press, const sf::Font& font);
void launch_options_configure_xbox(std::fstream& file, const sf::Texture& menu_background, const sf::Sound& over, const sf::Sound& press, const sf::Font& font);
int launch_options_second_control(const sf::Texture& menu_background, const sf::Sound& over, const sf::Sound& press, const sf::Font& font);
int main()
{
/*Configuration's file*/
std::fstream fconfig;
sf::Music music;
//Load the texure
if (!music.openFromFile("media/sounds/menu_music.ogg"))
std::cout<<"Error loading music"<<std::endl;
music.play();
music.setLoop(true);
//True if config file doesn't exist
bool first_time;
//Colors read
std::array<int, 3> cA_N_E = {{-1, -1, -1}};
fconfig.open("config.txt");
//Exists and it's open
if (fconfig.is_open())
{
//Read language
std::string idiom;
first_time = false;
fconfig >> idiom;
if (idiom == "English")
fdx::menu::Language::setLang(fdx::menu::Language::Langs::ENGLISH);
else
fdx::menu::Language::setLang(fdx::menu::Language::Langs::SPANISH);
//Read the colors and identify them with the dictionary
fconfig >> cA_N_E[0];
fdx::fighter::teams.set_friendly(fdx::menu::DictionaryColors::getColor(cA_N_E[0]));
fconfig >> cA_N_E[1];
fdx::fighter::teams.set_neutral(fdx::menu::DictionaryColors::getColor(cA_N_E[1]));
fconfig >> cA_N_E[2];
fdx::fighter::teams.set_enemy(fdx::menu::DictionaryColors::getColor(cA_N_E[2]));
}
else
{
first_time = true;
fdx::menu::Language::setLang(fdx::menu::Language::Langs::ENGLISH);
fconfig.open("config.txt", std::ios::out);
if (!fconfig.is_open())
return 0;
}
/*Bindings's file*/
std::ifstream fbindings("bindings.data", std::ios::binary);
//Exists and it's open
if (fbindings.is_open())
{
fdx::fighter::controllers.read_from(fbindings);
}
fbindings.close();
/*Variables*/
/*Button*/
sf::Font font;
sf::Sound over;
sf::Sound press;
sf::SoundBuffer buffer1, buffer2;
int x,y,but = false;
/*Load font*/
if(!font.loadFromFile("media/fonts/ethnocentric rg.ttf"))
std::cout << "Font not found" << std::endl;
/*Load Sounds*/
buffer1.loadFromFile("media/sounds/Pressed.wav");
press.setBuffer(buffer1);
buffer2.loadFromFile("media/sounds/Over.wav");
over.setBuffer(buffer2);
/*Load position*/
x=sf::Mouse::getPosition().x;
y=sf::Mouse::getPosition().y;
/*Images*/
sf::Texture menu_background;
sf::Texture menu_options;
sf::Texture menu_exit;
/*Load images*/
if (!menu_background.loadFromFile("media/images/background.png"))
std::cout << "Image not found" << std::endl;
if (!menu_options.loadFromFile("media/images/options_img.png"))
std::cout << "Image not found" << std::endl;
if (!menu_exit.loadFromFile("media/images/exit_img.png"))
std::cout << "Image not found" << std::endl;
menu_options.setSmooth(true);
menu_exit.setSmooth(true);
if (first_time)
{
launch_options_language(fconfig, menu_background, over, press, font);
launch_options_colors(fconfig, cA_N_E, menu_background, over, press, font);
first_time = false;
}
/*Window*/
sf::RenderWindow window(sf::VideoMode(600, 600), "SHIELD_ MENU");
/*Create menu*/
fdx::menu::Menu menu_principal(menu_background, "Shield_", 50, 160, 50, font, sf::Color::White);
/*Draw principal menu's buttons*/
menu_principal.add_button(new fdx::menu::ButtonText(160, 150, 275, 50, 5, 5, sf::Color(255,127,42,255), sf::Color(150,60,0,255), true, over, press, fdx::menu::Language::getText(fdx::menu::Language::Language::SINGLEPLAYER), font, 20, sf::Color::Black, sf::Color(191,191,191)));
menu_principal.add_button(new fdx::menu::ButtonText(160, 250, 275, 50, 5, 5, sf::Color(255,127,42,255), sf::Color(150,60,0,255), true, over, press, fdx::menu::Language::getText(fdx::menu::Language::Language::MULTIPLAYER), font, 20, sf::Color::Black, sf::Color(191,191,191)));
menu_principal.add_button(new fdx::menu::ButtonText(160, 350, 275, 50, 5, 5, sf::Color(255,127,42,255), sf::Color(150,60,0,255), true, over, press, fdx::menu::Language::getText(fdx::menu::Language::Language::STATISTICS), font, 20, sf::Color::Black, sf::Color(191,191,191)));
menu_principal.add_button(new fdx::menu::ButtonImage(160, 450, 120, 70, 5, 5, sf::Color(255,127,42,255), sf::Color(150,60,0,255), true, over, press, menu_options));
menu_principal.add_button(new fdx::menu::ButtonImage(315, 450, 120, 70, 5, 5, sf::Color(255,127,42,255), sf::Color(150,60,0,255), true, over, press, menu_exit));
while (window.isOpen())
{
window.setSize(sf::Vector2u(600,600));
sf::Event event;
while (window.pollEvent(event))
{
switch (event.type)
{
case sf::Event::MouseMoved:
{
x=event.mouseMove.x;
y=event.mouseMove.y;
break;
}
case sf::Event::MouseButtonPressed:
{
if (event.mouseButton.button==sf::Mouse::Button::Left)
but=true;
break;
}
case sf::Event::MouseButtonReleased:
{
if (event.mouseButton.button==sf::Mouse::Button::Left)
but=false;
break;
}
case sf::Event::Closed:
{
window.close();
break;
}
default:
break;
}
if (event.type == sf::Event::Closed)
window.close();
}
/*Button selected*/
switch (menu_principal.button_pressed(x, y, but))
{
//Singleplayer
case 0:
{
music.stop();
fdx::fighter::launch_single_player();
music.play();
break;
}
//Multiplayer
case 1:
{
fdx::fighter::controllers.set_controller2(launch_options_second_control(menu_background, over, press, font));
music.stop();
fdx::fighter::launch_multi_player();
music.play();
break;
}
//Tutorial
case 2:
{
music.stop();
fdx::fighter::launch_tutorial();
music.play();
break;
}
//Options
case 3:
{
int cp_lang = fdx::menu::Language::getLang();
launch_options(fconfig, cA_N_E, menu_background, over, press, font);
//Language changed
if (cp_lang != fdx::menu::Language::getLang())
window.close();
break;
}
//Exit
case 4:
{
window.close();
break;
}
}
window.clear();
window.draw(menu_principal);
window.display();
}
fconfig.close();
return 0;
}
void launch_options(std::fstream& file, const std::array<int,3>& colors_read, const sf::Texture& menu_background, const sf::Sound& over, const sf::Sound& press, const sf::Font& font)
{
/*Window*/
sf::RenderWindow options(sf::VideoMode(600, 500), fdx::menu::Language::getText(fdx::menu::Language::OPTIONS));
/*Button*/
int x,y,but = false;
/*Load position*/
x=sf::Mouse::getPosition().x;
y=sf::Mouse::getPosition().y;
/*Images*/
sf::Texture go_back;
/*Load image*/
if (!go_back.loadFromFile("media/images/back_img.png"))
std::cout << "Image not found" << std::endl;
/*Create menu*/
fdx::menu::Menu menu_options(menu_background, fdx::menu::Language::getText(fdx::menu::Language::OPTIONS), 25, 220, 30, font, sf::Color::White);
/*Draw option menu's buttons*/
menu_options.add_button(new fdx::menu::ButtonText(160, 75, 275, 50, 5, 5, sf::Color(255,127,42,255), sf::Color(150,60,0,255), false, over, press, fdx::menu::Language::getText(fdx::menu::Language::PERSONALIZE), font, 20, sf::Color::Black,sf::Color(205,201,201,255)));
menu_options.add_button(new fdx::menu::ButtonText(160, 155, 275, 50, 5, 5, sf::Color(255,127,42,255), sf::Color(150,60,0,255), true, over, press, fdx::menu::Language::getText(fdx::menu::Language::COLOR), font, 20, sf::Color::Black,sf::Color(205,201,201,255)));
menu_options.add_button(new fdx::menu::ButtonText(160, 240, 275, 50, 5, 5, sf::Color(255,127,42,255), sf::Color(150,60,0,255), true, over, press, fdx::menu::Language::getText(fdx::menu::Language::LANGUAGE), font, 20, sf::Color::Black,sf::Color(205,201,201,255)));
menu_options.add_button(new fdx::menu::ButtonText(160, 325, 275, 50, 5, 5, sf::Color(255,127,42,255), sf::Color(150,60,0,255), true, over, press, fdx::menu::Language::getText(fdx::menu::Language::CONTROLS), font, 20, sf::Color::Black, sf::Color(205,201,201,255)));
menu_options.add_button(new fdx::menu::ButtonImage(160, 405, 140, 50, 5, 5, sf::Color(255,127,42,255), sf::Color(150,60,0,255), true, over, press, go_back));
while (options.isOpen())
{
options.setSize(sf::Vector2u(600,500));
sf::Event event;
while (options.pollEvent(event))
{
switch (event.type)
{
case sf::Event::MouseMoved:
{
x=event.mouseMove.x;
y=event.mouseMove.y;
break;
}
case sf::Event::MouseButtonPressed:
{
if (event.mouseButton.button==sf::Mouse::Button::Left)
but=true;
break;
}
case sf::Event::MouseButtonReleased:
{
if (event.mouseButton.button==sf::Mouse::Button::Left)
but=false;
break;
}
case sf::Event::Closed:
{
options.close();
break;
}
default:
break;
}
if (event.type == sf::Event::Closed)
options.close();
}
/*Button selected*/
switch (menu_options.button_pressed(x, y, but))
{
//Personalize
case 0:
{
break;
}
//Color
case 1:
{
launch_options_colors(file, colors_read, menu_background, over, press, font);
break;
}
//Language
case 2:
{
int cp_lang = fdx::menu::Language::getLang();
launch_options_language(file, menu_background, over, press, font);
//Language changed
if(cp_lang != fdx::menu::Language::getLang())
options.close();
break;
}
//Controls
case 3:
{
launch_options_controls(file, menu_background, over, press, font);
break;
}
//Back
case 4:
{
options.close();
break;
}
}
options.clear();
options.draw(menu_options);
options.display();
}
}
void launch_options_colors(std::fstream& file, const std::array<int,3>& colors_read, const sf::Texture& menu_background, const sf::Sound& over, const sf::Sound& press, const sf::Font& font)
{
/*Window*/
sf::RenderWindow colors(sf::VideoMode(600, 400), fdx::menu::Language::getText(fdx::menu::Language::OPTIONS));
/*Button*/
int x,y,but = false;
/*Load position*/
x=sf::Mouse::getPosition().x;
y=sf::Mouse::getPosition().y;
/*Images*/
sf::Texture go_back;
/*Load image*/
if (!go_back.loadFromFile("media/images/back_img.png"))
std::cout << "Image not found" << std::endl;
/*Create menu*/
fdx::menu::Menu options_colors(menu_background, fdx::menu::Language::getText(fdx::menu::Language::COLORS), 25, 220, 30, font, sf::Color::White);
//Array of colors selected
std::array<int, 3> color_selected = colors_read;
//Array of names
std::array<std::string, 3> names = {{"A", "N", "E"}};
//Index of array
int ptr = -1;
//Number of buttons
int nb = 11;
/*Draw color menu's buttons*/
for(int i = 0; i < nb; ++i)
{
if (i < 3)
options_colors.add_button(new fdx::menu::ButtonText(100+(i*150), 100, 120, 50, 5, 5, sf::Color(255,127,42,255), sf::Color(150,60,0,255), true, over, press, names[i], font, 50, sf::Color::Black, sf::Color(205,201,201,255)));
else
options_colors.add_button(new fdx::menu::ButtonImage(20+((i-3)*70), 200, 65, 50, 5, 5, fdx::menu::DictionaryColors::getSemiColor(i-3), sf::Color(150,60,0,255), false, over, press, sf::Texture()));
}
/*Confirm and back Button*/
options_colors.add_button(new fdx::menu::ButtonText(330, 275, 200, 50, 5, 5, sf::Color(255,127,42,255), sf::Color(150,60,0,255), false, over, press, fdx::menu::Language::getText(fdx::menu::Language::CONFIRM), font, 20, sf::Color::Black, sf::Color(205,201,201,255)));
options_colors.add_button(new fdx::menu::ButtonImage(120, 275, 150, 50, 5, 5, sf::Color(255,127,42,255), sf::Color(150,60,0,255), true, over, press, go_back));
while (colors.isOpen())
{
colors.setSize(sf::Vector2u(600,400));
sf::Event event;
while (colors.pollEvent(event))
{
switch (event.type)
{
case sf::Event::MouseMoved:
{
x=event.mouseMove.x;
y=event.mouseMove.y;
break;
}
case sf::Event::MouseButtonPressed:
{
if (event.mouseButton.button==sf::Mouse::Button::Left)
but=true;
break;
}
case sf::Event::MouseButtonReleased:
{
if (event.mouseButton.button==sf::Mouse::Button::Left)
but=false;
break;
}
case sf::Event::Closed:
{
colors.close();
break;
}
default:
break;
}
if (event.type == sf::Event::Closed)
colors.close();
}
//Copy of index
int cp_ptr;
//Button selected
ptr = options_colors.button_pressed(x,y,but);
//It's the default value, do nothing
if (ptr == -1);
//Button has been pressed
else
{
//It's an ANE color
if (ptr < 3)
{
//Get the copy for change color later
cp_ptr = ptr;
//Mark the button selected
options_colors.change_color_rect(ptr, sf::Color::Transparent);
//Unlock color buttons
for (int i = 3; i < nb; ++i)
{
if (color_selected[0] != i-3 && color_selected[1] != i-3 && color_selected[2] != i-3)
{
options_colors.unlock_buttons(i);
options_colors.change_color_rect(i, fdx::menu::DictionaryColors::getColor(i-3));
}
}
}
//It's an button color or finish button
else
{
//It's an button color
if(ptr < 11)
{
//Fill the mark button with the color selected
options_colors.change_color_rect(cp_ptr, fdx::menu::DictionaryColors::getColor(ptr-3));
color_selected[cp_ptr] = ptr - 3;
if (color_selected[0] != -1 && color_selected[1] != -1 && color_selected[2] != -1)
{
options_colors.unlock_buttons(11);
}
//Block the color buttons
for (int i = 3; i < nb; ++i)
{
options_colors.lock_buttons(i);
options_colors.change_color_rect(i, fdx::menu::DictionaryColors::getSemiColor(i-3));
}
}
//It's the finish button
else
{
//It's the back button
if(ptr == 12)
{
colors.close();
}
//It's the confirm button
else
{
file.seekg(9);
for (int i = 0; i < 3; ++i)
{
file << color_selected[i] << std::endl;
}
colors.close();
}
}
}
}
fdx::fighter::teams.set_friendly(fdx::menu::DictionaryColors::getColor(color_selected[0]));
fdx::fighter::teams.set_neutral(fdx::menu::DictionaryColors::getColor(color_selected[1]));
fdx::fighter::teams.set_enemy(fdx::menu::DictionaryColors::getColor(color_selected[2]));
colors.clear();
colors.draw(options_colors);
colors.display();
}
}
void launch_options_language(std::fstream& file, const sf::Texture& menu_background, const sf::Sound& over, const sf::Sound& press, const sf::Font& font)
{
/*Window*/
sf::RenderWindow language(sf::VideoMode(600, 400), fdx::menu::Language::getText(fdx::menu::Language::OPTIONS));
/*Button*/
int x,y,but = false;
/*Load position*/
x=sf::Mouse::getPosition().x;
y=sf::Mouse::getPosition().y;
/*Images*/
sf::Texture go_back;
sf::Texture esp_flag;
sf::Texture eng_flag;
/*Load image*/
if (!go_back.loadFromFile("media/images/back_img.png"))
std::cout << "Image not found" << std::endl;
if (!esp_flag.loadFromFile("media/images/esp_flag.png"))
std::cout << "Image not found" << std::endl;
if (!eng_flag.loadFromFile("media/images/eng_flag.png"))
std::cout << "Image not found" << std::endl;
/*Create menu*/
fdx::menu::Menu menu_language(menu_background, fdx::menu::Language::getText(fdx::menu::Language::LANGUAGES), 25, 210, 30, font, sf::Color::White);
/*Draw language menu's buttons*/
menu_language.add_button(new fdx::menu::ButtonImage(100, 100, 125, 75, 10, 10, sf::Color(255,127,42,255), sf::Color(150,60,0,255), true, over, press, esp_flag));
menu_language.add_button(new fdx::menu::ButtonImage(325, 100, 125, 75, 10, 10, sf::Color(255,127,42,255), sf::Color(150,60,0,255), true, over, press, eng_flag));
menu_language.add_button(new fdx::menu::ButtonText(325, 240, 200, 50, 10, 10, sf::Color(255,127,42,255), sf::Color(150,60,0,255), true, over, press, fdx::menu::Language::getText(fdx::menu::Language::CONFIRM), font, 20, sf::Color::Black, sf::Color(205,201,201,255)));
menu_language.add_button(new fdx::menu::ButtonImage(100, 240, 140, 50, 10, 10, sf::Color(255,127,42,255), sf::Color(150,60,0,255), true, over, press, go_back));
menu_language.add_button(new fdx::menu::ButtonText(120, 320, 350, 50, 10, 10, sf::Color::Transparent, sf::Color::Transparent, false, sf::Sound(), sf::Sound(), fdx::menu::Language::getText(fdx::menu::Language::RESTART), font, 10, sf::Color::Yellow, sf::Color::Transparent));
while (language.isOpen())
{
language.setSize(sf::Vector2u(600,400));
sf::Event event;
while (language.pollEvent(event))
{
switch (event.type)
{
case sf::Event::MouseMoved:
{
x=event.mouseMove.x;
y=event.mouseMove.y;
break;
}
case sf::Event::MouseButtonPressed:
{
if (event.mouseButton.button==sf::Mouse::Button::Left)
but=true;
break;
}
case sf::Event::MouseButtonReleased:
{
if (event.mouseButton.button==sf::Mouse::Button::Left)
but=false;
break;
}
case sf::Event::Closed:
{
language.close();
break;
}
default:
break;
}
if (event.type == sf::Event::Closed)
language.close();
}
/*Button selected*/
int eng_esp;
switch (menu_language.button_pressed(x, y, but))
{
//Spanish
case 0:
{
eng_esp = 1;
//Mark the esp flag, unmark the eng flag
menu_language.change_color_image(0, sf::Color(255,255,255,128));
menu_language.change_color_image(1, sf::Color(255,255,255,255));
//It's the other option
if (fdx::menu::Language::getLang() != eng_esp)
{
//Show message
menu_language.unlock_buttons(4);
}
else
{
//Hide message
menu_language.lock_buttons(4);
}
break;
}
//English
case 1:
{
eng_esp = 0;
//Mark the esp flag, unmark the eng flag
menu_language.change_color_image(1, sf::Color(255,255,255,128));
menu_language.change_color_image(0, sf::Color(255,255,255,255));
//It's the other option
if (fdx::menu::Language::getLang() != eng_esp)
{
//Show message
menu_language.unlock_buttons(4);
}
else
{
//Hide message
menu_language.lock_buttons(4);
}
break;
}
//Confirm
case 2:
{
fdx::menu::Language::setLang(eng_esp);
file.seekg(std::ios_base::beg);
if(fdx::menu::Language::getLang() == 1)
file << "Español" << std::endl;
else
file << "English" << std::endl;
language.close();
break;
}
//Back
case 3:
{
language.close();
break;
}
}
language.clear();
language.draw(menu_language);
language.display();
}
}
void launch_options_controls(std::fstream& file, const sf::Texture& menu_background, const sf::Sound& over, const sf::Sound& press, const sf::Font& font)
{
/*Window*/
sf::RenderWindow controls(sf::VideoMode(600, 420), fdx::menu::Language::getText(fdx::menu::Language::OPTIONS));
/*Button*/
int x,y,but = false;
/*Load position*/
x=sf::Mouse::getPosition().x;
y=sf::Mouse::getPosition().y;
/*Images*/
sf::Texture go_back;
sf::Texture wii;
sf::Texture xbox;
sf::Texture mouse;
/*Load image*/
if (!go_back.loadFromFile("media/images/back_img.png"))
std::cout << "Image not found" << std::endl;
if (!wii.loadFromFile("media/images/wii.png"))
std::cout << "Image not found" << std::endl;
if (!xbox.loadFromFile("media/images/xbox.png"))
std::cout << "Image not found" << std::endl;
if (!mouse.loadFromFile("media/images/mouse.png"))
std::cout << "Image not found" << std::endl;
/*Create menu*/
fdx::menu::Menu menu_controls(menu_background, fdx::menu::Language::getText(fdx::menu::Language::CONTROLS), 25, 200, 30, font, sf::Color::White);
/*Draw option menu's buttons*/
menu_controls.add_button(new fdx::menu::ButtonImage(100, 105, 100, 100, 5, 5, sf::Color(255,127,42,255), sf::Color(150,60,0,255), true, over, press, mouse));
menu_controls.add_button(new fdx::menu::ButtonImage(260, 105, 100, 100, 5, 5, sf::Color(255,127,42,255), sf::Color(150,60,0,255), true, over, press, xbox));
menu_controls.add_button(new fdx::menu::ButtonImage(415, 105, 100, 100, 5, 5, sf::Color(255,127,42,255), sf::Color(150,60,0,255), true, over, press, wii));
menu_controls.add_button(new fdx::menu::ButtonText(100, 240, 200, 50, 5, 5, sf::Color(255,127,42,255), sf::Color(150,60,0,255), false, over, press, fdx::menu::Language::getText(fdx::menu::Language::CONFIGURE), font, 20, sf::Color::Black, sf::Color(205,201,201,255)));
menu_controls.add_button(new fdx::menu::ButtonText(320, 240, 200, 50, 5, 5, sf::Color(255,127,42,255), sf::Color(150,60,0,255), false, over, press, fdx::menu::Language::getText(fdx::menu::Language::CONFIRM), font, 20, sf::Color::Black, sf::Color(205,201,201,255)));
menu_controls.add_button(new fdx::menu::ButtonImage(100, 320, 140, 50, 5, 5, sf::Color(255,127,42,255), sf::Color(150,60,0,255), true, over, press, go_back));
menu_controls.change_color_image(fdx::fighter::controllers.get_cont_num(), sf::Color(255,255,255,128));
while (controls.isOpen())
{
sf::Event event;
while (controls.pollEvent(event))
{
switch (event.type)
{
case sf::Event::MouseMoved:
{
x=event.mouseMove.x;
y=event.mouseMove.y;
break;
}
case sf::Event::MouseButtonPressed:
{
if (event.mouseButton.button==sf::Mouse::Button::Left)
but=true;
break;
}
case sf::Event::MouseButtonReleased:
{
if (event.mouseButton.button==sf::Mouse::Button::Left)
but=false;
break;
}
case sf::Event::Closed:
{
controls.close();
break;
}
default:
break;
}
if (event.type == sf::Event::Closed)
controls.close();
}
//Button selected
int control;
switch (menu_controls.button_pressed(x, y, but))
{
//Keyboard and mouse
case 0:
{
//Keyboard and mouse
control = 0;
//Mark the button, unmark the others
menu_controls.change_color_image(0, sf::Color(255,255,255,128));
menu_controls.change_color_image(1, sf::Color(255,255,255,255));
menu_controls.change_color_image(2, sf::Color(255,255,255,255));
//Unlock confirm
menu_controls.unlock_buttons(3);
menu_controls.unlock_buttons(4);
break;
}
//Xbox controlles
case 1:
{
//Xbox controller
control = 1;
//Mark the button, unmark the others
menu_controls.change_color_image(1, sf::Color(255,255,255,128));
menu_controls.change_color_image(0, sf::Color(255,255,255,255));
menu_controls.change_color_image(2, sf::Color(255,255,255,255));
//Unlock confirm
menu_controls.unlock_buttons(3);
menu_controls.unlock_buttons(4);
break;
}
//Wii controller
case 2:
{
//Wii controller
control = 2;
//Mark the button, unmark the others
menu_controls.change_color_image(2, sf::Color(255,255,255,128));
menu_controls.change_color_image(1, sf::Color(255,255,255,255));
menu_controls.change_color_image(0, sf::Color(255,255,255,255));
//Unlock confirm
menu_controls.unlock_buttons(3);
menu_controls.unlock_buttons(4);
break;
}
case 3:
{
if (control == 0)
launch_options_configure_mouse(file, menu_background, over, press, font);
else if (control == 1)
launch_options_configure_xbox(file, menu_background, over, press, font);
break;
}
case 4:
if (control>=0&&control<=2)
fdx::fighter::controllers.set_controller(control);
case 5:
//Save
std::ofstream fbindings("bindings.data", std::ios::trunc);
fdx::fighter::controllers.write_to(fbindings);
fbindings.close();
controls.close();
break;
}
controls.clear();
controls.draw(menu_controls);
controls.display();
}
}
void launch_options_configure_mouse(std::fstream& file, const sf::Texture& menu_background, const sf::Sound& over, const sf::Sound& press, const sf::Font& font)
{
/*Window*/
sf::RenderWindow configure_mouse(sf::VideoMode(600, 420), fdx::menu::Language::getText(fdx::menu::Language::OPTIONS));
/*Button*/
int x,y,but = false;
/*Load position*/
x=sf::Mouse::getPosition().x;
y=sf::Mouse::getPosition().y;
/*Images*/
sf::Texture go_back;
/*Load image*/
if (!go_back.loadFromFile("media/images/back_img.png"))
std::cout << "Image not found" << std::endl;
//Controller
fdx::fighter::KM_Controller controller(fdx::fighter::controllers.get_km());
int selected_bind=-1;
/*Create menu with the tittle of the control*/
fdx::menu::Menu menu_mouse(menu_background, fdx::menu::Language::getText(fdx::menu::Language::MOUSE), 25, 140, 30, font, sf::Color::White);
/*Text with the spaceship's action*/
sf::Text shoot(fdx::menu::Language::getText(fdx::menu::Language::SHOOT), font, 20);
sf::Text speed(fdx::menu::Language::getText(fdx::menu::Language::ACCELERATE), font, 20);
sf::Text brake(fdx::menu::Language::getText(fdx::menu::Language::BRAKE), font, 20);
//Actions
shoot.setPosition(70, 110);
shoot.setColor(sf::Color::Yellow);
speed.setPosition(70,190);
speed.setColor(sf::Color::Yellow);
brake.setPosition(70,275);
brake.setColor(sf::Color::Yellow);
/*Draw buttons*/
menu_mouse.add_button(new fdx::menu::ButtonText(300, 95, 200, 50, 5, 5, sf::Color(255,127,42,255), sf::Color(150,60,0,255), true, over, press, controller.get_fire().print(), font, 20, sf::Color::Black, sf::Color(205,201,201,255)));
menu_mouse.add_button(new fdx::menu::ButtonText(300, 175, 200, 50, 5, 5, sf::Color(255,127,42,255), sf::Color(150,60,0,255), true, over, press, controller.get_acc().print(), font, 20, sf::Color::Black, sf::Color(205,201,201,255)));
menu_mouse.add_button(new fdx::menu::ButtonText(300, 260, 200, 50, 5, 5, sf::Color(255,127,42,255), sf::Color(150,60,0,255), true, over, press, controller.get_brake().print(), font, 20, sf::Color::Black, sf::Color(205,201,201,255)));
menu_mouse.add_button(new fdx::menu::ButtonText(300, 340, 200, 50, 5, 5, sf::Color(255,127,42,255), sf::Color(150,60,0,255), true, over, press, fdx::menu::Language::getText(fdx::menu::Language::CONFIRM), font, 20, sf::Color::Black, sf::Color(205,201,201,255)));
menu_mouse.add_button(new fdx::menu::ButtonImage(70, 340, 140, 50, 5, 5, sf::Color(255,127,42,255), sf::Color(150,60,0,255), true, over, press, go_back));
while (configure_mouse.isOpen())
{
sf::Event event;
while (configure_mouse.pollEvent(event))
{
if (selected_bind>=0&&selected_bind<=2)
{
fdx::fighter::Event_KM new_bind;
if (new_bind.set_from_event(event)&&new_bind.check_event())
{
switch (selected_bind)
{
case 0:
{
controller.set_fire(new_bind);
break;
}
case 1:
{
controller.set_acc(new_bind);
break;
}
case 2:
{
controller.set_brake(new_bind);
break;
}
}
menu_mouse.change_color_rect(selected_bind,sf::Color(255,127,42,255));
menu_mouse.change_text(selected_bind,new_bind.print());
selected_bind=-1;
}
}
else switch (event.type)
{
case sf::Event::MouseMoved:
{
x=event.mouseMove.x;
y=event.mouseMove.y;
break;
}
case sf::Event::MouseButtonPressed:
{
if (event.mouseButton.button==sf::Mouse::Button::Left)
but=true;
break;
}
case sf::Event::MouseButtonReleased:
{
if (event.mouseButton.button==sf::Mouse::Button::Left)
but=false;
break;
}
case sf::Event::Closed:
{
configure_mouse.close();
break;
}
default:
break;
}
if (event.type == sf::Event::Closed)
configure_mouse.close();
}
int pressed_button;
switch (pressed_button=menu_mouse.button_pressed(x, y, but))
{
//Controls
case 0:
case 1:
case 2:
{
selected_bind=pressed_button;
menu_mouse.change_color_rect(pressed_button,sf::Color::Red);
break;
}
//Confirm
case 3:
//SAVE HERE
fdx::fighter::controllers.set_km(controller);
//Go back
case 4:
configure_mouse.close();
break;
}
configure_mouse.clear();
configure_mouse.draw(menu_mouse);