Skip to content

Commit

Permalink
Add Combined DataSource
Browse files Browse the repository at this point in the history
  • Loading branch information
Krappa322 committed Mar 6, 2021
1 parent 18d00bf commit a80d348
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 33 deletions.
18 changes: 9 additions & 9 deletions AggregatedStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -59,9 +59,9 @@ const AggregatedStatsEntry& AggregatedStats::GetTotal()
return *myTotal;
}

const AggregatedVector& AggregatedStats::GetStats()
const AggregatedVector& AggregatedStats::GetStats(DataSource pDataSource)
{
switch (static_cast<DataSource>(myOptions.DataSourceChoice))
switch (pDataSource)
{
case DataSource::Skills:
return GetSkills();
Expand All @@ -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<DataSource>(myOptions.DataSourceChoice) == DataSource::Skills)
{
return GetSkillDetails(static_cast<uint32_t>(pId));
}
else
switch (pDataSource)
{
case DataSource::Skills:
GetSkillDetails(static_cast<uint32_t>(pId));
case DataSource::Agents:
default:
return GetAgentDetails(pId);
}
}
Expand Down
4 changes: 2 additions & 2 deletions AggregatedStats.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
96 changes: 75 additions & 21 deletions GUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <array>
#include <Windows.h>

static void Display_DetailsWindow(HealWindowContext& pContext, DetailsWindowState& pState)
static void Display_DetailsWindow(HealWindowContext& pContext, DetailsWindowState& pState, DataSource pDataSource)
{
if (pState.IsOpen == false)
{
Expand All @@ -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<int>(pDataSource), pState.Id);
ImGui::SetNextWindowSize(ImVec2(600, 360), ImGuiCond_FirstUseEver);
ImGui::Begin(buffer, &pState.IsOpen, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings);

Expand All @@ -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<int>(pDataSource), pState.Id);
ImGui::BeginChild(buffer, ImVec2(ImGui::GetWindowContentRegionWidth() * 0.35f, 0));
ImGui::Text("total healing");
ImGuiEx::TextRightAlignedSameLine("%llu", pState.Healing);
Expand Down Expand Up @@ -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<int>(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());

Expand All @@ -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<int>(entry.Id));
ImGui::PushID(i);
float startX = ImGui::GetCursorPosX();
ImGui::Selectable("", false, ImGuiSelectableFlags_SpanAllColumns);
ImGui::PopID();
Expand All @@ -132,9 +135,23 @@ static void Display_Content(HealWindowContext& pContext, uint32_t pWindowIndex)
ImGui::EndGroup();

DetailsWindowState* state = nullptr;
if (entry.Id != 0)
std::vector<DetailsWindowState>* 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)
{
Expand All @@ -150,11 +167,11 @@ static void Display_Content(HealWindowContext& pContext, uint32_t pWindowIndex)
*static_cast<AggregatedStatsEntry*>(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;

Expand Down Expand Up @@ -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<uint64_t>(DataSource::Max), "Added data source without updating gui?");
ImGui::Combo("data source", &curWindow.DataSourceChoice, dataSourceItems, static_cast<int>(DataSource::Max));
ImGuiEx::AddTooltipToLastItem("Decides how targets and skills are sorted in the 'Targets' and 'Skills' sections.");
Expand Down Expand Up @@ -307,19 +324,56 @@ void Display_GUI(HealTableOptions& pHealingOptions)
ImGui::EndPopup();
}

Display_Content(curWindow, i);
if (static_cast<DataSource>(curWindow.DataSourceChoice) != DataSource::Combined)
{
Display_Content(curWindow, static_cast<DataSource>(curWindow.DataSourceChoice), i);
}
else
{
ImGui::PushID(static_cast<int>(DataSource::Totals));
ImGuiEx::TextColoredCentered(ImColor(0, 209, 165), "Totals");
Display_Content(curWindow, DataSource::Totals, i);
ImGui::PopID();

ImGui::PushID(static_cast<int>(DataSource::Agents));
ImGuiEx::TextColoredCentered(ImColor(0, 209, 165), "Targets");
Display_Content(curWindow, DataSource::Agents, i);
ImGui::PopID();

ImGui::PushID(static_cast<int>(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<DetailsWindowState>* 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();
Expand Down
10 changes: 10 additions & 0 deletions ImGuiEx.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ namespace ImGuiEx
ImGui::Text("%s", buffer);
}

template <typename... Args>
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 <typename... Args>
void BottomText(const char* pFormatString, Args... pArgs)
{
Expand Down
4 changes: 4 additions & 0 deletions Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(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)");
}
3 changes: 2 additions & 1 deletion Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ struct HealWindowContext : HealWindowOptions
std::unique_ptr<AggregatedStats> CurrentAggregatedStats; // In-Memory only
time_t LastAggregatedTime = 0; // In-Memory only

std::vector<DetailsWindowState> OpenDetailWindows; // In-Memory only
std::vector<DetailsWindowState> OpenSkillWindows; // In-Memory only
std::vector<DetailsWindowState> OpenAgentWindows; // In-Memory only
};

struct HealTableOptions
Expand Down
1 change: 1 addition & 0 deletions State.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ enum class DataSource
Agents = 0,
Skills = 1,
Totals = 2,
Combined = 3,
Max
};

Expand Down

0 comments on commit a80d348

Please sign in to comment.