mail[Wesnoth-commits] r28376 - in /trunk: data/gui/default/window/ src/ src/editor2/ src/gui/dialogs/ src/gui/widgets/


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

Header


Content

Posted by kailoran on August 08, 2008 - 17:41:
Author: ilor
Date: Fri Aug  8 17:41:21 2008
New Revision: 28376

URL: http://svn.gna.org/viewcvs/wesnoth?rev=28376&view=rev
Log:
editor2: resize map dialog, fix resizing issues that also came up in 
flipping, made size members in map protected to allow said fix. Flipping 
still broken but at least will no longer occasionally crash.

Added:
    trunk/data/gui/default/window/editor_resize_map.cfg
      - copied, changed from r28375, 
trunk/data/gui/default/window/editor_new_map.cfg
    trunk/src/gui/dialogs/editor_resize_map.cpp
      - copied, changed from r28374, trunk/src/gui/dialogs/editor_new_map.cpp
    trunk/src/gui/dialogs/editor_resize_map.hpp
      - copied, changed from r28374, trunk/src/gui/dialogs/editor_new_map.hpp
Modified:
    trunk/src/CMakeLists.txt
    trunk/src/Makefile.am
    trunk/src/SConscript
    trunk/src/editor2/editor_controller.cpp
    trunk/src/editor2/editor_controller.hpp
    trunk/src/editor2/editor_map.cpp
    trunk/src/editor2/editor_map.hpp
    trunk/src/gui/widgets/settings.cpp
    trunk/src/gui/widgets/settings.hpp
    trunk/src/map.hpp

Copied: trunk/data/gui/default/window/editor_resize_map.cfg (from r28375, 
trunk/data/gui/default/window/editor_new_map.cfg)
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/gui/default/window/editor_resize_map.cfg?p2=trunk/data/gui/default/window/editor_resize_map.cfg&p1=trunk/data/gui/default/window/editor_new_map.cfg&r1=28375&r2=28376&rev=28376&view=diff
==============================================================================
--- trunk/data/gui/default/window/editor_new_map.cfg (original)
+++ trunk/data/gui/default/window/editor_resize_map.cfg Fri Aug  8 17:41:21 
2008
@@ -3,8 +3,8 @@
 ###
 
 [window]
-       id = "editor_new_map"
-       description = "New map dialog."
+       id = "editor_resize_map"
+       description = "Resize map dialog."
 
        [resolution]
                definition = "default"
@@ -23,7 +23,7 @@
                                        horizontal_alignment = "left"
                                        [label]
                                                definition = "title"
-                                               label = _ "New Map"
+                                               label = _ "Resize Map"
                                        [/label]
                                [/column]
                        [/row]                  
@@ -42,7 +42,7 @@
                                                                
horizontal_alignment = "left"
                                                                [label]
                                                                        
definition = "default"
-                                                                       label 
= _ "Width:"
+                                                                       label 
= _ "New width:"
                                                                [/label]
                                                        [/column]             
                  
                                                        [column]
@@ -58,6 +58,27 @@
                                                                    step_size 
= 1
                                                                [/slider]
                                                        [/column]
+                                                       [column]
+                                                               grow_factor = 0
+                                                               border = "all"
+                                                               border_size = 
5
+                                                               
horizontal_alignment = "left"
+                                                               [label]
+                                                                       
definition = "default"
+                                                                       label 
= _ "Old width:"
+                                                               [/label]
+                                                       [/column]             
                                                                          
+                                                       [column]
+                                                               grow_factor = 0
+                                                               border = "all"
+                                                               border_size = 
5
+                                                               
horizontal_alignment = "left"
+                                                               [label]
+                                                                       id = 
"old_width"
+                                                                       
definition = "default"
+                                                                       label 
= _ "-1"
+                                                               [/label]
+                                                       [/column]             
                                                                          
                                                [/row]
                                                [row]
                                                        grow_factor = 1
@@ -68,7 +89,7 @@
                                                                
horizontal_alignment = "left"
                                                                [label]
                                                                        
definition = "default"
-                                                                       label 
= _ "Height:"
+                                                                       label 
= _ "New height:"
                                                                [/label]
                                                        [/column]             
                  
                                                        [column]
@@ -84,7 +105,37 @@
                                                                    step_size 
= 1
                                                                [/slider]
                                                        [/column]
+                                                       [column]
+                                                               grow_factor = 0
+                                                               border = "all"
+                                                               border_size = 
5
+                                                               
horizontal_alignment = "left"
+                                                               [label]
+                                                                       
definition = "default"
+                                                                       label 
= _ "Old height:"
+                                                               [/label]
+                                                       [/column]             
                                                                          
