Example #1
0
static int save_state() {
	FCEUI_SaveState(NULL);
	save_preview();
	return 0;
}
Example #2
0
std::string load_game_dialog(display& disp, const config& game_config, bool* show_replay, bool* cancel_orders)
{
	std::vector<savegame::save_info> games;
	{
		cursor::setter cur(cursor::WAIT);
		games = savegame::manager::get_saves_list();
	}

	if(games.empty()) {
		gui2::show_transient_message(disp.video(),
		                 _("No Saved Games"),
				 _("There are no saved games to load.\n\n(Games are saved automatically when you complete a scenario)"));
		return "";
	}

	std::vector<config*> summaries;
	std::vector<savegame::save_info>::const_iterator i;
	//FIXME: parent_to_child is not used yet
	std::map<std::string,std::string> parent_to_child;
	for(i = games.begin(); i != games.end(); ++i) {
		config& cfg = savegame::save_index::save_summary(i->name);
		parent_to_child[cfg["parent"]] = i->name;
		summaries.push_back(&cfg);
	}

	const events::event_context context;

	std::vector<std::string> items;
	std::ostringstream heading;
	heading << HEADING_PREFIX << _("Name") << COLUMN_SEPARATOR << _("Date");
	items.push_back(heading.str());

	for(i = games.begin(); i != games.end(); ++i) {
		std::string name = i->name;
		utils::truncate_as_wstring(name, std::min<size_t>(name.size(), 40));

		std::ostringstream str;
		str << name << COLUMN_SEPARATOR << format_time_summary(i->time_modified);

		items.push_back(str.str());
	}

	gamemap map_obj(game_config, "");


	gui::dialog lmenu(disp,
			  _("Load Game"),
			  _("Choose the game to load"), gui::NULL_DIALOG);
	lmenu.set_basic_behavior(gui::OK_CANCEL);

	gui::menu::basic_sorter sorter;
	sorter.set_alpha_sort(0).set_id_sort(1);
	lmenu.set_menu(items, &sorter);

	gui::filter_textbox* filter = new gui::filter_textbox(disp.video(), _("Filter: "), items, items, 1, lmenu);
	lmenu.set_textbox(filter);

	save_preview_pane save_preview(disp.video(),game_config,&map_obj,games,summaries,*filter);
	lmenu.add_pane(&save_preview);
	// create an option for whether the replay should be shown or not
//	if(show_replay != NULL) {
//		lmenu.add_option(_("Show replay"), false,
//			// use smallgui layout as default, otherwise the load screen glitches at low res!
//			//game_config::small_gui ? gui::dialog::BUTTON_CHECKBOX : gui::dialog::BUTTON_STANDARD);
//			gui::dialog::BUTTON_CHECKBOX);
//	}
	if(cancel_orders != NULL) {
		lmenu.add_option(_("Cancel orders"), false,
			// use smallgui layout as default, otherwise the load screen glitches at low res!
			//game_config::small_gui ? gui::dialog::BUTTON_STANDARD : gui::dialog::BUTTON_EXTRA);
			gui::dialog::BUTTON_STANDARD);
	}
	lmenu.add_button(new gui::standard_dialog_button(disp.video(),_("OK"),0,false), gui::dialog::BUTTON_STANDARD);
	lmenu.add_button(new gui::standard_dialog_button(disp.video(),_("Cancel"),1,true), gui::dialog::BUTTON_STANDARD);

	delete_save save_deleter(disp,*filter,games,summaries);
	gui::dialog_button_info delete_button(&save_deleter,_("Delete Save"));

	lmenu.add_button(delete_button,
		// use smallgui layout as default, otherwise the load screen glitches at low res!
		//game_config::small_gui ? gui::dialog::BUTTON_HELP : gui::dialog::BUTTON_EXTRA);
		gui::dialog::BUTTON_HELP);

	int res = lmenu.show();

	savegame::save_index::write_save_index();

	if(res == -1)
		return "";

	res = filter->get_index(res);
	int option_index = 0;
	if(show_replay != NULL) {
	  *show_replay = lmenu.option_checked(option_index++);

		const config& summary = *summaries[res];
		if (summary["replay"].to_bool() && !summary["snapshot"].to_bool(true)) {
			*show_replay = true;
		}
	}
	if (cancel_orders != NULL) {
		*cancel_orders = lmenu.option_checked(option_index++);
	}

	return games[res].name;
}