From e51aaa626f8d4535ccce9c1972eb575d5e18ed24 Mon Sep 17 00:00:00 2001 From: fendrin Date: Tue, 7 May 2013 16:05:19 +0200 Subject: [PATCH] Basic support for area selecting. --- src/editor/editor_controller.cpp | 4 ++-- src/editor/map/editor_map.cpp | 10 ++++++++++ src/editor/map/editor_map.hpp | 6 ++++++ src/editor/map/map_context.cpp | 5 +++++ src/editor/map/map_context.hpp | 6 ++++++ src/tod_manager.cpp | 5 +++++ src/tod_manager.hpp | 5 +++++ 7 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/editor/editor_controller.cpp b/src/editor/editor_controller.cpp index 103fc26a5cd..8e5735b65d9 100644 --- a/src/editor/editor_controller.cpp +++ b/src/editor/editor_controller.cpp @@ -486,8 +486,8 @@ bool editor_controller::execute_command(hotkey::HOTKEY_COMMAND command, int inde // toolkit_->get_palette_manager()->draw(); return true; case AREA: - //TODO - return true; + //TODO store the selection for the state setting. + return context_manager_->get_map_context().select_area(index); } return true; diff --git a/src/editor/map/editor_map.cpp b/src/editor/map/editor_map.cpp index b3036f1dd75..e7703f22414 100644 --- a/src/editor/map/editor_map.cpp +++ b/src/editor/map/editor_map.cpp @@ -167,6 +167,16 @@ bool editor_map::add_to_selection(const map_location& loc) return on_board_with_border(loc) ? selection_.insert(loc).second : false; } +bool editor_map::set_selection(const std::set& area) +{ + clear_selection(); + BOOST_FOREACH(const map_location& loc, area) { + if (!add_to_selection(loc)) + return false; + } + return true; +} + bool editor_map::remove_from_selection(const map_location& loc) { return selection_.erase(loc) != 0; diff --git a/src/editor/map/editor_map.hpp b/src/editor/map/editor_map.hpp index 52b5b1473c0..5355485a9f3 100644 --- a/src/editor/map/editor_map.hpp +++ b/src/editor/map/editor_map.hpp @@ -138,6 +138,12 @@ public: */ bool remove_from_selection(const map_location& loc); + /** + * Select the given area. + * @param area to select. + */ + bool set_selection(const std::set& area); + /** * Return the selection set. */ diff --git a/src/editor/map/map_context.cpp b/src/editor/map/map_context.cpp index 272fc6d4255..523455d4ee9 100644 --- a/src/editor/map/map_context.cpp +++ b/src/editor/map/map_context.cpp @@ -177,6 +177,11 @@ map_context::~map_context() clear_stack(redo_stack_); } +bool map_context::select_area(int index) +{ + return map_.set_selection(tod_manager_->get_area_by_index(index)); +} + void map_context::draw_terrain(const t_translation::t_terrain & terrain, const map_location& loc, bool one_layer_only) { diff --git a/src/editor/map/map_context.hpp b/src/editor/map/map_context.hpp index 0ebac4695c7..4c659f70a5a 100644 --- a/src/editor/map/map_context.hpp +++ b/src/editor/map/map_context.hpp @@ -58,6 +58,12 @@ public: */ ~map_context(); + /** + * Select the nth tod area. + * @param index of the tod area to select. + */ + bool select_area(int index); + /** * Map accesor */ diff --git a/src/tod_manager.cpp b/src/tod_manager.cpp index 5bd0b70a7c4..3d443b71825 100644 --- a/src/tod_manager.cpp +++ b/src/tod_manager.cpp @@ -208,6 +208,11 @@ std::vector tod_manager::get_area_ids() const return areas; } +const std::set& tod_manager::get_area_by_index(int index) const +{ + return areas_[index].hexes; +} + void tod_manager::add_time_area(const config& cfg) { areas_.push_back(area_time_of_day()); diff --git a/src/tod_manager.hpp b/src/tod_manager.hpp index 53c70343a14..24b5fa1be28 100644 --- a/src/tod_manager.hpp +++ b/src/tod_manager.hpp @@ -71,6 +71,11 @@ class tod_manager : public savegame::savegame_config */ std::vector get_area_ids() const; + /** + * @returns the nth area. + */ + const std::set& get_area_by_index(int index) const; + /** * Adds a new local time area from config, making it follow its own * time-of-day sequence.