From d0e2d0423fac600dbb8d727da318d45d446b5cad Mon Sep 17 00:00:00 2001 From: Kelsi Date: Wed, 25 Mar 2026 15:54:14 -0700 Subject: [PATCH] refactor: extract Gameplay and Controls settings tabs Extract renderSettingsGameplayTab() (162 lines) and renderSettingsControlsTab() (96 lines) from renderSettingsWindow(). 5 of 7 settings tabs are now in dedicated methods; only Video and Interface remain inline (they share resolution/display local state). --- include/ui/game_screen.hpp | 2 + src/ui/game_screen.cpp | 521 +++++++++++++++++++------------------ 2 files changed, 267 insertions(+), 256 deletions(-) diff --git a/include/ui/game_screen.hpp b/include/ui/game_screen.hpp index d759bf1f..b8550580 100644 --- a/include/ui/game_screen.hpp +++ b/include/ui/game_screen.hpp @@ -385,6 +385,8 @@ private: void renderSettingsAudioTab(); void renderSettingsChatTab(); void renderSettingsAboutTab(); + void renderSettingsGameplayTab(); + void renderSettingsControlsTab(); void applyGraphicsPreset(GraphicsPreset preset); void updateGraphicsPresetFromCurrentSettings(); void renderQuestMarkers(game::GameHandler& gameHandler); diff --git a/src/ui/game_screen.cpp b/src/ui/game_screen.cpp index 9ec0a1e3..27d18888 100644 --- a/src/ui/game_screen.cpp +++ b/src/ui/game_screen.cpp @@ -18203,6 +18203,269 @@ void GameScreen::renderPetUnlearnConfirmDialog(game::GameHandler& gameHandler) { // Settings Window // ============================================================ +void GameScreen::renderSettingsGameplayTab() { + auto* renderer = core::Application::getInstance().getRenderer(); +ImGui::Spacing(); + +ImGui::Text("Controls"); +ImGui::Separator(); +if (ImGui::SliderFloat("Mouse Sensitivity", &pendingMouseSensitivity, 0.05f, 1.0f, "%.2f")) { + if (renderer) { + if (auto* cameraController = renderer->getCameraController()) { + cameraController->setMouseSensitivity(pendingMouseSensitivity); + } + } + saveSettings(); +} +if (ImGui::Checkbox("Invert Mouse", &pendingInvertMouse)) { + if (renderer) { + if (auto* cameraController = renderer->getCameraController()) { + cameraController->setInvertMouse(pendingInvertMouse); + } + } + saveSettings(); +} +if (ImGui::Checkbox("Extended Camera Zoom", &pendingExtendedZoom)) { + if (renderer) { + if (auto* cameraController = renderer->getCameraController()) { + cameraController->setExtendedZoom(pendingExtendedZoom); + } + } + saveSettings(); +} +if (ImGui::IsItemHovered()) + ImGui::SetTooltip("Allow the camera to zoom out further than normal"); + +if (ImGui::SliderFloat("Field of View", &pendingFov, 45.0f, 110.0f, "%.0f°")) { + if (renderer) { + if (auto* camera = renderer->getCamera()) { + camera->setFov(pendingFov); + } + } + saveSettings(); +} +if (ImGui::IsItemHovered()) + ImGui::SetTooltip("Camera field of view in degrees (default: 70)"); + +ImGui::Spacing(); +ImGui::Spacing(); + +ImGui::Text("Interface"); +ImGui::Separator(); +if (ImGui::SliderInt("UI Opacity", &pendingUiOpacity, 20, 100, "%d%%")) { + uiOpacity_ = static_cast(pendingUiOpacity) / 100.0f; + saveSettings(); +} +if (ImGui::Checkbox("Rotate Minimap", &pendingMinimapRotate)) { + // Force north-up minimap. + minimapRotate_ = false; + pendingMinimapRotate = false; + if (renderer) { + if (auto* minimap = renderer->getMinimap()) { + minimap->setRotateWithCamera(false); + } + } + saveSettings(); +} +if (ImGui::Checkbox("Square Minimap", &pendingMinimapSquare)) { + minimapSquare_ = pendingMinimapSquare; + if (renderer) { + if (auto* minimap = renderer->getMinimap()) { + minimap->setSquareShape(minimapSquare_); + } + } + saveSettings(); +} +if (ImGui::Checkbox("Show Nearby NPC Dots", &pendingMinimapNpcDots)) { + minimapNpcDots_ = pendingMinimapNpcDots; + saveSettings(); +} +// Zoom controls +ImGui::Text("Minimap Zoom:"); +ImGui::SameLine(); +if (ImGui::Button(" - ")) { + if (renderer) { + if (auto* minimap = renderer->getMinimap()) { + minimap->zoomOut(); + saveSettings(); + } + } +} +ImGui::SameLine(); +if (ImGui::Button(" + ")) { + if (renderer) { + if (auto* minimap = renderer->getMinimap()) { + minimap->zoomIn(); + saveSettings(); + } + } +} + +ImGui::Spacing(); +ImGui::Text("Loot"); +ImGui::Separator(); +if (ImGui::Checkbox("Auto Loot", &pendingAutoLoot)) { + saveSettings(); // per-frame sync applies pendingAutoLoot to gameHandler +} +if (ImGui::IsItemHovered()) + ImGui::SetTooltip("Automatically pick up all items when looting"); +if (ImGui::Checkbox("Auto Sell Greys", &pendingAutoSellGrey)) { + saveSettings(); +} +if (ImGui::IsItemHovered()) + ImGui::SetTooltip("Automatically sell all grey (poor quality) items when opening a vendor"); +if (ImGui::Checkbox("Auto Repair", &pendingAutoRepair)) { + saveSettings(); +} +if (ImGui::IsItemHovered()) + ImGui::SetTooltip("Automatically repair all damaged equipment when opening an armorer vendor"); + +ImGui::Spacing(); +ImGui::Text("Bags"); +ImGui::Separator(); +if (ImGui::Checkbox("Separate Bag Windows", &pendingSeparateBags)) { + inventoryScreen.setSeparateBags(pendingSeparateBags); + saveSettings(); +} +if (ImGui::Checkbox("Show Key Ring", &pendingShowKeyring)) { + inventoryScreen.setShowKeyring(pendingShowKeyring); + saveSettings(); +} + +ImGui::Spacing(); +ImGui::Separator(); +ImGui::Spacing(); + +if (ImGui::Button("Restore Gameplay Defaults", ImVec2(-1, 0))) { + pendingMouseSensitivity = 0.2f; + pendingInvertMouse = false; + pendingExtendedZoom = false; + pendingUiOpacity = 65; + pendingMinimapRotate = false; + pendingMinimapSquare = false; + pendingMinimapNpcDots = false; + pendingSeparateBags = true; + inventoryScreen.setSeparateBags(true); + pendingShowKeyring = true; + inventoryScreen.setShowKeyring(true); + uiOpacity_ = 0.65f; + minimapRotate_ = false; + minimapSquare_ = false; + minimapNpcDots_ = false; + if (renderer) { + if (auto* cameraController = renderer->getCameraController()) { + cameraController->setMouseSensitivity(pendingMouseSensitivity); + cameraController->setInvertMouse(pendingInvertMouse); + cameraController->setExtendedZoom(pendingExtendedZoom); + } + if (auto* minimap = renderer->getMinimap()) { + minimap->setRotateWithCamera(minimapRotate_); + minimap->setSquareShape(minimapSquare_); + } + } + saveSettings(); +} + +} + +void GameScreen::renderSettingsControlsTab() { +ImGui::Spacing(); + +ImGui::Text("Keybindings"); +ImGui::Separator(); + +auto& km = ui::KeybindingManager::getInstance(); +int numActions = km.getActionCount(); + +for (int i = 0; i < numActions; ++i) { + auto action = static_cast(i); + const char* actionName = km.getActionName(action); + ImGuiKey currentKey = km.getKeyForAction(action); + + // Display current binding + ImGui::Text("%s:", actionName); + ImGui::SameLine(200); + + // Get human-readable key name (basic implementation) + const char* keyName = "Unknown"; + if (currentKey >= ImGuiKey_A && currentKey <= ImGuiKey_Z) { + static char keyBuf[16]; + snprintf(keyBuf, sizeof(keyBuf), "%c", 'A' + (currentKey - ImGuiKey_A)); + keyName = keyBuf; + } else if (currentKey >= ImGuiKey_0 && currentKey <= ImGuiKey_9) { + static char keyBuf[16]; + snprintf(keyBuf, sizeof(keyBuf), "%c", '0' + (currentKey - ImGuiKey_0)); + keyName = keyBuf; + } else if (currentKey == ImGuiKey_Escape) { + keyName = "Escape"; + } else if (currentKey == ImGuiKey_Enter) { + keyName = "Enter"; + } else if (currentKey == ImGuiKey_Tab) { + keyName = "Tab"; + } else if (currentKey == ImGuiKey_Space) { + keyName = "Space"; + } else if (currentKey >= ImGuiKey_F1 && currentKey <= ImGuiKey_F12) { + static char keyBuf[16]; + snprintf(keyBuf, sizeof(keyBuf), "F%d", 1 + (currentKey - ImGuiKey_F1)); + keyName = keyBuf; + } + + ImGui::Text("[%s]", keyName); + + // Rebind button + ImGui::SameLine(350); + if (ImGui::Button(awaitingKeyPress && pendingRebindAction == i ? "Waiting..." : "Rebind", ImVec2(100, 0))) { + pendingRebindAction = i; + awaitingKeyPress = true; + } +} + +// Handle key press during rebinding +if (awaitingKeyPress && pendingRebindAction >= 0) { + ImGui::Spacing(); + ImGui::Separator(); + ImGui::Text("Press any key to bind to this action (Esc to cancel)..."); + + // Check for any key press + bool foundKey = false; + ImGuiKey newKey = ImGuiKey_None; + for (int k = ImGuiKey_NamedKey_BEGIN; k < ImGuiKey_NamedKey_END; ++k) { + if (ImGui::IsKeyPressed(static_cast(k), false)) { + if (k == ImGuiKey_Escape) { + // Cancel rebinding + awaitingKeyPress = false; + pendingRebindAction = -1; + foundKey = true; + break; + } + newKey = static_cast(k); + foundKey = true; + break; + } + } + + if (foundKey && newKey != ImGuiKey_None) { + auto action = static_cast(pendingRebindAction); + km.setKeyForAction(action, newKey); + awaitingKeyPress = false; + pendingRebindAction = -1; + saveSettings(); + } +} + +ImGui::Spacing(); +ImGui::Separator(); +ImGui::Spacing(); + +if (ImGui::Button("Reset to Defaults", ImVec2(-1, 0))) { + km.resetToDefaults(); + awaitingKeyPress = false; + pendingRebindAction = -1; + saveSettings(); +} + +} + void GameScreen::renderSettingsAudioTab() { auto* renderer = core::Application::getInstance().getRenderer(); ImGui::Spacing(); @@ -18934,167 +19197,7 @@ void GameScreen::renderSettingsWindow() { // GAMEPLAY TAB // ============================================================ if (ImGui::BeginTabItem("Gameplay")) { - ImGui::Spacing(); - - ImGui::Text("Controls"); - ImGui::Separator(); - if (ImGui::SliderFloat("Mouse Sensitivity", &pendingMouseSensitivity, 0.05f, 1.0f, "%.2f")) { - if (renderer) { - if (auto* cameraController = renderer->getCameraController()) { - cameraController->setMouseSensitivity(pendingMouseSensitivity); - } - } - saveSettings(); - } - if (ImGui::Checkbox("Invert Mouse", &pendingInvertMouse)) { - if (renderer) { - if (auto* cameraController = renderer->getCameraController()) { - cameraController->setInvertMouse(pendingInvertMouse); - } - } - saveSettings(); - } - if (ImGui::Checkbox("Extended Camera Zoom", &pendingExtendedZoom)) { - if (renderer) { - if (auto* cameraController = renderer->getCameraController()) { - cameraController->setExtendedZoom(pendingExtendedZoom); - } - } - saveSettings(); - } - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Allow the camera to zoom out further than normal"); - - if (ImGui::SliderFloat("Field of View", &pendingFov, 45.0f, 110.0f, "%.0f°")) { - if (renderer) { - if (auto* camera = renderer->getCamera()) { - camera->setFov(pendingFov); - } - } - saveSettings(); - } - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Camera field of view in degrees (default: 70)"); - - ImGui::Spacing(); - ImGui::Spacing(); - - ImGui::Text("Interface"); - ImGui::Separator(); - if (ImGui::SliderInt("UI Opacity", &pendingUiOpacity, 20, 100, "%d%%")) { - uiOpacity_ = static_cast(pendingUiOpacity) / 100.0f; - saveSettings(); - } - if (ImGui::Checkbox("Rotate Minimap", &pendingMinimapRotate)) { - // Force north-up minimap. - minimapRotate_ = false; - pendingMinimapRotate = false; - if (renderer) { - if (auto* minimap = renderer->getMinimap()) { - minimap->setRotateWithCamera(false); - } - } - saveSettings(); - } - if (ImGui::Checkbox("Square Minimap", &pendingMinimapSquare)) { - minimapSquare_ = pendingMinimapSquare; - if (renderer) { - if (auto* minimap = renderer->getMinimap()) { - minimap->setSquareShape(minimapSquare_); - } - } - saveSettings(); - } - if (ImGui::Checkbox("Show Nearby NPC Dots", &pendingMinimapNpcDots)) { - minimapNpcDots_ = pendingMinimapNpcDots; - saveSettings(); - } - // Zoom controls - ImGui::Text("Minimap Zoom:"); - ImGui::SameLine(); - if (ImGui::Button(" - ")) { - if (renderer) { - if (auto* minimap = renderer->getMinimap()) { - minimap->zoomOut(); - saveSettings(); - } - } - } - ImGui::SameLine(); - if (ImGui::Button(" + ")) { - if (renderer) { - if (auto* minimap = renderer->getMinimap()) { - minimap->zoomIn(); - saveSettings(); - } - } - } - - ImGui::Spacing(); - ImGui::Text("Loot"); - ImGui::Separator(); - if (ImGui::Checkbox("Auto Loot", &pendingAutoLoot)) { - saveSettings(); // per-frame sync applies pendingAutoLoot to gameHandler - } - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Automatically pick up all items when looting"); - if (ImGui::Checkbox("Auto Sell Greys", &pendingAutoSellGrey)) { - saveSettings(); - } - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Automatically sell all grey (poor quality) items when opening a vendor"); - if (ImGui::Checkbox("Auto Repair", &pendingAutoRepair)) { - saveSettings(); - } - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Automatically repair all damaged equipment when opening an armorer vendor"); - - ImGui::Spacing(); - ImGui::Text("Bags"); - ImGui::Separator(); - if (ImGui::Checkbox("Separate Bag Windows", &pendingSeparateBags)) { - inventoryScreen.setSeparateBags(pendingSeparateBags); - saveSettings(); - } - if (ImGui::Checkbox("Show Key Ring", &pendingShowKeyring)) { - inventoryScreen.setShowKeyring(pendingShowKeyring); - saveSettings(); - } - - ImGui::Spacing(); - ImGui::Separator(); - ImGui::Spacing(); - - if (ImGui::Button("Restore Gameplay Defaults", ImVec2(-1, 0))) { - pendingMouseSensitivity = kDefaultMouseSensitivity; - pendingInvertMouse = kDefaultInvertMouse; - pendingExtendedZoom = false; - pendingUiOpacity = 65; - pendingMinimapRotate = false; - pendingMinimapSquare = false; - pendingMinimapNpcDots = false; - pendingSeparateBags = true; - inventoryScreen.setSeparateBags(true); - pendingShowKeyring = true; - inventoryScreen.setShowKeyring(true); - uiOpacity_ = 0.65f; - minimapRotate_ = false; - minimapSquare_ = false; - minimapNpcDots_ = false; - if (renderer) { - if (auto* cameraController = renderer->getCameraController()) { - cameraController->setMouseSensitivity(pendingMouseSensitivity); - cameraController->setInvertMouse(pendingInvertMouse); - cameraController->setExtendedZoom(pendingExtendedZoom); - } - if (auto* minimap = renderer->getMinimap()) { - minimap->setRotateWithCamera(minimapRotate_); - minimap->setSquareShape(minimapSquare_); - } - } - saveSettings(); - } - + renderSettingsGameplayTab(); ImGui::EndTabItem(); } @@ -19102,101 +19205,7 @@ void GameScreen::renderSettingsWindow() { // CONTROLS TAB // ============================================================ if (ImGui::BeginTabItem("Controls")) { - ImGui::Spacing(); - - ImGui::Text("Keybindings"); - ImGui::Separator(); - - auto& km = ui::KeybindingManager::getInstance(); - int numActions = km.getActionCount(); - - for (int i = 0; i < numActions; ++i) { - auto action = static_cast(i); - const char* actionName = km.getActionName(action); - ImGuiKey currentKey = km.getKeyForAction(action); - - // Display current binding - ImGui::Text("%s:", actionName); - ImGui::SameLine(200); - - // Get human-readable key name (basic implementation) - const char* keyName = "Unknown"; - if (currentKey >= ImGuiKey_A && currentKey <= ImGuiKey_Z) { - static char keyBuf[16]; - snprintf(keyBuf, sizeof(keyBuf), "%c", 'A' + (currentKey - ImGuiKey_A)); - keyName = keyBuf; - } else if (currentKey >= ImGuiKey_0 && currentKey <= ImGuiKey_9) { - static char keyBuf[16]; - snprintf(keyBuf, sizeof(keyBuf), "%c", '0' + (currentKey - ImGuiKey_0)); - keyName = keyBuf; - } else if (currentKey == ImGuiKey_Escape) { - keyName = "Escape"; - } else if (currentKey == ImGuiKey_Enter) { - keyName = "Enter"; - } else if (currentKey == ImGuiKey_Tab) { - keyName = "Tab"; - } else if (currentKey == ImGuiKey_Space) { - keyName = "Space"; - } else if (currentKey >= ImGuiKey_F1 && currentKey <= ImGuiKey_F12) { - static char keyBuf[16]; - snprintf(keyBuf, sizeof(keyBuf), "F%d", 1 + (currentKey - ImGuiKey_F1)); - keyName = keyBuf; - } - - ImGui::Text("[%s]", keyName); - - // Rebind button - ImGui::SameLine(350); - if (ImGui::Button(awaitingKeyPress && pendingRebindAction == i ? "Waiting..." : "Rebind", ImVec2(100, 0))) { - pendingRebindAction = i; - awaitingKeyPress = true; - } - } - - // Handle key press during rebinding - if (awaitingKeyPress && pendingRebindAction >= 0) { - ImGui::Spacing(); - ImGui::Separator(); - ImGui::Text("Press any key to bind to this action (Esc to cancel)..."); - - // Check for any key press - bool foundKey = false; - ImGuiKey newKey = ImGuiKey_None; - for (int k = ImGuiKey_NamedKey_BEGIN; k < ImGuiKey_NamedKey_END; ++k) { - if (ImGui::IsKeyPressed(static_cast(k), false)) { - if (k == ImGuiKey_Escape) { - // Cancel rebinding - awaitingKeyPress = false; - pendingRebindAction = -1; - foundKey = true; - break; - } - newKey = static_cast(k); - foundKey = true; - break; - } - } - - if (foundKey && newKey != ImGuiKey_None) { - auto action = static_cast(pendingRebindAction); - km.setKeyForAction(action, newKey); - awaitingKeyPress = false; - pendingRebindAction = -1; - saveSettings(); - } - } - - ImGui::Spacing(); - ImGui::Separator(); - ImGui::Spacing(); - - if (ImGui::Button("Reset to Defaults", ImVec2(-1, 0))) { - km.resetToDefaults(); - awaitingKeyPress = false; - pendingRebindAction = -1; - saveSettings(); - } - + renderSettingsControlsTab(); ImGui::EndTabItem(); }