From feac6d118606b73ce515a53cf99b246485741246 Mon Sep 17 00:00:00 2001 From: Anthony Stewart Date: Fri, 11 Jul 2025 22:51:52 -0500 Subject: [PATCH] Logic Tracker drawing updates. --- .../randomizer/randomizer_logic_tracker.cpp | 144 +++++++++++------- .../randomizer/randomizer_logic_tracker.h | 2 +- 2 files changed, 86 insertions(+), 60 deletions(-) diff --git a/soh/soh/Enhancements/randomizer/randomizer_logic_tracker.cpp b/soh/soh/Enhancements/randomizer/randomizer_logic_tracker.cpp index 19939406d..5358384d2 100644 --- a/soh/soh/Enhancements/randomizer/randomizer_logic_tracker.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer_logic_tracker.cpp @@ -47,6 +47,7 @@ struct LogicTrackerNode { std::string NodeName; std::vector Connections; int NodeId = -1; + RandomizerRegion RandomizerRegion = RR_NONE; }; bool expandingNode = false; @@ -165,7 +166,7 @@ void LogicTrackerWindow::ShowRandomizerCheck(RandomizerCheck randomizerCheck) { nodes.clear(); LogicTrackerNode node; - node.NodeName = location->GetName(); + node.NodeName = "Check: " + location->GetName(); node.NodeId = nodes.size(); for (int randomizerRegion = RR_NONE; randomizerRegion < RR_MAX; ++randomizerRegion) { @@ -173,7 +174,7 @@ void LogicTrackerWindow::ShowRandomizerCheck(RandomizerCheck randomizerCheck) { for (const auto& locationAccess : region.locations) { if (locationAccess.GetLocation() == randomizerCheck) { LogicTrackerNode::Connection connection; - connection.ParentName = region.regionName; + connection.ParentName = "Region: " + region.regionName; connection.ParentRandomizerRegion = RandomizerRegion(randomizerRegion); connection.ChildDayAccess = region.childDay; connection.ChildNightAccess = region.childNight; @@ -195,18 +196,23 @@ void LogicTrackerWindow::ShowRandomizerCheck(RandomizerCheck randomizerCheck) { expandNodeId = node.NodeId; } -void LogicTrackerWindow::ShowRandomizerRegion(RandomizerRegion randomizerRegion) { - const auto& region = RegionTable(randomizerRegion); +void LogicTrackerWindow::ShowRandomizerRegion(RandomizerRegion toRandomizerRegion, RandomizerRegion fromRandomizerRegion) { + const auto& region = RegionTable(toRandomizerRegion); LogicTrackerNode node; - node.NodeName = region->regionName; + node.NodeName = "Region: " + region->regionName; node.NodeId = nodes.size(); + node.RandomizerRegion = toRandomizerRegion; for (const auto& entrance : region->entrances) { + if (entrance->GetParentRegionKey() == fromRandomizerRegion) { + continue; + } + const auto& parentRegion = entrance->GetParentRegion(); LogicTrackerNode::Connection connection; - connection.ParentName = parentRegion->regionName; + connection.ParentName = "Region: " + parentRegion->regionName; connection.ParentRandomizerRegion = entrance->GetParentRegionKey(); connection.ChildDayAccess = parentRegion->childDay; connection.ChildNightAccess = parentRegion->childNight; @@ -408,53 +414,7 @@ static void DrawExpressionTable(ExpressionTable& table) { } static void DrawNodeConnection(LogicTrackerNode& node, LogicTrackerNode::Connection& connection) { - ImGui::PushID(connection.ParentName.c_str()); - - ImGui::TextUnformatted("Parent Access:"); - if (ImGui::BeginTable("", 4, - ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | ImGuiTableFlags_NoHostExtendX)) { - ImGui::TableSetupColumn("Child Day", ImGuiTableColumnFlags_WidthFixed); - ImGui::TableSetupColumn("Child Night", ImGuiTableColumnFlags_WidthFixed); - ImGui::TableSetupColumn("Adult Day", ImGuiTableColumnFlags_WidthFixed); - ImGui::TableSetupColumn("Adult Night", ImGuiTableColumnFlags_WidthFixed); - ImGui::TableHeadersRow(); - - ImGui::TableNextRow(); - - ImGui::PushFont(OTRGlobals::Instance->fontMono); - - ImGui::TableNextColumn(); - ImGui::TextUnformatted(connection.ChildDayAccess ? "true" : "false"); - - ImGui::TableNextColumn(); - ImGui::TextUnformatted(connection.ChildNightAccess ? "true" : "false"); - - ImGui::TableNextColumn(); - ImGui::TextUnformatted(connection.AdultDayAccess ? "true" : "false"); - - ImGui::TableNextColumn(); - ImGui::TextUnformatted(connection.AdultNightAccess ? "true" : "false"); - - ImGui::PopFont(); - - ImGui::EndTable(); - } - - if (connection.ParentRandomizerRegion != RR_NONE) { - ImGui::SameLine(); - if (ImGui::Button("Show Region Logic")) { - while (nodes.back().NodeId > node.NodeId) { - nodes.pop_back(); - } - - LogicTrackerWindow::ShowRandomizerRegion(connection.ParentRandomizerRegion); - } - } - - ImGui::TextUnformatted("Node Access:"); DrawExpressionTable(connection.ExpressionTable); - - ImGui::PopID(); } static void DrawNode(LogicTrackerNode& node) { @@ -464,16 +424,82 @@ static void DrawNode(LogicTrackerNode& node) { ImGui::SetNextItemOpen(expandNodeId == node.NodeId, ImGuiCond_Always); } - if (ImGui::CollapsingHeader(node.NodeName.c_str(), - ImGuiTreeNodeFlags_AllowOverlap | ImGuiTreeNodeFlags_SpanFullWidth)) { - ImGui::Indent(25.0f); + bool nodeOpen = ImGui::CollapsingHeader(("To " + node.NodeName).c_str(), + ImGuiTreeNodeFlags_AllowOverlap | ImGuiTreeNodeFlags_SpanFullWidth); + if (ImGui::IsItemHovered()) { + ImGui::SetTooltip("Show Connections"); + } + + if (nodeOpen) { for (int i = 0; i < node.Connections.size(); i++) { - if (ImGui::CollapsingHeader(node.Connections[i].ParentName.c_str(), ImGuiTreeNodeFlags_AllowOverlap | - ImGuiTreeNodeFlags_SpanAvailWidth)) { - DrawNodeConnection(node, node.Connections[i]); + auto& connection = node.Connections[i]; + ImGui::PushID(connection.ParentName.c_str()); + + auto& connectionHeader = connection.ParentName; + + std::string access = ""; + if (connection.ChildDayAccess && connection.ChildNightAccess && connection.AdultDayAccess && + connection.AdultNightAccess) { + access += "All"; + } else { + std::vector accessParts; + if (connection.ChildDayAccess && connection.ChildNightAccess) { + accessParts.push_back("Child"); + } else { + if (connection.ChildDayAccess) { + accessParts.push_back("Child Day"); + } + if (connection.ChildNightAccess) { + accessParts.push_back("Child Night"); + } + } + if (connection.AdultDayAccess && connection.AdultNightAccess) { + accessParts.push_back("Adult"); + } else { + if (connection.AdultDayAccess) { + accessParts.push_back("Adult Day"); + } + if (connection.AdultNightAccess) { + accessParts.push_back("Adult Night"); + } + } + if (!accessParts.empty()) { + for (size_t i = 0; i < accessParts.size(); ++i) { + if (i > 0) { + access += ", "; + } + access += accessParts[i]; + } + } } + + if (ImGui::Button(ICON_FA_COGS)) { + LogicTrackerWindow::ShowRandomizerRegion(connection.ParentRandomizerRegion, node.RandomizerRegion); + } + if (ImGui::IsItemHovered()) { + ImGui::SetTooltip("Show Region Logic"); + } + ImGui::SameLine(); + + bool connectionOpen = ImGui::CollapsingHeader( + ("From " + connection.ParentName).c_str(), ImGuiTreeNodeFlags_AllowOverlap | ImGuiTreeNodeFlags_SpanAvailWidth); + if (ImGui::IsItemHovered()) { + ImGui::SetTooltip("Show Connection Logic"); + } + + ImGui::SameLine(ImGui::GetContentRegionAvail().x - ImGui::CalcTextSize(access.c_str()).x); + ImGui::TextUnformatted(access.c_str()); + if (ImGui::IsItemHovered()) { + ImGui::SetTooltip("Connection Access"); + } + + if (connectionOpen) { + DrawNodeConnection(node, connection); + } + + ImGui::PopID(); } - ImGui::Unindent(25.0f); + } ImGui::PopID(); diff --git a/soh/soh/Enhancements/randomizer/randomizer_logic_tracker.h b/soh/soh/Enhancements/randomizer/randomizer_logic_tracker.h index 466475117..e194ed782 100644 --- a/soh/soh/Enhancements/randomizer/randomizer_logic_tracker.h +++ b/soh/soh/Enhancements/randomizer/randomizer_logic_tracker.h @@ -8,7 +8,7 @@ class LogicTrackerWindow : public Ship::GuiWindow { void DrawElement() override; static void ShowRandomizerCheck(RandomizerCheck randomizerCheck); - static void ShowRandomizerRegion(RandomizerRegion randomizerRegion); + static void ShowRandomizerRegion(RandomizerRegion toRandomizerRegion, RandomizerRegion fromRandomizerRegion); protected: void InitElement() override;