More stuff for the storyscreen code refactoring.
The code at the moment is sketchy and messy; this will change later.
This commit is contained in:
parent
40e3dd8d13
commit
089f42d488
10 changed files with 460 additions and 34 deletions
|
@ -307,6 +307,8 @@ SET(wesnoth-main_SRC
|
|||
statistics.cpp
|
||||
statistics_dialog.cpp
|
||||
storyscreen.cpp
|
||||
storyscreen_controller.cpp
|
||||
storyscreen_page.cpp
|
||||
team.cpp
|
||||
terrain_filter.cpp
|
||||
time_of_day.cpp
|
||||
|
|
|
@ -144,6 +144,8 @@ wesnoth_source = \
|
|||
statistics.cpp \
|
||||
statistics_dialog.cpp \
|
||||
storyscreen.cpp \
|
||||
storyscreen_controller.cpp \
|
||||
storyscreen_page.cpp \
|
||||
team.cpp \
|
||||
terrain_filter.cpp \
|
||||
text.cpp \
|
||||
|
|
|
@ -199,6 +199,8 @@ wesnoth_sources = Split("""
|
|||
statistics.cpp
|
||||
statistics_dialog.cpp
|
||||
storyscreen.cpp
|
||||
storyscreen_controller.cpp
|
||||
storyscreen_page.cpp
|
||||
team.cpp
|
||||
terrain_filter.cpp
|
||||
time_of_day.cpp
|
||||
|
|
|
@ -17,8 +17,6 @@
|
|||
* Introduction sequence at start of a scenario, End-screen after end of
|
||||
* campaign.
|
||||
*/
|
||||
|
||||
// Do not remove the #ifndef below. See storyscreen.hpp.
|
||||
#ifndef SHADOWM_STORYSCREEN
|
||||
|
||||
#include "global.hpp"
|
||||
|
|
|
@ -13,17 +13,21 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
// This code is work in progress, and shouldn't be enabled for production
|
||||
// builds. It is supposed to completely replace the old story screens code
|
||||
// at intro.cpp, introducing new WML conventions while at it.
|
||||
//
|
||||
// Do not remove the #ifdef below.
|
||||
/**
|
||||
* @file storyscreen.cpp
|
||||
* This code is work in progress, and shouldn't be enabled for production
|
||||
* builds. It is supposed to completely replace the old story screens code
|
||||
* at intro.cpp, introducing new WML conventions while at it.
|
||||
*/
|
||||
#ifdef SHADOWM_STORYSCREEN
|
||||
|
||||
#include "global.hpp"
|
||||
#include "foreach.hpp"
|
||||
#include "variable.hpp"
|
||||
|
||||
#include "storyscreen.hpp"
|
||||
#include "storyscreen_controller.hpp"
|
||||
|
||||
#include "display.hpp"
|
||||
#include "game_events.hpp"
|
||||
#include "gamestatus.hpp"
|
||||
|
@ -39,34 +43,23 @@
|
|||
#define ERR_DI LOG_STREAM(err , display)
|
||||
|
||||
// TODO: remove when completed
|
||||
#include "boost/current_function.hpp"
|
||||
#define STUB() \
|
||||
std::cerr << "OUCH: entered stub " << BOOST_CURRENT_FUNCTION << " [at " << __FILE__ << ":" << __LINE__ << "]\n"
|
||||
|
||||
class storyscreen
|
||||
{
|
||||
public:
|
||||
storyscreen(display& disp, const vconfig& data, const config& scenario_cfg);
|
||||
|
||||
private:
|
||||
display& disp_;
|
||||
vconfig data_;
|
||||
config scenario_;
|
||||
};
|
||||
#include "stub.hpp"
|
||||
|
||||
namespace {
|
||||
void write_generic_endscreen_config(config& append_to_cfg)
|
||||
void generate_endscreen_page_config(config& append_to_cfg)
|
||||
{
|
||||
config& partcfg = append_to_cfg.add_child("story").add_child("page");
|
||||
partcfg["text_align"] = "centered";
|
||||
}
|
||||
} // end anonymous namespace
|
||||
|
||||
void show_storyscreen(display& disp, const vconfig& data, const config& scenario_cfg)
|
||||
void show_storyscreen(display& disp, const vconfig& story_cfg, const std::string& scenario_name)
|
||||
{
|
||||
STUB();
|
||||
LOG_NG << "entering storyscreen procedure...\n";
|
||||
|
||||
storyscreen::controller ctl(disp, story_cfg, scenario_name);
|
||||
|
||||
// FIXME: stub!
|
||||
|
||||
LOG_NG << "leaving storyscreen procedure...\n";
|
||||
|
@ -77,6 +70,8 @@ void show_endscreen(display& disp, const t_string& text, unsigned int duration)
|
|||
STUB();
|
||||
LOG_NG << "show_endscreen() invoked...\n";
|
||||
|
||||
config story_cfg;
|
||||
|
||||
// FIXME: stub!
|
||||
|
||||
LOG_NG << "show_endscreen() completed...\n";
|
||||
|
@ -85,7 +80,8 @@ void show_endscreen(display& disp, const t_string& text, unsigned int duration)
|
|||
// Trivial drop-in compatibility with intro.cpp
|
||||
void show_intro(display &disp, const vconfig& data, const config& level)
|
||||
{
|
||||
show_storyscreen(disp,data,level);
|
||||
const std::string scenario_name = level["name"];
|
||||
show_storyscreen(disp,data,scenario_name);
|
||||
}
|
||||
|
||||
void the_end(display &disp, std::string text, unsigned int duration)
|
||||
|
|
|
@ -13,14 +13,13 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
/** @file storyscreen.hpp */
|
||||
// FIXME: textscreen.[ch]pp ??
|
||||
|
||||
// This code is work in progress, and shouldn't be enabled for production
|
||||
// builds. It is supposed to completely replace the old story screens code
|
||||
// at intro.cpp, introducing new WML conventions while at it.
|
||||
//
|
||||
// Do not remove the #ifdef below.
|
||||
/**
|
||||
* @file storyscreen.hpp
|
||||
* This code is work in progress, and shouldn't be enabled for production
|
||||
* builds. It is supposed to completely replace the old story screens code
|
||||
* at intro.cpp, introducing new WML conventions while at it.
|
||||
*/
|
||||
#ifdef SHADOWM_STORYSCREEN
|
||||
|
||||
#ifndef STORYSCREEN_HPP_INCLUDED
|
||||
|
@ -30,13 +29,12 @@ class config;
|
|||
class vconfig;
|
||||
class display;
|
||||
class t_string;
|
||||
#include "SDL.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
/**
|
||||
* Function to show an introduction sequence using story WML.
|
||||
* The WML config data has a format similar to:
|
||||
* The WML config data (story_cfg) has a format similar to:
|
||||
* @code
|
||||
* [part]
|
||||
* id='id'
|
||||
|
@ -49,7 +47,7 @@ class t_string;
|
|||
* be displayed in turn, with the user able to go to the next part, or skip
|
||||
* it entirely.
|
||||
*/
|
||||
void show_storyscreen(display& disp, const vconfig& data, const config& scenario_cfg);
|
||||
void show_storyscreen(display& disp, const vconfig& story_cfg, const std::string& scenario_name);
|
||||
|
||||
/**
|
||||
* Displays a simple fading screen with any user-provided text.
|
||||
|
|
102
src/storyscreen_controller.cpp
Normal file
102
src/storyscreen_controller.cpp
Normal file
|
@ -0,0 +1,102 @@
|
|||
/* $Id$ */
|
||||
/*
|
||||
Copyright (C) 2003 - 2009 by David White <dave@whitevine.net>
|
||||
Copyright (C) 2009 by Ignacio R. Morelle <shadowm2006@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 version 2
|
||||
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.
|
||||
*/
|
||||
|
||||
// FIXME: textscreen.[ch]pp ??
|
||||
/**
|
||||
* @file storyscreen_controller.cpp
|
||||
* This code is work in progress, and shouldn't be enabled for production
|
||||
* builds. It is supposed to completely replace the old story screens code
|
||||
* at intro.cpp, introducing new WML conventions while at it.
|
||||
*/
|
||||
#ifdef SHADOWM_STORYSCREEN
|
||||
|
||||
#include "global.hpp"
|
||||
#include "SDL.h"
|
||||
|
||||
#include "storyscreen_controller.hpp"
|
||||
#include "storyscreen_page.hpp"
|
||||
|
||||
#include "asserts.hpp"
|
||||
#include "foreach.hpp"
|
||||
#include "variable.hpp"
|
||||
|
||||
#include "display.hpp"
|
||||
#include "game_events.hpp"
|
||||
#include "gamestatus.hpp"
|
||||
#include "gettext.hpp"
|
||||
#include "intro.hpp"
|
||||
#include "language.hpp"
|
||||
#include "log.hpp"
|
||||
#include "sound.hpp"
|
||||
#include "text.hpp"
|
||||
|
||||
#define ERR_NG LOG_STREAM(err , engine)
|
||||
#define LOG_NG LOG_STREAM(info, engine)
|
||||
#define ERR_DI LOG_STREAM(err , display)
|
||||
|
||||
// TODO: remove when completed
|
||||
#include "stub.hpp"
|
||||
|
||||
namespace storyscreen {
|
||||
|
||||
controller::controller(display& disp, const vconfig& data, const std::string& scenario_name)
|
||||
: disp_(disp)
|
||||
, disp_resize_lock_()
|
||||
, evt_context_()
|
||||
, data_(data)
|
||||
, scenario_name_(scenario_name)
|
||||
, pages_()
|
||||
, gamestate_(game_events::get_state_of_game())
|
||||
{
|
||||
ASSERT_LOG(gamestate_ != NULL, "Ouch: gamestate is NULL when initializing storyscreen controller");
|
||||
build_pages();
|
||||
}
|
||||
|
||||
controller::~controller()
|
||||
{
|
||||
clear_pages();
|
||||
}
|
||||
|
||||
void controller::build_pages()
|
||||
{
|
||||
|
||||
|
||||
for(vconfig::all_children_iterator i = data_.ordered_begin(); i != data_.ordered_end(); i++) {
|
||||
const std::pair<const std::string, const vconfig> item = *i;
|
||||
|
||||
if(item.first == "page" && !item.second.empty()) {
|
||||
vconfig cfg = item.second;
|
||||
// Use scenario name as page title if the WML doesn't supply a custom one.
|
||||
// if(cfg["title"].empty()) {
|
||||
// cfg["title"] = scenario_name_;
|
||||
// }
|
||||
|
||||
page* story_page = new page(*gamestate_, cfg);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void controller::clear_pages()
|
||||
{
|
||||
foreach(page* p, pages_) {
|
||||
delete p;
|
||||
}
|
||||
pages_.clear();
|
||||
}
|
||||
|
||||
} // end namespace storyscreen
|
||||
|
||||
#endif /* SHADOWM_STORYSCREEN */
|
81
src/storyscreen_controller.hpp
Normal file
81
src/storyscreen_controller.hpp
Normal file
|
@ -0,0 +1,81 @@
|
|||
/* $Id$ */
|
||||
/*
|
||||
Copyright (C) 2003 - 2009 by David White <dave@whitevine.net>
|
||||
Copyright (C) 2009 by Ignacio R. Morelle <shadowm2006@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 version 2
|
||||
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.
|
||||
*/
|
||||
|
||||
// FIXME: textscreen.[ch]pp ??
|
||||
/**
|
||||
* @file storyscreen_controller.hpp
|
||||
* This code is work in progress, and shouldn't be enabled for production
|
||||
* builds. It is supposed to completely replace the old story screens code
|
||||
* at intro.cpp, introducing new WML conventions while at it.
|
||||
*/
|
||||
#ifdef SHADOWM_STORYSCREEN
|
||||
|
||||
#ifndef STORYSCREEN_CONTROLLER_HPP_INCLUDED
|
||||
#define STORYSCREEN_CONTROLLER_HPP_INCLUDED
|
||||
|
||||
#include "events.hpp"
|
||||
#include "variable.hpp"
|
||||
#include "video.hpp"
|
||||
|
||||
class display;
|
||||
class game_state;
|
||||
// class vconfig;
|
||||
|
||||
namespace storyscreen {
|
||||
|
||||
class page;
|
||||
class floating_image;
|
||||
|
||||
class controller
|
||||
{
|
||||
public:
|
||||
controller(display& disp, const vconfig& data, const std::string& scenario_name);
|
||||
~controller();
|
||||
|
||||
/**
|
||||
* Display story screen pages.
|
||||
*/
|
||||
void show_all_pages() const;
|
||||
|
||||
|
||||
private:
|
||||
// Used by ctor; processes possible WML branching instructions
|
||||
// ([if]/[else] and [switch]) and builds the page cache.
|
||||
void build_pages();
|
||||
// Used by dtor.
|
||||
void clear_pages();
|
||||
|
||||
display& disp_;
|
||||
const resize_lock disp_resize_lock_;
|
||||
const events::event_context evt_context_;
|
||||
|
||||
vconfig data_;
|
||||
std::string scenario_name_;
|
||||
|
||||
// The page cache.
|
||||
std::vector<page*> pages_;
|
||||
|
||||
// The state of the world.
|
||||
game_state* gamestate_;
|
||||
|
||||
public:
|
||||
struct no_pages {};
|
||||
|
||||
};
|
||||
|
||||
} // end namespace storyscreen
|
||||
|
||||
#endif /* ! STORYSCREEN_CONTROLLER_HPP_INCLUDED */
|
||||
#endif /* SHADOWM_STORYSCREEN */
|
142
src/storyscreen_page.cpp
Normal file
142
src/storyscreen_page.cpp
Normal file
|
@ -0,0 +1,142 @@
|
|||
/* $Id$ */
|
||||
/*
|
||||
Copyright (C) 2009 by Ignacio R. Morelle <shadowm2006@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 version 2
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifdef SHADOWM_STORYSCREEN
|
||||
#include "global.hpp"
|
||||
#include "asserts.hpp"
|
||||
#include "log.hpp"
|
||||
#include "storyscreen_page.hpp"
|
||||
|
||||
#include "config.hpp"
|
||||
#include "gamestatus.hpp"
|
||||
#include "game_events.hpp"
|
||||
#include "serialization/string_utils.hpp"
|
||||
#include "util.hpp"
|
||||
#include "variable.hpp"
|
||||
|
||||
// TODO: remove when completed
|
||||
#include "stub.hpp"
|
||||
|
||||
namespace storyscreen {
|
||||
|
||||
floating_image::floating_image(const config& cfg)
|
||||
: file_(cfg["file"])
|
||||
, x_(lexical_cast_default<int>(cfg["x"]))
|
||||
, y_(lexical_cast_default<int>(cfg["y"]))
|
||||
, delay_(lexical_cast_default<int>(cfg["delay"]))
|
||||
, autoscaled_(utils::string_bool(cfg["scaled"], false))
|
||||
, centered_(utils::string_bool(cfg["centered"], false))
|
||||
{
|
||||
}
|
||||
|
||||
page::page(game_state& state_of_game, const vconfig& page_cfg)
|
||||
: scale_background_(utils::string_bool(page_cfg["scale_background"], true))
|
||||
, background_file_(page_cfg["background"])
|
||||
, show_title_(utils::string_bool(page_cfg["show_title"], false))
|
||||
, text_(page_cfg["story"])
|
||||
, text_title_(page_cfg["title"])
|
||||
, text_block_loc_(string_tblock_loc(page_cfg["text_layout"]))
|
||||
, music_(page_cfg["music"])
|
||||
, floating_images_()
|
||||
{
|
||||
resolve_wml(page_cfg);
|
||||
}
|
||||
|
||||
page::TEXT_BLOCK_LOCATION page::string_tblock_loc(const std::string& s)
|
||||
{
|
||||
if(s.empty() != true) {
|
||||
if(s == "top") {
|
||||
return page::TOP;
|
||||
}
|
||||
else if(s == "middle" || s == "center") {
|
||||
return page::MIDDLE;
|
||||
}
|
||||
}
|
||||
|
||||
return page::BOTTOM;
|
||||
}
|
||||
|
||||
void page::resolve_wml(const vconfig& page_cfg)
|
||||
{
|
||||
STUB();
|
||||
for(vconfig::all_children_iterator i = page_cfg.ordered_begin(); i != page_cfg.ordered_end(); ++ i) {
|
||||
const std::pair<const std::string, const vconfig> xi = *i;
|
||||
if(xi.first == "image") {
|
||||
floating_images_.push_back(xi.second.get_parsed_config());
|
||||
}
|
||||
else if(xi.first == "if") {
|
||||
const std::string type = game_events::conditional_passed(
|
||||
NULL, xi.second) ? "then":"else";
|
||||
const vconfig branch = xi.second.child(type);
|
||||
if(!branch.empty()) {
|
||||
if(branch.has_attribute("background")) {
|
||||
this->background_file_ = branch["background"];
|
||||
}
|
||||
if(branch.has_attribute("scale_background")) {
|
||||
this->scale_background_ = utils::string_bool(branch["scale_background"], true);
|
||||
}
|
||||
if(branch.has_attribute("show_title")) {
|
||||
this->show_title_ = utils::string_bool(branch["show_title"], false);
|
||||
}
|
||||
if(branch.has_attribute("title")) {
|
||||
this->text_title_ = branch["title"];
|
||||
}
|
||||
if(branch.has_attribute("story")) {
|
||||
this->text_ = branch["story"];
|
||||
}
|
||||
if(branch.has_attribute("text_layout")) {
|
||||
this->text_block_loc_ = string_tblock_loc(branch["text_layout"]);
|
||||
}
|
||||
if(branch.has_attribute("music")) {
|
||||
this->text_ = branch["music"];
|
||||
}
|
||||
|
||||
// TODO recursive eval
|
||||
// TODO image stack
|
||||
|
||||
}
|
||||
}
|
||||
else if(xi.first == "switch") {
|
||||
}
|
||||
else if(xi.first == "deprecated_message") {
|
||||
const std::string dmsg = (xi.second)["message"];
|
||||
if(!dmsg.empty()) {
|
||||
lg::wml_error << dmsg << '\n';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
floating_image::floating_image()
|
||||
: file_(), x_(0), y_(0), delay_(0), autoscaled_(false), centered_(false)
|
||||
{
|
||||
ASSERT_EQ(0xBAD,0xBEEF);
|
||||
}
|
||||
|
||||
page::page()
|
||||
: scale_background_()
|
||||
, background_file_()
|
||||
, show_title_()
|
||||
, text_()
|
||||
, text_title_()
|
||||
, text_block_loc_()
|
||||
, music_()
|
||||
, floating_images_()
|
||||
{
|
||||
ASSERT_EQ(0xDEAD,0xBEEF);
|
||||
}
|
||||
|
||||
} // end namespace storyscreen
|
||||
|
||||
#endif /* SHADOWM_STORYSCREEN */
|
103
src/storyscreen_page.hpp
Normal file
103
src/storyscreen_page.hpp
Normal file
|
@ -0,0 +1,103 @@
|
|||
/* $Id$ */
|
||||
/*
|
||||
Copyright (C) 2009 by Ignacio R. Morelle <shadowm2006@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 version 2
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifdef SHADOWM_STORYSCREEN
|
||||
#ifndef STORYSCREEN_PAGE_HPP_INCLUDED
|
||||
#define STORYSCREEN_PAGE_HPP_INCLUDED
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class config;
|
||||
class vconfig;
|
||||
class game_state;
|
||||
|
||||
namespace storyscreen {
|
||||
|
||||
/**
|
||||
* Represents and contains informations about image labels used
|
||||
* in story screen pages.
|
||||
*/
|
||||
class floating_image
|
||||
{
|
||||
public:
|
||||
floating_image(const config& cfg);
|
||||
|
||||
/** Returns the referential X coordinate of the image. */
|
||||
int ref_x() const { return x_; }
|
||||
/** Returns the referential Y coordinate of the image. */
|
||||
int ref_y() const { return y_; }
|
||||
|
||||
bool autoscale() const { return autoscaled_; }
|
||||
bool centered() const { return centered_; }
|
||||
|
||||
/** Delay before displaying, in milliseconds. */
|
||||
int display_delay() const { return delay_; }
|
||||
|
||||
private:
|
||||
floating_image();
|
||||
|
||||
std::string file_;
|
||||
int x_, y_; // referential (non corrected) x,y
|
||||
int delay_;
|
||||
bool autoscaled_;
|
||||
bool centered_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Represents and contains information about a single storyscreen page.
|
||||
*/
|
||||
class page
|
||||
{
|
||||
public:
|
||||
enum TEXT_BLOCK_LOCATION {
|
||||
TOP,
|
||||
MIDDLE,
|
||||
BOTTOM
|
||||
};
|
||||
|
||||
page(game_state& state_of_game, const vconfig& page_cfg);
|
||||
|
||||
bool scale_background() const { return scale_background_; }
|
||||
const std::string& background() const { return background_file_; }
|
||||
|
||||
bool show_title() const { return show_title_; }
|
||||
const std::string& text() const { return text_; }
|
||||
const std::string& title() const { return text_title_; }
|
||||
|
||||
private:
|
||||
page();
|
||||
|
||||
void resolve_wml(const vconfig& page_cfg);
|
||||
|
||||
static TEXT_BLOCK_LOCATION string_tblock_loc(const std::string& s);
|
||||
|
||||
bool scale_background_;
|
||||
std::string background_file_;
|
||||
|
||||
bool show_title_;
|
||||
std::string text_;
|
||||
std::string text_title_;
|
||||
TEXT_BLOCK_LOCATION text_block_loc_;
|
||||
|
||||
std::string music_;
|
||||
|
||||
std::vector<floating_image> floating_images_;
|
||||
};
|
||||
|
||||
} // end namespace storyscreen
|
||||
|
||||
|
||||
#endif /* ! STORYSCREEN_PAGE_HPP_INCLUDED */
|
||||
#endif /* ! SHADOWM_STORYSCREEN */
|
Loading…
Add table
Reference in a new issue