mail[Wesnoth-commits] r28349 - /trunk/src/editor2/


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

Header


Content

Posted by kailoran on August 07, 2008 - 07:43:
Author: ilor
Date: Wed Aug  6 17:45:21 2008
New Revision: 28349

URL: http://svn.gna.org/viewcvs/wesnoth?rev=28349&view=rev
Log:
editor: starting position tool (works more or less like in the old editor)

Modified:
    trunk/src/editor2/action.cpp
    trunk/src/editor2/action.hpp
    trunk/src/editor2/editor_controller.cpp
    trunk/src/editor2/editor_map.cpp
    trunk/src/editor2/editor_map.hpp
    trunk/src/editor2/map_context.cpp
    trunk/src/editor2/map_context.hpp
    trunk/src/editor2/mouse_action.cpp
    trunk/src/editor2/mouse_action.hpp

Modified: trunk/src/editor2/action.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/action.cpp?rev=28349&r1=28348&r2=28349&view=diff
==============================================================================
--- trunk/src/editor2/action.cpp (original)
+++ trunk/src/editor2/action.cpp Wed Aug  6 17:45:21 2008
@@ -51,6 +51,9 @@
                delete a;
        }
 }
+void editor_action_chain::append_action(editor_action* a) {
+       actions_.push_back(a);
+}
 editor_action_chain* editor_action_chain::perform(map_context& mc) const {
        std::vector<editor_action*> undo;
        foreach (editor_action* a, actions_) {
@@ -125,12 +128,42 @@
        mc.set_needs_terrain_rebuild();
 }
 
+editor_action* editor_action_starting_position::perform(map_context& mc) 
const
+{
+       editor_action* undo;
+       int old_player = mc.get_map().is_starting_position(loc_) + 1;
+       gamemap::location old_loc = mc.get_map().starting_position(player_);
+       LOG_ED << "ssp perform, player_" << player_ << ", loc_ " << loc_ << 
", old_player " << old_player << ", old_loc " << old_loc << "\n";
+       if (old_player != -1) {
+               editor_action_chain* undo_chain = new editor_action_chain();
+               undo_chain->append_action(new 
editor_action_starting_position(loc_, old_player));
+               undo_chain->append_action(new 
editor_action_starting_position(old_loc, player_));
+               undo = undo_chain;
+               LOG_ED << "ssp actual: " << old_player << " to " << 
gamemap::location() << "\n";
+               mc.get_map().set_starting_position(old_player, 
gamemap::location());
+       } else {
+               undo = new editor_action_starting_position(old_loc, player_);
+       }
+       LOG_ED << "ssp actual: " << player_ << " to " << loc_ << "\n";
+       mc.get_map().set_starting_position(player_, loc_);
+       mc.set_needs_labels_reset();
+       return undo;
+}
+void editor_action_starting_position::perform_without_undo(map_context& mc) 
const
+{
+       int old_player = mc.get_map().is_starting_position(loc_);
+       if (old_player != -1) {
+               mc.get_map().set_starting_position(old_player, 
gamemap::location());
+       }
+       mc.get_map().set_starting_position(player_, loc_);
+       mc.set_needs_labels_reset();
+}
+
 editor_action_select_xor* editor_action_select_xor::perform(map_context& mc) 
const
 {
        perform_without_undo(mc);
        return new editor_action_select_xor(area_);
 }
-
 void editor_action_select_xor::perform_without_undo(map_context& mc) const
 {
        foreach (const gamemap::location& loc, area_) {

Modified: trunk/src/editor2/action.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/action.hpp?rev=28349&r1=28348&r2=28349&view=diff
==============================================================================
--- trunk/src/editor2/action.hpp (original)
+++ trunk/src/editor2/action.hpp Wed Aug  6 17:45:21 2008
@@ -50,11 +50,15 @@
 class editor_action_chain : public editor_action
 {
        public:
+               editor_action_chain()
+               {
+               }
                explicit editor_action_chain(std::vector<editor_action*> 
actions)
                : actions_(actions)
                {
                }
                ~editor_action_chain();
+               void append_action(editor_action* a);
                editor_action_chain* perform(map_context& m) const;
            void perform_without_undo(map_context& m) const;
     protected:
@@ -154,6 +158,19 @@
         }
         editor_action_paint_area* perform(map_context& mc) const;
         void perform_without_undo(map_context& mc) const;
+};
+
+class editor_action_starting_position : public editor_action_location
+{
+    public:
+        editor_action_starting_position(gamemap::location loc, int player)
+        : editor_action_location(loc), player_(player)
+        {
+        }
+        editor_action* perform(map_context& mc) const;
+        void perform_without_undo(map_context& mc) const;
+       protected:
+               int player_;
 };
 
 class editor_action_select_xor : public editor_action_area

Modified: trunk/src/editor2/editor_controller.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_controller.cpp?rev=28349&r1=28348&r2=28349&view=diff
==============================================================================
--- trunk/src/editor2/editor_controller.cpp (original)
+++ trunk/src/editor2/editor_controller.cpp Wed Aug  6 17:45:21 2008
@@ -72,6 +72,8 @@
                new mouse_action_fill(foreground_terrain_)));
        
