Load-game dialog: Cleaning up and adding leader image support.
This commit is contained in:
parent
fb7ecaead6
commit
cc1aa93ca3
7 changed files with 488 additions and 435 deletions
|
@ -1,338 +1,359 @@
|
|||
#textdomain wesnoth-lib
|
||||
###
|
||||
### Definition of the window to ask for the savegame filename
|
||||
###
|
||||
|
||||
[window]
|
||||
id = "game_load"
|
||||
description = "Load game dialog."
|
||||
|
||||
[resolution]
|
||||
definition = "default"
|
||||
|
||||
automatic_placement = "true"
|
||||
vertical_placement = "top"
|
||||
horizontal_placement = "center"
|
||||
|
||||
[grid]
|
||||
|
||||
[row]
|
||||
grow_factor = 0
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_alignment = "left"
|
||||
[label]
|
||||
id = "lblTitle"
|
||||
definition = "title"
|
||||
|
||||
label = _ "Load Game"
|
||||
[/label]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[row]
|
||||
grow_factor = 1
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
|
||||
horizontal_grow = "true"
|
||||
|
||||
[grid]
|
||||
|
||||
[row]
|
||||
grow_factor = 1
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
|
||||
border = "all"
|
||||
border_size = 5
|
||||
vertical_alignment = "top"
|
||||
|
||||
[grid]
|
||||
|
||||
[row]
|
||||
grow_factor = 1
|
||||
|
||||
|
||||
[column]
|
||||
|
||||
grow_factor = 1
|
||||
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_alignment = "right"
|
||||
|
||||
[minimap]
|
||||
id = "minimap"
|
||||
definition = "default"
|
||||
[/minimap]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[row]
|
||||
|
||||
[column]
|
||||
|
||||
grow_factor = 1
|
||||
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_alignment = "left"
|
||||
|
||||
[label]
|
||||
id = "lblScenario"
|
||||
definition = "default"
|
||||
|
||||
label = " "
|
||||
[/label]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[row]
|
||||
|
||||
[column]
|
||||
|
||||
grow_factor = 1
|
||||
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_alignment = "left"
|
||||
|
||||
[label]
|
||||
id = "lblSummary"
|
||||
definition = "default_small"
|
||||
|
||||
label = " "
|
||||
[/label]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[/grid]
|
||||
|
||||
[/column]
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_grow = "true"
|
||||
|
||||
[grid]
|
||||
|
||||
[row]
|
||||
[column]
|
||||
horizontal_alignment = "left"
|
||||
|
||||
[label]
|
||||
id = "lblChoose"
|
||||
definition = "choose"
|
||||
|
||||
label = _ "Choose the game to load"
|
||||
[/label]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[row]
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
horizontal_grow = "true"
|
||||
|
||||
border = "all"
|
||||
border_size = 5
|
||||
|
||||
[listbox]
|
||||
id = "savegame_list"
|
||||
definition = "default"
|
||||
|
||||
[header]
|
||||
|
||||
[row]
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
horizontal_grow = "true"
|
||||
|
||||
border = "all"
|
||||
border_size = 5
|
||||
|
||||
[label]
|
||||
id = "filename"
|
||||
definition = "default"
|
||||
|
||||
label = _ "Name"
|
||||
[/label]
|
||||
|
||||
[/column]
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
horizontal_grow = "true"
|
||||
|
||||
border = "all"
|
||||
border_size = 5
|
||||
|
||||
[label]
|
||||
id = "date"
|
||||
definition = "default"
|
||||
|
||||
label = _ "Date"
|
||||
[/label]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[/header]
|
||||
|
||||
[list_definition]
|
||||
|
||||
[row]
|
||||
|
||||
[column]
|
||||
|
||||
[toggle_panel]
|
||||
definition = "default"
|
||||
|
||||
return_value_id = "ok"
|
||||
[grid]
|
||||
|
||||
[row]
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
horizontal_grow = "true"
|
||||
|
||||
border = "all"
|
||||
border_size = 5
|
||||
|
||||
[label]
|
||||
id = "filename"
|
||||
definition = "default"
|
||||
[/label]
|
||||
|
||||
[/column]
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
horizontal_grow = "true"
|
||||
|
||||
border = "all"
|
||||
border_size = 5
|
||||
|
||||
[label]
|
||||
id = "date"
|
||||
definition = "default"
|
||||
[/label]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[/grid]
|
||||
|
||||
[/toggle_panel]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[/list_definition]
|
||||
|
||||
[/listbox]
|
||||
|
||||
[/column]
|
||||
[/row]
|
||||
|
||||
[/grid]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[/grid]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[row]
|
||||
grow_factor = 0
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
horizontal_grow = "true"
|
||||
|
||||
[grid]
|
||||
|
||||
[row]
|
||||
grow_factor = 0
|
||||
|
||||
[column]
|
||||
|
||||
[spacer]
|
||||
definition = "default"
|
||||
[/spacer]
|
||||
|
||||
[/column]
|
||||
|
||||
[column]
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_alignment = "right"
|
||||
|
||||
[button]
|
||||
id = "ok"
|
||||
definition = "default"
|
||||
|
||||
size_text = _ "OK"
|
||||
label = _ "OK"
|
||||
[/button]
|
||||
|
||||
[/column]
|
||||
|
||||
[column]
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_alignment = "right"
|
||||
|
||||
[button]
|
||||
id = "cancel"
|
||||
definition = "default"
|
||||
|
||||
label = _ "Cancel"
|
||||
[/button]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[/grid]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[/grid]
|
||||
|
||||
[/resolution]
|
||||
|
||||
[/window]
|
||||
|
||||
#textdomain wesnoth-lib
|
||||
###
|
||||
### Definition of the window to ask for the savegame filename
|
||||
###
|
||||
|
||||
[window]
|
||||
id = "game_load"
|
||||
description = "Load game dialog."
|
||||
|
||||
[resolution]
|
||||
definition = "default"
|
||||
|
||||
automatic_placement = "true"
|
||||
vertical_placement = "top"
|
||||
horizontal_placement = "center"
|
||||
|
||||
[grid]
|
||||
|
||||
[row]
|
||||
grow_factor = 0
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_alignment = "left"
|
||||
[label]
|
||||
id = "lblTitle"
|
||||
definition = "title"
|
||||
|
||||
label = _ "Load Game"
|
||||
[/label]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[row]
|
||||
grow_factor = 1
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
|
||||
horizontal_grow = "true"
|
||||
|
||||
[grid]
|
||||
|
||||
[row]
|
||||
grow_factor = 1
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
|
||||
border = "all"
|
||||
border_size = 5
|
||||
vertical_alignment = "top"
|
||||
|
||||
[grid]
|
||||
|
||||
[row]
|
||||
grow_factor = 1
|
||||
|
||||
[column]
|
||||
|
||||
[grid]
|
||||
|
||||
[row]
|
||||
grow_factor = 1
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
horizontal_alignment = "left"
|
||||
|
||||
[image]
|
||||
id = "imgLeader"
|
||||
definition = "default"
|
||||
[/image]
|
||||
|
||||
[/column]
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_alignment = "right"
|
||||
|
||||
[minimap]
|
||||
id = "minimap"
|
||||
definition = "default"
|
||||
[/minimap]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[/grid]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[row]
|
||||
|
||||
[column]
|
||||
|
||||
grow_factor = 1
|
||||
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_alignment = "left"
|
||||
|
||||
[label]
|
||||
id = "lblScenario"
|
||||
definition = "default"
|
||||
|
||||
label = " "
|
||||
[/label]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[row]
|
||||
|
||||
[column]
|
||||
|
||||
grow_factor = 1
|
||||
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_alignment = "left"
|
||||
|
||||
[label]
|
||||
id = "lblSummary"
|
||||
definition = "default_small"
|
||||
|
||||
label = " "
|
||||
[/label]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[/grid]
|
||||
|
||||
[/column]
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_grow = "true"
|
||||
|
||||
[grid]
|
||||
|
||||
[row]
|
||||
[column]
|
||||
horizontal_alignment = "left"
|
||||
|
||||
[label]
|
||||
id = "lblChoose"
|
||||
definition = "choose"
|
||||
|
||||
label = _ "Choose the game to load"
|
||||
[/label]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[row]
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
horizontal_grow = "true"
|
||||
|
||||
border = "all"
|
||||
border_size = 5
|
||||
|
||||
[listbox]
|
||||
id = "savegame_list"
|
||||
definition = "default"
|
||||
|
||||
[header]
|
||||
|
||||
[row]
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
horizontal_grow = "true"
|
||||
|
||||
border = "all"
|
||||
border_size = 5
|
||||
|
||||
[label]
|
||||
id = "filename"
|
||||
definition = "default"
|
||||
|
||||
label = _ "Name"
|
||||
[/label]
|
||||
|
||||
[/column]
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
horizontal_grow = "true"
|
||||
|
||||
border = "all"
|
||||
border_size = 5
|
||||
|
||||
[label]
|
||||
id = "date"
|
||||
definition = "default"
|
||||
|
||||
label = _ "Date"
|
||||
[/label]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[/header]
|
||||
|
||||
[list_definition]
|
||||
|
||||
[row]
|
||||
|
||||
[column]
|
||||
|
||||
[toggle_panel]
|
||||
definition = "default"
|
||||
|
||||
return_value_id = "ok"
|
||||
[grid]
|
||||
|
||||
[row]
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
horizontal_grow = "true"
|
||||
|
||||
border = "all"
|
||||
border_size = 5
|
||||
|
||||
[label]
|
||||
id = "filename"
|
||||
definition = "default"
|
||||
[/label]
|
||||
|
||||
[/column]
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
horizontal_grow = "true"
|
||||
|
||||
border = "all"
|
||||
border_size = 5
|
||||
|
||||
[label]
|
||||
id = "date"
|
||||
definition = "default"
|
||||
[/label]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[/grid]
|
||||
|
||||
[/toggle_panel]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[/list_definition]
|
||||
|
||||
[/listbox]
|
||||
|
||||
[/column]
|
||||
[/row]
|
||||
|
||||
[/grid]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[/grid]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[row]
|
||||
grow_factor = 0
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
horizontal_grow = "true"
|
||||
|
||||
[grid]
|
||||
|
||||
[row]
|
||||
grow_factor = 0
|
||||
|
||||
[column]
|
||||
|
||||
[spacer]
|
||||
definition = "default"
|
||||
[/spacer]
|
||||
|
||||
[/column]
|
||||
|
||||
[column]
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_alignment = "right"
|
||||
|
||||
[button]
|
||||
id = "ok"
|
||||
definition = "default"
|
||||
|
||||
size_text = _ "OK"
|
||||
label = _ "OK"
|
||||
[/button]
|
||||
|
||||
[/column]
|
||||
|
||||
[column]
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_alignment = "right"
|
||||
|
||||
[button]
|
||||
id = "cancel"
|
||||
definition = "default"
|
||||
|
||||
label = _ "Cancel"
|
||||
[/button]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[/grid]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[/grid]
|
||||
|
||||
[/resolution]
|
||||
|
||||
[/window]
|
||||
|
|
|
@ -310,7 +310,7 @@ public:
|
|||
gui::preview_pane(video),
|
||||
game_config_(&game_config),
|
||||
map_(map), info_(&info),
|
||||
summaries_(&summaries),
|
||||
summaries_(summaries),
|
||||
index_(0),
|
||||
map_cache_(),
|
||||
textbox_(textbox)
|
||||
|
@ -331,7 +331,7 @@ private:
|
|||
const config* game_config_;
|
||||
gamemap* map_;
|
||||
const std::vector<save_info>* info_;
|
||||
const std::vector<config*>* summaries_;
|
||||
const std::vector<config*>& summaries_;
|
||||
int index_;
|
||||
std::map<std::string,surface> map_cache_;
|
||||
const gui::filter_textbox& textbox_;
|
||||
|
@ -339,16 +339,16 @@ private:
|
|||
|
||||
void save_preview_pane::draw_contents()
|
||||
{
|
||||
if (size_t(index_) >= summaries_->size() || info_->size() != summaries_->size()) {
|
||||
if (size_t(index_) >= summaries_.size() || info_->size() != summaries_.size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::string dummy;
|
||||
config& summary = *(*summaries_)[index_];
|
||||
config& summary = *summaries_[index_];
|
||||
if (summary["label"] == ""){
|
||||
try {
|
||||
savegame_manager::load_summary((*info_)[index_].name, summary, &dummy);
|
||||
*(*summaries_)[index_] = summary;
|
||||
*summaries_[index_] = summary;
|
||||
} catch(game::load_game_failed&) {
|
||||
summary["corrupt"] = "yes";
|
||||
}
|
||||
|
|
|
@ -442,18 +442,19 @@ void extract_summary_from_config(config& cfg_save, config& cfg_summary)
|
|||
|
||||
/** @todo Ideally we should grab all leaders if there's more than 1 human player? */
|
||||
std::string leader;
|
||||
std::string leader_image;
|
||||
|
||||
foreach (const config &p, cfg_save.child_range("player"))
|
||||
{
|
||||
if (utils::string_bool(p["canrecruit"], false)) {
|
||||
leader = p["save_id"];
|
||||
}
|
||||
}
|
||||
//foreach (const config &p, cfg_save.child_range("player"))
|
||||
//{
|
||||
// if (utils::string_bool(p["canrecruit"], false)) {
|
||||
// leader = p["save_id"];
|
||||
// }
|
||||
//}
|
||||
|
||||
bool shrouded = false;
|
||||
|
||||
if (!leader.empty())
|
||||
{
|
||||
//if (!leader.empty())
|
||||
//{
|
||||
if (const config &snapshot = *(has_snapshot ? &cfg_snapshot : &cfg_replay_start))
|
||||
{
|
||||
foreach (const config &side, snapshot.child_range("side"))
|
||||
|
@ -466,18 +467,27 @@ void extract_summary_from_config(config& cfg_save, config& cfg_summary)
|
|||
shrouded = true;
|
||||
}
|
||||
|
||||
if (side["canrecruit"] == "yes")
|
||||
{
|
||||
leader = side["id"];
|
||||
leader_image = side["image"];
|
||||
break;
|
||||
}
|
||||
|
||||
foreach (const config &u, side.child_range("unit"))
|
||||
{
|
||||
if (utils::string_bool(u["canrecruit"], false)) {
|
||||
leader = u["id"];
|
||||
leader_image = u["image"];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//}
|
||||
|
||||
cfg_summary["leader"] = leader;
|
||||
cfg_summary["leader_image"] = leader_image;
|
||||
cfg_summary["map_data"] = "";
|
||||
|
||||
if(!shrouded) {
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "gettext.hpp"
|
||||
#include "gui/auxiliary/log.hpp"
|
||||
#include "gui/dialogs/helper.hpp"
|
||||
#include "gui/widgets/image.hpp"
|
||||
#include "gui/widgets/label.hpp"
|
||||
#include "gui/widgets/listbox.hpp"
|
||||
#include "gui/widgets/minimap.hpp"
|
||||
|
@ -78,57 +79,69 @@ void tgame_load::pre_show(CVideo& /*video*/, twindow& window)
|
|||
item["label"] = game.name;
|
||||
data.insert(std::make_pair("filename", item));
|
||||
|
||||
item["label"] = format_time_summary(game.time_modified);
|
||||
item["label"] = game.format_time_summary();
|
||||
data.insert(std::make_pair("date", item));
|
||||
|
||||
list->add_row(data);
|
||||
}
|
||||
|
||||
display_savegame(window);
|
||||
}
|
||||
|
||||
void tgame_load::list_item_clicked(twindow& window){
|
||||
display_savegame(window);
|
||||
}
|
||||
|
||||
void tgame_load::post_show(twindow& window)
|
||||
{
|
||||
//filename_ = txtFilename_->get_widget_value(window);
|
||||
}
|
||||
|
||||
void tgame_load::display_savegame(twindow& window){
|
||||
tlistbox* list = dynamic_cast<tlistbox*>(window.find_widget("savegame_list", false));
|
||||
VALIDATE(list, missing_widget("savegame_list"));
|
||||
save_info& game = games_[list->get_selected_row()];
|
||||
|
||||
config summary;
|
||||
config cfg_summary;
|
||||
std::string dummy;
|
||||
save_info game = games_[list->get_selected_row()];
|
||||
|
||||
try {
|
||||
savegame_manager::load_summary(game.name, summary, &dummy);
|
||||
savegame_manager::load_summary(game.name, cfg_summary, &dummy);
|
||||
} catch(game::load_game_failed&) {
|
||||
summary["corrupt"] = "yes";
|
||||
cfg_summary["corrupt"] = "yes";
|
||||
}
|
||||
|
||||
timage* img_leader = dynamic_cast<timage*>(window.find_widget("imgLeader", false));
|
||||
VALIDATE(img_leader, missing_widget("imgLeader"));
|
||||
img_leader->set_label(cfg_summary["leader_image"]);
|
||||
|
||||
tminimap* minimap = dynamic_cast<tminimap*>(window.find_widget("minimap", false));
|
||||
VALIDATE(minimap, missing_widget("minimap"));
|
||||
minimap->set_map_data(summary["map_data"]);
|
||||
minimap->set_map_data(cfg_summary["map_data"]);
|
||||
|
||||
tlabel* scenario = dynamic_cast<tlabel*>(window.find_widget("lblScenario", false));
|
||||
scenario->set_label(game.name);
|
||||
|
||||
std::stringstream str;
|
||||
str << game.format_time_local();
|
||||
evaluate_summary_string(str, cfg_summary);
|
||||
|
||||
char time_buf[256] = {0};
|
||||
tm* tm_l = localtime(&game.time_modified);
|
||||
if (tm_l) {
|
||||
const size_t res = strftime(time_buf,sizeof(time_buf),_("%a %b %d %H:%M %Y"),tm_l);
|
||||
if(res == 0) {
|
||||
time_buf[0] = 0;
|
||||
}
|
||||
} else {
|
||||
LOG_GUI_G << "localtime() returned null for time " << game.time_modified << ", save " << game.name;
|
||||
}
|
||||
tlabel* lblSummary = dynamic_cast<tlabel*>(window.find_widget("lblSummary", false));
|
||||
lblSummary->set_label(str.str());
|
||||
|
||||
str << time_buf;
|
||||
// FIXME: Find a better way to change the label width
|
||||
window.invalidate_layout();
|
||||
}
|
||||
|
||||
const std::string& campaign_type = summary["campaign_type"];
|
||||
if(utils::string_bool(summary["corrupt"], false)) {
|
||||
void tgame_load::evaluate_summary_string(std::stringstream& str, const config& cfg_summary){
|
||||
const std::string& campaign_type = cfg_summary["campaign_type"];
|
||||
if(utils::string_bool(cfg_summary["corrupt"], false)) {
|
||||
str << "\n" << _("#(Invalid)");
|
||||
} else if (!campaign_type.empty()) {
|
||||
str << "\n";
|
||||
|
||||
if(campaign_type == "scenario") {
|
||||
const std::string campaign_id = summary["campaign"];
|
||||
const std::string campaign_id = cfg_summary["campaign"];
|
||||
const config *campaign = NULL;
|
||||
if (!campaign_id.empty()) {
|
||||
if (const config &c = cache_config_.find_child("campaign", "id", campaign_id))
|
||||
|
@ -157,75 +170,19 @@ void tgame_load::list_item_clicked(twindow& window){
|
|||
|
||||
str << "\n";
|
||||
|
||||
if(utils::string_bool(summary["replay"], false) && !utils::string_bool(summary["snapshot"], true)) {
|
||||
if(utils::string_bool(cfg_summary["replay"], false) && !utils::string_bool(cfg_summary["snapshot"], true)) {
|
||||
str << _("replay");
|
||||
} else if (!summary["turn"].empty()) {
|
||||
str << _("Turn") << " " << summary["turn"];
|
||||
} else if (!cfg_summary["turn"].empty()) {
|
||||
str << _("Turn") << " " << cfg_summary["turn"];
|
||||
} else {
|
||||
str << _("Scenario Start");
|
||||
}
|
||||
|
||||
str << "\n" << _("Difficulty: ") << string_table[summary["difficulty"]];
|
||||
if(!summary["version"].empty()) {
|
||||
str << "\n" << _("Version: ") << summary["version"];
|
||||
str << "\n" << _("Difficulty: ") << string_table[cfg_summary["difficulty"]];
|
||||
if(!cfg_summary["version"].empty()) {
|
||||
str << "\n" << _("Version: ") << cfg_summary["version"];
|
||||
}
|
||||
}
|
||||
|
||||
tlabel* lblSummary = dynamic_cast<tlabel*>(window.find_widget("lblSummary", false));
|
||||
lblSummary->set_label(str.str());
|
||||
|
||||
// FIXME: Find a better way to change the label width
|
||||
window.invalidate_layout();
|
||||
}
|
||||
|
||||
void tgame_load::post_show(twindow& window)
|
||||
{
|
||||
//filename_ = txtFilename_->get_widget_value(window);
|
||||
}
|
||||
|
||||
std::string tgame_load::format_time_summary(time_t t)
|
||||
{
|
||||
time_t curtime = time(NULL);
|
||||
const struct tm* timeptr = localtime(&curtime);
|
||||
if(timeptr == NULL) {
|
||||
return "";
|
||||
}
|
||||
|
||||
const struct tm current_time = *timeptr;
|
||||
|
||||
timeptr = localtime(&t);
|
||||
if(timeptr == NULL) {
|
||||
return "";
|
||||
}
|
||||
|
||||
const struct tm save_time = *timeptr;
|
||||
|
||||
const char* format_string = _("%b %d %y");
|
||||
|
||||
if(current_time.tm_year == save_time.tm_year) {
|
||||
const int days_apart = current_time.tm_yday - save_time.tm_yday;
|
||||
if(days_apart == 0) {
|
||||
// save is from today
|
||||
format_string = _("%H:%M");
|
||||
} else if(days_apart > 0 && days_apart <= current_time.tm_wday) {
|
||||
// save is from this week
|
||||
format_string = _("%A, %H:%M");
|
||||
} else {
|
||||
// save is from current year
|
||||
format_string = _("%b %d");
|
||||
}
|
||||
} else {
|
||||
// save is from a different year
|
||||
format_string = _("%b %d %y");
|
||||
}
|
||||
|
||||
char buf[40];
|
||||
const size_t res = strftime(buf,sizeof(buf),format_string,&save_time);
|
||||
if(res == 0) {
|
||||
buf[0] = 0;
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
} // namespace gui2
|
|
@ -42,7 +42,8 @@ private:
|
|||
|
||||
void list_item_clicked(twindow& window);
|
||||
|
||||
std::string format_time_summary(time_t t);
|
||||
void display_savegame(twindow& window);
|
||||
void evaluate_summary_string(std::stringstream& str, const config& cfg_summary);
|
||||
|
||||
//tfield_text* txtFilename_;
|
||||
std::string filename_;
|
||||
|
|
|
@ -123,6 +123,67 @@ static lg::log_domain log_engine("engine");
|
|||
}
|
||||
#endif /* _WIN32 */
|
||||
|
||||
const std::string save_info::format_time_local() const{
|
||||
char time_buf[256] = {0};
|
||||
tm* tm_l = localtime(&time_modified);
|
||||
if (tm_l) {
|
||||
const size_t res = strftime(time_buf,sizeof(time_buf),_("%a %b %d %H:%M %Y"),tm_l);
|
||||
if(res == 0) {
|
||||
time_buf[0] = 0;
|
||||
}
|
||||
} else {
|
||||
LOG_SAVE << "localtime() returned null for time " << time_modified << ", save " << name;
|
||||
}
|
||||
|
||||
return time_buf;
|
||||
}
|
||||
|
||||
const std::string save_info::format_time_summary() const
|
||||
{
|
||||
time_t t = time_modified;
|
||||
time_t curtime = time(NULL);
|
||||
const struct tm* timeptr = localtime(&curtime);
|
||||
if(timeptr == NULL) {
|
||||
return "";
|
||||
}
|
||||
|
||||
const struct tm current_time = *timeptr;
|
||||
|
||||
timeptr = localtime(&t);
|
||||
if(timeptr == NULL) {
|
||||
return "";
|
||||
}
|
||||
|
||||
const struct tm save_time = *timeptr;
|
||||
|
||||
const char* format_string = _("%b %d %y");
|
||||
|
||||
if(current_time.tm_year == save_time.tm_year) {
|
||||
const int days_apart = current_time.tm_yday - save_time.tm_yday;
|
||||
if(days_apart == 0) {
|
||||
// save is from today
|
||||
format_string = _("%H:%M");
|
||||
} else if(days_apart > 0 && days_apart <= current_time.tm_wday) {
|
||||
// save is from this week
|
||||
format_string = _("%A, %H:%M");
|
||||
} else {
|
||||
// save is from current year
|
||||
format_string = _("%b %d");
|
||||
}
|
||||
} else {
|
||||
// save is from a different year
|
||||
format_string = _("%b %d %y");
|
||||
}
|
||||
|
||||
char buf[40];
|
||||
const size_t res = strftime(buf,sizeof(buf),format_string,&save_time);
|
||||
if(res == 0) {
|
||||
buf[0] = 0;
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
/**
|
||||
* A structure for comparing to save_info objects based on their modified time.
|
||||
* If the times are equal, will order based on the name.
|
||||
|
|
|
@ -35,6 +35,9 @@ struct save_info {
|
|||
save_info(const std::string& n, time_t t) : name(n), time_modified(t) {}
|
||||
std::string name;
|
||||
time_t time_modified;
|
||||
|
||||
const std::string format_time_summary() const;
|
||||
const std::string format_time_local() const;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue