made it display date/time accessed next to save games, ...
...and order save games by date/time accessed
This commit is contained in:
parent
0f99a4a097
commit
2582c90457
5 changed files with 60 additions and 35 deletions
|
@ -15,9 +15,12 @@
|
|||
#include "language.hpp"
|
||||
#include "replay.hpp"
|
||||
#include "show_dialog.hpp"
|
||||
#include "util.hpp"
|
||||
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <time.h>
|
||||
#include <vector>
|
||||
|
||||
namespace dialogs
|
||||
|
@ -116,7 +119,7 @@ int get_save_name(display & disp,const std::string& caption, const std::string&
|
|||
|
||||
std::string load_game_dialog(display& disp, bool* show_replay)
|
||||
{
|
||||
const std::vector<std::string>& games = get_saves_list();
|
||||
const std::vector<save_info>& games = get_saves_list();
|
||||
|
||||
if(games.empty()) {
|
||||
gui::show_dialog(disp,NULL,
|
||||
|
@ -126,6 +129,16 @@ std::string load_game_dialog(display& disp, bool* show_replay)
|
|||
return "";
|
||||
}
|
||||
|
||||
std::vector<std::string> items;
|
||||
for(std::vector<save_info>::const_iterator i = games.begin(); i != games.end(); ++i) {
|
||||
std::string name = i->name;
|
||||
name.resize(minimum<size_t>(name.size(),40));
|
||||
|
||||
std::stringstream str;
|
||||
str << name << "," << ::ctime(&(i->time_modified));
|
||||
items.push_back(str.str());
|
||||
}
|
||||
|
||||
//create an option for whether the replay should be shown or not
|
||||
std::vector<gui::check_item> options;
|
||||
|
||||
|
@ -135,7 +148,7 @@ std::string load_game_dialog(display& disp, bool* show_replay)
|
|||
const int res = gui::show_dialog(disp,NULL,
|
||||
string_table["load_game_heading"],
|
||||
string_table["load_game_message"],
|
||||
gui::OK_CANCEL,&games,NULL,"",NULL,NULL,&options);
|
||||
gui::OK_CANCEL,&items,NULL,"",NULL,NULL,&options);
|
||||
|
||||
if(res == -1)
|
||||
return "";
|
||||
|
@ -143,7 +156,7 @@ std::string load_game_dialog(display& disp, bool* show_replay)
|
|||
if(show_replay != NULL)
|
||||
*show_replay = options.front().checked;
|
||||
|
||||
return games[res];
|
||||
return games[res].name;
|
||||
}
|
||||
|
||||
} //end namespace dialogs
|
||||
|
|
|
@ -153,17 +153,36 @@ void write_game(const game_state& game, config& cfg)
|
|||
cfg.children["start"].push_back(new config(game.starting_pos));
|
||||
}
|
||||
|
||||
std::vector<std::string> get_saves_list()
|
||||
//a structure for comparing to save_info objects based on their modified time.
|
||||
//if the times are equal, will order based on the name
|
||||
struct save_info_less_time {
|
||||
bool operator()(const save_info& a, const save_info& b) const {
|
||||
return a.time_modified > b.time_modified ||
|
||||
a.time_modified == b.time_modified && a.name > b.name;
|
||||
}
|
||||
};
|
||||
|
||||
std::vector<save_info> get_saves_list()
|
||||
{
|
||||
std::vector<std::string> res;
|
||||
get_files_in_dir(get_saves_dir(),&res);
|
||||
for(std::vector<std::string>::iterator i = res.begin(); i != res.end(); ++i)
|
||||
const std::string& saves_dir = get_saves_dir();
|
||||
|
||||
std::vector<std::string> saves;
|
||||
get_files_in_dir(saves_dir,&saves);
|
||||
|
||||
std::vector<save_info> res;
|
||||
for(std::vector<std::string>::iterator i = saves.begin(); i != saves.end(); ++i) {
|
||||
const time_t modified = file_last_access(saves_dir + "/" + *i);
|
||||
|
||||
std::replace(i->begin(),i->end(),'_',' ');
|
||||
res.push_back(save_info(*i,modified));
|
||||
}
|
||||
|
||||
std::sort(res.begin(),res.end(),save_info_less_time());
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
bool save_game_exists(const std::string & name)
|
||||
bool save_game_exists(const std::string& name)
|
||||
{
|
||||
std::string fname = name;
|
||||
std::replace(fname.begin(),fname.end(),' ','_');
|
||||
|
|
|
@ -100,8 +100,15 @@ struct game_state
|
|||
config starting_pos;
|
||||
};
|
||||
|
||||
struct save_info {
|
||||
save_info(const std::string& n, time_t t) : name(n), time_modified(t) {}
|
||||
std::string name;
|
||||
time_t time_modified;
|
||||
};
|
||||
|
||||
//function to get a list of available saves.
|
||||
std::vector<std::string> get_saves_list();
|
||||
std::vector<save_info> get_saves_list();
|
||||
|
||||
// function returns true iff there is already savegame with that name
|
||||
bool save_game_exists(const std::string & name);
|
||||
|
||||
|
|
|
@ -385,26 +385,16 @@ int play_multiplayer(display& disp, game_data& units_data, config cfg,
|
|||
if(res == -1)
|
||||
break;
|
||||
|
||||
bool show_replay = false;
|
||||
|
||||
//if we're loading a saved game
|
||||
config loaded_level;
|
||||
if(size_t(res) == options.size()-1) {
|
||||
const std::vector<std::string>& games = get_saves_list();
|
||||
if(games.empty()) {
|
||||
gui::show_dialog(disp,NULL,
|
||||
string_table["no_saves_heading"],
|
||||
string_table["no_saves_message"],
|
||||
gui::OK_ONLY);
|
||||
break;
|
||||
}
|
||||
|
||||
const int res = gui::show_dialog(disp,NULL,
|
||||
string_table["load_game_heading"],
|
||||
string_table["load_game_message"],
|
||||
gui::OK_CANCEL, &games);
|
||||
if(res == -1)
|
||||
const std::string game = dialogs::load_game_dialog(disp,&show_replay);
|
||||
if(game == "")
|
||||
break;
|
||||
|
||||
load_game(units_data,games[res],state);
|
||||
load_game(units_data,game,state);
|
||||
|
||||
if(state.campaign_type != "multiplayer") {
|
||||
gui::show_dialog(disp,NULL,"",
|
||||
|
@ -724,13 +714,9 @@ int play_multiplayer(display& disp, game_data& units_data, config cfg,
|
|||
|
||||
recorder.set_save_info(state);
|
||||
|
||||
//see if we should show the replay of the game so far
|
||||
if(!recorder.empty()) {
|
||||
const int res = gui::show_dialog(disp,NULL,
|
||||
"", string_table["replay_game_message"],
|
||||
gui::YES_NO);
|
||||
//if yes, then show the replay, otherwise
|
||||
//skip showing the replay
|
||||
if(res == 0) {
|
||||
if(show_replay) {
|
||||
recorder.set_skip(0);
|
||||
} else {
|
||||
std::cerr << "skipping...\n";
|
||||
|
|
|
@ -206,7 +206,7 @@ void turn_info::handle_event(const SDL_Event& event)
|
|||
if(u != units_.end() && (u->second.side() == team_num_ || gui_.fogged(u->first.x,u->first.y))) {
|
||||
u = units_.end();
|
||||
}
|
||||
} else if(u->second.side() != team_num_) {
|
||||
} else if(u->second.side() != team_num_ || gui_.fogged(u->first.x,u->first.y)) {
|
||||
u = units_.end();
|
||||
}
|
||||
|
||||
|
@ -285,7 +285,7 @@ void turn_info::mouse_motion(const SDL_MouseMotionEvent& event)
|
|||
const unit_map::iterator un = units_.find(new_hex);
|
||||
|
||||
if(un != units_.end() && un->second.side() != team_num_ &&
|
||||
current_paths_.routes.empty()) {
|
||||
current_paths_.routes.empty() && !gui_.fogged(un->first.x,un->first.y)) {
|
||||
unit_movement_resetter move_reset(un->second);
|
||||
|
||||
const bool ignore_zocs = un->second.type().is_skirmisher();
|
||||
|
@ -545,7 +545,7 @@ void turn_info::left_click(const SDL_MouseButtonEvent& event)
|
|||
gui_.set_route(NULL);
|
||||
|
||||
const unit_map::iterator it = units_.find(hex);
|
||||
if(it != units_.end() && it->second.side() == team_num_) {
|
||||
if(it != units_.end() && it->second.side() == team_num_ && !gui_.fogged(it->first.x,it->first.y)) {
|
||||
const bool ignore_zocs = it->second.type().is_skirmisher();
|
||||
const bool teleport = it->second.type().teleports();
|
||||
current_paths_ = paths(map_,gameinfo_,units_,hex,teams_,
|
||||
|
@ -682,7 +682,7 @@ void turn_info::cycle_units()
|
|||
}
|
||||
}
|
||||
|
||||
if(it != units_.end()) {
|
||||
if(it != units_.end() && !gui_.fogged(it->first.x,it->first.y)) {
|
||||
const bool ignore_zocs = it->second.type().is_skirmisher();
|
||||
const bool teleport = it->second.type().teleports();
|
||||
current_paths_ = paths(map_,gameinfo_,units_,
|
||||
|
|
Loading…
Add table
Reference in a new issue