Added better mouse recapture.

This commit is contained in:
Andrew Lalis 2022-08-01 15:48:05 +02:00
parent 7b0a1ca0e7
commit dbb2e8a40f
2 changed files with 7 additions and 0 deletions

View File

@ -3,6 +3,7 @@ package nl.andrewl.aos2_client.control.context;
import nl.andrewl.aos2_client.Camera;
import nl.andrewl.aos2_client.control.InputContext;
import nl.andrewl.aos2_client.control.InputHandler;
import nl.andrewl.aos2_client.util.WindowUtils;
import nl.andrewl.aos_core.model.item.BlockItemStack;
import nl.andrewl.aos_core.model.item.GunItemStack;
import nl.andrewl.aos_core.model.item.ItemStack;
@ -81,6 +82,9 @@ public class NormalContext implements InputContext {
hitting = false;
interacting = false;
reloading = false;
var size = WindowUtils.getSize(inputHandler.getWindowId());
lastMouseCursorX = size.first() / 2f;
lastMouseCursorY = size.second() / 2f;
updateInputState();
}

View File

@ -94,6 +94,9 @@ public class GameRenderer {
glfwSetMouseButtonCallback(windowHandle, new PlayerInputMouseClickCallback(inputHandler));
glfwSetScrollCallback(windowHandle, new PlayerInputMouseScrollCallback(inputHandler));
glfwSetCharCallback(windowHandle, new PlayerCharacterInputCallback(inputHandler));
glfwSetWindowFocusCallback(windowHandle, (window, focused) -> {
if (!focused) inputHandler.switchToExitMenuContext();
});
if (config.captureCursor) {
glfwSetInputMode(windowHandle, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
}