mail[Wesnoth-commits] r41482 - in /branches/fendrin_editor: data/themes/ src/ src/editor/


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

Header


Content

Posted by fabianmueller5 on March 06, 2010 - 22:55:
Author: fendrin
Date: Sat Mar  6 22:55:41 2010
New Revision: 41482

URL: http://svn.gna.org/viewcvs/wesnoth?rev=41482&view=rev
Log:
Enabled side switching to the editor. 
Yumm.

Modified:
    branches/fendrin_editor/data/themes/editor.cfg
    branches/fendrin_editor/src/editor/editor_controller.cpp
    branches/fendrin_editor/src/editor/editor_controller.hpp
    branches/fendrin_editor/src/editor/editor_map.hpp
    branches/fendrin_editor/src/editor/mouse_action.cpp
    branches/fendrin_editor/src/hotkeys.cpp
    branches/fendrin_editor/src/hotkeys.hpp

Modified: branches/fendrin_editor/data/themes/editor.cfg
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/fendrin_editor/data/themes/editor.cfg?rev=41482&r1=41481&r2=41482&view=diff
==============================================================================
--- branches/fendrin_editor/data/themes/editor.cfg (original)
+++ branches/fendrin_editor/data/themes/editor.cfg Sat Mar  6 22:55:41 2010
@@ -159,6 +159,16 @@
         [/menu]
 
         [menu]
+            id=menu-editor-side
+            title= _ "Side"
+            image=lite
+            items=editor-switch-side
+            rect="+2,=,+100,="
+            xanchor=fixed
+            yanchor=fixed
+        [/menu]
+
+        [menu]
             id=menu-editor-areas
             title= _ "Areas"
             image=lite
@@ -233,6 +243,7 @@
         [menu]
             id=unit_button_editor
             image=start_position_button_editor
+#            image=themes/units.png
             items=editor-tool-unit
             ref=draw_button_editor
             # wmllint: local spelling alt+number

Modified: branches/fendrin_editor/src/editor/editor_controller.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/fendrin_editor/src/editor/editor_controller.cpp?rev=41482&r1=41481&r2=41482&view=diff
==============================================================================
--- branches/fendrin_editor/src/editor/editor_controller.cpp (original)
+++ branches/fendrin_editor/src/editor/editor_controller.cpp Sat Mar  6 
22:55:41 2010
@@ -398,6 +398,31 @@
        resources::units = &((*map_contexts_[index]).get_map().get_units());
 }
 
+void editor_controller::switch_area(const int index)
+{
+       //TODO implement undo
+       const map_areas areas = get_map().get_named_areas();
+       const std::vector<std::string> ids = areas.get_area_ids();
+       current_area_index_ = index;
+       std::string area_id = ids[index];
+       map_area area = areas.get_area(area_id);
+       std::set<map_location> area_locs = area.get_simple_locations();
+       get_display().scroll_to_tile(*(area_locs.begin()),display::WARP);
+       perform_refresh(editor_action_select(area_locs));
+}
+
+void editor_controller::switch_side(const int index)
+{
+       if (index < 0 || static_cast<size_t>(index) >= 
get_map_context().get_map().get_teams().size()) {
+               //TODO extend the number of sides.
+               WRN_ED << "Invalid index in switch side context: " << index 
<< "\n";
+               return;
+       }
+       get_display().set_playing_team(index);
+       current_side_index_ = index;
+       //TODO implement
+}
+
 void editor_controller::replace_map_context(map_context* new_mc)
 {
        std::auto_ptr<map_context> del(map_contexts_[current_context_index_]);
@@ -835,24 +860,21 @@
 {
 
        using namespace hotkey; //reduce hotkey:: clutter
+       unsigned i = static_cast<unsigned>(index);
        switch (command) {
                case HOTKEY_NULL:
-                       if (is_map_menu_) {
-                               if (index >= 0) {
-                                       unsigned i = 
static_cast<unsigned>(index);
-                                       if (i < map_contexts_.size()) {
-                                               return true;
-                                       }
-                               }
-                       } else {
-                               //TODO move to an action
-                               //                              
get_map().get_named_areas().
-                               //                              unsigned i = 
static_cast<unsigned>(index);
-
-                               //                              if (i < 
get_map().get_named_areas().get_area_ids().size()           )
-                               return true;
-                       }
-                       return false;
+
+                       if (index < 0)
+                               return false;
+
+                       switch (menu_context_) {
+                               case WINDOW:
+                                       return (i < map_contexts_.size());
+                               case AREA:
+                                       return (i < 
get_map().get_named_areas().get_area_ids().size());
+                               case SIDE:
+                                       return (i < 
get_map().get_teams().size());
+                       }
                case HOTKEY_ZOOM_IN:
                case HOTKEY_ZOOM_OUT:
                case HOTKEY_ZOOM_DEFAULT:
@@ -884,6 +906,7 @@
                case HOTKEY_EDITOR_MAP_SAVE:
                case HOTKEY_EDITOR_SWITCH_MAP:
                case HOTKEY_EDITOR_SWITCH_AREA:
+               case HOTKEY_EDITOR_SWITCH_SIDE:
                case HOTKEY_EDITOR_CLOSE_MAP:
                        return true;
                case HOTKEY_EDITOR_MAP_REVERT:
@@ -957,10 +980,15 @@
                case HOTKEY_EDITOR_DRAW_TERRAIN_CODES:
                        return gui_->get_draw_terrain_codes() ? ACTION_ON : 
ACTION_OFF;
                case HOTKEY_NULL:
-                       if (is_map_menu_) {
-                       return index == current_context_index_ ? ACTION_ON : 
ACTION_OFF; }
-                       else { return index == current_area_index_ ? 
ACTION_ON : ACTION_OFF; }
-               default:
+                       switch (menu_context_) {
+                       case WINDOW:
+                               return index == current_context_index_ ? 
ACTION_ON : ACTION_OFF;
+                       case AREA:
+                               return index == current_area_index_ ? 
ACTION_ON : ACTION_OFF;
+                       case SIDE:
+                               return index == current_side_index_ ? 
ACTION_ON : ACTION_OFF;
+                       }
+                       default:
                        return command_executor::get_action_state(command, 
index);
        }
 }
