Initial implementation of GUI2 story viewer
This commit is contained in:
parent
dd41514ea8
commit
1cf90d02d6
8 changed files with 423 additions and 4 deletions
205
data/gui/window/story_viewer.cfg
Normal file
205
data/gui/window/story_viewer.cfg
Normal file
|
@ -0,0 +1,205 @@
|
|||
#textdomain wesnoth-lib
|
||||
|
||||
#define _GUI_TEXT_PANEL
|
||||
[panel]
|
||||
id = "text_panel"
|
||||
definition = "wml_message"
|
||||
|
||||
[grid]
|
||||
|
||||
[row]
|
||||
grow_factor = 0
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
border = "all"
|
||||
border_size = 10
|
||||
horizontal_grow = true
|
||||
vertical_grow = true
|
||||
|
||||
[label]
|
||||
definition = "default"
|
||||
id = "part_text"
|
||||
|
||||
wrap = true
|
||||
use_markup = true
|
||||
[/label]
|
||||
[/column]
|
||||
|
||||
[column]
|
||||
grow_factor = 0
|
||||
horizontal_alignment = "right"
|
||||
vertical_alignment = "bottom"
|
||||
|
||||
[grid]
|
||||
|
||||
# TODO: proper layout
|
||||
[row]
|
||||
|
||||
[column]
|
||||
border = "all"
|
||||
border_size = 10
|
||||
|
||||
[button]
|
||||
id = "next"
|
||||
definition = "default"
|
||||
label = _ "Next"
|
||||
[/button]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[row]
|
||||
|
||||
[column]
|
||||
border = "all"
|
||||
border_size = 10
|
||||
|
||||
[button]
|
||||
id = "back"
|
||||
definition = "default"
|
||||
label = _ "Back"
|
||||
[/button]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[row]
|
||||
|
||||
[column]
|
||||
border = "all"
|
||||
border_size = 10
|
||||
|
||||
[button]
|
||||
id = "cancel"
|
||||
definition = "default"
|
||||
label = _ "Skip"
|
||||
[/button]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[/grid]
|
||||
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[/grid]
|
||||
|
||||
[/panel]
|
||||
#enddef
|
||||
|
||||
[window_definition]
|
||||
id = "storyscreen"
|
||||
description = "The window definition for the story screen."
|
||||
|
||||
[resolution]
|
||||
|
||||
[background]
|
||||
|
||||
[draw]
|
||||
|
||||
[rectangle]
|
||||
x = 0
|
||||
y = 0
|
||||
w = "(width)"
|
||||
h = "(height)"
|
||||
|
||||
fill_color = "0, 0, 0, 255"
|
||||
[/rectangle]
|
||||
|
||||
[image]
|
||||
x = 0
|
||||
y = 0
|
||||
w = "(width)"
|
||||
h = "(height)"
|
||||
|
||||
name = "(background_image)"
|
||||
[/image]
|
||||
|
||||
[/draw]
|
||||
|
||||
[/background]
|
||||
|
||||
[foreground]
|
||||
|
||||
[draw]
|
||||
|
||||
[/draw]
|
||||
|
||||
[/foreground]
|
||||
|
||||
[/resolution]
|
||||
|
||||
[/window_definition]
|
||||
|
||||
[window]
|
||||
id = "story_viewer"
|
||||
description = "Story screen browser"
|
||||
|
||||
[resolution]
|
||||
definition = "storyscreen"
|
||||
|
||||
{GUI_WINDOW_FULLSCREEN}
|
||||
|
||||
[tooltip]
|
||||
id = "tooltip_large"
|
||||
[/tooltip]
|
||||
|
||||
[helptip]
|
||||
id = "tooltip_large"
|
||||
[/helptip]
|
||||
|
||||
[linked_group]
|
||||
id = "images"
|
||||
fixed_width = true
|
||||
[/linked_group]
|
||||
|
||||
[linked_group]
|
||||
id = "names"
|
||||
fixed_width = true
|
||||
[/linked_group]
|
||||
|
||||
[grid]
|
||||
|
||||
[row]
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_grow = true
|
||||
|
||||
[label]
|
||||
definition = "title"
|
||||
id = "title"
|
||||
label = "Placeholder text"
|
||||
[/label]
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[row]
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
horizontal_grow = true
|
||||
vertical_alignment = "bottom"
|
||||
|
||||
{GUI_FORCE_WIDGET_MINIMUM_SIZE 0 ("(screen_height / 4)") (
|
||||
{_GUI_TEXT_PANEL}
|
||||
)}
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[/grid]
|
||||
|
||||
[/resolution]
|
||||
|
||||
[/window]
|
|
@ -653,6 +653,8 @@
|
|||
<Unit filename="../../src/gui/dialogs/sp_options_configure.hpp" />
|
||||
<Unit filename="../../src/gui/dialogs/statistics_dialog.cpp" />
|
||||
<Unit filename="../../src/gui/dialogs/statistics_dialog.hpp" />
|
||||
<Unit filename="../../src/gui/dialogs/story_viewer.cpp" />
|
||||
<Unit filename="../../src/gui/dialogs/story_viewer.hpp" />
|
||||
<Unit filename="../../src/gui/dialogs/terrain_layers.cpp" />
|
||||
<Unit filename="../../src/gui/dialogs/terrain_layers.hpp" />
|
||||
<Unit filename="../../src/gui/dialogs/theme_list.cpp" />
|
||||
|
|
|
@ -231,6 +231,7 @@ gui/dialogs/select_orb_colors.cpp
|
|||
gui/dialogs/simple_item_selector.cpp
|
||||
gui/dialogs/sp_options_configure.cpp
|
||||
gui/dialogs/statistics_dialog.cpp
|
||||
gui/dialogs/story_viewer.cpp
|
||||
gui/dialogs/terrain_layers.cpp
|
||||
gui/dialogs/theme_list.cpp
|
||||
gui/dialogs/title_screen.cpp
|
||||
|
|
108
src/gui/dialogs/story_viewer.cpp
Normal file
108
src/gui/dialogs/story_viewer.cpp
Normal file
|
@ -0,0 +1,108 @@
|
|||
/*
|
||||
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/story_viewer.hpp"
|
||||
|
||||
#include "formula/variant.hpp"
|
||||
#include "gui/auxiliary/find_widget.hpp"
|
||||
#include "gui/widgets/button.hpp"
|
||||
#include "gui/widgets/image.hpp"
|
||||
#include "gui/widgets/label.hpp"
|
||||
#include "gui/widgets/scroll_label.hpp"
|
||||
#include "gui/widgets/settings.hpp"
|
||||
#include "gui/widgets/settings.hpp"
|
||||
#include "gui/widgets/window.hpp"
|
||||
|
||||
namespace gui2
|
||||
{
|
||||
namespace dialogs
|
||||
{
|
||||
|
||||
REGISTER_DIALOG(story_viewer)
|
||||
|
||||
story_viewer::story_viewer(storyscreen::controller& controller)
|
||||
: controller_(controller)
|
||||
, part_index_(0)
|
||||
, current_part_()
|
||||
{
|
||||
update_current_part_ptr();
|
||||
}
|
||||
|
||||
void story_viewer::pre_show(window& window)
|
||||
{
|
||||
window.set_enter_disabled(true);
|
||||
|
||||
// Special callback to make Enter advance to the next part.
|
||||
connect_signal_pre_key_press(window, std::bind(&story_viewer::key_press_callback, this, std::ref(window), _5));
|
||||
|
||||
connect_signal_mouse_left_click(find_widget<button>(&window, "next", false),
|
||||
std::bind(&story_viewer::nav_button_callback, this, std::ref(window), DIR_FORWARD));
|
||||
|
||||
connect_signal_mouse_left_click(find_widget<button>(&window, "back", false),
|
||||
std::bind(&story_viewer::nav_button_callback, this, std::ref(window), DIR_BACKWARDS));
|
||||
|
||||
display_part(window);
|
||||
}
|
||||
|
||||
void story_viewer::update_current_part_ptr()
|
||||
{
|
||||
current_part_ = controller_.get_part(part_index_);
|
||||
}
|
||||
|
||||
void story_viewer::display_part(window& window)
|
||||
{
|
||||
// TODO: handle all layers
|
||||
const std::string bg = current_part_->get_background_layers()[0].file();
|
||||
|
||||
window.get_canvas(0).set_variable("background_image", variant(bg));
|
||||
|
||||
find_widget<label>(&window, "title", false).set_label(current_part_->title());
|
||||
find_widget<label>(&window, "part_text", false).set_label(current_part_->text());
|
||||
|
||||
// Needed to make the background redraw correctly.
|
||||
window.set_is_dirty(true);
|
||||
}
|
||||
|
||||
void story_viewer::nav_button_callback(window& window, NAV_DIRECTION direction)
|
||||
{
|
||||
part_index_ = (direction == DIR_FORWARD ? part_index_ + 1 : part_index_ -1);
|
||||
|
||||
// If we've viewed all the parts, close the dialog.
|
||||
if(part_index_ == controller_.max_parts()) {
|
||||
window.close();
|
||||
return;
|
||||
}
|
||||
|
||||
if(part_index_ < 0) {
|
||||
part_index_ = 0;
|
||||
}
|
||||
|
||||
// TODO: disable buttons
|
||||
|
||||
update_current_part_ptr();
|
||||
|
||||
display_part(window);
|
||||
}
|
||||
|
||||
void story_viewer::key_press_callback(window& window, const SDL_Keycode key)
|
||||
{
|
||||
if(key == SDLK_RETURN) {
|
||||
nav_button_callback(window, DIR_FORWARD);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace dialogs
|
||||
} // namespace gui2
|
73
src/gui/dialogs/story_viewer.hpp
Normal file
73
src/gui/dialogs/story_viewer.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_story_viewer_HPP_INCLUDED
|
||||
#define GUI_DIALOGS_story_viewer_HPP_INCLUDED
|
||||
|
||||
#include "gui/dialogs/modal_dialog.hpp"
|
||||
|
||||
#include "storyscreen/controller.hpp"
|
||||
#include "storyscreen/part.hpp"
|
||||
|
||||
#include "config.hpp"
|
||||
|
||||
class CVideo;
|
||||
|
||||
namespace gui2
|
||||
{
|
||||
namespace dialogs
|
||||
{
|
||||
|
||||
/** Dialog to view the storyscreen. */
|
||||
class story_viewer : public modal_dialog
|
||||
{
|
||||
public:
|
||||
story_viewer(storyscreen::controller& controller);
|
||||
|
||||
static void display(storyscreen::controller& controller, CVideo& video)
|
||||
{
|
||||
story_viewer(controller).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);
|
||||
|
||||
void update_current_part_ptr();
|
||||
|
||||
void display_part(window& window);
|
||||
|
||||
enum NAV_DIRECTION {
|
||||
DIR_FORWARD,
|
||||
DIR_BACKWARDS
|
||||
};
|
||||
|
||||
void nav_button_callback(window& window, NAV_DIRECTION direction);
|
||||
|
||||
void key_press_callback(window& window, const SDL_Keycode key);
|
||||
|
||||
storyscreen::controller controller_;
|
||||
|
||||
int part_index_;
|
||||
|
||||
storyscreen::controller::part_pointer_type current_part_;
|
||||
};
|
||||
|
||||
} // namespace dialogs
|
||||
} // namespace gui2
|
||||
|
||||
#endif
|
|
@ -41,6 +41,9 @@ class floating_image;
|
|||
class controller
|
||||
{
|
||||
public:
|
||||
typedef std::shared_ptr< part > part_pointer_type;
|
||||
typedef std::shared_ptr< part_ui > render_pointer_type;
|
||||
|
||||
controller(CVideo& video, const vconfig& data, const std::string& scenario_name,
|
||||
int segment_index);
|
||||
|
||||
|
@ -49,10 +52,17 @@ public:
|
|||
*/
|
||||
STORY_RESULT show(START_POSITION startpos=START_BEGINNING);
|
||||
|
||||
private:
|
||||
typedef std::shared_ptr< part > part_pointer_type;
|
||||
typedef std::shared_ptr< part_ui > render_pointer_type;
|
||||
part_pointer_type get_part(int index) const
|
||||
{
|
||||
return parts_[index];
|
||||
}
|
||||
|
||||
int max_parts() const
|
||||
{
|
||||
return parts_.size();
|
||||
}
|
||||
|
||||
private:
|
||||
// Executes WML flow instructions and inserts parts.
|
||||
void resolve_wml(const vconfig& cfg);
|
||||
|
||||
|
|
|
@ -22,6 +22,9 @@
|
|||
#include "storyscreen/interface.hpp"
|
||||
#include "storyscreen/controller.hpp"
|
||||
|
||||
#include "gui/widgets/settings.hpp"
|
||||
#include "gui/dialogs/story_viewer.hpp"
|
||||
|
||||
#include "font/text.hpp"
|
||||
#include "gettext.hpp"
|
||||
#include "intro.hpp"
|
||||
|
@ -36,7 +39,21 @@ static lg::log_domain log_engine("engine");
|
|||
void show_story(CVideo& video, const std::string &scenario_name,
|
||||
const config::const_child_itors &story)
|
||||
{
|
||||
events::event_context story_context;
|
||||
if(gui2::new_widgets) {
|
||||
// Combine all the [story] tags into a single config
|
||||
config cfg;
|
||||
for(const auto& iter : story) {
|
||||
cfg.append_children(iter);
|
||||
}
|
||||
|
||||
storyscreen::controller controller(video, vconfig(cfg, true), scenario_name, 0);
|
||||
|
||||
gui2::dialogs::story_viewer::display(controller, video);
|
||||
|
||||
video2::trigger_full_redraw();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int segment_count = 0;
|
||||
config::const_child_iterator itor = story.begin();
|
||||
|
|
|
@ -93,6 +93,7 @@
|
|||
#include "gui/dialogs/select_orb_colors.hpp"
|
||||
#include "gui/dialogs/sp_options_configure.hpp"
|
||||
#include "gui/dialogs/statistics_dialog.hpp"
|
||||
#include "gui/dialogs/story_viewer.hpp"
|
||||
#include "gui/dialogs/theme_list.hpp"
|
||||
#include "gui/dialogs/terrain_layers.hpp"
|
||||
#include "gui/dialogs/title_screen.hpp"
|
||||
|
@ -453,6 +454,7 @@ BOOST_AUTO_TEST_CASE(test_gui2)
|
|||
test<select_orb_colors>();
|
||||
test<sp_options_configure>();
|
||||
test<statistics_dialog>();
|
||||
//test<story_viewer>();
|
||||
test<theme_list>();
|
||||
//test<terrain_layers>();
|
||||
//test<title_screen>();
|
||||
|
@ -512,6 +514,7 @@ BOOST_AUTO_TEST_CASE(test_gui2)
|
|||
"terrain_layers",
|
||||
"attack_predictions",
|
||||
"help_browser",
|
||||
"story_viewer",
|
||||
};
|
||||
std::sort(list.begin(), list.end());
|
||||
std::sort(omitted.begin(), omitted.end());
|
||||
|
|
Loading…
Add table
Reference in a new issue