Added basic GUI2 end credits dialog (incomplete)

This commit is contained in:
Charles Dang 2016-09-11 18:52:48 +11:00
parent 865f7262f9
commit d0cae514ff
8 changed files with 261 additions and 1 deletions

View file

@ -0,0 +1,134 @@
#textdomain wesnoth-lib
###
### Definition of the credits screen
###
[window_definition]
id = "end_credits_window"
description = "The window definition for the credits screen."
[resolution]
[background]
[draw]
[image]
w = "(width)"
h = "(height)"
x = 0
y = 0
name = "(background_image)"
[/image]
[/draw]
[/background]
[foreground]
[draw]
[/draw]
[/foreground]
[/resolution]
[/window_definition]
[window]
id = "end_credits"
description = "End credits dialog."
[resolution]
definition = "end_credits_window"
{GUI_WINDOW_FULLSCREEN}
[tooltip]
id = "tooltip"
[/tooltip]
[helptip]
id = "tooltip"
[/helptip]
[grid]
[row]
grow_factor = 1
[column]
horizontal_grow = "true"
vertical_grow = "true"
border = "all"
border_size = 30
[panel]
definition = "box_display"
[grid]
[row]
[column]
horizontal_grow = "true"
vertical_grow = "true"
[scroll_label]
definition = "default_small"
id = "text"
horizontal_scrollbar_mode = "never"
[/scroll_label]
[/column]
[/row]
[/grid]
[/panel]
[/column]
[/row]
[row]
grow_factor = 0
[column]
grow_factor = 1
horizontal_alignment = "center"
border = "all"
border_size = 5
[button]
id = "cancel"
definition = "default"
label = _ "Close"
[/button]
[/column]
[/row]
[row]
grow_factor = 0
[column]
[spacer]
height = 10
[/spacer]
[/column]
[/row]
[/grid]
[/resolution]
[/window]

View file

@ -551,6 +551,8 @@
<Unit filename="../../src/gui/dialogs/editor/resize_map.hpp" />
<Unit filename="../../src/gui/dialogs/editor/set_starting_position.cpp" />
<Unit filename="../../src/gui/dialogs/editor/set_starting_position.hpp" />
<Unit filename="../../src/gui/dialogs/end_credits.cpp" />
<Unit filename="../../src/gui/dialogs/end_credits.hpp" />
<Unit filename="../../src/gui/dialogs/folder_create.cpp" />
<Unit filename="../../src/gui/dialogs/folder_create.hpp" />
<Unit filename="../../src/gui/dialogs/formula_debugger.cpp" />

View file