+                                                       [column]
+                                                               grow_factor = 0
+                                                               border = "all"
+                                                               border_size = 
5
+                                                               
horizontal_alignment = "left"
+                                                               [label]
+                                                                       id = 
"old_height"
+                                                                       
definition = "default"
+                                                                       label 
= _ "-1"
+                                                               [/label]
+                                                       [/column]             
                                                                              
                                                    
                                                [/row]
+                                       [/grid]
+                               [/column]
+                       [/row]
+                       [row]
+                               grow_factor = 0
+                               [column]
+                                       grow_factor = 1
+                                       horizontal_grow = "true"
+                                       [grid]
                                                [row]
                                                        grow_factor = 0
                                                        [column]
@@ -94,8 +145,8 @@
                                                                [button]
                                                                        id = 
"ok"
                                                                        
definition = "default"
-                                                                       
size_text = _ "Create new map"
-                                                                       label 
= _ "Create new map"
+                                                                       
size_text = _ "Resize map"
+                                                                       label 
= _ "Resize map"
                                                                [/button]
                                                        [/column]
                                                        [column]

Modified: trunk/src/CMakeLists.txt
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/CMakeLists.txt?rev=28376&r1=28375&r2=28376&view=diff
==============================================================================
--- trunk/src/CMakeLists.txt (original)
+++ trunk/src/CMakeLists.txt Fri Aug  8 17:41:21 2008
@@ -209,7 +209,7 @@
     attack_prediction.cpp
     attack_prediction_display.cpp
     callable_objects.cpp
-       config_cache.cpp
+    config_cache.cpp
     config_adapter.cpp
     controller_base.cpp
     dialogs.cpp
@@ -300,8 +300,8 @@
     variable.cpp
     variant.cpp
     widgets/combo.cpp
-       widgets/combo_drag.cpp
-       widgets/drop_target.cpp
+    widgets/combo_drag.cpp
+    widgets/drop_target.cpp
     widgets/scrollpane.cpp
 )
 