@@ -969,29 +997,43 @@
 {
        SCOPE_ED;
        using namespace hotkey;
+       unsigned i = static_cast<unsigned>(index);
        switch (command) {
                case HOTKEY_NULL:
-                       if (is_map_menu_) {
-                               if (index >= 0) {
-                                       unsigned i = 
static_cast<unsigned>(index);
-                                       if (i < map_contexts_.size()) {
-                                               switch_context(index);
-                                               return true;
-                                       }
+                       if (index < 0) {
+                               return false;
+                       }
+                       switch (menu_context_) {
+
+                       case WINDOW:
+                               if (i < map_contexts_.size()) {
+                                       switch_context(index);
+                                       return true;
                                }
-                       } else {
-                               //TODO implement undo
-                               const map_areas areas = 
get_map().get_named_areas();
-                               const std::vector<std::string> ids = 
areas.get_area_ids();
-                               current_area_index_ = index;
-                               std::string area_id = ids[index];
-                               map_area area = areas.get_area(area_id);
-                               std::set<map_location> area_locs = 
area.get_simple_locations();
-                               
get_display().scroll_to_tile(*(area_locs.begin()),display::WARP);
-                               
perform_refresh(editor_action_select(area_locs));
-                               return true;
-                       }
-                       return false;
+                       case SIDE:
+                               if (i < get_map().get_teams().size()) {
+                                       switch_side(index);
+                                       return true;
+                               }
+                       case AREA:
+                               if (i < 
get_map().get_named_areas().get_area_ids().size()) {
+                                       switch_area(index);
+                                       return true;
+                               }
+                       }
+
+
+//                             //TODO implement undo
+//                             const map_areas areas = 
get_map().get_named_areas();
+//                             const std::vector<std::string> ids = 
areas.get_area_ids();
+//                             current_area_index_ = index;
+//                             std::string area_id = ids[index];
+//                             map_area area = areas.get_area(area_id);
+//                             std::set<map_location> area_locs = 
area.get_simple_locations();
+//                             
get_display().scroll_to_tile(*(area_locs.begin()),display::WARP);
+//                             
perform_refresh(editor_action_select(area_locs));
+
+
                case HOTKEY_QUIT_GAME:
                        quit_confirm(EXIT_NORMAL);
                        return true;
@@ -1167,21 +1209,33 @@
                        break;
                }
        }
-       is_map_menu_ = true;
+       menu_context_ = WINDOW;
+}
+
+void editor_controller::expand_side_menu(std::vector<std::string>& items)
+{
+       for (unsigned int i = 0 ; i < items.size(); ++i) {
+               if (items[i] == "editor-switch-side") {
+                       items.erase(items.begin() + i);
+                       for (unsigned int i = 0; i < 
get_map().get_teams().size(); ++i) {
+                               std::string side_text = _("Side ") + i;
+                               items.push_back(side_text);
+                       }
+               }
+       }
+       menu_context_ = SIDE;
 }
 
 void editor_controller::expand_named_area_menu(std::vector<std::string>& 
items)
 {
-               for (unsigned int i = 0; i < items.size(); ++i) {
+       for (unsigned int i = 0; i < items.size(); ++i) {
                if (items[i] == "editor-switch-area") {
                        items.erase(items.begin() + i);
                        std::vector<std::string> areas = 
get_map().get_named_areas().get_area_ids();
                        items.insert(items.end(), areas.begin(), areas.end() 
);
                }
        }
-       is_map_menu_ = false;
-//     TODO clean up.
-       //get_display().labels().clear_all();
+       menu_context_ = AREA;
 }
 
 void editor_controller::show_menu(const std::vector<std::string>& items_arg, 
int xloc, int yloc, bool context_menu)
@@ -1234,6 +1288,10 @@
        }
        if (!items.empty() && items.front() == "editor-switch-area") {
                expand_named_area_menu(items);
+               context_menu = true; //FIXME hack to display a one-item menu
+       }
+       if (!items.empty() && items.front() == "editor-switch-side") {
+               expand_side_menu(items);
                context_menu = true; //FIXME hack to display a one-item menu
        }
        command_executor::show_menu(items, xloc, yloc, context_menu, gui());

