diff --git a/Minecraft.Client/Common/UI/UIController.cpp b/Minecraft.Client/Common/UI/UIController.cpp index 197d178a..2f4ba86a 100644 --- a/Minecraft.Client/Common/UI/UIController.cpp +++ b/Minecraft.Client/Common/UI/UIController.cpp @@ -986,6 +986,29 @@ void UIController::handleKeyPress(unsigned int iPad, unsigned int key) pressed = InputManager.ButtonPressed(iPad,key); // Toggle released = InputManager.ButtonReleased(iPad,key); // Toggle +#ifdef _WINDOWS64 + // Keyboard menu input for player 0 + if (iPad == 0) + { + bool kbDown = false, kbPressed = false, kbReleased = false; + switch(key) + { + case ACTION_MENU_UP: kbDown = KMInput.IsKeyDown(VK_UP); kbPressed = KMInput.IsKeyPressed(VK_UP); kbReleased = KMInput.IsKeyReleased(VK_UP); break; + case ACTION_MENU_DOWN: kbDown = KMInput.IsKeyDown(VK_DOWN); kbPressed = KMInput.IsKeyPressed(VK_DOWN); kbReleased = KMInput.IsKeyReleased(VK_DOWN); break; + case ACTION_MENU_LEFT: kbDown = KMInput.IsKeyDown(VK_LEFT); kbPressed = KMInput.IsKeyPressed(VK_LEFT); kbReleased = KMInput.IsKeyReleased(VK_LEFT); break; + case ACTION_MENU_RIGHT: kbDown = KMInput.IsKeyDown(VK_RIGHT); kbPressed = KMInput.IsKeyPressed(VK_RIGHT); kbReleased = KMInput.IsKeyReleased(VK_RIGHT); break; + case ACTION_MENU_OK: kbDown = KMInput.IsKeyDown(VK_RETURN); kbPressed = KMInput.IsKeyPressed(VK_RETURN); kbReleased = KMInput.IsKeyReleased(VK_RETURN); break; + case ACTION_MENU_A: kbDown = KMInput.IsKeyDown(VK_RETURN); kbPressed = KMInput.IsKeyPressed(VK_RETURN); kbReleased = KMInput.IsKeyReleased(VK_RETURN); break; + case ACTION_MENU_CANCEL: kbDown = KMInput.IsKeyDown(VK_ESCAPE); kbPressed = KMInput.IsKeyPressed(VK_ESCAPE); kbReleased = KMInput.IsKeyReleased(VK_ESCAPE); break; + case ACTION_MENU_B: kbDown = KMInput.IsKeyDown(VK_ESCAPE); kbPressed = KMInput.IsKeyPressed(VK_ESCAPE); kbReleased = KMInput.IsKeyReleased(VK_ESCAPE); break; + case ACTION_MENU_PAUSEMENU: kbDown = KMInput.IsKeyDown(VK_ESCAPE); kbPressed = KMInput.IsKeyPressed(VK_ESCAPE); kbReleased = KMInput.IsKeyReleased(VK_ESCAPE); break; + } + pressed = pressed || kbPressed; + released = released || kbReleased; + down = down || kbDown; + } +#endif + //if(pressed) app.DebugPrintf("Pressed %d\n",key); //if(released) app.DebugPrintf("Released %d\n",key); // Repeat handling diff --git a/Minecraft.Client/Input.cpp b/Minecraft.Client/Input.cpp index 1e3e0637..eea0519d 100644 --- a/Minecraft.Client/Input.cpp +++ b/Minecraft.Client/Input.cpp @@ -18,6 +18,7 @@ Input::Input() lReset = false; rReset = false; + m_gamepadSneaking = false; } void Input::tick(LocalPlayer *player) @@ -40,6 +41,24 @@ void Input::tick(LocalPlayer *player) else ya = 0.0f; + +#ifdef _WINDOWS64 + // WASD movement (combine with gamepad) + if (iPad == 0) + { + float kbX = 0.0f, kbY = 0.0f; + if (KMInput.IsKeyDown('W')) kbY += 1.0f; + if (KMInput.IsKeyDown('S')) kbY -= 1.0f; + if (KMInput.IsKeyDown('A')) kbX += 1.0f; // inverted like gamepad + if (KMInput.IsKeyDown('D')) kbX -= 1.0f; + // Normalize diagonal + if (kbX != 0.0f && kbY != 0.0f) { kbX *= 0.707f; kbY *= 0.707f; } + if (pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_LEFT) || pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_RIGHT)) + xa = max(min(xa + kbX, 1.0f), -1.0f); + if (pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_FORWARD) || pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_BACKWARD)) + ya = max(min(ya + kbY, 1.0f), -1.0f); + } +#endif #ifndef _CONTENT_PACKAGE if (app.GetFreezePlayers()) { @@ -62,9 +81,16 @@ void Input::tick(LocalPlayer *player) { if((player->ullButtonsPressed&(1LL<localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_SNEAK_TOGGLE)) { - sneaking=!sneaking; + m_gamepadSneaking=!m_gamepadSneaking; } } + sneaking = m_gamepadSneaking; + +#ifdef _WINDOWS64 + // Keyboard hold-to-sneak (overrides gamepad toggle) + if (iPad == 0 && KMInput.IsKeyDown(VK_SHIFT) && !player->abilities.flying) + sneaking = true; +#endif if(sneaking) { @@ -101,6 +127,19 @@ void Input::tick(LocalPlayer *player) } player->interpolateTurn(tx * abs(tx) * turnSpeed, ty * abs(ty) * turnSpeed); +#ifdef _WINDOWS64 + // Mouse look (added after stick-based turn) + if (iPad == 0 && KMInput.IsCaptured()) + { + float mouseSensitivity = 1.25f; + float mdx = KMInput.GetMouseDeltaX() * mouseSensitivity; + float mdy = -KMInput.GetMouseDeltaY() * mouseSensitivity; + if (app.GetGameSettings(iPad, eGameSetting_ControlInvertLook)) + mdy = -mdy; + player->interpolateTurn(mdx, mdy); + } +#endif + //jumping = controller.isButtonPressed(0); @@ -110,6 +149,12 @@ void Input::tick(LocalPlayer *player) else jumping = false; +#ifdef _WINDOWS64 + // Keyboard jump (Space) + if (iPad == 0 && KMInput.IsKeyDown(VK_SPACE) && pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_JUMP)) + jumping = true; +#endif + #ifndef _CONTENT_PACKAGE if (app.GetFreezePlayers()) jumping = false; #endif diff --git a/Minecraft.Client/Input.h b/Minecraft.Client/Input.h index eb3487e9..84cd76de 100644 --- a/Minecraft.Client/Input.h +++ b/Minecraft.Client/Input.h @@ -19,4 +19,5 @@ private: bool lReset; bool rReset; + bool m_gamepadSneaking; }; \ No newline at end of file diff --git a/Minecraft.Client/LocalPlayer.cpp b/Minecraft.Client/LocalPlayer.cpp index a7f1356d..90299bcd 100644 --- a/Minecraft.Client/LocalPlayer.cpp +++ b/Minecraft.Client/LocalPlayer.cpp @@ -279,6 +279,15 @@ void LocalPlayer::aiStep() // world with low food, then reload it in creative. if(abilities.mayfly || isAllowedToFly() ) enoughFoodToSprint = true; +#ifdef _WINDOWS64 + // Keyboard sprint: Ctrl held while moving forward + if (GetXboxPad() == 0 && KMInput.IsKeyDown(VK_CONTROL) && input->ya > 0.0f && + enoughFoodToSprint && !isUsingItem() && !hasEffect(MobEffect::blindness) && onGround) + { + if (!isSprinting()) setSprinting(true); + } +#endif + // 4J - altered this slightly to make sure that the joypad returns to below returnTreshold in between registering two movements up to runThreshold if (onGround && !isSprinting() && enoughFoodToSprint && !isUsingItem() && !hasEffect(MobEffect::blindness)) { diff --git a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp index 56f7a486..28476abe 100644 --- a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp +++ b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp @@ -868,6 +868,9 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, // Set the number of possible joypad layouts that the user can switch between, and the number of actions InputManager.Initialise(1,3,MINECRAFT_ACTION_MAX, ACTION_MAX_MENU); + //univ - thank you smartcmd :3 + g_KBMInput.Init(); + // Set the default joypad action mappings for Minecraft DefineActions(); InputManager.SetJoypadMapVal(0,0); @@ -928,6 +931,8 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, MSG msg = {0}; while( WM_QUIT != msg.message ) { + g_KBMInput.Tick(); + if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) { TranslateMessage( &msg ); @@ -959,8 +964,17 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, g_KBMInput.SetKBMActive(true); //if (ui.FindScene(eUIScene_BookMenu) != nullptr) ui.FindScene(eUIScene_BookMenu)->KBMUpdate(true); } + } else + g_KBMInput.SetKBMActive(true); + + if (!g_KBMInput.IsMouseGrabbed()) + { + if (!g_KBMInput.IsKBMActive()) + g_KBMInput.SetCursorHiddenForUI(true); + else if (!g_KBMInput.IsScreenCursorHidden()) + g_KBMInput.SetCursorHiddenForUI(false); } - + PIXEndNamedEvent(); /*PIXBeginNamedEvent(0,"Profile manager tick"); ProfileManager.Tick(); @@ -980,6 +994,7 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, // Render game graphics. if(app.GetGameStarted()) { + pMinecraft->applyFrameMouseLook(); pMinecraft->run_middle(); app.SetAppPaused( g_NetworkManager.IsLocalGame() && g_NetworkManager.GetPlayerCount() == 1 && ui.IsPauseMenuDisplayed(ProfileManager.GetPrimaryPad()) ); } @@ -1009,6 +1024,35 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, ui.CheckMenuDisplayed(); + // Update mouse grab: grab when in-game and no menu is open + { + static bool altToggleSuppressCapture = false; + const bool shouldCapture = app.GetGameStarted() && !ui.GetMenuDisplayed(0) && pMinecraft->screen == nullptr; + // Left Alt key toggles capture on/off for debugging + if (g_KBMInput.IsKeyPressed(VK_LMENU) || g_KBMInput.IsKeyPressed(VK_RMENU)) + { + if (g_KBMInput.IsMouseGrabbed()) { g_KBMInput.SetMouseGrabbed(false); altToggleSuppressCapture = true; } + else if (shouldCapture) { g_KBMInput.SetMouseGrabbed(true); altToggleSuppressCapture = false; } + } + else if (!shouldCapture) + { + if (g_KBMInput.IsMouseGrabbed()) g_KBMInput.SetMouseGrabbed(false); + altToggleSuppressCapture = false; + } + else if (shouldCapture && !g_KBMInput.IsMouseGrabbed() && GetFocus() == g_hWnd && !altToggleSuppressCapture) + { + g_KBMInput.SetMouseGrabbed(true); + } + } + + // Open chat + if (g_KBMInput.IsKeyPressed(KeyboardMouseInput::KEY_CHAT) && app.GetGameStarted() && !ui.GetMenuDisplayed(0) && pMinecraft->screen == NULL) + { + g_KBMInput.ClearCharBuffer(); + pMinecraft->setScreen(new ChatScreen()); + SetFocus(g_hWnd); + } + // Any threading type things to deal with from the xui side? app.HandleXuiActions();