Skip to content

Commit

Permalink
Add separate getLocalizedStatsName() macro
Browse files Browse the repository at this point in the history
  • Loading branch information
past-due committed Nov 4, 2023
1 parent 9b44fe5 commit fd19430
Show file tree
Hide file tree
Showing 15 changed files with 43 additions and 41 deletions.
20 changes: 10 additions & 10 deletions src/design.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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, " ");
}

Expand All @@ -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, " ");
}

Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/droid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions src/hci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/hci/manufacture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/hci/objects_stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/hci/research.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/intdisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ class IntStatsButton : public IntFancyButton
void setStatsAndTip(BASE_STATS *stats)
{
setStats(stats);
setTip(getStatsName(stats));
setTip(getLocalizedStatsName(stats));
}

protected:
Expand Down
2 changes: 1 addition & 1 deletion src/keybind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/multigifts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/multilimit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/oprint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<void *>(psStats->pIMD));
}
Expand Down
4 changes: 2 additions & 2 deletions src/research.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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]));
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/statsdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
30 changes: 15 additions & 15 deletions src/structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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())
{
Expand All @@ -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)
Expand All @@ -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");
Expand All @@ -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())
{
Expand All @@ -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)
Expand All @@ -5485,15 +5485,15 @@ 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)
console(_("ID %u - Research Points: %u"), psStructure->id, getBuildingResearchPoints(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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions src/wzscriptdebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit fd19430

Please sign in to comment.