From fd19430264cb71a1006bb388ec4e0f5437a763c3 Mon Sep 17 00:00:00 2001 From: past-due <30942300+past-due@users.noreply.github.com> Date: Sat, 4 Nov 2023 17:13:23 -0400 Subject: [PATCH] Add separate getLocalizedStatsName() macro --- src/design.cpp | 20 ++++++++++---------- src/droid.cpp | 2 +- src/hci.cpp | 6 +++--- src/hci/manufacture.cpp | 2 +- src/hci/objects_stats.h | 4 ++-- src/hci/research.cpp | 2 +- src/intdisplay.h | 2 +- src/keybind.cpp | 2 +- src/multigifts.cpp | 4 ++-- src/multilimit.cpp | 2 +- src/oprint.cpp | 2 +- src/research.cpp | 4 ++-- src/statsdef.h | 1 + src/structure.cpp | 30 +++++++++++++++--------------- src/wzscriptdebug.cpp | 1 + 15 files changed, 43 insertions(+), 41 deletions(-) diff --git a/src/design.cpp b/src/design.cpp index 7d5884fcd53..85e2a1c7109 100644 --- a/src/design.cpp +++ b/src/design.cpp @@ -1356,7 +1356,7 @@ const char *GetDefaultTemplateName(DROID_TEMPLATE *psTemplate) psTemplate->asParts[COMP_REPAIRUNIT] != 0 || psTemplate->asParts[COMP_BRAIN] != 0) { - sstrcpy(aCurrName, getStatsName(psStats)); + sstrcpy(aCurrName, getLocalizedStatsName(psStats)); sstrcat(aCurrName, " "); } @@ -1370,8 +1370,8 @@ const char *GetDefaultTemplateName(DROID_TEMPLATE *psTemplate) psStats = (COMPONENT_STATS *)(asBodyStats + compIndex); if (psTemplate->asParts[COMP_BODY] != 0) { - checkStringLength(aCurrName, getStatsName(psStats)); - sstrcat(aCurrName, getStatsName(psStats)); + checkStringLength(aCurrName, getLocalizedStatsName(psStats)); + sstrcat(aCurrName, getLocalizedStatsName(psStats)); sstrcat(aCurrName, " "); } @@ -1380,8 +1380,8 @@ const char *GetDefaultTemplateName(DROID_TEMPLATE *psTemplate) psStats = (COMPONENT_STATS *)(asPropulsionStats + compIndex); if (psTemplate->asParts[COMP_PROPULSION] != 0) { - checkStringLength(aCurrName, getStatsName(psStats)); - sstrcat(aCurrName, getStatsName(psStats)); + checkStringLength(aCurrName, getLocalizedStatsName(psStats)); + sstrcat(aCurrName, getLocalizedStatsName(psStats)); } return aCurrName; @@ -1478,7 +1478,7 @@ static bool intSetSystemForm(COMPONENT_STATS *psStats) sFormInit.y = DES_BARFORMY; sFormInit.width = DES_BARFORMWIDTH; //COMPBUTWIDTH; sFormInit.height = DES_BARFORMHEIGHT; //COMPBUTHEIGHT; - sFormInit.pTip = getStatsName(psStats); // set form tip to stats string + sFormInit.pTip = getLocalizedStatsName(psStats); // set form tip to stats string sFormInit.pUserData = psStats; /* store component stats */ sFormInit.pDisplay = intDisplayStatForm; auto systemForm = widgAddForm(psWScreen, &sFormInit); @@ -1773,7 +1773,7 @@ static bool intSetPropulsionForm(PROPULSION_STATS *psStats) sFormInit.y = DES_BARFORMY; sFormInit.width = DES_BARFORMWIDTH; //DES_COMPBUTWIDTH; sFormInit.height = DES_BARFORMHEIGHT; //DES_COMPBUTHEIGHT; - sFormInit.pTip = getStatsName(psStats); // set form tip to stats string + sFormInit.pTip = getLocalizedStatsName(psStats); // set form tip to stats string sFormInit.pDisplay = intDisplayStatForm; auto propulsionForm = widgAddForm(psWScreen, &sFormInit); if (!propulsionForm) @@ -2194,7 +2194,7 @@ static void intSetSystemStats(COMPONENT_STATS *psStats) ASSERT_OR_RETURN(, psStats != nullptr, "Invalid stats pointer"); /* set form tip to stats string */ - widgSetTip(psWScreen, IDDES_SYSTEMFORM, checkIfZNullStat(psStats) ? "" : getStatsName(psStats)); + widgSetTip(psWScreen, IDDES_SYSTEMFORM, checkIfZNullStat(psStats) ? "" : getLocalizedStatsName(psStats)); /* set form stats for later display in intDisplayStatForm */ psForm = (W_FORM *) widgGetFromID(psWScreen, IDDES_SYSTEMFORM); @@ -2447,7 +2447,7 @@ static void intSetBodyStats(BODY_STATS *psStats) ASSERT_OR_RETURN(, psStats->hasType(STAT_BODY), "stats have wrong type"); /* set form tip to stats string */ - widgSetTip(psWScreen, IDDES_BODYFORM, checkIfZNullStat(psStats) ? "" : getStatsName(psStats)); + widgSetTip(psWScreen, IDDES_BODYFORM, checkIfZNullStat(psStats) ? "" : getLocalizedStatsName(psStats)); /* armour */ //do kinetic armour @@ -2664,7 +2664,7 @@ static void intSetPropulsionStats(PROPULSION_STATS *psStats) ASSERT_OR_RETURN(, psStats->hasType(STAT_PROPULSION), "stats have wrong type"); /* set form tip to stats string */ - widgSetTip(psWScreen, IDDES_PROPFORM, checkIfZNullStat(psStats) ? "" : getStatsName(psStats)); + widgSetTip(psWScreen, IDDES_PROPFORM, checkIfZNullStat(psStats) ? "" : getLocalizedStatsName(psStats)); /* set form stats for later display in intDisplayStatForm */ psForm = (W_FORM *) widgGetFromID(psWScreen, IDDES_PROPFORM); diff --git a/src/droid.cpp b/src/droid.cpp index ebfd478e8d0..0c87681ae77 100644 --- a/src/droid.cpp +++ b/src/droid.cpp @@ -1640,7 +1640,7 @@ DROID *reallyBuildDroid(const DROID_TEMPLATE *pTemplate, Position pos, UDWORD pl ASSERT_OR_RETURN(nullptr, player < MAX_PLAYERS, "Invalid player: %" PRIu32 "", player); DROID *psDroid = new DROID(id, player); - droidSetName(psDroid, getStatsName(pTemplate)); + droidSetName(psDroid, getLocalizedStatsName(pTemplate)); // Set the droids type psDroid->droidType = droidTemplateType(pTemplate); // Is set again later to the same thing, in droidSetBits. diff --git a/src/hci.cpp b/src/hci.cpp index 4ae9310945c..1b59dab0546 100644 --- a/src/hci.cpp +++ b/src/hci.cpp @@ -1731,7 +1731,7 @@ INT_RETVAL intRunWidgets() // the fact that we're cheating ourselves a new // structure. std::string msg = astringf(_("Player %u is cheating (debug menu) him/herself a new structure: %s."), - selectedPlayer, getStatsName(psStructure->pStructureType)); + selectedPlayer, getLocalizedStatsName(psStructure->pStructureType)); sendInGameSystemMessage(msg.c_str()); Cheated = true; } @@ -1740,7 +1740,7 @@ INT_RETVAL intRunWidgets() { // Send a text message to all players, notifying them of the fact that we're cheating ourselves a new feature. std::string msg = astringf(_("Player %u is cheating (debug menu) him/herself a new feature: %s."), - selectedPlayer, getStatsName(psPositionStats)); + selectedPlayer, getLocalizedStatsName(psPositionStats)); sendInGameSystemMessage(msg.c_str()); Cheated = true; // Notify the other hosts that we've just built ourselves a feature @@ -2371,7 +2371,7 @@ static bool intAddDebugStatsForm(BASE_STATS **_ppsStatsList, UDWORD numStats) statList->addWidgetToLayout(button); BASE_STATS *Stat = _ppsStatsList[i]; - WzString tipString = getStatsName(_ppsStatsList[i]); + WzString tipString = getLocalizedStatsName(_ppsStatsList[i]); unsigned powerCost = 0; W_BARGRAPH *bar; if (Stat->hasType(STAT_STRUCTURE)) // It's a structure. diff --git a/src/hci/manufacture.cpp b/src/hci/manufacture.cpp index 90a7d6aa88f..e30f3dccd62 100644 --- a/src/hci/manufacture.cpp +++ b/src/hci/manufacture.cpp @@ -272,7 +272,7 @@ class ManufactureObjectButton : public ObjectButton { auto factory = controller->getObjectAt(objectIndex); ASSERT_NOT_NULLPTR_OR_RETURN("", factory); - return getStatsName(factory->pStructureType); + return getLocalizedStatsName(factory->pStructureType); } ManufactureController &getController() const override diff --git a/src/hci/objects_stats.h b/src/hci/objects_stats.h index 71dac6aa829..07a14354673 100644 --- a/src/hci/objects_stats.h +++ b/src/hci/objects_stats.h @@ -133,7 +133,7 @@ class StatsButton: public DynamicIntFancyButton std::string getTip() override { auto stats = getStats(); - return stats == nullptr ? "": getStatsName(stats); + return stats == nullptr ? "": getLocalizedStatsName(stats); } void addProgressBar(); @@ -178,7 +178,7 @@ class StatsFormButton : public StatsButton { WzString costString = WzString::fromUtf8(astringf(_("Cost: %u"), getCost())); auto stats = getStats(); - WzString tipString = (stats == nullptr) ? "" : getStatsName(stats); + WzString tipString = (stats == nullptr) ? "" : getLocalizedStatsName(stats); tipString.append("\n"); tipString.append(costString); return tipString.toUtf8(); diff --git a/src/hci/research.cpp b/src/hci/research.cpp index 9890b346334..65f1301a004 100644 --- a/src/hci/research.cpp +++ b/src/hci/research.cpp @@ -348,7 +348,7 @@ class ResearchObjectButton : public ObjectButton { auto facility = controller->getObjectAt(objectIndex); ASSERT_NOT_NULLPTR_OR_RETURN("", facility); - return getStatsName(facility->pStructureType); + return getLocalizedStatsName(facility->pStructureType); } ResearchController &getController() const override diff --git a/src/intdisplay.h b/src/intdisplay.h index 16bd75b0ab2..8781e3d0784 100644 --- a/src/intdisplay.h +++ b/src/intdisplay.h @@ -202,7 +202,7 @@ class IntStatsButton : public IntFancyButton void setStatsAndTip(BASE_STATS *stats) { setStats(stats); - setTip(getStatsName(stats)); + setTip(getLocalizedStatsName(stats)); } protected: diff --git a/src/keybind.cpp b/src/keybind.cpp index 5a4075f8bb0..ebd336ed77e 100644 --- a/src/keybind.cpp +++ b/src/keybind.cpp @@ -1586,7 +1586,7 @@ void kf_FinishResearch() { researchResult(rindex, selectedPlayer, true, psCurr, true); } - std::string cmsg = astringf(_("(Player %u) is using cheat :%s %s"), selectedPlayer, _("Researched"), getStatsName(pSubject)); + std::string cmsg = astringf(_("(Player %u) is using cheat :%s %s"), selectedPlayer, _("Researched"), getLocalizedStatsName(pSubject)); sendInGameSystemMessage(cmsg.c_str()); intResearchFinished(psCurr); } diff --git a/src/multigifts.cpp b/src/multigifts.cpp index a08a75e5a49..758b429c4c6 100644 --- a/src/multigifts.cpp +++ b/src/multigifts.cpp @@ -252,7 +252,7 @@ static void recvGiftStruct(uint8_t from, uint8_t to, uint32_t structID) syncDebugStructure(psStruct, '>'); if (to == selectedPlayer) { - CONPRINTF(_("%s Gives you a %s"), getPlayerName(from), objInfo(psStruct)); + CONPRINTF(_("%s Gives you a %s"), getPlayerName(from), getLocalizedStatsName(psStruct->pStructureType)); } } else @@ -830,7 +830,7 @@ bool pickupArtefact(int toPlayer, int fromPlayer) MakeResearchPossible(&asPlayerResList[toPlayer][topic]); if (toPlayer == selectedPlayer) { - CONPRINTF(_("You Discover Blueprints For %s"), getStatsName(&asResearch[topic])); + CONPRINTF(_("You Discover Blueprints For %s"), getLocalizedStatsName(&asResearch[topic])); } break; } diff --git a/src/multilimit.cpp b/src/multilimit.cpp index 136ae8904f3..db8bb81b163 100644 --- a/src/multilimit.cpp +++ b/src/multilimit.cpp @@ -503,7 +503,7 @@ static void displayStructureBar(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset displayStructureStatButton(stat, &rotation, &position, scale); // draw name - cache.wzNameText.setText(_(getStatsName(stat)), font_regular); + cache.wzNameText.setText(getLocalizedStatsName(stat), font_regular); cache.wzNameText.render(x + 80, y + psWidget->height() / 2 + 3, WZCOL_TEXT_BRIGHT); // draw limit diff --git a/src/oprint.cpp b/src/oprint.cpp index 8cf006871d5..7ce34d946ca 100644 --- a/src/oprint.cpp +++ b/src/oprint.cpp @@ -60,7 +60,7 @@ static void printComponentInfo(const COMPONENT_STATS *psStats) { CONPRINTF("%s ref %d\n" " bPwr %d bPnts %d wt %d bdy %d imd %p\n", - getStatsName(psStats), psStats->ref, psStats->buildPower, + getLocalizedStatsName(psStats), psStats->ref, psStats->buildPower, psStats->buildPoints, psStats->weight, psStats->getBase().hitpoints, static_cast(psStats->pIMD)); } diff --git a/src/research.cpp b/src/research.cpp index 1b23e488e9b..c9bce1b1e7d 100644 --- a/src/research.cpp +++ b/src/research.cpp @@ -1040,7 +1040,7 @@ void researchResult(UDWORD researchIndex, UBYTE player, bool bDisplay, STRUCTURE if (player == selectedPlayer && bDisplay) { //add console text message - snprintf(consoleMsg, MAX_RESEARCH_MSG_SIZE, _("Research completed: %s"), _(getStatsName(pResearch))); + snprintf(consoleMsg, MAX_RESEARCH_MSG_SIZE, _("Research completed: %s"), getLocalizedStatsName(pResearch)); addConsoleMessage(consoleMsg, LEFT_JUSTIFY, SYSTEM_MESSAGE); } @@ -1554,7 +1554,7 @@ void researchReward(UBYTE losingPlayer, UBYTE rewardPlayer) //name the actual reward CONPRINTF("%s :- %s", _("Research Award"), - getStatsName(&asResearch[rewardID])); + getLocalizedStatsName(&asResearch[rewardID])); } } } diff --git a/src/statsdef.h b/src/statsdef.h index f71f8cccc98..c94545b3d34 100644 --- a/src/statsdef.h +++ b/src/statsdef.h @@ -286,6 +286,7 @@ struct BASE_STATS }; #define getStatsName(_psStats) ((_psStats)->name.isEmpty() ? "" : gettext((_psStats)->name.toUtf8().c_str())) +#define getLocalizedStatsName(_psStats) ((_psStats)->name.isEmpty() ? "" : gettext((_psStats)->name.toUtf8().c_str())) #define getID(_psStats) (_psStats)->id.toUtf8().c_str() #define checkIfZNullStat(_psStats) ((_psStats)->id.toUtf8().find("ZNULL") != std::string::npos) diff --git a/src/structure.cpp b/src/structure.cpp index 5807234b54e..2e79b2c0694 100644 --- a/src/structure.cpp +++ b/src/structure.cpp @@ -5402,7 +5402,7 @@ void printStructureInfo(STRUCTURE *psStructure) { unsigned int assigned_droids = countAssignedDroids(psStructure); console(ngettext("%s - %u Unit assigned - Hitpoints %d/%d", "%s - %u Units assigned - Hitpoints %d/%d", assigned_droids), - getStatsName(psStructure->pStructureType), assigned_droids, psStructure->body, structureBody(psStructure)); + getLocalizedStatsName(psStructure->pStructureType), assigned_droids, psStructure->body, structureBody(psStructure)); if (dbgInputManager.debugMappingsAllowed()) { // TRANSLATORS: A debug output string (user-visible if debug mode is enabled) @@ -5422,11 +5422,11 @@ void printStructureInfo(STRUCTURE *psStructure) { unsigned int assigned_droids = countAssignedDroids(psStructure); console(ngettext("%s - %u Unit assigned - Damage %d/%d", "%s - %u Units assigned - Hitpoints %d/%d", assigned_droids), - getStatsName(psStructure->pStructureType), assigned_droids, psStructure->body, structureBody(psStructure)); + getLocalizedStatsName(psStructure->pStructureType), assigned_droids, psStructure->body, structureBody(psStructure)); } else { - console(_("%s - Hitpoints %d/%d"), getStatsName(psStructure->pStructureType), psStructure->body, structureBody(psStructure)); + console(_("%s - Hitpoints %d/%d"), getLocalizedStatsName(psStructure->pStructureType), psStructure->body, structureBody(psStructure)); } if (dbgInputManager.debugMappingsAllowed()) { @@ -5439,7 +5439,7 @@ void printStructureInfo(STRUCTURE *psStructure) } break; case REF_REPAIR_FACILITY: - console(_("%s - Hitpoints %d/%d"), getStatsName(psStructure->pStructureType), psStructure->body, structureBody(psStructure)); + console(_("%s - Hitpoints %d/%d"), getLocalizedStatsName(psStructure->pStructureType), psStructure->body, structureBody(psStructure)); if (dbgInputManager.debugMappingsAllowed()) { // TRANSLATORS: A debug output string (user-visible if debug mode is enabled) @@ -5448,7 +5448,7 @@ void printStructureInfo(STRUCTURE *psStructure) } break; case REF_RESOURCE_EXTRACTOR: - console(_("%s - Hitpoints %d/%d"), getStatsName(psStructure->pStructureType), psStructure->body, structureBody(psStructure)); + console(_("%s - Hitpoints %d/%d"), getLocalizedStatsName(psStructure->pStructureType), psStructure->body, structureBody(psStructure)); if (dbgInputManager.debugMappingsAllowed() && selectedPlayer < MAX_PLAYERS) { console(_("ID %d - %s"), psStructure->id, (auxTile(map_coord(psStructure->pos.x), map_coord(psStructure->pos.y), selectedPlayer) & AUXBITS_DANGER) ? "danger" : "safe"); @@ -5464,7 +5464,7 @@ void printStructureInfo(STRUCTURE *psStructure) numConnected++; } } - console(_("%s - Connected %u of %u - Hitpoints %d/%d"), getStatsName(psStructure->pStructureType), numConnected, + console(_("%s - Connected %u of %u - Hitpoints %d/%d"), getLocalizedStatsName(psStructure->pStructureType), numConnected, NUM_POWER_MODULES, psStructure->body, structureBody(psStructure)); if (dbgInputManager.debugMappingsAllowed()) { @@ -5475,7 +5475,7 @@ void printStructureInfo(STRUCTURE *psStructure) case REF_CYBORG_FACTORY: case REF_VTOL_FACTORY: case REF_FACTORY: - console(_("%s - Hitpoints %d/%d"), getStatsName(psStructure->pStructureType), psStructure->body, structureBody(psStructure)); + console(_("%s - Hitpoints %d/%d"), getLocalizedStatsName(psStructure->pStructureType), psStructure->body, structureBody(psStructure)); if (dbgInputManager.debugMappingsAllowed()) { // TRANSLATORS: A debug output string (user-visible if debug mode is enabled) @@ -5485,7 +5485,7 @@ void printStructureInfo(STRUCTURE *psStructure) } break; case REF_RESEARCH: - console(_("%s - Hitpoints %d/%d"), getStatsName(psStructure->pStructureType), psStructure->body, structureBody(psStructure)); + console(_("%s - Hitpoints %d/%d"), getLocalizedStatsName(psStructure->pStructureType), psStructure->body, structureBody(psStructure)); if (dbgInputManager.debugMappingsAllowed()) { // TRANSLATORS: A debug output string (user-visible if debug mode is enabled) @@ -5493,7 +5493,7 @@ void printStructureInfo(STRUCTURE *psStructure) } break; case REF_REARM_PAD: - console(_("%s - Hitpoints %d/%d"), getStatsName(psStructure->pStructureType), psStructure->body, structureBody(psStructure)); + console(_("%s - Hitpoints %d/%d"), getLocalizedStatsName(psStructure->pStructureType), psStructure->body, structureBody(psStructure)); if (dbgInputManager.debugMappingsAllowed()) { // TRANSLATORS: A debug output string (user-visible if debug mode is enabled) @@ -5502,7 +5502,7 @@ void printStructureInfo(STRUCTURE *psStructure) } break; default: - console(_("%s - Hitpoints %d/%d"), getStatsName(psStructure->pStructureType), psStructure->body, structureBody(psStructure)); + console(_("%s - Hitpoints %d/%d"), getLocalizedStatsName(psStructure->pStructureType), psStructure->body, structureBody(psStructure)); if (dbgInputManager.debugMappingsAllowed()) { // TRANSLATORS: A debug output string (user-visible if debug mode is enabled) @@ -5625,7 +5625,7 @@ bool electronicDamage(BASE_OBJECT *psTarget, UDWORD damage, UBYTE attackPlayer) if (psStructure->player == selectedPlayer) { console(_("%s - Electronically Damaged"), - getStatsName(psStructure->pStructureType)); + getLocalizedStatsName(psStructure->pStructureType)); } bCompleted = true; //give the structure to the attacking player @@ -5838,7 +5838,7 @@ void factoryReward(UBYTE losingPlayer, UBYTE rewardPlayer) apCompLists[rewardPlayer][COMP_PROPULSION][comp] = AVAILABLE; if (rewardPlayer == selectedPlayer) { - console("%s :- %s", _("Factory Reward - Propulsion"), getStatsName(&asPropulsionStats[comp])); + console("%s :- %s", _("Factory Reward - Propulsion"), getLocalizedStatsName(&asPropulsionStats[comp])); } return; } @@ -5860,7 +5860,7 @@ void factoryReward(UBYTE losingPlayer, UBYTE rewardPlayer) apCompLists[rewardPlayer][COMP_BODY][comp] = AVAILABLE; if (rewardPlayer == selectedPlayer) { - console("%s :- %s", _("Factory Reward - Body"), getStatsName(&asBodyStats[comp])); + console("%s :- %s", _("Factory Reward - Body"), getLocalizedStatsName(&asBodyStats[comp])); } return; } @@ -5882,7 +5882,7 @@ void factoryReward(UBYTE losingPlayer, UBYTE rewardPlayer) apCompLists[rewardPlayer][COMP_WEAPON][comp] = AVAILABLE; if (rewardPlayer == selectedPlayer) { - console("%s :- %s", _("Factory Reward - Weapon"), getStatsName(&asWeaponStats[comp])); + console("%s :- %s", _("Factory Reward - Weapon"), getLocalizedStatsName(&asWeaponStats[comp])); } return; } @@ -5920,7 +5920,7 @@ void repairFacilityReward(UBYTE losingPlayer, UBYTE rewardPlayer) apCompLists[rewardPlayer][COMP_REPAIRUNIT][comp] = AVAILABLE; if (rewardPlayer == selectedPlayer) { - console("%s :- %s", _("Repair Facility Award - Repair"), getStatsName(&asRepairStats[comp])); + console("%s :- %s", _("Repair Facility Award - Repair"), getLocalizedStatsName(&asRepairStats[comp])); } return; } diff --git a/src/wzscriptdebug.cpp b/src/wzscriptdebug.cpp index c332ef39be1..331b84fb364 100644 --- a/src/wzscriptdebug.cpp +++ b/src/wzscriptdebug.cpp @@ -355,6 +355,7 @@ nlohmann::ordered_json componentToString(const COMPONENT_STATS *psStats, int pla nlohmann::ordered_json key = nlohmann::ordered_json::object(); key["Name"] = getStatsName(psStats); + key["NameLocalized"] = getLocalizedStatsName(psStats); key["^Id"] = psStats->id.toUtf8(); key["^Power"] = psStats->buildPower; key["^Build Points"] = psStats->buildPoints;