16 #define GETTEXT_DOMAIN "wesnoth-lib"
30 using namespace std::chrono_literals;
36 constexpr
auto fade_duration = 500ms;
48 , display_duration_(
info.end_text_duration)
49 , stage_(
stage::fading_in)
52 if(!
info.end_text.empty()) {
53 text_.push_back(
info.end_text);
55 text_.push_back(
_(
"The End"));
58 if(
info.end_credits) {
62 for(
const auto&
about : (*campaign_credits)->sections) {
63 if(
about.names.empty()) {
68 static const float chunk_size = 5.0;
70 const unsigned num_names =
about.names.size();
71 const unsigned num_chunks = std::ceil(num_names / chunk_size);
73 for(std::size_t
i = 0;
i < num_chunks; ++
i) {
78 ss <<
about.title <<
"\n\n";
81 for(std::size_t k =
i * chunk_size; k < std::min<unsigned>((
i + 1) * chunk_size, num_names); ++k) {
86 std::string section_text = ss.str();
87 section_text.pop_back();
89 text_.push_back(std::move(section_text));
95 if(display_duration_ == 0ms) {
96 display_duration_ = 3500ms;
100 void outro::pre_show()
102 set_enter_disabled(
true);
103 get_canvas(0).set_variable(
"outro_text",
wfl::variant(text_[0]));
104 get_canvas(0).set_variable(
"fade_alpha",
wfl::variant(0));
110 if(text_index_ >= text_.size()) {
114 const auto now = std::chrono::steady_clock::now();
115 canvas& window_canvas = window::get_canvas(0);
122 const auto goto_stage = [
this, &now](
stage new_stage) {
127 if(stage_start_ == std::chrono::steady_clock::time_point{}) {
132 case stage::fading_in:
133 if(now <= stage_start_ + fade_duration) {
136 goto_stage(stage::waiting);
141 if(now <= stage_start_ + display_duration_) {
144 goto_stage(stage::fading_out);
148 case stage::fading_out:
149 if(now <= stage_start_ + fade_duration) {
151 }
else if(++text_index_ < text_.size()) {
153 goto_stage(stage::fading_in);
167 double outro::get_fade_progress(
const std::chrono::steady_clock::time_point& now)
const
A simple canvas which can be drawn upon.
void set_variable(const std::string &key, wfl::variant &&value)
void update_size_variables()
Update WFL size variables.
Abstract base class for all modal dialogs.
Dialog to display 'The End' at the end of a campaign.
stage
Tracks whether we're fading in, displaying text, or fading out.
constexpr uint8_t float_to_color(double n)
Convert a double in the range [0.0,1.0] to an 8-bit colour value.
static std::string _(const char *str)
#define REGISTER_DIALOG(window_id)
Wrapper for REGISTER_DIALOG2.
Display credits about all contributors.
utils::optional< credits_data::const_iterator > get_campaign_credits(const std::string &campaign)
Gets credits for a given campaign.
constexpr double normalize_progress(const std::chrono::duration< RepE, PeriodE > &elapsed, const std::chrono::duration< RepD, PeriodD > &duration)
std::string span_size(std::string_view size, Args &&... data)
Applies Pango markup to the input specifying its display size.