godot-cpp-utils/player_input.hpp

44 lines
1.2 KiB
C++
Raw Normal View History

2024-02-13 13:59:01 +00:00
#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:
2024-02-13 13:59:01 +00:00
String actionNegative{""};
String actionPositive{""};
float lastCached{0.f};
String methodName{""};
Node *object{nullptr};
bool isMouseEvent{false};
2024-02-13 13:59:01 +00:00
public:
2024-02-13 13:59:01 +00:00
Listener(String positive, String negative, Node *object, String method);
static float evaluate_event(Ref<InputEvent> const &event, String const &action);
2024-02-13 13:59:01 +00:00
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