Author: ilor
Date: Mon Oct 13 21:05:30 2008
New Revision: 30138

URL: http://svn.gna.org/viewcvs/wesnoth?rev=30138&view=rev
Log:
editor2: add mask applying and creating to the editor. possibly under-featured, 
needs testing

Modified:
    trunk/data/themes/editor2.cfg
    trunk/src/editor2/action.cpp
    trunk/src/editor2/action.hpp
    trunk/src/editor2/action_base.hpp
    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/hotkeys.cpp
    trunk/src/hotkeys.hpp

Modified: trunk/data/themes/editor2.cfg
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/themes/editor2.cfg?rev=30138&r1=30137&r2=30138&view=diff
==============================================================================
--- trunk/data/themes/editor2.cfg (original)
+++ trunk/data/themes/editor2.cfg Mon Oct 13 21:05:30 2008
@@ -130,7 +130,7 @@
             id=menu-editor-edit
             title= _ "Edit"
             image=lite
-            
items=undo,redo,editor-cut,editor-copy,editor-paste,editor-select-all,editor-select-inverse,editor-select-none,editor-selection-fill,editor-selection-rotate,editor-selection-flip,editor-selection-generate,editor-selection-randomize,editor-clipboard-rotate-cw,editor-clipboard-rotate-ccw,editor-clipboard-flip-horizontal,editor-clipboard-flip-vertical
+            items=undo,redo,editor-cut,editor-copy,editor-paste, 
editor-select-all,editor-select-inverse,editor-select-none, 
editor-selection-fill,editor-selection-rotate,editor-selection-flip, 
editor-selection-generate,editor-selection-randomize, 
editor-clipboard-rotate-cw,editor-clipboard-rotate-ccw, 
editor-clipboard-flip-horizontal,editor-clipboard-flip-vertical
             rect="+2,=,+100,="
             xanchor=fixed
             yanchor=fixed
@@ -140,7 +140,7 @@
             id=menu-editor-map
             title= _ "Map"
             image=lite
-            
items=editor-map-resize,editor-map-rotate,editor-map-generate,editor-refresh,editor-update-transitions,editor-auto-update-transitions,editor-refresh-image-cache,editor-draw-coordinates,editor-draw-terrain-codes
+            items=editor-map-resize,editor-map-rotate,editor-map-generate, 
editor-map-apply-mask,editor-map-create-mask-to, 
editor-refresh,editor-update-transitions,editor-auto-update-transitions,editor-refresh-image-cache,
 editor-draw-coordinates,editor-draw-terrain-codes
             rect="+2,=,+100,="
             xanchor=fixed
             yanchor=fixed

Modified: trunk/src/editor2/action.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/action.cpp?rev=30138&r1=30137&r2=30138&view=diff
==============================================================================
--- trunk/src/editor2/action.cpp (original)
+++ trunk/src/editor2/action.cpp Mon Oct 13 21:05:30 2008
@@ -289,7 +289,6 @@
 
 editor_action_deselect* editor_action_select_all::perform(map_context& mc) 
