Author: ilor
Date: Tue Sep 23 14:27:09 2008
New Revision: 29661

URL: http://svn.gna.org/viewcvs/wesnoth?rev=29661&view=rev
Log:
Move the recently added debug display of hex coordinates and terrain codes from 
the editor2 into the common display class. Allow setting this in-game via :sc 
and :tc commands. Unless debug mode is on, only non-shrouded tiles will have 
the terrain code displayed.

Modified:
    trunk/src/display.cpp
    trunk/src/display.hpp
    trunk/src/editor2/editor_display.cpp
    trunk/src/editor2/editor_display.hpp
    trunk/src/menu_events.cpp

Modified: trunk/src/display.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/display.cpp?rev=29661&r1=29660&r2=29661&view=diff
==============================================================================
--- trunk/src/display.cpp (original)
+++ trunk/src/display.cpp Tue Sep 23 14:27:09 2008
@@ -119,7 +119,9 @@
        idle_anim_(preferences::idle_anim()),
        idle_anim_rate_(1.0),
        map_screenshot_surf_(NULL),
-       redraw_observers_()
+       redraw_observers_(),
+       draw_coordinates_(false),
+       draw_terrain_codes_(false)
 {
        if(non_interactive()
                && (get_video_surface() != NULL
@@ -1923,6 +1925,38 @@
                drawing_buffer_add(LAYER_FOG_SHROUD, drawing_order, tblit(xpos, 
ypos,
                        get_terrain_images(loc, tod_.id, image_type, 
ADJACENT_FOGSHROUD)));
        }
+       if (on_map) {
+               if (draw_coordinates_) {
+                       int off_x = xpos + hex_size()/2;
+                       int off_y = ypos + hex_size()/2;
+                       surface text = 
font::get_rendered_text(lexical_cast<std::string>(loc), font::SIZE_SMALL, 
font::NORMAL_COLOUR);
+                       surface bg = create_neutral_surface(text->w, text->h);
+                       SDL_Rect bg_rect = {0, 0, text->w, text->h};
+                       SDL_FillRect(bg, &bg_rect, 0xaa000000);
+                       off_x -= text->w / 2;
+                       if (draw_terrain_codes_) {      
+                               off_y -= text->h;
+                       } else {
+                               off_y -= text->h / 2;
+                       }
+                       drawing_buffer_add(LAYER_FOG_SHROUD, drawing_order, 
tblit(off_x, off_y, bg));
+                       drawing_buffer_add(LAYER_FOG_SHROUD, drawing_order, 
tblit(off_x, off_y, text));
+               }
+               if (draw_terrain_codes_ && (game_config::debug || 
!shrouded(loc))) {
+                       int off_x = xpos + hex_size()/2;
+                       int off_y = ypos + hex_size()/2;
+                       surface text = 
font::get_rendered_text(lexical_cast<std::string>(map_.get_terrain(loc)), 
font::SIZE_SMALL, font::NORMAL_COLOUR);
+                       surface bg = create_neutral_surface(text->w, text->h);
+                       SDL_Rect bg_rect = {0, 0, text->w, text->h};
+                       SDL_FillRect(bg, &bg_rect, 0xaa000000);
+                       off_x -= text->w / 2;
+                       if (!draw_coordinates_) {       
+                               off_y -= text->h / 2;
+                       }
+                       drawing_buffer_add(LAYER_FOG_SHROUD, drawing_order, 
tblit(off_x, off_y, bg));
+                       drawing_buffer_add(LAYER_FOG_SHROUD, drawing_order, 
tblit(off_x, off_y, text));
+               }
+       }               
 }
 
 image::TYPE display::get_image_type(const gamemap::location& /*loc*/) {

Modified: trunk/src/display.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/display.hpp?rev=29661&r1=29660&r2=29661&view=diff
==============================================================================
--- trunk/src/display.hpp (original)
+++ trunk/src/display.hpp Tue Sep 23 14:27:09 2008
@@ -222,6 +222,16 @@
         * (to more clearly show where hexes are)
         */
        void set_grid(const bool grid) { grid_ = grid; }
+       
+       /** Getter for the x,y debug overlay on tiles */
+       bool get_draw_coordinates() { return draw_coordinates_; }
+       /** Setter for the x,y debug overlay on tiles */
+       void set_draw_coordinates(bool value) { draw_coordinates_ = value; }
+       
+       /** Getter for the terrain code debug overlay on tiles */
+       bool get_draw_terrain_codes() { return draw_terrain_codes_; }
+       /** Setter for the terrain code debug overlay on tiles */
+       void set_draw_terrain_codes(bool value) { draw_terrain_codes_ = value; 
}        
 
        /** Save a (map-)screenshot and return the estimated file size */
        int screenshot(std::string filename, bool map_screenshot = false);
@@ -771,6 +781,11 @@
        surface map_screenshot_surf_;
        
        std::vector<boost::function<void(display&)> > redraw_observers_;
+       
+       /** Debug flag - overlay x,y coords on tiles */
+       bool draw_coordinates_;
+       /** Debug flag - overlay terrain codes on tiles */
+       bool draw_terrain_codes_;
 };
 
 #endif

Modified: trunk/src/editor2/editor_display.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_display.cpp?rev=29661&r1=29660&r2=29661&view=diff
==============================================================================
--- trunk/src/editor2/editor_display.cpp (original)
+++ trunk/src/editor2/editor_display.cpp Tue Sep 23 14:27:09 2008
@@ -26,8 +26,6 @@
        : display(video, map, theme_cfg, cfg, level)
        , brush_locations_()
        , toolbar_hint_()
-       , draw_coordinates_(false)
-       , draw_terrain_codes_(false)
 {
     clear_screen();
 }
@@ -92,38 +90,6 @@
                                
image::get_image("editor/selection-overlay.png", image::SCALED_TO_HEX)));
                }
        }