Modified: branches/fendrin_editor/src/editor/editor_controller.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/fendrin_editor/src/editor/editor_controller.hpp?rev=41482&r1=41481&r2=41482&view=diff
==============================================================================
--- branches/fendrin_editor/src/editor/editor_controller.hpp (original)
+++ branches/fendrin_editor/src/editor/editor_controller.hpp Sat Mar  6 
22:55:41 2010
@@ -137,6 +137,12 @@
                /** Switches the context to the one under the specified 
index. */
                void switch_context(const int index);
 
+               /** Switches the side to the one under the specified index. */
+               void switch_area(const int index);
+
+               /** Switches the side to the one under the specified index. */
+               void switch_side(const int index);
+
                /** Set the default dir (where the filebrowser is pointing at 
when there is no map file opened) */
                void set_default_dir(const std::string& str);
 
@@ -231,6 +237,9 @@
 
                /** Menu expanding for open maps list */
                void expand_open_maps_menu(std::vector<std::string>& items);
+
+               /** Menu expanding for defined locations list */
+               void expand_side_menu(std::vector<std::string>& items);
 
                /** Menu expanding for defined locations list */
                void expand_named_area_menu(std::vector<std::string>& items);
@@ -397,6 +406,9 @@
                /** Index for the areas */
                int current_area_index_;
 
+               /** Index for the sides */
+               int current_side_index_;
+
                /** The display object used and owned by the editor. */
                boost::scoped_ptr<editor_display> gui_;
 
@@ -466,7 +478,13 @@
                /** Default directory for map load/save as dialogs */
                std::string default_dir_;
 
-               bool is_map_menu_;
+               enum menu_context {
+                               WINDOW,
+                               AREA,
+                               SIDE,
+                       };
+
+               menu_context menu_context_;
 
                //TODO
                game_state game_state_;

Modified: branches/fendrin_editor/src/editor/editor_map.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/fendrin_editor/src/editor/editor_map.hpp?rev=41482&r1=41481&r2=41482&view=diff
==============================================================================
--- branches/fendrin_editor/src/editor/editor_map.hpp (original)
+++ branches/fendrin_editor/src/editor/editor_map.hpp Sat Mar  6 22:55:41 2010
@@ -135,6 +135,8 @@
 
        map_areas& get_named_areas() { return named_areas_; }
 
+       const map_areas& get_named_areas() const { return named_areas_; }
+
        const labels& get_game_labels() const { return game_labels_; }
 
        tod_manager&  get_tod_manager() { return tod_manager_; }
@@ -144,6 +146,8 @@
 //     soundsource::manager* get_sound_source_manager() { return 
soundsources_manager_; }
 
        std::vector<team>&  get_teams() { return teams_; }
