Author: shadowmaster
Date: Sun Apr  5 01:47:31 2009
New Revision: 34508

URL: http://svn.gna.org/viewcvs/wesnoth?rev=34508&view=rev
Log:
Progress in new storyscreen code:
* StoryWML should handle [if], [switch], [deprecated_message], [wml_message], 
[part] and [page] correctly now.
* StoryWML::PageWML should handle [if], [switch], [deprecated_message], 
[wml_message] and possible page property overrides in [if] and [switch] cases 
correctly now.
* Started to write rendering components - now floating_image can create a set 
of parameters for rendering itself.

Modified:
    trunk/src/storyscreen/controller.cpp
    trunk/src/storyscreen/controller.hpp
    trunk/src/storyscreen/page.cpp
    trunk/src/storyscreen/page.hpp

Modified: trunk/src/storyscreen/controller.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/storyscreen/controller.cpp?rev=34508&r1=34507&r2=34508&view=diff
==============================================================================
--- trunk/src/storyscreen/controller.cpp (original)
+++ trunk/src/storyscreen/controller.cpp Sun Apr  5 01:47:31 2009
@@ -67,23 +67,72 @@
        clear_pages();
 }
 
-void controller::build_pages()
+void controller::resolve_wml(const vconfig& cfg)
 {
+       for(vconfig::all_children_iterator i = cfg.ordered_begin(); i != 
cfg.ordered_end(); i++)
+       {
+               // i->first and i->second are goddamn temporaries; do not make 
references
+               const std::string key = i->first;
+               const vconfig node = i->second;
 
+               // [page] and deprecated [part] (remove in 1.7.4)
+               if((key == "page" || key == "part") && !node.empty()) {
+                       if(key == "part") {
+                               lg::wml_error << "[part] in [story] has been 
deprecated and support for it will be removed in 1.7.4; use [page] instead.\n";
+                       }
 
-       for(vconfig::all_children_iterator i = data_.ordered_begin(); i != 
data_.ordered_end(); i++) {
-               const std::pair<const std::string, const vconfig> item = *i;
+                       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_ );
+                       }
+                       pages_.push_back(story_page);
+               }
+               // [if]
+               else if(key == "if") {
+                       const std::string branch_label =
+                               game_events::conditional_passed(NULL, node) ?
+                               "then" : "else";
+                       const vconfig branch = node.child(branch_label);
+                       resolve_wml(branch);
+               }
+               // [switch]
+               else if(key == "switch") {
+                       const std::string var_name = node["variable"];
+                       const std::string var_actual_value = 
(*gamestate_).get_variable_const(var_name);
+                       bool case_not_found = true;
 
-               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_;
-//                     }
+                       for(vconfig::all_children_iterator j = 
node.ordered_begin(); j != node.ordered_end(); ++j) {
+                               if(j->first != "case") continue;
 
-//                     page* story_page = new page(*gamestate_, cfg);
+                               // Enter all matching cases.
+                               const std::string var_expected_value = 
(j->second)["value"];
+                           if(var_actual_value == var_expected_value) {
+                                       case_not_found = false;
+                                       resolve_wml(j->second);
+                           }
+                       }
+
+                       if(case_not_found) {
+                               for(vconfig::all_children_iterator j = 
node.ordered_begin(); j != node.ordered_end(); ++j) {
+                                       if(j->first != "else") continue;
+
+                                       // Enter all elses.
+                                       resolve_wml(j->second);
+                               }
+                       }
                }
-
+               // [deprecated_message]
+               else if(key == "deprecated_message") {
+                       // Won't appear until the scenario start event finishes.
+                       
game_events::handle_deprecated_message(node.get_parsed_config());
+               }
+               // [wml_message]
+               else if(key == "wml_message") {
+                       // Pass to game events handler. As with 
[deprecated_message],
+                       // it won't appear until the scenario start event is 
complete.
+                       
game_events::handle_wml_log_message(node.get_parsed_config());
+               }
        }
 }
 

Modified: trunk/src/storyscreen/controller.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/storyscreen/controller.hpp?rev=34508&r1=34507&r2=34508&view=diff
==============================================================================
--- trunk/src/storyscreen/controller.hpp (original)
+++ trunk/src/storyscreen/controller.hpp Sun Apr  5 01:47:31 2009
@@ -49,9 +49,12 @@
 
 
 private:
-       // Used by ctor; processes possible WML branching instructions
-       // ([if]/[else] and [switch]) and builds the page cache.
-       void build_pages();
+       // Executes WML flow instructions and inserts pages.
+       void resolve_wml(const vconfig& cfg);
+       // Used by ctor.
+       void build_pages() {
+               resolve_wml(data_);
+       }
        // Used by dtor.
        void clear_pages();
 

Modified: trunk/src/storyscreen/page.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/storyscreen/page.cpp?rev=34508&r1=34507&r2=34508&view=diff
==============================================================================
--- trunk/src/storyscreen/page.cpp (original)
+++ trunk/src/storyscreen/page.cpp Sun Apr  5 01:47:31 2009
@@ -21,6 +21,7 @@
 
 #include "global.hpp"
 #include "asserts.hpp"
+#include "image.hpp"
 #include "log.hpp"
 #include "storyscreen/page.hpp"
 
@@ -35,6 +36,27 @@
 #include "stub.hpp"
 
 namespace storyscreen {
+
+floating_image::floating_image()
+       : file_()
+       , x_(0)
+       , y_(0)
+       , delay_(0)
+       , autoscaled_(false)
+       , centered_(false)
+{
+}
+
+floating_image::floating_image(const floating_image& fi)
+       : file_()
+       , x_(0)
+       , y_(0)
+       , delay_(0)
+       , autoscaled_(false)
+       , centered_(false)
+{
+       this->assign(fi);
+}
 
 floating_image::floating_image(const config& cfg)
        : file_(cfg["file"])
@@ -46,88 +68,42 @@
 {
 }
 
-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);
+void floating_image::assign(const floating_image& fi)
+{
+       if(&fi == this)
+               return;
+
+       file_ = fi.file_; x_ = fi.x_; y_ = fi.y_; delay_ = fi.delay_;
+       autoscaled_ = fi.autoscaled_; centered_ = fi.centered_;
+}
+
+floating_image::render_input floating_image::get_render_input(double scale, 
SDL_Rect& dst_rect) const
+{
+       render_input ri = {
+               {0,0,0,0},
+               file_.empty() ? NULL : image::get_image(file_)
+       };
+
+       if(!ri.image.null()) {
+               if(autoscaled_) {
+                       ri.image = scale_surface(
+                               ri.image,
+                               static_cast<int>(ri.image->w * scale),
+                               static_cast<int>(ri.image->h * scale)
+                       );
+               }
+
+               ri.rect.x = static_cast<int>(x_*scale) + dst_rect.x;
+               ri.rect.y = static_cast<int>(y_*scale) + dst_rect.y;
+               ri.rect.w = ri.image->w;
+               ri.rect.h = ri.image->h;
+
+               if(centered_) {
+                       ri.rect.x -= ri.rect.w / 2;
+                       ri.rect.y -= ri.rect.h / 2;
+               }
+       }
+       return ri;
 }
 
 page::page()
@@ -137,11 +113,144 @@
        , text_()
        , text_title_()
        , text_block_loc_()
+       , title_alignment_()
        , music_()
        , floating_images_()
 {
-       ASSERT_EQ(0xDEAD,0xBEEF);
-}
+       ASSERT_LOG(0xDEADBEEF == 0x0, "Ouch: shouldn't happen");
+}
+
+page::page(game_state& state_of_game, const vconfig& page_cfg)
+       : scale_background_()
+       , background_file_()
+       , show_title_()
+       , text_()
+       , text_title_()
+       , text_block_loc_()
+       , title_alignment_()
+       , music_()
+       , floating_images_()
+{
+       // This method takes care of initializing
+       // and branching properties.
+       resolve_wml(page_cfg, state_of_game);
+}
+
+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 == "centered" || s == "center" || s == "middle") {
+                       return page::MIDDLE;
+               }
+       }
+       return page::BOTTOM;
+}
+
+page::TITLE_ALIGNMENT page::string_title_align(const std::string& s)
+{
+       if(s.empty() != true) {
+               if(s == "right") {
+                       return page::RIGHT;
+               }
+               else if(s == "centered" || s == "center" || s == "middle") {
+                       return page::CENTERED;
+               }
+       }
+       return page::LEFT;
+}
+
+void page::resolve_wml(const vconfig& cfg, game_state& gamestate)
+{
+       if(cfg.has_attribute("background")) {
+               background_file_ = cfg["background"];
+       }
+       if(cfg.has_attribute("scale_background")) {
+               scale_background_ = utils::string_bool(cfg["scale_background"], 
true);
+       }
+       if(cfg.has_attribute("show_title")) {
+               show_title_ = utils::string_bool(cfg["show_title"]);
+       }
+       if(cfg.has_attribute("story")) {
+               text_ = cfg["story"];
+       }
+       if(cfg.has_attribute("title")) {
+               text_title_ = cfg["title"];
+       }
+       if(cfg.has_attribute("text_layout")) {
+               text_block_loc_ = string_tblock_loc(cfg["text_layout"]);
+       }
+       if(cfg.has_attribute("title_alignment")) {
+               title_alignment_ = string_title_align(cfg["title_alignment"]);
+       }
+       if(cfg.has_attribute("music")) {
+               music_ = cfg["music"];
+       }
+
+       // Execution flow/branching/[image]
+       for(vconfig::all_children_iterator i = cfg.ordered_begin(); i != 
cfg.ordered_end(); ++ i) {
+               // i->first and i->second are goddamn temporaries; do not make 
references
+               const std::string key = i->first;
+               const vconfig node = i->second;
+
+               // [image]
+               if(key == "image") {
+                       floating_images_.push_back(node.get_parsed_config());
+               }
+               // [if]
+               else if(key == "if") {
+                       const std::string branch_label =
+                               game_events::conditional_passed(NULL, node) ?
+                               "then" : "else";
+                       const vconfig branch = node.child(branch_label);
+                       resolve_wml(branch, gamestate);
+               }
+               // [switch]
+               else if(key == "switch") {
+                       const std::string var_name = node["variable"];
+                       const std::string var_actual_value = 
gamestate.get_variable_const(var_name);
+                       bool case_not_found = true;
+
+                       for(vconfig::all_children_iterator j = 
node.ordered_begin(); j != node.ordered_end(); ++j) {
+                               if(j->first != "case") continue;
+
+                               // Enter all matching cases.
+                               const std::string var_expected_value = 
(j->second)["value"];
+                           if(var_actual_value == var_expected_value) {
+                                       case_not_found = false;
+                                       resolve_wml(j->second, gamestate);
+                           }
+                       }
+
+                       if(case_not_found) {
+                               for(vconfig::all_children_iterator j = 
node.ordered_begin(); j != node.ordered_end(); ++j) {
+                                       if(j->first != "else") continue;
+
+                                       // Enter all elses.
+                                       resolve_wml(j->second, gamestate);
+                               }
+                       }
+               }
+               // [deprecated_message]
+               else if(key == "deprecated_message") {
+                       // Won't appear until the scenario start event finishes.
+                       
game_events::handle_deprecated_message(node.get_parsed_config());
+               }
+               // [wml_message]
+               else if(key == "wml_message") {
+                       // Pass to game events handler. As with 
[deprecated_message],
+                       // it won't appear until the scenario start event is 
complete.
+                       
game_events::handle_wml_log_message(node.get_parsed_config());
+               }
+       }
+}
+
+void page::render() const
+{
+}
+
 
 } // end namespace storyscreen
 