mouse_actions_.insert(std::make_pair(hotkey::HOTKEY_EDITOR_TOOL_SELECT, 
                new mouse_action_select(&brush_)));
+       
mouse_actions_.insert(std::make_pair(hotkey::HOTKEY_EDITOR_TOOL_STARTING_POSITION,
+               new mouse_action_starting_position()));
        mouse_actions_.insert(std::make_pair(hotkey::HOTKEY_EDITOR_PASTE,
                new mouse_action_paste(clipboard_)));
        hotkey_set_mouse_action(hotkey::HOTKEY_EDITOR_TOOL_PAINT);      
@@ -407,8 +409,10 @@
                case HOTKEY_EDITOR_TOOL_PAINT:
                case HOTKEY_EDITOR_TOOL_FILL:
                case HOTKEY_EDITOR_TOOL_SELECT:
-               case HOTKEY_EDITOR_PASTE:
-//             case HOTKEY_EDITOR_TOOL_STARTING_POSITION:
+               case HOTKEY_EDITOR_TOOL_STARTING_POSITION:
+                       hotkey_set_mouse_action(command);
+                       return true;
+               case HOTKEY_EDITOR_PASTE: //paste is somewhat different as it 
might be "one action then revert to previous mode"
                        hotkey_set_mouse_action(command);
                        return true;
                case HOTKEY_EDITOR_BRUSH_NEXT:
@@ -629,23 +633,30 @@
                reload_map();
                get_map_context().set_needs_reload(false);
                get_map_context().set_needs_terrain_rebuild(false);
-               get_map_context().clear_changed_locations();
-       } else if (get_map_context().needs_terrain_rebuild()) {
-               if (!drag_part || auto_update_transitions_ || 
get_map_context().everything_changed()) {
-                       gui().rebuild_all();
-                       gui().invalidate_all(); 
-                       get_map_context().set_needs_terrain_rebuild(false);
+               get_map_context().set_needs_labels_reset(false);
+       } else {
+               if (get_map_context().needs_terrain_rebuild()) {
+                       if (!drag_part || auto_update_transitions_ || 
get_map_context().everything_changed()) {
+                               gui().rebuild_all();
+                               gui().invalidate_all(); 
+                               
get_map_context().set_needs_terrain_rebuild(false);
+                       } else {
+                               foreach (const gamemap::location& loc, 
get_map_context().changed_locations()) {
+                                       gui().rebuild_terrain(loc);
+                               }
+                               
gui().invalidate(get_map_context().changed_locations());
+                       }
                } else {
-                       foreach (const gamemap::location& loc, 
get_map_context().changed_locations()) {
-                               gui().rebuild_terrain(loc);
-                       }
-                       
gui().invalidate(get_map_context().changed_locations());
-               }
-       } else {
-               if (get_map_context().everything_changed()) {
-                       gui().invalidate_all();
-               } else {
-                       
gui().invalidate(get_map_context().changed_locations());
+                       if (get_map_context().everything_changed()) {
+                               gui().invalidate_all();
+                       } else {
+                               
gui().invalidate(get_map_context().changed_locations());
+                       }
+               }
+               if (get_map_context().needs_labels_reset()) {
+                       
get_map_context().clear_starting_position_labels(gui());
+                       get_map_context().set_starting_position_labels(gui());
+                       get_map_context().set_needs_labels_reset(false);
                }
        }
        get_map_context().clear_changed_locations();

Modified: trunk/src/editor2/editor_map.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_map.cpp?rev=28349&r1=28348&r2=28349&view=diff
==============================================================================
--- trunk/src/editor2/editor_map.cpp (original)
+++ trunk/src/editor2/editor_map.cpp Wed Aug  6 17:45:21 2008
@@ -214,11 +214,6 @@
        }
 }
 
-void editor_map::set_starting_position(int pos, const location& loc)
-{
-       startingPositions_[pos] = loc;
-}
-
 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=28349&r1=28348&r2=28349&view=diff
