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


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

Header


Content

Posted by kailoran on August 13, 2008 - 14:44:
Author: ilor
Date: Wed Aug 13 14:44:11 2008
New Revision: 28535

URL: http://svn.gna.org/viewcvs/wesnoth?rev=28535&view=rev
Log:
editor2: selection tool "magic wand" feature (hold ALT), set starting 
position tool responds to keypresses 1-9 and delete, some cleanup

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

Modified: trunk/src/editor2/editor_controller.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_controller.cpp?rev=28535&r1=28534&r2=28535&view=diff
==============================================================================
--- trunk/src/editor2/editor_controller.cpp (original)
+++ trunk/src/editor2/editor_controller.cpp Wed Aug 13 14:44:11 2008
@@ -78,11 +78,11 @@
        mouse_actions_.insert(std::make_pair(hotkey::HOTKEY_EDITOR_TOOL_FILL, 
                new mouse_action_fill(foreground_terrain_, key_)));
        
mouse_actions_.insert(std::make_pair(hotkey::HOTKEY_EDITOR_TOOL_SELECT, 
-               new mouse_action_select(&brush_)));
+               new mouse_action_select(&brush_, key_)));
        
mouse_actions_.insert(std::make_pair(hotkey::HOTKEY_EDITOR_TOOL_STARTING_POSITION,
-               new mouse_action_starting_position()));
+               new mouse_action_starting_position(key_)));
        mouse_actions_.insert(std::make_pair(hotkey::HOTKEY_EDITOR_PASTE,
-               new mouse_action_paste(clipboard_)));
+               new mouse_action_paste(clipboard_, key_)));
        foreach (const theme::menu& menu, gui().get_theme().menus()) {
                if (menu.items().size() == 1) {
                        mouse_action_map::iterator i = 
mouse_actions_.find(hotkey::get_hotkey(menu.items().front()).get_id());
@@ -103,6 +103,7 @@
        gui_->draw();
        palette_->draw(true);
        load_tooltips();
+       redraw_toolbar();
        events::raise_draw_event();     
 }
 
@@ -724,8 +725,10 @@
 
 void editor_controller::perform_refresh_delete(editor_action* action)
 {
-       std::auto_ptr<editor_action> action_auto(action);
-       perform_refresh(*action);
+       if (action) {
+               std::auto_ptr<editor_action> action_auto(action);
+               perform_refresh(*action);
+       }
 }
 
 void editor_controller::perform_refresh(const editor_action& action)
@@ -836,29 +839,23 @@
        if (dragging_ && (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON_LEFT) != 0
        && get_map().on_board_with_border(drag_from_hex_)) {
                if (!get_map().on_board_with_border(hex_clicked)) return;
-               if (get_mouse_action() != NULL) {
-                       LOG_ED << "Mouse drag\n";
-                       editor_action* last_undo = 
get_map_context().last_undo_action();
-                       bool partial = false;
-                       editor_action* a = get_mouse_action()->drag(*gui_, x, 
y, partial, last_undo);
-                       //Partial means that the mouse action has modified 
the last undo action and the controller shouldn't add
-                       //anything to the undo stack (hence a diferent 
perform_ call
-                       if (a != NULL) {
-                               std::auto_ptr<editor_action> aa(a);
-                               if (partial) {
-                                       
get_map_context().perform_partial_action(*a);
-                               } else {
-                                       get_map_context().perform_action(*a);
-                               }
-                               refresh_after_action(true);
-                       }
-               } else {
-                       WRN_ED << __FUNCTION__ << ": There is no mouse action 
active!\n";
-               }               
+               LOG_ED << "Mouse drag\n";
+               editor_action* last_undo = 
get_map_context().last_undo_action();
+               bool partial = false;
+               editor_action* a = get_mouse_action()->drag(*gui_, x, y, 
partial, last_undo);
+               //Partial means that the mouse action has modified the last 
undo action and the controller shouldn't add
+               //anything to the undo stack (hence a diferent perform_ call
+               if (a != NULL) {
+                       std::auto_ptr<editor_action> aa(a);
+                       if (partial) {
+                               get_map_context().perform_partial_action(*a);
+                       } else {
+                               get_map_context().perform_action(*a);
+                       }
+                       refresh_after_action(true);
+               }
        } else {
-               if (get_mouse_action() != NULL) {
-                       get_mouse_action()->move(*gui_, x, y);
-               }
+               get_mouse_action()->move(*gui_, x, y);
        }
        gui().highlight_hex(hex_clicked);
 }
