diff --git a/modules/wave_survival/player_input.cpp b/modules/wave_survival/player_input.cpp index e6f279d1..647eb6aa 100644 --- a/modules/wave_survival/player_input.cpp +++ b/modules/wave_survival/player_input.cpp @@ -1,4 +1,5 @@ #include "player_input.h" +#include "scene/main/scene_tree.h" String PlayerInput::sig_movement_input{ "movement_input" }; String PlayerInput::sig_look_input{ "look_input" }; @@ -20,13 +21,33 @@ void PlayerInput::_bind_methods() { ADD_SIGNAL(MethodInfo(sig_crouch, PropertyInfo(Variant::BOOL, "is_crouching"))); } +void PlayerInput::normalize_input() { + emit_signal(sig_movement_input, Vector2()); + emit_signal(sig_look_input, Vector2()); + emit_signal(sig_primary_fire, false); + emit_signal(sig_alt_mode, false); + emit_signal(sig_run, false); + emit_signal(sig_crouch, false); +} + 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); + switch (what) { + case NOTIFICATION_READY: + set_process(true); + set_process_unhandled_input(true); + Input::get_singleton()->set_mouse_mode(Input::MouseMode::MOUSE_MODE_CAPTURED); + return; + case NOTIFICATION_PROCESS: { + bool const is_paused{ get_tree()->is_paused() }; + if (is_paused != this->was_paused) { + this->was_paused = is_paused; + callable_mp(this, &self_type::normalize_input).call_deferred(); + } + return; + } } } diff --git a/modules/wave_survival/player_input.h b/modules/wave_survival/player_input.h index 240db670..7ebe65c7 100644 --- a/modules/wave_survival/player_input.h +++ b/modules/wave_survival/player_input.h @@ -6,6 +6,7 @@ class PlayerInput : public Node { GDCLASS(PlayerInput, Node); static void _bind_methods(); + void normalize_input(); void _notification(int what); virtual void unhandled_input(Ref const &event) override; @@ -18,6 +19,9 @@ public: static String sig_run; static String sig_jump; static String sig_crouch; + +private: + bool was_paused{ false }; }; #endif // !PLAYER_INPUT_H