From dec0fd6dfdc51f125ef44f380061d539fe3e5e96 Mon Sep 17 00:00:00 2001 From: Charles Dang Date: Sun, 9 Apr 2017 21:35:28 +1100 Subject: [PATCH] Convert outro screen to GUI2 It's the screen that shows 'The End' at the end of an SP campaign. --- data/gui/window/outro.cfg | 79 ++++++++++++++++++++++ projectfiles/CodeBlocks/wesnoth.cbp | 4 +- source_lists/wesnoth | 2 +- src/game_launcher.cpp | 6 +- src/gui/dialogs/outro.cpp | 100 ++++++++++++++++++++++++++++ src/gui/dialogs/outro.hpp | 73 ++++++++++++++++++++ src/intro.cpp | 78 ---------------------- src/intro.hpp | 35 ---------- src/storyscreen/controller.cpp | 1 - src/storyscreen/interface.cpp | 1 - src/tests/gui/test_gui2.cpp | 3 + 11 files changed, 262 insertions(+), 120 deletions(-) create mode 100644 data/gui/window/outro.cfg create mode 100644 src/gui/dialogs/outro.cpp create mode 100644 src/gui/dialogs/outro.hpp delete mode 100644 src/intro.cpp delete mode 100644 src/intro.hpp diff --git a/data/gui/window/outro.cfg b/data/gui/window/outro.cfg new file mode 100644 index 000000000000..d80b90a6277e --- /dev/null +++ b/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] diff --git a/projectfiles/CodeBlocks/wesnoth.cbp b/projectfiles/CodeBlocks/wesnoth.cbp index 2b9dde1a1908..f095bcec61ef 100644 --- a/projectfiles/CodeBlocks/wesnoth.cbp +++ b/projectfiles/CodeBlocks/wesnoth.cbp @@ -643,6 +643,8 @@ + + @@ -817,8 +819,6 @@ - - diff --git a/source_lists/wesnoth b/source_lists/wesnoth index 24d0650b0dc6..11704ae686f9 100644 --- a/source_lists/wesnoth +++ b/source_lists/wesnoth @@ -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 diff --git a/src/game_launcher.cpp b/src/game_launcher.cpp index 79edf58c092c..6d18d37d93e1 100644 --- a/src/game_launcher.cpp +++ b/src/game_launcher.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); } diff --git a/src/gui/dialogs/outro.cpp b/src/gui/dialogs/outro.cpp new file mode 100644 index 000000000000..db739f87b028 --- /dev/null +++ b/src/gui/dialogs/outro.cpp @@ -0,0 +1,100 @@ +/* + Copyright (C) 2017 by Charles Dang + 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 diff --git a/src/gui/dialogs/outro.hpp b/src/gui/dialogs/outro.hpp new file mode 100644 index 000000000000..66be6e6684c6 --- /dev/null +++ b/src/gui/dialogs/outro.hpp @@ -0,0 +1,73 @@ +/* + Copyright (C) 2017 by Charles Dang + 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 diff --git a/src/intro.cpp b/src/intro.cpp deleted file mode 100644 index f0e1dfe87d44..000000000000 --- a/src/intro.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* - Copyright (C) 2003 - 2017 by David White - 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; - } -} diff --git a/src/intro.hpp b/src/intro.hpp deleted file mode 100644 index 67c91d905a9d..000000000000 --- a/src/intro.hpp +++ /dev/null @@ -1,35 +0,0 @@ -/* - Copyright (C) 2003 - 2017 by David White - 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 - -/** - * 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 */ diff --git a/src/storyscreen/controller.cpp b/src/storyscreen/controller.cpp index be8dc509080d..d0b0373b7580 100644 --- a/src/storyscreen/controller.cpp +++ b/src/storyscreen/controller.cpp @@ -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" diff --git a/src/storyscreen/interface.cpp b/src/storyscreen/interface.cpp index 29ba8248c8e4..551ef8635e77 100644 --- a/src/storyscreen/interface.cpp +++ b/src/storyscreen/interface.cpp @@ -27,7 +27,6 @@ #include "font/text.hpp" #include "gettext.hpp" -#include "intro.hpp" #include "language.hpp" #include "log.hpp" #include "sound.hpp" diff --git a/src/tests/gui/test_gui2.cpp b/src/tests/gui/test_gui2.cpp index 24a20946c0e3..69f5f7a1a0cf 100644 --- a/src/tests/gui/test_gui2.cpp +++ b/src/tests/gui/test_gui2.cpp @@ -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(); test(); //test(); + //test(); test(); test(); test(); @@ -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());