@@ -875,38 +872,29 @@
        LOG_ED << "Left click, after generic handling\n";
        gamemap::location hex_clicked = gui().hex_clicked_on(x, y);
        if (!get_map().on_board_with_border(hex_clicked)) return true;
-       if (get_mouse_action() != NULL) {
-               LOG_ED << "Left click action " << hex_clicked.x << " " << 
hex_clicked.y << "\n";
-               editor_action* a = get_mouse_action()->click(*gui_, x, y);
-               if (a != NULL) {
-                       perform_refresh_delete(a);
-               }
-               return true;
-       } else {
-               LOG_ED << __FUNCTION__ << ": There is no mouse action 
active!\n";
-               return false;
-       }
+       LOG_ED << "Left click action " << hex_clicked.x << " " << 
hex_clicked.y << "\n";
+       editor_action* a = get_mouse_action()->click(*gui_, x, y);
+       perform_refresh_delete(a);
+       return true;
 }
 
 void editor_controller::left_drag_end(int x, int y, const bool browse)
 {
-       if (get_mouse_action() != NULL) {
-               editor_action* a = get_mouse_action()->drag_end(*gui_, x, y);
-               if (a != NULL) {
-                       perform_refresh_delete(a);
-               }
-       } else {
-               LOG_ED << __FUNCTION__ << ": There is no mouse action 
active!\n";
-       }       
+       editor_action* a = get_mouse_action()->drag_end(*gui_, x, y);
+       perform_refresh_delete(a);
 }
 
 void editor_controller::left_mouse_up(int x, int y, const bool browse)
 {
-       if (get_mouse_action() != NULL) {
-               refresh_after_action();
-       } else {
-               LOG_ED << __FUNCTION__ << ": There is no mouse action 
active!\n";
-       }       
-}
+       refresh_after_action();
+}
+
+void editor_controller::process_keyup_event(const SDL_Event& event)
+{
+       LOG_ED << "keyup\n";
+       editor_action* a = get_mouse_action()->key_event(gui(), event);
+       perform_refresh_delete(a);
+}
+
 
 } //end namespace editor2

Modified: trunk/src/editor2/editor_controller.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_controller.hpp?rev=28535&r1=28534&r2=28535&view=diff
==============================================================================
--- trunk/src/editor2/editor_controller.hpp (original)
+++ trunk/src/editor2/editor_controller.hpp Wed Aug 13 14:44:11 2008
@@ -108,6 +108,7 @@
                void left_mouse_up(int x, int y, const bool browse);
                
        protected:
+               void process_keyup_event(const SDL_Event& event);
                mouse_handler_base& get_mouse_handler_base();
                editor_display& get_display();  
                brush* get_brush();

Modified: trunk/src/editor2/mouse_action.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/mouse_action.cpp?rev=28535&r1=28534&r2=28535&view=diff
==============================================================================
--- trunk/src/editor2/mouse_action.cpp (original)
+++ trunk/src/editor2/mouse_action.cpp Wed Aug 13 14:44:11 2008
@@ -27,6 +27,7 @@
 
 void mouse_action::move(editor_display& disp, int x, int y)
 {
+       previous_move_hex_ = disp.hex_clicked_on(x, y);
 }
 
 editor_action* mouse_action::drag(editor_display& disp, int x, int y, bool& 
partial, editor_action* last_undo)
@@ -39,21 +40,39 @@
        return NULL;
 }
 
