mail[Wesnoth-commits] r28606 - in /trunk/src/editor2: action.cpp action.hpp editor_controller.cpp


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

Header


Content

Posted by kailoran on August 15, 2008 - 19:44:
Author: ilor
Date: Fri Aug 15 19:44:07 2008
New Revision: 28606

URL: http://svn.gna.org/viewcvs/wesnoth?rev=28606&view=rev
Log:
editor2: randomize selection 

Modified:
    trunk/src/editor2/action.cpp
    trunk/src/editor2/action.hpp
    trunk/src/editor2/editor_controller.cpp

Modified: trunk/src/editor2/action.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/action.cpp?rev=28606&r1=28605&r2=28606&view=diff
==============================================================================
--- trunk/src/editor2/action.cpp (original)
+++ trunk/src/editor2/action.cpp Fri Aug 15 19:44:07 2008
@@ -291,4 +291,29 @@
        throw editor_action_not_implemented();
 }
 
+editor_action_paste* editor_action_shuffle_area::perform(map_context& mc) 
const
+{
+       map_fragment mf(mc.get_map(), area_);
+       std::auto_ptr<editor_action_paste> undo(new 
editor_action_paste(gamemap::location(0,0), mf));
+       perform_without_undo(mc);
+       return undo.release();
+}
+
+void editor_action_shuffle_area::perform_without_undo(map_context& mc) const
+{
+       std::vector<gamemap::location> shuffle;
+       std::copy(area_.begin(), area_.end(), std::inserter(shuffle, 
shuffle.begin()));
+       std::random_shuffle(shuffle.begin(), shuffle.end());
+       std::vector<gamemap::location>::const_iterator shuffle_it = 
shuffle.begin();
+       std::set<gamemap::location>::const_iterator orig_it = area_.begin();
+       while (orig_it != area_.end()) {
+               t_translation::t_terrain tmp = 
mc.get_map().get_terrain(*orig_it);
+               mc.draw_terrain(mc.get_map().get_terrain(*shuffle_it), 
*orig_it);
+               mc.draw_terrain(tmp, *shuffle_it);
+               orig_it++;
+               shuffle_it++;
+       }
+       mc.set_needs_terrain_rebuild();
+}
+
 } //end namespace editor2

Modified: trunk/src/editor2/action.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/action.hpp?rev=28606&r1=28605&r2=28606&view=diff
==============================================================================
--- trunk/src/editor2/action.hpp (original)
+++ trunk/src/editor2/action.hpp Fri Aug 15 19:44:07 2008
@@ -342,6 +342,21 @@
                gamemap::location loc2_;
 };
 
+/**
+ * Randomize terrain in an area
+ */
+class editor_action_shuffle_area : public editor_action_area
+{
+       public:
+               editor_action_shuffle_area(const std::set<gamemap::location>& 
area)
+               : editor_action_area(area)
+               {
+               }
+               editor_action_paste* perform(map_context& mc) const;
+               void perform_without_undo(map_context& mc) const;
+};
+
+
 } //end namespace editor2
 
 #endif

Modified: trunk/src/editor2/editor_controller.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_controller.cpp?rev=28606&r1=28605&r2=28606&view=diff
==============================================================================
--- trunk/src/editor2/editor_controller.cpp (original)
+++ trunk/src/editor2/editor_controller.cpp Fri Aug 15 19:44:07 2008
@@ -456,15 +456,15 @@
                case HOTKEY_EDITOR_SELECTION_ROTATE:
                case HOTKEY_EDITOR_SELECTION_FLIP:
                case HOTKEY_EDITOR_SELECTION_FILL:
-               case HOTKEY_EDITOR_SELECTION_GENERATE:
                case HOTKEY_EDITOR_SELECTION_RANDOMIZE:
                        return !get_map().selection().empty();
+               case HOTKEY_EDITOR_SELECTION_GENERATE:                  
+                       return false; //not implemented
                case HOTKEY_EDITOR_PASTE:
                        return !clipboard_.empty();
                case HOTKEY_EDITOR_SELECT_ALL:
                case HOTKEY_EDITOR_SELECT_INVERSE:
                case HOTKEY_EDITOR_MAP_RESIZE:
-               case HOTKEY_EDITOR_MAP_ROTATE:
                case HOTKEY_EDITOR_MAP_FLIP_X:
                case HOTKEY_EDITOR_MAP_FLIP_Y:
                case HOTKEY_EDITOR_MAP_GENERATE:
@@ -473,6 +473,8 @@
                case HOTKEY_EDITOR_AUTO_UPDATE_TRANSITIONS:
                case HOTKEY_EDITOR_REFRESH_IMAGE_CACHE:
                        return true;
+               case HOTKEY_EDITOR_MAP_ROTATE:
+                       return false; //not implemented
                default:
                        return false;
        }
@@ -535,6 +537,9 @@
                        return true;
                case HOTKEY_EDITOR_SELECTION_FILL:
                        fill_selection();
+                       return true;
+               case HOTKEY_EDITOR_SELECTION_RANDOMIZE:
+                       
perform_refresh(editor_action_shuffle_area(get_map().selection()));
                        return true;
                case HOTKEY_EDITOR_MAP_FLIP_X:
                        perform_refresh(editor_action_flip_x());




Related Messages


Powered by MHonArc, Updated Fri Aug 15 21:21:26 2008