/** * Open a help dialog using a toplevel other than the default. * * This allows for complete customization of the contents, although not in a * very easy way. */ void show_help(display &disp, const section &toplevel_sec, const std::string& show_topic, int xloc, int yloc) { const events::event_context dialog_events_context; const gui::dialog_manager manager; const resize_lock prevent_resizing; CVideo& screen = disp.video(); const surface& scr = screen.getSurface(); const int width = std::min<int>(font::relative_size(1000), scr->w - font::relative_size(20)); const int height = std::min<int>(font::relative_size(800), scr->h - font::relative_size(150)); const int left_padding = font::relative_size(10); const int right_padding = font::relative_size(10); const int top_padding = font::relative_size(10); const int bot_padding = font::relative_size(10); // If not both locations were supplied, put the dialog in the middle // of the screen. if (yloc <= -1 || xloc <= -1) { xloc = scr->w / 2 - width / 2; yloc = scr->h / 2 - height / 2; } std::vector<gui::button*> buttons_ptr; gui::button close_button_(disp.video(), _("Close")); buttons_ptr.push_back(&close_button_); gui::dialog_frame f(disp.video(), _("The Battle for Wesnoth Help"), gui::dialog_frame::default_style, true, &buttons_ptr); f.layout(xloc, yloc, width, height); f.draw(); // Find all unit_types that have not been constructed yet and fill in the information // needed to create the help topics unit_types.build_all(unit_type::HELP_INDEXED); if (preferences::encountered_units().size() != size_t(last_num_encountered_units) || preferences::encountered_terrains().size() != size_t(last_num_encountered_terrains) || last_debug_state != game_config::debug || last_num_encountered_units < 0) { // More units or terrains encountered, update the contents. last_num_encountered_units = preferences::encountered_units().size(); last_num_encountered_terrains = preferences::encountered_terrains().size(); last_debug_state = game_config::debug; generate_contents(); } try { help_browser hb(disp, toplevel_sec); hb.set_location(xloc + left_padding, yloc + top_padding); hb.set_width(width - left_padding - right_padding); hb.set_height(height - top_padding - bot_padding); if (show_topic != "") { hb.show_topic(show_topic); } else { hb.show_topic(default_show_topic); } hb.set_dirty(true); events::raise_draw_event(); disp.flip(); disp.invalidate_all(); CKey key; for (;;) { events::pump(); events::raise_process_event(); events::raise_draw_event(); if (key[SDLK_ESCAPE]) { // Escape quits from the dialog. return; } for (std::vector<gui::button*>::iterator button_it = buttons_ptr.begin(); button_it != buttons_ptr.end(); ++button_it) { if ((*button_it)->pressed()) { // There is only one button, close. return; } } disp.flip(); disp.delay(10); } } catch (parse_error& e) { std::stringstream msg; msg << _("Parse error when parsing help text: ") << "'" << e.message << "'"; gui2::show_transient_message(disp.video(), "", msg.str()); } }