2 Copyright (C) 2003, 2010 - Wolfire Games
3 Copyright (C) 2010-2017 - Lugaru contributors (see AUTHORS file)
5 This file is part of Lugaru.
7 Lugaru is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 Lugaru is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Lugaru. If not, see <http://www.gnu.org/licenses/>.
21 #include "Menu/Menu.hpp"
23 #include "Audio/openal_wrapper.hpp"
24 #include "Graphic/gamegl.hpp"
25 #include "Level/Campaign.hpp"
26 #include "User/Settings.hpp"
27 #include "Utils/Input.hpp"
28 #include "Version.hpp"
30 // Should not be needed, Menu should call methods from other classes to launch maps and challenges and so on
31 #include "Level/Awards.hpp"
39 extern float multiplier;
40 extern std::set<std::pair<int, int>> resolutions;
42 extern std::vector<CampaignLevel> campaignlevels;
43 extern float musicvolume[4];
44 extern float oldmusicvolume[4];
45 extern bool stillloading;
46 extern bool visibleloading;
47 extern int whichchoice;
48 extern int leveltheme;
50 extern void toggleFullscreen();
53 std::string newusername = "";
54 unsigned newuserselected = 0;
55 float newuserblinkdelay = 0;
56 bool newuserblink = false;
58 std::vector<MenuItem> Menu::items;
60 MenuItem::MenuItem(MenuItemType _type, int _id, const string& _text, Texture _texture,
61 int _x, int _y, int _w, int _h, float _r, float _g, float _b,
62 float _linestartsize, float _lineendsize)
75 , linestartsize(_linestartsize)
76 , lineendsize(_lineendsize)
78 if (type == MenuItem::BUTTON) {
80 w = text.length() * 10;
88 void Menu::clearMenu()
93 void Menu::addLabel(int id, const string& text, int x, int y, float r, float g, float b)
95 items.emplace_back(MenuItem::LABEL, id, text, Texture(), x, y, -1, -1, r, g, b);
97 void Menu::addButton(int id, const string& text, int x, int y, float r, float g, float b)
99 items.emplace_back(MenuItem::BUTTON, id, text, Texture(), x, y, -1, -1, r, g, b);
101 void Menu::addImage(int id, Texture texture, int x, int y, int w, int h, float r, float g, float b)
103 items.emplace_back(MenuItem::IMAGE, id, "", texture, x, y, w, h, r, g, b);
105 void Menu::addButtonImage(int id, Texture texture, int x, int y, int w, int h, float r, float g, float b)
107 items.emplace_back(MenuItem::IMAGEBUTTON, id, "", texture, x, y, w, h, r, g, b);
109 void Menu::addMapLine(int x, int y, int w, int h, float startsize, float endsize, float r, float g, float b)
111 items.emplace_back(MenuItem::MAPLINE, -1, "", Texture(), x, y, w, h, r, g, b, startsize, endsize);
113 void Menu::addMapMarker(int id, Texture texture, int x, int y, int w, int h, float r, float g, float b)
115 items.emplace_back(MenuItem::MAPMARKER, id, "", texture, x, y, w, h, r, g, b);
117 void Menu::addMapLabel(int id, const string& text, int x, int y, float r, float g, float b)
119 items.emplace_back(MenuItem::MAPLABEL, id, text, Texture(), x, y, -1, -1, r, g, b);
122 void Menu::setText(int id, const string& text)
124 for (vector<MenuItem>::iterator it = items.begin(); it != items.end(); it++) {
127 it->w = it->text.length() * 10;
133 void Menu::setText(int id, const string& text, int x, int y, int w, int h)
135 for (vector<MenuItem>::iterator it = items.begin(); it != items.end(); it++) {
141 it->w = it->text.length() * 10;
151 int Menu::getSelected(int mousex, int mousey)
153 for (vector<MenuItem>::reverse_iterator it = items.rbegin(); it != items.rend(); it++) {
154 if (it->type == MenuItem::BUTTON || it->type == MenuItem::IMAGEBUTTON || it->type == MenuItem::MAPMARKER) {
157 if (it->type == MenuItem::MAPMARKER) {
161 if (mx >= it->x && mx < it->x + it->w && my >= it->y && my < it->y + it->h) {
169 void Menu::handleFadeEffect()
171 for (vector<MenuItem>::iterator it = items.begin(); it != items.end(); it++) {
172 if (it->id == Game::selected) {
173 it->effectfade += multiplier * 5;
174 if (it->effectfade > 1) {
178 it->effectfade -= multiplier * 5;
179 if (it->effectfade < 0) {
186 void Menu::drawItems()
189 glEnable(GL_TEXTURE_2D);
190 glEnable(GL_ALPHA_TEST);
192 for (vector<MenuItem>::iterator it = items.begin(); it != items.end(); it++) {
194 case MenuItem::IMAGE:
195 case MenuItem::IMAGEBUTTON:
196 case MenuItem::MAPMARKER:
197 glColor4f(it->r, it->g, it->b, 1);
199 if (it->type == MenuItem::MAPMARKER) {
200 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
201 glTranslatef(2.5, -4.5, 0); //from old code
203 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
206 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
207 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
210 glVertex3f(it->x, it->y, 0);
212 glVertex3f(it->x + it->w, it->y, 0);
214 glVertex3f(it->x + it->w, it->y + it->h, 0);
216 glVertex3f(it->x, it->y + it->h, 0);
218 if (it->type != MenuItem::IMAGE) {
219 //mouseover highlight
220 for (int i = 0; i < 10; i++) {
221 if (1 - ((float)i) / 10 - (1 - it->effectfade) > 0) {
222 glColor4f(it->r, it->g, it->b, (1 - ((float)i) / 10 - (1 - it->effectfade)) * .25);
225 glVertex3f(it->x - ((float)i) * 1 / 2, it->y - ((float)i) * 1 / 2, 0);
227 glVertex3f(it->x + it->w + ((float)i) * 1 / 2, it->y - ((float)i) * 1 / 2, 0);
229 glVertex3f(it->x + it->w + ((float)i) * 1 / 2, it->y + it->h + ((float)i) * 1 / 2, 0);
231 glVertex3f(it->x - ((float)i) * 1 / 2, it->y + it->h + ((float)i) * 1 / 2, 0);
238 case MenuItem::LABEL:
239 case MenuItem::BUTTON:
240 glColor4f(it->r, it->g, it->b, 1);
241 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
242 Game::text->glPrint(it->x, it->y, it->text.c_str(), 0, 1, 640, 480);
243 if (it->type != MenuItem::LABEL) {
244 //mouseover highlight
245 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
246 for (int i = 0; i < 15; i++) {
247 if (1 - ((float)i) / 15 - (1 - it->effectfade) > 0) {
248 glColor4f(it->r, it->g, it->b, (1 - ((float)i) / 10 - (1 - it->effectfade)) * .25);
249 Game::text->glPrint(it->x - ((float)i), it->y, it->text.c_str(), 0, 1 + ((float)i) / 70, 640, 480);
254 case MenuItem::MAPLABEL:
255 Game::text->glPrintOutlined(0.9, 0, 0, 1, it->x, it->y, it->text.c_str(), 0, 0.6, 640, 480);
257 case MenuItem::MAPLINE: {
263 lineend.x = it->x + it->w;
264 lineend.y = it->y + it->h;
266 XYZ offset = lineend - linestart;
269 offset = DoRotation(offset, 0, 0, 90);
272 linestart += fac * 4 * it->linestartsize;
273 lineend -= fac * 4 * it->lineendsize;
275 glDisable(GL_TEXTURE_2D);
276 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
277 glColor4f(it->r, it->g, it->b, 1);
279 glTranslatef(2, -5, 0); //from old code
281 glVertex3f(linestart.x - offset.x * it->linestartsize, linestart.y - offset.y * it->linestartsize, 0.0f);
282 glVertex3f(linestart.x + offset.x * it->linestartsize, linestart.y + offset.y * it->linestartsize, 0.0f);
283 glVertex3f(lineend.x + offset.x * it->lineendsize, lineend.y + offset.y * it->lineendsize, 0.0f);
284 glVertex3f(lineend.x - offset.x * it->lineendsize, lineend.y - offset.y * it->lineendsize, 0.0f);
287 glEnable(GL_TEXTURE_2D);
296 void Menu::updateSettingsMenu()
298 std::string sbuf = std::string("Resolution: ") + to_string(newscreenwidth) + "*" + to_string(newscreenheight);
299 if (((float)newscreenwidth <= (float)newscreenheight * 1.61) && ((float)newscreenwidth >= (float)newscreenheight * 1.59)) {
300 sbuf += " (widescreen)";
303 setText(14, fullscreen ? "Fullscreen: On" : "Fullscreen: Off");
304 if (newdetail == 0) {
305 setText(1, "Detail: Low");
307 if (newdetail == 1) {
308 setText(1, "Detail: Medium");
310 if (newdetail == 2) {
311 setText(1, "Detail: High");
313 if (bloodtoggle == 0) {
314 setText(2, "Blood: Off");
316 if (bloodtoggle == 1) {
317 setText(2, "Blood: On, low detail");
319 if (bloodtoggle == 2) {
320 setText(2, "Blood: On, high detail (slower)");
322 setText(4, ismotionblur ? "Blur Effects: Enabled (less compatible)" : "Blur Effects: Disabled (more compatible)");
323 setText(5, decalstoggle ? "Decals: Enabled (slower)" : "Decals: Disabled");
324 setText(6, musictoggle ? "Music: Enabled" : "Music: Disabled");
325 setText(9, invertmouse ? "Invert mouse: Yes" : "Invert mouse: No");
326 setText(10, std::string("Mouse Speed: ") + to_string(int(usermousesensitivity * 5)));
327 setText(11, std::string("Volume: ") + to_string(int(volume * 100)) + "%");
328 setText(13, showdamagebar ? "Damage Bar: On" : "Damage Bar: Off");
329 if ((newdetail == detail) && (newscreenheight == (int)screenheight) && (newscreenwidth == (int)screenwidth)) {
332 setText(8, "Back (some changes take effect next time Lugaru is opened)");
336 void Menu::updateStereoConfigMenu()
338 setText(0, std::string("Stereo mode: ") + StereoModeName(newstereomode));
339 setText(1, std::string("Stereo separation: ") + to_string(stereoseparation));
340 setText(2, std::string("Reverse stereo: ") + (stereoreverse ? "Yes" : "No"));
343 void Menu::updateControlsMenu()
345 setText(0, (string) "Forwards: " + (keyselect == 0 ? "_" : Input::keyToChar(forwardkey)));
346 setText(1, (string) "Back: " + (keyselect == 1 ? "_" : Input::keyToChar(backkey)));
347 setText(2, (string) "Left: " + (keyselect == 2 ? "_" : Input::keyToChar(leftkey)));
348 setText(3, (string) "Right: " + (keyselect == 3 ? "_" : Input::keyToChar(rightkey)));
349 setText(4, (string) "Crouch: " + (keyselect == 4 ? "_" : Input::keyToChar(crouchkey)));
350 setText(5, (string) "Jump: " + (keyselect == 5 ? "_" : Input::keyToChar(jumpkey)));
351 setText(6, (string) "Draw: " + (keyselect == 6 ? "_" : Input::keyToChar(drawkey)));
352 setText(7, (string) "Throw: " + (keyselect == 7 ? "_" : Input::keyToChar(throwkey)));
353 setText(8, (string) "Attack: " + (keyselect == 8 ? "_" : Input::keyToChar(attackkey)));
355 setText(9, (string) "Console: " + (keyselect == 9 ? "_" : Input::keyToChar(consolekey)));
362 2 Menu pause (resume/end game)
364 4 Controls configuration menu
365 5 Main game menu (choose level or challenge)
367 7 User managment menu (select/add)
368 8 Choose difficulty menu
369 9 Challenge level selection menu
370 10 End of the campaign congratulation (is that really a menu?)
371 11 Same that 9 ??? => unused
372 18 stereo configuration
381 addImage(0, Mainmenuitems[0], 150, 480 - 128, 256, 128);
382 addButtonImage(1, Mainmenuitems[mainmenu == 1 ? 1 : 5], 18, 480 - 152 - 32, 128, 32);
383 addButtonImage(2, Mainmenuitems[2], 18, 480 - 228 - 32, 112, 32);
384 addButtonImage(3, Mainmenuitems[mainmenu == 1 ? 3 : 6], 18, 480 - 306 - 32, mainmenu == 1 ? 68 : 132, 32);
385 addLabel(-1, VERSION_NUMBER + VERSION_SUFFIX, 640 - 100, 10);
388 addButton(0, "", 10 + 20, 440);
389 addButton(14, "", 10 + 400, 440);
390 addButton(1, "", 10 + 60, 405);
391 addButton(2, "", 10 + 70, 370);
392 addButton(4, "", 10, 335);
393 addButton(5, "", 10 + 60, 300);
394 addButton(6, "", 10 + 70, 265);
395 addButton(9, "", 10, 230);
396 addButton(10, "", 20, 195);
397 addButton(11, "", 10 + 60, 160);
398 addButton(13, "", 30, 125);
399 addButton(7, "-Configure Controls-", 10 + 15, 90);
400 addButton(12, "-Configure Stereo -", 10 + 15, 55);
401 addButton(8, "Back", 10, 10);
402 updateSettingsMenu();
405 addButton(0, "", 10, 400);
406 addButton(1, "", 10 + 40, 360);
407 addButton(2, "", 10 + 40, 320);
408 addButton(3, "", 10 + 30, 280);
409 addButton(4, "", 10 + 20, 240);
410 addButton(5, "", 10 + 40, 200);
411 addButton(6, "", 10 + 40, 160);
412 addButton(7, "", 10 + 30, 120);
413 addButton(8, "", 10 + 20, 80);
415 addButton(9, "", 10 + 10, 40);
417 addButton(devtools ? 10 : 9, "Back", 10, 10);
418 updateControlsMenu();
422 addLabel(-1, Account::active().getName(), 5, 400);
423 addButton(1, "Tutorial", 5, 300);
424 addButton(2, "Challenge", 5, 240);
425 addButton(3, "Delete User", 400, 10);
426 addButton(4, "Main Menu", 5, 10);
427 addButton(5, "Change User", 5, 180);
428 addButton(6, "Campaign : " + Account::active().getCurrentCampaign(), 200, 420);
431 //with (2,-5) offset from old code
432 addImage(-1, Mainmenuitems[7], 150 + 2, 60 - 5, 400, 400);
434 int numlevels = Account::active().getCampaignChoicesMade();
435 numlevels += numlevels > 0 ? campaignlevels[numlevels - 1].nextlevel.size() : 1;
436 for (int i = 0; i < numlevels; i++) {
437 XYZ midpoint = campaignlevels[i].getCenter();
438 float itemsize = campaignlevels[i].getWidth();
439 const bool active = (i >= Account::active().getCampaignChoicesMade());
445 XYZ start = campaignlevels[i - 1].getCenter();
446 addMapLine(start.x, start.y, midpoint.x - start.x, midpoint.y - start.y, 0.5, active ? 1 : 0.5, active ? 1 : 0.5, 0, 0);
448 addMapMarker(NB_CAMPAIGN_MENU_ITEM + i, Mapcircletexture,
449 midpoint.x - itemsize / 2, midpoint.y - itemsize / 2, itemsize, itemsize, active ? 1 : 0.5, 0, 0);
452 addMapLabel(-2, campaignlevels[i].description,
453 campaignlevels[i].getStartX() + 10,
454 campaignlevels[i].getStartY() - 4);
459 addLabel(-1, "Are you sure you want to delete this user?", 10, 400);
460 addButton(1, "Yes", 10, 360);
461 addButton(2, "No", 10, 320);
464 if (Account::getNbAccounts() < 8) {
465 addButton(0, "New User", 10, 400);
467 addLabel(0, "No More Users", 10, 400);
469 addLabel(-2, "", 20, 400);
470 addButton(Account::getNbAccounts() + 1, "Back", 10, 10);
471 for (int i = 0; i < Account::getNbAccounts(); i++) {
472 addButton(i + 1, Account::get(i).getName(), 10, 340 - 20 * (i + 1));
476 addButton(0, "Easier", 10, 400);
477 addButton(1, "Difficult", 10, 360);
478 addButton(2, "Insane", 10, 320);
481 for (int i = 0; i < numchallengelevels; i++) {
482 string name = "Level ";
483 name += to_string(i + 1);
484 if (name.size() < 17) {
485 name.append((17 - name.size()), ' ');
487 name += to_string(int(Account::active().getHighScore(i)));
488 if (name.size() < 32) {
489 name.append((32 - name.size()), ' ');
491 int fasttime = (int)round(Account::active().getFastTime(i));
492 name += to_string(int((fasttime - fasttime % 60) / 60));
494 if (fasttime % 60 < 10) {
497 name += to_string(fasttime % 60);
499 addButton(i, name, 10, 400 - i * 25, i > Account::active().getProgress() ? 0.5 : 1, 0, 0);
502 addButton(-1, " High Score Best Time", 10, 440);
503 addButton(numchallengelevels, "Back", 10, 10);
506 addLabel(0, campaignEndText[0], 80, 330);
507 addLabel(1, campaignEndText[1], 80, 300);
508 addLabel(2, campaignEndText[2], 80, 270);
509 addButton(3, "Back", 10, 10);
510 addLabel(4, string("Your score: ") + to_string((int)Account::active().getCampaignScore()), 190, 200);
511 addLabel(5, string("Highest score: ") + to_string((int)Account::active().getCampaignHighScore()), 190, 180);
514 addButton(0, "", 70, 400);
515 addButton(1, "", 10, 360);
516 addButton(2, "", 40, 320);
517 addButton(3, "Back", 10, 10);
518 updateStereoConfigMenu();
526 if (Input::isKeyPressed(SDL_SCANCODE_ESCAPE) &&
527 (mainmenu >= 3) && (mainmenu != 8) && !((mainmenu == 7) && entername)) {
529 //finished with settings menu
534 if (mainmenu >= 3 && mainmenu != 8) {
542 mainmenu = gameon ? 2 : 1;
558 selected = getSelected(mousecoordh * 640 / screenwidth, 480 - mousecoordv * 480 / screenheight);
560 // some specific case where we do something even if the left mouse button is not pressed.
561 if ((mainmenu == 5) && (endgame == 2)) {
562 Account::active().endGame();
565 if (mainmenu == 10) {
568 if (mainmenu == 18 && Input::isKeyPressed(MOUSEBUTTON_RIGHT) && selected == 1) {
569 stereoseparation -= 0.001;
570 updateStereoConfigMenu();
573 static int oldmainmenu = mainmenu;
575 if (Input::MouseClicked() && (selected >= 0)) { // handling of the left mouse clic in menus
576 set<pair<int, int>>::iterator newscreenresolution;
582 if (gameon) { //resume
584 pause_sound(stream_menutheme);
585 resume_stream(leveltheme);
587 fireSound(firestartsound);
589 mainmenu = (Account::hasActive() ? 5 : 7);
603 if (newscreenwidth > 3000) {
604 newscreenwidth = screenwidth;
606 if (newscreenwidth < 0) {
607 newscreenwidth = screenwidth;
609 if (newscreenheight > 3000) {
610 newscreenheight = screenheight;
612 if (newscreenheight < 0) {
613 newscreenheight = screenheight;
619 if (gameon) { //end game
624 pause_sound(stream_menutheme);
633 newscreenresolution = resolutions.find(make_pair(newscreenwidth, newscreenheight));
634 /* Next one (end() + 1 is also end() so the ++ is safe even if it was not found) */
635 newscreenresolution++;
636 if (newscreenresolution == resolutions.end()) {
637 /* It was the last one (or not found), go back to the beginning */
638 newscreenresolution = resolutions.begin();
640 newscreenwidth = newscreenresolution->first;
641 newscreenheight = newscreenresolution->second;
651 if (bloodtoggle > 2) {
656 ismotionblur = !ismotionblur;
659 decalstoggle = !decalstoggle;
662 musictoggle = !musictoggle;
664 emit_stream_np(stream_menutheme);
666 pause_sound(leveltheme);
667 pause_sound(stream_fighttheme);
668 pause_sound(stream_menutheme);
670 for (int i = 0; i < 4; i++) {
671 oldmusicvolume[i] = 0;
685 mainmenu = gameon ? 2 : 1;
688 invertmouse = !invertmouse;
691 usermousesensitivity += .2;
692 if (usermousesensitivity > 2) {
693 usermousesensitivity = .2;
698 if (volume > 1.0001f) {
701 OPENAL_SetSFXMasterVolume((int)(volume * 255));
705 newstereomode = stereomode;
710 showdamagebar = !showdamagebar;
716 updateSettingsMenu();
721 if (selected < (devtools ? 10 : 9) && keyselect == -1) {
722 keyselect = selected;
724 if (keyselect != -1) {
727 if (selected == (devtools ? 10 : 9)) {
732 updateControlsMenu();
737 if ((selected - NB_CAMPAIGN_MENU_ITEM >= Account::active().getCampaignChoicesMade())) {
748 whichchoice = selected - NB_CAMPAIGN_MENU_ITEM - Account::active().getCampaignChoicesMade();
749 actuallevel = (Account::active().getCampaignChoicesMade() > 0 ? campaignlevels[Account::active().getCampaignChoicesMade() - 1].nextlevel[whichchoice] : 0);
750 visibleloading = true;
752 LoadLevel(campaignlevels[actuallevel].mapname.c_str());
756 pause_sound(stream_menutheme);
774 pause_sound(stream_menutheme);
783 mainmenu = (gameon ? 2 : 1);
789 vector<string> campaigns = ListCampaigns();
790 vector<string>::iterator c;
791 if ((c = find(campaigns.begin(), campaigns.end(), Account::active().getCurrentCampaign())) == campaigns.end()) {
792 if (!campaigns.empty()) {
793 Account::active().setCurrentCampaign(campaigns.front());
797 if (c == campaigns.end()) {
798 c = campaigns.begin();
800 Account::active().setCurrentCampaign(*c);
810 Account::destroyActive();
812 } else if (selected == 2) {
819 if (selected == 0 && Account::getNbAccounts() < 8) {
821 } else if (selected < Account::getNbAccounts() + 1) {
824 Account::setActive(selected - 1);
825 } else if (selected == Account::getNbAccounts() + 1) {
827 if (Account::hasActive()) {
841 Account::active().setDifficulty(selected);
846 if (selected < numchallengelevels && selected <= Account::active().getProgress()) {
854 targetlevel = selected;
865 pause_sound(stream_menutheme);
867 if (selected == numchallengelevels) {
882 stereoseparation += 0.001;
886 newstereomode = (StereoMode)(newstereomode + 1);
887 while (!CanInitStereo(newstereomode)) {
888 printf("Failed to initialize mode %s (%i)\n", StereoModeName(newstereomode).c_str(), newstereomode);
889 newstereomode = (StereoMode)(newstereomode + 1);
890 if (newstereomode >= stereoCount) {
891 newstereomode = stereoNone;
894 } else if (selected == 2) {
895 stereoreverse = !stereoreverse;
896 } else if (selected == 3) {
900 stereomode = newstereomode;
901 InitStereo(stereomode);
904 updateStereoConfigMenu();
909 OPENAL_SetFrequency(channels[stream_menutheme]);
912 inputText(newusername, &newuserselected);
913 if (!waiting) { // the input as finished
914 if (!newusername.empty()) { // with enter
915 Account::add(string(newusername));
921 fireSound(firestartsound);
931 newuserblinkdelay -= multiplier;
932 if (newuserblinkdelay <= 0) {
933 newuserblinkdelay = .3;
934 newuserblink = !newuserblink;
939 setText(0, newusername, 20, 400, -1, -1);
940 setText(-2, newuserblink ? "_" : "", 20 + newuserselected * 10, 400, -1, -1);
943 if (oldmainmenu != mainmenu) {
946 oldmainmenu = mainmenu;
949 int setKeySelected_thread(void*)
951 using namespace Game;
954 while (scancode == -1) {
955 SDL_WaitEvent(&evenement);
956 switch (evenement.type) {
958 scancode = evenement.key.keysym.scancode;
960 case SDL_MOUSEBUTTONDOWN:
961 scancode = SDL_NUM_SCANCODES + evenement.button.button;
967 if (scancode != SDL_SCANCODE_ESCAPE) {
971 forwardkey = scancode;
983 crouchkey = scancode;
995 attackkey = scancode;
998 consolekey = scancode;
1010 void Menu::setKeySelected()
1013 printf("launch thread\n");
1014 SDL_Thread* thread = SDL_CreateThread(setKeySelected_thread, NULL, NULL);
1015 if (thread == NULL) {
1016 fprintf(stderr, "Unable to create thread: %s\n", SDL_GetError());