@@ -310,6 +310,7 @@
 
 SET(wesnoth-editor2_SRC
     gui/dialogs/editor_generate_map.cpp
+    gui/dialogs/editor_resize_map.cpp
     gui/dialogs/editor_new_map.cpp
     editor2/action.cpp
     editor2/brush.cpp

Modified: trunk/src/Makefile.am
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/Makefile.am?rev=28376&r1=28375&r2=28376&view=diff
==============================================================================
--- trunk/src/Makefile.am (original)
+++ trunk/src/Makefile.am Fri Aug  8 17:41:21 2008
@@ -156,6 +156,7 @@
 wesnoth_editor2_SOURCES = \
        gui/dialogs/editor_generate_map.cpp \
        gui/dialogs/editor_new_map.cpp \
+       gui/dialogs/editor_resize_map.cpp \
        editor2/action.cpp \
        editor2/brush.cpp \
        editor2/editor_main.cpp \

Modified: trunk/src/SConscript
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/SConscript?rev=28376&r1=28375&r2=28376&view=diff
==============================================================================
--- trunk/src/SConscript (original)
+++ trunk/src/SConscript Fri Aug  8 17:41:21 2008
@@ -248,6 +248,7 @@
 wesnoth_editor2_sources = Split("""
     gui/dialogs/editor_generate_map.cpp
     gui/dialogs/editor_new_map.cpp
+    gui/dialogs/editor_resize_map.cpp
     editor2/action.cpp
     editor2/brush.cpp
     editor2/editor_main.cpp

Modified: trunk/src/editor2/editor_controller.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_controller.cpp?rev=28376&r1=28375&r2=28376&view=diff
==============================================================================
--- trunk/src/editor2/editor_controller.cpp (original)
+++ trunk/src/editor2/editor_controller.cpp Fri Aug  8 17:41:21 2008
@@ -21,6 +21,7 @@
 
 #include "gui/dialogs/editor_new_map.hpp"
 #include "gui/dialogs/editor_generate_map.hpp"
+#include "gui/dialogs/editor_resize_map.hpp"
 #include "gui/widgets/button.hpp"
 #include "gui/widgets/window.hpp"
 
@@ -204,7 +205,6 @@
        save_map_as(input_name);
 }
 
-
 void editor_controller::generate_map_dialog()
 {
        if (map_generator_ == NULL) {
@@ -225,6 +225,24 @@
        dialog.show(gui().video());
        if (map_generator_->allow_user_config()) {
                map_generator_->user_config(gui());
+       }
+}
+
+void editor_controller::resize_map_dialog()
+{
+       gui2::teditor_resize_map dialog;
+       dialog.set_map_width(get_map().total_width());
+       dialog.set_map_height(get_map().total_height());
+       
+       dialog.show(gui().video());
+       int res = dialog.get_retval();
+       if(res == gui2::twindow::OK) {
+               int w = dialog.map_width();
+               int h = dialog.map_height();
+               t_translation::t_terrain fill = t_translation::GRASS_LAND;
+               editor_action_resize_map a(w, h, 0, 0);
+               get_map_context().perform_action(a);
+               refresh_after_action();
        }
 }
 
@@ -470,6 +488,10 @@
                case HOTKEY_EDITOR_MAP_GENERATE:
                        generate_map_dialog();
                        return true;
+               case HOTKEY_EDITOR_MAP_RESIZE:
+                       std::cerr << "A";
+                       resize_map_dialog();
+                       return true;
                case HOTKEY_EDITOR_AUTO_UPDATE_TRANSITIONS:
                        auto_update_transitions_ = !auto_update_transitions_;
                        if (!auto_update_transitions_) {

Modified: trunk/src/editor2/editor_controller.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_controller.hpp?rev=28376&r1=28375&r2=28376&view=diff
==============================================================================
--- trunk/src/editor2/editor_controller.hpp (original)
+++ trunk/src/editor2/editor_controller.hpp Fri Aug  8 17:41:21 2008
@@ -71,6 +71,7 @@
                void new_map_dialog();
                void save_map_as_dialog();
                void generate_map_dialog();
+               void resize_map_dialog();
                bool save_map(bool display_confirmation = false);
                bool save_map_as(const std::string& filename);
                void new_map(int width, int height, t_translation::t_terrain 
fill);

Modified: trunk/src/editor2/editor_map.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_map.cpp?rev=28376&r1=28375&r2=28376&view=diff
==============================================================================
--- trunk/src/editor2/editor_map.cpp (original)
+++ trunk/src/editor2/editor_map.cpp Fri Aug  8 17:41:21 2008
@@ -30,16 +30,42 @@
 editor_map::editor_map(const config& terrain_cfg, const std::string& data)
 : gamemap(terrain_cfg, data)
 {
+       sanity_check();
 }
 
 editor_map::editor_map(const config& terrain_cfg, size_t width, size_t 
height, t_translation::t_terrain filler)
 : gamemap(terrain_cfg, gamemap::default_map_header + 
t_translation::write_game_map(
        t_translation::t_map(width, t_translation::t_list(height, filler))))
 {
+       sanity_check();
 }
 
 editor_map::~editor_map()
 {
+}
+
+void editor_map::sanity_check()
+{
+       int errors = 0;
+       if (total_width() != tiles_.size()) {
+               ERR_ED << "total_width is " << total_width() << " but 
tiles_.size() is " << tiles_.size() << "\n";
+               ++errors;
+       }
+       if (total_height() != tiles_[0].size()) {
+               ERR_ED << "total_height is " << total_height() << " but 
tiles_[0].size() is " << tiles_.size() << "\n";
+               ++errors;
+       }
+       if (w() + 2 * border_size() != total_width()) {
+               ERR_ED << "h is " << h_ << " and border_size is " << 
border_size() << " but total_width is " << total_width() << "\n";
+               ++errors;
+       }
+       if (h() + 2 * border_size() != total_height()) {
+               ERR_ED << "w is " << w_ << " and border_size is " << 
border_size() << " but total_height is " << total_height() << "\n";
+               ++errors;
+       }
+       if (errors) {
+               throw editor_map_integrity_error();
+       }
 }
 
 std::set<gamemap::location> editor_map::get_contigious_terrain_tiles(const 
gamemap::location& start) const
@@ -246,6 +272,8 @@
        for (int x = 0; x < count; ++x) {
                tiles_.push_back(clone_column(w, filler));
        }
+       w_ += count;
+       total_width_ += count;
 }
 
 void editor_map::expand_left(int count, t_translation::t_terrain filler)
@@ -254,6 +282,8 @@
                tiles_.insert(tiles_.begin(), 1, clone_column(0, filler));
                clear_border_cache();
        }
+       w_ += count;
+       total_width_ += count;
 }
 
 void editor_map::expand_top(int count, t_translation::t_terrain filler)
@@ -269,6 +299,8 @@
                        clear_border_cache();
                }
        }
+       h_ += count;
+       total_height_ += count;
 }
 
 void editor_map::expand_bottom(int count, t_translation::t_terrain filler)
@@ -284,6 +316,8 @@
                        tiles_[x].push_back(terrain);
                }
        }
+       h_ += count;
+       total_height_ += count;
 }
 
 void editor_map::shrink_right(int count)
@@ -292,6 +326,8 @@
                throw editor_map_operation_exception();
        }
        tiles_.resize(tiles_.size() - count);
+       w_ -= count;
+       total_width_ -= count;  
 }
 
 void editor_map::shrink_left(int count)
@@ -300,6 +336,8 @@
                throw editor_map_operation_exception();
        }
        tiles_.erase(tiles_.begin(), tiles_.begin() + count);
+       w_ -= count;
+       total_width_ -= count;  
 }
 
 void editor_map::shrink_top(int count)
@@ -310,6 +348,8 @@
        for (size_t x = 0; x < tiles_.size(); ++x) {
                tiles_[x].erase(tiles_[x].begin(), tiles_[x].begin() + count);
        }
+       h_ -= count;
+       total_height_ -= count;
 }
 
 void editor_map::shrink_bottom(int count)
@@ -320,6 +360,8 @@
        for (size_t x = 0; x < tiles_.size(); ++x) {
                tiles_[x].erase(tiles_[x].end() - count, tiles_[x].end());
        }
+       h_ -= count;
+       total_height_ -= count;
 }
 
 

Modified: trunk/src/editor2/editor_map.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_map.hpp?rev=28376&r1=28375&r2=28376&view=diff
==============================================================================
--- trunk/src/editor2/editor_map.hpp (original)
+++ trunk/src/editor2/editor_map.hpp Fri Aug  8 17:41:21 2008
@@ -27,6 +27,10 @@
 {
 };
 
+struct editor_map_integrity_error : public editor_exception
+{
+};
+
 /**
  * This class adds extra editor-specific functionality to a normal gamemap.
  */    
@@ -39,6 +43,11 @@
        editor_map(const config& terrain_cfg, size_t width, size_t height, 
t_translation::t_terrain filler);
        
        ~editor_map();
+       
+       /** 
+        * Debugging aid. Check if the widths and heights correspond to the 
actual map data sizes.
+        */
+       void sanity_check();
        
        /**
         * Get a contigious set of tiles having the same terrain as the 
starting location.

Copied: trunk/src/gui/dialogs/editor_resize_map.cpp (from r28374, 
trunk/src/gui/dialogs/editor_new_map.cpp)
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/dialogs/editor_resize_map.cpp?p2=trunk/src/gui/dialogs/editor_resize_map.cpp&p1=trunk/src/gui/dialogs/editor_new_map.cpp&r1=28374&r2=28376&rev=28376&view=diff
==============================================================================
--- trunk/src/gui/dialogs/editor_new_map.cpp (original)
+++ trunk/src/gui/dialogs/editor_resize_map.cpp Fri Aug  8 17:41:21 2008
@@ -12,7 +12,7 @@
    see the copying file for more details.
 */
 
-#include "gui/dialogs/editor_new_map.hpp"
+#include "gui/dialogs/editor_resize_map.hpp"
 
 #include "foreach.hpp"
 #include "gui/dialogs/field.hpp"
@@ -36,35 +36,35 @@
 
 namespace gui2 {
 
-teditor_new_map::teditor_new_map() :
+teditor_resize_map::teditor_resize_map() :
        map_width_(register_integer("width", false)),
        map_height_(register_integer("height", false))
 {
 }
 
-void teditor_new_map::set_map_width(int value) 
+void teditor_resize_map::set_map_width(int value) 
 { 
        map_width_->set_value(value);
 }
 
-int teditor_new_map::map_width() const
+int teditor_resize_map::map_width() const
 {
        return map_width_->get_value();
 }
 
-void teditor_new_map::set_map_height(int value)
+void teditor_resize_map::set_map_height(int value)
 { 
        map_height_->set_value(value);
 }
 
-int teditor_new_map::map_height() const
+int teditor_resize_map::map_height() const
 {
        return map_height_->get_value();
 }
 
-twindow teditor_new_map::build_window(CVideo& video)
+twindow teditor_resize_map::build_window(CVideo& video)
 {
-       return build(video, get_id(EDITOR_NEW_MAP));
+       return build(video, get_id(EDITOR_RESIZE_MAP));
 }
 
 } // namespace gui2

Copied: trunk/src/gui/dialogs/editor_resize_map.hpp (from r28374, 
trunk/src/gui/dialogs/editor_new_map.hpp)
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/dialogs/editor_resize_map.hpp?p2=trunk/src/gui/dialogs/editor_resize_map.hpp&p1=trunk/src/gui/dialogs/editor_new_map.hpp&r1=28374&r2=28376&rev=28376&view=diff
==============================================================================
--- trunk/src/gui/dialogs/editor_new_map.hpp (original)
+++ trunk/src/gui/dialogs/editor_resize_map.hpp Fri Aug  8 17:41:21 2008
@@ -12,22 +12,36 @@
    see the copying file for more details.
 */
 
-#ifndef GUI_DIALOGS_EDITOR_NEW_MAP_HPP_INCLUDED
-#define GUI_DIALOGS_EDITOR_NEW_MAP_HPP_INCLUDED
+#ifndef GUI_DIALOGS_EDITOR_RESIZE_MAP_HPP_INCLUDED
+#define GUI_DIALOGS_EDITOR_RESIZE_MAP_HPP_INCLUDED
 
 #include "gui/dialogs/dialog.hpp"
 
 namespace gui2 {
 
-class teditor_new_map : public tdialog
+class teditor_resize_map : public tdialog
 {
 public:
-       teditor_new_map();
+       teditor_resize_map();
        
        void set_map_width(int value);
        int map_width() const;
        void set_map_height(int value);
        int map_height() const;
+
+       enum EXPAND_DIRECTION {
+               EXPAND_BOTTOM_RIGHT,
+               EXPAND_BOTTOM,
+               EXPAND_BOTTOM_LEFT,
+               EXPAND_RIGHT,
+               EXPAND_CENTER,
+               EXPAND_LEFT,
+               EXPAND_TOP_RIGHT,
+               EXPAND_TOP,
+               EXPAND_TOP_LEFT
+       };
+       
+       EXPAND_DIRECTION expand_direction() { return EXPAND_BOTTOM_RIGHT; }
 
 private:
        /**

Modified: trunk/src/gui/widgets/settings.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/settings.cpp?rev=28376&r1=28375&r2=28376&view=diff
==============================================================================
--- trunk/src/gui/widgets/settings.cpp (original)
+++ trunk/src/gui/widgets/settings.cpp Fri Aug  8 17:41:21 2008
@@ -91,6 +91,7 @@
 #ifdef USE_EDITOR2     
        window_type_list[EDITOR_NEW_MAP] = "editor_new_map";
        window_type_list[EDITOR_GENERATE_MAP] = "editor_generate_map";
+       window_type_list[EDITOR_RESIZE_MAP] = "editor_resize_map";
 #endif
 }
 

Modified: trunk/src/gui/widgets/settings.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/settings.hpp?rev=28376&r1=28375&r2=28376&view=diff
==============================================================================
--- trunk/src/gui/widgets/settings.hpp (original)
+++ trunk/src/gui/widgets/settings.hpp Fri Aug  8 17:41:21 2008
@@ -44,6 +44,7 @@
 #ifdef USE_EDITOR2
        EDITOR_NEW_MAP,          //<! New map dialog
        EDITOR_GENERATE_MAP,     /** Editor random map genarator dialog */
+       EDITOR_RESIZE_MAP,               /** Editor resize map dialog */
 #endif
        DUMMY                    //<! Dummy always the last one.
 };

Modified: trunk/src/map.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/map.hpp?rev=28376&r1=28375&r2=28376&view=diff
==============================================================================
--- trunk/src/map.hpp (original)
+++ trunk/src/map.hpp Fri Aug  8 17:41:21 2008
@@ -281,7 +281,7 @@
     //! (using the default base if new terrain is an overlay terrain)
     //! Will return the resulting terrain or NONE_TERRAIN if merging failed
     t_translation::t_terrain merge_terrains(const t_translation::t_terrain 
old_t, const t_translation::t_terrain new_t, const tmerge_mode mode, bool 
replace_if_failed = false);
-
+       
 protected:
        t_translation::t_map tiles_;
        //! The size of the starting positions array is MAX_PLAYERS + 1, 
@@ -312,6 +312,7 @@
        mutable std::map<location, t_translation::t_terrain> borderCache_;
        mutable std::map<t_translation::t_terrain, size_t> 
terrainFrequencyCache_;
 
+protected:
        //! Sizes of the map area.
        int w_;
        int h_;
@@ -319,7 +320,8 @@
        //! Sizes of the map including the borders.
        int total_width_;
        int total_height_;
-
+       
+private:
        //! The size of the border around the map.
        int border_size_;
        //! The kind of map is being loaded.




Related Messages


Powered by MHonArc, Updated Fri Aug 08 18:01:52 2008