Number of mouse inputs is now tracked, and mouse mode is changed more reliably.

This commit is contained in:
2026-09-03 11:24:38 -04:00
parent 1e43a2433c
commit c91a539a26
2 changed files with 9 additions and 6 deletions
+7 -6
View File
@@ -146,7 +146,6 @@ void InputHandler::add_input_resource(Node *target, InputResource *resource)
if (axis->get_include_mouse()) if (axis->get_include_mouse())
{ {
Engine *engine = Engine::get_singleton();
this->call_deferred("_enable_mouse_capture"); this->call_deferred("_enable_mouse_capture");
const StringName callback_name = StringName("_on_") + axis->get_axis_name() + INPUTAXIS_MOUSE_INPUT_SUFFIX; const StringName callback_name = StringName("_on_") + axis->get_axis_name() + INPUTAXIS_MOUSE_INPUT_SUFFIX;
@@ -176,8 +175,8 @@ void InputHandler::add_input_resource(Node *target, InputResource *resource)
} }
void InputHandler::_enable_mouse_capture() void InputHandler::_enable_mouse_capture()
{ {
Input *input = Input::get_singleton(); this->mouse_input_counter++;
input->set_mouse_mode(Input::MOUSE_MODE_CAPTURED); Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_CAPTURED);
} }
void InputHandler::remove_input_resource(Node *target, InputResource *resource) void InputHandler::remove_input_resource(Node *target, InputResource *resource)
@@ -305,7 +304,6 @@ void InputHandler::remove_input_resource(Node *target, InputResource *resource)
if (axis->get_include_mouse()) if (axis->get_include_mouse())
{ {
Engine *engine = Engine::get_singleton();
this->call_deferred("_disable_mouse_capture"); this->call_deferred("_disable_mouse_capture");
} }
} }
@@ -315,6 +313,9 @@ void InputHandler::remove_input_resource(Node *target, InputResource *resource)
} }
void InputHandler::_disable_mouse_capture() void InputHandler::_disable_mouse_capture()
{ {
Input *input = Input::get_singleton(); mouse_input_counter--;
input->set_mouse_mode(Input::MOUSE_MODE_VISIBLE); if (mouse_input_counter <= 0)
{
Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE);
}
} }
+2
View File
@@ -39,6 +39,8 @@ private:
const StringName input_axis_suffixes[3] = { INPUTAXIS_ONE_DIMENSIONAL_SUFFIX, INPUTAXIS_TWO_DIMENSIONAL_SUFFIX, INPUTAXIS_THREE_DIMENSIONAL_SUFFIX }; const StringName input_axis_suffixes[3] = { INPUTAXIS_ONE_DIMENSIONAL_SUFFIX, INPUTAXIS_TWO_DIMENSIONAL_SUFFIX, INPUTAXIS_THREE_DIMENSIONAL_SUFFIX };
std::map<const StringName, MethodBind*> bound_remove_methods; std::map<const StringName, MethodBind*> bound_remove_methods;
int8_t mouse_input_counter = 0;
// Godot boilerplate below // Godot boilerplate below
protected: protected: