Revert to storyscreen page -> part convention in new storyscreen code
(part 4 and final - C++ interface has been renamed).
This commit is contained in:
parent
a1cdfa4a0c
commit
f495bbf8f3
7 changed files with 74 additions and 74 deletions
|
@ -50,16 +50,16 @@ controller::controller(display& disp, const vconfig& data, const std::string& sc
|
|||
, evt_context_()
|
||||
, data_(data)
|
||||
, scenario_name_(scenario_name)
|
||||
, pages_()
|
||||
, parts_()
|
||||
, gamestate_(game_events::get_state_of_game())
|
||||
{
|
||||
ASSERT_LOG(gamestate_ != NULL, "Ouch: gamestate is NULL when initializing storyscreen controller");
|
||||
build_pages();
|
||||
build_parts();
|
||||
}
|
||||
|
||||
controller::~controller()
|
||||
{
|
||||
clear_pages();
|
||||
clear_parts();
|
||||
}
|
||||
|
||||
void controller::resolve_wml(const vconfig& cfg)
|
||||
|
@ -71,12 +71,12 @@ void controller::resolve_wml(const vconfig& cfg)
|
|||
const vconfig node = i->second;
|
||||
|
||||
if(key == "part" && !node.empty()) {
|
||||
page* const story_page = new page(*gamestate_, node);
|
||||
// Use scenario name as page title if the WML doesn't supply a custom one.
|
||||
if((*story_page).show_title() && (*story_page).title().empty()) {
|
||||
(*story_page).set_title( scenario_name_ );
|
||||
part* const story_part = new part(*gamestate_, node);
|
||||
// Use scenario name as part title if the WML doesn't supply a custom one.
|
||||
if((*story_part).show_title() && (*story_part).title().empty()) {
|
||||
(*story_part).set_title( scenario_name_ );
|
||||
}
|
||||
pages_.push_back(story_page);
|
||||
parts_.push_back(story_part);
|
||||
}
|
||||
// [if]
|
||||
else if(key == "if") {
|
||||
|
@ -126,50 +126,50 @@ void controller::resolve_wml(const vconfig& cfg)
|
|||
}
|
||||
}
|
||||
|
||||
void controller::clear_pages()
|
||||
void controller::clear_parts()
|
||||
{
|
||||
foreach(page* p, pages_) {
|
||||
foreach(part* p, parts_) {
|
||||
delete p;
|
||||
}
|
||||
pages_.clear();
|
||||
parts_.clear();
|
||||
}
|
||||
|
||||
void controller::show_all_pages()
|
||||
void controller::show_all_parts()
|
||||
{
|
||||
if(pages_.empty()) {
|
||||
LOG_NG << "no storyscreen pages to show\n";
|
||||
if(parts_.empty()) {
|
||||
LOG_NG << "no storyscreen parts to show\n";
|
||||
}
|
||||
|
||||
size_t page_n = 0, pages_c = pages_.size();
|
||||
while((page_n = show_page(page_n)) < pages_c)
|
||||
size_t part_n = 0, parts_c = parts_.size();
|
||||
while((part_n = show_part(part_n)) < parts_c)
|
||||
;
|
||||
}
|
||||
|
||||
size_t controller::show_page(size_t page_num)
|
||||
size_t controller::show_part(size_t part_num)
|
||||
{
|
||||
if(page_num >= pages_.size()) {
|
||||
ERR_NG << "attempted to display inexistant storyscreen page: " << page_num+1 << " (of " << pages_.size() << ")\n";
|
||||
return pages_.size();
|
||||
if(part_num >= parts_.size()) {
|
||||
ERR_NG << "attempted to display inexistant storyscreen part: " << part_num+1 << " (of " << parts_.size() << ")\n";
|
||||
return parts_.size();
|
||||
}
|
||||
|
||||
LOG_NG << "displaying storyscreen page " << page_num+1 << " of " << pages_.size() << '\n';
|
||||
LOG_NG << "displaying storyscreen part " << part_num+1 << " of " << parts_.size() << '\n';
|
||||
|
||||
page* const p = pages_[page_num];
|
||||
ASSERT_LOG( p != NULL, "Ouch: hit NULL storyscreen page in collection" );
|
||||
part* const p = parts_[part_num];
|
||||
ASSERT_LOG( p != NULL, "Ouch: hit NULL storyscreen part in collection" );
|
||||
|
||||
// TODO:
|
||||
// gui::button back_button(disp_.video(),std::string("< ")+_("Next"));
|
||||
gui::button next_button(disp_.video(),_("Next") + std::string(" >"));
|
||||
gui::button skip_button(disp_.video(),_("Skip"));
|
||||
|
||||
page_ui ui(*p, disp_, next_button, skip_button);
|
||||
part_ui ui(*p, disp_, next_button, skip_button);
|
||||
switch(ui.show()) {
|
||||
case page_ui::NEXT:
|
||||
return page_num+1;
|
||||
case page_ui::BACK:
|
||||
return(page_num > 0 ? page_num-1 : page_num);
|
||||
case page_ui::SKIP:
|
||||
return pages_.size();
|
||||
case part_ui::NEXT:
|
||||
return part_num+1;
|
||||
case part_ui::BACK:
|
||||
return(part_num > 0 ? part_num-1 : part_num);
|
||||
case part_ui::SKIP:
|
||||
return parts_.size();
|
||||
default:
|
||||
throw quit();
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ class game_state;
|
|||
|
||||
namespace storyscreen {
|
||||
|
||||
class page;
|
||||
class part;
|
||||
class floating_image;
|
||||
|
||||
class controller
|
||||
|
@ -40,24 +40,24 @@ public:
|
|||
~controller();
|
||||
|
||||
/**
|
||||
* Display all story screen pages in a first..last sequence.
|
||||
* Display all story screen parts in a first..last sequence.
|
||||
*/
|
||||
void show_all_pages();
|
||||
void show_all_parts();
|
||||
/**
|
||||
* Display a single story screen page.
|
||||
* @return Next page requested by the user interface.
|
||||
* Display a single story screen part.
|
||||
* @return Next part requested by the user interface.
|
||||
*/
|
||||
size_t show_page(size_t page_num);
|
||||
size_t show_part(size_t part_num);
|
||||
|
||||
private:
|
||||
// Executes WML flow instructions and inserts pages.
|
||||
// Executes WML flow instructions and inserts parts.
|
||||
void resolve_wml(const vconfig& cfg);
|
||||
// Used by ctor.
|
||||
void build_pages() {
|
||||
void build_parts() {
|
||||
resolve_wml(data_);
|
||||
}
|
||||
// Used by dtor.
|
||||
void clear_pages();
|
||||
void clear_parts();
|
||||
|
||||
display& disp_;
|
||||
const resize_lock disp_resize_lock_;
|
||||
|
@ -66,14 +66,14 @@ private:
|
|||
vconfig data_;
|
||||
std::string scenario_name_;
|
||||
|
||||
// The page cache.
|
||||
std::vector<page*> pages_;
|
||||
// The part cache.
|
||||
std::vector<part*> parts_;
|
||||
|
||||
// The state of the world.
|
||||
game_state* gamestate_;
|
||||
|
||||
public:
|
||||
struct no_pages {};
|
||||
struct no_parts {};
|
||||
struct quit {};
|
||||
|
||||
};
|
||||
|
|
|
@ -41,7 +41,7 @@ static lg::log_domain log_engine("engine");
|
|||
#include "stub.hpp"
|
||||
|
||||
namespace {
|
||||
void generate_endscreen_page_config(config& append_to_cfg)
|
||||
void generate_endscreen_part_config(config& append_to_cfg)
|
||||
{
|
||||
config& partcfg = append_to_cfg.add_child("story").add_child("part");
|
||||
partcfg["text_align"] = "centered";
|
||||
|
@ -55,7 +55,7 @@ void show_storyscreen(display& disp, const vconfig& story_cfg, const std::string
|
|||
storyscreen::controller ctl(disp, story_cfg, scenario_name);
|
||||
|
||||
try {
|
||||
ctl.show_all_pages();
|
||||
ctl.show_all_parts();
|
||||
} catch(storyscreen::controller::quit const&) {
|
||||
LOG_NG << "leaving storyscreen for titlescreen...\n";
|
||||
STUB();
|
||||
|
|
|
@ -106,7 +106,7 @@ floating_image::render_input floating_image::get_render_input(double scale, SDL_
|
|||
return ri;
|
||||
}
|
||||
|
||||
page::page()
|
||||
part::part()
|
||||
: scale_background_()
|
||||
, background_file_()
|
||||
, show_title_()
|
||||
|
@ -120,7 +120,7 @@ page::page()
|
|||
ASSERT_LOG(0xDEADBEEF == 0x0, "Ouch: shouldn't happen");
|
||||
}
|
||||
|
||||
page::page(game_state& state_of_game, const vconfig& page_cfg)
|
||||
part::part(game_state& state_of_game, const vconfig& part_cfg)
|
||||
: scale_background_(true)
|
||||
, background_file_()
|
||||
, show_title_()
|
||||
|
@ -133,36 +133,36 @@ page::page(game_state& state_of_game, const vconfig& page_cfg)
|
|||
{
|
||||
// This method takes care of initializing
|
||||
// and branching properties.
|
||||
resolve_wml(page_cfg, state_of_game);
|
||||
resolve_wml(part_cfg, state_of_game);
|
||||
}
|
||||
|
||||
page::TEXT_BLOCK_LOCATION page::string_tblock_loc(const std::string& s)
|
||||
part::TEXT_BLOCK_LOCATION part::string_tblock_loc(const std::string& s)
|
||||
{
|
||||
if(s.empty() != true) {
|
||||
if(s == "top") {
|
||||
return page::TOP;
|
||||
return part::TOP;
|
||||
}
|
||||
else if(s == "centered" || s == "center" || s == "middle") {
|
||||
return page::MIDDLE;
|
||||
return part::MIDDLE;
|
||||
}
|
||||
}
|
||||
return page::BOTTOM;
|
||||
return part::BOTTOM;
|
||||
}
|
||||
|
||||
page::TITLE_ALIGNMENT page::string_title_align(const std::string& s)
|
||||
part::TITLE_ALIGNMENT part::string_title_align(const std::string& s)
|
||||
{
|
||||
if(s.empty() != true) {
|
||||
if(s == "right") {
|
||||
return page::RIGHT;
|
||||
return part::RIGHT;
|
||||
}
|
||||
else if(s == "centered" || s == "center" || s == "middle") {
|
||||
return page::CENTERED;
|
||||
return part::CENTERED;
|
||||
}
|
||||
}
|
||||
return page::LEFT;
|
||||
return part::LEFT;
|
||||
}
|
||||
|
||||
void page::resolve_wml(const vconfig& cfg, game_state& gamestate)
|
||||
void part::resolve_wml(const vconfig& cfg, game_state& gamestate)
|
||||
{
|
||||
if(cfg.has_attribute("background")) {
|
||||
background_file_ = cfg["background"];
|
||||
|
|
|
@ -35,7 +35,7 @@ namespace storyscreen {
|
|||
|
||||
/**
|
||||
* Represents and contains informations about image labels used
|
||||
* in story screen pages.
|
||||
* in story screen parts.
|
||||
*/
|
||||
class floating_image
|
||||
{
|
||||
|
@ -80,9 +80,9 @@ private:
|
|||
};
|
||||
|
||||
/**
|
||||
* Represents and contains information about a single storyscreen page.
|
||||
* Represents and contains information about a single storyscreen part.
|
||||
*/
|
||||
class page
|
||||
class part
|
||||
{
|
||||
public:
|
||||
enum TEXT_BLOCK_LOCATION {
|
||||
|
@ -99,7 +99,7 @@ public:
|
|||
QUIT
|
||||
};
|
||||
|
||||
page(game_state& state_of_game, const vconfig& page_cfg);
|
||||
part(game_state& state_of_game, const vconfig& part_cfg);
|
||||
|
||||
bool scale_background() const { return scale_background_; }
|
||||
const std::string& background() const { return background_file_; }
|
||||
|
@ -117,7 +117,7 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
page();
|
||||
part();
|
||||
|
||||
void resolve_wml(const vconfig& cfg, game_state& gamestate);
|
||||
|
||||
|
@ -137,7 +137,7 @@ private:
|
|||
|
||||
std::vector<floating_image> floating_images_;
|
||||
|
||||
friend class page_ui;
|
||||
friend class part_ui;
|
||||
};
|
||||
|
||||
} // end namespace storyscreen
|
||||
|
|
|
@ -55,7 +55,7 @@ namespace {
|
|||
|
||||
namespace storyscreen {
|
||||
|
||||
page_ui::page_ui(page& p, display& disp, gui::button& next_button, gui::button& skip_button)
|
||||
part_ui::part_ui(part& p, display& disp, gui::button& next_button, gui::button& skip_button)
|
||||
: p_(p)
|
||||
, disp_(disp)
|
||||
, video_(disp.video())
|
||||
|
@ -89,7 +89,7 @@ page_ui::page_ui(page& p, display& disp, gui::button& next_button, gui::button&
|
|||
background_ =
|
||||
scale_surface(background_, static_cast<int>(background_->w*scale_factor_), static_cast<int>(background_->h*scale_factor_));
|
||||
|
||||
ASSERT_LOG(background_.null() == false, "Ouch: storyscreen page background got NULL");
|
||||
ASSERT_LOG(background_.null() == false, "Ouch: storyscreen part background got NULL");
|
||||
|
||||
base_rect_.x = (video_.getx() - background_->w) / 2;
|
||||
base_rect_.y = (video_.gety() - background_->h) / 2;
|
||||
|
@ -121,7 +121,7 @@ page_ui::page_ui(page& p, display& disp, gui::button& next_button, gui::button&
|
|||
}
|
||||
}
|
||||
|
||||
void page_ui::render_text_box()
|
||||
void part_ui::render_text_box()
|
||||
{
|
||||
const bool rtl = current_language_rtl();
|
||||
|
||||
|
@ -272,7 +272,7 @@ void page_ui::render_text_box()
|
|||
);
|
||||
}
|
||||
|
||||
void page_ui::render_title_box()
|
||||
void part_ui::render_title_box()
|
||||
{
|
||||
// Text color
|
||||
const int r = 0, g = 0, b = 0;
|
||||
|
@ -291,7 +291,7 @@ void page_ui::render_title_box()
|
|||
));
|
||||
}
|
||||
|
||||
void page_ui::render_background()
|
||||
void part_ui::render_background()
|
||||
{
|
||||
draw_solid_tinted_rectangle(
|
||||
0, 0, video_.getx(), video_.gety(), 0, 0, 0, 1.0,
|
||||
|
@ -300,7 +300,7 @@ void page_ui::render_background()
|
|||
SDL_BlitSurface(background_, NULL, video_.getSurface(), &base_rect_);
|
||||
}
|
||||
|
||||
bool page_ui::render_floating_images()
|
||||
bool part_ui::render_floating_images()
|
||||
{
|
||||
events::raise_draw_event();
|
||||
update_whole_screen();
|
||||
|
@ -361,7 +361,7 @@ bool page_ui::render_floating_images()
|
|||
return true;
|
||||
}
|
||||
|
||||
page_ui::RESULT page_ui::show()
|
||||
part_ui::RESULT part_ui::show()
|
||||
{
|
||||
if(p_.music_.empty() != true) {
|
||||
sound::play_music_repeatedly(p_.music_);
|
||||
|
@ -383,7 +383,7 @@ page_ui::RESULT page_ui::show()
|
|||
render_text_box();
|
||||
}
|
||||
catch(utils::invalid_utf8_exception const&) {
|
||||
ERR_NG << "invalid UTF-8 sequence in story text, skipping page...\n";
|
||||
ERR_NG << "invalid UTF-8 sequence in story text, skipping part...\n";
|
||||
}
|
||||
|
||||
return ret_;
|
||||
|
|
|
@ -33,22 +33,22 @@ namespace gui { class button; }
|
|||
namespace storyscreen {
|
||||
|
||||
/**
|
||||
* Storyscreen page user interface.
|
||||
* Storyscreen part user interface.
|
||||
* This works on the assumption, like the old one, that the screen
|
||||
* cannot be resized while we are at this. More specifically, it is
|
||||
* assumed that the screen dimensions remain constant between the
|
||||
* constructor call, and the destruction of the objects.
|
||||
*/
|
||||
class page_ui
|
||||
class part_ui
|
||||
{
|
||||
public:
|
||||
enum RESULT { NEXT, BACK, SKIP, QUIT };
|
||||
|
||||
page_ui(page& p, display& disp, gui::button& next_button, gui::button& skip_button);
|
||||
part_ui(part& p, display& disp, gui::button& next_button, gui::button& skip_button);
|
||||
RESULT show();
|
||||
|
||||
private:
|
||||
page& p_;
|
||||
part& p_;
|
||||
display& disp_;
|
||||
CVideo& video_;
|
||||
CKey keys_;
|
||||
|
|
Loading…
Add table
Reference in a new issue