void free_menu(struct Menu * menu){ free_title(menu->titles); free(menu->position); free(menu->bg_picture); free(menu); menu=NULL; }
void frame_recalc_bar(WFrame *frame, bool complete) { int textw, i; WLListIterTmp tmp; WRegion *sub; char *title; bool set_shape; if(frame->bar_brush==NULL || frame->titles==NULL) return; set_shape=frame->tabs_params.alg(frame,complete); if(set_shape) { if(frame->barmode==FRAME_BAR_SHAPED) frame_set_shape(frame); else frame_clear_shape(frame); } i=0; if(FRAME_MCOUNT(frame)==0){ free_title(frame, i); textw=frame->titles[i].iw; if(textw>0){ title=grbrush_make_label(frame->bar_brush, TR("<empty frame>"), textw); frame->titles[i].text=title; } return; } FRAME_MX_FOR_ALL(sub, frame, tmp){ free_title(frame, i); textw=frame->titles[i].iw; if(textw>0){ title=region_make_label(sub, textw, frame->bar_brush); frame->titles[i].text=title; } i++; }
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; }