- Menu::set_current(main_menu);
- while (Menu::current())
- {
- // if we spent to much time on a menu entry
- if( (update_time - last_update_time) > 1000)
- update_time = last_update_time = st_get_ticks();
-
- // Calculate the movement-factor
- double frame_ratio = ((double)(update_time-last_update_time))/((double)FRAME_RATE);
- if(frame_ratio > 1.5) /* Quick hack to correct the unprecise CPU clocks a little bit. */
- frame_ratio = 1.5 + (frame_ratio - 1.5) * 0.85;
- /* Lower the frame_ratio that Tux doesn't jump to hectically throught the demo. */
- frame_ratio /= 2;
-
- SDL_Event event;
- while (SDL_PollEvent(&event))
- {
- if (Menu::current())
- {
- Menu::current()->event(event);
- }
- // FIXME: QUIT signal should be handled more generic, not locally
- if (event.type == SDL_QUIT)
- Menu::set_current(0);
- }
-
- /* Draw the background: */
- draw_background();
- draw_demo(&session, frame_ratio);
-
- if (Menu::current() == main_menu)
- logo->draw( 160, 30);
-
- /* Don't draw menu, if quit is true */
- Menu* menu = Menu::current();
- if(menu)
- {
- menu->draw();
- menu->action();
-
- if(menu == main_menu)
- {
- switch (main_menu->check())
- {
- case MNID_STARTGAME:
- // Start Game, ie. goto the slots menu
- update_load_save_game_menu(load_game_menu);
- break;
- case MNID_CONTRIB:
- // Contrib Menu
- puts("Entering contrib menu");
- generate_contrib_menu();
- break;
- case MNID_LEVELEDITOR:
- leveleditor(1);
- Menu::set_current(main_menu);
- break;
- case MNID_CREDITS:
- display_text_file("CREDITS", bkg_title, SCROLL_SPEED_CREDITS);
- Menu::set_current(main_menu);
- break;
- case MNID_QUITMAINMENU:
- Menu::set_current(0);
- break;
- }
- }
- else if(menu == options_menu)
- {
- process_options_menu();
- }
- else if(menu == load_game_menu)
- {
- if(event.key.keysym.sym == SDLK_DELETE)
- {
- int slot = menu->get_active_item_id();
- char str[1024];
- sprintf(str,"Are you sure you want to delete slot %d?", slot);
-
- draw_background();
-
- if(confirm_dialog(str))
- {
- sprintf(str,"%s/slot%d.stsg", st_save_dir, slot);
- printf("Removing: %s\n",str);
- remove(str);
- }
-
- update_load_save_game_menu(load_game_menu);
- update_time = st_get_ticks();
- }
- else if (process_load_game_menu())
- {
- // FIXME: shouldn't be needed if GameSession doesn't relay on global variables
- // reset tux
- scroll_x = 0;
- //titletux.level_begin();
- update_time = st_get_ticks();
- }
- }
- else if(menu == contrib_menu)
- {
- check_contrib_menu();
- }
- else if (menu == contrib_subset_menu)
- {
- check_contrib_subset_menu();
- }
- }
-
- mouse_cursor->draw();
-
- flipscreen();
-
- /* Set the time of the last update and the time of the current update */
- last_update_time = update_time;
- update_time = st_get_ticks();
-
- /* Pause: */
- frame++;
- SDL_Delay(25);
- }
- /* Free surfaces: */