zamotivator

Untitled

Feb 4th, 2012
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.64 KB | None | 0 0
  1. std::string load_game_dialog(display& disp, const config& game_config, bool* show_replay, bool* cancel_orders)
  2. {
  3. std::vector<savegame::save_info> games;
  4. {
  5. cursor::setter cur(cursor::WAIT);
  6. games = savegame::manager::get_saves_list();
  7. }
  8.  
  9. if(games.empty()) {
  10. gui2::show_transient_message(disp.video(),
  11. _("No Saved Games"),
  12. _("There are no saved games to load.\n\n(Games are saved automatically when you complete a scenario)"));
  13. return "";
  14. }
  15.  
  16. std::vector<config*> summaries;
  17. std::vector<savegame::save_info>::const_iterator i;
  18. //FIXME: parent_to_child is not used yet
  19. std::map<std::string,std::string> parent_to_child;
  20. for(i = games.begin(); i != games.end(); ++i) {
  21. config& cfg = savegame::save_index::save_summary(i->name);
  22. parent_to_child[cfg["parent"]] = i->name;
  23. summaries.push_back(&cfg);
  24. }
  25.  
  26. const events::event_context context;
  27.  
  28. std::vector<std::string> items;
  29. std::ostringstream heading;
  30. heading << HEADING_PREFIX << _("Name") << COLUMN_SEPARATOR << _("Date");
  31. items.push_back(heading.str());
  32.  
  33. for(i = games.begin(); i != games.end(); ++i) {
  34. std::string name = i->name;
  35. utils::truncate_as_wstring(name, std::min<size_t>(name.size(), 40));
  36.  
  37. std::ostringstream str;
  38. str << name << COLUMN_SEPARATOR << format_time_summary(i->time_modified);
  39.  
  40. items.push_back(str.str());
  41. }
  42.  
  43. gamemap map_obj(game_config, "");
  44.  
  45.  
  46. gui::dialog lmenu(disp,
  47. _("Load Game"),
  48. _("Choose the game to load"), gui::NULL_DIALOG);
  49. lmenu.set_basic_behavior(gui::OK_CANCEL);
  50.  
  51. gui::menu::basic_sorter sorter;
  52. sorter.set_alpha_sort(0).set_id_sort(1);
  53. lmenu.set_menu(items, &sorter);
  54.  
  55. gui::filter_textbox* filter = new gui::filter_textbox(disp.video(), _("Filter: "), items, items, 1, lmenu);
  56. lmenu.set_textbox(filter);
  57.  
  58. save_preview_pane save_preview(disp.video(),game_config,&map_obj,games,summaries,*filter);
  59. lmenu.add_pane(&save_preview);
  60. // create an option for whether the replay should be shown or not
  61. if(show_replay != NULL) {
  62. lmenu.add_option(_("Show replay"), false,
  63. // use smallgui layout as default, otherwise the load screen glitches at low res!
  64. //game_config::small_gui ? gui::dialog::BUTTON_CHECKBOX : gui::dialog::BUTTON_STANDARD);
  65. gui::dialog::BUTTON_CHECKBOX);
  66. }
  67. if(cancel_orders != NULL) {
  68. lmenu.add_option(_("Cancel orders"), false,
  69. // use smallgui layout as default, otherwise the load screen glitches at low res!
  70. //game_config::small_gui ? gui::dialog::BUTTON_STANDARD : gui::dialog::BUTTON_EXTRA);
  71. gui::dialog::BUTTON_STANDARD);
  72. }
  73. lmenu.add_button(new gui::standard_dialog_button(disp.video(),_("OK"),0,false), gui::dialog::BUTTON_STANDARD);
  74. lmenu.add_button(new gui::standard_dialog_button(disp.video(),_("Cancel"),1,true), gui::dialog::BUTTON_STANDARD);
  75.  
  76. delete_save save_deleter(disp,*filter,games,summaries);
  77. gui::dialog_button_info delete_button(&save_deleter,_("Delete Save"));
  78.  
  79. lmenu.add_button(delete_button,
  80. // use smallgui layout as default, otherwise the load screen glitches at low res!
  81. //game_config::small_gui ? gui::dialog::BUTTON_HELP : gui::dialog::BUTTON_EXTRA);
  82. gui::dialog::BUTTON_HELP);
  83.  
  84. int res = lmenu.show();
  85.  
  86. savegame::save_index::write_save_index();
  87.  
  88. if(res == -1)
  89. return "";
  90.  
  91. res = filter->get_index(res);
  92. int option_index = 0;
  93. if(show_replay != NULL) {
  94. *show_replay = lmenu.option_checked(option_index++);
  95.  
  96. const config& summary = *summaries[res];
  97. if (summary["replay"].to_bool() && !summary["snapshot"].to_bool(true)) {
  98. *show_replay = true;
  99. }
  100. }
  101. if (cancel_orders != NULL) {
  102. *cancel_orders = lmenu.option_checked(option_index++);
  103. }
  104.  
  105. return games[res].name;
  106. }
Advertisement
Add Comment
Please, Sign In to add comment