Commit d425c86b authored by louiz’'s avatar louiz’

Auto-cast the ability on the key release

parent 8d21ee76
#include <gui/screen/screen.hpp>
#include <gui/camera/camera.hpp>
#include <game/game_client.hpp>
#include <functional>
#include <gui/hud/hud.hpp>
......@@ -91,6 +92,8 @@ bool Hud::handle_event(const sf::Event& event)
if (event.type == sf::Event::KeyPressed)
return this->handle_keypress(event);
else if (event.type == sf::Event::KeyReleased)
return this->handle_keyrelease(event);
return false;
......@@ -117,6 +120,20 @@ bool Hud::handle_keypress(const sf::Event& event)
return false;
bool Hud::handle_keyrelease(const sf::Event& event)
if (this->screen->get_left_click().callback)
Camera& camera = this->game->get_camera();
const auto mouse_pos = camera.get_mouse_position();
const auto pos = camera.camera_to_world_position(mouse_pos.x, mouse_pos.y);
if (this->screen->get_left_click().callback(pos) == true)
return true;
return false;
void Hud::add_info_message(std::string&& text)
......@@ -36,6 +36,7 @@ public:
void add_info_message(std::string&& text);
void activate_ability(const std::size_t nb);
bool handle_keypress(const sf::Event& event);
bool handle_keyrelease(const sf::Event& event);
Hud(const Hud&);
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