bool menu::update(float timediff, bool esc_down, bool left_mouse_down, bool right_mouse_down, int mouse_x, int mouse_y, game& g) { //aktualni hodnoty pro prichod do podmenu mapname = maplist_get_name(g.get_mapchosen()); username = userlist_get_name(g.get_userchosen()); sens = sensitivities[g.get_sensitivity()]; dayt = daytime[g.get_daytime()]; weat = weather[g.get_weather()]; diff = difficulty[g.get_difficulty()]; //urceni pozice kurzoru cursor_pos += mouse_y; if (cursor_pos >= (int)(items.size() *100)) cursor_pos = (int)(items.size() * 100 - 1); if (cursor_pos < 0) cursor_pos = 0; int left_just_pressed = 0, esc_just_pressed = 0; //proti sekvencim stisknutych tlacitek if (left_mouse_down) { if (!left_mouse_hit) left_just_pressed = left_mouse_hit = 1; } else left_mouse_hit = 0; if (esc_down) { if (!esc_hit) esc_just_pressed = esc_hit = 1; } else esc_hit = 0; //pro vytvoreni prvniho uzivatelskeho uctu pri prvnim spusteni hry if ((username == "") && (menustatus != 10)) { new_one = true; set_menu(10); } //vyber submenu if (left_just_pressed || esc_just_pressed) if (!handle_menu_click(cursor_pos / 100, g, esc_just_pressed)) return false; return true; }
bool menu::handle_menu_click(int item, game& g, int esc_just_pressed) { stringstream ss; int mapchosen = g.get_mapchosen(); int userchosen = g.get_userchosen(); int cp = g.get_campaign_status(); int tmp_cp; if (esc_just_pressed) item = -1; switch (menustatus) { //hlavni menu case 0: switch (item) { case 0: set_menu(1); break; case 1: set_menu(2); break; case 2: set_menu(3); break; case 3: g.create_map(); break; case 4: g.save_user(); g.save_game(); return false; case -1: set_menu(0); break; } break; //kampan case 1: switch (item) { case 0: //posuvnik nahoru camp_id--; if (camp_id < 0) camp_id = campaign.size() - 1; if (camp_id > g.get_campaign_status()) active = false; else active = true; camp = campaign[camp_id]; set_menu(1); break; case 1: //zkontroluje mozny pristup do dalsich levelu kampane if (camp_id > g.get_campaign_status()) set_menu(1); else { g.change_mapchosen(maplist_get_mapid(campaign[camp_id])); g.go_to_game(); new_one_plays = false; } break; case 2: //posuvnik dolu camp_id++; if (camp_id > campaign.size() - 1) camp_id = 0; if (camp_id > g.get_campaign_status()) active = false; else active = true; camp = campaign[camp_id]; set_menu(1); break; case -1: set_menu(0); break; } break; //samostatne mise mimo kampan case 2: switch (item) { case 0: set_menu(4); break; case 1: set_menu(5); break; case 2: set_menu(6); break; case 3: set_menu(7); break; case 4: g.go_to_game(); break; case 5: set_menu(0); break; case -1: set_menu(0); break; } break; //nastaveni case 3: switch (item) { case 0: set_menu(8); break; case 1: set_menu(9); break; case 2: set_menu(0); break; case -1: set_menu(0); break; } break; //vyber mapy case 4: switch (item) { case 0: //posuvnik nahoru mapchosen--; if (mapchosen < 0) mapchosen = maplist_count() - 1; mapname = maplist_get_name(mapchosen); while (mapname[0] == 'm') { ss.clear(); ss << mapname[mapname.length() - 1]; ss >> tmp_cp; if (tmp_cp > cp) { mapchosen--; if (mapchosen < 0) mapchosen = maplist_count() - 1; mapname = maplist_get_name(mapchosen); } else break; } g.change_mapchosen(mapchosen); set_menu(4); break; case 1: set_menu(2); break; case 2: //posuvnik dolu mapchosen++; if (mapchosen > maplist_count() - 1) mapchosen = 0; mapname = maplist_get_name(mapchosen); while (mapname[0] == 'm') { ss.clear(); ss << mapname[mapname.length() - 1]; ss >> tmp_cp; if (tmp_cp > cp) { mapchosen++; if (mapchosen > maplist_count() - 1) mapchosen = 0; mapname = maplist_get_name(mapchosen); } else break; } g.change_mapchosen(mapchosen); set_menu(4); break; case -1: set_menu(2); break; } break; //denni doba case 5: switch (item) { case 0: //posuvnik nahoru dayt_id--; if (dayt_id < 0) dayt_id = daytime.size() - 1; g.change_daytime(dayt_id); dayt = daytime[dayt_id]; set_menu(5); break; case 1: set_menu(2); break; case 2: //posuvnik dolu dayt_id++; if (dayt_id > daytime.size() - 1) dayt_id = 0; g.change_daytime(dayt_id); dayt = daytime[dayt_id]; set_menu(5); break; case -1: set_menu(2); break; } break; //pocasi case 6: switch (item) { case 0: //posuvnik nahoru weat_id--; if (weat_id < 0) weat_id = weather.size() - 1; g.change_weather(weat_id); weat = weather[weat_id]; set_menu(6); break; case 1: set_menu(2); break; case 2: //posuvnik dolu weat_id++; if (weat_id > weather.size() - 1) weat_id = 0; g.change_weather(weat_id); weat = weather[weat_id]; set_menu(6); break; case -1: set_menu(2); break; } break; //obtiznost hry case 7: switch (item) { case 0: //posuvnik nahoru diff_id--; if (diff_id < 0) diff_id = difficulty.size() - 1; g.change_difficulty(diff_id); diff = difficulty[diff_id]; set_menu(7); break; case 1: set_menu(2); break; case 2: //posuvnik dolu diff_id++; if (diff_id > difficulty.size() - 1) diff_id = 0; g.change_difficulty(diff_id); diff = difficulty[diff_id]; set_menu(7); break; case -1: set_menu(2); break; } break; //hrac case 8: switch (item) { case 0: //pred spustenim randomizeru jmen - prazdno name = ""; set_menu(10); break; case 1: set_menu(11); break; case 2: set_menu(3); break; case -1: set_menu(3); break; } break; //nastaveni mysi case 9: switch (item) { case 0: //posuvnik nahoru sens_id--; if (sens_id < 0) sens_id = sensitivities.size() - 1; g.change_sensitivity(sens_id); sens = sensitivities[sens_id]; set_menu(9); break; case 1: set_menu(3); break; case 2: //posuvnik dolu sens_id++; if (sens_id > sensitivities.size() - 1) sens_id = 0; g.change_sensitivity(sens_id); sens = sensitivities[sens_id]; set_menu(9); break; case -1: set_menu(3); break; } break; //novy hrac case 10: switch (item) { case 0: //vygeneruje jmeno pro noveho hrace name = get_random_name(1); set_menu(10); break; case 2: //kontrola pro nevygenerovane jmeno if (name == "") set_menu(10); else { //pri zvoleni jmena, zaridi vse potrebne g.save_user(); g.change_userchosen(make_user(name)); username = name; if (new_one) { set_menu(0); new_one = false; new_one_plays = true; } else set_menu(8); } break; case -1: set_menu(8); break; } break; //vyber accountu case 11: switch (item) { case 0: //posuvnik nahoru g.save_user(); userchosen--; if (userchosen < 0) userchosen = userlist_count() - 1; g.change_userchosen(userchosen); username = userlist_get_name(userchosen); set_menu(11); break; case 1: //jmeno uctu k vyberu if (username == "") set_menu(11); else set_menu(8); break; case 2: //posuvnik dolu g.save_user(); userchosen++; if (userchosen > userlist_count() - 1) userchosen = 0; g.change_userchosen(userchosen); username = userlist_get_name(userchosen); set_menu(11); break; case -1: set_menu(8); break; } break; //vitezny screen case 12: set_menu(0); if (item == -1) set_menu(0); break; //prohrany screen case 13: set_menu(0); if (item == -1) set_menu(0); break; //menu po zmackuti Esc ze hry case 14: switch(item) { case 0: g.go_back_to_game(); break; case 1: set_menu(0); break; } } return true; }