Allow multiple brushes, loaded from WML...
...(currently they are only displayed, not used in painting, use alt+b to switch brushes)
This commit is contained in:
parent
0b2292941d
commit
f962ad3664
7 changed files with 94 additions and 20 deletions
|
@ -21,6 +21,7 @@
|
|||
{core/units.cfg}
|
||||
#ifdef EDITOR2
|
||||
{core/editor-groups.cfg}
|
||||
{core/editor2-brushes.cfg}
|
||||
{core/editor2-hotkeys.cfg}
|
||||
#endif
|
||||
#endif
|
||||
|
|
57
data/core/editor2-brushes.cfg
Normal file
57
data/core/editor2-brushes.cfg
Normal file
|
@ -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]
|
||||
|
|
@ -55,7 +55,7 @@ std::set<gamemap::location> brush::project(const gamemap::location& hotspot) con
|
|||
{
|
||||
std::set<gamemap::location> result;
|
||||
foreach (const gamemap::location& relative, relative_tiles_) {
|
||||
result.insert(hotspot + relative);
|
||||
result.insert(relative + hotspot);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -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<std::string, mouse_action*> 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)
|
||||
|
|
|
@ -140,7 +140,7 @@ class editor_controller : public controller_base,
|
|||
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
|
||||
|
|
|
@ -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; }
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue