Skip to content

Commit

Permalink
Game Load: Show list of enabled modifications (#3495)
Browse files Browse the repository at this point in the history
  • Loading branch information
jostephd authored and jyrkive committed Aug 27, 2018
1 parent 328a9c9 commit 6f67055
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
8 changes: 5 additions & 3 deletions data/gui/window/game_load.cfg
Expand Up @@ -365,11 +365,13 @@
border_size = 5
horizontal_grow = true

[label]
id = "lblSummary"
[scroll_label]
id = "slblSummary"
definition = "default_small"
use_markup = true
[/label]
vertical_scrollbar_mode = "auto"
wrap = false
[/scroll_label]

[/column]

Expand Down
21 changes: 20 additions & 1 deletion src/gui/dialogs/game_load.cpp
Expand Up @@ -32,6 +32,7 @@
#include "gui/widgets/label.hpp"
#include "gui/widgets/listbox.hpp"
#include "gui/widgets/minimap.hpp"
#include "gui/widgets/scroll_label.hpp"
#include "gui/widgets/text_box.hpp"
#include "gui/widgets/toggle_button.hpp"
#include "gui/widgets/window.hpp"
Expand Down Expand Up @@ -222,7 +223,9 @@ void game_load::display_savegame(window& window)
str << game.format_time_local() << "\n";
evaluate_summary_string(str, summary_);

find_widget<label>(&window, "lblSummary", false).set_label(str.str());
// The new label value may have more or less lines than the previous value, so invalidate the layout.
find_widget<scroll_label>(&window, "slblSummary", false).set_label(str.str());
window.invalidate_layout();

toggle_button& replay_toggle = dynamic_cast<toggle_button&>(*show_replay_->get_widget());
toggle_button& cancel_orders_toggle = dynamic_cast<toggle_button&>(*cancel_orders_->get_widget());
Expand Down Expand Up @@ -374,6 +377,22 @@ void game_load::evaluate_summary_string(std::stringstream& str, const config& cf
if(!cfg_summary["version"].empty()) {
str << "\n" << _("Version: ") << cfg_summary["version"];
}

const std::vector<std::string>& active_mods = utils::split(cfg_summary["active_mods"]);
if(!active_mods.empty()) {
str << "\n" << _("Modifications: ");
for(const auto& mod_id : active_mods) {
std::string mod_name;
try {
mod_name = cache_config_.find_child("modification", "id", mod_id)["name"].str();
} catch(const config::error&) {
// Fallback to nontranslatable mod id.
mod_name = "(" + mod_id + ")";
}

str << "\n" << font::unicode_bullet << " " << mod_name;
}
}
}

void game_load::delete_button_callback(window& window)
Expand Down
1 change: 1 addition & 0 deletions src/save_index.cpp
Expand Up @@ -373,6 +373,7 @@ void extract_summary_from_config(config& cfg_save, config& cfg_summary)
cfg_summary["difficulty"] = cfg_save["difficulty"];
cfg_summary["random_mode"] = cfg_save["random_mode"];

cfg_summary["active_mods"] = cfg_save.child("multiplayer")["active_mods"];
cfg_summary["campaign"] = cfg_save["campaign"];
cfg_summary["version"] = cfg_save["version"];
cfg_summary["corrupt"] = "";
Expand Down

0 comments on commit 6f67055

Please sign in to comment.