Number of mouse inputs is now tracked, and mouse mode is changed more reliably.
This commit is contained in:
@@ -146,7 +146,6 @@ void InputHandler::add_input_resource(Node *target, InputResource *resource)
|
||||
|
||||
if (axis->get_include_mouse())
|
||||
{
|
||||
Engine *engine = Engine::get_singleton();
|
||||
this->call_deferred("_enable_mouse_capture");
|
||||
|
||||
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()
|
||||
{
|
||||
Input *input = Input::get_singleton();
|
||||
input->set_mouse_mode(Input::MOUSE_MODE_CAPTURED);
|
||||
this->mouse_input_counter++;
|
||||
Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_CAPTURED);
|
||||
}
|
||||
|
||||
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())
|
||||
{
|
||||
Engine *engine = Engine::get_singleton();
|
||||
this->call_deferred("_disable_mouse_capture");
|
||||
}
|
||||
}
|
||||
@@ -315,6 +313,9 @@ void InputHandler::remove_input_resource(Node *target, InputResource *resource)
|
||||
}
|
||||
void InputHandler::_disable_mouse_capture()
|
||||
{
|
||||
Input *input = Input::get_singleton();
|
||||
input->set_mouse_mode(Input::MOUSE_MODE_VISIBLE);
|
||||
mouse_input_counter--;
|
||||
if (mouse_input_counter <= 0)
|
||||
{
|
||||
Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,8 @@ private:
|
||||
|
||||
std::map<const StringName, MethodBind*> bound_remove_methods;
|
||||
|
||||
int8_t mouse_input_counter = 0;
|
||||
|
||||
// Godot boilerplate below
|
||||
protected:
|
||||
static void _bind_methods()
|
||||
|
||||
Reference in New Issue
Block a user