mail[Wesnoth-commits] r44251 - in /trunk/src: builder.cpp builder.hpp display.cpp display.hpp menu_events.cpp


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by alinktomine on July 17, 2010 - 15:30:
Author: alink
Date: Sat Jul 17 15:30:43 2010
New Revision: 44251

URL: http://svn.gna.org/viewcvs/wesnoth?rev=44251&view=rev
Log:
Clean the implentation of ':layers'
- also display (scaled) image from the source for easier identification
- show center.x/y
- support [variant]
- directly log from the engine function to avoid code duplication

Modified:
    trunk/src/builder.cpp
    trunk/src/builder.hpp
    trunk/src/display.cpp
    trunk/src/display.hpp
    trunk/src/menu_events.cpp

Modified: trunk/src/builder.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/builder.cpp?rev=44251&r1=44250&r2=44251&view=diff
==============================================================================
--- trunk/src/builder.cpp (original)
+++ trunk/src/builder.cpp Sat Jul 17 15:30:43 2010
@@ -67,7 +67,7 @@
        sorted_images(false)
 {}
 
-void terrain_builder::tile::rebuild_cache(const std::string& tod)
+void terrain_builder::tile::rebuild_cache(const std::string& tod, logs* log)
 {
        images_background.clear();
        images_foreground.clear();
@@ -102,6 +102,10 @@
 
                        img_list.push_back(variant.image);
                        img_list.back().set_animation_time(ri.rand % 
img_list.back().get_animation_duration());
+
+                       if(log) {
+                               log->push_back(std::make_pair(&ri, &variant));
+                       }
 
                        break; // found a matching variant
                }
@@ -274,14 +278,6 @@
        }
 
        return NULL;
-}
-
-std::vector<std::string> terrain_builder::get_tile_info(const map_location 
&loc) const
-{
-       if(tile_map_.on_map(loc))
-               return tile_map_[loc].get_info();
-       else
-               return std::vector<std::string>();
 }
 
 bool terrain_builder::update_animation(const map_location &loc)
@@ -1107,3 +1103,10 @@
                ++rule_index;
        }
 }
+
+terrain_builder::tile* terrain_builder::get_tile(const map_location &loc)
+{
+       if(tile_map_.on_map(loc))
+               return &(tile_map_[loc]);
+       return NULL;
+}

Modified: trunk/src/builder.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/builder.hpp?rev=44251&r1=44250&r2=44251&view=diff
==============================================================================
--- trunk/src/builder.hpp (original)
+++ trunk/src/builder.hpp Sat Jul 17 15:30:43 2010
@@ -112,8 +112,6 @@
        const imagelist *get_terrain_at(const map_location &loc,
                        const std::string &tod, TERRAIN_TYPE const 
terrain_type);
 
-       std::vector<std::string> get_tile_info(const map_location &loc) const;
-
        /** Updates the animation at a given tile.
         * Returns true if something has changed, and must be redrawn.
         *
@@ -265,13 +263,16 @@
                /** Contructor for the tile() structure */
                tile();
 
+               struct rule_image_rand;
+               typedef std::pair<const rule_image_rand*, const 
rule_image_variant*> log_details;
+               typedef std::vector<log_details> logs;
                /** Rebuilds the whole image cache, for a given time-of-day.
                 * Must be called when the time-of-day has changed,
                 * to select the correct images.
                 *
                 * @param tod    The current time-of-day
                 */
-               void rebuild_cache(const std::string &tod);
+               void rebuild_cache(const std::string &tod, logs* log = NULL);
 
                std::vector<std::string> get_info() const;
 
@@ -317,6 +318,8 @@
                /** Indicates if 'images' is sorted */
                bool sorted_images;
        };
+
+       tile* get_tile(const map_location &loc);
 
 private:
        /**

Modified: trunk/src/display.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/display.cpp?rev=44251&r1=44250&r2=44251&view=diff
==============================================================================
--- trunk/src/display.cpp (original)
+++ trunk/src/display.cpp Sat Jul 17 15:30:43 2010
@@ -809,11 +809,6 @@
        debug_foreground = !debug_foreground;
 }
 
-std::vector<std::string> display::get_tile_info(const map_location &loc)
-{
-       return builder_->get_tile_info(loc);
-}
-
 void display::flip()
 {
        if(video().faked()) {

Modified: trunk/src/display.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/display.hpp?rev=44251&r1=44250&r2=44251&view=diff
==============================================================================
--- trunk/src/display.hpp (original)
+++ trunk/src/display.hpp Sat Jul 17 15:30:43 2010
@@ -344,7 +344,7 @@
         */
        static void toggle_debug_foreground();
 
-       std::vector<std::string> get_tile_info(const map_location &loc);
+       terrain_builder& get_builder() {return *builder_;};
 
        void flip();
 

Modified: trunk/src/menu_events.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/menu_events.cpp?rev=44251&r1=44250&r2=44251&view=diff
==============================================================================
--- trunk/src/menu_events.cpp (original)
+++ trunk/src/menu_events.cpp Sat Jul 17 15:30:43 2010
@@ -21,6 +21,7 @@
 
 #include "global.hpp"
 
+#include "builder.hpp"
 #include "ai/manager.hpp"
 #include "dialogs.hpp"
 #include "formatter.hpp"
@@ -3119,21 +3120,55 @@
        const mouse_handler& mousehandler = 
resources::controller->get_mouse_handler_base();
        const map_location &loc = mousehandler.get_last_hex();
 
-
        std::vector<std::string> layers;
-       //FIXME: translate columns
+       //NOTE: columns reflect WML keys, don't translate them
        std::string heading = std::string(1,HEADING_PREFIX) +
-                                                               "Image"       
   + COLUMN_SEPARATOR + // 0
-                                                               "Loc"         
+ COLUMN_SEPARATOR + // 1
-                                                               "Layer"       
 + COLUMN_SEPARATOR + // 2
-                                                               "Base.x"      
      + COLUMN_SEPARATOR + // 3
-                                                               "Base.y"     
// 4
-;
+               "Image"   + COLUMN_SEPARATOR + // 0
+               "Name"    + COLUMN_SEPARATOR + // 1
+               "Loc"     + COLUMN_SEPARATOR + // 2
+               "Layer"   + COLUMN_SEPARATOR + // 3
+               "Base.x"  + COLUMN_SEPARATOR + // 4
+               "Base.y"  + COLUMN_SEPARATOR + // 5
+               "Center.x"+ COLUMN_SEPARATOR + // 6
+               "Center.y"                     // 7
+       ;
        layers.push_back(heading);
 
-       std::vector<std::string> info =
-                       menu_handler_.gui_->get_tile_info(loc);
-       layers.insert(layers.end(), info.begin(), info.end());
+       display& disp = *(menu_handler_.gui_);
+       terrain_builder& builder = disp.get_builder();
+       terrain_builder::tile* tile = builder.get_tile(loc);
+
+       const std::string& tod_id = disp.get_time_of_day(loc).id;
+       terrain_builder::tile::logs tile_logs;
+       tile->rebuild_cache(tod_id, &tile_logs);
+
+       foreach(const terrain_builder::tile::log_details det, tile_logs) {
+               const terrain_builder::tile::rule_image_rand& ri = *det.first;
+               const terrain_builder::rule_image_variant& variant = 
*det.second;
+
+               const image::locator& img = variant.image.get_first_frame();
+               const std::string& name = img.get_filename();
+               //TODO deal with (rarely used) ~modifications
+               //const std::string& modif = img.get_modifications();
+               const map_location& loc = img.get_loc();
+
+               std::ostringstream info;
+               info << IMAGE_PREFIX << name
+                       << "~LOC("
+                               << loc.x << "," << loc.y << ","
+                               << img.get_center_x() << "," << 
img.get_center_y()
+                       << ")"
+                       << COLUMN_SEPARATOR
+                       << IMAGE_PREFIX  << name << "~SCALE(72,72)"
+                       << IMG_TEXT_SEPARATOR << name
+                       << COLUMN_SEPARATOR << img.get_loc()
+                       << COLUMN_SEPARATOR << ri->layer
+                       << COLUMN_SEPARATOR << ri->basex
+                       << COLUMN_SEPARATOR << ri->basey
+                       << COLUMN_SEPARATOR << ri->center_x
+                       << COLUMN_SEPARATOR << ri->center_y;
+               layers.push_back(info.str());
+       }
 
        int choice = 0;
        {




Related Messages


Powered by MHonArc, Updated Sat Jul 17 16:00:13 2010