#include "player_input.h" String PlayerInput::sig_movement_input{ "movement_input" }; String PlayerInput::sig_look_input{ "look_input" }; String PlayerInput::sig_primary_fire{ "primary_fire" }; String PlayerInput::sig_alt_mode{ "alt_mode" }; String PlayerInput::sig_run{ "run" }; String PlayerInput::sig_jump{ "jump" }; String PlayerInput::sig_crouch{ "crouch" }; void PlayerInput::_bind_methods() { ADD_SIGNAL(MethodInfo(sig_movement_input, PropertyInfo(Variant::VECTOR2, "axes"))); ADD_SIGNAL(MethodInfo(sig_look_input, PropertyInfo(Variant::VECTOR2, "axes"))); ADD_SIGNAL(MethodInfo(sig_primary_fire, PropertyInfo(Variant::BOOL, "is_pressed"))); ADD_SIGNAL(MethodInfo(sig_alt_mode, PropertyInfo(Variant::BOOL, "is_active"))); ADD_SIGNAL(MethodInfo(sig_run, PropertyInfo(Variant::BOOL, "is_running"))); ADD_SIGNAL(MethodInfo(sig_jump)); ADD_SIGNAL(MethodInfo(sig_crouch, PropertyInfo(Variant::BOOL, "is_crouching"))); } void PlayerInput::_notification(int what) { if (Engine::get_singleton()->is_editor_hint()) { return; } if (what == NOTIFICATION_READY) { set_process_unhandled_input(true); Input::get_singleton()->set_mouse_mode(Input::MouseMode::MOUSE_MODE_CAPTURED); } } void PlayerInput::unhandled_input(Ref const &event) { Input *input{ Input::get_singleton() }; if (event->is_action("move_left") || event->is_action("move_right") || event->is_action("move_forward") || event->is_action("move_back")) { Vector2 state{ input->get_axis("move_right", "move_left"), input->get_axis("move_back", "move_forward") }; emit_signal(sig_movement_input, state); } Ref mouse_motion{ event }; if (mouse_motion.is_valid()) { Vector2 state{ -mouse_motion->get_relative() * 0.001f }; emit_signal(sig_look_input, state); } if (event->is_action("primary_fire")) { bool state{ event->is_pressed() }; emit_signal(sig_primary_fire, state); } if (event->is_action("alt_mode")) { bool state{ event->is_pressed() }; emit_signal(sig_alt_mode, state); } if (event->is_action("run")) { bool state{ event->is_pressed() }; emit_signal(sig_run, state); } if (event->is_pressed() && event->is_action("jump") && input->is_action_just_pressed("jump")) { emit_signal(sig_jump); } }