Skip to content

Commit

Permalink
Tweaks and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Vultraz committed Oct 6, 2020
1 parent 60ed288 commit ef31563
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
9 changes: 8 additions & 1 deletion src/about.cpp
Expand Up @@ -15,6 +15,7 @@
#include "about.hpp"

#include "config.hpp"
#include "font/pango/escape.hpp"
#include "game_config_view.hpp"
#include "gettext.hpp"
#include "serialization/string_utils.hpp"
Expand Down Expand Up @@ -81,7 +82,7 @@ credits_group::about_group::about_group(const config& cfg)
names.reserve(cfg.child_count("entry"));

for(const config& entry : cfg.child_range("entry")) {
names.emplace_back(entry["name"].str(), entry["comment"].str());
names.emplace_back(font::escape_text(entry["name"].str()), font::escape_text(entry["comment"].str()));
}
}

Expand All @@ -95,6 +96,12 @@ const credits_data& get_credits_data()
return parsed_credits_data;
}

credits_data::const_iterator get_campaign_credits(const std::string& campaign)
{
return std::find_if(parsed_credits_data.begin(), parsed_credits_data.end(),
[&campaign](const credits_group& group) { return group.id == campaign; });
}

std::vector<std::string> get_background_images(const std::string& campaign)
{
if(!campaign.empty() && !images_campaigns[campaign].empty()) {
Expand Down
12 changes: 6 additions & 6 deletions src/about.hpp
Expand Up @@ -53,16 +53,16 @@ struct credits_group

using credits_data = std::vector<credits_group>;

/**
* General getter methods for the credits config and image lists by campaign id
*/
/** Gets all credits data. */
const credits_data& get_credits_data();

/** Gets credits for a given campaign. */
credits_data::const_iterator get_campaign_credits(const std::string& campaign);

/** Gets credit background images for a given campaaign. */
std::vector<std::string> get_background_images(const std::string& campaign);

/**
* Regenerates the credits config
*/
/** Regenerates the credits data. */
void set_about(const game_config_view& cfg);

} // namespace about
19 changes: 12 additions & 7 deletions src/gui/dialogs/outro.cpp
Expand Up @@ -50,13 +50,14 @@ outro::outro(const game_classification& info)

// We only show the end text and the title if credits were turned off
if(info.end_credits) {
const auto& credits = about::get_credits_data();
const auto campaign_credits = std::find_if(credits.begin(), credits.end(),
[&info](const about::credits_group& group) { return group.id == info.campaign; });
for(const auto& about : about::get_campaign_credits(info.campaign)->sections) {
if(about.names.empty()) {
continue;
}

for(const about::credits_group::about_group& about : campaign_credits->sections) {
// Split the names into chunks of 5
static const unsigned chunk_size = 5;

const unsigned num_names = about.names.size();
const unsigned num_chunks = std::max<unsigned>(1, std::ceil(num_names / chunk_size));

Expand All @@ -65,14 +66,18 @@ outro::outro(const game_classification& info)

// Only include section title on first chunk
if(i == 0) {
ss << about.title << "\n";
ss << about.title << "\n\n";
}

for(std::size_t k = i * chunk_size; k < std::min<unsigned>((i + 1) * chunk_size, num_names); ++k) {
ss << "\n<span size='xx-small'>" << about.names[k].first << "</span>";
ss << "<span size='xx-small'>" << about.names[k].first << "</span>\n";
}

text_.push_back(ss.str());
// Clean up the trailing newline
std::string section_text = ss.str();
section_text.pop_back();

text_.push_back(std::move(section_text));
}
}
}
Expand Down

0 comments on commit ef31563

Please sign in to comment.