+editor_action* mouse_action::key_event(editor_display& disp, const 
SDL_Event& e)
+{
+       return NULL;
+}
+
 
 void brush_drag_mouse_action::move(editor_display& disp, int x, int y)
 {
        gamemap::location hex = disp.hex_clicked_on(x, y);
+       move(disp, hex);
+}
+
+void brush_drag_mouse_action::move(editor_display& disp, const 
gamemap::location& hex)
+{
+       LOG_ED << "Move" << hex << previous_move_hex_ << "\n";
        if (hex != previous_move_hex_) {
-               
disp.set_brush_locs(get_brush().project(disp.hex_clicked_on(x,y)));
+               LOG_ED << "setMove\n";
+               disp.set_brush_locs(affected_hexes(disp, hex));
                previous_move_hex_ = hex;
        }
 }
 
+std::set<gamemap::location> brush_drag_mouse_action::affected_hexes(
+       editor_display& disp, const gamemap::location& hex)
+{
+       return get_brush().project(hex);
+}
+
 editor_action* brush_drag_mouse_action::click(editor_display& disp, int x, 
int y)
 {
        gamemap::location hex = disp.hex_clicked_on(x, y);
        previous_drag_hex_ = hex;
-       return click_perform(disp, hex);
+       return click_perform(disp, affected_hexes(disp, hex));
 }
 
 editor_action* brush_drag_mouse_action::drag(editor_display& disp, int x, 
int y, bool& partial, editor_action* last_undo)
@@ -61,7 +80,7 @@
        move(disp, x, y);
        gamemap::location hex = disp.hex_clicked_on(x, y);
        if (hex != previous_drag_hex_) {
-               editor_action* a = click_perform(disp, hex);
+               editor_action* a = click_perform(disp, affected_hexes(disp, 
hex));
                previous_drag_hex_ = hex;
                return a;
        } else {
@@ -82,10 +101,10 @@
 }
 
 
-editor_action* mouse_action_paint::click_perform(editor_display& disp, const 
gamemap::location& hex)
+editor_action* mouse_action_paint::click_perform(editor_display& disp, const 
std::set<gamemap::location>& hexes)
 {
        bool one_layer = (key_[SDLK_RALT] || key_[SDLK_LALT]);
-       return new editor_action_paint_area(get_brush().project(hex), 
terrain_, one_layer);
+       return new editor_action_paint_area(hexes, terrain_, one_layer);
 }
 
 editor_action* mouse_action_select::click(editor_display& disp, int x, int y)
@@ -95,13 +114,32 @@
        return brush_drag_mouse_action::click(disp, x, y);
 }
 
-editor_action* mouse_action_select::click_perform(editor_display& disp, 
const gamemap::location& hex)
-{
-       editor_action* a(NULL);
+std::set<gamemap::location> mouse_action_select::affected_hexes(
+       editor_display& disp, const gamemap::location& hex)
+{
+       if (key_[SDLK_RALT] || key_[SDLK_LALT]) {
+               return disp.map().get_contigious_terrain_tiles(hex);
+       } else {
+               return brush_drag_mouse_action::affected_hexes(disp, hex);
+       }
+}
+
+editor_action* mouse_action_select::key_event(editor_display& disp, const 
SDL_Event& e)
+{
+       // Force an actual move
+       gamemap::location tmp = previous_move_hex_;
+       previous_move_hex_ = gamemap::location();
+       move(disp, tmp);
+       return NULL;
+}
+
+editor_action* mouse_action_select::click_perform(editor_display& disp, 
const std::set<gamemap::location>& hexes)
+{
+       editor_action* a(NULL); 
        if (selecting_) {
-               a = new editor_action_select(get_brush().project(hex));
+               a = new editor_action_select(hexes);
        } else {
-               a = new editor_action_deselect(get_brush().project(hex));
+               a = new editor_action_deselect(hexes);
        }
        return a;
 }
@@ -134,6 +172,7 @@
        bool one_layer = (key_[SDLK_RALT] || key_[SDLK_LALT]);
        gamemap::location hex = disp.hex_clicked_on(x, y);
        //TODO only take the base terrain into account when searching for 
contigious terrain when painting base only
+       //or use a different key modifier for that
        editor_action_fill* a = new editor_action_fill(hex, terrain_, 
one_layer);
        return a;
 }
