Commit bf67ecf6 authored by louiz’'s avatar louiz’

Only select one entity on left click without doing a rectangular selection

parent d6d87dcd
...@@ -157,7 +157,7 @@ void Camera::handle_right_click(const sf::Event& event) ...@@ -157,7 +157,7 @@ void Camera::handle_right_click(const sf::Event& event)
if (ids.empty()) if (ids.empty())
return ; return ;
const Entity* entity_under_mouse = this->get_entity_under_mouse(); const Entity* entity_under_mouse = this->get_entity_under_mouse();
if (entity_under_mouse) if (entity_under_mouse && std::find(ids.begin(), ids.end(), entity_under_mouse->get_id()) == ids.end())
this->game->action_follow(ids, entity_under_mouse->get_id(), queue); this->game->action_follow(ids, entity_under_mouse->get_id(), queue);
else else
this->game->action_move(ids, pos, queue); this->game->action_move(ids, pos, queue);
...@@ -200,7 +200,9 @@ void Camera::set_mouse_selection_to_selection() ...@@ -200,7 +200,9 @@ void Camera::set_mouse_selection_to_selection()
// Only the manipulable entities are considered // Only the manipulable entities are considered
std::vector<const Entity*> entities_in_mouse_selection; std::vector<const Entity*> entities_in_mouse_selection;
for (const auto& entity: this->world().entities) const auto sorted_entities = this->world().sorted_entities();
for (const auto& entity: sorted_entities)
{ {
Location* location = entity->get<Location>(); Location* location = entity->get<Location>();
Team* team = entity->get<Team>(); Team* team = entity->get<Team>();
...@@ -208,7 +210,13 @@ void Camera::set_mouse_selection_to_selection() ...@@ -208,7 +210,13 @@ void Camera::set_mouse_selection_to_selection()
continue; continue;
if (this->mouse_selection.contains(mouse_pos, if (this->mouse_selection.contains(mouse_pos,
this->world_to_camera_position(location->position()))) this->world_to_camera_position(location->position())))
entities_in_mouse_selection.push_back(entity.get()); {
entities_in_mouse_selection.push_back(entity);
if (!this->mouse_selection.is_rectangular_selection_ongoing(mouse_pos))
// Only select one entity, because we are not doing a
// rectangular selection.
break;
}
} }
if (entities_in_mouse_selection.empty()) if (entities_in_mouse_selection.empty())
......
#include <gui/camera/mouse_selection.hpp> #include <gui/camera/mouse_selection.hpp>
#include <utils/math.hpp>
MouseSelection::MouseSelection(): MouseSelection::MouseSelection():
ongoing(false) ongoing(false)
...@@ -19,7 +21,7 @@ void MouseSelection::end() ...@@ -19,7 +21,7 @@ void MouseSelection::end()
bool MouseSelection::is_rectangular_selection_ongoing(const sf::Vector2i& mouse_pos) const bool MouseSelection::is_rectangular_selection_ongoing(const sf::Vector2i& mouse_pos) const
{ {
return this->ongoing && this->start_pos != mouse_pos; return this->ongoing && (vect_distance(this->start_pos, mouse_pos) > 5);
} }
bool MouseSelection::contains(const sf::Vector2i& mouse_pos, bool MouseSelection::contains(const sf::Vector2i& mouse_pos,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment