Skip to content

Commit

Permalink
Repurposed Outro dialog for campaign-specific credits
Browse files Browse the repository at this point in the history
  • Loading branch information
Vultraz committed Oct 4, 2020
1 parent 105a551 commit c3e578b
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 17 deletions.
5 changes: 3 additions & 2 deletions data/gui/window/outro.cfg
Expand Up @@ -24,19 +24,20 @@
[/rectangle]

[text]
x = {GUI__TEXT_HORIZONTALLY_CENTRED}
x = 0
y = {GUI__TEXT_VERTICALLY_CENTRED}
w = "(width)"
h = "(text_height)"
maximum_width = "(width)"

font_size = 100
font_size = 80
font_family = "script"

color = "([215, 215, 215, min(ceil(as_decimal(fade_step * 25.5)), 255)])"

text = "(outro_text)"
text_markup = true
text_alignment = "center"
[/text]

[/draw]
Expand Down
5 changes: 0 additions & 5 deletions src/game_launcher.cpp
Expand Up @@ -27,7 +27,6 @@
#include "game_config_manager.hpp" // for game_config_manager
#include "generators/map_generator.hpp" // for mapgen_exception
#include "gettext.hpp" // for _
#include "gui/dialogs/end_credits.hpp"
#include "gui/dialogs/language_selection.hpp" // for language_selection
#include "gui/dialogs/loading_screen.hpp"
#include "gui/dialogs/message.hpp" //for show error message
Expand Down Expand Up @@ -1031,10 +1030,6 @@ void game_launcher::launch_game(RELOAD_GAME_DATA reload)
preferences::add_completed_campaign(state_.classification().campaign, state_.classification().difficulty);

gui2::dialogs::outro::display(state_.classification());

if(state_.classification().end_credits) {
gui2::dialogs::end_credits::display(state_.classification().campaign);
}
}
} catch (const savegame::load_game_exception &e) {
load_data_.reset(new savegame::load_game_metadata(std::move(e.data_)));
Expand Down
66 changes: 57 additions & 9 deletions src/gui/dialogs/outro.cpp
Expand Up @@ -16,6 +16,7 @@

#include "gui/dialogs/outro.hpp"

#include "about.hpp"
#include "formula/variant.hpp"
#include "game_classification.hpp"
#include "gettext.hpp"
Expand All @@ -31,26 +32,59 @@ namespace dialogs
REGISTER_DIALOG(outro)

outro::outro(const game_classification& info)
: text_(info.end_text)
: text_()
, current_text_()
, duration_(info.end_text_duration)
, fade_step_(0)
, fading_in_(true)
, timer_id_(0)
, next_draw_(0)
{
if(text_.empty()) {
text_ = _("The End");
if(!info.end_text.empty()) {
text_.push_back(info.end_text);
} else {
text_.push_back(_("The End"));
}

text_.push_back("<span size='large'>" + info.campaign_name + "</span>");

// 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 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));

for(std::size_t i = 0; i < num_chunks; ++i) {
std::stringstream ss;
ss << about.title << "\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>";
}

std::cerr << "pushing back " << ss.str() << std::endl;
text_.push_back(ss.str());
}
}
}

current_text_ = text_.begin();

if(!duration_) {
duration_ = 3500;
duration_ = 3500; // 3.5 seconds
}
}

void outro::pre_show(window& window)
{
window.set_enter_disabled(true);
window.get_canvas(0).set_variable("outro_text", wfl::variant(text_));
window.get_canvas(0).set_variable("outro_text", wfl::variant(*current_text_));

connect_signal_on_draw(window, std::bind(&outro::draw_callback, this, std::ref(window)));

Expand Down Expand Up @@ -86,13 +120,27 @@ void outro::draw_callback(window& window)
return;
}

canvas& window_canvas = window.get_canvas(0);

// If we've faded fully out...
if(!fading_in_ && fade_step_ < 0) {
window.close();
return;
}
std::advance(current_text_, 1);

canvas& window_canvas = window.get_canvas(0);
// ...and we've just showed the last text bit, close the window.
if(current_text_ == text_.end()) {
window.close();
return;
}

// ...else show the next bit.
window_canvas.set_variable("outro_text", wfl::variant(*current_text_));

fading_in_ = true;
fade_step_ = 0;

remove_timer(timer_id_);
timer_id_ = 0;
}

window_canvas.set_variable("fade_step", wfl::variant(fade_step_));
window_canvas.set_is_dirty(true);
Expand Down
3 changes: 2 additions & 1 deletion src/gui/dialogs/outro.hpp
Expand Up @@ -53,7 +53,8 @@ class outro : public modal_dialog

void draw_callback(window& window);

std::string text_;
std::vector<std::string> text_;
std::vector<std::string>::iterator current_text_;

unsigned int duration_;
int fade_step_;
Expand Down

0 comments on commit c3e578b

Please sign in to comment.