@ -805,6 +805,7 @@ set(wesnoth-main_SRC
gui/dialogs/editor/new_map.cpp
gui/dialogs/editor/resize_map.cpp
gui/dialogs/editor/set_starting_position.cpp
gui/dialogs/end_credits.cpp
gui/dialogs/folder_create.cpp
gui/dialogs/formula_debugger.cpp
gui/dialogs/game_cache_options.cpp

View file

@ -381,6 +381,7 @@ wesnoth_sources = Split("""
gui/dialogs/editor/new_map.cpp
gui/dialogs/editor/resize_map.cpp
gui/dialogs/editor/set_starting_position.cpp
gui/dialogs/end_credits.cpp
gui/dialogs/folder_create.cpp
gui/dialogs/formula_debugger.cpp
gui/dialogs/game_cache_options.cpp

View file

@ -36,6 +36,7 @@
#include "tstring.hpp" // for operator==
#include "video.hpp" // for update_rect, CVideo
#include "widgets/button.hpp" // for button
#include "gui/dialogs/end_credits.hpp"
#include <algorithm> // for max
#include <map> // for map, map<>::mapped_type
@ -229,6 +230,9 @@ void show_about(CVideo &video, const std::string &campaign)
surface map_image, map_image_scaled;
// TODO: enable
//gui2::tend_credits::display(text, image_list, video);
if(!image_list.empty()) {
map_image = image::get_image(image_list[0]);
} else {

View file

@ -0,0 +1,63 @@
/*
Copyright (C) 2016 by 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/end_credits.hpp"
#include "game_config.hpp"
#include "gui/auxiliary/find_widget.hpp"
#include "gui/widgets/settings.hpp"
#include "gui/widgets/scroll_label.hpp"
#include "gui/widgets/window.hpp"
#include "formatter.hpp"
#include "marked-up_text.hpp"
namespace gui2
{
REGISTER_DIALOG(end_credits)
tend_credits::tend_credits(const std::vector<std::string>& text, const std::vector<std::string>& backgrounds)
: text_(text)
, backgrounds_(backgrounds)
{
if(backgrounds_.empty()) {
backgrounds_.push_back(game_config::images::game_title_background);
}
}
void tend_credits::pre_show(twindow& window)
{
// TODO: apparently, multiple images are supported... need to implement along with scrolling
window.canvas()[0].set_variable("background_image", variant(backgrounds_[0]));
std::stringstream str;
// BIG FAT TODO: get rid of this hacky string crap once we drop the GUI1 version
for(const auto& line : text_) {
if(line[0] == '-') {
str << font::escape_text(line.substr(1)) << "\n";
} else if(line[0] == '+') {
str << "<big>" << font::escape_text(line.substr(1)) << "</big>" << "\n";
}
}
tscroll_label& text = find_widget<tscroll_label>(&window, "text", false);
text.set_text_alignment(PangoAlignment::PANGO_ALIGN_CENTER);
text.set_use_markup(true);
text.set_label(str.str());
}
}

View file

@ -0,0 +1,52 @@
/*
Copyright (C) 2016 by 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_END_CREDITS_HPP_INCLUDED
#define GUI_DIALOGS_END_CREDITS_HPP_INCLUDED
#include "gui/dialogs/dialog.hpp"
#include <memory>
#include <string>
#include <vector>
class display;
namespace gui2
{
class tend_credits : public tdialog
{
public:
tend_credits(const std::vector<std::string>& text, const std::vector<std::string>& backgrounds);
static void display(const std::vector<std::string>& text, const std::vector<std::string>& backgrounds, CVideo& video)
{
tend_credits(text, backgrounds).show(video);
}
private:
/** Inherited from tdialog, implemented by REGISTER_DIALOG. */
virtual const std::string& window_id() const;
/** Inherited from tdialog. */
void pre_show(twindow& window);
const std::vector<std::string>& text_;
std::vector<std::string> backgrounds_;
};
} // namespace gui2
#endif /* ! GUI_DIALOGS_END_CREDITS_HPP_INCLUDED */

View file

@ -50,6 +50,7 @@
#include "gui/dialogs/editor/new_map.hpp"
#include "gui/dialogs/editor/resize_map.hpp"
#include "gui/dialogs/editor/set_starting_position.hpp"
#include "gui/dialogs/end_credits.hpp"
#include "gui/dialogs/folder_create.hpp"
#include "gui/dialogs/formula_debugger.hpp"
#include "gui/dialogs/game_cache_options.hpp"
@ -437,6 +438,7 @@ BOOST_AUTO_TEST_CASE(test_gui2)
test<gui2::teditor_edit_label>();
test<gui2::teditor_edit_side>();
test<gui2::teditor_edit_scenario>();
//test<gui2::tend_credits>();
test<gui2::tcore_selection>();
//test<gui2::tlua_interpreter>(& lua_kernel_base());
@ -479,7 +481,8 @@ BOOST_AUTO_TEST_CASE(test_gui2)
"mp_host_game_prompt",
"mp_create_game",
// The title screen appears to be throwing a bad_alloc on Travis, so disable it for now
"title_screen"
"title_screen",
"end_credits",
};
std::sort(list.begin(), list.end());
std::sort(omitted.begin(), omitted.end());