From 303e671a6cfa84d9081425d73c1e1fca0ef7e746 Mon Sep 17 00:00:00 2001 From: Luke Street Date: Fri, 28 May 2021 11:57:23 -0400 Subject: [PATCH] Add "Current area" option to Inspect --- Runtime/ImGuiConsole.cpp | 32 +++++++++++++++++++++----------- Runtime/ImGuiConsole.hpp | 1 + 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/Runtime/ImGuiConsole.cpp b/Runtime/ImGuiConsole.cpp index 8602982ee..642b3a297 100644 --- a/Runtime/ImGuiConsole.cpp +++ b/Runtime/ImGuiConsole.cpp @@ -231,13 +231,20 @@ void ImGuiConsole::ShowInspectWindow(bool* isOpen) { if (ImGui::Begin("Inspect", isOpen)) { CObjectList& list = g_StateManager->GetAllObjectList(); ImGui::Text("Objects: %d / 1024", list.size()); - if (ImGui::Button("Deselect all")) { + ImGui::SameLine(); + if (ImGui::SmallButton("Deselect all")) { for (auto* const ent : list) { ent->m_debugSelected = false; } } + if (ImGui::Button("Clear")) { + m_inspectFilterText[0] = '\0'; + } + ImGui::SameLine(); ImGui::InputText("Filter", m_inspectFilterText.data(), m_inspectFilterText.size()); ImGui::Checkbox("Active", &m_inspectActiveOnly); + ImGui::SameLine(); + ImGui::Checkbox("Current area", &m_inspectCurrentAreaOnly); if (ImGui::BeginTable("Entities", 4, ImGuiTableFlags_Resizable | ImGuiTableFlags_Sortable | ImGuiTableFlags_RowBg | @@ -260,22 +267,25 @@ void ImGuiConsole::ShowInspectWindow(bool* isOpen) { (sortSpecs->Specs[0].ColumnUserID != 'id' || sortSpecs->Specs[0].SortDirection != ImGuiSortDirection_Ascending); std::string_view search{m_inspectFilterText.data(), strlen(m_inspectFilterText.data())}; - if (!search.empty() || m_inspectActiveOnly || hasSortSpec) { + if (!search.empty() || m_inspectActiveOnly || m_inspectCurrentAreaOnly || hasSortSpec) { std::vector sortedList; sortedList.reserve(list.size()); s16 uid = list.GetFirstObjectIndex(); + + auto currAreaId = kInvalidAreaId; + CPlayer* player; + if (m_inspectCurrentAreaOnly && (player = g_StateManager->Player()) != nullptr) { + currAreaId = player->GetAreaIdAlways(); + } + while (uid != -1) { ImGuiEntityEntry& entry = ImGuiConsole::entities[uid]; - if (m_inspectActiveOnly && !entry.active) { - uid = list.GetNextObjectIndex(uid); - continue; + if ((!m_inspectActiveOnly || entry.active) && + (!m_inspectCurrentAreaOnly || entry.ent->x4_areaId == currAreaId) && + (search.empty() || ContainsCaseInsensitive(entry.type, search) || + ContainsCaseInsensitive(entry.name, search))) { + sortedList.push_back(uid); } - if (!search.empty() && !ContainsCaseInsensitive(entry.type, search) && - !ContainsCaseInsensitive(entry.name, search)) { - uid = list.GetNextObjectIndex(uid); - continue; - } - sortedList.push_back(uid); uid = list.GetNextObjectIndex(uid); } if (hasSortSpec) { diff --git a/Runtime/ImGuiConsole.hpp b/Runtime/ImGuiConsole.hpp index 193473afb..674169ac5 100644 --- a/Runtime/ImGuiConsole.hpp +++ b/Runtime/ImGuiConsole.hpp @@ -57,6 +57,7 @@ private: bool m_stepFrame = false; bool m_inspectActiveOnly = false; + bool m_inspectCurrentAreaOnly = false; std::array m_inspectFilterText{}; // Debug overlays