From daa1d9056e26c9075abc38048bec91f52f69cc8f Mon Sep 17 00:00:00 2001 From: Geoffray Levasseur Date: Sat, 7 Nov 2026 01:19:27 +0100 Subject: [PATCH] finish city improvment --- game/localplayer/CityScreen.cpp | 4 +- game/localplayer/CityType.cpp | 11 ++--- game/localplayer/Help.cpp | 83 +++++++++++++++++++++++++++++++++ game/localplayer/Help.h | 2 + game/localplayer/Select.cpp | 2 +- 5 files changed, 91 insertions(+), 11 deletions(-) diff --git a/game/localplayer/CityScreen.cpp b/game/localplayer/CityScreen.cpp index 6627bee..53f87be 100644 --- a/game/localplayer/CityScreen.cpp +++ b/game/localplayer/CityScreen.cpp @@ -148,7 +148,7 @@ QString phrase(const QString &key) QString impName(int iix) { - return QStringLiteral("Improvement #%1").arg(iix); + return phrases.lookup(QStringLiteral("IMPROVEMENTS"), iix); } QString modelName(int cOwner, int mix) @@ -158,7 +158,7 @@ QString modelName(int cOwner, int mix) QString governmentName(int gov) { - return QStringLiteral("Government #%1").arg(gov); + return phrases.lookup(QStringLiteral("GOVERNMENT"), gov); } void play(const QString &item) diff --git a/game/localplayer/CityType.cpp b/game/localplayer/CityType.cpp index c3f824d..5303f4e 100644 --- a/game/localplayer/CityType.cpp +++ b/game/localplayer/CityType.cpp @@ -32,6 +32,7 @@ #include "Cevo/CevoScreenTools.h" #include "Cevo/CevoTexture.h" #include "ClientTools.h" +#include "Global.h" #include "Term.h" #include @@ -58,18 +59,12 @@ QString phrase(const QString &key) QString phraseCityType(int ctype) { - static const QHash table = { - {0, QStringLiteral("Type A")}, {1, QStringLiteral("Type B")}, - {2, QStringLiteral("Type C")}, {3, QStringLiteral("Type D")}, - }; - const auto it = table.constFind(ctype); - return it != table.constEnd() ? it.value() : QString(); + return phrases.lookup(QStringLiteral("CITYTYPE"), ctype); } QString phraseImprovement(int iix) { - // Imp[]'s display names (StringTables.pas) aren't ported. - return QStringLiteral("Improvement #%1").arg(iix); + return phrases.lookup(QStringLiteral("IMPROVEMENTS"), iix); } constexpr int xList = 7; diff --git a/game/localplayer/Help.cpp b/game/localplayer/Help.cpp index 15fa5ab..30c1172 100644 --- a/game/localplayer/Help.cpp +++ b/game/localplayer/Help.cpp @@ -43,6 +43,7 @@ #include "Cevo/CevoScreenTools.h" #include "Cevo/Protocol.h" +#include "ClientTools.h" #include "Global.h" #include "Inp.h" #include "KeyBindings.h" @@ -214,6 +215,8 @@ void HelpDlg::prepare(int sbPos) mainText.appendList(searchResult); } else if (kind == LinkCategory::Adv && no >= 0 && no < nAdv) { prepareAdvance(no); + } else if (kind == LinkCategory::Imp && no >= 0 && no < nImp) { + prepareImprovement(no); } else { mainText.addLine(QStringLiteral("Detailed help content isn't available in this build.")); } @@ -299,6 +302,86 @@ void HelpDlg::prepareAdvance(int advance) addSection(QStringLiteral("FOLLOWADV"), follow); } +void HelpDlg::prepareImprovement(int imp) +{ + const auto addSection = [this](const QString &headerKey, const HyperText &entries) { + if (entries.count() == 0) + return; + mainText.lineFeed(); + mainText.addLine(helpText.lookup(headerKey), TextFormat::Section); + mainText.appendList(entries); + }; + const auto formatD = [](QString fmt, int value) { + fmt.replace(QStringLiteral("%d"), QString::number(value)); + fmt.replace(QStringLiteral("%%"), QStringLiteral("%")); + return fmt; + }; + const auto formatS = [](QString fmt, const QString &value) { + fmt.replace(QStringLiteral("%s"), value); + fmt.replace(QStringLiteral("%%"), QStringLiteral("%")); + return fmt; + }; + + switch (Imp[imp].Kind) { + case ikWonder: mainText.addLine(helpText.lookup(QStringLiteral("HELPSPEC_WONDER"))); break; + case ikCommon: mainText.addLine(helpText.lookup(QStringLiteral("HELPSPEC_IMP"))); break; + case ikShipPart: mainText.addLine(helpText.lookup(QStringLiteral("HELPSPEC_SHIPPART"))); break; + default: mainText.addLine(helpText.lookup(QStringLiteral("HELPSPEC_NAT"))); break; + } + + if (Imp[imp].Kind != ikShipPart) { + const QString effect = helpText.lookup(QStringLiteral("IMPHELP"), imp); + if (!effect.isEmpty()) { + mainText.lineFeed(); + mainText.addLine(helpText.lookup(QStringLiteral("EFFECT")), TextFormat::Section); + mainText.addLine(effect); + } + } + + HyperText preqs; + if (Imp[imp].Preq != preNone) + preqs.addLine(phrases.lookup(QStringLiteral("ADVANCES"), Imp[imp].Preq), TextFormat::AdvIconAsPreq, 0, + LinkCategory::Adv, Imp[imp].Preq, true); + addSection(QStringLiteral("PREREQ"), preqs); + + mainText.lineFeed(); + mainText.addLine(helpText.lookup(QStringLiteral("COSTS")), TextFormat::Section); + const int difficulty = ClientTools::g.Difficulty[ClientTools::me]; + const int cost = difficulty == 0 ? Imp[imp].Cost : Imp[imp].Cost * BuildCostMod[difficulty] / 12; + mainText.addLine(formatD(helpText.lookup(QStringLiteral("BUILDCOST")), cost)); + if (Imp[imp].Maint > 0) + mainText.addLine(formatD(helpText.lookup(QStringLiteral("MAINTCOST")), Imp[imp].Maint)); + + HyperText replaces; + for (int i = 0; i < nImpReplacement; ++i) { + if (ImpReplacement[i].NewImp == imp) + replaces.addLine(phrases.lookup(QStringLiteral("IMPROVEMENTS"), ImpReplacement[i].OldImp), + TextFormat::SmallIcon, 0, LinkCategory::Imp, ImpReplacement[i].OldImp, true); + } + addSection(QStringLiteral("REPLACE"), replaces); + + if (imp < nWonder && Imp[imp].Expiration >= 0) { + mainText.lineFeed(); + mainText.addLine(helpText.lookup(QStringLiteral("EXPIRATION")), TextFormat::Section); + mainText.addLine(formatS(helpText.lookup(QStringLiteral("EXPWITH")), + phrases.lookup(QStringLiteral("ADVANCES"), Imp[imp].Expiration))); + } + + HyperText seeAlso; + if (imp < nWonder && Imp[imp].Expiration >= 0) + seeAlso.addLine(phrases.lookup(QStringLiteral("IMPROVEMENTS"), woEiffel), TextFormat::SmallIcon, 0, + LinkCategory::Imp, woEiffel, true); + for (int i = 0; i < nImpReplacement; ++i) { + if (ImpReplacement[i].OldImp == imp) + seeAlso.addLine(phrases.lookup(QStringLiteral("IMPROVEMENTS"), ImpReplacement[i].NewImp), + TextFormat::SmallIcon, 0, LinkCategory::Imp, ImpReplacement[i].NewImp, true); + } + if (imp == imSupermarket) + seeAlso.addLine(helpText.lookup(QStringLiteral("HELPTITLE_JOBLIST")), TextFormat::Normal, 0, + LinkCategory::Misc, static_cast(MiscLinkIndex::JobList), true); + addSection(QStringLiteral("SEEALSO"), seeAlso); +} + void HelpDlg::line(Dpi::Canvas &canvas, int i, bool lit) { const int idx = scrollBar->position() + i; diff --git a/game/localplayer/Help.h b/game/localplayer/Help.h index 3b36d5b..723a85b 100644 --- a/game/localplayer/Help.h +++ b/game/localplayer/Help.h @@ -137,6 +137,8 @@ private: // THelpDlg.Prepare's hkAdv branch): prerequisites, and what the advance // newly allows (governments/improvements/features/further research). void prepareAdvance(int advance); + // Same idea as prepareAdvance(), for LinkCategory::Imp pages. + void prepareImprovement(int imp); void search(const QString &searchString); void line(Dpi::Canvas &canvas, int i, bool lit); void paintTerrIcon(int x, int y, int xSrc, int ySrc); diff --git a/game/localplayer/Select.cpp b/game/localplayer/Select.cpp index acb4a85..3e1ca04 100644 --- a/game/localplayer/Select.cpp +++ b/game/localplayer/Select.cpp @@ -987,7 +987,7 @@ void ListDlg::paintLine(Dpi::Canvas &ca, int l, bool nonText, bool lit, bool toW break; case ListKind::Project: { if (lix & cpType) { - s = impName(lix & cpIndex); // CITYTYPE phrase not ported; reuses imp placeholder naming + s = phrases.lookup(QStringLiteral("CITYTYPE"), lix & cpIndex); } else if ((lix & cpImp) == 0) { s = Tribes::tribe[static_cast(ClientTools::me)]->modelNameAt(lix & cpIndex); if (lix & cpConscripts)