diff --git a/src/hci/research.cpp b/src/hci/research.cpp index 783c2266e42..819b4f8cfde 100644 --- a/src/hci/research.cpp +++ b/src/hci/research.cpp @@ -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 controller; size_t researchOptionIndex; AllyResearchsIcons allyResearchIcons; diff --git a/src/research.cpp b/src/research.cpp index f6579fae817..a96a310e15d 100644 --- a/src/research.cpp +++ b/src/research.cpp @@ -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 @@ -587,6 +588,36 @@ bool loadResearch(WzConfig &ini) return false; } + // populate research category info + std::unordered_map> 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{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()) { diff --git a/src/researchdef.h b/src/researchdef.h index 02670bc35c7..7e37757a5bc 100644 --- a/src/researchdef.h +++ b/src/researchdef.h @@ -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) {}