16 #define GETTEXT_DOMAIN "wesnoth-lib"
30 using namespace std::chrono_literals;
36 const auto fade_duration = 500ms;
49 , duration_(
info.end_text_duration)
55 if(!
info.end_text.empty()) {
56 text_.push_back(
info.end_text);
58 text_.push_back(
_(
"The End"));
61 if(
info.end_credits) {
65 for(
const auto&
about : (*campaign_credits)->sections) {
66 if(
about.names.empty()) {
71 static const float chunk_size = 5.0;
73 const unsigned num_names =
about.names.size();
74 const unsigned num_chunks = std::ceil(num_names / chunk_size);
76 for(std::size_t
i = 0;
i < num_chunks; ++
i) {
81 ss <<
about.title <<
"\n\n";
84 for(std::size_t k =
i * chunk_size; k < std::min<unsigned>((
i + 1) * chunk_size, num_names); ++k) {
89 std::string section_text = ss.str();
90 section_text.pop_back();
92 text_.push_back(std::move(section_text));
98 current_text_ = text_[0];
100 if(duration_ == 0ms) {
105 void outro::pre_show()
107 set_enter_disabled(
true);
108 get_canvas(0).set_variable(
"outro_text",
wfl::variant(current_text_));
114 if(text_index_ >= text_.size()) {
118 if(fade_start_ == 0) {
119 fade_start_ = SDL_GetTicks();
123 if(fading_in_ && fade_alpha_ >= 255) {
126 timer_id_ =
add_timer(duration_, [
this](std::size_t) {
135 canvas& window_canvas = window::get_canvas(0);
138 if(!fading_in_ && fade_alpha_ == 0) {
141 if(text_index_ >= text_.size()) {
145 current_text_ = text_[text_index_];
155 fade_start_ = SDL_GetTicks();
162 auto current_ticks = SDL_GetTicks();
164 if(fade_start_ > current_ticks) {
168 fade_start_ = current_ticks;
171 fade_alpha_ = std::clamp<int>(
172 std::round(255.0 *
double(current_ticks - fade_start_) /
double(fade_duration.count())),
175 fade_alpha_ = 255 - fade_alpha_;
179 void outro::post_show()
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.
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.
std::size_t add_timer(const std::chrono::milliseconds &interval, const std::function< void(std::size_t id)> &callback, const bool repeat)
Adds a new timer.
bool remove_timer(const std::size_t id)
Removes a timer.
std::string span_size(const std::string &size, Args &&... data)
Contains the gui2 timer routines.