Skip to content

Commit

Permalink
Convert outro screen to GUI2
Browse files Browse the repository at this point in the history
It's the screen that shows 'The End' at the end of an SP campaign.
  • Loading branch information
Vultraz committed Apr 9, 2017
1 parent 10f867b commit dec0fd6
Show file tree
Hide file tree
Showing 11 changed files with 262 additions and 120 deletions.
79 changes: 79 additions & 0 deletions data/gui/window/outro.cfg
@@ -0,0 +1,79 @@
#textdomain wesnoth-lib

[window_definition]
id = "outro"
description = "The window definition for the outro screen."

[resolution]

# NOTE: we don't specify borders like most definitions since we want
# widgets to fully reach the edge of the window.

[background]

[draw]

[rectangle]
x = 0
y = 0
w = "(width)"
h = "(height)"

fill_color = "0, 0, 0, 255"
immutable = true
[/rectangle]

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

font_size = {GUI_FONT_SIZE_HUGE}
color = "([215, 215, 215, min(fade_step * 5, 255)])"

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

[/draw]

[/background]

[foreground]

[draw]

[/draw]

[/foreground]

[/resolution]

[/window_definition]

[window]
id = "outro"
description = "Outro text display"

[resolution]
definition = "outro"

{GUI_WINDOW_FULLSCREEN}

[tooltip]
id = "tooltip_large"
[/tooltip]

[helptip]
id = "tooltip_large"
[/helptip]

# No contents. The only text is drawn in the background by the canvas.
[grid]
[/grid]

[/resolution]

