diff --git a/data/core/_main.cfg b/data/core/_main.cfg index b3f93735d21..db566ca398c 100644 --- a/data/core/_main.cfg +++ b/data/core/_main.cfg @@ -21,6 +21,7 @@ {core/units.cfg} #ifdef EDITOR2 {core/editor-groups.cfg} +{core/editor2-brushes.cfg} {core/editor2-hotkeys.cfg} #endif #endif diff --git a/data/core/editor2-brushes.cfg b/data/core/editor2-brushes.cfg new file mode 100644 index 00000000000..ffcc17d0ad3 --- /dev/null +++ b/data/core/editor2-brushes.cfg @@ -0,0 +1,57 @@ +#textdomain wesnoth-editor + +[brush] + radius=1 + name= _ "1 Hex" + [relative] + x=0 + y=1 + [/relative] +[/brush] + +[brush] + radius=2 + name= _ "Radius 2 Hex" +[/brush] + +[brush] + radius=3 + name= _ "Radius 3 Hex" +[/brush] + +[brush] + [relative] + x=-1 + y=-1 + [/relative] + [relative] + x=1 + y=0 + [/relative] + name= _ "Hex Line NW-SE" +[/brush] + +[brush] + [relative] + x=-1 + y=0 + [/relative] + [relative] + x=1 + y=-1 + [/relative] + name= _ "Hex Line NW-SE" +[/brush] + +[brush] + [relative] + x=0 + y=1 + [/relative] + [relative] + x=0 + y=-1 + [/relative] + name= _ "Hex Line N-S" +[/brush] + diff --git a/src/editor2/brush.cpp b/src/editor2/brush.cpp index 0d0a879cbed..6076cfc8714 100644 --- a/src/editor2/brush.cpp +++ b/src/editor2/brush.cpp @@ -55,7 +55,7 @@ std::set brush::project(const gamemap::location& hotspot) con { std::set result; foreach (const gamemap::location& relative, relative_tiles_) { - result.insert(hotspot + relative); + result.insert(relative + hotspot); } return result; } diff --git a/src/editor2/editor_controller.cpp b/src/editor2/editor_controller.cpp index b04f46cc63b..10356cec8e8 100644 --- a/src/editor2/editor_controller.cpp +++ b/src/editor2/editor_controller.cpp @@ -42,15 +42,19 @@ editor_controller::editor_controller(const config &game_config, CVideo& video) gui_->invalidate_all(); gui_->draw(); events::raise_draw_event(); + brushes_.push_back(brush()); - brushes_[0].add_relative_location(0,0); - brushes_[0].add_relative_location(1,0); - brushes_[0].add_relative_location(-1,0); - brushes_[0].add_relative_location(-2,0); + const config::child_list& children = game_config.get_children("brush"); + foreach (const config* i, game_config.get_children("brush")) { + brushes_.push_back(brush(*i)); + } + if (brushes_.size() == 1) { + WRN_ED << "No brushes defined!"; + } set_brush(&brushes_[0]); - mouse_actions_.push_back(new mouse_action_paint(*this)); - mouse_actions_.push_back(new mouse_action_fill(*this)); - set_mouse_action(mouse_actions_[0]); + mouse_actions_.insert(std::make_pair("paint", new mouse_action_paint(*this))); + mouse_actions_.insert(std::make_pair("fill", new mouse_action_fill(*this))); + set_mouse_action(mouse_actions_["paint"]); } @@ -68,8 +72,9 @@ editor_controller::~editor_controller() delete gui_; clear_stack(undo_stack_); clear_stack(redo_stack_); - foreach (mouse_action* a, mouse_actions_) { - delete a; + typedef std::pair apr; + foreach (apr a, mouse_actions_) { + delete a.second; } } @@ -104,6 +109,8 @@ bool editor_controller::can_execute_command(hotkey::HOTKEY_COMMAND command, int case HOTKEY_EDITOR_MAP_NEW: case HOTKEY_EDITOR_MAP_LOAD: case HOTKEY_EDITOR_MAP_SAVE_AS: + case HOTKEY_EDITOR_BRUSH_NEXT: + case HOTKEY_EDITOR_TOOL_NEXT: return true; //editor hotkeys we can always do case HOTKEY_EDITOR_MAP_SAVE: case HOTKEY_EDITOR_MAP_REVERT: @@ -138,13 +145,25 @@ bool editor_controller::can_execute_command(hotkey::HOTKEY_COMMAND command, int bool editor_controller::execute_command(hotkey::HOTKEY_COMMAND command, int index) { + SCOPE_ED; using namespace hotkey; switch (command) { case HOTKEY_EDITOR_TOOL_PAINT: - set_mouse_action(mouse_actions_[0]); + set_mouse_action(mouse_actions_["paint"]); return true; case HOTKEY_EDITOR_TOOL_FILL: - set_mouse_action(mouse_actions_[1]); + set_mouse_action(mouse_actions_["fill"]); + return true; + case HOTKEY_EDITOR_BRUSH_NEXT: + { + brush* next = get_brush(); + next++; + if (next > &brushes_.back()) { + next = &brushes_[0]; + } + set_brush(next); + gui().invalidate_all(); + } return true; default: return controller_base::execute_command(command, index); @@ -213,28 +232,22 @@ void editor_controller::clear_stack(action_stack& stack) bool editor_controller::can_undo() const { - std::cerr << "\ncan_undo" << undo_stack_.size() << "\n"; return !undo_stack_.empty(); } bool editor_controller::can_redo() const { - std::cerr << "\ncan_redo" << redo_stack_.size() << "\n"; return !redo_stack_.empty(); } void editor_controller::undo() { - std::cerr << "\npreundo : " << undo_stack_.size() << redo_stack_.size() << "\n"; perform_action_between_stacks(undo_stack_, redo_stack_); - std::cerr << "\nupostndo : " << undo_stack_.size() << redo_stack_.size() << "\n"; } void editor_controller::redo() { - std::cerr << "\npreredo : " << undo_stack_.size() << redo_stack_.size() << "\n"; perform_action_between_stacks(redo_stack_, undo_stack_); - std::cerr << "\npostredo : " << undo_stack_.size() << redo_stack_.size() << "\n"; } void editor_controller::perform_action_between_stacks(action_stack& from, action_stack& to) diff --git a/src/editor2/editor_controller.hpp b/src/editor2/editor_controller.hpp index 7e82f15451b..91964045382 100644 --- a/src/editor2/editor_controller.hpp +++ b/src/editor2/editor_controller.hpp @@ -140,7 +140,7 @@ class editor_controller : public controller_base, static const int max_action_stack_size_; std::vector brushes_; - std::vector mouse_actions_; + std::map mouse_actions_; }; } //end namespace editor2 diff --git a/src/editor2/editor_mode.hpp b/src/editor2/editor_mode.hpp index 74ef3c6313d..fd5d0360f1b 100644 --- a/src/editor2/editor_mode.hpp +++ b/src/editor2/editor_mode.hpp @@ -38,7 +38,7 @@ public: } const t_translation::t_terrain& get_foreground_terrain() const { return foreground_terrain_; } const t_translation::t_terrain& get_background_terrain() const { return background_terrain_; } - const brush* get_brush() const { return brush_; } + brush* get_brush() { return brush_; } mouse_action* get_mouse_action() { return mouse_action_; } protected: void set_foreground_terrain(t_translation::t_terrain t) { foreground_terrain_ = t; } diff --git a/src/editor2/mouse_action.cpp b/src/editor2/mouse_action.cpp index 9b7a4428876..8e79f7050ff 100644 --- a/src/editor2/mouse_action.cpp +++ b/src/editor2/mouse_action.cpp @@ -20,6 +20,7 @@ #include "mouse_action.hpp" #include "../foreach.hpp" +#include "../pathutils.hpp" namespace editor2 { @@ -39,6 +40,7 @@ editor_action* mouse_action::drag_end(editor_display& disp, int x, int y) void mouse_action_paint::move(editor_display& disp, int x, int y) { + SCOPE_ED; disp.clear_highlighted_locs(); if (mode_.get_brush() != NULL) { foreach (gamemap::location loc, mode_.get_brush()->project(disp.hex_clicked_on(x,y))) { @@ -58,6 +60,7 @@ editor_action* mouse_action_paint::click(editor_display& disp, int x, int y) editor_action* mouse_action_paint::drag(editor_display& disp, int x, int y) { + move(disp, x, y); gamemap::location hex = disp.hex_clicked_on(x, y); if (hex != previous_hex_) { return click(disp, x, y);