From a80d3487c8cc2911f9301bf3fe8dbe2ef89d1f9f Mon Sep 17 00:00:00 2001 From: Kappa322 Date: Sat, 6 Mar 2021 17:18:37 +0100 Subject: [PATCH] Add Combined DataSource --- AggregatedStats.cpp | 18 ++++----- AggregatedStats.h | 4 +- GUI.cpp | 96 +++++++++++++++++++++++++++++++++++---------- ImGuiEx.h | 10 +++++ Options.cpp | 4 ++ Options.h | 3 +- State.h | 1 + 7 files changed, 103 insertions(+), 33 deletions(-) diff --git a/AggregatedStats.cpp b/AggregatedStats.cpp index 414ad98..c293236 100644 --- a/AggregatedStats.cpp +++ b/AggregatedStats.cpp @@ -49,7 +49,7 @@ const AggregatedStatsEntry& AggregatedStats::GetTotal() uint64_t healing = 0; uint64_t hits = 0; - for (const AggregatedStatsEntry& entry : GetStats()) + for (const AggregatedStatsEntry& entry : GetSkills()) { healing += entry.Healing; hits += entry.Hits; @@ -59,9 +59,9 @@ const AggregatedStatsEntry& AggregatedStats::GetTotal() return *myTotal; } -const AggregatedVector& AggregatedStats::GetStats() +const AggregatedVector& AggregatedStats::GetStats(DataSource pDataSource) { - switch (static_cast(myOptions.DataSourceChoice)) + switch (pDataSource) { case DataSource::Skills: return GetSkills(); @@ -73,14 +73,14 @@ const AggregatedVector& AggregatedStats::GetStats() } } -const AggregatedVector& AggregatedStats::GetDetails(uint64_t pId) +const AggregatedVector& AggregatedStats::GetDetails(DataSource pDataSource, uint64_t pId) { - if (static_cast(myOptions.DataSourceChoice) == DataSource::Skills) - { - return GetSkillDetails(static_cast(pId)); - } - else + switch (pDataSource) { + case DataSource::Skills: + GetSkillDetails(static_cast(pId)); + case DataSource::Agents: + default: return GetAgentDetails(pId); } } diff --git a/AggregatedStats.h b/AggregatedStats.h index ade9296..a7c2337 100644 --- a/AggregatedStats.h +++ b/AggregatedStats.h @@ -43,8 +43,8 @@ class AggregatedStats AggregatedStats(HealingStats&& pSourceData, const HealWindowOptions& pOptions, bool pDebugMode); const AggregatedStatsEntry& GetTotal(); - const AggregatedVector& GetStats(); - const AggregatedVector& GetDetails(uint64_t pId); + const AggregatedVector& GetStats(DataSource pDataSource); + const AggregatedVector& GetDetails(DataSource pDataSource, uint64_t pId); uint64_t GetCombatTime(); const AggregatedVector& GetGroupFilterTotals(); diff --git a/GUI.cpp b/GUI.cpp index b67aad6..f0c4e45 100644 --- a/GUI.cpp +++ b/GUI.cpp @@ -9,7 +9,7 @@ #include #include -static void Display_DetailsWindow(HealWindowContext& pContext, DetailsWindowState& pState) +static void Display_DetailsWindow(HealWindowContext& pContext, DetailsWindowState& pState, DataSource pDataSource) { if (pState.IsOpen == false) { @@ -22,7 +22,7 @@ static void Display_DetailsWindow(HealWindowContext& pContext, DetailsWindowStat char buffer[1024]; // Using "###" means the id of the window is calculated only from the part after the hashes (which // in turn means that the name of the window can change if necessary) - snprintf(buffer, sizeof(buffer), "%s###HEALDETAILS%llu", pState.Name.c_str(), pState.Id); + snprintf(buffer, sizeof(buffer), "%s###HEALDETAILS.%i.%llu", pState.Name.c_str(), static_cast(pDataSource), pState.Id); ImGui::SetNextWindowSize(ImVec2(600, 360), ImGuiCond_FirstUseEver); ImGui::Begin(buffer, &pState.IsOpen, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings); @@ -44,7 +44,7 @@ static void Display_DetailsWindow(HealWindowContext& pContext, DetailsWindowStat ImVec4 bgColor = ImGui::GetStyle().Colors[ImGuiCol_WindowBg]; bgColor.w = 0.0f; ImGui::PushStyleColor(ImGuiCol_ChildBg, bgColor); - snprintf(buffer, sizeof(buffer), "##HEALDETAILS.TOTALS.%llu", pState.Id); + snprintf(buffer, sizeof(buffer), "##HEALDETAILS.TOTALS.%i.%llu", static_cast(pDataSource), pState.Id); ImGui::BeginChild(buffer, ImVec2(ImGui::GetWindowContentRegionWidth() * 0.35f, 0)); ImGui::Text("total healing"); ImGuiEx::TextRightAlignedSameLine("%llu", pState.Healing); @@ -73,10 +73,10 @@ static void Display_DetailsWindow(HealWindowContext& pContext, DetailsWindowStat ImGuiEx::BottomText("id %u", pState.Id); ImGui::EndChild(); - snprintf(buffer, sizeof(buffer), "##HEALDETAILS.ENTRIES.%llu", pState.Id); + snprintf(buffer, sizeof(buffer), "##HEALDETAILS.ENTRIES.%i.%llu", static_cast(pDataSource), pState.Id); ImGui::SameLine(); ImGui::BeginChild(buffer, ImVec2(0, 0)); - for (const auto& entry : pContext.CurrentAggregatedStats->GetDetails(pState.Id)) + for (const auto& entry : pContext.CurrentAggregatedStats->GetDetails(pDataSource, pState.Id)) { ImGui::Text("%s", entry.Name.c_str()); @@ -99,17 +99,20 @@ static void Display_DetailsWindow(HealWindowContext& pContext, DetailsWindowStat ImGui::End(); } -static void Display_Content(HealWindowContext& pContext, uint32_t pWindowIndex) +static void Display_Content(HealWindowContext& pContext, DataSource pDataSource, uint32_t pWindowIndex) { char buffer[1024]; uint64_t timeInCombat = pContext.CurrentAggregatedStats->GetCombatTime(); const AggregatedStatsEntry& aggregatedTotal = pContext.CurrentAggregatedStats->GetTotal(); - for (const auto& entry : pContext.CurrentAggregatedStats->GetStats()) + const AggregatedVector& stats = pContext.CurrentAggregatedStats->GetStats(pDataSource); + for (int i = 0; i < stats.size(); i++) { + const auto& entry = stats[i]; + ImGui::BeginGroup(); - ImGui::PushID(static_cast(entry.Id)); + ImGui::PushID(i); float startX = ImGui::GetCursorPosX(); ImGui::Selectable("", false, ImGuiSelectableFlags_SpanAllColumns); ImGui::PopID(); @@ -132,9 +135,23 @@ static void Display_Content(HealWindowContext& pContext, uint32_t pWindowIndex) ImGui::EndGroup(); DetailsWindowState* state = nullptr; - if (entry.Id != 0) + std::vector* vec; + switch (pDataSource) + { + case DataSource::Agents: + vec = &pContext.OpenAgentWindows; + break; + case DataSource::Skills: + vec = &pContext.OpenSkillWindows; + break; + default: + vec = nullptr; + break; + } + + if (vec != nullptr) { - for (auto& iter : pContext.OpenDetailWindows) + for (auto& iter : *vec) { if (iter.Id == entry.Id) { @@ -150,11 +167,11 @@ static void Display_Content(HealWindowContext& pContext, uint32_t pWindowIndex) *static_cast(state) = entry; } - if (ImGui::IsItemClicked() == true && entry.Id != 0) + if (vec != nullptr && ImGui::IsItemClicked() == true) { if (state == nullptr) { - state = &pContext.OpenDetailWindows.emplace_back(entry); + state = &vec->emplace_back(entry); } state->IsOpen = !state->IsOpen; @@ -220,7 +237,7 @@ void Display_GUI(HealTableOptions& pHealingOptions) if (ImGui::BeginPopupContextWindow("Options##HEAL") == true) { - const char* const dataSourceItems[] = {"targets", "skills", "totals"}; + const char* const dataSourceItems[] = {"targets", "skills", "totals", "combined"}; static_assert((sizeof(dataSourceItems) / sizeof(dataSourceItems[0])) == static_cast(DataSource::Max), "Added data source without updating gui?"); ImGui::Combo("data source", &curWindow.DataSourceChoice, dataSourceItems, static_cast(DataSource::Max)); ImGuiEx::AddTooltipToLastItem("Decides how targets and skills are sorted in the 'Targets' and 'Skills' sections."); @@ -307,19 +324,56 @@ void Display_GUI(HealTableOptions& pHealingOptions) ImGui::EndPopup(); } - Display_Content(curWindow, i); + if (static_cast(curWindow.DataSourceChoice) != DataSource::Combined) + { + Display_Content(curWindow, static_cast(curWindow.DataSourceChoice), i); + } + else + { + ImGui::PushID(static_cast(DataSource::Totals)); + ImGuiEx::TextColoredCentered(ImColor(0, 209, 165), "Totals"); + Display_Content(curWindow, DataSource::Totals, i); + ImGui::PopID(); + + ImGui::PushID(static_cast(DataSource::Agents)); + ImGuiEx::TextColoredCentered(ImColor(0, 209, 165), "Targets"); + Display_Content(curWindow, DataSource::Agents, i); + ImGui::PopID(); + + ImGui::PushID(static_cast(DataSource::Skills)); + ImGuiEx::TextColoredCentered(ImColor(0, 209, 165), "Skills"); + Display_Content(curWindow, DataSource::Skills, i); + ImGui::PopID(); + } - auto iter = curWindow.OpenDetailWindows.begin(); - while (iter != curWindow.OpenDetailWindows.end()) + for (const DataSource dataSource : std::array{DataSource::Agents, DataSource::Skills}) { - if (iter->IsOpen == false) + std::vector* vec; + switch (dataSource) { - iter = curWindow.OpenDetailWindows.erase(iter); - continue; + case DataSource::Agents: + vec = &curWindow.OpenAgentWindows; + break; + case DataSource::Skills: + vec = &curWindow.OpenSkillWindows; + break; + default: + vec = nullptr; + break; } - Display_DetailsWindow(curWindow, *iter); - iter++; + auto iter = vec->begin(); + while (iter != vec->end()) + { + if (iter->IsOpen == false) + { + iter = vec->erase(iter); + continue; + } + + Display_DetailsWindow(curWindow, *iter, dataSource); + iter++; + } } ImGui::End(); diff --git a/ImGuiEx.h b/ImGuiEx.h index c062d55..b1a1c06 100644 --- a/ImGuiEx.h +++ b/ImGuiEx.h @@ -15,6 +15,16 @@ namespace ImGuiEx ImGui::Text("%s", buffer); } + template + void TextColoredCentered(ImColor pColor, const char* pFormatString, Args... pArgs) + { + char buffer[1024]; + + snprintf(buffer, sizeof(buffer), pFormatString, pArgs...); + ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x * 0.5f - ImGui::CalcTextSize(buffer).x * 0.5f); + ImGui::TextColored(pColor, "%s", buffer); + } + template void BottomText(const char* pFormatString, Args... pArgs) { diff --git a/Options.cpp b/Options.cpp index 4b13871..3a3df67 100644 --- a/Options.cpp +++ b/Options.cpp @@ -209,4 +209,8 @@ HealTableOptions::HealTableOptions() snprintf(Windows[4].TitleFormat, sizeof(Windows[4].TitleFormat), "%s", "Skills {1} ({5}/hit, {2} hits)"); snprintf(Windows[4].EntryFormat, sizeof(Windows[4].EntryFormat), "%s", "{1} ({5}/hit, {2} hits)"); snprintf(Windows[4].DetailsEntryFormat, sizeof(Windows[4].DetailsEntryFormat), "%s", "{1} ({5}/hit, {2} hits)"); + + Windows[9].DataSourceChoice = static_cast(DataSource::Combined); + snprintf(Windows[9].Name, sizeof(Windows[9].Name), "%s", "Combined"); + snprintf(Windows[9].TitleFormat, sizeof(Windows[9].TitleFormat), "%s", "Combined {1} ({4}/s, {7}s in combat)"); } diff --git a/Options.h b/Options.h index 3da8516..3a937ca 100644 --- a/Options.h +++ b/Options.h @@ -23,7 +23,8 @@ struct HealWindowContext : HealWindowOptions std::unique_ptr CurrentAggregatedStats; // In-Memory only time_t LastAggregatedTime = 0; // In-Memory only - std::vector OpenDetailWindows; // In-Memory only + std::vector OpenSkillWindows; // In-Memory only + std::vector OpenAgentWindows; // In-Memory only }; struct HealTableOptions diff --git a/State.h b/State.h index 540f8f6..f6d66b0 100644 --- a/State.h +++ b/State.h @@ -12,6 +12,7 @@ enum class DataSource Agents = 0, Skills = 1, Totals = 2, + Combined = 3, Max };