[/window]
4 changes: 2 additions & 2 deletions projectfiles/CodeBlocks/wesnoth.cbp
Expand Up @@ -643,6 +643,8 @@
<Unit filename="../../src/gui/dialogs/multiplayer/synced_choice_wait.hpp" />
<Unit filename="../../src/gui/dialogs/network_transmission.cpp" />
<Unit filename="../../src/gui/dialogs/network_transmission.hpp" />
<Unit filename="../../src/gui/dialogs/outro.cpp" />
<Unit filename="../../src/gui/dialogs/outro.hpp" />
<Unit filename="../../src/gui/dialogs/preferences_dialog.cpp" />
<Unit filename="../../src/gui/dialogs/preferences_dialog.hpp" />
<Unit filename="../../src/gui/dialogs/screenshot_notification.cpp" />
Expand Down Expand Up @@ -817,8 +819,6 @@
<Unit filename="../../src/image.hpp" />
<Unit filename="../../src/image_modifications.cpp" />
<Unit filename="../../src/image_modifications.hpp" />
<Unit filename="../../src/intro.cpp" />
<Unit filename="../../src/intro.hpp" />
<Unit filename="../../src/joystick.cpp" />
<Unit filename="../../src/joystick.hpp" />
<Unit filename="../../src/key.cpp" />
Expand Down
2 changes: 1 addition & 1 deletion source_lists/wesnoth
Expand Up @@ -226,6 +226,7 @@ gui/dialogs/multiplayer/mp_options_helper.cpp
gui/dialogs/multiplayer/mp_staging.cpp
gui/dialogs/multiplayer/synced_choice_wait.cpp
gui/dialogs/network_transmission.cpp
gui/dialogs/outro.cpp
gui/dialogs/preferences_dialog.cpp
gui/dialogs/screenshot_notification.cpp
gui/dialogs/select_orb_colors.cpp
Expand Down Expand Up @@ -301,7 +302,6 @@ help/help_topic_generators.cpp
hotkey/hotkey_handler.cpp
hotkey/hotkey_handler_mp.cpp
hotkey/hotkey_handler_sp.cpp
intro.cpp
lobby_preferences.cpp
menu_events.cpp
mouse_events.cpp
Expand Down
6 changes: 4 additions & 2 deletions src/game_launcher.cpp
Expand Up @@ -34,12 +34,12 @@
#include "gui/dialogs/message.hpp" //for show error message
#include "gui/dialogs/multiplayer/mp_host_game_prompt.hpp" //for host game prompt
#include "gui/dialogs/multiplayer/mp_method_selection.hpp"
#include "gui/dialogs/outro.hpp"
#include "gui/dialogs/preferences_dialog.hpp"
#include "gui/dialogs/transient_message.hpp" // for show_transient_message
#include "gui/dialogs/title_screen.hpp" // for show_debug_clock_button
#include "gui/widgets/settings.hpp" // for new_widgets
#include "gui/widgets/window.hpp" // for window, etc
#include "intro.hpp"
#include "language.hpp" // for language_def, etc
#include "log.hpp" // for LOG_STREAM, logger, general, etc
#include "map/exception.hpp"
Expand Down Expand Up @@ -951,7 +951,9 @@ void game_launcher::launch_game(RELOAD_GAME_DATA reload)
// change this if MP campaigns are implemented
if(result == LEVEL_RESULT::VICTORY && !state_.classification().is_normal_mp_game()) {
preferences::add_completed_campaign(state_.classification().campaign, state_.classification().difficulty);
the_end(video(), state_.classification().end_text, state_.classification().end_text_duration);

gui2::dialogs::outro::display(state_.classification().end_text, state_.classification().end_text_duration, video());

if(state_.classification().end_credits) {
gui2::dialogs::end_credits::display(video(), state_.classification().campaign);
}
Expand Down
100 changes: 100 additions & 0 deletions src/gui/dialogs/outro.cpp
@@ -0,0 +1,100 @@
/*
Copyright (C) 2017 by Charles Dang <exodia339@gmail.com>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/

#define GETTEXT_DOMAIN "wesnoth-lib"

#include "gui/dialogs/outro.hpp"

#include "formula/variant.hpp"
#include "gettext.hpp"
#include "gui/auxiliary/find_widget.hpp"
#include "gui/core/timer.hpp"
#include "gui/widgets/settings.hpp"
#include "gui/widgets/window.hpp"

namespace gui2
{
namespace dialogs
{

REGISTER_DIALOG(outro)

outro::outro(const std::string& text, unsigned int duration)
: text_(text)
, duration_(duration)
, fade_step_(0)
, fading_in_(true)
, timer_id_(0)
, timer_id_secondary_(0)
{
if(text_.empty()) {
text_ = _("The End");
}

if(!duration_) {
duration_ = 3500;
}
}

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

timer_id_ = add_timer(50, std::bind(&outro::timer_callback, this, std::ref(window)), true);
}

void outro::timer_callback(window& window)
{
// If we've faded fully in...
if(fading_in_ && fade_step_ == 255) {
// Schedule the fadeout after the provided delay.
if(timer_id_secondary_ == 0) {
timer_id_secondary_ = add_timer(duration_, [this](size_t) { fading_in_ = false; });
}

return;
}

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

canvas& window_canvas = window.get_canvas(0);

window_canvas.set_variable("fade_step", wfl::variant(fade_step_));
window_canvas.set_is_dirty(true);

window.set_is_dirty(true);

if(fading_in_) {
fade_step_ += 5;
} else {
fade_step_ -= 5;
}
}

void outro::post_show(window& /*window*/)
{
remove_timer(timer_id_);
remove_timer(timer_id_secondary_);

timer_id_ = 0;
timer_id_secondary_ = 0;
}

} // namespace dialogs
} // namespace gui2
73 changes: 73 additions & 0 deletions src/gui/dialogs/outro.hpp
@@ -0,0 +1,73 @@
/*
Copyright (C) 2017 by Charles Dang <exodia339@gmail.com>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/

#ifndef GUI_DIALOGS_OUTRO_HPP_INCLUDED
#define GUI_DIALOGS_OUTRO_HPP_INCLUDED

#include "gui/dialogs/modal_dialog.hpp"

class CVideo;

namespace gui2
{
namespace dialogs
{

/** Dialog to display 'The End' at the end of a campaign. */
class outro : public modal_dialog
{
public:
outro(const std::string& text, unsigned int duration);

/**
* Displays a simple fading screen with any user-provided text.
* Used after the end of single-player campaigns.
*
* @param text Text to display, centered on the screen.
*
* @param duration In milliseconds, for how much time the text will
* be displayed on screen.
*/
static void display(const std::string& text, unsigned int duration, CVideo& video)
{
outro(text, duration).show(video);
}

private:
/** Inherited from modal_dialog, implemented by REGISTER_DIALOG. */
virtual const std::string& window_id() const;

/** Inherited from modal_dialog. */
void pre_show(window& window);

/** Inherited from modal_dialog. */
void post_show(window& window);

void timer_callback(window& window);

std::string text_;

unsigned int duration_;
int fade_step_;

bool fading_in_;

size_t timer_id_;
size_t timer_id_secondary_;
};

} // namespace dialogs
} // namespace gui2

#endif
78 changes: 0 additions & 78 deletions src/intro.cpp

This file was deleted.

0 comments on commit dec0fd6

Please sign in to comment.