From 53aabceae256c7f33ef1897a029d825ac3abaec7 Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Sat, 29 May 2021 01:39:50 -0700 Subject: [PATCH] Allow editing amount/capacity separately --- Runtime/ImGuiConsole.cpp | 32 ++++++++++++++++++++++++-------- Runtime/ImGuiEntitySupport.cpp | 4 +--- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/Runtime/ImGuiConsole.cpp b/Runtime/ImGuiConsole.cpp index a5559f9da..0aba7840d 100644 --- a/Runtime/ImGuiConsole.cpp +++ b/Runtime/ImGuiConsole.cpp @@ -11,7 +11,7 @@ namespace ImGui { // Internal functions void ClearIniSettings(); -} +} // namespace ImGui #include "TCastTo.hpp" // Generated file, do not modify include path @@ -266,9 +266,10 @@ void ImGuiConsole::ShowInspectWindow(bool* isOpen) { ImGui::TableHeadersRow(); ImGuiTableSortSpecs* sortSpecs = ImGui::TableGetSortSpecs(); - bool hasSortSpec = sortSpecs != nullptr && sortSpecs->SpecsCount == 1 && // no multi-sort - // We can skip sorting if we just want uid ascending, - // since that's how we iterate over CObjectList + bool hasSortSpec = sortSpecs != nullptr && + sortSpecs->SpecsCount == 1 && // no multi-sort + // We can skip sorting if we just want uid ascending, + // since that's how we iterate over CObjectList (sortSpecs->Specs[0].ColumnUserID != 'id' || sortSpecs->Specs[0].SortDirection != ImGuiSortDirection_Ascending); std::string_view search{m_inspectFilterText.data(), strlen(m_inspectFilterText.data())}; @@ -730,6 +731,14 @@ static constexpr std::array ArtifactItems{ CPlayerState::EItemType::World, CPlayerState::EItemType::Spirit, CPlayerState::EItemType::Newborn, }; +int roundMultiple(int value, int multiple) { + if (multiple == 0) { + return value; + } + return static_cast(std::round(static_cast(value) / static_cast(multiple)) * + static_cast(multiple)); +} + static void RenderItemType(CPlayerState& pState, CPlayerState::EItemType itemType) { u32 maxValue = CPlayerState::GetPowerUpMaxValue(itemType); std::string name{CPlayerState::ItemTypeToName(itemType)}; @@ -748,10 +757,17 @@ static void RenderItemType(CPlayerState& pState, CPlayerState::EItemType itemTyp } } } else if (maxValue > 1) { - int capacity = int(pState.GetItemCapacity(itemType)); - if (ImGui::SliderInt(name.c_str(), &capacity, 0, int(maxValue), "%d", ImGuiSliderFlags_AlwaysClamp)) { - pState.ReInitializePowerUp(itemType, u32(capacity)); - pState.ResetAndIncrPickUp(itemType, u32(capacity)); + std::array item{}; + item[0] = int(pState.GetItemAmount(itemType)); + item[1] = int(pState.GetItemCapacity(itemType)); + if (ImGui::SliderInt2((name + " (Amount/Capacity)").c_str(), item.data(), 0, int(maxValue), "%d", + ImGuiSliderFlags_AlwaysClamp)) { + if (itemType == CPlayerState::EItemType::Missiles) { + pState.ReInitializePowerUp(itemType, roundMultiple(item[1], 5)); + } else { + pState.ReInitializePowerUp(itemType, u32(item[1])); + } + pState.ResetAndIncrPickUp(itemType, u32(item[0])); } } } diff --git a/Runtime/ImGuiEntitySupport.cpp b/Runtime/ImGuiEntitySupport.cpp index 28ba6e223..f5917b72b 100644 --- a/Runtime/ImGuiEntitySupport.cpp +++ b/Runtime/ImGuiEntitySupport.cpp @@ -152,8 +152,6 @@ #include "Runtime/MP1/World/CThardusRockProjectile.hpp" #include "Runtime/MP1/World/CTryclops.hpp" #include "Runtime/MP1/World/CWarWasp.hpp" - -#include "Runtime/CStateManager.hpp" #include "Runtime/GameGlobalObjects.hpp" #include "ImGuiConsole.hpp" @@ -265,7 +263,7 @@ void CEntity::ImGuiInspect() { ImGui::TableSetupColumn("State", ImGuiTableColumnFlags_WidthFixed, 0, 'stat'); ImGui::TableSetupColumn("Message", ImGuiTableColumnFlags_WidthFixed, 0, 'msg'); ImGui::TableSetupColumn("", ImGuiTableColumnFlags_NoSort | ImGuiTableColumnFlags_WidthFixed | - ImGuiTableColumnFlags_NoResize); + ImGuiTableColumnFlags_NoResize); ImGui::TableSetupScrollFreeze(0, 1); ImGui::TableHeadersRow(); for (const auto& item : *m_incomingConnections) {