==============================================================================
--- trunk/src/editor2/editor_map.hpp (original)
+++ trunk/src/editor2/editor_map.hpp Wed Aug  6 17:45:21 2008
@@ -106,7 +106,6 @@
        void flip_y();
 
 protected:
-       void set_starting_position(int pos, const location& loc);
        void swap_starting_position(int x1, int y1, int x2, int y2);
        t_translation::t_list clone_column(int x, t_translation::t_terrain 
filler);
        void expand_right(int count, t_translation::t_terrain filler);

Modified: trunk/src/editor2/map_context.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/map_context.cpp?rev=28349&r1=28348&r2=28349&view=diff
==============================================================================
--- trunk/src/editor2/map_context.cpp (original)
+++ trunk/src/editor2/map_context.cpp Wed Aug  6 17:45:21 2008
@@ -32,7 +32,8 @@
 
 map_context::map_context(const editor_map& map)
 : map_(map), filename_(), actions_since_save_(0),
-needs_reload_(false), needs_terrain_rebuild_(false), 
everything_changed_(false)
+needs_reload_(false), needs_terrain_rebuild_(false), 
+needs_labels_reset_(false), everything_changed_(false)
 {
 }
 

Modified: trunk/src/editor2/map_context.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/map_context.hpp?rev=28349&r1=28348&r2=28349&view=diff
==============================================================================
--- trunk/src/editor2/map_context.hpp (original)
+++ trunk/src/editor2/map_context.hpp Wed Aug  6 17:45:21 2008
@@ -47,6 +47,9 @@
        
        bool needs_terrain_rebuild() const { return needs_terrain_rebuild_; }
        void set_needs_terrain_rebuild(bool value=true) { 
needs_terrain_rebuild_ = value; }
+       
+       bool needs_labels_reset() const { return needs_labels_reset_; }
+       void set_needs_labels_reset(bool value=true) { needs_labels_reset_ = 
value; }
        
        const std::set<gamemap::location> changed_locations() const { return 
changed_locations_; }
        void clear_changed_locations();
@@ -153,6 +156,7 @@
        
        bool needs_reload_;
        bool needs_terrain_rebuild_;
+       bool needs_labels_reset_;
        std::set<gamemap::location> changed_locations_;
        bool everything_changed_;
 };

Modified: trunk/src/editor2/mouse_action.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/mouse_action.cpp?rev=28349&r1=28348&r2=28349&view=diff
==============================================================================
--- trunk/src/editor2/mouse_action.cpp (original)
+++ trunk/src/editor2/mouse_action.cpp Wed Aug  6 17:45:21 2008
@@ -18,7 +18,9 @@
 #include "editor_display.hpp"
 #include "mouse_action.hpp"
 
+#include "../construct_dialog.hpp"
 #include "../foreach.hpp"
+#include "../gettext.hpp"
 #include "../pathutils.hpp"
 
 namespace editor2 {
@@ -133,4 +135,37 @@
        return a;
 }
 
+
+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));
+}
+
+editor_action* mouse_action_starting_position::click(editor_display& disp, 
int x, int y)
+{
+       gamemap::location hex = disp.hex_clicked_on(x, y);
+       int player_starting_at_hex = disp.map().is_starting_position(hex) + 1;
+       std::vector<std::string> players;
+       players.push_back("None");
+       for (int i = 1; i <= gamemap::MAX_PLAYERS; i++) {
+               std::stringstream str;
+               str << _("Player") << " " << i;
+               players.push_back(str.str());
+       }
+       gui::dialog pmenu = gui::dialog(disp,
+                                      _("Which Player?"),
+                                      _("Which player should start here?"),
+                                      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) {
+               a = new editor_action_starting_position(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=28349&r1=28348&r2=28349&view=diff
==============================================================================
--- trunk/src/editor2/mouse_action.hpp (original)
+++ trunk/src/editor2/mouse_action.hpp Wed Aug  6 17:45:21 2008
@@ -129,6 +129,17 @@
        const t_translation::t_terrain& terrain_;
 };
 
+class mouse_action_starting_position : public mouse_action
+{
+public:
+       mouse_action_starting_position()
+       : mouse_action()
+       {
+       }
+       void move(editor_display& disp, int x, int y);
+       editor_action* click(editor_display& disp, int x, int y);
+};
+
 } //end namespace editor2
 
 #endif




Related Messages


Powered by MHonArc, Updated Thu Aug 07 09:00:50 2008