From e96b87177988f738be09452c603095a9f8e08ffb Mon Sep 17 00:00:00 2001 From: Geoffray Levasseur Date: Tue, 17 Nov 2026 11:42:28 +0100 Subject: [PATCH] removed old temporary phrase and formatPrase implementations --- game/localplayer/Battle.cpp | 21 +--- game/localplayer/CityScreen.cpp | 163 ++++++++++++-------------------- game/localplayer/CityType.cpp | 23 +---- game/localplayer/Diagram.cpp | 45 +++------ game/localplayer/Diplomacy.cpp | 57 +++-------- game/localplayer/Draft.cpp | 44 +++------ game/localplayer/Enhance.cpp | 21 +--- game/localplayer/Help.cpp | 23 +---- game/localplayer/NatStat.cpp | 95 +++++-------------- game/localplayer/Nego.cpp | 112 ++++++---------------- game/localplayer/Rates.cpp | 31 ++---- game/localplayer/Select.cpp | 100 ++++++-------------- game/localplayer/UnitStat.cpp | 69 ++++---------- game/localplayer/Wonders.cpp | 25 +---- 14 files changed, 231 insertions(+), 598 deletions(-) diff --git a/game/localplayer/Battle.cpp b/game/localplayer/Battle.cpp index 9f2c89e..3d7c66c 100644 --- a/game/localplayer/Battle.cpp +++ b/game/localplayer/Battle.cpp @@ -32,6 +32,7 @@ #include "Cevo/CevoScreenTools.h" #include "Cevo/CevoTexture.h" #include "ClientTools.h" +#include "Global.h" #include "Term.h" #include @@ -51,26 +52,14 @@ constexpr QRgb DamageColor = 0x0000E0; constexpr QRgb FanaticColor = 0x800080; constexpr QRgb FirstStrikeColor = 0xA0A0A0; -// TODO: needs Phrases[] (StringTables.pas not ported) - plain English literals. -QString phrase(const QString &key) -{ - static const QHash table = { - {QStringLiteral("BTN_YES"), QStringLiteral("Yes")}, - {QStringLiteral("BTN_NO"), QStringLiteral("No")}, - {QStringLiteral("TITLE_SUICIDE"), QStringLiteral("Hopeless attack")}, - {QStringLiteral("SUICIDE"), QStringLiteral("This attack has no chance of success.\\Attack anyway?")}, - }; - const auto it = table.constFind(key); - return it != table.constEnd() ? *it : key; -} } // namespace BattleDlg::BattleDlg(QWidget *parent) : DrawDlg(parent), ui(new Ui::BattleDlg) { ui->setupUi(this); isoMap = std::make_unique(); - ui->okBtn->setCaption(phrase(QStringLiteral("BTN_YES"))); - ui->cancelBtn->setCaption(phrase(QStringLiteral("BTN_NO"))); + ui->okBtn->setCaption(phrases.lookup(QStringLiteral("BTN_YES"))); + ui->cancelBtn->setCaption(phrases.lookup(QStringLiteral("BTN_NO"))); initButtons(); ui->okBtn->onClick = [this] { @@ -226,10 +215,10 @@ void BattleDlg::paintEvent(QPaintEvent *) int ym; if (isSuicideQuery) { canvas.font().assign(UniFont[static_cast(FontType::Caption)]); - QString s = phrase(QStringLiteral("TITLE_SUICIDE")); + QString s = phrases.lookup(QStringLiteral("TITLE_SUICIDE")); risedTextOut(canvas, (width() - biColorTextWidth(canvas, s)) / 2, 7 + Border, s); canvas.font().assign(UniFont[static_cast(FontType::Normal)]); - s = phrase(QStringLiteral("SUICIDE")); + s = phrases.lookup(QStringLiteral("SUICIDE")); const int p = s.indexOf(QLatin1Char('\\')); if (p < 0) { risedTextOut(canvas, (width() - biColorTextWidth(canvas, s)) / 2, 205, s); diff --git a/game/localplayer/CityScreen.cpp b/game/localplayer/CityScreen.cpp index d83f9b4..345418a 100644 --- a/game/localplayer/CityScreen.cpp +++ b/game/localplayer/CityScreen.cpp @@ -97,55 +97,6 @@ constexpr std::array ImpPosition = { -1, 9, -1, -1, -1, -1, }; -// Phrases/Phrases2 (StringTables.pas) aren't ported; disclosed -// plain-English placeholders for this dialog's own flat-key text. -QString phrase(const QString &key) -{ - static const QHash table = { - {QStringLiteral("BTN_OK"), QStringLiteral("OK")}, - {QStringLiteral("BTN_BUY"), QStringLiteral("Buy")}, - {QStringLiteral("SUPUNITS"), QStringLiteral("Supported units")}, - {QStringLiteral("LUX"), QStringLiteral("Luxury")}, - {QStringLiteral("UNREST"), QStringLiteral("Unrest")}, - {QStringLiteral("HAPPINESSDEMAND"), QStringLiteral("Demand")}, - {QStringLiteral("HAPPINESSPLUS"), QStringLiteral("Content")}, - {QStringLiteral("HAPPINESS"), QStringLiteral("Happiness")}, - {QStringLiteral("CONTROL"), QStringLiteral("Martial law")}, - {QStringLiteral("FAITH"), QStringLiteral("Faith")}, - {QStringLiteral("LACK"), QStringLiteral("Lack")}, - {QStringLiteral("FOOD"), QStringLiteral("Food")}, - {QStringLiteral("DEMAND"), QStringLiteral("Demand")}, - {QStringLiteral("SUPPORT"), QStringLiteral("Support")}, - {QStringLiteral("PROFIT"), QStringLiteral("Profit")}, - {QStringLiteral("SURPLUS"), QStringLiteral("Surplus")}, - {QStringLiteral("STORAGE"), QStringLiteral("Storage")}, - {QStringLiteral("MATERIAL"), QStringLiteral("Material")}, - {QStringLiteral("PROD"), QStringLiteral("Production")}, - {QStringLiteral("POLL"), QStringLiteral("Pollution")}, - {QStringLiteral("TRADE"), QStringLiteral("Trade")}, - {QStringLiteral("CORR"), QStringLiteral("Corruption")}, - {QStringLiteral("TAX"), QStringLiteral("Tax")}, - {QStringLiteral("SCIENCE"), QStringLiteral("Science")}, - {QStringLiteral("READY"), QStringLiteral("Already completed.")}, - {QStringLiteral("NOMONEY"), QStringLiteral("Not enough money (%1 needed, %2 available).")}, - {QStringLiteral("BUY"), QStringLiteral("Buy for %1 gold?")}, - {QStringLiteral("NOCHANGEINANARCHY"), QStringLiteral("Cannot change city management in anarchy.")}, - {QStringLiteral("NOSELLAGAIN"), QStringLiteral("Cannot sell %1 again this turn.")}, - {QStringLiteral("OUTOFCONTROL"), QStringLiteral("%1 is out of our control.")}, - {QStringLiteral("SELL"), QStringLiteral("Sell %1?")}, - {QStringLiteral("DISPOSE"), QStringLiteral("Dispose of %1?")}, - {QStringLiteral("SPDESTRUCTQUERY"), QStringLiteral("This will destroy the space ship parts built so far.")}, - {QStringLiteral("CITYMANAGEOFF"), QStringLiteral("Turn off city management?")}, - {QStringLiteral("DOUBLESTATEIMP"), - QStringLiteral("%1 is already being built in %2.")}, - {QStringLiteral("LOSEMAT"), QStringLiteral("This will lose %1/%2 production material.")}, - {QStringLiteral("LOSEMAT3"), QStringLiteral("This will lose production material.")}, - {QStringLiteral("EMIGRATE"), QStringLiteral("City is too small; found a new city instead?")}, - }; - const auto it = table.find(key); - return it != table.end() ? *it : key; -} - QString impName(int iix) { return phrases.lookup(QStringLiteral("IMPROVEMENTS"), iix); @@ -185,9 +136,9 @@ CityDlg::CityDlg(QWidget *parent) : BufferedDrawDlg(parent), ui(new Ui::CityDlg) agePrepared = -2; optimizeCixTileChange = -1; - ui->closeBtn->setCaption(phrase(QStringLiteral("BTN_OK"))); - ui->buyBtn->setToolTip(phrase(QStringLiteral("BTN_BUY"))); - ui->supportArea->setToolTip(phrase(QStringLiteral("SUPUNITS"))); + ui->closeBtn->setCaption(phrases.lookup(QStringLiteral("BTN_OK"))); + ui->buyBtn->setToolTip(phrases.lookup(QStringLiteral("BTN_BUY"))); + ui->supportArea->setToolTip(phrases.lookup(QStringLiteral("SUPUNITS"))); back.setTransparent(false); back.setSize(width(), height()); @@ -582,7 +533,7 @@ void CityDlg::offscreenPaint() if (!isCityAlive) { makeRed(offscreen, 18, 280, 298, 40); - s = cGov == gAnarchy ? governmentName(gAnarchy) : phrase(QStringLiteral("CITYEVENT_CAPTURED")); + s = cGov == gAnarchy ? governmentName(gAnarchy) : phrases.lookup(QStringLiteral("CITYEVENTS"), 14); risedTextOut(canvas, 167 - biColorTextWidth(canvas, s) / 2, ymOpt - 9, s); } else if (allowChange) { const int optiType = c.Status >> 4 & 0x0F; @@ -688,47 +639,47 @@ void CityDlg::offscreenPaint() // happiness section if (isCityAlive) { if (cGov == gFundamentalism) { - countBar(offscreen, xHapp, yHapp + dyBar, wBar, 17, phrase(QStringLiteral("FAITH")), + countBar(offscreen, xHapp, yHapp + dyBar, wBar, 17, phrases.lookup(QStringLiteral("FAITH")), report.CollectedControl, *MainTexture); } else { - countBar(offscreen, xHapp, yHapp + dyBar, wBar, 17, phrase(QStringLiteral("HAPPINESS")), report.Morale, + countBar(offscreen, xHapp, yHapp + dyBar, wBar, 17, phrases.lookup(QStringLiteral("HAPPINESS")), report.Morale, *MainTexture); - countBar(offscreen, xHapp, yHapp + 2 * dyBar, wBar, 16, phrase(QStringLiteral("CONTROL")), + countBar(offscreen, xHapp, yHapp + 2 * dyBar, wBar, 16, phrases.lookup(QStringLiteral("CONTROL")), report.CollectedControl, *MainTexture); } - countBar(offscreen, xHapp, yHapp, wBar, 8, phrase(QStringLiteral("LUX")), report.Luxury, *MainTexture); - countBar(offscreen, xHapp + dxBar, yHapp, wBar, 19, phrase(QStringLiteral("UNREST")), 2 * report.Deployed, + countBar(offscreen, xHapp, yHapp, wBar, 8, phrases.lookup(QStringLiteral("LUX")), report.Luxury, *MainTexture); + countBar(offscreen, xHapp + dxBar, yHapp, wBar, 19, phrases.lookup(QStringLiteral("UNREST")), 2 * report.Deployed, *MainTexture); - countBar(offscreen, xHapp + dxBar, yHapp + dyBar, wBar, 17, phrase(QStringLiteral("HAPPINESSDEMAND")), + countBar(offscreen, xHapp + dxBar, yHapp + dyBar, wBar, 17, phrases.lookup(QStringLiteral("HAPPINESSDEMAND")), c.Size, *MainTexture); if (report.HappinessBalance >= 0) { - countBar(offscreen, xHapp + dxBar, yHapp + 2 * dyBar, wBar, 17, phrase(QStringLiteral("HAPPINESSPLUS")), + countBar(offscreen, xHapp + dxBar, yHapp + 2 * dyBar, wBar, 17, phrases.lookup(QStringLiteral("HAPPINESSPLUS")), report.HappinessBalance, *MainTexture); } else { makeRed(offscreen, xHapp + dxBar - 6, yHapp + 2 * dyBar, wBar + 10, 38); - countBar(offscreen, xHapp + dxBar, yHapp + 2 * dyBar, wBar, 18, phrase(QStringLiteral("LACK")), + countBar(offscreen, xHapp + dxBar, yHapp + 2 * dyBar, wBar, 18, phrases.lookup(QStringLiteral("LACK")), -report.HappinessBalance, redTex); } } // food section if (isCityAlive) { - countBar(offscreen, xFood, yFood + dyBar / 2, wBar, 0, phrase(QStringLiteral("FOOD")), report.CollectedFood, + countBar(offscreen, xFood, yFood + dyBar / 2, wBar, 0, phrases.lookup(QStringLiteral("FOOD")), report.CollectedFood, *MainTexture); - countBar(offscreen, xFood + dxBar, yFood + dyBar, wBar, 0, phrase(QStringLiteral("DEMAND")), 2 * c.Size, + countBar(offscreen, xFood + dxBar, yFood + dyBar, wBar, 0, phrases.lookup(QStringLiteral("DEMAND")), 2 * c.Size, *MainTexture); - countBar(offscreen, xFood + dxBar, yFood, wBar, 0, phrase(QStringLiteral("SUPPORT")), report.FoodSupport, + countBar(offscreen, xFood + dxBar, yFood, wBar, 0, phrases.lookup(QStringLiteral("SUPPORT")), report.FoodSupport, *MainTexture); if (report.FoodSurplus >= 0) { if (cGov == gFuture || (c.Size >= NeedAqueductSize && report.FoodSurplus < 2)) - countBar(offscreen, xFood + dxBar, yFood + 2 * dyBar, wBar, 6, phrase(QStringLiteral("PROFIT")), + countBar(offscreen, xFood + dxBar, yFood + 2 * dyBar, wBar, 6, phrases.lookup(QStringLiteral("PROFIT")), report.FoodSurplus, *MainTexture); else - countBar(offscreen, xFood + dxBar, yFood + 2 * dyBar, wBar, 0, phrase(QStringLiteral("SURPLUS")), + countBar(offscreen, xFood + dxBar, yFood + 2 * dyBar, wBar, 0, phrases.lookup(QStringLiteral("SURPLUS")), report.FoodSurplus, *MainTexture); } else { makeRed(offscreen, xFood + dxBar - 6, yFood + 2 * dyBar, wBar + 10, 38); - countBar(offscreen, xFood + dxBar, yFood + 2 * dyBar, wBar, 1, phrase(QStringLiteral("LACK")), + countBar(offscreen, xFood + dxBar, yFood + 2 * dyBar, wBar, 1, phrases.lookup(QStringLiteral("LACK")), -report.FoodSurplus, redTex); } } @@ -739,24 +690,24 @@ void CityDlg::offscreenPaint() report.Storage, 1, canGrow); loweredTextOut(canvas, -1, *MainTexture, xFood + 3 - 5, yFood + 102 - 20, QStringLiteral("%1/%2").arg(trueFood).arg(report.Storage)); - loweredTextOut(canvas, -1, *MainTexture, xFood - 2, yFood + 66, phrase(QStringLiteral("STORAGE"))); + loweredTextOut(canvas, -1, *MainTexture, xFood - 2, yFood + 66, phrases.lookup(QStringLiteral("STORAGE"))); // production section if (isCityAlive) { - countBar(offscreen, xProd, yProd, wBar, 2, phrase(QStringLiteral("MATERIAL")), report.CollectedMaterial, + countBar(offscreen, xProd, yProd, wBar, 2, phrases.lookup(QStringLiteral("MATERIAL")), report.CollectedMaterial, *MainTexture); - countBar(offscreen, xProd + dxBar, yProd, wBar, 2, phrase(QStringLiteral("SUPPORT")), report.MaterialSupport, + countBar(offscreen, xProd + dxBar, yProd, wBar, 2, phrases.lookup(QStringLiteral("SUPPORT")), report.MaterialSupport, *MainTexture); if (report.Production >= 0) { if ((c.Project & (cpImp + cpIndex)) == cpImp + imTrGoods) - countBar(offscreen, xProd + dxBar, yProd + dyBar + 16, wBar, 6, phrase(QStringLiteral("PROFIT")), + countBar(offscreen, xProd + dxBar, yProd + dyBar + 16, wBar, 6, phrases.lookup(QStringLiteral("PROFIT")), report.Production, *MainTexture); else - countBar(offscreen, xProd + dxBar, yProd + dyBar + 16, wBar, 2, phrase(QStringLiteral("PROD")), + countBar(offscreen, xProd + dxBar, yProd + dyBar + 16, wBar, 2, phrases.lookup(QStringLiteral("PROD")), report.Production, *MainTexture); } else { makeRed(offscreen, xProd + dxBar - 6, yProd + dyBar + 17, wBar + 10, 38); - countBar(offscreen, xProd + dxBar, yProd + dyBar + 16, wBar, 3, phrase(QStringLiteral("LACK")), + countBar(offscreen, xProd + dxBar, yProd + dyBar + 16, wBar, 3, phrases.lookup(QStringLiteral("LACK")), -report.Production, redTex); } } @@ -779,17 +730,17 @@ void CityDlg::offscreenPaint() // pollution section if (isCityAlive && report.AddPollution > 0) { fillBar(xPoll + 3, yPoll + 20, truePoll, report.AddPollution, MaxPollution, 3, true); - risedTextOut(canvas, xPoll + 3 - 5, yPoll + 20 - 20, phrase(QStringLiteral("POLL"))); + risedTextOut(canvas, xPoll + 3 - 5, yPoll + 20 - 20, phrases.lookup(QStringLiteral("POLL"))); } // trade section if (isCityAlive && report.CollectedTrade > 0) { - countBar(offscreen, xTrade, yTrade + dyBar / 2, wBar, 4, phrase(QStringLiteral("TRADE")), + countBar(offscreen, xTrade, yTrade + dyBar / 2, wBar, 4, phrases.lookup(QStringLiteral("TRADE")), report.CollectedTrade, *MainTexture); - countBar(offscreen, xTrade + dxBar, yTrade + 2 * dyBar, wBar, 5, phrase(QStringLiteral("CORR")), + countBar(offscreen, xTrade + dxBar, yTrade + 2 * dyBar, wBar, 5, phrases.lookup(QStringLiteral("CORR")), report.Corruption, *MainTexture); - countBar(offscreen, xTrade + dxBar, yTrade, wBar, 6, phrase(QStringLiteral("TAX")), report.Tax, *MainTexture); - countBar(offscreen, xTrade + dxBar, yTrade + dyBar, wBar, 12, phrase(QStringLiteral("SCIENCE")), + countBar(offscreen, xTrade + dxBar, yTrade, wBar, 6, phrases.lookup(QStringLiteral("TAX")), report.Tax, *MainTexture); + countBar(offscreen, xTrade + dxBar, yTrade + dyBar, wBar, 12, phrases.lookup(QStringLiteral("SCIENCE")), report.Science, *MainTexture); } @@ -883,7 +834,7 @@ void CityDlg::offscreenPaint() ui->imp4Area->setToolTip(imix[4] >= 0 ? impName(imix[4]) : QString()); ui->imp5Area->setToolTip(imix[5] >= 0 ? impName(imix[5]) : QString()); } else { // smSupportedUnits - loweredTextOut(canvas, -1, *MainTexture, xZoomMap + 6, yZoomMap + 2, phrase(QStringLiteral("SUPUNITS"))); + loweredTextOut(canvas, -1, *MainTexture, xZoomMap + 6, yZoomMap + 2, phrases.lookup(QStringLiteral("SUPUNITS"))); int freeSupp = c.Size * SupportFree[cGov] >> 1; int cnt = 0; for (int i = 0; i < ClientTools::myRO->nUn; ++i) @@ -1107,14 +1058,15 @@ void CityDlg::buyClick() else cost *= 4; if (cost <= 0 && report.HappinessBalance >= 0) { - dlg->messageText = phrase(QStringLiteral("READY")); + dlg->messageText = phrases.lookup(QStringLiteral("READY")); dlg->kind = MessageKind::Ok; } else if (cost > ClientTools::myRO->Money) { dlg->openSound = QStringLiteral("MSG_DEFAULT"); - dlg->messageText = phrase(QStringLiteral("NOMONEY")).arg(cost).arg(ClientTools::myRO->Money); + dlg->messageText = formatPhrase(QStringLiteral("NOMONEY"), + { QString::number(cost), QString::number(ClientTools::myRO->Money) }); dlg->kind = MessageKind::Ok; } else { - dlg->messageText = phrase(QStringLiteral("BUY")).arg(cost); + dlg->messageText = formatPhrase(QStringLiteral("BUY"), { QString::number(cost) }); dlg->kind = MessageKind::YesNo; } const MessageKind queriedKind = dlg->kind; @@ -1165,9 +1117,9 @@ void CityDlg::chooseProject() int cix1 = ClientTools::myRO->nCity - 1; while (cix1 >= 0 && ClientTools::myCity[cix1].Built[newProject & cpIndex] == 0) --cix1; - dlg->messageText = phrase(QStringLiteral("DOUBLESTATEIMP")) - .arg(impName(newProject & cpIndex)) - .arg(Tribes::cityName(ClientTools::myCity[cix1].ID)); + dlg->messageText = formatPhrase(QStringLiteral("DOUBLESTATEIMP"), + { impName(newProject & cpIndex), + Tribes::cityName(ClientTools::myCity[cix1].ID) }); dlg->openSound = QStringLiteral("MSG_DEFAULT"); dlg->kind = MessageKind::OkCancel; dlg->iconKind = MessgEx::MessageIconKind::Imp; @@ -1185,14 +1137,15 @@ void CityDlg::chooseProject() if ((newProject & (cpImp | cpIndex)) != (ClientTools::myCity[cix].Project0 & (cpImp | cpIndex))) { if (pt1 == ProjectKind::TrGoods || pt1 == ProjectKind::Ship || (pt1 != pt0 && pt0 != ProjectKind::Caravan)) { - queryOk = MessgEx::simpleQuery(MessageKind::OkCancel, - phrase(QStringLiteral("LOSEMAT")) - .arg(ClientTools::myCity[cix].Prod0) - .arg(ClientTools::myCity[cix].Prod0), - QStringLiteral("MSG_DEFAULT")) == Dpi::ModalResult::Ok; + queryOk = MessgEx::simpleQuery( + MessageKind::OkCancel, + formatPhrase(QStringLiteral("LOSEMAT"), + { QString::number(ClientTools::myCity[cix].Prod0), + QString::number(ClientTools::myCity[cix].Prod0) }), + QStringLiteral("MSG_DEFAULT")) == Dpi::ModalResult::Ok; } else if ((ClientTools::myCity[cix].Project & (cpImp | cpIndex)) == (ClientTools::myCity[cix].Project0 & (cpImp | cpIndex))) { - queryOk = MessgEx::simpleQuery(MessageKind::OkCancel, phrase(QStringLiteral("LOSEMAT3")), + queryOk = MessgEx::simpleQuery(MessageKind::OkCancel, phrases.lookup(QStringLiteral("LOSEMAT3")), QStringLiteral("MSG_DEFAULT")) == Dpi::ModalResult::Ok; } } @@ -1208,7 +1161,7 @@ void CityDlg::chooseProject() (ClientTools::myCity[cix].Size < 3 && (ClientTools::myModel[newProject & cpIndex].Kind == mkSlaves || (newProject & cpConscripts) != 0)))) { - if (MessgEx::simpleQuery(MessageKind::YesNo, phrase(QStringLiteral("EMIGRATE")), + if (MessgEx::simpleQuery(MessageKind::YesNo, phrases.lookup(QStringLiteral("EMIGRATE")), QStringLiteral("MSG_DEFAULT")) != Dpi::ModalResult::Ok) newProject |= cpDisbandCity; } @@ -1266,7 +1219,7 @@ void CityDlg::mousePressEvent(QMouseEvent *event) if (IsoEngine::clientMode < scContact && x >= xView && y >= yView && x < xView + 73 && y < yView + 50) { if (cGov == gAnarchy) { if (auto *dlg = Term::mainScreenMessgExDlg()) { - dlg->messageText = phrase(QStringLiteral("NOCHANGEINANARCHY")); + dlg->messageText = phrases.lookup(QStringLiteral("NOCHANGEINANARCHY")); dlg->kind = MessageKind::Ok; dlg->showModal(); } @@ -1296,19 +1249,19 @@ void CityDlg::mousePressEvent(QMouseEvent *event) if (iix == imPalace || Imp[iix].Kind == ikWonder) { dlg->messageText = impName(iix); if (iix == woOracle) - dlg->messageText += QStringLiteral("\n") + - phrase(QStringLiteral("ORACLEINCOME")) - .arg(ClientTools::myRO->OracleIncome); + dlg->messageText += + QStringLiteral("\n") + + formatPhrase(QStringLiteral("ORACLEINCOME"), + { QString::number(ClientTools::myRO->OracleIncome) }); dlg->kind = MessageKind::Ok; dlg->showModal(); } else { const int sellResult = ClientTools::server(sSellCityImprovement - sExecute, ClientTools::me, cix, &iix); if (sellResult < rExecuted) { - dlg->messageText = - phrase(sellResult == eOnlyOnce ? QStringLiteral("NOSELLAGAIN") - : QStringLiteral("OUTOFCONTROL")) - .arg(impName(iix)); + dlg->messageText = formatPhrase(sellResult == eOnlyOnce ? QStringLiteral("NOSELLAGAIN") + : QStringLiteral("OUTOFCONTROL"), + { impName(iix) }); dlg->kind = MessageKind::Ok; dlg->showModal(); } else { @@ -1317,24 +1270,24 @@ void CityDlg::mousePressEvent(QMouseEvent *event) if (ClientTools::server(sRebuildCityImprovement - sExecute, ClientTools::me, cix, &iix) < rExecuted) { rebuild = false; - dlg->messageText = phrase(QStringLiteral("SELL")).arg(impName(iix)); + dlg->messageText = formatPhrase(QStringLiteral("SELL"), { impName(iix) }); if (iix == imSpacePort) { const auto &ship = ClientTools::myRO->Ship[ClientTools::me]; if (ship.Parts[0] + ship.Parts[1] + ship.Parts[2] > 0) dlg->messageText += - QStringLiteral(" ") + phrase(QStringLiteral("SPDESTRUCTQUERY")); + QStringLiteral(" ") + phrases.lookup(QStringLiteral("SPDESTRUCTQUERY")); } dlg->kind = MessageKind::YesNo; if (dlg->showModal() != Dpi::ModalResult::Ok) newIix = -1; } else { rebuild = true; - dlg->messageText = phrase(QStringLiteral("DISPOSE")).arg(impName(iix)); + dlg->messageText = formatPhrase(QStringLiteral("DISPOSE"), { impName(iix) }); if (iix == imSpacePort) { const auto &ship = ClientTools::myRO->Ship[ClientTools::me]; if (ship.Parts[0] + ship.Parts[1] + ship.Parts[2] > 0) dlg->messageText += - QStringLiteral(" ") + phrase(QStringLiteral("SPDESTRUCTQUERY")); + QStringLiteral(" ") + phrases.lookup(QStringLiteral("SPDESTRUCTQUERY")); } dlg->kind = MessageKind::YesNo; if (dlg->showModal() != Dpi::ModalResult::Ok) @@ -1397,7 +1350,7 @@ void CityDlg::mousePressEvent(QMouseEvent *event) Q_ASSERT(!Term::supervising); if ((c.Status & Term::csResourceWeightsMask) != 0) { if (auto *dlg = Term::mainScreenMessgExDlg()) { - dlg->messageText = phrase(QStringLiteral("CITYMANAGEOFF")); + dlg->messageText = phrases.lookup(QStringLiteral("CITYMANAGEOFF")); dlg->openSound = QStringLiteral("MSG_DEFAULT"); dlg->kind = MessageKind::OkCancel; dlg->iconKind = MessgEx::MessageIconKind::FullControl; diff --git a/game/localplayer/CityType.cpp b/game/localplayer/CityType.cpp index 5303f4e..07c3bcb 100644 --- a/game/localplayer/CityType.cpp +++ b/game/localplayer/CityType.cpp @@ -35,7 +35,6 @@ #include "Global.h" #include "Term.h" -#include #include namespace Cevo { @@ -43,20 +42,6 @@ namespace CityType { namespace { -// Phrases (StringTables.pas) aren't ported; disclosed plain-English -// placeholders for this dialog's own text. -QString phrase(const QString &key) -{ - static const QHash table = { - {QStringLiteral("TITLE_CITYTYPES"), QStringLiteral("City Types")}, - {QStringLiteral("BTN_DELETE"), QStringLiteral("Delete")}, - {QStringLiteral("BUILDORDER"), QStringLiteral("Build order")}, - {QStringLiteral("BUILDREST"), QStringLiteral("Remaining improvements")}, - }; - const auto it = table.constFind(key); - return it != table.constEnd() ? it.value() : key; -} - QString phraseCityType(int ctype) { return phrases.lookup(QStringLiteral("CITYTYPE"), ctype); @@ -91,8 +76,8 @@ CityTypeDlg::CityTypeDlg(QWidget *parent) : FramedDlg(parent), ui(new Ui::CityTy captionRight = ui->closeBtn->x(); initButtons(); helpContext = QStringLiteral("MACRO"); - setWindowTitle(phrase(QStringLiteral("TITLE_CITYTYPES"))); - ui->deleteBtn->setToolTip(phrase(QStringLiteral("BTN_DELETE"))); + setWindowTitle(phrases.lookup(QStringLiteral("TITLE_CITYTYPES"))); + ui->deleteBtn->setToolTip(phrases.lookup(QStringLiteral("BTN_DELETE"))); ui->closeBtn->onClick = [this] { close(); }; ui->deleteBtn->onClick = [this] { @@ -194,9 +179,9 @@ void CityTypeDlg::offscreenPaint() bitBltBitmap(offscreen, xSwitch + 2 + i * 42, ySwitch + 2, Term::xSizeSmall, Term::ySizeSmall, *Term::smallImp, (i + 3) * Term::xSizeSmall, 0); } - risedTextOut(canvas, 8, yList + 32 * nListRow + 2, phrase(QStringLiteral("BUILDORDER"))); + risedTextOut(canvas, 8, yList + 32 * nListRow + 2, phrases.lookup(QStringLiteral("BUILDORDER"))); risedTextOut(canvas, 8, ySwitch + 26, phraseCityType(ctype)); - const QString buildRest = phrase(QStringLiteral("BUILDREST")); + const QString buildRest = phrases.lookup(QStringLiteral("BUILDREST")); risedTextOut(canvas, (innerWidth - biColorTextWidth(canvas, buildRest)) / 2, yList + 72 + 32 * nListRow, buildRest); diff --git a/game/localplayer/Diagram.cpp b/game/localplayer/Diagram.cpp index 704b6be..a093b99 100644 --- a/game/localplayer/Diagram.cpp +++ b/game/localplayer/Diagram.cpp @@ -33,9 +33,9 @@ #include "Cevo/CevoTexture.h" #include "Cevo/Database.h" #include "ClientTools.h" +#include "Global.h" #include "Tribes.h" -#include #include #include @@ -46,33 +46,9 @@ namespace Diagram { namespace { -// Phrases/Phrases2 (StringTables.pas) aren't ported; disclosed -// plain-English placeholders for this dialog's own text. -QString phrase(const QString &key) -{ - static const QHash table = { - {QStringLiteral("BTN_PAGE"), QStringLiteral("Next chart")}, - {QStringLiteral("BTN_SELECT"), QStringLiteral("Select nation")}, - {QStringLiteral("TITLE_DIAGRAMS"), QStringLiteral("Charts")}, - {QStringLiteral("TITLE_SHIPS"), QStringLiteral("Colonization Ships")}, - {QStringLiteral("SHARE"), QStringLiteral("%1/%2")}, - {QStringLiteral("SHIPHAB"), QStringLiteral("Habitation")}, - {QStringLiteral("SHIPPOW"), QStringLiteral("Power")}, - {QStringLiteral("SHIPCOMP"), QStringLiteral("Components")}, - }; - const auto it = table.constFind(key); - return it != table.constEnd() ? it.value() : key; -} - QString phraseDiagram(int mode) { - static const QHash table = { - {stPop, QStringLiteral("Population")}, {stTerritory, QStringLiteral("Territory")}, - {stMil, QStringLiteral("Military")}, {stScience, QStringLiteral("Science")}, - {stExplore, QStringLiteral("Explored")}, {stWork, QStringLiteral("Workers")}, - }; - const auto it = table.constFind(mode); - return it != table.constEnd() ? it.value() : QString(); + return phrases.lookup(QStringLiteral("DIAGRAM"), mode); } constexpr int Border = 24; @@ -90,7 +66,8 @@ void shareBar(Dpi::Canvas &canvas, int x, int y, const QString &cap, int val0, i { loweredTextOut(canvas, -1, *MainTexture, x - 2, y, cap); dLine(canvas, x - 2, x + 169, y + 16, MainTexture->colorTextShade, MainTexture->colorTextLight); - const QString s = val0 > 0 ? phrase(QStringLiteral("SHARE")).arg(val0).arg(val1) : QStringLiteral("0"); + const QString s = val0 > 0 ? formatPhrase(QStringLiteral("SHARE"), { QString::number(val0), QString::number(val1) }) + : QStringLiteral("0"); risedTextOut(canvas, x + 170 - biColorTextWidth(canvas, s), y, s); } @@ -261,11 +238,11 @@ void DiaDlg::offscreenPaint() paintColonyShip(canvas, player, 8, innerWidth - 16, yArea); - shareBar(canvas, innerWidth / 2 - 85, innerHeight - 62, phrase(QStringLiteral("SHIPHAB")), + shareBar(canvas, innerWidth / 2 - 85, innerHeight - 62, phrases.lookup(QStringLiteral("SHIPHAB")), ClientTools::myRO->Ship[player].Parts[spHab], 2); - shareBar(canvas, innerWidth / 2 - 85, innerHeight - 43, phrase(QStringLiteral("SHIPPOW")), + shareBar(canvas, innerWidth / 2 - 85, innerHeight - 43, phrases.lookup(QStringLiteral("SHIPPOW")), ClientTools::myRO->Ship[player].Parts[spPow], 4); - shareBar(canvas, innerWidth / 2 - 85, innerHeight - 24, phrase(QStringLiteral("SHIPCOMP")), + shareBar(canvas, innerWidth / 2 - 85, innerHeight - 24, phrases.lookup(QStringLiteral("SHIPCOMP")), ClientTools::myRO->Ship[player].Parts[spComp], 6); } @@ -308,8 +285,8 @@ void DiaDlg::showNewContentCharts(WindowMode newMode) kind = DiagramKind::Chart; mode = stPop; ui->toggleBtn->setButtonIndex(15); - ui->toggleBtn->setToolTip(phrase(QStringLiteral("BTN_PAGE"))); - setWindowTitle(phrase(QStringLiteral("TITLE_DIAGRAMS"))); + ui->toggleBtn->setToolTip(phrases.lookup(QStringLiteral("BTN_PAGE"))); + setWindowTitle(phrases.lookup(QStringLiteral("TITLE_DIAGRAMS"))); showNewContent(newMode); } @@ -326,8 +303,8 @@ void DiaDlg::showNewContentShip(WindowMode newMode, int p) player = p; } ui->toggleBtn->setButtonIndex(28); - ui->toggleBtn->setToolTip(phrase(QStringLiteral("BTN_SELECT"))); - setWindowTitle(phrase(QStringLiteral("TITLE_SHIPS"))); + ui->toggleBtn->setToolTip(phrases.lookup(QStringLiteral("BTN_SELECT"))); + setWindowTitle(phrases.lookup(QStringLiteral("TITLE_SHIPS"))); showNewContent(newMode); } diff --git a/game/localplayer/Diplomacy.cpp b/game/localplayer/Diplomacy.cpp index 3c2b941..e4214e6 100644 --- a/game/localplayer/Diplomacy.cpp +++ b/game/localplayer/Diplomacy.cpp @@ -31,38 +31,11 @@ #include "Global.h" #include "Tribes.h" -#include - namespace Cevo { namespace Diplomacy { namespace { -// Phrases/Phrases2 (StringTables.pas) aren't ported; disclosed -// plain-English placeholders for the (non tribe-specific) keys this file -// looks up directly via Phrases[...]. -QString phrase(const QString &key) -{ - static const QHash table = { - {QStringLiteral("FRCANCELTREATY_PEACE"), QStringLiteral("I hereby cancel our peace treaty.")}, - {QStringLiteral("FRCANCELTREATY_FRIENDLY"), QStringLiteral("I hereby end our friendly relations.")}, - {QStringLiteral("FRCANCELTREATY_ALLIANCE"), QStringLiteral("I hereby cancel our alliance.")}, - {QStringLiteral("FRNOTICE"), QStringLiteral("I have a notice for you.")}, - {QStringLiteral("FRDONE"), QStringLiteral("That is all.")}, - {QStringLiteral("FRDELCHOICE"), QStringLiteral("in exchange for %1, you may choose what we deliver")}, - {QStringLiteral("FRCOSTCHOICE"), QStringLiteral("we offer %1, you may choose the price")}, - {QStringLiteral("FROFFER"), QStringLiteral("we offer %1 in exchange for %2")}, - {QStringLiteral("PRICE_CHOOSE"), QStringLiteral("something of our choosing")}, - {QStringLiteral("PRICE_SHIPCOMP"), QStringLiteral("%1 spaceship component(s)")}, - {QStringLiteral("PRICE_SHIPPOW"), QStringLiteral("%1 spaceship power module(s)")}, - {QStringLiteral("PRICE_SHIPHAB"), QStringLiteral("%1 spaceship habitation module(s)")}, - {QStringLiteral("PRICE_TRIBUTE"), QStringLiteral("a tribute of %1")}, - {QStringLiteral("PRICE_CONCAT"), QStringLiteral("%1, %2")}, - }; - const auto it = table.constFind(key); - return it != table.constEnd() ? it.value() : key; -} - QString phraseTreaty(int treatyType) { switch (treatyType) { @@ -84,7 +57,7 @@ QString priceToString(int p, std::uint32_t price) Tribes::Tribe &tribe = *Tribes::tribe[static_cast(p)]; switch (price & static_cast(opMask)) { case opChoose: - return phrase(QStringLiteral("PRICE_CHOOSE")); + return phrases.lookup(QStringLiteral("PRICE_CHOOSE")); case opCivilReport: return tribe.tPhrase(QStringLiteral("PRICE_CIVIL")); case opMilReport: @@ -95,15 +68,15 @@ QString priceToString(int p, std::uint32_t price) return phraseTreaty(static_cast(price - opTreaty)); case opShipParts: switch ((price >> 16) & 0xFu) { - case 0: return phrase(QStringLiteral("PRICE_SHIPCOMP")).arg(price & 0xFFFFu); - case 1: return phrase(QStringLiteral("PRICE_SHIPPOW")).arg(price & 0xFFFFu); - case 2: return phrase(QStringLiteral("PRICE_SHIPHAB")).arg(price & 0xFFFFu); + case 0: return formatPhrase(QStringLiteral("PRICE_SHIPCOMP"), { QString::number(price & 0xFFFFu) }); + case 1: return formatPhrase(QStringLiteral("PRICE_SHIPPOW"), { QString::number(price & 0xFFFFu) }); + case 2: return formatPhrase(QStringLiteral("PRICE_SHIPHAB"), { QString::number(price & 0xFFFFu) }); default: return QString(); } case opMoney: return QStringLiteral("%1%c").arg(price - opMoney); case opTribute: - return phrase(QStringLiteral("PRICE_TRIBUTE")).arg(price - opTribute); + return formatPhrase(QStringLiteral("PRICE_TRIBUTE"), { QString::number(price - opTribute) }); case opTech: return phraseAdvance(static_cast(price - opTech)); case opAllTech: @@ -131,16 +104,16 @@ QString dipCommandToString(int pSender, int pTarget, int treaty, int oppCommand, switch (command) { case scDipCancelTreaty: switch (treaty) { - case trPeace: result = phrase(QStringLiteral("FRCANCELTREATY_PEACE")); break; - case trFriendlyContact: result = phrase(QStringLiteral("FRCANCELTREATY_FRIENDLY")); break; - case trAlliance: result = phrase(QStringLiteral("FRCANCELTREATY_ALLIANCE")); break; + case trPeace: result = phrases.lookup(QStringLiteral("FRCANCELTREATY_PEACE")); break; + case trFriendlyContact: result = phrases.lookup(QStringLiteral("FRCANCELTREATY_FRIENDLY")); break; + case trAlliance: result = phrases.lookup(QStringLiteral("FRCANCELTREATY_ALLIANCE")); break; default: break; } doIntro = false; break; case scDipNotice: - result = phrase(QStringLiteral("FRNOTICE")); + result = phrases.lookup(QStringLiteral("FRNOTICE")); break; case scDipAccept: @@ -177,12 +150,12 @@ QString dipCommandToString(int pSender, int pTarget, int treaty, int oppCommand, QString sDeliver; for (int i = 0; i < offer.nDeliver; ++i) { const QString sAdd = priceToString(pSender, offer.Price[i]); - sDeliver = i == 0 ? sAdd : phrase(QStringLiteral("PRICE_CONCAT")).arg(sDeliver, sAdd); + sDeliver = i == 0 ? sAdd : formatPhrase(QStringLiteral("PRICE_CONCAT"), { sDeliver, sAdd }); } QString sCost; for (int i = 0; i < offer.nCost; ++i) { const QString sAdd = priceToString(pTarget, offer.Price[offer.nDeliver + i]); - sCost = i == 0 ? sAdd : phrase(QStringLiteral("PRICE_CONCAT")).arg(sCost, sAdd); + sCost = i == 0 ? sAdd : formatPhrase(QStringLiteral("PRICE_CONCAT"), { sCost, sAdd }); } if (offer.nDeliver == 0 && offer.nCost == 0) { @@ -194,7 +167,7 @@ QString dipCommandToString(int pSender, int pTarget, int treaty, int oppCommand, // here, unreachable without a StringTables.pas port. result = sender.tPhrase(QStringLiteral("FRNOTACCEPTOFFER")) + QLatin1Char(' '); } - result += phrase(QStringLiteral("FRDONE")); + result += phrases.lookup(QStringLiteral("FRDONE")); doIntro = false; } } else if (offer.nDeliver + offer.nCost == 1 && @@ -214,11 +187,11 @@ QString dipCommandToString(int pSender, int pTarget, int treaty, int oppCommand, } else if (offer.nCost == 0) { result += target.tPhrase(QStringLiteral("FRPRESENT")).arg(sDeliver); } else if (offer.nDeliver == 1 && offer.Price[0] == opChoose) { - result += phrase(QStringLiteral("FRDELCHOICE")).arg(sCost); + result += formatPhrase(QStringLiteral("FRDELCHOICE"), { sCost }); } else if (offer.nCost == 1 && offer.Price[offer.nDeliver] == opChoose) { - result += phrase(QStringLiteral("FRCOSTCHOICE")).arg(sDeliver); + result += formatPhrase(QStringLiteral("FRCOSTCHOICE"), { sDeliver }); } else { - result += phrase(QStringLiteral("FROFFER")).arg(sDeliver, sCost); + result += formatPhrase(QStringLiteral("FROFFER"), { sDeliver, sCost }); } break; } diff --git a/game/localplayer/Draft.cpp b/game/localplayer/Draft.cpp index 000b062..cd3e1ef 100644 --- a/game/localplayer/Draft.cpp +++ b/game/localplayer/Draft.cpp @@ -36,7 +36,6 @@ #include "Term.h" #include "Tribes.h" -#include #include namespace Cevo { @@ -59,25 +58,6 @@ constexpr int yTotal0 = 354; constexpr int xView = 17; constexpr int yView0 = 283; -// Phrases/Phrases2 (StringTables.pas) aren't ported; disclosed -// plain-English placeholders for this dialog's own text. -QString phrase(const QString &key) -{ - static const QHash table = { - {QStringLiteral("TITLE_DRAFT"), QStringLiteral("Unit Design")}, - {QStringLiteral("BTN_OK"), QStringLiteral("OK")}, - {QStringLiteral("DOMAIN0"), QStringLiteral("Ground units")}, - {QStringLiteral("DOMAIN1"), QStringLiteral("Sea units")}, - {QStringLiteral("DOMAIN2"), QStringLiteral("Air units")}, - {QStringLiteral("UNITSTRENGTH"), QStringLiteral("Strength")}, - {QStringLiteral("UNITTRANSPORT"), QStringLiteral("Transport")}, - {QStringLiteral("UNITSPEED"), QStringLiteral("Speed")}, - {QStringLiteral("UNITCOST"), QStringLiteral("Cost")}, - }; - const auto it = table.constFind(key); - return it != table.constEnd() ? it.value() : key; -} - QString phraseFeature(int code) { return phrases.lookup(QStringLiteral("FEATURES"), code); @@ -107,12 +87,18 @@ DraftDlg::DraftDlg(QWidget *parent) : BufferedDrawDlg(parent), ui(new Ui::DraftD ui->setupUi(this); initButtons(); helpContext = QStringLiteral("CLASSES"); - setWindowTitle(phrase(QStringLiteral("TITLE_DRAFT"))); - ui->okBtn->setCaption(phrase(QStringLiteral("BTN_OK"))); + setWindowTitle(phrases.lookup(QStringLiteral("TITLE_DRAFT"))); + ui->okBtn->setCaption(phrases.lookup(QStringLiteral("BTN_OK"))); - ui->groundArea->setToolTip(phrase(QStringLiteral("DOMAIN0"))); - ui->seaArea->setToolTip(phrase(QStringLiteral("DOMAIN1"))); - ui->airArea->setToolTip(phrase(QStringLiteral("DOMAIN2"))); + if (!phrases2FallenBackToEnglish) { + ui->groundArea->setToolTip(phrases2.lookup(QStringLiteral("DRAFTDOMAIN"), 0)); + ui->seaArea->setToolTip(phrases2.lookup(QStringLiteral("DRAFTDOMAIN"), 1)); + ui->airArea->setToolTip(phrases2.lookup(QStringLiteral("DRAFTDOMAIN"), 2)); + } else { + ui->groundArea->setToolTip(phrases.lookup(QStringLiteral("DOMAIN"), 0)); + ui->seaArea->setToolTip(phrases.lookup(QStringLiteral("DOMAIN"), 1)); + ui->airArea->setToolTip(phrases.lookup(QStringLiteral("DOMAIN"), 2)); + } back.setSize(width(), height()); back.canvas().begin(); @@ -282,7 +268,7 @@ void DraftDlg::offscreenPaint() int y = yTotal; darkGradient(canvas, xTotal - 6, y + 1, 184, 2); darkGradient(canvas, xTotal2 + 172, y + 1, 95, 2); - risedTextOut(canvas, xTotal - 2, y, phrase(QStringLiteral("UNITSTRENGTH"))); + risedTextOut(canvas, xTotal - 2, y, phrases.lookup(QStringLiteral("UNITSTRENGTH"))); risedTextOut(canvas, xTotal + 112 + 30, y, QStringLiteral("x%1").arg(devModel.MStrength)); risedTextOut(canvas, xTotal2 + 148 + 30, y, QStringLiteral("=")); const QString s = QStringLiteral("%1/%2").arg(devModel.Attack).arg(devModel.Defense); @@ -293,7 +279,7 @@ void DraftDlg::offscreenPaint() y = yTotal + 19; darkGradient(canvas, xTotal - 6, y + 1, 184, 1); darkGradient(canvas, xTotal2 + 172, y + 1, 95, 1); - risedTextOut(canvas, xTotal - 2, y, phrase(QStringLiteral("UNITTRANSPORT"))); + risedTextOut(canvas, xTotal - 2, y, phrases.lookup(QStringLiteral("UNITTRANSPORT"))); risedTextOut(canvas, xTotal + 112 + 30, y, QStringLiteral("x%1").arg(devModel.MTrans)); risedTextOut(canvas, xTotal2 + 148 + 30, y, QStringLiteral("=")); @@ -325,7 +311,7 @@ void DraftDlg::offscreenPaint() // speed bar y = yTotal + 38; - loweredTextOut(canvas, -1, *MainTexture, xTotal - 2, y, phrase(QStringLiteral("UNITSPEED"))); + loweredTextOut(canvas, -1, *MainTexture, xTotal - 2, y, phrases.lookup(QStringLiteral("UNITSPEED"))); dLine(canvas, xTotal - 2, xTotal + 174, y + 16, MainTexture->colorBevelShade, MainTexture->colorBevelLight); dLine(canvas, xTotal2 + 176, xTotal2 + 263, y + 16, MainTexture->colorBevelShade, MainTexture->colorBevelLight); @@ -334,7 +320,7 @@ void DraftDlg::offscreenPaint() // cost bar y = yTotal + 57; - loweredTextOut(canvas, -1, *MainTexture, xTotal - 2, y, phrase(QStringLiteral("UNITCOST"))); + loweredTextOut(canvas, -1, *MainTexture, xTotal - 2, y, phrases.lookup(QStringLiteral("UNITCOST"))); loweredTextOut(canvas, -1, *MainTexture, xTotal + 112 + 30, y, QStringLiteral("x%1").arg(devModel.MCost)); loweredTextOut(canvas, -1, *MainTexture, xTotal2 + 148 + 30, y, QStringLiteral("=")); dLine(canvas, xTotal - 2, xTotal + 174, y + 16, MainTexture->colorBevelShade, MainTexture->colorBevelLight); diff --git a/game/localplayer/Enhance.cpp b/game/localplayer/Enhance.cpp index 5062610..c8537d6 100644 --- a/game/localplayer/Enhance.cpp +++ b/game/localplayer/Enhance.cpp @@ -49,19 +49,6 @@ namespace Enhance { namespace { -// TODO: needs Phrases[] (StringTables.pas not ported) - plain English -// literals until localization is ported. -QString phrase(const QString &key) -{ - static const QHash table = { - {QStringLiteral("TITLE_ENHANCE"), QStringLiteral("Enhance terrain")}, - {QStringLiteral("BTN_SELECT"), QStringLiteral("Select terrain")}, - {QStringLiteral("TWOTERRAINS"), QStringLiteral("%1/%2")}, - }; - const auto it = table.constFind(key); - return it != table.constEnd() ? *it : key; -} - QString terrainName(int terrType) { return phrases.lookup(QStringLiteral("TERRAIN"), terrType); @@ -81,8 +68,8 @@ EnhanceDlg::EnhanceDlg(QWidget *parent) : FramedDlg(parent), ui(new Ui::EnhanceD captionRight = ui->closeBtn->x(); captionLeft = ui->toggleBtn->x() + ui->toggleBtn->width(); initButtons(); - setWindowTitle(phrase(QStringLiteral("TITLE_ENHANCE"))); - ui->toggleBtn->setToolTip(phrase(QStringLiteral("BTN_SELECT"))); + setWindowTitle(phrases.lookup(QStringLiteral("TITLE_ENHANCE"))); + ui->toggleBtn->setToolTip(phrases.lookup(QStringLiteral("BTN_SELECT"))); popup = new QMenu(this); for (int terrType = fGrass; terrType <= fMountains; ++terrType) { @@ -90,9 +77,9 @@ EnhanceDlg::EnhanceDlg(QWidget *parent) : FramedDlg(parent), ui(new Ui::EnhanceD continue; QString caption; if (terrType == fGrass) - caption = phrase(QStringLiteral("TWOTERRAINS")).arg(terrainName(fGrass)).arg(terrainName(fGrass + 12)); + caption = formatPhrase(QStringLiteral("TWOTERRAINS"), { terrainName(fGrass), terrainName(fGrass + 12) }); else if (terrType == fForest) - caption = phrase(QStringLiteral("TWOTERRAINS")).arg(terrainName(fForest)).arg(terrainName(Term::fJungle)); + caption = formatPhrase(QStringLiteral("TWOTERRAINS"), { terrainName(fForest), terrainName(Term::fJungle) }); else caption = terrainName(terrType); QAction *action = popup->addAction(caption); diff --git a/game/localplayer/Help.cpp b/game/localplayer/Help.cpp index bcab1d9..c47ac02 100644 --- a/game/localplayer/Help.cpp +++ b/game/localplayer/Help.cpp @@ -50,7 +50,6 @@ #include "Messg.h" #include "Term.h" -#include #include #include #include @@ -69,20 +68,6 @@ namespace { constexpr int MaxHist = 16; constexpr int ScrollBarWidth = 16; // matches Dpi::ScrollBar's fixed width -// Phrases/Phrases2 (StringTables.pas) aren't ported; disclosed -// plain-English placeholders for this dialog's own chrome text. -QString phrase(const QString &key) -{ - static const QHash table = { - {QStringLiteral("BTN_CONTENTS"), QStringLiteral("Contents")}, - {QStringLiteral("BTN_BACK"), QStringLiteral("Back")}, - {QStringLiteral("BTN_SEARCH"), QStringLiteral("Search")}, - {QStringLiteral("SEARCH"), QStringLiteral("Search Help")}, - }; - const auto it = table.constFind(key); - return it != table.constEnd() ? it.value() : key; -} - // Help.txt phrases carry raw C printf-style specifiers (copied from the // original's Format() call sites) - NOT Qt's %1/%2 .arg() syntax. Scans // left to right, filling each %d/%s in order from args (supports formats @@ -232,9 +217,9 @@ HelpDlg::HelpDlg(QWidget *parent) : FramedDlg(parent), ui(new Ui::HelpDlg) helpText.loadFromFile(localizedFilePath(QStringLiteral("Help/Help.txt"))); helpContext = QStringLiteral("CONCEPTS"); - ui->topBtn->setToolTip(phrase(QStringLiteral("BTN_CONTENTS"))); - ui->backBtn->setToolTip(phrase(QStringLiteral("BTN_BACK"))); - ui->searchBtn->setToolTip(phrase(QStringLiteral("BTN_SEARCH"))); + ui->topBtn->setToolTip(phrases.lookup(QStringLiteral("BTN_CONTENTS"))); + ui->backBtn->setToolTip(phrases.lookup(QStringLiteral("BTN_BACK"))); + ui->searchBtn->setToolTip(phrases.lookup(QStringLiteral("BTN_SEARCH"))); ui->closeBtn->onClick = [this] { close(); }; ui->backBtn->onClick = [this] { backBtnClicked(); }; @@ -1157,7 +1142,7 @@ void HelpDlg::topBtnClicked() void HelpDlg::searchBtnClicked() { auto inputDlg = std::make_unique(nullptr); - inputDlg->setWindowTitle(phrase(QStringLiteral("SEARCH"))); + inputDlg->setWindowTitle(phrases.lookup(QStringLiteral("SEARCH"))); inputDlg->editInput()->setText(searchContent); inputDlg->centerToRect(geometry()); if (inputDlg->showModal() == Dpi::ModalResult::Ok && inputDlg->editInput()->text().length() >= 2) { diff --git a/game/localplayer/NatStat.cpp b/game/localplayer/NatStat.cpp index b763ff8..4729e1a 100644 --- a/game/localplayer/NatStat.cpp +++ b/game/localplayer/NatStat.cpp @@ -37,7 +37,6 @@ #include "Term.h" #include "Tribes.h" -#include #include #include @@ -62,60 +61,14 @@ constexpr int yReport = 165; constexpr int wReport = 352; constexpr int hReport = ReportLines * LineSpacing; -// Phrases/Phrases2 (StringTables.pas) aren't ported; disclosed -// plain-English placeholders for this dialog's own text. -QString phrase(const QString &key) -{ - static const QHash table = { - {QStringLiteral("BTN_SELECT"), QStringLiteral("Select nation")}, - {QStringLiteral("BTN_DIALOG"), QStringLiteral("Negotiate")}, - {QStringLiteral("FRSTATPOP"), QStringLiteral("Population: %1")}, - {QStringLiteral("FRSTATTER"), QStringLiteral("Territory: %1")}, - {QStringLiteral("FRSTATTECH"), QStringLiteral("Advances researched: %1")}, - {QStringLiteral("FRSTATEXP"), QStringLiteral("Land explored: %1%")}, - {QStringLiteral("FROLDCIVILREP"), QStringLiteral("Last report: %1")}, - {QStringLiteral("FRTREASURY"), QStringLiteral("Treasury: %1")}, - {QStringLiteral("FRRELATIONS"), QStringLiteral("Relations:")}, - {QStringLiteral("FRCOLDWAR"), QStringLiteral("We are in a cold war.")}, - {QStringLiteral("FRMYANARCHY"), QStringLiteral("We are in anarchy.")}, - {QStringLiteral("FRANARCHY"), QStringLiteral("They are in anarchy.")}, - {QStringLiteral("FREXTINCT"), QStringLiteral("Extinct since")}, - {QStringLiteral("FRCREDIBILITY"), QStringLiteral("Credibility: %1")}, - {QStringLiteral("FRNOCONTACT"), QStringLiteral("No contact")}, - {QStringLiteral("FRTREATY"), QStringLiteral("Treaty:")}, - {QStringLiteral("FRNOVISIT"), QStringLiteral("Never visited")}, - {QStringLiteral("FRLASTCONTACT"), QStringLiteral("Last contact:")}, - {QStringLiteral("FRNOCIVILREP"), QStringLiteral("No civil report available.")}, - {QStringLiteral("MENU_TELLAI"), QStringLiteral("Tell AI")}, - }; - const auto it = table.constFind(key); - return it != table.constEnd() ? it.value() : key; -} - QString phraseGovernment(int government) { - return QStringLiteral("government #%1 ").arg(government); + return phrases.lookup(QStringLiteral("GOVERNMENT"), government); } QString phraseCredibility(int roughCredibility) { - static const QHash table = { - {0, QStringLiteral("poor")}, {1, QStringLiteral("fair")}, {2, QStringLiteral("good")}, - {3, QStringLiteral("perfect")}, - }; - const auto it = table.constFind(roughCredibility); - return it != table.constEnd() ? it.value() : QString(); -} - -QString phraseTreaty(int treaty) -{ - static const QHash table = { - {trNoContact, QStringLiteral("no contact")}, {trNone, QStringLiteral("none")}, - {trCeaseFire, QStringLiteral("cease-fire")}, {trPeace, QStringLiteral("peace")}, - {trFriendlyContact, QStringLiteral("friendly")}, {trAlliance, QStringLiteral("alliance")}, - }; - const auto it = table.constFind(treaty); - return it != table.constEnd() ? it.value() : QString(); + return phrases.lookup(QStringLiteral("CREDIBILITY"), roughCredibility); } } // namespace @@ -127,8 +80,8 @@ NatStatDlg::NatStatDlg(QWidget *parent) : BufferedDrawDlg(parent), ui(new Ui::Na ui->contactBtn->setTemplate(Templates ? &Templates->data : nullptr); ui->contactBtn->setButtonIndex(3); helpContext = QStringLiteral("DIPLOMACY"); - ui->toggleBtn->setToolTip(phrase(QStringLiteral("BTN_SELECT"))); - ui->contactBtn->setToolTip(phrase(QStringLiteral("BTN_DIALOG"))); + ui->toggleBtn->setToolTip(phrases.lookup(QStringLiteral("BTN_SELECT"))); + ui->contactBtn->setToolTip(phrases.lookup(QStringLiteral("BTN_DIALOG"))); back.setSize(width(), height()); back.canvas().begin(); @@ -237,11 +190,12 @@ void NatStatDlg::generateReportText() ClientTools::server(sGetChart + (no << 4), ClientTools::me, pView, list.data()) >= rExecuted) { const int i = list[static_cast(currentReport->TurnOfCivilReport)]; switch (no) { - case stPop: return phrase(QStringLiteral("FRSTATPOP")).arg(i); - case stTerritory: return phrase(QStringLiteral("FRSTATTER")).arg(i); - case stScience: return phrase(QStringLiteral("FRSTATTECH")).arg(i / nAdv); + case stPop: return formatPhrase(QStringLiteral("FRSTATPOP"), { QString::number(i) }); + case stTerritory: return formatPhrase(QStringLiteral("FRSTATTER"), { QString::number(i) }); + case stScience: return formatPhrase(QStringLiteral("FRSTATTECH"), { QString::number(i / nAdv) }); case stExplore: - return phrase(QStringLiteral("FRSTATEXP")).arg(i * 100 / (ClientTools::g.lx * ClientTools::g.ly)); + return formatPhrase(QStringLiteral("FRSTATEXP"), + { QString::number(i * 100 / (ClientTools::g.lx * ClientTools::g.ly)) }); default: return QString(); } } @@ -252,12 +206,12 @@ void NatStatDlg::generateReportText() reportText.append(QString()); if (ClientTools::myRO->Turn - currentReport->TurnOfCivilReport > 1 && (1u << pView & static_cast(ClientTools::myRO->Alive)) != 0) { - reportText.append(phrase(QStringLiteral("FROLDCIVILREP")).arg(Term::turnToString(currentReport->TurnOfCivilReport))); + reportText.append(formatPhrase(QStringLiteral("FROLDCIVILREP"), { Term::turnToString(currentReport->TurnOfCivilReport) })); reportText.append(QString()); } if ((1u << pView & static_cast(ClientTools::myRO->Alive)) != 0) { - reportText.append(phrase(QStringLiteral("FRTREASURY")).arg(currentReport->Money)); + reportText.append(formatPhrase(QStringLiteral("FRTREASURY"), { QString::number(currentReport->Money) })); reportText.append(statText(stPop)); reportText.append(statText(stTerritory)); } @@ -272,13 +226,14 @@ void NatStatDlg::generateReportText() } if (hasContact) { reportText.append(QString()); - reportText.append(phrase(QStringLiteral("FRRELATIONS"))); + reportText.append(phrases.lookup(QStringLiteral("FRRELATIONS"))); for (int extinctPart = 0; extinctPart <= 1; ++extinctPart) { for (int treaty = trAlliance; treaty >= trNone; --treaty) { for (int p1 = 0; p1 < nPl; ++p1) { if (p1 != ClientTools::me && currentReport->Treaty[p1] == treaty && ((1u << p1 & static_cast(ClientTools::myRO->Alive)) == 0) == (extinctPart != 0)) { - QString s = Tribes::tribe[static_cast(p1)]->tString(phraseTreaty(treaty)); + QString s = Tribes::tribe[static_cast(p1)]->tString( + phrases.lookup(QStringLiteral("HAVETREATY"), treaty)); if (extinctPart) s = QLatin1Char('(') + s + QLatin1Char(')'); reportText.append(s); @@ -315,38 +270,38 @@ void NatStatDlg::offscreenPaint() if (pView == ClientTools::me || !extinct) loweredTextOut(canvas, -1, *MainTexture, xAttrib, yAttrib, - phraseGovernment(currentReport->Government) + QStringLiteral("and")); + phraseGovernment(currentReport->Government) + phrases.lookup(QStringLiteral("FRAND"))); if (pView == ClientTools::me) { loweredTextOut(canvas, -1, *MainTexture, xAttrib, yAttrib + 19, phraseCredibility(Term::roughCredibility(ClientTools::myRO->Credibility))); loweredTextOut(canvas, -1, *MainTexture, xAttrib, yAttrib + 38, - phrase(QStringLiteral("FRCREDIBILITY")).arg(ClientTools::myRO->Credibility)); + formatPhrase(QStringLiteral("FRCREDIBILITY"), { QString::number(ClientTools::myRO->Credibility) })); } else { if (extinct) { - loweredTextOut(canvas, -1, *MainTexture, xAttrib, yAttrib + 9, phrase(QStringLiteral("FREXTINCT"))); + loweredTextOut(canvas, -1, *MainTexture, xAttrib, yAttrib + 9, phrases.lookup(QStringLiteral("FREXTINCT"))); loweredTextOut(canvas, -1, *MainTexture, xAttrib, yAttrib + 28, Term::turnToString(currentReport->TurnOfCivilReport)); } else { loweredTextOut(canvas, -1, *MainTexture, xAttrib, yAttrib + 19, phraseCredibility(Term::roughCredibility(currentReport->Credibility))); loweredTextOut(canvas, -1, *MainTexture, xAttrib, yAttrib + 38, - phrase(QStringLiteral("FRCREDIBILITY")).arg(currentReport->Credibility)); + formatPhrase(QStringLiteral("FRCREDIBILITY"), { QString::number(currentReport->Credibility) })); } if (ClientTools::myRO->Treaty[pView] == trNoContact) { - const QString s = phrase(QStringLiteral("FRNOCONTACT")); + const QString s = phrases.lookup(QStringLiteral("FRNOCONTACT")); loweredTextOut(canvas, -1, *MainTexture, (width() - biColorTextWidth(canvas, s)) / 2, yRelation + 9, s); } else if (showContact) { - loweredTextOut(canvas, -1, *MainTexture, xRelation, yRelation, phrase(QStringLiteral("FRTREATY"))); + loweredTextOut(canvas, -1, *MainTexture, xRelation, yRelation, phrases.lookup(QStringLiteral("FRTREATY"))); loweredTextOut(canvas, -1, *MainTexture, width() / 2, yRelation, - phraseTreaty(ClientTools::myRO->Treaty[pView])); + phrases.lookup(QStringLiteral("TREATY"), ClientTools::myRO->Treaty[pView])); if (currentReport->TurnOfContact < 0) { loweredTextOut(canvas, -1, *MainTexture, width() / 2, yRelation + 19, - phrase(QStringLiteral("FRNOVISIT"))); + phrases.lookup(QStringLiteral("FRNOVISIT"))); } else { loweredTextOut(canvas, -1, *MainTexture, xRelation, yRelation + 19, - phrase(QStringLiteral("FRLASTCONTACT"))); + phrases.lookup(QStringLiteral("FRLASTCONTACT"))); loweredTextOut(canvas, -1, *MainTexture, width() / 2, yRelation + 19, Term::turnToString(currentReport->TurnOfContact)); } @@ -374,7 +329,7 @@ void NatStatDlg::offscreenPaint() } } } else { - const QString s = phrase(QStringLiteral("FRNOCIVILREP")); + const QString s = phrases.lookup(QStringLiteral("FRNOCIVILREP")); risedTextOut(canvas, (width() - biColorTextWidth(canvas, s)) / 2, yReport + hReport / 2 - 10, s); } @@ -382,7 +337,7 @@ void NatStatDlg::offscreenPaint() // Server(sGetAIInfo,...) returning a live AI-credits string isn't wired here yet. loweredTextOut(canvas, -1, *MainTexture, 42, 445, QString()); } else { - loweredTextOut(canvas, -2, *MainTexture, 42, 445, phrase(QStringLiteral("MENU_TELLAI"))); + loweredTextOut(canvas, -2, *MainTexture, 42, 445, phrases.lookup(QStringLiteral("MENU_TELLAI"))); } ui->contactBtn->setBack(canvas, ui->contactBtn->x(), ui->contactBtn->y()); diff --git a/game/localplayer/Nego.cpp b/game/localplayer/Nego.cpp index 9861bb6..ae89f3e 100644 --- a/game/localplayer/Nego.cpp +++ b/game/localplayer/Nego.cpp @@ -34,6 +34,7 @@ #include "Cevo/CevoTexture.h" #include "ClientTools.h" #include "Diplomacy.h" +#include "Global.h" #include "Inp.h" #include "IsoEngine.h" #include "MessgEx.h" @@ -92,54 +93,6 @@ const std::array ButtonPrice = { static_cast(opShipParts), static_cast(opShipParts), }; -// Phrases/Phrases2 (StringTables.pas) aren't ported; disclosed -// plain-English placeholders for this dialog's own text. -QString phrase(const QString &key) -{ - static const QHash table = { - {QStringLiteral("BTN_OK"), QStringLiteral("OK")}, - {QStringLiteral("BTN_ACCEPT"), QStringLiteral("Accept")}, - {QStringLiteral("BTN_BREAK"), QStringLiteral("Break off")}, - {QStringLiteral("BTN_CNTREATY"), QStringLiteral("Cancel treaty")}, - {QStringLiteral("BTN_NOTICE"), QStringLiteral("Notice")}, - {QStringLiteral("BTN_PASS"), QStringLiteral("Pass")}, - {QStringLiteral("BTN_WANTPEACE"), QStringLiteral("Want peace")}, - {QStringLiteral("BTN_OFFERPEACE"), QStringLiteral("Offer peace")}, - {QStringLiteral("BTN_WANTFRIENDLY"), QStringLiteral("Want friendly relations")}, - {QStringLiteral("BTN_OFFERFRIENDLY"), QStringLiteral("Offer friendly relations")}, - {QStringLiteral("BTN_WANTALLIANCE"), QStringLiteral("Want alliance")}, - {QStringLiteral("BTN_OFFERALLIANCE"), QStringLiteral("Offer alliance")}, - {QStringLiteral("MAX2WANTS"), QStringLiteral("You can only ask for 2 things at once.")}, - {QStringLiteral("MAX2OFFERS"), QStringLiteral("You can only offer 2 things at once.")}, - {QStringLiteral("CANCELTREATYRUSH"), QStringLiteral("You can't cancel the treaty again so soon.")}, - {QStringLiteral("TITLE_AMOUNT"), QStringLiteral("Enter amount")}, - {QStringLiteral("TITLE_NUMBER"), QStringLiteral("Enter number")}, - {QStringLiteral("NOSPACEPORT"), QStringLiteral("We have no space port to ship parts from.")}, - {QStringLiteral("WANT_ANYTHING"), QStringLiteral("Anything")}, - {QStringLiteral("WANT_STATEREPORT"), QStringLiteral("State report")}, - {QStringLiteral("WANT_MILREPORT"), QStringLiteral("Military report")}, - {QStringLiteral("WANT_MAP"), QStringLiteral("Map")}, - {QStringLiteral("WANT_TECH"), QStringLiteral("Advance")}, - {QStringLiteral("WANT_MODEL"), QStringLiteral("Unit design")}, - {QStringLiteral("WANT_MONEY"), QStringLiteral("Money")}, - {QStringLiteral("WANT_HITREATY"), QStringLiteral("Improve treaty")}, - {QStringLiteral("WANT_LOTREATY"), QStringLiteral("Worsen treaty")}, - {QStringLiteral("WANT_SHIPPART"), QStringLiteral("Ship part")}, - {QStringLiteral("OFFER_ANYTHING"), QStringLiteral("Anything")}, - {QStringLiteral("OFFER_STATEREPORT"), QStringLiteral("State report")}, - {QStringLiteral("OFFER_MILREPORT"), QStringLiteral("Military report")}, - {QStringLiteral("OFFER_MAP"), QStringLiteral("Map")}, - {QStringLiteral("OFFER_TECH"), QStringLiteral("Advance")}, - {QStringLiteral("OFFER_MODEL"), QStringLiteral("Unit design")}, - {QStringLiteral("OFFER_MONEY"), QStringLiteral("Money")}, - {QStringLiteral("OFFER_HITREATY"), QStringLiteral("Improve treaty")}, - {QStringLiteral("OFFER_LOTREATY"), QStringLiteral("Worsen treaty")}, - {QStringLiteral("OFFER_SHIPPART"), QStringLiteral("Ship part")}, - }; - const auto it = table.constFind(key); - return it != table.constEnd() ? *it : key; -} - } // namespace NegoDlg::NegoDlg(QWidget *parent) : BufferedDrawDlg(parent), ui(new Ui::NegoDlg) @@ -154,24 +107,15 @@ NegoDlg::NegoDlg(QWidget *parent) : BufferedDrawDlg(parent), ui(new Ui::NegoDlg) ui->offerTech1Btn, ui->offerTech2Btn, ui->offerModelBtn, ui->offerMoneyBtn, ui->offerHiTreatyBtn, ui->offerLoTreatyBtn, ui->offerShipPart1Btn, ui->offerShipPart2Btn}; - const std::array wantHints = { - phrase(QStringLiteral("WANT_ANYTHING")), phrase(QStringLiteral("WANT_STATEREPORT")), - phrase(QStringLiteral("WANT_MILREPORT")), phrase(QStringLiteral("WANT_MAP")), - phrase(QStringLiteral("WANT_TECH")), phrase(QStringLiteral("WANT_TECH")), - phrase(QStringLiteral("WANT_MODEL")), phrase(QStringLiteral("WANT_MONEY")), - phrase(QStringLiteral("WANT_HITREATY")), phrase(QStringLiteral("WANT_LOTREATY")), - phrase(QStringLiteral("WANT_SHIPPART")), phrase(QStringLiteral("WANT_SHIPPART")), - }; - const std::array offerHints = { - phrase(QStringLiteral("OFFER_ANYTHING")), phrase(QStringLiteral("OFFER_STATEREPORT")), - phrase(QStringLiteral("OFFER_MILREPORT")), phrase(QStringLiteral("OFFER_MAP")), - phrase(QStringLiteral("OFFER_TECH")), phrase(QStringLiteral("OFFER_TECH")), - phrase(QStringLiteral("OFFER_MODEL")), phrase(QStringLiteral("OFFER_MONEY")), - phrase(QStringLiteral("OFFER_HITREATY")), phrase(QStringLiteral("OFFER_LOTREATY")), - phrase(QStringLiteral("OFFER_SHIPPART")), phrase(QStringLiteral("OFFER_SHIPPART")), - }; const std::array buttonIndex = {17, 6, 7, 8, 10, 10, 11, 12, 14, 15, 16, 16}; + std::array wantHints; + std::array offerHints; + for (int i = 0; i < 12; ++i) { + wantHints[static_cast(i)] = phrases.lookup(QStringLiteral("WANT"), buttonIndex[static_cast(i)] - 6); + offerHints[static_cast(i)] = phrases.lookup(QStringLiteral("OFFER"), buttonIndex[static_cast(i)] - 6); + } + for (int i = 0; i < 12; ++i) { ButtonN *w = wantButtons[static_cast(i)]; ButtonN *o = offerButtons[static_cast(i)]; @@ -210,10 +154,10 @@ NegoDlg::NegoDlg(QWidget *parent) : BufferedDrawDlg(parent), ui(new Ui::NegoDlg) ui->cancelTreatyBtn->onClick = [this] { fastClicked(scDipCancelTreaty - scDipStart); }; helpContext = QStringLiteral("DIPLOMACY"); - ui->okBtn->setCaption(phrase(QStringLiteral("BTN_OK"))); - ui->acceptBtn->setSmartHint(phrase(QStringLiteral("BTN_ACCEPT"))); - ui->exitBtn->setSmartHint(phrase(QStringLiteral("BTN_BREAK"))); - ui->cancelTreatyBtn->setSmartHint(phrase(QStringLiteral("BTN_CNTREATY"))); + ui->okBtn->setCaption(phrases.lookup(QStringLiteral("BTN_OK"))); + ui->acceptBtn->setSmartHint(phrases.lookup(QStringLiteral("BTN_ACCEPT"))); + ui->exitBtn->setSmartHint(phrases.lookup(QStringLiteral("BTN_BREAK"))); + ui->cancelTreatyBtn->setSmartHint(phrases.lookup(QStringLiteral("BTN_CNTREATY"))); romanFont.setName(QStringLiteral("Times New Roman")); romanFont.setSize(20); @@ -275,20 +219,20 @@ void NegoDlg::showNewContent(WindowMode newMode) setButtonStates(); const int pContact = Term::dipMem[static_cast(ClientTools::me)].pContact; ui->passBtn->setSmartHint(IsoEngine::clientMode == scDipCancelTreaty || IsoEngine::clientMode == scDipBreak - ? phrase(QStringLiteral("BTN_NOTICE")) - : phrase(QStringLiteral("BTN_PASS"))); + ? phrases.lookup(QStringLiteral("BTN_NOTICE")) + : phrases.lookup(QStringLiteral("BTN_PASS"))); switch (ClientTools::myRO->Treaty[pContact]) { case trNone: - ui->wantHiTreatyBtn->setSmartHint(phrase(QStringLiteral("BTN_WANTPEACE"))); - ui->offerHiTreatyBtn->setSmartHint(phrase(QStringLiteral("BTN_OFFERPEACE"))); + ui->wantHiTreatyBtn->setSmartHint(phrases.lookup(QStringLiteral("BTN_WANTPEACE"))); + ui->offerHiTreatyBtn->setSmartHint(phrases.lookup(QStringLiteral("BTN_OFFERPEACE"))); break; case trPeace: - ui->wantHiTreatyBtn->setSmartHint(phrase(QStringLiteral("BTN_WANTFRIENDLY"))); - ui->offerHiTreatyBtn->setSmartHint(phrase(QStringLiteral("BTN_OFFERFRIENDLY"))); + ui->wantHiTreatyBtn->setSmartHint(phrases.lookup(QStringLiteral("BTN_WANTFRIENDLY"))); + ui->offerHiTreatyBtn->setSmartHint(phrases.lookup(QStringLiteral("BTN_OFFERFRIENDLY"))); break; case trFriendlyContact: - ui->wantHiTreatyBtn->setSmartHint(phrase(QStringLiteral("BTN_WANTALLIANCE"))); - ui->offerHiTreatyBtn->setSmartHint(phrase(QStringLiteral("BTN_OFFERALLIANCE"))); + ui->wantHiTreatyBtn->setSmartHint(phrases.lookup(QStringLiteral("BTN_WANTALLIANCE"))); + ui->offerHiTreatyBtn->setSmartHint(phrases.lookup(QStringLiteral("BTN_OFFERALLIANCE"))); break; default: break; @@ -671,7 +615,7 @@ void NegoDlg::wantClicked(int priceIndex) price = 0xFFFFFFFFu; // toggle off } else { if (currentOffer.nCost >= 2) { - MessgEx::soundMessageEx(phrase(QStringLiteral("MAX2WANTS")), QString()); + MessgEx::soundMessageEx(phrases.lookup(QStringLiteral("MAX2WANTS")), QString()); return; } price = ButtonPrice[static_cast(priceIndex)]; @@ -684,7 +628,7 @@ void NegoDlg::wantClicked(int priceIndex) break; case static_cast(opMoney): { InputDlg dlg; - dlg.setWindowTitle(phrase(QStringLiteral("TITLE_AMOUNT"))); + dlg.setWindowTitle(phrases.lookup(QStringLiteral("TITLE_AMOUNT"))); dlg.editInput()->setText(QString()); dlg.centerToRect(geometry()); if (dlg.showModal() != Dpi::ModalResult::Ok) @@ -700,7 +644,7 @@ void NegoDlg::wantClicked(int priceIndex) if (ClientTools::myRO->NatBuilt[imSpacePort] == 0) { if (auto *dlg = Term::mainScreenMessgExDlg()) { dlg->openSound = QStringLiteral("WARNING_LOWSUPPORT"); - dlg->messageText = phrase(QStringLiteral("NOSPACEPORT")); + dlg->messageText = phrases.lookup(QStringLiteral("NOSPACEPORT")); dlg->kind = MessageKind::YesNo; dlg->iconKind = MessgEx::MessageIconKind::Imp; dlg->iconIndex = imSpacePort; @@ -717,7 +661,7 @@ void NegoDlg::wantClicked(int priceIndex) price += static_cast(selectDlg->result << 16); int max = ClientTools::myRO->Ship[pContact].Parts[selectDlg->result]; InputDlg amountDlg; - amountDlg.setWindowTitle(phrase(QStringLiteral("TITLE_NUMBER"))); + amountDlg.setWindowTitle(phrases.lookup(QStringLiteral("TITLE_NUMBER"))); amountDlg.editInput()->setText(QString()); amountDlg.centerToRect(geometry()); if (amountDlg.showModal() != Dpi::ModalResult::Ok) @@ -788,7 +732,7 @@ void NegoDlg::offerClicked(int priceIndex) price = 0xFFFFFFFFu; // toggle off } else { if (currentOffer.nDeliver >= 2) { - MessgEx::soundMessageEx(phrase(QStringLiteral("MAX2OFFERS")), QString()); + MessgEx::soundMessageEx(phrases.lookup(QStringLiteral("MAX2OFFERS")), QString()); return; } price = ButtonPrice[static_cast(priceIndex)]; @@ -801,7 +745,7 @@ void NegoDlg::offerClicked(int priceIndex) break; case static_cast(opMoney): { InputDlg dlg; - dlg.setWindowTitle(phrase(QStringLiteral("TITLE_AMOUNT"))); + dlg.setWindowTitle(phrases.lookup(QStringLiteral("TITLE_AMOUNT"))); dlg.editInput()->setText(QString()); dlg.centerToRect(geometry()); if (dlg.showModal() != Dpi::ModalResult::Ok) @@ -825,7 +769,7 @@ void NegoDlg::offerClicked(int priceIndex) price += static_cast(selectDlg->result << 16); int max = ClientTools::myRO->Ship[me].Parts[selectDlg->result]; InputDlg amountDlg; - amountDlg.setWindowTitle(phrase(QStringLiteral("TITLE_NUMBER"))); + amountDlg.setWindowTitle(phrases.lookup(QStringLiteral("TITLE_NUMBER"))); amountDlg.editInput()->setText(QString()); amountDlg.centerToRect(geometry()); if (amountDlg.showModal() != Dpi::ModalResult::Ok) @@ -893,7 +837,7 @@ void NegoDlg::fastClicked(int commandOffset) ClientTools::myRO->Turn < ClientTools::myRO->LastCancelTreaty[Term::dipMem[static_cast(ClientTools::me)].pContact] + CancelTreatyTurns) { - MessgEx::soundMessageEx(phrase(QStringLiteral("CANCELTREATYRUSH")), QString()); + MessgEx::soundMessageEx(phrases.lookup(QStringLiteral("CANCELTREATYRUSH")), QString()); return; } if (newCommand == scDipOffer && (IsoEngine::clientMode == scDipCancelTreaty || IsoEngine::clientMode == scDipBreak)) diff --git a/game/localplayer/Rates.cpp b/game/localplayer/Rates.cpp index 6e4f685..f101b63 100644 --- a/game/localplayer/Rates.cpp +++ b/game/localplayer/Rates.cpp @@ -32,11 +32,10 @@ #include "Cevo/CevoScreenTools.h" #include "Cevo/CevoTexture.h" #include "ClientTools.h" +#include "Global.h" #include "Term.h" #include "Tribes.h" -#include - namespace Cevo { namespace Rates { @@ -44,22 +43,6 @@ namespace { constexpr int MessageLineSpacing = 20; -// Phrases/Phrases2 (StringTables.pas) aren't ported; disclosed -// plain-English placeholders for this dialog's own text. -QString phrase(const QString &key) -{ - static const QHash table = { - {QStringLiteral("TITLE_RATES"), QStringLiteral("Rates")}, - {QStringLiteral("NORATES"), QStringLiteral("The Statue of Liberty lets your people decide for themselves.")}, - {QStringLiteral("RATES"), QStringLiteral("Set your tax, science and luxury rates.\\(click the arrows)")}, - {QStringLiteral("SCIENCE"), QStringLiteral("Science")}, - {QStringLiteral("LUX"), QStringLiteral("Luxury")}, - {QStringLiteral("TAXRATE"), QStringLiteral("Tax")}, - }; - const auto it = table.constFind(key); - return it != table.constEnd() ? it.value() : key; -} - } // namespace RatesDlg::RatesDlg(QWidget *parent) : BufferedDrawDlg(parent), ui(new Ui::RatesDlg) @@ -74,7 +57,7 @@ RatesDlg::RatesDlg(QWidget *parent) : BufferedDrawDlg(parent), ui(new Ui::RatesD ui->scienceBtn->onClick = [this] { taxLuxBtnClick(2); }; ui->luxBtn->onClick = [this] { taxLuxBtnClick(3); }; onShow = [this] { - setWindowTitle(phrase(QStringLiteral("TITLE_RATES"))); + setWindowTitle(phrases.lookup(QStringLiteral("TITLE_RATES"))); const bool hasLiberty = ClientTools::myRO->Wonder[woLiberty].EffectiveOwner == ClientTools::me; ui->scienceBtn->setVisible(!hasLiberty); ui->luxBtn->setVisible(!hasLiberty); @@ -101,11 +84,11 @@ void RatesDlg::offscreenPaint() btnFrame(canvas, ui->closeBtn->geometry(), *MainTexture); canvas.font().assign(UniFont[static_cast(FontType::Caption)]); - QString s = phrase(QStringLiteral("TITLE_RATES")); + QString s = phrases.lookup(QStringLiteral("TITLE_RATES")); risedTextOut(canvas, (width() - biColorTextWidth(canvas, s)) / 2 - 1, 7, s); const bool hasLiberty = ClientTools::myRO->Wonder[woLiberty].EffectiveOwner == ClientTools::me; - s = phrase(hasLiberty ? QStringLiteral("NORATES") : QStringLiteral("RATES")); + s = phrases.lookup(hasLiberty ? QStringLiteral("NORATES") : QStringLiteral("RATES")); canvas.font().assign(UniFont[static_cast(FontType::Normal)]); const int p = s.indexOf(QLatin1Char('\\')); if (p < 0) { @@ -125,7 +108,7 @@ void RatesDlg::offscreenPaint() bitBltBitmap(offscreen, width() / 2 - xSizeBig / 2, 52, xSizeBig, ySizeBig, *bigImp, (woLiberty % 7) * xSizeBig, (woLiberty / 7 + Term::SystemIconLines) * ySizeBig); } else { - s = phrase(QStringLiteral("SCIENCE")); + s = phrases.lookup(QStringLiteral("SCIENCE")); risedTextOut(canvas, 16 + 120 - biColorTextWidth(canvas, s), 44, s); s = QStringLiteral("%1%").arg(100 - ClientTools::myRO->TaxRate - ClientTools::myRO->LuxRate); risedTextOut(canvas, 16 + 120 - biColorTextWidth(canvas, s), 60, s); @@ -145,7 +128,7 @@ void RatesDlg::offscreenPaint() canvas.fillRect(QRect(x, y, max - current, 7)); canvas.brush().setStyle(Qt::NoBrush); - risedTextOut(canvas, 16 + 160, 44, phrase(QStringLiteral("LUX"))); + risedTextOut(canvas, 16 + 160, 44, phrases.lookup(QStringLiteral("LUX"))); s = QStringLiteral("%1%").arg(ClientTools::myRO->LuxRate); risedTextOut(canvas, 16 + 160, 60, s); paintProgressBar(canvas, 5, 16 + 160, 81, ClientTools::myRO->LuxRate * 120 / 100, 0, 120, *MainTexture); @@ -154,7 +137,7 @@ void RatesDlg::offscreenPaint() } dLine(canvas, 1, width() - 2, 154, MainTexture->colorBevelShade, MainTexture->colorBevelLight); - risedTextOut(canvas, 16 + 80, 164, phrase(QStringLiteral("TAXRATE"))); + risedTextOut(canvas, 16 + 80, 164, phrases.lookup(QStringLiteral("TAXRATE"))); s = QStringLiteral("%1%").arg(ClientTools::myRO->TaxRate); risedTextOut(canvas, 16 + 80, 180, s); paintProgressBar(canvas, 0, 16 + 80, 201, ClientTools::myRO->TaxRate * 120 / 100, 0, 120, *MainTexture); diff --git a/game/localplayer/Select.cpp b/game/localplayer/Select.cpp index f39a987..e322c69 100644 --- a/game/localplayer/Select.cpp +++ b/game/localplayer/Select.cpp @@ -62,46 +62,6 @@ bool mustChoose(ListKind kind) return kind == ListKind::Tribe || kind == ListKind::StealTech || kind == ListKind::Government; } -QString phrase(const QString &key) -{ - static const QHash table = { - {QStringLiteral("BTN_IMPRS"), QStringLiteral("Improvements")}, - {QStringLiteral("BTN_WONDERS"), QStringLiteral("Wonders")}, - {QStringLiteral("BTN_CLASSES"), QStringLiteral("Unit classes")}, - {QStringLiteral("BTN_PAGE"), QStringLiteral("Show events")}, - {QStringLiteral("BTN_SELECT"), QStringLiteral("Select player")}, - {QStringLiteral("FARTECH"), QStringLiteral("Research focus")}, - {QStringLiteral("TECHFOCUS"), QStringLiteral("Research focus: %1")}, - {QStringLiteral("TITLE_CITIES"), QStringLiteral("Cities")}, - {QStringLiteral("TITLE_EVENTS"), QStringLiteral("Events (%1)")}, - {QStringLiteral("SHIFTCLICK"), QStringLiteral("Shift+click for more information")}, - {QStringLiteral("CONSCRIPTS"), QStringLiteral("%1 (conscripts)")}, - {QStringLiteral("NATEXISTS"), QStringLiteral("%1 (already built elsewhere)")}, - {QStringLiteral("PRICECAT_ALLMODEL"), QStringLiteral("All unit designs")}, - {QStringLiteral("PRICECAT_ALLTECH"), QStringLiteral("All advances")}, - {QStringLiteral("NEXUS"), QStringLiteral("Galactic Nexus")}, - {QStringLiteral("NOFARTECH"), QStringLiteral("No research focus")}, - {QStringLiteral("INITUNIT"), QStringLiteral("New unit class")}, - {QStringLiteral("SCIENCEREPORT_EXTINCT"), QStringLiteral("%1 (extinct)")}, - {QStringLiteral("TITLE_PROJECT"), QStringLiteral("Choose project")}, - {QStringLiteral("TITLE_TECHSELECT"), QStringLiteral("Choose advance")}, - {QStringLiteral("TITLE_FARTECH"), QStringLiteral("Choose research focus")}, - {QStringLiteral("FRMILREP"), QStringLiteral("Military report")}, - {QStringLiteral("TITLE_EMODELS"), QStringLiteral("Enemy unit designs")}, - {QStringLiteral("TITLE_TRIBE"), QStringLiteral("Choose nation")}, - {QStringLiteral("TITLE_SCIENCE"), QStringLiteral("Science report")}, - {QStringLiteral("TITLE_CHOOSESHIPPART"), QStringLiteral("Choose ship part")}, - {QStringLiteral("TITLE_CHOOSETECH"), QStringLiteral("Choose advance")}, - {QStringLiteral("TITLE_CHOOSEMODEL"), QStringLiteral("Choose unit design")}, - {QStringLiteral("TITLE_GOV"), QStringLiteral("Choose government")}, - {QStringLiteral("TITLE_SPYMISSION"), QStringLiteral("Choose mission")}, - {QStringLiteral("TITLE_CITYNAME"), QStringLiteral("Rename city")}, - {QStringLiteral("TITLE_MODELNAME"), QStringLiteral("Rename unit design")}, - }; - const auto it = table.constFind(key); - return it != table.constEnd() ? *it : key; -} - QString advanceName(int advance) { return phrases.lookup(QStringLiteral("ADVANCES"), advance); @@ -170,9 +130,9 @@ ListDlg::ListDlg(QWidget *parent) : FramedDlg(parent), ui(new Ui::ListDlg) popup = new QMenu(this); - ui->layerImprovementsButton->setToolTip(phrase(QStringLiteral("BTN_IMPRS"))); - ui->layerWondersButton->setToolTip(phrase(QStringLiteral("BTN_WONDERS"))); - ui->layerClassesButton->setToolTip(phrase(QStringLiteral("BTN_CLASSES"))); + ui->layerImprovementsButton->setToolTip(phrases.lookup(QStringLiteral("BTN_IMPRS"))); + ui->layerWondersButton->setToolTip(phrases.lookup(QStringLiteral("BTN_WONDERS"))); + ui->layerClassesButton->setToolTip(phrases.lookup(QStringLiteral("BTN_CLASSES"))); ui->closeBtn->onClick = [this] { closable = true; @@ -317,7 +277,7 @@ bool ListDlg::renameCity(int cix) { const QString oldName = Tribes::cityName(ClientTools::myCity[cix].ID); InputDlg dlg; - dlg.setWindowTitle(phrase(QStringLiteral("TITLE_CITYNAME"))); + dlg.setWindowTitle(phrases.lookup(QStringLiteral("TITLE_CITYNAME"))); dlg.editInput()->setText(oldName); dlg.centerToRect(geometry()); const Dpi::ModalResult result = dlg.showModal(); @@ -338,7 +298,7 @@ bool ListDlg::renameModel(int mix) { const QString oldName = Tribes::tribe[static_cast(ClientTools::me)]->modelNameAt(mix); InputDlg dlg; - dlg.setWindowTitle(phrase(QStringLiteral("TITLE_MODELNAME"))); + dlg.setWindowTitle(phrases.lookup(QStringLiteral("TITLE_MODELNAME"))); dlg.editInput()->setText(oldName); dlg.centerToRect(geometry()); const Dpi::ModalResult result = dlg.showModal(); @@ -955,7 +915,7 @@ void ListDlg::paintLine(Dpi::Canvas &ca, int l, bool nonText, bool lit, bool toW case ListKind::AllEnemyModels: case ListKind::ChooseEnemyModel: if (lix == mixAll) { - s = phrase(QStringLiteral("PRICECAT_ALLMODEL")); + s = phrases.lookup(QStringLiteral("PRICECAT_ALLMODEL")); } else { const TModelInfo &mox = (*ClientTools::myRO->EnemyModel)[lix]; if (Term::mainScreenNamesChecked) { @@ -978,7 +938,7 @@ void ListDlg::paintLine(Dpi::Canvas &ca, int l, bool nonText, bool lit, bool toW break; case ListKind::ChooseModel: if (lix == mixAll) { - s = phrase(QStringLiteral("PRICECAT_ALLMODEL")); + s = phrases.lookup(QStringLiteral("PRICECAT_ALLMODEL")); } else { s = Tribes::tribe[static_cast(ClientTools::me)]->modelNameAt(lix); if (nonText) @@ -991,7 +951,7 @@ void ListDlg::paintLine(Dpi::Canvas &ca, int l, bool nonText, bool lit, bool toW } else if ((lix & cpImp) == 0) { s = Tribes::tribe[static_cast(ClientTools::me)]->modelNameAt(lix & cpIndex); if (lix & cpConscripts) - s = phrase(QStringLiteral("CONSCRIPTS")).arg(s); + s = formatPhrase(QStringLiteral("CONSCRIPTS"), { s }); } else { s = impName(lix & cpIndex); const int iix = lix & cpIndex; @@ -1001,7 +961,7 @@ void ListDlg::paintLine(Dpi::Canvas &ca, int l, bool nonText, bool lit, bool toW ClientTools::myCity[cixProject].Built[imPower] + ClientTools::myCity[cixProject].Built[imHydro] + ClientTools::myCity[cixProject].Built[imNuclear] > 0)) - s = phrase(QStringLiteral("NATEXISTS")).arg(s); + s = formatPhrase(QStringLiteral("NATEXISTS"), { s }); } if (nonText) displayProject(8 + ofs, y0 - 15, lix); @@ -1014,14 +974,14 @@ void ListDlg::paintLine(Dpi::Canvas &ca, int l, bool nonText, bool lit, bool toW case ListKind::ChooseEnemyTech: case ListKind::StealTech: { if (lix == adAll) { - s = phrase(QStringLiteral("PRICECAT_ALLTECH")); + s = phrases.lookup(QStringLiteral("PRICECAT_ALLTECH")); } else { if (lix == Term::adNexus) - s = phrase(QStringLiteral("NEXUS")); + s = phrases.lookup(QStringLiteral("NEXUS")); else if (lix == Term::adNone) - s = phrase(QStringLiteral("NOFARTECH")); + s = phrases.lookup(QStringLiteral("NOFARTECH")); else if (lix == adMilitary) - s = phrase(QStringLiteral("INITUNIT")); + s = phrases.lookup(QStringLiteral("INITUNIT")); else { s = advanceName(lix); if (kind == ListKind::Advance && IsFutureTech(lix)) { @@ -1208,7 +1168,7 @@ void ListDlg::offscreenPaint() Tribes::tribe[static_cast(ClientTools::me)]->tPhrase(QStringLiteral("TITLE_CITIES"))); break; case ListKind::CityEvents: - setWindowTitle(phrase(QStringLiteral("TITLE_EVENTS")).arg(Term::turnToString(ClientTools::myRO->Turn))); + setWindowTitle(formatPhrase(QStringLiteral("TITLE_EVENTS"), { Term::turnToString(ClientTools::myRO->Turn) })); break; default: break; @@ -1268,45 +1228,45 @@ void ListDlg::showNewContent(WindowMode newMode, ListKind listKind) modalIndication = !mustChoose(kind); switch (kind) { case ListKind::Project: - setWindowTitle(phrase(QStringLiteral("TITLE_PROJECT"))); + setWindowTitle(phrases.lookup(QStringLiteral("TITLE_PROJECT"))); break; case ListKind::Advance: - setWindowTitle(phrase(QStringLiteral("TITLE_TECHSELECT"))); + setWindowTitle(phrases.lookup(QStringLiteral("TITLE_TECHSELECT"))); break; case ListKind::FarAdvance: - setWindowTitle(phrase(QStringLiteral("TITLE_FARTECH"))); + setWindowTitle(phrases.lookup(QStringLiteral("TITLE_FARTECH"))); break; case ListKind::Models: case ListKind::EnemyModels: - setWindowTitle(phrase(QStringLiteral("FRMILREP"))); + setWindowTitle(phrases.lookup(QStringLiteral("FRMILREP"))); break; case ListKind::AllEnemyModels: - setWindowTitle(phrase(QStringLiteral("TITLE_EMODELS"))); + setWindowTitle(phrases.lookup(QStringLiteral("TITLE_EMODELS"))); break; case ListKind::Tribe: - setWindowTitle(phrase(QStringLiteral("TITLE_TRIBE"))); + setWindowTitle(phrases.lookup(QStringLiteral("TITLE_TRIBE"))); break; case ListKind::Science: - setWindowTitle(phrase(QStringLiteral("TITLE_SCIENCE"))); + setWindowTitle(phrases.lookup(QStringLiteral("TITLE_SCIENCE"))); break; case ListKind::ShipPart: case ListKind::EnemyShipPart: - setWindowTitle(phrase(QStringLiteral("TITLE_CHOOSESHIPPART"))); + setWindowTitle(phrases.lookup(QStringLiteral("TITLE_CHOOSESHIPPART"))); break; case ListKind::ChooseTech: case ListKind::ChooseEnemyTech: case ListKind::StealTech: - setWindowTitle(phrase(QStringLiteral("TITLE_CHOOSETECH"))); + setWindowTitle(phrases.lookup(QStringLiteral("TITLE_CHOOSETECH"))); break; case ListKind::ChooseModel: case ListKind::ChooseEnemyModel: - setWindowTitle(phrase(QStringLiteral("TITLE_CHOOSEMODEL"))); + setWindowTitle(phrases.lookup(QStringLiteral("TITLE_CHOOSEMODEL"))); break; case ListKind::Government: - setWindowTitle(phrase(QStringLiteral("TITLE_GOV"))); + setWindowTitle(phrases.lookup(QStringLiteral("TITLE_GOV"))); break; case ListKind::Mission: - setWindowTitle(phrase(QStringLiteral("TITLE_SPYMISSION"))); + setWindowTitle(phrases.lookup(QStringLiteral("TITLE_SPYMISSION"))); break; default: break; @@ -1316,13 +1276,13 @@ void ListDlg::showNewContent(WindowMode newMode, ListKind listKind) if (kind == ListKind::Advance) { ui->toggleBtn->setButtonIndex(13); - ui->toggleBtn->setToolTip(phrase(QStringLiteral("FARTECH"))); + ui->toggleBtn->setToolTip(phrases.lookup(QStringLiteral("FARTECH"))); } else if (kind == ListKind::Cities) { ui->toggleBtn->setButtonIndex(15); - ui->toggleBtn->setToolTip(phrase(QStringLiteral("BTN_PAGE"))); + ui->toggleBtn->setToolTip(phrases.lookup(QStringLiteral("BTN_PAGE"))); } else { ui->toggleBtn->setButtonIndex(28); - ui->toggleBtn->setToolTip(phrase(QStringLiteral("BTN_SELECT"))); + ui->toggleBtn->setToolTip(phrases.lookup(QStringLiteral("BTN_SELECT"))); } bool showFocus = false; @@ -1616,7 +1576,7 @@ void ListDlg::mouseMoveEvent(QMouseEvent *event) if (scienceNation >= 0) { QString s = Tribes::tribe[static_cast(scienceNation)]->tPhrase(QStringLiteral("SHORTNAME")); if ((ClientTools::myRO->Alive & (1 << scienceNation)) == 0) - s = phrase(QStringLiteral("SCIENCEREPORT_EXTINCT")).arg(s); + s = formatPhrase(QStringLiteral("SCIENCEREPORT_EXTINCT"), { s }); else if (ClientTools::myRO->EnemyReport[scienceNation]->TurnOfCivilReport < ClientTools::myRO->Turn - 1) s += QStringLiteral(" (%1)").arg( Term::turnToString(ClientTools::myRO->EnemyReport[scienceNation]->TurnOfCivilReport)); diff --git a/game/localplayer/UnitStat.cpp b/game/localplayer/UnitStat.cpp index 2ac41c3..af2329d 100644 --- a/game/localplayer/UnitStat.cpp +++ b/game/localplayer/UnitStat.cpp @@ -36,8 +36,6 @@ #include "Term.h" #include "Tribes.h" -#include - namespace Cevo { namespace UnitStat { @@ -59,38 +57,11 @@ constexpr int hEnemyCityDefense = 320; constexpr int hEnemyCity = 166; constexpr int hMax = 320; -// Phrases/Phrases2 (StringTables.pas) aren't ported; disclosed -// plain-English placeholders for this dialog's own text. -QString phrase(const QString &key) -{ - static const QHash table = { - {QStringLiteral("UNITSPECIAL"), QStringLiteral("Special unit")}, - {QStringLiteral("CONTROLS6"), QStringLiteral("Special unit controls")}, - {QStringLiteral("UNITSTRENGTH"), QStringLiteral("Attack/Defense")}, - {QStringLiteral("UNITSPEED"), QStringLiteral("Speed")}, - {QStringLiteral("UNITCOST"), QStringLiteral("Cost")}, - {QStringLiteral("UNITADOPT"), QStringLiteral("Adopted")}, - {QStringLiteral("UNITINTRO"), QStringLiteral("Introduced")}, - {QStringLiteral("UNITBUILT"), QStringLiteral("Built")}, - {QStringLiteral("UNITLOST"), QStringLiteral("Lost")}, - {QStringLiteral("UNITINPROD"), QStringLiteral("In production")}, - {QStringLiteral("UNITAVAILABLE"), QStringLiteral("Available")}, - {QStringLiteral("UNITDESTROYED"), QStringLiteral("Destroyed")}, - {QStringLiteral("UNITKNOWN"), QStringLiteral("Known")}, - {QStringLiteral("BTN_OBSOLETE"), QStringLiteral("Mark as obsolete")}, - {QStringLiteral("BTN_NONOBSOLETE"), QStringLiteral("Mark as not obsolete")}, - {QStringLiteral("BTN_NOCONSCRIPTS"), QStringLiteral("Allow conscripts")}, - {QStringLiteral("BTN_ALLOWCONSCRIPTS"), QStringLiteral("Disallow conscripts")}, - }; - const auto it = table.constFind(key); - return it != table.constEnd() ? it.value() : key; -} - void featureBar(Dpi::Canvas &canvas, int x, int y, const TModelInfo &mi, const Texture &) { darkGradient(canvas, x - 6, y + 1, 180, 1); if (mi.Kind >= 0x10) { - const QString s = phrase(QStringLiteral("UNITSPECIAL")); + const QString s = phrases.lookup(QStringLiteral("UNITSPECIAL")); canvas.font().setColor(Qt::black); canvas.textOut(x - 1, y + 1, s); canvas.font().setColor(QColor(0xB0, 0xB0, 0xB0)); @@ -159,20 +130,20 @@ UnitStatDlg::UnitStatDlg(QWidget *parent) : BufferedDrawDlg(parent), ui(new Ui:: ClientTools::myModel[mixShow].Status ^= Term::msObsolete; if (ClientTools::myModel[mixShow].Status & Term::msObsolete) { ui->switchBtn->setButtonIndex(12); - ui->switchBtn->setToolTip(phrase(QStringLiteral("BTN_OBSOLETE"))); + ui->switchBtn->setToolTip(phrases.lookup(QStringLiteral("BTN_OBSOLETE"))); } else { ui->switchBtn->setButtonIndex(11); - ui->switchBtn->setToolTip(phrase(QStringLiteral("BTN_NONOBSOLETE"))); + ui->switchBtn->setToolTip(phrases.lookup(QStringLiteral("BTN_NONOBSOLETE"))); } }; ui->conscriptsBtn->onClick = [this] { ClientTools::myModel[mixShow].Status ^= Term::msAllowConscripts; if ((ClientTools::myModel[mixShow].Status & Term::msAllowConscripts) == 0) { ui->conscriptsBtn->setButtonIndex(30); - ui->conscriptsBtn->setToolTip(phrase(QStringLiteral("BTN_NOCONSCRIPTS"))); + ui->conscriptsBtn->setToolTip(phrases.lookup(QStringLiteral("BTN_NOCONSCRIPTS"))); } else { ui->conscriptsBtn->setButtonIndex(29); - ui->conscriptsBtn->setToolTip(phrase(QStringLiteral("BTN_ALLOWCONSCRIPTS"))); + ui->conscriptsBtn->setToolTip(phrases.lookup(QStringLiteral("BTN_ALLOWCONSCRIPTS"))); } }; ui->helpBtn->onClick = [this] { @@ -263,7 +234,7 @@ UnitStatDlg::UnitStatDlg(QWidget *parent) : BufferedDrawDlg(parent), ui(new Ui:: setWindowTitle(Tribes::tribe[owner]->tPhrase(QStringLiteral("GENMODEL")).arg(mix)); } if (isSpecialUnit) - ui->helpBtn->setToolTip(phrase(QStringLiteral("CONTROLS6"))); + ui->helpBtn->setToolTip(phrases.lookup(QStringLiteral("CONTROLS"), 6)); ui->helpBtn->setVisible(isSpecialUnit); offscreenPaint(); }; @@ -540,13 +511,13 @@ void UnitStatDlg::offscreenPaint() } darkGradient(canvas, xTotal - 6, yTotal + 1, 180, 2); - risedTextOut(canvas, xTotal - 2, yTotal, phrase(QStringLiteral("UNITSTRENGTH"))); + risedTextOut(canvas, xTotal - 2, yTotal, phrases.lookup(QStringLiteral("UNITSTRENGTH"))); QString s = QString::number(mi.Attack) + QLatin1Char('/') + QString::number(mi.Defense); risedTextOut(canvas, xTotal + 170 - biColorTextWidth(canvas, s), yTotal, s); featureBar(canvas, xTotal, yTotal + 19, mi, *MainTexture); - numberBarS(canvas, xTotal, yTotal + 38, phrase(QStringLiteral("UNITSPEED")), movementToString(mi.Speed), + numberBarS(canvas, xTotal, yTotal + 38, phrases.lookup(QStringLiteral("UNITSPEED")), movementToString(mi.Speed), *MainTexture); - loweredTextOut(canvas, -1, *MainTexture, xTotal - 2, yTotal + 57, phrase(QStringLiteral("UNITCOST"))); + loweredTextOut(canvas, -1, *MainTexture, xTotal - 2, yTotal + 57, phrases.lookup(QStringLiteral("UNITCOST"))); dLine(canvas, xTotal - 2, xTotal + 170, yTotal + 57 + 16, MainTexture->colorBevelShade, MainTexture->colorBevelLight); s = ClientTools::g.Difficulty[ClientTools::me] == 0 @@ -559,7 +530,7 @@ void UnitStatDlg::offscreenPaint() const TModel &m = ClientTools::myModel[mixShow]; if (m.IntroTurn > 0) { loweredTextOut(canvas, -1, *MainTexture, xTotal - 2, yTotal + StatDown - 19, - phrase(m.Kind == mkEnemyDeveloped ? QStringLiteral("UNITADOPT") + phrases.lookup(m.Kind == mkEnemyDeveloped ? QStringLiteral("UNITADOPT") : QStringLiteral("UNITINTRO"))); dLine(canvas, xTotal - 2, xTotal + 170, (yTotal + StatDown - 19) + 16, MainTexture->colorTextShade, MainTexture->colorTextLight); @@ -567,37 +538,37 @@ void UnitStatDlg::offscreenPaint() risedTextOut(canvas, xTotal + 170 - biColorTextWidth(canvas, introS), yTotal + StatDown - 19, introS); } - numberBar(canvas, xTotal, yTotal + StatDown, phrase(QStringLiteral("UNITBUILT")), m.Built, *MainTexture); + numberBar(canvas, xTotal, yTotal + StatDown, phrases.lookup(QStringLiteral("UNITBUILT")), m.Built, *MainTexture); if (m.Lost > 0) - numberBar(canvas, xTotal, yTotal + StatDown + 19, phrase(QStringLiteral("UNITLOST")), m.Lost, + numberBar(canvas, xTotal, yTotal + StatDown + 19, phrases.lookup(QStringLiteral("UNITLOST")), m.Lost, *MainTexture); if (inProd > 0) - numberBar(canvas, xTotal, yTotal + StatDown + 57, phrase(QStringLiteral("UNITINPROD")), inProd, + numberBar(canvas, xTotal, yTotal + StatDown + 57, phrases.lookup(QStringLiteral("UNITINPROD")), inProd, *MainTexture); if (available > 0) - numberBar(canvas, xTotal, yTotal + StatDown + 38, phrase(QStringLiteral("UNITAVAILABLE")), available, + numberBar(canvas, xTotal, yTotal + StatDown + 38, phrases.lookup(QStringLiteral("UNITAVAILABLE")), available, *MainTexture); if (m.Status & Term::msObsolete) { ui->switchBtn->setButtonIndex(12); - ui->switchBtn->setToolTip(phrase(QStringLiteral("BTN_OBSOLETE"))); + ui->switchBtn->setToolTip(phrases.lookup(QStringLiteral("BTN_OBSOLETE"))); } else { ui->switchBtn->setButtonIndex(11); - ui->switchBtn->setToolTip(phrase(QStringLiteral("BTN_NONOBSOLETE"))); + ui->switchBtn->setToolTip(phrases.lookup(QStringLiteral("BTN_NONOBSOLETE"))); } if ((m.Status & Term::msAllowConscripts) == 0) { ui->conscriptsBtn->setButtonIndex(30); - ui->conscriptsBtn->setToolTip(phrase(QStringLiteral("BTN_NOCONSCRIPTS"))); + ui->conscriptsBtn->setToolTip(phrases.lookup(QStringLiteral("BTN_NOCONSCRIPTS"))); } else { ui->conscriptsBtn->setButtonIndex(29); - ui->conscriptsBtn->setToolTip(phrase(QStringLiteral("BTN_ALLOWCONSCRIPTS"))); + ui->conscriptsBtn->setToolTip(phrases.lookup(QStringLiteral("BTN_ALLOWCONSCRIPTS"))); } } else if (kind == UnitStatDialogKind::EnemyModel) { if (destroyed > 0) - numberBar(canvas, xTotal, yTotal + StatDown - 19, phrase(QStringLiteral("UNITDESTROYED")), destroyed, + numberBar(canvas, xTotal, yTotal + StatDown - 19, phrases.lookup(QStringLiteral("UNITDESTROYED")), destroyed, *MainTexture); if (available > 0) - numberBar(canvas, xTotal, yTotal + StatDown, phrase(QStringLiteral("UNITKNOWN")), available, + numberBar(canvas, xTotal, yTotal + StatDown, phrases.lookup(QStringLiteral("UNITKNOWN")), available, *MainTexture); } } diff --git a/game/localplayer/Wonders.cpp b/game/localplayer/Wonders.cpp index a56af94..2073f98 100644 --- a/game/localplayer/Wonders.cpp +++ b/game/localplayer/Wonders.cpp @@ -39,7 +39,6 @@ #include "Dpi/DpiPixelPointer.h" -#include #include namespace Cevo { @@ -71,20 +70,6 @@ constexpr QPoint RingPosition[21] = { QPoint(160, 64), // Mir }; -// Phrases/Phrases2 (StringTables.pas) aren't ported; disclosed -// plain-English placeholders for this dialog's own text. -QString phrase(const QString &key) -{ - static const QHash table = { - {QStringLiteral("TITLE_WONDERS"), QStringLiteral("World Wonders")}, - {QStringLiteral("NOWONDER"), QStringLiteral("No wonder built yet")}, - {QStringLiteral("DESTROYED"), QStringLiteral("Destroyed")}, - {QStringLiteral("EXPIRED"), QStringLiteral("Expired")}, - }; - const auto it = table.constFind(key); - return it != table.constEnd() ? it.value() : key; -} - } // namespace WondersDlg::WondersDlg(QWidget *parent) : BufferedDrawDlg(parent), ui(new Ui::WondersDlg) @@ -94,7 +79,7 @@ WondersDlg::WondersDlg(QWidget *parent) : BufferedDrawDlg(parent), ui(new Ui::Wo ui->closeBtn->onClick = [this] { close(); }; initButtons(); onShow = [this] { - setWindowTitle(phrase(QStringLiteral("TITLE_WONDERS"))); + setWindowTitle(phrases.lookup(QStringLiteral("TITLE_WONDERS"))); selection = -1; offscreenPaint(); }; @@ -206,7 +191,7 @@ void WondersDlg::offscreenPaint() btnFrame(canvas, ui->closeBtn->geometry(), *MainTexture); canvas.font().assign(UniFont[static_cast(FontType::Caption)]); - QString s = phrase(QStringLiteral("TITLE_WONDERS")); + QString s = phrases.lookup(QStringLiteral("TITLE_WONDERS")); risedTextOut(canvas, (width() - biColorTextWidth(canvas, s)) / 2 - 1, 7, s); canvas.font().assign(UniFont[static_cast(FontType::Normal)]); @@ -258,7 +243,7 @@ void WondersDlg::offscreenPaint() } if (!haveWonder) { - s = phrase(QStringLiteral("NOWONDER")); + s = phrases.lookup(QStringLiteral("NOWONDER")); risedTextOut(canvas, center.x() - biColorTextWidth(canvas, s) / 2, center.y() - canvas.textHeight(s) / 2, s); } canvas.end(); @@ -278,9 +263,9 @@ void WondersDlg::vpaint(Dpi::Canvas &canvas) loweredTextOut(canvas, -1, *MainTexture, (width() - biColorTextWidth(canvas, s)) / 2, height() - 3 - 36 - 10, s); if (ClientTools::myRO->Wonder[selection].CityID == WonderDestroyed) - s = phrase(QStringLiteral("DESTROYED")); + s = phrases.lookup(QStringLiteral("DESTROYED")); else if (ClientTools::myRO->Wonder[selection].EffectiveOwner < 0) - s = phrase(QStringLiteral("EXPIRED")); + s = phrases.lookup(QStringLiteral("EXPIRED")); else s = Tribes::tribe[static_cast(ClientTools::myRO->Wonder[selection].EffectiveOwner)]->tPhrase( QStringLiteral("WONDEROWNER"));