From 70443ddff5012012bc40dfd8d0d79d2d65da56bd Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Sun, 22 Oct 2023 17:38:48 -0700 Subject: [PATCH] Make Input Overlay position persistent when is selected --- Runtime/ConsoleVariables/CVarCommons.cpp | 4 ++++ Runtime/ConsoleVariables/CVarCommons.hpp | 1 + Runtime/ImGuiConsole.cpp | 12 ++++++++++++ Runtime/ImGuiConsole.hpp | 2 ++ 4 files changed, 19 insertions(+) diff --git a/Runtime/ConsoleVariables/CVarCommons.cpp b/Runtime/ConsoleVariables/CVarCommons.cpp index e8cd8ce6b..516cd9baa 100644 --- a/Runtime/ConsoleVariables/CVarCommons.cpp +++ b/Runtime/ConsoleVariables/CVarCommons.cpp @@ -59,6 +59,10 @@ CVarCommons::CVarCommons(CVarManager& manager) : m_mgr(manager) { m_debugInputOverlayCorner = m_mgr.findOrMakeCVar("debugOverlay.inputOverlayCorner"sv, "ImGui input overlay corner"sv, 3 /* bottom-right */, CVar::EFlags::System | CVar::EFlags::Archive | CVar::EFlags::Hidden); + m_debugInputOverlayPos = + m_mgr.findOrMakeCVar("debugOverlay.inputOverlayPosition"sv, "ImGui custom input overlay position"sv, zeus::CVector2f{0.f, 0.f} /* uninitialized */, + CVar::EFlags::System | CVar::EFlags::Archive | CVar::EFlags::Hidden); + m_debugToolDrawAiPath = m_mgr.findOrMakeCVar("debugTool.drawAiPath", "Draws the selected paths of any AI in the room"sv, false, CVar::EFlags::Game | CVar::EFlags::Archive | CVar::EFlags::ReadOnly); diff --git a/Runtime/ConsoleVariables/CVarCommons.hpp b/Runtime/ConsoleVariables/CVarCommons.hpp index ae845605e..a8f723d32 100644 --- a/Runtime/ConsoleVariables/CVarCommons.hpp +++ b/Runtime/ConsoleVariables/CVarCommons.hpp @@ -41,6 +41,7 @@ struct CVarCommons { CVar* m_debugOverlayShowInput = nullptr; CVar* m_debugOverlayCorner = nullptr; CVar* m_debugInputOverlayCorner = nullptr; + CVar* m_debugInputOverlayPos = nullptr; CVar* m_debugToolDrawAiPath = nullptr; CVar* m_debugToolDrawLighting = nullptr; CVar* m_debugToolDrawCollisionActors = nullptr; diff --git a/Runtime/ImGuiConsole.cpp b/Runtime/ImGuiConsole.cpp index 560b02b3d..2dfd7a161 100644 --- a/Runtime/ImGuiConsole.cpp +++ b/Runtime/ImGuiConsole.cpp @@ -1046,8 +1046,20 @@ void ImGuiConsole::ShowInputViewer() { SetOverlayWindowLocation(m_inputOverlayCorner); windowFlags |= ImGuiWindowFlags_NoMove; } + + if (m_initialInputOverlayDraw && m_inputOverlayCorner == -1) { + ImGui::SetNextWindowPos(m_inputOverlayPos); + m_initialInputOverlayDraw = false; + } + ImGui::SetNextWindowBgAlpha(0.65f); if (ImGui::Begin("Input Overlay", nullptr, windowFlags)) { + /* If the position has changed and we're not in a corner, grab it and store it */ + if (m_inputOverlayCorner == -1 && (ImGui::GetWindowPos().x != m_inputOverlayPos.x() || ImGui::GetWindowPos().y != m_inputOverlayPos.y())) { + m_inputOverlayPos = ImGui::GetWindowPos(); + m_cvarCommons.m_debugInputOverlayPos->fromVec2f(m_inputOverlayPos); + } + float scale = GetScale(); if (!m_controllerName.empty()) { TextCenter(m_controllerName); diff --git a/Runtime/ImGuiConsole.hpp b/Runtime/ImGuiConsole.hpp index a8953ac6f..3ffa890b6 100644 --- a/Runtime/ImGuiConsole.hpp +++ b/Runtime/ImGuiConsole.hpp @@ -132,6 +132,8 @@ private: int m_debugOverlayCorner = m_cvarCommons.m_debugOverlayCorner->toSigned(); int m_inputOverlayCorner = m_cvarCommons.m_debugInputOverlayCorner->toSigned(); + zeus::CVector2f m_inputOverlayPos = m_cvarCommons.m_debugInputOverlayPos->toVec2f(); + bool m_initialInputOverlayDraw = true; const void* m_currentRoom = nullptr; double m_lastRoomTime = 0.f; double m_currentRoomStart = 0.f;