godot-cpp-utils/player_input.hpp

44 lines
1.2 KiB
C++

#ifndef PLAYER_INPUT_HPP
#define PLAYER_INPUT_HPP
#include <vector>
#include "godot_cpp/classes/input.hpp"
#include "godot_cpp/classes/input_event.hpp"
#include "godot_cpp/classes/node.hpp"
namespace godot {
class PlayerInput : public Node {
GDCLASS(PlayerInput, Node)
static void _bind_methods();
public:
struct Listener {
friend class PlayerInput;
private:
String actionNegative{""};
String actionPositive{""};
float lastCached{0.f};
String methodName{""};
Node *object{nullptr};
bool isMouseEvent{false};
public:
Listener(String positive, String negative, Node *object, String method);
static float evaluate_event(Ref<InputEvent> const &event, String const &action);
bool has_changed(Ref<InputEvent> const &event);
float evaluate(Ref<InputEvent> const &event);
bool operator==(godot::PlayerInput::Listener const& b);
};
private:
std::vector<Listener> listeners{};
public:
virtual void _unhandled_input(Ref<InputEvent> const &event) override;
void listen_to(Listener const& listener);
void stop_listening(Node *node);
void stop_listening(Listener const& listener);
};
}
#endif // !PLAYER_INPUT_HPP