-       if (map().on_board(loc)) {
-               if (draw_coordinates_) {
-                       int off_x = xpos + hex_size()/2;
-                       int off_y = ypos + hex_size()/2;
-                       surface text = 
font::get_rendered_text(lexical_cast<std::string>(loc), font::SIZE_SMALL, 
font::NORMAL_COLOUR);
-                       surface bg = create_neutral_surface(text->w, text->h);
-                       SDL_Rect bg_rect = {0, 0, text->w, text->h};
-                       SDL_FillRect(bg, &bg_rect, 0xff000000);
-                       off_x -= text->w / 2;
-                       if (draw_terrain_codes_) {      
-                               off_y -= text->h;
-                       } else {
-                               off_y -= text->h / 2;
-                       }
-                       drawing_buffer_add(LAYER_FOG_SHROUD, drawing_order, 
tblit(off_x, off_y, bg));
-                       drawing_buffer_add(LAYER_FOG_SHROUD, drawing_order, 
tblit(off_x, off_y, text));
-               }
-               if (draw_terrain_codes_) {
-                       int off_x = xpos + hex_size()/2;
-                       int off_y = ypos + hex_size()/2;
-                       surface text = 
font::get_rendered_text(lexical_cast<std::string>(map().get_terrain(loc)), 
font::SIZE_SMALL, font::NORMAL_COLOUR);
-                       surface bg = create_neutral_surface(text->w, text->h);
-                       SDL_Rect bg_rect = {0, 0, text->w, text->h};
-                       SDL_FillRect(bg, &bg_rect, 0xff000000);
-                       off_x -= text->w / 2;
-                       if (!draw_coordinates_) {       
-                               off_y -= text->h / 2;
-                       }
-                       drawing_buffer_add(LAYER_FOG_SHROUD, drawing_order, 
tblit(off_x, off_y, bg));
-                       drawing_buffer_add(LAYER_FOG_SHROUD, drawing_order, 
tblit(off_x, off_y, text));
-               }
-       }
 }
 
 const SDL_Rect& editor_display::get_clip_rect()

Modified: trunk/src/editor2/editor_display.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_display.hpp?rev=29661&r1=29660&r2=29661&view=diff
==============================================================================
--- trunk/src/editor2/editor_display.hpp (original)
+++ trunk/src/editor2/editor_display.hpp Tue Sep 23 14:27:09 2008
@@ -34,10 +34,7 @@
        const editor_map& map() const { return static_cast<const 
editor_map&>(map_); }
        void rebuild_terrain(const gamemap::location &loc);
        void set_toolbar_hint(const std::string value) { toolbar_hint_ = value; 
}
-       bool get_draw_coordinates() { return draw_coordinates_; }
-       void set_draw_coordinates(bool value) { draw_coordinates_ = value; }
-       bool get_draw_terrain_codes() { return draw_terrain_codes_; }
-       void set_draw_terrain_codes(bool value) { draw_terrain_codes_ = value; }
+
 protected:
        void pre_draw();
        /**
@@ -52,9 +49,6 @@
        
        std::set<gamemap::location> brush_locations_;
        std::string toolbar_hint_;
-       
-       bool draw_coordinates_;
-       bool draw_terrain_codes_;
 };
 
 } //end namespace editor2

Modified: trunk/src/menu_events.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/menu_events.cpp?rev=29661&r1=29660&r2=29661&view=diff
==============================================================================
--- trunk/src/menu_events.cpp (original)
+++ trunk/src/menu_events.cpp Tue Sep 23 14:27:09 2008
@@ -2247,6 +2247,8 @@
                        void do_shroud();
                        void do_gold();
                        void do_event();
+                       void do_toggle_draw_coordinates();
+                       void do_toggle_draw_terrain_codes();
 
                        std::string get_flags_description() const {
                                return "(D) - debug only, (N) - network only";
@@ -2337,6 +2339,12 @@
                                register_command("throw", 
&console_handler::do_event,
                                        _("Fire a game event."), "", "D");
                                register_alias("throw", "fire");
+                               register_command("show_coordinates", 
&console_handler::do_toggle_draw_coordinates,
+                                       _("Toggle overalying of x,y coordinates 
on hexes."));
+                               register_alias("show_coordinates", "sc");
+                               register_command("show_terrain_codes", 
&console_handler::do_toggle_draw_terrain_codes,
+                                       _("Toggle overalying of terrain codes 
on hexes."));
+                               register_alias("show_terrain_codes", "tc");
 
                                config* alias_list = preferences::get_alias();
                                if (alias_list != NULL) {
@@ -2978,6 +2986,14 @@
                game_events::fire(get_data());
                menu_handler_.gui_->redraw_everything();
        }
+       void console_handler::do_toggle_draw_coordinates() {
+               
menu_handler_.gui_->set_draw_coordinates(!menu_handler_.gui_->get_draw_coordinates());
+               menu_handler_.gui_->invalidate_all();
+       }
+       void console_handler::do_toggle_draw_terrain_codes() {
+               
menu_handler_.gui_->set_draw_terrain_codes(!menu_handler_.gui_->get_draw_terrain_codes());
+               menu_handler_.gui_->invalidate_all();   
+       }
 
        void menu_handler::do_ai_formula(const std::string& str,
                        const unsigned int team_num, mouse_handler& 
/*mousehandler*/)


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

Reply via email to