const
 {
-       
        std::set<gamemap::location> current = mc.get_map().selection();
        mc.get_map().select_all();
        std::set<gamemap::location> all = mc.get_map().selection();
@@ -308,7 +307,6 @@
 
 editor_action_select* editor_action_select_none::perform(map_context& mc) const
 {
-       
        std::set<gamemap::location> current = mc.get_map().selection();
        mc.get_map().clear_selection();
        mc.set_everything_changed();
@@ -336,6 +334,18 @@
 {
        mc.get_map().resize(x_size_, y_size_, x_offset_, y_offset_, fill_);
        mc.set_needs_reload();
+}
+
+void editor_action_apply_mask::perform_without_undo(map_context& mc) const
+{
+       mc.get_map().overlay(mask_, config(), 0, 0);
+       mc.set_needs_terrain_rebuild();
+}
+
+void editor_action_create_mask::perform_without_undo(map_context& mc) const
+{
+       mc.get_map() = editor_map(mc.get_map().mask_to(target_));
+       mc.set_needs_terrain_rebuild();
 }
 
 void editor_action_rotate_map::perform_without_undo(map_context& /*mc*/) const

Modified: trunk/src/editor2/action.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/action.hpp?rev=30138&r1=30137&r2=30138&view=diff
==============================================================================
--- trunk/src/editor2/action.hpp (original)
+++ trunk/src/editor2/action.hpp Mon Oct 13 21:05:30 2008
@@ -403,6 +403,30 @@
                int angle_;
 };
 
+class editor_action_apply_mask : public editor_action
+{
+       public:
+               editor_action_apply_mask(const gamemap& mask)
+               : mask_(mask)
+               {
+               }
+               void perform_without_undo(map_context& mc) const;
+       private:
+               gamemap mask_;
+};
+
+class editor_action_create_mask : public editor_action
+{
+       public:
+               editor_action_create_mask(const gamemap& target)
+               : target_(target)
+               {
+               }
+               void perform_without_undo(map_context& mc) const;
+       private:
+               gamemap target_;
+};
+
 //plot a route between two points
 class editor_action_plot_route : public editor_action_location_terrain
 {

Modified: trunk/src/editor2/action_base.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/action_base.hpp?rev=30138&r1=30137&r2=30138&view=diff
==============================================================================
--- trunk/src/editor2/action_base.hpp (original)
+++ trunk/src/editor2/action_base.hpp Mon Oct 13 21:05:30 2008
@@ -28,7 +28,7 @@
 #define EDITOR2_ACTION_BASE_HPP_INCLUDED
 
 #include "editor_common.hpp"
-
+#include "../gettext.hpp"
 #include <string>
 
 
@@ -96,7 +96,7 @@
 //TODO: add messages etc
 struct editor_action_exception : public editor_exception
 {
-       editor_action_exception(const char* msg) 
+       editor_action_exception(const std::string& msg) 
        : editor_exception(msg)
        {
        }
@@ -106,7 +106,7 @@
 struct editor_action_not_implemented : public editor_action_exception
 {
        editor_action_not_implemented()
-       : editor_action_exception("Action not implemented")
+       : editor_action_exception(_("Action not implemented"))
        {
        }
 };
@@ -115,7 +115,7 @@
 struct editor_action_creation_fail : public editor_action_exception
 {
        editor_action_creation_fail()
-       : editor_action_exception("Error creating action object")
+       : editor_action_exception(_("Error creating action object"))
        {
        }
 };

Modified: trunk/src/editor2/editor_controller.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_controller.cpp?rev=30138&r1=30137&r2=30138&view=diff
==============================================================================
--- trunk/src/editor2/editor_controller.cpp (original)
+++ trunk/src/editor2/editor_controller.cpp Mon Oct 13 21:05:30 2008
@@ -375,6 +375,50 @@
        }
 }
 
+void editor_controller::apply_mask_dialog()
+{
+       std::string fn = get_map_context().get_filename();
+       if (fn.empty()) {
+               fn = default_dir_;
+       }
+       int res = dialogs::show_file_chooser_dialog(gui(), fn, _("Choose a mask 
to apply"));
+       if (res == 0) {
+               try {
+                       editor_map mask = 
editor_map::load_from_file(game_config_, fn);
+                       editor_action_apply_mask a(mask);
+                       perform_refresh(a);
+               } catch (editor_map_load_exception& e) {
+                       gui::message_dialog(gui(), _("Error loading mask"), 
e.what()).show();
+                       return;
+               } catch (editor_action_exception& e) {
+                       gui::message_dialog(gui(), _("Error"), e.what()).show();
+                       return;
+               }
+       }
+}
+
+void editor_controller::create_mask_to_dialog()
+{
+       std::string fn = get_map_context().get_filename();
+       if (fn.empty()) {
+               fn = default_dir_;
+       }
+       int res = dialogs::show_file_chooser_dialog(gui(), fn, _("Choose target 
map"));
+       if (res == 0) {
+               try {
+                       editor_map map = 
editor_map::load_from_file(game_config_, fn);
+                       editor_action_create_mask a(map);
+                       perform_refresh(a);
+               } catch (editor_map_load_exception& e) {
+                       gui::message_dialog(gui(), _("Error loading map"), 
e.what()).show();
+                       return;
+               } catch (editor_action_exception& e) {
+                       gui::message_dialog(gui(), _("Error"), e.what()).show();
+                       return;
+               }
+       }
+}
+
 void editor_controller::resize_map_dialog()
 {
        gui2::teditor_resize_map dialog;
@@ -609,6 +653,8 @@
                case HOTKEY_EDITOR_SELECT_NONE:
                case HOTKEY_EDITOR_MAP_RESIZE:
                case HOTKEY_EDITOR_MAP_GENERATE:
+               case HOTKEY_EDITOR_MAP_APPLY_MASK:
+               case HOTKEY_EDITOR_MAP_CREATE_MASK_TO:
                case HOTKEY_EDITOR_REFRESH:
                case HOTKEY_EDITOR_UPDATE_TRANSITIONS:
                case HOTKEY_EDITOR_AUTO_UPDATE_TRANSITIONS:
@@ -741,6 +787,12 @@
                case HOTKEY_EDITOR_MAP_GENERATE:
                        generate_map_dialog();
                        return true;
+               case HOTKEY_EDITOR_MAP_APPLY_MASK:
+                       apply_mask_dialog();
+                       return true;
+               case HOTKEY_EDITOR_MAP_CREATE_MASK_TO:
+                       create_mask_to_dialog();
+                       return true;
                case HOTKEY_EDITOR_MAP_RESIZE:
                        resize_map_dialog();
                        return true;

Modified: trunk/src/editor2/editor_controller.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_controller.hpp?rev=30138&r1=30137&r2=30138&view=diff
==============================================================================
--- trunk/src/editor2/editor_controller.hpp (original)
+++ trunk/src/editor2/editor_controller.hpp Mon Oct 13 21:05:30 2008
@@ -109,6 +109,12 @@
 
                /** Display a generate random map dialog and process user 
input. */
                void generate_map_dialog();
+
+               /** Display an apply mask dialog and process user input. */
+               void apply_mask_dialog();
+
+               /** Display an apply mask dialog and process user input. */
+               void create_mask_to_dialog();
 
                /** Display a load map dialog and process user input. */
                void resize_map_dialog();

Modified: trunk/src/editor2/editor_map.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_map.cpp?rev=30138&r1=30137&r2=30138&view=diff
==============================================================================
--- trunk/src/editor2/editor_map.cpp (original)
+++ trunk/src/editor2/editor_map.cpp Mon Oct 13 21:05:30 2008
@@ -50,6 +50,13 @@
        sanity_check();
 }
 
+editor_map::editor_map(const gamemap& map)
+       : gamemap(map)
+       , selection_()
+{
+       sanity_check();
+}
+
 editor_map editor_map::load_from_file(const config& game_config, const 
std::string& filename)
 {
        std::string map_string = read_file(filename);
@@ -62,13 +69,13 @@
                return new_map;
        } catch (gamemap::incorrect_format_exception& e) {
                WRN_ED << "format error in load map " << filename << "\n";
-               std::string message = _("There was a format error while loading 
the map:");
+               std::string message = _("There was a format error while loading 
the file:");
                message += "\n";
                message += e.msg_;
                throw editor_map_load_exception(filename, message);
        } catch (twml_exception& e) {
                WRN_ED << "wml error in load map " << filename << "\n";
-               std::string message = _("There was a wml error while loading 
the map:");
+               std::string message = _("There was a wml error while loading 
the file:");
                message += "\n";
                message += e.user_message;
                throw editor_map_load_exception(filename, message);
@@ -257,6 +264,23 @@
        sanity_check();
 }
 
+gamemap editor_map::mask_to(const gamemap& target) const
+{
+       if (target.w() != w() || target.h() != h()) {
+               throw editor_action_exception(_("The size of the target map is 
different from the current map"));
+       }
+       gamemap mask(target);
+       gamemap::location iter;
+       for (iter.x = 0 ; iter.x < w(); ++iter.x) {
+               for (iter.y = 0; iter.y < h(); ++iter.y) {
+                       if (target.get_terrain(iter) == get_terrain(iter)) {
+                               mask.set_terrain(iter, t_translation::FOGGED);
+                       }
+               }
+       }
+       return mask;
+}
+
 void editor_map::swap_starting_position(int x1, int y1, int x2, int y2)
 {
        int pos1 = is_starting_position(location(x1, y1));

Modified: trunk/src/editor2/editor_map.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_map.hpp?rev=30138&r1=30137&r2=30138&view=diff
==============================================================================
--- trunk/src/editor2/editor_map.hpp (original)
+++ trunk/src/editor2/editor_map.hpp Mon Oct 13 21:05:30 2008
@@ -62,6 +62,8 @@
        editor_map(const config& terrain_cfg, size_t width, size_t height, 
t_translation::t_terrain filler);
        
        editor_map(const config& terrain_cfg, const gamemap& map);
+       
+       explicit editor_map(const gamemap& map);
        
        static editor_map load_from_file(const config& game_config, const 
std::string& filename);
        
@@ -138,16 +140,12 @@
         */
        void resize(int width, int height, int x_offset, int y_offset,
                t_translation::t_terrain filler = t_translation::NONE_TERRAIN);
-
-       /** 
-        * Flip the map along the X axis. Seems somewhat broken, was so in the 
old editor.
+       
+       /**
+        * A sort-of diff operation returning a mask that, when applied to the 
current editor_map,
+        * will transform it into the target map.
         */
-       void flip_x();
-
-       /** 
-        * Flip the map along the Y axis. Seems somewhat broken, was so in the 
old editor.
-        */
-       void flip_y();
+       gamemap mask_to(const gamemap& target) const;
 
 protected:
        void swap_starting_position(int x1, int y1, int x2, int y2);

Modified: trunk/src/hotkeys.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/hotkeys.cpp?rev=30138&r1=30137&r2=30138&view=diff
==============================================================================
--- trunk/src/hotkeys.cpp (original)
+++ trunk/src/hotkeys.cpp Mon Oct 13 21:05:30 2008
@@ -161,6 +161,10 @@
                N_("Rotate Map"), false, hotkey::SCOPE_EDITOR },
        { hotkey::HOTKEY_EDITOR_MAP_GENERATE, "editor-map-generate",
                 N_("Generate Map"), false, hotkey::SCOPE_EDITOR },
+       { hotkey::HOTKEY_EDITOR_MAP_APPLY_MASK, "editor-map-apply-mask",
+                N_("Apply a Mask"), false, hotkey::SCOPE_EDITOR },
+       { hotkey::HOTKEY_EDITOR_MAP_CREATE_MASK_TO, "editor-map-create-mask-to",
+                N_("Create Mask"), false, hotkey::SCOPE_EDITOR },
        { hotkey::HOTKEY_EDITOR_REFRESH, "editor-refresh", 
                N_("Refresh Display"), false, hotkey::SCOPE_EDITOR },
        { hotkey::HOTKEY_EDITOR_UPDATE_TRANSITIONS, 
"editor-update-transitions", 

Modified: trunk/src/hotkeys.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/hotkeys.hpp?rev=30138&r1=30137&r2=30138&view=diff
==============================================================================
--- trunk/src/hotkeys.hpp (original)
+++ trunk/src/hotkeys.hpp Mon Oct 13 21:05:30 2008
@@ -79,7 +79,8 @@
        HOTKEY_EDITOR_SELECTION_FILL,
        HOTKEY_EDITOR_SELECTION_GENERATE, HOTKEY_EDITOR_SELECTION_RANDOMIZE,
        HOTKEY_EDITOR_MAP_RESIZE, HOTKEY_EDITOR_MAP_ROTATE, 
-       HOTKEY_EDITOR_MAP_GENERATE,
+       HOTKEY_EDITOR_MAP_GENERATE, HOTKEY_EDITOR_MAP_APPLY_MASK,
+       HOTKEY_EDITOR_MAP_CREATE_MASK_TO,
        HOTKEY_EDITOR_REFRESH, HOTKEY_EDITOR_UPDATE_TRANSITIONS,
        HOTKEY_EDITOR_AUTO_UPDATE_TRANSITIONS,
        HOTKEY_EDITOR_REFRESH_IMAGE_CACHE,


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

Reply via email to