Author: ilor
Date: Mon Jul 14 19:42:08 2008
New Revision: 28029
URL: http://svn.gna.org/viewcvs/wesnoth?rev=28029&view=rev
Log:
Allow multiple brushes, loaded from WML (currently they are only displayed, not
used in painting, use alt+b to switch brushes)
Added:
trunk/data/core/editor2-brushes.cfg
Modified:
trunk/data/core/_main.cfg
trunk/src/editor2/brush.cpp
trunk/src/editor2/editor_controller.cpp
trunk/src/editor2/editor_controller.hpp
trunk/src/editor2/editor_mode.hpp
trunk/src/editor2/mouse_action.cpp
Modified: trunk/data/core/_main.cfg
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/data/core/_main.cfg?rev=28029&r1=28028&r2=28029&view=diff
==============================================================================
--- trunk/data/core/_main.cfg (original)
+++ trunk/data/core/_main.cfg Mon Jul 14 19:42:08 2008
@@ -21,6 +21,7 @@
{core/units.cfg}
#ifdef EDITOR2
{core/editor-groups.cfg}
+{core/editor2-brushes.cfg}
{core/editor2-hotkeys.cfg}
#endif
#endif
Added: trunk/data/core/editor2-brushes.cfg
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/data/core/editor2-brushes.cfg?rev=28029&view=auto
==============================================================================
--- trunk/data/core/editor2-brushes.cfg (added)
+++ trunk/data/core/editor2-brushes.cfg Mon Jul 14 19:42:08 2008
@@ -1,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]
+
Modified: trunk/src/editor2/brush.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/brush.cpp?rev=28029&r1=28028&r2=28029&view=diff
==============================================================================
--- trunk/src/editor2/brush.cpp (original)
+++ trunk/src/editor2/brush.cpp Mon Jul 14 19:42:08 2008
@@ -55,7 +55,7 @@
{
std::set<gamemap::location> result;
foreach (const gamemap::location& relative, relative_tiles_) {
- result.insert(hotspot + relative);
+ result.insert(relative + hotspot);
}
return result;
}
Modified: trunk/src/editor2/editor_controller.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_controller.cpp?rev=28029&r1=28028&r2=28029&view=diff
==============================================================================
--- trunk/src/editor2/editor_controller.cpp (original)
+++ trunk/src/editor2/editor_controller.cpp Mon Jul 14 19:42:08 2008
@@ -42,15 +42,19 @@
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 @@
delete gui_;
clear_stack(undo_stack_);
clear_stack(redo_stack_);
- foreach (mouse_action* a, mouse_actions_) {
- delete a;
+ typedef std::pair<std::string, mouse_action*> apr;
+ foreach (apr a, mouse_actions_) {
+ delete a.second;
}
}
@@ -104,6 +109,8 @@
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::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 @@
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)
Modified: trunk/src/editor2/editor_controller.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_controller.hpp?rev=28029&r1=28028&r2=28029&view=diff
==============================================================================
--- trunk/src/editor2/editor_controller.hpp (original)
+++ trunk/src/editor2/editor_controller.hpp Mon Jul 14 19:42:08 2008
@@ -140,7 +140,7 @@
static const int max_action_stack_size_;
std::vector<brush> brushes_;
- std::vector<mouse_action*> mouse_actions_;
+ std::map<std::string, mouse_action*> mouse_actions_;
};
} //end namespace editor2
Modified: trunk/src/editor2/editor_mode.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_mode.hpp?rev=28029&r1=28028&r2=28029&view=diff
==============================================================================
--- trunk/src/editor2/editor_mode.hpp (original)
+++ trunk/src/editor2/editor_mode.hpp Mon Jul 14 19:42:08 2008
@@ -38,7 +38,7 @@
}
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; }
Modified: trunk/src/editor2/mouse_action.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/mouse_action.cpp?rev=28029&r1=28028&r2=28029&view=diff
==============================================================================
--- trunk/src/editor2/mouse_action.cpp (original)
+++ trunk/src/editor2/mouse_action.cpp Mon Jul 14 19:42:08 2008
@@ -20,6 +20,7 @@
#include "mouse_action.hpp"
#include "../foreach.hpp"
+#include "../pathutils.hpp"
namespace editor2 {
@@ -39,6 +40,7 @@
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::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);
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits