Author: ilor
Date: Sun Jul 13 21:01:31 2008
New Revision: 28020
URL: http://svn.gna.org/viewcvs/wesnoth?rev=28020&view=rev
Log:
editor2: WIP fill tool (use the menu to choose). Uses some quick hacks that
will be cleaned up later. Also removed code that duplicated pathutils.?pp
functionality.
Modified:
trunk/src/editor2/action.cpp
trunk/src/editor2/brush.cpp
trunk/src/editor2/editor_controller.cpp
trunk/src/editor2/editor_controller.hpp
trunk/src/editor2/editor_map.cpp
trunk/src/editor2/editor_map.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=28020&r1=28019&r2=28020&view=diff
==============================================================================
--- trunk/src/editor2/action.cpp (original)
+++ trunk/src/editor2/action.cpp Sun Jul 13 21:01:31 2008
@@ -70,11 +70,8 @@
editor_action_paint_hex* editor_action_paint_hex::perform(editor_map& map)
const
{
- SCOPE_ED;
- LOG_ED << "Old terrain is " << map.get_terrain_string(loc_) << ", new
will be " << map.get_terrain_string(t_) << "\n";
editor_action_paint_hex* undo = new editor_action_paint_hex(loc_,
map.get_terrain(loc_));
perform_without_undo(map);
- LOG_ED << "Now the terrain is " << map.get_terrain_string(loc_) << "\n";
return undo;
}
void editor_action_paint_hex::perform_without_undo(editor_map& map) const
@@ -91,13 +88,18 @@
throw editor_action_not_implemented();
}
-editor_action_fill* editor_action_fill::perform(editor_map& /*map*/) const
+editor_action_fill* editor_action_fill::perform(editor_map& map) const
{
- throw editor_action_not_implemented();
+ editor_action_fill* undo = new editor_action_fill(loc_,
map.get_terrain(loc_));
+ perform_without_undo(map);
+ return undo;
}
-void editor_action_fill::perform_without_undo(editor_map& /*map*/) const
+void editor_action_fill::perform_without_undo(editor_map& map) const
{
- throw editor_action_not_implemented();
+ std::set<gamemap::location> to_fill =
map.get_contigious_terrain_tiles(loc_);
+ foreach (gamemap::location l, to_fill) {
+ map.set_terrain(l, t_);
+ }
}
editor_action_whole_map* editor_action_resize_map::perform(editor_map&
/*map*/) const
Modified: trunk/src/editor2/brush.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/brush.cpp?rev=28020&r1=28019&r2=28020&view=diff
==============================================================================
--- trunk/src/editor2/brush.cpp (original)
+++ trunk/src/editor2/brush.cpp Sun Jul 13 21:01:31 2008
@@ -16,6 +16,7 @@
#include "editor_map.hpp"
#include "../foreach.hpp"
+#include "../pathutils.hpp"
#include <vector>
@@ -29,8 +30,8 @@
{
int radius = lexical_cast_default<int>(cfg["radius"], 0);
if (radius > 0) {
- std::vector<gamemap::location> in_radius =
- editor_map::get_tiles_in_radius(gamemap::location(0,
0), radius);
+ std::vector<gamemap::location> in_radius;
+ get_tiles_in_radius(gamemap::location(0, 0), radius, in_radius);
foreach (gamemap::location& loc, in_radius) {
add_relative_location(loc.x, loc.y);
}
Modified: trunk/src/editor2/editor_controller.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_controller.cpp?rev=28020&r1=28019&r2=28020&view=diff
==============================================================================
--- trunk/src/editor2/editor_controller.cpp (original)
+++ trunk/src/editor2/editor_controller.cpp Sun Jul 13 21:01:31 2008
@@ -37,7 +37,6 @@
hotkey::set_scope_active(hotkey::SCOPE_GENERAL);
hotkey::set_scope_active(hotkey::SCOPE_EDITOR);
init(video);
- set_mouse_action(new mouse_action_paint(*this));
cursor::set(cursor::NORMAL);
gui_->invalidate_game_status();
gui_->invalidate_all();
@@ -47,8 +46,11 @@
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);
set_brush(&brushes_[0]);
- //redraw_everything();
+ mouse_actions_.push_back(new mouse_action_paint(*this));
+ mouse_actions_.push_back(new mouse_action_fill(*this));
+ set_mouse_action(mouse_actions_[0]);
}
@@ -66,6 +68,9 @@
delete gui_;
clear_stack(undo_stack_);
clear_stack(redo_stack_);
+ foreach (mouse_action* a, mouse_actions_) {
+ delete a;
+ }
}
void editor_controller::main_loop()
@@ -78,7 +83,7 @@
bool editor_controller::can_execute_command(hotkey::HOTKEY_COMMAND command,
int /*index*/) const
{
using namespace hotkey; //reduce hotkey:: clutter
- switch(command) {
+ switch (command) {
case HOTKEY_ZOOM_IN:
case HOTKEY_ZOOM_OUT:
case HOTKEY_ZOOM_DEFAULT:
@@ -127,6 +132,21 @@
}
}
+bool editor_controller::execute_command(hotkey::HOTKEY_COMMAND command, int
index)
+{
+ using namespace hotkey;
+ switch (command) {
+ case HOTKEY_EDITOR_TOOL_PAINT:
+ set_mouse_action(mouse_actions_[0]);
+ return true;
+ case HOTKEY_EDITOR_TOOL_FILL:
+ set_mouse_action(mouse_actions_[1]);
+ return true;
+ default:
+ return controller_base::execute_command(command, index);
+ }
+}
+
void editor_controller::toggle_grid()
{
preferences::set_grid(!preferences::grid());
Modified: trunk/src/editor2/editor_controller.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_controller.hpp?rev=28020&r1=28019&r2=28020&view=diff
==============================================================================
--- trunk/src/editor2/editor_controller.hpp (original)
+++ trunk/src/editor2/editor_controller.hpp Sun Jul 13 21:01:31 2008
@@ -44,6 +44,7 @@
~editor_controller();
void main_loop();
bool can_execute_command(hotkey::HOTKEY_COMMAND, int index =
-1) const;
+ bool execute_command(hotkey::HOTKEY_COMMAND command, int index
= -1);
void preferences();
void toggle_grid();
@@ -137,6 +138,7 @@
static const int max_action_stack_size_;
std::vector<brush> brushes_;
+ std::vector<mouse_action*> mouse_actions_;
};
} //end namespace editor2
Modified: trunk/src/editor2/editor_map.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_map.cpp?rev=28020&r1=28019&r2=28020&view=diff
==============================================================================
--- trunk/src/editor2/editor_map.cpp (original)
+++ trunk/src/editor2/editor_map.cpp Sun Jul 13 21:01:31 2008
@@ -14,6 +14,11 @@
#include "editor_map.hpp"
+#include "../pathutils.hpp"
+
+#include <deque>
+
+
namespace editor2 {
editor_map::editor_map(const config& terrain_cfg, const std::string& data)
@@ -27,29 +32,28 @@
const t_translation::t_map map(width, column);
return editor_map(terrain_cfg, gamemap::default_map_header +
t_translation::write_game_map(map));
}
-
-std::vector<gamemap::location> editor_map::get_tiles_in_radius(const
gamemap::location& center, const unsigned int radius) {
- const unsigned int distance = radius - 1;
- std::vector<gamemap::location> res;
- res.push_back(center);
- for (unsigned int d = 1; d <= distance; d++) {
- gamemap::location loc = center;
- unsigned int i;
- // Get the starting point.
- for (i = 1; i <= d; i++) {
- loc = loc.get_direction(gamemap::location::NORTH, 1);
- }
- // Get all the tiles clockwise with distance d.
- const gamemap::location::DIRECTION direction[6] =
- {gamemap::location::SOUTH_EAST,
gamemap::location::SOUTH, gamemap::location::SOUTH_WEST,
- gamemap::location::NORTH_WEST,
gamemap::location::NORTH, gamemap::location::NORTH_EAST};
- for (i = 0; i < 6; i++) {
- for (unsigned int j = 1; j <= d; j++) {
- loc = loc.get_direction(direction[i], 1);
+
+std::set<gamemap::location> editor_map::get_contigious_terrain_tiles(const
gamemap::location& start) const
+{
+ t_translation::t_terrain terrain = get_terrain(start);
+ std::set<gamemap::location> result;
+ std::deque<gamemap::location> queue;
+ result.insert(start);
+ queue.push_back(start);
+ //this is basically a breadth-first search along adjacent hexes
+ do {
+ gamemap::location adj[6];
+ get_adjacent_tiles(queue.front(), adj);
+ for (int i = 0; i < 6; ++i) {
+ if (on_board_with_border(adj[i]) && get_terrain(adj[i])
== terrain
+ && result.find(adj[i]) == result.end()) {
+ result.insert(adj[i]);
+ queue.push_back(adj[i]);
}
}
- }
- return res;
+ queue.pop_front();
+ } while (!queue.empty());
+ return result;
}
bool editor_map::in_selection(const gamemap::location& loc) const
Modified: trunk/src/editor2/editor_map.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_map.hpp?rev=28020&r1=28019&r2=28020&view=diff
==============================================================================
--- trunk/src/editor2/editor_map.hpp (original)
+++ trunk/src/editor2/editor_map.hpp Sun Jul 13 21:01:31 2008
@@ -27,8 +27,14 @@
{
public:
editor_map(const config& terrain_cfg, const std::string& data);
- static std::vector<gamemap::location> get_tiles_in_radius(const
gamemap::location& center, const unsigned int radius);
static editor_map new_map(const config& terrain_cfg, size_t width,
size_t height, t_translation::t_terrain filler);
+
+ /**
+ * Get a contigious set of tiles having the same terrain as the
starting location.
+ * Useful for flood fill or magic wand selection
+ * @return a contigious set of locations that will always contain at
least the starting element
+ */
+ std::set<gamemap::location> get_contigious_terrain_tiles(const
gamemap::location& start) const;
/**
* @return true when the location is part of the selection, false
otherwise
Modified: trunk/src/editor2/mouse_action.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/mouse_action.cpp?rev=28020&r1=28019&r2=28020&view=diff
==============================================================================
--- trunk/src/editor2/mouse_action.cpp (original)
+++ trunk/src/editor2/mouse_action.cpp Sun Jul 13 21:01:31 2008
@@ -71,4 +71,24 @@
return drag(disp, x, y);
}
+void mouse_action_fill::move(editor_display& disp, int x, int y)
+{
+ disp.clear_highlighted_locs();
+ std::set<gamemap::location> affected =
+ dynamic_cast<const editor_map&>(disp.get_map()).
+ get_contigious_terrain_tiles(disp.hex_clicked_on(x, y));
+ foreach (gamemap::location loc, affected) {
+ disp.add_highlighted_loc(loc);
+ }
+}
+
+editor_action* mouse_action_fill::click(editor_display& disp, int x, int y)
+{
+ gamemap::location hex = disp.hex_clicked_on(x, y);
+ t_translation::t_terrain terrain = mode_.get_foreground_terrain();
+ editor_action_fill* a = new editor_action_fill(hex, terrain);
+ previous_hex_ = hex;
+ 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=28020&r1=28019&r2=28020&view=diff
==============================================================================
--- trunk/src/editor2/mouse_action.hpp (original)
+++ trunk/src/editor2/mouse_action.hpp Sun Jul 13 21:01:31 2008
@@ -58,6 +58,7 @@
protected:
editor_mode& mode_;
+ gamemap::location previous_hex_;
};
class mouse_action_paint : public mouse_action
@@ -71,10 +72,18 @@
editor_action* click(editor_display& disp, int x, int y);
editor_action* drag(editor_display& disp, int x, int y);
editor_action* drag_end(editor_display& disp, int x, int y);
-protected:
- gamemap::location previous_hex_;
};
+class mouse_action_fill : public mouse_action
+{
+public:
+ mouse_action_fill(editor_mode& mode)
+ : mouse_action(mode)
+ {
+ }
+ void move(editor_display& disp, int x, int y);
+ editor_action* click(editor_display& disp, int x, int y);
+};
} //end namespace editor2
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits