From 0e54d55bf72e8c7876e47110f7e40dbcd2befa18 Mon Sep 17 00:00:00 2001 From: Luke Street Date: Wed, 26 May 2021 15:57:59 -0400 Subject: [PATCH] Inspect window filter & Patterned body state info --- Runtime/Character/CMakeLists.txt | 2 +- Runtime/Character/CharacterCommon.cpp | 62 +++++++++++++++++++++++++++ Runtime/Character/CharacterCommon.hpp | 4 ++ Runtime/ImGuiConsole.cpp | 50 +++++++++++++++++---- Runtime/ImGuiEntitySupport.cpp | 17 +++++++- 5 files changed, 124 insertions(+), 11 deletions(-) create mode 100644 Runtime/Character/CharacterCommon.cpp diff --git a/Runtime/Character/CMakeLists.txt b/Runtime/Character/CMakeLists.txt index 653f4e391..d984308c3 100644 --- a/Runtime/Character/CMakeLists.txt +++ b/Runtime/Character/CMakeLists.txt @@ -1,5 +1,5 @@ set(CHARACTER_SOURCES - CharacterCommon.hpp + CharacterCommon.hpp CharacterCommon.cpp CAssetFactory.hpp CAssetFactory.cpp CCharacterFactory.hpp CCharacterFactory.cpp CModelData.hpp CModelData.cpp diff --git a/Runtime/Character/CharacterCommon.cpp b/Runtime/Character/CharacterCommon.cpp new file mode 100644 index 000000000..fd3489e40 --- /dev/null +++ b/Runtime/Character/CharacterCommon.cpp @@ -0,0 +1,62 @@ +#include "CharacterCommon.hpp" + +using namespace std::literals; + +namespace metaforce::pas { +std::string_view AnimationStateToStr(EAnimationState state) { + switch (state) { + case EAnimationState::Invalid: + return "Invalid"sv; + case EAnimationState::Fall: + return "Fall"sv; + case EAnimationState::Getup: + return "Getup"sv; + case EAnimationState::LieOnGround: + return "LieOnGround"sv; + case EAnimationState::Step: + return "Step"sv; + case EAnimationState::Death: + return "Death"sv; + case EAnimationState::Locomotion: + return "Locomotion"sv; + case EAnimationState::KnockBack: + return "KnockBack"sv; + case EAnimationState::MeleeAttack: + return "MeleeAttack"sv; + case EAnimationState::Turn: + return "Turn"sv; + case EAnimationState::LoopAttack: + return "LoopAttack"sv; + case EAnimationState::LoopReaction: + return "LoopReaction"sv; + case EAnimationState::GroundHit: + return "GroundHit"sv; + case EAnimationState::Generate: + return "Generate"sv; + case EAnimationState::Jump: + return "Jump"sv; + case EAnimationState::Hurled: + return "Hurled"sv; + case EAnimationState::Slide: + return "Slide"sv; + case EAnimationState::Taunt: + return "Taunt"sv; + case EAnimationState::Scripted: + return "Scripted"sv; + case EAnimationState::ProjectileAttack: + return "ProjectileAttack"sv; + case EAnimationState::Cover: + return "Cover"sv; + case EAnimationState::WallHang: + return "WallHang"sv; + case EAnimationState::AdditiveIdle: + return "AdditiveIdle"sv; + case EAnimationState::AdditiveAim: + return "AdditiveAim"sv; + case EAnimationState::AdditiveFlinch: + return "AdditiveFlinch"sv; + case EAnimationState::AdditiveReaction: + return "AdditiveReaction"sv; + } +} +} // namespace metaforce::pas diff --git a/Runtime/Character/CharacterCommon.hpp b/Runtime/Character/CharacterCommon.hpp index 0ccb8674d..432acdc8e 100644 --- a/Runtime/Character/CharacterCommon.hpp +++ b/Runtime/Character/CharacterCommon.hpp @@ -1,5 +1,7 @@ #pragma once +#include + namespace metaforce { namespace pas { enum class ELocomotionType { @@ -52,6 +54,8 @@ enum class EAnimationState { AdditiveReaction = 24 }; +std::string_view AnimationStateToStr(EAnimationState state); + enum class EHurledState { Invalid = -1, KnockIntoAir, diff --git a/Runtime/ImGuiConsole.cpp b/Runtime/ImGuiConsole.cpp index dd81f79fd..31dfd9137 100644 --- a/Runtime/ImGuiConsole.cpp +++ b/Runtime/ImGuiConsole.cpp @@ -90,6 +90,11 @@ static void Warp(const CAssetId worldId, TAreaId aId) { } } +bool containsCaseInsensitive(std::string_view str, std::string_view val) { + return std::search(str.begin(), str.end(), val.begin(), val.end(), + [](char ch1, char ch2) { return std::toupper(ch1) == std::toupper(ch2); }) != str.end(); +} + static bool stepFrame = false; static void ShowMenuGame() { @@ -120,9 +125,7 @@ static void ShowMenuGame() { } } -void ImGuiStringViewText(std::string_view text) { - ImGui::TextUnformatted(text.begin(), text.end()); -} +void ImGuiStringViewText(std::string_view text) { ImGui::TextUnformatted(text.begin(), text.end()); } static void LerpActorColor(CActor* act) { act->m_debugAddColorTime += 1.f / 60.f; @@ -137,6 +140,7 @@ static void LerpActorColor(CActor* act) { } static void ShowInspectWindow(bool* isOpen) { + static std::array filterText{}; if (ImGui::Begin("Inspect", isOpen)) { CObjectList& list = *g_StateManager->GetObjectList(); ImGui::Text("Objects: %d / 1024", list.size()); @@ -147,6 +151,7 @@ static void ShowInspectWindow(bool* isOpen) { } } } + ImGui::InputText("Filter", filterText.data(), filterText.size()); if (ImGui::BeginTable("Entities", 4, ImGuiTableFlags_Resizable | ImGuiTableFlags_Sortable | ImGuiTableFlags_RowBg | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV | ImGuiTableFlags_ScrollY)) { @@ -162,6 +167,14 @@ static void ShowInspectWindow(bool* isOpen) { std::vector items; items.reserve(list.size()); for (auto* ent : list) { + std::string_view search{filterText.data(), strlen(filterText.data())}; + if (!search.empty()) { + std::string_view type = ent->ImGuiType(); + std::string_view name = ent->GetName(); + if (!containsCaseInsensitive(type, search) && !containsCaseInsensitive(name, search)) { + continue; + } + } items.push_back(ent); } if (ImGuiTableSortSpecs* sortSpecs = ImGui::TableGetSortSpecs()) { @@ -190,13 +203,31 @@ static void ShowInspectWindow(bool* isOpen) { TUniqueId uid = item->GetUniqueId(); ImGui::PushID(uid.Value()); ImGui::TableNextRow(); + bool isActive = item->GetActive(); + if (!isActive) { + ImGui::PushStyleColor(ImGuiCol_Text, 0xAAFFFFFF); + } if (ImGui::TableNextColumn()) { auto text = fmt::format(FMT_STRING("{:x}"), uid.Value()); - if (TCastToPtr act = item) { - ImGui::Selectable(text.c_str(), &act->m_debugSelected, - ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowItemOverlap); - } else { - ImGui::TextUnformatted(text.c_str()); + bool tmp = false; + bool* selected = &tmp; + TCastToPtr act = item; + if (act != nullptr) { + selected = &act->m_debugSelected; + } + ImGui::Selectable(text.c_str(), selected, + ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowItemOverlap); + if (ImGui::BeginPopupContextItem(text.c_str())) { + if (!isActive) { + ImGui::PopStyleColor(); + } + if (ImGui::MenuItem(isActive ? "Deactivate" : "Activate")) { + item->SetActive(!isActive); + } + ImGui::EndPopup(); + if (!isActive) { + ImGui::PushStyleColor(ImGuiCol_Text, 0xAAFFFFFF); + } } } if (ImGui::TableNextColumn()) { @@ -210,6 +241,9 @@ static void ShowInspectWindow(bool* isOpen) { ImGuiConsole::inspectingEntities.insert(uid); } } + if (!isActive) { + ImGui::PopStyleColor(); + } ImGui::PopID(); } ImGui::EndTable(); diff --git a/Runtime/ImGuiEntitySupport.cpp b/Runtime/ImGuiEntitySupport.cpp index bb5c55e88..30bd10856 100644 --- a/Runtime/ImGuiEntitySupport.cpp +++ b/Runtime/ImGuiEntitySupport.cpp @@ -417,8 +417,21 @@ IMGUI_ENTITY_INSPECT(MP1::CRipperControlledPlatform, CScriptPlatform, RipperCont // <- CAi IMGUI_ENTITY_INSPECT(CDestroyableRock, CAi, DestroyableRock, {}) -IMGUI_ENTITY_INSPECT(CPatterned, CAi, Patterned, - { BITFIELD_CHECKBOX("Enable state machine", x403_25_enableStateMachine); }) +IMGUI_ENTITY_INSPECT(CPatterned, CAi, Patterned, { + BITFIELD_CHECKBOX("Enable state machine", x403_25_enableStateMachine); + ImGui::Text("Body state:"); + ImGui::SameLine(); + ImGuiStringViewText(pas::AnimationStateToStr(x450_bodyController->GetCurrentStateId())); + if (ImGui::Button("Burn")) { + Burn(1.f, 1.f); + } + if (ImGui::Button("Shock")) { + Shock(*g_StateManager, 1.f, 1.f); + } + if (ImGui::Button("Freeze")) { + Freeze(*g_StateManager, GetTranslation(), zeus::skZero3f, 1.f); + } +}) // <- CPatterned IMGUI_ENTITY_INSPECT(MP1::CAtomicAlpha, CPatterned, AtomicAlpha, {})