@@ -141,13 +180,20 @@
 
 void mouse_action_starting_position::move(editor_display& disp, int x, int y)
 {
-       disp.clear_brush_locs();
-       disp.add_brush_loc(disp.hex_clicked_on(x, y));
+       gamemap::location hex = disp.hex_clicked_on(x, y);
+       if (hex != previous_move_hex_) {
+               disp.clear_brush_locs();
+               disp.add_brush_loc(disp.hex_clicked_on(x, y));
+               previous_move_hex_ = disp.hex_clicked_on(x, y);
+       }
 }
 
 editor_action* mouse_action_starting_position::click(editor_display& disp, 
int x, int y)
 {
        gamemap::location hex = disp.hex_clicked_on(x, y);
+       if (!disp.map().on_board(hex)) {
+               return NULL;
+       }
        int player_starting_at_hex = disp.map().is_starting_position(hex) + 1;
        std::vector<std::string> players;
        players.push_back(_("(Player)^None"));
@@ -157,18 +203,38 @@
                players.push_back(str.str());
        }
        gui::dialog pmenu = gui::dialog(disp,
-                                      _("Which Player?"),
-                                      _("Which player should start here?"),
+                                      _("Choose player"),
+                                      _("Which player should start here? You 
can also use the 1-9 and delete keys to set/clear staring positions."),
                                       gui::OK_CANCEL);
        pmenu.set_menu(players);
        int res = pmenu.show();
        editor_action* a = NULL;
        if (res == 0 && player_starting_at_hex != -1) {
                a = new editor_action_starting_position(gamemap::location(), 
player_starting_at_hex);
-       } else if (res > 0) {
+       } else if (res > 0 && res != player_starting_at_hex) {
                a = new editor_action_starting_position(hex, res);
        }
        return a;
 }
 
+editor_action* mouse_action_starting_position::key_event(editor_display& 
disp, const SDL_Event& event)
+{
+       editor_action* a = NULL;
+       if (!disp.map().on_board(previous_move_hex_) || event.type != 
SDL_KEYUP) {
+               return NULL;
+       }
+       if (event.key.keysym.sym >= '1' && event.key.keysym.sym <= '9' || 
event.key.keysym.sym == SDLK_DELETE) {
+               int res = event.key.keysym.sym - '0';
+               if (res > gamemap::MAX_PLAYERS || event.key.keysym.sym == 
SDLK_DELETE) res = 0;
+               int player_starting_at_hex = 
disp.map().is_starting_position(previous_move_hex_) + 1;
+               if (res == 0 && player_starting_at_hex != -1) {
+                       a = new 
editor_action_starting_position(gamemap::location(), player_starting_at_hex);
+               } else if (res > 0 && res != player_starting_at_hex) {
+                       a = new 
editor_action_starting_position(previous_move_hex_, res);
+               }
+       }
+       return a;
+}
+
+
 } //end namespace editor2