Modified: trunk/src/storyscreen/page.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/storyscreen/page.hpp?rev=34508&r1=34507&r2=34508&view=diff
==============================================================================
--- trunk/src/storyscreen/page.hpp (original)
+++ trunk/src/storyscreen/page.hpp Sun Apr  5 01:47:31 2009
@@ -25,6 +25,8 @@
 #include <string>
 #include <vector>
 
+struct SDL_Rect;
+struct surface;
 class config;
 class vconfig;
 class game_state;
@@ -38,7 +40,22 @@
 class floating_image
 {
 public:
+       struct render_input
+       {
+               SDL_Rect rect;  /**< Corrected rectangle for rendering surf. */
+               surface image;  /**< Surface, scaled if required. */
+       };
+
+       floating_image();
        floating_image(const config& cfg);
+       floating_image(const floating_image& fi);
+
+       void assign(const floating_image& fi);
+
+       floating_image& operator=(const floating_image& fi) {
+               assign(fi);
+               return *this;
+       }
 
        /** Returns the referential X coordinate of the image. */
        int ref_x() const { return x_; }
@@ -51,9 +68,10 @@
        /** Delay before displaying, in milliseconds. */
        int display_delay() const { return delay_; }
 
+       /** Render. */
+       render_input get_render_input(double scale, SDL_Rect& dst_rect) const;
+
 private:
-       floating_image();
-
        std::string file_;
        int x_, y_; // referential (non corrected) x,y
        int delay_;
@@ -72,6 +90,9 @@
                MIDDLE,
                BOTTOM
        };
+       enum TITLE_ALIGNMENT {
+               LEFT, CENTERED, RIGHT
+       };
 
        page(game_state& state_of_game, const vconfig& page_cfg);
 
@@ -82,12 +103,18 @@
        const std::string& text() const { return text_; }
        const std::string& title() const { return text_title_; }
 
+       void set_text(const std::string& text) { text_ = text; }
+       void set_title(const std::string& title) { text_title_ = title; }
+
+       void render() const;
+
 private:
        page();
 
-       void resolve_wml(const vconfig& page_cfg);
+       void resolve_wml(const vconfig& cfg, game_state& gamestate);
 
        static TEXT_BLOCK_LOCATION string_tblock_loc(const std::string& s);
+       static TITLE_ALIGNMENT string_title_align(const std::string& s);
 
        bool scale_background_;
        std::string background_file_;
@@ -96,6 +123,7 @@
        std::string text_;
        std::string text_title_;
        TEXT_BLOCK_LOCATION text_block_loc_;
+       TITLE_ALIGNMENT title_alignment_;
 
        std::string music_;
 


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to