/** * Fade-in the wesnoth-logo. * * Animation-effect: scroll-in from right. \n * Used only once, after the game is started. * * @param screen surface to operate on * @param xpos x-position of logo * @param ypos y-position of logo * * @return Result of running the routine * @retval true operation finished (successful or not) * @retval false operation failed (because modeChanged), need to retry */ static bool fade_logo(game_display& screen, int xpos, int ypos) { const surface logo(image::get_image(game_config::game_logo)); if(logo == NULL) { ERR_DP << "Could not find game logo\n"; return true; } surface const fb = screen.video().getSurface(); if(fb == NULL || xpos < 0 || ypos < 0 || xpos + logo->w > fb->w || ypos + logo->h > fb->h) { return true; } // Only once, when the game is first started, the logo fades in unless // it was disabled in adv. preferences static bool faded_in = !preferences::startup_effect(); // static bool faded_in = true; // for faster startup: mark logo as 'has already faded in' CKey key; bool last_button = key[SDLK_ESCAPE] || key[SDLK_SPACE]; LOG_DP << "fading logo in....\n"; LOG_DP << "logo size: " << logo->w << "," << logo->h << "\n"; for(int x = 0; x != logo->w; ++x) { SDL_Rect srcrect = {x,0,1,logo->h}; SDL_Rect dstrect = {xpos+x,ypos,1,logo->h}; SDL_BlitSurface(logo,&srcrect,fb,&dstrect); update_rect(dstrect); if(!faded_in && (x%5) == 0) { const bool new_button = key[SDLK_ESCAPE] || key[SDLK_SPACE] || key[SDLK_RETURN] || key[SDLK_KP_ENTER] ; if(new_button && !last_button) { faded_in = true; } last_button = new_button; screen.update_display(); screen.delay(10); events::pump(); if(screen.video().modeChanged()) { faded_in = true; return false; } } } LOG_DP << "logo faded in\n"; faded_in = true; return true; }
TITLE_RESULT show_title(game_display& screen, config& tips_of_day) { disableTerrainCache(); free_all_caches(); cursor::set(cursor::NORMAL); const preferences::display_manager disp_manager(&screen); const hotkey::basic_handler key_handler(&screen); const font::floating_label_context label_manager; screen.video().modeChanged(); // resets modeChanged value // if (background_is_dirty_) { draw_background(screen); } //- Texts for the menu-buttons. //- Members of this array must correspond to the enumeration TITLE_RESULT static const char* button_labels[] = { //N_("TitleScreen button^Tutorial"), N_("TitleScreen button^Campaign"), #ifndef FREE_VERSION N_("TitleScreen button^Skirmish"), N_("TitleScreen button^Multiplayer"), #endif N_("TitleScreen button^Load"), // N_("TitleScreen button^Add-ons"), //#ifndef DISABLE_EDITOR2 //N_("TitleScreen button^Map Editor"), //#endif //N_("TitleScreen button^Language"), N_("TitleScreen button^Preferences"), N_("Sync Saves"), #ifndef DISABLE_OPENFEINT N_("TitleScreen button^OpenFeint"), #endif N_("TitleScreen button^Help"), //N_("TitleScreen button^Quit"), // Only the above buttons go into the menu-frame // Next 2 buttons go into frame for the tip-of-the-day: N_("TitleScreen button^Previous"), N_("TitleScreen button^Next"), //N_("TitleScreen button^Help"), // Next entry is no button, but shown as a mail-icon instead: //N_("TitleScreen button^Help Wesnoth") }; //- Texts for the tooltips of the menu-buttons static const char* help_button_labels[] = { //N_("Start a tutorial to familiarize yourself with the game"), N_("Start a new single player campaign"), #ifndef FREE_VERSION N_("Play a single scenario against the AI"), N_("Play multiplayer (hotseat or Internet)"), #endif N_("Load a saved game"), // N_("Download usermade campaigns, eras, or map packs"), //#ifndef DISABLE_EDITOR2 //N_("Start the map editor"), //#endif //N_("Change the language"), N_("Configure the game's settings"), N_("Sync saved games"), #ifndef DISABLE_OPENFEINT N_("Launch the OpenFeint dashboard"), #endif N_("Show Battle for Wesnoth help"), //N_("Quit the game"), N_("Show next tip of the day"), //N_("Upload statistics") }; //static const size_t nbuttons = sizeof(button_labels)/sizeof(*button_labels); #ifdef FREE_VERSION int nbuttons = 10; #else int nbuttons = 8; #endif #ifdef DISABLE_OPENFEINT nbuttons--; #endif #ifndef __IPAD__ nbuttons--; // because help is off to the left now #endif int menu_xbase = CVideo::getx()-108-10; //380; //(game_config::title_buttons_x*screen.w())/1024; const int menu_xincr = 0; #ifdef USE_TINY_GUI //const int menu_ybase = 15; //(330*screen.h())/768 - 50; //15; const int menu_yincr = 36+5; //(35*3)/4;//15; const int menu_ybase = (screen.h() - (36+5)*nbuttons - 5) / 2 + 4; #else const int menu_ybase = (screen.h() - (36+5)*nbuttons - 5) / 2 + 4; const int menu_yincr = 36+5; #endif #ifdef __IPAD__ menu_xbase -= 10; #endif const int padding = 4; //game_config::title_buttons_padding; std::vector<button> buttons; size_t b, max_width = 0; size_t n_menubuttons = 0; for(b = 0; b != nbuttons; ++b) { //#ifdef __IPHONEOS__ // if (b + TUTORIAL == TUTORIAL || b + TUTORIAL == START_MAP_EDITOR || b+TUTORIAL == CHANGE_LANGUAGE) // continue; //#endif buttons.push_back(button(screen.video(),sgettext(button_labels[b]))); buttons.back().set_help_string(sgettext(help_button_labels[b])); max_width = std::max<size_t>(max_width,buttons.back().width()); n_menubuttons = b; #ifdef __IPAD__ if(b + NEW_CAMPAIGN == SHOW_HELP) break; #else if(b + NEW_CAMPAIGN == SHOW_OPENFEINT) break; #endif } SDL_Rect main_dialog_area = {menu_xbase-padding, menu_ybase-padding, max_width+padding*2, menu_yincr*(n_menubuttons)+buttons.back().height()+padding*2}; gui::dialog_frame main_frame(screen.video(), "", gui::dialog_frame::titlescreen_style, false); main_frame.layout(main_dialog_area); // we only redraw transparent parts when asked, // to prevent alpha growing if (background_is_dirty_) { main_frame.draw_background(); main_frame.draw_border(); } int i=0; for(b = 0; b != nbuttons; ++b) { //#ifdef __IPHONEOS__ // if (b + TUTORIAL == TUTORIAL || b + TUTORIAL == START_MAP_EDITOR || b+TUTORIAL == CHANGE_LANGUAGE) // continue; //#endif buttons[i].set_width(max_width); buttons[i].set_location(menu_xbase + i*menu_xincr, menu_ybase + i*menu_yincr); #ifdef __IPAD__ if(b + NEW_CAMPAIGN == SHOW_HELP) break; #else if(b + NEW_CAMPAIGN == SHOW_OPENFEINT) break; #endif i++; } #ifndef __IPAD__ buttons.push_back(button(screen.video(),sgettext(button_labels[i+1]))); buttons.back().set_help_string(sgettext(help_button_labels[i+1])); buttons[i+1].set_width(max_width); buttons[i+1].set_location(5, 320-menu_yincr); #endif // b = TIP_PREVIOUS - NEW_CAMPAIGN; // gui::button previous_tip_button(screen.video(),sgettext(button_labels[b]),button::TYPE_PRESS,"lite_small"); // previous_tip_button.set_help_string( sgettext(button_labels[b] )); // b = TIP_NEXT - NEW_CAMPAIGN; // gui::button next_tip_button(screen.video(),sgettext(button_labels[b]),button::TYPE_PRESS,"lite_small"); // next_tip_button.set_help_string( sgettext(button_labels[b] )); // b = SHOW_HELP - NEW_CAMPAIGN; // gui::button help_tip_button(screen.video(),sgettext(button_labels[b]),button::TYPE_PRESS,"lite_small"); // help_tip_button.set_help_string( sgettext(button_labels[b] )); // gui::button beg_button(screen.video(),_("Help Wesnoth"),button::TYPE_IMAGE,"menu-button",button::MINIMUM_SPACE); // beg_button.set_help_string(_("Help Wesnoth by sending us information")); // next_tip_of_day(tips_of_day); // surface_restorer tip_of_day_restorer; // draw_tip_of_day(screen, tips_of_day, gui::dialog_frame::titlescreen_style, // &previous_tip_button, &next_tip_button, NULL/*&help_tip_button*/, &main_dialog_area, tip_of_day_restorer); // const int pad = game_config::title_tip_padding; // beg_button.set_location(screen.w() - pad - beg_button.location().w, // screen.h() - pad - beg_button.location().h); events::raise_draw_event(); LOG_DP << "drew buttons dialog\n"; // draw logo over everything #ifdef __IPAD__ std::string path = game_config::path + "/data/core/images/misc/logo.png"; #else std::string path = game_config::path + "/data/core/images/misc/logo_small.png"; #endif surface logo_surface = IMG_Load(path.c_str()); //blit_surface(480-logo_surface.get()->w, 0, logo_surface); CKey key; size_t keyboard_button = nbuttons; bool key_processed = false; // update_whole_screen(); background_is_dirty_ = false; titlescreen_handler ts_handler(key[SDLK_ESCAPE] != 0); //!= 0 to avoid a MSVC warning C4800 LOG_DP << "entering interactive loop...\n"; memory_stats("At titlescreen"); // Initialize OpenFeint now of_init(); for(;;) { events::pump(); for(size_t b = 0; b != buttons.size(); ++b) { if(buttons[b].pressed()) { free_title(); return static_cast<TITLE_RESULT>(b + NEW_CAMPAIGN); } } /* if(previous_tip_button.pressed()) { next_tip_of_day(tips_of_day, true); draw_tip_of_day(screen, tips_of_day, gui::dialog_frame::titlescreen_style, &previous_tip_button, &next_tip_button, &help_tip_button, &main_dialog_area, tip_of_day_restorer); } if(next_tip_button.pressed()) { next_tip_of_day(tips_of_day, false); draw_tip_of_day(screen, tips_of_day, gui::dialog_frame::titlescreen_style, &previous_tip_button, &next_tip_button, &help_tip_button, &main_dialog_area, tip_of_day_restorer); } */ // if(help_tip_button.pressed()) { // return SHOW_HELP; // } // if(beg_button.pressed()) { // return BEG_FOR_UPLOAD; // } if (key[SDLK_UP]) { if (!key_processed) { buttons[keyboard_button].set_active(false); if (keyboard_button == 0) { keyboard_button = nbuttons - 1; } else { keyboard_button--; } key_processed = true; buttons[keyboard_button].set_active(true); } } else if (key[SDLK_DOWN]) { if (!key_processed) { buttons[keyboard_button].set_active(false); if (keyboard_button > nbuttons - 1) { keyboard_button = 0; } else { keyboard_button++; } key_processed = true; buttons[keyboard_button].set_active(true); } } else { key_processed = false; } events::raise_process_event(); // KP: redraw draw_background(screen); main_frame.draw_background(); main_frame.draw_border(); events::raise_draw_event(); //blit_surface(480-logo_surface.get()->w, 0, logo_surface); #ifdef __IPAD__ blit_surface(-10, 0, logo_surface); #else blit_surface(-15, -10, logo_surface); #endif screen.flip(); // if (key[SDLK_ESCAPE] && !ts_handler.get_esc_ignore()) // return QUIT_GAME; if (key[SDLK_F5]) return RELOAD_GAME_DATA; if (key[SDLK_RETURN] && keyboard_button < nbuttons) { return static_cast<TITLE_RESULT>(keyboard_button + NEW_CAMPAIGN); } // If the resolution has changed due to the user resizing the screen, // or from changing between windowed and fullscreen: if(screen.video().modeChanged()) { return REDRAW_BACKGROUND; } screen.delay(10); } free_title(); return REDRAW_BACKGROUND; }