+
+       const std::vector<team>& get_teams() const { return teams_; }
 
        /**
         * Set labels for staring positions in the given display object.

Modified: branches/fendrin_editor/src/editor/mouse_action.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/fendrin_editor/src/editor/mouse_action.cpp?rev=41482&r1=41481&r2=41482&view=diff
==============================================================================
--- branches/fendrin_editor/src/editor/mouse_action.cpp (original)
+++ branches/fendrin_editor/src/editor/mouse_action.cpp Sat Mar  6 22:55:41 
2010
@@ -450,7 +450,7 @@
        click_ = true;
        map_location hex = disp.hex_clicked_on(x, y);
        clicked_on_ = hex;
-
+       last_draged_ = hex;
        return NULL;
 }
 editor_action* mouse_action_map_label::click_right(editor_display& /*disp*/, 
int /*x*/, int /*y*/)
@@ -472,8 +472,7 @@
 
        //TODO this is somewhat hacky.
        disp.labels().clear_all();
-       disp.map().set_starting_position_labels(disp);
-       disp.invalidate(last_draged_);
+       //TODO How can they be redrawn?
 
        last_draged_ = hex;
 
@@ -481,6 +480,7 @@
        if (clicked_label) {
                std::string text = clicked_label->text() + "\n";
                const label* hex_label = disp.labels().get_label(hex);
+               //TODO the stacking is not working because we don't redraw 
all the labels.
                if (hex_label)
                        text += hex_label->text();
 

Modified: branches/fendrin_editor/src/hotkeys.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/fendrin_editor/src/hotkeys.cpp?rev=41482&r1=41481&r2=41482&view=diff
==============================================================================
--- branches/fendrin_editor/src/hotkeys.cpp (original)
+++ branches/fendrin_editor/src/hotkeys.cpp Sat Mar  6 22:55:41 2010
@@ -105,6 +105,7 @@
        { hotkey::HOTKEY_EDITOR_QUIT_TO_DESKTOP, "editor-quit-to-desktop", 
N_("Quit to Desktop"), false, hotkey::SCOPE_EDITOR },
        { hotkey::HOTKEY_EDITOR_CLOSE_MAP, "editor-close-map", N_("Close 
Map"), false, hotkey::SCOPE_EDITOR },
        { hotkey::HOTKEY_EDITOR_SWITCH_MAP, "editor-switch-map", N_("Switch 
Map"), false, hotkey::SCOPE_EDITOR },
+       { hotkey::HOTKEY_EDITOR_SWITCH_SIDE, "editor-switch-side", N_("Switch 
Side"), false, hotkey::SCOPE_EDITOR },
        { hotkey::HOTKEY_EDITOR_SWITCH_AREA, "editor-switch-area", N_("Switch 
Area"), false, hotkey::SCOPE_EDITOR },
        { hotkey::HOTKEY_EDITOR_SETTINGS, "editor-settings", N_("Editor 
Settings"), false, hotkey::SCOPE_EDITOR },
        { hotkey::HOTKEY_EDITOR_PARTIAL_UNDO, "editor-partial-undo", 
N_("Partial Undo"), false, hotkey::SCOPE_EDITOR },

Modified: branches/fendrin_editor/src/hotkeys.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/fendrin_editor/src/hotkeys.hpp?rev=41482&r1=41481&r2=41482&view=diff
==============================================================================
--- branches/fendrin_editor/src/hotkeys.hpp (original)
+++ branches/fendrin_editor/src/hotkeys.hpp Sat Mar  6 22:55:41 2010
@@ -64,7 +64,7 @@
 #ifndef DISABLE_EDITOR
        HOTKEY_EDITOR_QUIT_TO_DESKTOP,
        HOTKEY_EDITOR_CLOSE_MAP, HOTKEY_EDITOR_SWITCH_MAP,
-       HOTKEY_EDITOR_SWITCH_AREA,
+       HOTKEY_EDITOR_SWITCH_AREA, HOTKEY_EDITOR_SWITCH_SIDE,
        HOTKEY_EDITOR_SETTINGS,
        HOTKEY_EDITOR_PARTIAL_UNDO,
        HOTKEY_EDITOR_MAP_NEW, HOTKEY_EDITOR_MAP_LOAD, HOTKEY_EDITOR_MAP_SAVE,




Related Messages


Powered by MHonArc, Updated Sun Mar 07 00:40:10 2010