Skip to content

Commit

Permalink
initial research category progress tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsupermanhd committed Feb 27, 2025
1 parent 4ee15cc commit 7f58b35
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/hci/research.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,20 @@ class ResearchOptionButton: public StatsFormButton
});
}

std::string getTip() override
{
WzString costString = WzString::fromUtf8(astringf(_("Cost: %u"), getCost()));
auto stats = getStats();
WzString tipString = (stats == nullptr) ? "" : getLocalizedStatsName(stats);
if (!stats->category.isEmpty())
{
tipString.append(astringf("\n%s %d/%d", stats->category.toUtf8().c_str(), stats->categoryProgress, stats->categoryMax).c_str());
}
tipString.append("\n");
tipString.append(costString);
return tipString.toUtf8();
}

std::shared_ptr<ResearchController> controller;
size_t researchOptionIndex;
AllyResearchsIcons allyResearchIcons;
Expand Down
31 changes: 31 additions & 0 deletions src/research.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ bool loadResearch(WzConfig &ini)
RESEARCH research;
research.index = inc;
research.name = ini.string("name");
research.category = ini.string("category");
research.id = list[inc];

//check the name hasn't been used already
Expand Down Expand Up @@ -587,6 +588,36 @@ bool loadResearch(WzConfig &ini)
return false;
}

// populate research category info
std::unordered_map<WzString, std::vector<size_t>> resCategories = {};
for (size_t inc = 0; inc < asResearch.size(); inc++)
{
auto cat = asResearch[inc].category;
if (cat.isEmpty())
{
continue;
}
if (resCategories.count(cat))
{
resCategories.at(cat).push_back(inc);
}
else
{
resCategories.insert({cat, std::vector<size_t>{inc}});
}

}
for (const auto& cat : resCategories)
{
uint16_t prog = 1;
for (const auto& inc : cat.second)
{
asResearch[inc].categoryProgress = prog;
asResearch[inc].categoryMax = cat.second.size();
prog++;
}
}

// If the first research json file does not explicitly set calculationMode, default to compat
if (!researchUpgradeCalcMode.has_value())
{
Expand Down
3 changes: 3 additions & 0 deletions src/researchdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ struct RESEARCH : public BASE_STATS
BASE_STATS *psStat; /* A stat used to define which graphic is drawn instead of the two fields below */
iIMDBaseShape *pIMD; /* the IMD to draw for this research topic */
iIMDBaseShape *pIMD2; /* the 2nd IMD for base plates/turrets*/
WzString category; /* Category name as in json (for progression numbering) */
uint16_t categoryProgress; /* Category this/max (gets filled on load) */
uint16_t categoryMax; /* Category progress/this (gets filled on load) */
int index; ///< Unique index for this research, set incrementally

RESEARCH() : pViewData(nullptr), iconID(0), psStat(nullptr), pIMD(nullptr), pIMD2(nullptr) {}
Expand Down

0 comments on commit 7f58b35

Please sign in to comment.