Convert outro screen to GUI2
It's the screen that shows 'The End' at the end of an SP campaign.
This commit is contained in:
parent
10f867bd7e
commit
dec0fd6dfd
11 changed files with 262 additions and 120 deletions
79
data/gui/window/outro.cfg
Normal file
79
data/gui/window/outro.cfg
Normal file
|
@ -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]
|
|
@ -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" />
|
||||
|
@ -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" />
|
||||
|
|
|
@ -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
|
||||
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
@ -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);
|
||||
}
|
||||
|
|
100
src/gui/dialogs/outro.cpp
Normal file
100
src/gui/dialogs/outro.cpp
Normal file
|
@ -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
src/gui/dialogs/outro.hpp
Normal file
73
src/gui/dialogs/outro.hpp
Normal file
|
@ -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
|
|
@ -1,78 +0,0 @@
|
|||
/*
|
||||
Copyright (C) 2003 - 2017 by David White <dave@whitevine.net>
|
||||
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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Introduction sequence at start of a scenario, End-screen after end of
|
||||
* campaign.
|
||||
*/
|
||||
|
||||
#include "intro.hpp"
|
||||
|
||||
#include "video.hpp"
|
||||
#include "gettext.hpp"
|
||||
#include "font/marked-up_text.hpp"
|
||||
#include "color.hpp"
|
||||
#include "sdl/rect.hpp"
|
||||
#include "font/sdl_ttf.hpp"
|
||||
|
||||
void the_end(CVideo &video, std::string text, unsigned int duration)
|
||||
{
|
||||
//
|
||||
// Some sane defaults.
|
||||
//
|
||||
if(text.empty())
|
||||
text = _("The End");
|
||||
if(!duration)
|
||||
duration = 3500;
|
||||
|
||||
SDL_Rect area = screen_area();
|
||||
sdl::fill_rect(video.getSurface(),&area,0);
|
||||
|
||||
video.flip();
|
||||
|
||||
const size_t font_size = font::SIZE_XLARGE;
|
||||
|
||||
area = font::text_area(text,font_size);
|
||||
area.x = screen_area().w/2 - area.w/2;
|
||||
area.y = screen_area().h/2 - area.h/2;
|
||||
|
||||
for(size_t n = 0; n < 255; n += 5) {
|
||||
if(n)
|
||||
sdl::fill_rect(video.getSurface(),&area,0);
|
||||
|
||||
const color_t col = color_t(uint8_t(n), uint8_t(n), uint8_t(n), uint8_t(n));
|
||||
font::draw_text(&video,area,font_size,col,text,area.x,area.y);
|
||||
|
||||
events::pump();
|
||||
events::raise_process_event();
|
||||
events::raise_draw_event();
|
||||
video.flip();
|
||||
CVideo::delay(10);
|
||||
}
|
||||
|
||||
//
|
||||
// Delay after the end of fading.
|
||||
// Rounded to multiples of 10.
|
||||
//
|
||||
unsigned int count = duration/10;
|
||||
while(count) {
|
||||
events::pump();
|
||||
events::raise_process_event();
|
||||
events::raise_draw_event();
|
||||
video.flip();
|
||||
CVideo::delay(10);
|
||||
--count;
|
||||
}
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
/*
|
||||
Copyright (C) 2003 - 2017 by David White <dave@whitevine.net>
|
||||
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.
|
||||
*/
|
||||
|
||||
/** @file */
|
||||
|
||||
#ifndef INTRO_HPP_INCLUDED
|
||||
#define INTRO_HPP_INCLUDED
|
||||
|
||||
class CVideo;
|
||||
|
||||
#include <string>
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
void the_end(CVideo &video, std::string text, unsigned int duration);
|
||||
|
||||
#endif /* ! INTRO_HPP_INCLUDED */
|
|
@ -30,7 +30,6 @@
|
|||
#include "game_events/pump.hpp"
|
||||
#include "game_data.hpp"
|
||||
#include "gettext.hpp"
|
||||
#include "intro.hpp"
|
||||
#include "log.hpp"
|
||||
#include "resources.hpp"
|
||||
#include "widgets/button.hpp"
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
|
||||
#include "font/text.hpp"
|
||||
#include "gettext.hpp"
|
||||
#include "intro.hpp"
|
||||
#include "language.hpp"
|
||||
#include "log.hpp"
|
||||
#include "sound.hpp"
|
||||
|
|
|
@ -84,6 +84,7 @@
|
|||
#include "gui/dialogs/multiplayer/mp_join_game.hpp"
|
||||
#include "gui/dialogs/multiplayer/mp_join_game_password_prompt.hpp"
|
||||
#include "gui/dialogs/multiplayer/mp_staging.hpp"
|
||||
#include "gui/dialogs/outro.hpp"
|
||||
#include "gui/dialogs/depcheck_confirm_change.hpp"
|
||||
#include "gui/dialogs/depcheck_select_new.hpp"
|
||||
#include "gui/dialogs/multiplayer/mp_login.hpp"
|
||||
|
@ -449,6 +450,7 @@ BOOST_AUTO_TEST_CASE(test_gui2)
|
|||
test<mp_method_selection>();
|
||||
test<mp_server_list>();
|
||||
//test<mp_staging>();
|
||||
//test<outro>();
|
||||
test<simple_item_selector>();
|
||||
test<screenshot_notification>();
|
||||
test<select_orb_colors>();
|
||||
|
@ -515,6 +517,7 @@ BOOST_AUTO_TEST_CASE(test_gui2)
|
|||
"attack_predictions",
|
||||
"help_browser",
|
||||
"story_viewer",
|
||||
"outro",
|
||||
};
|
||||
std::sort(list.begin(), list.end());
|
||||
std::sort(omitted.begin(), omitted.end());
|
||||
|
|
Loading…
Add table
Reference in a new issue