Modified: trunk/src/editor2/mouse_action.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/mouse_action.hpp?rev=28535&r1=28534&r2=28535&view=diff
==============================================================================
--- trunk/src/editor2/mouse_action.hpp (original)
+++ trunk/src/editor2/mouse_action.hpp Wed Aug 13 14:44:11 2008
@@ -33,8 +33,8 @@
 class mouse_action
 {
 public:
-       mouse_action()
-       : toolbar_button_(NULL)
+       mouse_action(const CKey& key)
+       : key_(key), toolbar_button_(NULL)
        {
        }
 
@@ -57,11 +57,14 @@
         */
        virtual editor_action* drag_end(editor_display& disp, int x, int y);
        
+       virtual editor_action* key_event(editor_display& disp, const 
SDL_Event& e);
+       
        void set_toolbar_button(const theme::menu* value) { toolbar_button_ = 
value; }
        const theme::menu* toolbar_button() const { return toolbar_button_; }
 
 protected:
        gamemap::location previous_move_hex_;
+       const CKey& key_;
        
 private:
        const theme::menu* toolbar_button_;
@@ -70,13 +73,15 @@
 class brush_drag_mouse_action : public mouse_action
 {
 public:
-       brush_drag_mouse_action(const brush* const * const brush)
-       : mouse_action(), brush_(brush)
+       brush_drag_mouse_action(const brush* const * const brush, const CKey& 
key)
+       : mouse_action(key), brush_(brush)
        {
        }
        void move(editor_display& disp, int x, int y);
+       void move(editor_display& disp, const gamemap::location& hex);
+       virtual std::set<gamemap::location> affected_hexes(editor_display& 
disp, const gamemap::location& hex);
        editor_action* click(editor_display& disp, int x, int y);
-       virtual editor_action* click_perform(editor_display& disp, const 
gamemap::location& hex) = 0;
+       virtual editor_action* click_perform(editor_display& disp, const 
std::set<gamemap::location>& hexes) = 0;
        editor_action* drag(editor_display& disp, int x, int y, bool& 
partial, editor_action* last_undo);
        editor_action* drag_end(editor_display& disp, int x, int y);    
 protected:
@@ -90,24 +95,25 @@
 {
 public:
        mouse_action_paint(const t_translation::t_terrain& terrain, const 
brush* const * const brush, const CKey& key)
-       : brush_drag_mouse_action(brush), terrain_(terrain), key_(key)
+       : brush_drag_mouse_action(brush, key), terrain_(terrain)
        {
        }
-       editor_action* click_perform(editor_display& disp, const 
gamemap::location& hex);
+       editor_action* click_perform(editor_display& disp, const 
std::set<gamemap::location>& hexes);
 protected:
        const t_translation::t_terrain& terrain_;
-       const CKey& key_;
 };
 
 class mouse_action_select : public brush_drag_mouse_action
 {
 public:
-       mouse_action_select(const brush* const * const brush)
-       : brush_drag_mouse_action(brush), selecting_(true)
+       mouse_action_select(const brush* const * const brush, const CKey& key)
+       : brush_drag_mouse_action(brush, key), selecting_(true)
        {
        }
+       std::set<gamemap::location> affected_hexes(editor_display& disp, 
const gamemap::location& hex);
+       editor_action* key_event(editor_display& disp, const SDL_Event& e);
        editor_action* click(editor_display& disp, int x, int y);
-       editor_action* click_perform(editor_display& disp, const 
gamemap::location& hex);
+       editor_action* click_perform(editor_display& disp, const 
std::set<gamemap::location>& hexes);
 protected:
        bool selecting_;
 };
@@ -115,8 +121,8 @@
 class mouse_action_paste : public mouse_action
 {
 public:
-       mouse_action_paste(const map_fragment& paste)
-       : mouse_action(), paste_(paste)
+       mouse_action_paste(const map_fragment& paste, const CKey& key)
+       : mouse_action(key), paste_(paste)
        {
        }
        void move(editor_display& disp, int x, int y);
@@ -129,23 +135,23 @@
 {
 public:
        mouse_action_fill(const t_translation::t_terrain& terrain, const 
CKey& key)
-       : mouse_action(), terrain_(terrain), key_(key)
+       : mouse_action(key), terrain_(terrain)
        {
        }
        void move(editor_display& disp, int x, int y);
        editor_action* click(editor_display& disp, int x, int y);
 protected:
        const t_translation::t_terrain& terrain_;
-       const CKey& key_;
 };
 
 class mouse_action_starting_position : public mouse_action
 {
 public:
-       mouse_action_starting_position()
-       : mouse_action()
+       mouse_action_starting_position(const CKey& key)
+       : mouse_action(key)
        {
        }
+       editor_action* key_event(editor_display& disp, const SDL_Event& e);
        void move(editor_display& disp, int x, int y);
        editor_action* click(editor_display& disp, int x, int y);
 };




Related Messages


Powered by MHonArc, Updated Wed Aug 13 16:01:40 2008