// This file is part of c-evo-evo. // // This software is governed by the CeCILL license under French law and // abiding by the rules of distribution of free software. You can use, // modify and/or redistribute the software under the terms of the CeCILL // license as circulated by CEA, CNRS and INRIA at the following URL // "http://www.cecill.info". // // As a counterpart to the access to the source code and rights to copy, // modify and redistribute granted by the license, users are provided only // with a limited warranty and the software's author, the holder of the // economic rights, and the successive licensors have only limited // liability. // // In this respect, the user's attention is drawn to the risks associated // with loading, using, modifying and/or developing or reproducing the // software by the user in light of its specific status of free software, // that may mean that it is complicated to manipulate, and that also // therefore means that it is reserved for developers and experienced // professionals having in-depth computer knowledge. Users are therefore // encouraged to load and test the software's suitability as regards their // requirements in conditions enabling the security of their systems and/or // data to be ensured and, more generally, to use and operate it in the // same conditions as regards security. // // The fact that you are presently reading this means that you have had // knowledge of the CeCILL license and that you accept its terms. // PORT STATUS (see /memories/repo/cevo-evo-game.md): Help.pas is 2297 // lines; this is a deliberately SIMPLIFIED port. The navigation/history/ // search-plumbing/scrolling/link-click machinery is faithful. The real // Help/Help.txt content is loaded (resources/Help/Help.txt is shipped) and // used via the StringTable `helpText`/the global `phrases`. prepareAdvance() // renders a reasonably faithful LinkCategory::Adv page (prereqs/governments/ // improvements/features/follow-on research it unlocks). Other categories // (Imp/Ter/Feature/Model/Text) still render a plain placeholder paragraph // instead of the original's full icon-rich, per-TextFormat layout engine // (pkAdvIcon/pkBigIcon/pkTer/pkModel/...); extend prepare() similarly if // needed. waterSign()/paintTerrIcon() (cosmetic pixel effects) are no-ops. #include "Help.h" #include "ui_Help.h" #include "Cevo/CevoScreenTools.h" #include "Cevo/Protocol.h" #include "ClientTools.h" #include "Global.h" #include "Inp.h" #include "KeyBindings.h" #include "Messg.h" #include "Term.h" #include #include #include #include #include #include #include namespace Cevo { namespace Help { std::function showNewContent; namespace { constexpr int MaxHist = 16; // 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 // with more than one placeholder, e.g. "#STRENGTH Strength: %d/%d"). QString formatArgs(const QString &fmt, const QStringList &args) { QString result; result.reserve(fmt.size()); int argIndex = 0; for (int i = 0; i < fmt.size(); ++i) { if (fmt.at(i) == QLatin1Char('%') && i + 1 < fmt.size()) { const QChar next = fmt.at(i + 1); if ((next == QLatin1Char('d') || next == QLatin1Char('s')) && argIndex < args.size()) { result += args.at(argIndex++); ++i; continue; } if (next == QLatin1Char('%')) { result += QLatin1Char('%'); ++i; continue; } } result += fmt.at(i); } return result; } QString formatD(const QString &fmt, int value) { return formatArgs(fmt, { QString::number(value) }); } QString formatS(const QString &fmt, const QString &value) { return formatArgs(fmt, { value }); } // Help.pas's `TerrainHelp` (the fixed display order for the "complete // terrain type list" page). constexpr int TerrainHelp[] = { fGrass, fGrass + 12, fPrairie, fForest, Term::fJungle, fHills, fMountains, fSwamp, fTundra, fArctic, fDesert, 3 * 12, fShore, fOcean }; // Help.pas's `JobHelp` (the fixed display order for the terrain-jobs list). constexpr int JobHelp[] = { jRoad, jRR, jCanal, jIrr, jFarm, jMine, jFort, jBase }; // Help.pas's `SeeAlso` table: hand-authored extra cross-references shown // in a page's "See Also" section beyond what's derivable algorithmically. struct SeeAlsoEntry { LinkCategory kind; int no; LinkCategory seeKind; int seeNo; }; constexpr SeeAlsoEntry SeeAlsoTable[] = { { LinkCategory::Imp, imWalls, LinkCategory::Feature, mcArtillery }, { LinkCategory::Imp, imHydro, LinkCategory::Imp, woHoover }, { LinkCategory::Imp, imHighways, LinkCategory::Adv, adWheel }, { LinkCategory::Imp, imCathedral, LinkCategory::Imp, woBach }, { LinkCategory::Imp, imBank, LinkCategory::Imp, imStockEx }, { LinkCategory::Imp, imShipComp, LinkCategory::Imp, imSpacePort }, { LinkCategory::Imp, imShipPow, LinkCategory::Imp, imSpacePort }, { LinkCategory::Imp, imShipHab, LinkCategory::Imp, imSpacePort }, { LinkCategory::Feature, mcSub, LinkCategory::Feature, mcRadar }, { LinkCategory::Feature, mcDefense, LinkCategory::Adv, adSteel }, { LinkCategory::Feature, mcSE, LinkCategory::Feature, mcNP }, { LinkCategory::Adv, adWheel, LinkCategory::Imp, imHighways }, { LinkCategory::Adv, adSteel, LinkCategory::Feature, mcDefense }, }; // Appends this page's hand-authored extra "See Also" cross-references (if // any) onto `list`. void appendSeeAlsoEntries(HyperText &list, LinkCategory kind, int no) { for (const SeeAlsoEntry &entry : SeeAlsoTable) { if (entry.kind != kind || entry.no != no) continue; switch (entry.seeKind) { case LinkCategory::Imp: list.addLine(phrases.lookup(QStringLiteral("IMPROVEMENTS"), entry.seeNo), TextFormat::SmallIcon, 0, LinkCategory::Imp, entry.seeNo, true); break; case LinkCategory::Adv: list.addLine(phrases.lookup(QStringLiteral("ADVANCES"), entry.seeNo), TextFormat::AdvIcon, 0, LinkCategory::Adv, entry.seeNo, true); break; case LinkCategory::Feature: list.addLine(phrases.lookup(QStringLiteral("FEATURES"), entry.seeNo), TextFormat::Feature, 0, LinkCategory::Feature, entry.seeNo, true); break; default: break; } } } } // namespace void HyperText::addLine(const QString &s, TextFormat format, int picPix, LinkCategory linkCategory, int linkIndex, bool crossLink) { m_lines.push_back(s); HelpLineInfo info; info.format = format; info.picPix = picPix; info.category = linkCategory; info.index = linkIndex; info.crossLink = crossLink; m_info.push_back(info); } void HyperText::appendList(const HyperText &source) { for (int i = 0; i < source.count(); ++i) { m_lines.push_back(source.text(i)); m_info.push_back(source.info(i)); } } void HyperText::clear() { m_lines.clear(); m_info.clear(); } HelpDlg::HelpDlg(QWidget *parent) : FramedDlg(parent), ui(new Ui::HelpDlg) { ui->setupUi(this); initButtons(); ui->closeBtn->setButtonIndex(0); ui->backBtn->setButtonIndex(6); ui->topBtn->setButtonIndex(7); ui->searchBtn->setButtonIndex(18); captionLeft = ui->backBtn->x() + ui->backBtn->width(); captionRight = ui->searchBtn->x(); modalFrameIndent += 29; scrollBar = new PVScrollBar(this); scrollBar->setBorderSpacing(36, 9, 11); connect(scrollBar, &PVScrollBar::updated, this, [this] { sel = -1; smartUpdateContent(true); }); 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->closeBtn->onClick = [this] { close(); }; ui->backBtn->onClick = [this] { backBtnClicked(); }; ui->topBtn->onClick = [this] { topBtnClicked(); }; ui->searchBtn->onClick = [this] { searchBtnClicked(); }; showNewContentHook = [this](WindowMode mode, const QString &context) { showNewContent(mode, LinkCategory::Text, textIndex(context)); }; Cevo::Help::showNewContent = [this](WindowMode mode, LinkCategory category, int index) { showNewContent(mode, category, index); }; } HelpDlg::~HelpDlg() { showNewContentHook = nullptr; Cevo::Help::showNewContent = nullptr; delete ui; } void HelpDlg::showNewContent(WindowMode newMode, LinkCategory category, int index) { if (category != kind || index != no || (category == LinkCategory::Misc && index == static_cast(MiscLinkIndex::SearchResult))) { if (static_cast(histItems.size()) == MaxHist) histItems.erase(histItems.begin()); HistItem item; if (histItems.empty()) { item.kind = category; item.no = index; item.searchContent = newSearchContent; } else { item.kind = kind; item.no = no; item.searchContent = searchContent; } item.pos = scrollBar->position(); histItems.push_back(item); } kind = category; no = index; searchContent = newSearchContent; prepare(); offscreenPaint(); FramedDlg::showNewContent(newMode); } void HelpDlg::prepare(int sbPos) { mainText.clear(); QString title; switch (kind) { case LinkCategory::Adv: title = phrases.lookup(QStringLiteral("ADVANCES"), no); break; case LinkCategory::Imp: title = phrases.lookup(QStringLiteral("IMPROVEMENTS"), no); break; case LinkCategory::Ter: title = no == 200 ? helpText.lookup(QStringLiteral("HELPTITLE_TERLIST")) : phrases.lookup(QStringLiteral("TERRAIN"), no); break; case LinkCategory::Feature: title = no == 200 ? helpText.lookup(QStringLiteral("HELPTITLE_FEATURELIST")) : phrases.lookup(QStringLiteral("FEATURES"), no); break; case LinkCategory::Model: title = helpText.lookup(QStringLiteral("HELPTITLE_MODELLIST")); break; case LinkCategory::Text: title = helpText.lookupByHandle(no); break; case LinkCategory::Misc: switch (static_cast(no)) { case MiscLinkIndex::Main: title = helpText.lookup(QStringLiteral("HELPTITLE_MAIN")); break; case MiscLinkIndex::Credits: title = helpText.lookup(QStringLiteral("HELPTITLE_CREDITS")); break; case MiscLinkIndex::GovList: title = helpText.lookup(QStringLiteral("HELPTITLE_GOVLIST")); break; case MiscLinkIndex::JobList: title = helpText.lookup(QStringLiteral("HELPTITLE_JOBLIST")); break; case MiscLinkIndex::SearchResult: title = helpText.lookup(QStringLiteral("HELPTITLE_SEARCHRESULTS")); break; } break; default: title = QStringLiteral("Help"); break; } if (title.isEmpty()) title = QStringLiteral("Help"); mainText.addLine(title, TextFormat::Caption); mainText.lineFeed(); if (kind == LinkCategory::Misc && static_cast(no) == MiscLinkIndex::SearchResult) { mainText.addLine(formatS(helpText.lookup(QStringLiteral("MATCHES")), searchContent)); 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 if (kind == LinkCategory::Ter && (no == 200 || (no >= 0 && no < 48))) { prepareTerrain(no); } else if (kind == LinkCategory::Feature && (no == 200 || (no >= 0 && no < nFeature))) { prepareFeature(no); } else if (kind == LinkCategory::Model) { prepareModel(no); } else if (kind == LinkCategory::Misc && static_cast(no) == MiscLinkIndex::Main) { prepareMiscMain(); } else if (kind == LinkCategory::Misc && static_cast(no) == MiscLinkIndex::GovList) { prepareMiscGovList(); } else if (kind == LinkCategory::Misc && static_cast(no) == MiscLinkIndex::JobList) { prepareMiscJobList(); } else if (kind == LinkCategory::Misc && static_cast(no) == MiscLinkIndex::Credits) { prepareMiscCredits(); } else { mainText.addLine(QStringLiteral("Detailed help content isn't available in this build.")); } mainText.lineFeed(); scrollBar->init(mainText.count() - 1, innerHeight / 24); scrollBar->setPos(sbPos); ui->backBtn->setVisible(histItems.size() > 1); ui->topBtn->setVisible(histItems.size() > 1 || kind != LinkCategory::Misc || no != static_cast(MiscLinkIndex::Main)); sel = -1; } void HelpDlg::prepareAdvance(int advance) { // Section helper (NextSection in the original): only emits the section // header + a blank line separator if the section actually has entries. 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); }; if (IsFutureTech(advance)) { mainText.addLine(helpText.lookup(QStringLiteral("HELPSPEC_FUTURE"))); mainText.lineFeed(); mainText.addLine(helpText.lookup(advance == futResearchTechnology ? QStringLiteral("FUTURETECHHELP100") : QStringLiteral("FUTURETECHHELP25"))); } else { mainText.addLine(helpText.lookup(QStringLiteral("HELPSPEC_ADV"))); } HyperText preqs; for (int i = 0; i < 3; ++i) { if (AdvPreq[advance][i] != preNone) preqs.addLine(phrases.lookup(QStringLiteral("ADVANCES"), AdvPreq[advance][i]), TextFormat::AdvIconAsPreq, 0, LinkCategory::Adv, AdvPreq[advance][i], true); } addSection(AdvPreq[advance][2] != preNone ? QStringLiteral("PREREQALT") : QStringLiteral("PREREQ"), preqs); HyperText govs; for (int i = 2; i < nGov; ++i) { if (GovPreq[i] == advance) govs.addLine(phrases.lookup(QStringLiteral("GOVERNMENT"), i), TextFormat::Gov, 0, LinkCategory::Misc, static_cast(MiscLinkIndex::GovList), true); } addSection(QStringLiteral("GOVALLOW"), govs); HyperText imps; for (int i = 0; i < nWonder; ++i) { if (Imp[i].Preq == advance) imps.addLine(phrases.lookup(QStringLiteral("IMPROVEMENTS"), i), TextFormat::SmallIcon, 0, LinkCategory::Imp, i, true); } for (int i = nWonder; i < nImp; ++i) { if (Imp[i].Preq == advance && Imp[i].Kind != ikCommon) imps.addLine(phrases.lookup(QStringLiteral("IMPROVEMENTS"), i), TextFormat::SmallIcon, 0, LinkCategory::Imp, i, true); } for (int i = nWonder; i < nImp; ++i) { if (Imp[i].Preq == advance && Imp[i].Kind == ikCommon) imps.addLine(phrases.lookup(QStringLiteral("IMPROVEMENTS"), i), TextFormat::SmallIcon, 0, LinkCategory::Imp, i, true); } addSection(QStringLiteral("BUILDALLOW"), imps); HyperText feats; for (int i = 0; i < nFeature; ++i) { if (Feature[i].Preq == advance) feats.addLine(phrases.lookup(QStringLiteral("FEATURES"), i), TextFormat::Feature, 0, LinkCategory::Feature, i, true); } addSection(QStringLiteral("FEATALLOW"), feats); HyperText follow; for (int i = 0; i < nAdv; ++i) { if (AdvPreq[i][0] == advance || AdvPreq[i][1] == advance || AdvPreq[i][2] == advance) follow.addLine(phrases.lookup(QStringLiteral("ADVANCES"), i), TextFormat::AdvIcon, 0, LinkCategory::Adv, i, true); } addSection(QStringLiteral("FOLLOWADV"), follow); HyperText seeAlso; appendSeeAlsoEntries(seeAlso, LinkCategory::Adv, advance); addSection(QStringLiteral("SEEALSO"), seeAlso); } 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); }; 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 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); appendSeeAlsoEntries(seeAlso, LinkCategory::Imp, imp); addSection(QStringLiteral("SEEALSO"), seeAlso); } void HelpDlg::prepareTerrain(int no) { if (no == 200) { // complete terrain type list for (int i : TerrainHelp) { if (mainText.count() > 1) mainText.lineFeed(); mainText.addLine(phrases.lookup(QStringLiteral("TERRAIN"), i), TextFormat::Ter, 0, LinkCategory::Ter, i, true); } return; } 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); }; int terrType = no % 12; if (terrType == Term::fJungle) terrType = fForest; int terrSubType = no / 12; if (no == 3 * 12) { terrType = fDesert; terrSubType = 0; } const TerrainInfo &terrain = Terrain[terrType]; mainText.addLine(helpText.lookup(QStringLiteral("HELPSPEC_TER"))); mainText.lineFeed(); if (terrain.ProdRes[terrSubType] > 0 || terrain.MineEff > 0) { QString line = formatD(helpText.lookup(QStringLiteral("RESPROD")), terrain.ProdRes[terrSubType]); if (no < 3 * 12 && terrain.MineEff > 0) line += QLatin1Char(' ') + formatD(helpText.lookup(QStringLiteral("MOREMINE")), terrain.MineEff); mainText.addLine(line); } if (terrain.FoodRes[terrSubType] > 0 || terrain.IrrEff > 0) { QString line = formatD(helpText.lookup(QStringLiteral("RESFOOD")), terrain.FoodRes[terrSubType]); if (no < 3 * 12 && terrain.IrrEff > 0) line += QLatin1Char(' ') + formatD(helpText.lookup(QStringLiteral("MOREIRR")), terrain.IrrEff); mainText.addLine(line); } if (terrain.TradeRes[terrSubType] > 0) mainText.addLine(formatD(helpText.lookup(QStringLiteral("RESTRADE")), terrain.TradeRes[terrSubType])); if (terrain.Defense > 4) mainText.addLine(formatD(helpText.lookup(QStringLiteral("DEFBONUS")), (terrain.Defense - 4) * 25)); if (terrType >= fGrass && terrType != fMountains) mainText.addLine( helpText.lookup(terrain.MoveCost == 2 ? QStringLiteral("MOVEHEAVY") : QStringLiteral("MOVEPLAIN"))); if (no == 3 * 12) { mainText.lineFeed(); mainText.addLine(helpText.lookup(QStringLiteral("DEADLANDS"))); } if (terrType == fDesert && no != fDesert + 12) { mainText.lineFeed(); mainText.addLine(formatD(helpText.lookup(QStringLiteral("HOSTILE")), DesertThurst)); } if (terrType == fArctic) { mainText.lineFeed(); mainText.addLine(formatD(helpText.lookup(QStringLiteral("HOSTILE")), ArcticThurst)); } if (no < 3 * 12 && terrain.TransTerrain >= 0) { mainText.lineFeed(); int i = terrain.TransTerrain; if (terrType != fGrass && i != fGrass) i += terrSubType * 12; mainText.addLine(formatS(helpText.lookup(QStringLiteral("TRAFO")), phrases.lookup(QStringLiteral("TERRAIN"), i)), TextFormat::Ter, 0, LinkCategory::Ter, i, true); if (no == fSwamp + 12) { mainText.lineFeed(); mainText.addLine(formatS(helpText.lookup(QStringLiteral("TRAFO")), phrases.lookup(QStringLiteral("TERRAIN"), terrain.TransTerrain + 24)), TextFormat::Ter, 0, LinkCategory::Ter, terrain.TransTerrain + 24, true); } else if (i == fGrass) { mainText.lineFeed(); mainText.addLine(formatS(helpText.lookup(QStringLiteral("TRAFO")), phrases.lookup(QStringLiteral("TERRAIN"), fGrass + 12)), TextFormat::Ter, 0, LinkCategory::Ter, fGrass + 12, true); } } HyperText special; if (no == 3 * 12) { for (int sp = 1; sp <= 3; ++sp) { special.lineFeed(); special.addLine(phrases.lookup(QStringLiteral("TERRAIN"), 3 * 12 + sp), TextFormat::Ter, 0, LinkCategory::Ter, 3 * 12 + sp, true); } } else if (no < 12 && no != fGrass && no != fOcean) { for (int sp = 1; sp <= 2; ++sp) { if ((no != fArctic && no != fSwamp) || sp < 2) { special.lineFeed(); QString line = phrases.lookup(QStringLiteral("TERRAIN"), no + sp * 12); const int df = terrain.FoodRes[sp] - terrain.FoodRes[0]; if (df != 0) line += formatD(helpText.lookup(QStringLiteral("SPECIALFOOD")), df); const int dp = terrain.ProdRes[sp] - terrain.ProdRes[0]; if (dp != 0) line += formatD(helpText.lookup(QStringLiteral("SPECIALPROD")), dp); const int dt = terrain.TradeRes[sp] - terrain.TradeRes[0]; if (dt != 0) line += formatD(helpText.lookup(QStringLiteral("SPECIALTRADE")), dt); special.addLine(line, TextFormat::Ter, 0, LinkCategory::Ter, no + sp * 12, true); } } } addSection(QStringLiteral("SPECIAL"), special); if (no == 3 * 12) { mainText.lineFeed(); mainText.addLine(helpText.lookup(QStringLiteral("RARE"))); } HyperText seeAlso; if (no < 3 * 12 && (terrType == fDesert || terrType == fArctic)) seeAlso.addLine(phrases.lookup(QStringLiteral("IMPROVEMENTS"), woGardens), TextFormat::SmallIcon, 0, LinkCategory::Imp, woGardens, true); addSection(QStringLiteral("SEEALSO"), seeAlso); } void HelpDlg::prepareFeature(int no) { if (no == 200) { // complete feature list, grouped by capacity/special/advance for (int group = 0; group < 3; ++group) { if (mainText.count() > 1) { mainText.lineFeed(); mainText.lineFeed(); } switch (group) { case 0: mainText.addLine(helpText.lookup(QStringLiteral("HELPTITLE_FEATURE1LIST")), TextFormat::Section); break; case 1: mainText.addLine(helpText.lookup(QStringLiteral("HELPTITLE_FEATURE2LIST")), TextFormat::Section); break; case 2: mainText.addLine(helpText.lookup(QStringLiteral("HELPTITLE_FEATURE3LIST")), TextFormat::Section); break; } std::vector names; std::vector indices; for (int i = 0; i < nFeature; ++i) { if (Feature[i].Preq == preNA) continue; const int which = i < mcFirstNonCap ? 0 : (AutoFeature & (1u << i)) ? 2 : 1; if (which == group) { names.push_back(phrases.lookup(QStringLiteral("FEATURES"), i)); indices.push_back(i); } } std::vector order(names.size()); for (std::size_t i = 0; i < order.size(); ++i) order[i] = i; std::sort(order.begin(), order.end(), [&names](std::size_t a, std::size_t b) { return names[a] < names[b]; }); for (std::size_t i : order) mainText.addLine(names[i], TextFormat::Feature, 0, LinkCategory::Feature, indices[i], true); } return; } 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); }; if (no < mcFirstNonCap) mainText.addLine(helpText.lookup(QStringLiteral("HELPSPEC_CAP"))); else if (AutoFeature & (1u << no)) mainText.addLine(helpText.lookup(QStringLiteral("HELPSPEC_STANDARD"))); else mainText.addLine(helpText.lookup(QStringLiteral("HELPSPEC_FEATURE"))); const QString effect = helpText.lookup(QStringLiteral("FEATUREHELP"), no); if (!effect.isEmpty()) { mainText.lineFeed(); mainText.addLine(helpText.lookup(QStringLiteral("EFFECT")), TextFormat::Section); mainText.addLine(effect); } if (Feature[no].Weight != 0 || Feature[no].Cost != 0) { mainText.lineFeed(); mainText.addLine(helpText.lookup(QStringLiteral("COSTS")), TextFormat::Section); QString cost = QString::number(Feature[no].Cost); if (Feature[no].Cost >= 0) cost = QLatin1Char('+') + cost; mainText.addLine(formatS(helpText.lookup(QStringLiteral("COSTBASE")), cost)); if (Feature[no].Weight > 0) { mainText.addLine(formatS(helpText.lookup(QStringLiteral("WEIGHT")), QLatin1Char('+') + QString::number(Feature[no].Weight))); if (no == mcDefense) mainText.addLine(formatS(helpText.lookup(QStringLiteral("WEIGHT")), QStringLiteral("+2")), TextFormat::Domain, dGround); } } if (Feature[no].Preq != preNone) { mainText.lineFeed(); if (Feature[no].Preq == preSun) mainText.addLine(phrases.lookup(QStringLiteral("IMPROVEMENTS"), woSun), TextFormat::SmallIconAsPreq, 0, LinkCategory::Imp, woSun, true); else mainText.addLine(phrases.lookup(QStringLiteral("ADVANCES"), Feature[no].Preq), TextFormat::AdvIconAsPreq, 0, LinkCategory::Adv, Feature[no].Preq, true); mainText.text(mainText.count() - 1) = formatS(helpText.lookup(QStringLiteral("REQUIRED")), mainText.text(mainText.count() - 1)); } HyperText seeAlso; appendSeeAlsoEntries(seeAlso, LinkCategory::Feature, no); addSection(QStringLiteral("SEEALSO"), seeAlso); } void HelpDlg::prepareModel(int) { for (int i = 0; i < nSpecialModel; ++i) { if (i == 2) // skip pixSlaves/pixNoSlaves-style gap, matches the original continue; if (mainText.count() > 1) { mainText.lineFeed(); mainText.lineFeed(); } int pix = 0; QString name; Tribes::findStdModelPicture(Term::SpecialModelPictureCode[static_cast(i)], pix, name); mainText.addLine(name, TextFormat::Section); mainText.addLine(formatArgs(helpText.lookup(QStringLiteral("STRENGTH")), { QString::number(SpecialModel[i].Attack), QString::number(SpecialModel[i].Defense) })); mainText.addLine(formatS(helpText.lookup(QStringLiteral("SPEED")), movementToString(SpecialModel[i].Speed)), TextFormat::Model, pix); const int cost = difficulty == 0 ? SpecialModel[i].Cost : SpecialModel[i].Cost * BuildCostMod[difficulty] / 12; mainText.addLine(formatD(helpText.lookup(QStringLiteral("BUILDCOST")), cost)); const QString special = helpText.lookup(QStringLiteral("SPECIALMODEL"), i); if (!special.isEmpty() && special != QLatin1String("*")) mainText.addLine(special); if (SpecialModelPreq[i] >= 0) mainText.addLine(phrases.lookup(QStringLiteral("ADVANCES"), SpecialModelPreq[i]), TextFormat::AdvIconAsPreq, 0, LinkCategory::Adv, SpecialModelPreq[i], true); else if (SpecialModelPreq[i] == preLighthouse) mainText.addLine(phrases.lookup(QStringLiteral("IMPROVEMENTS"), woLighthouse), TextFormat::SmallIconAsPreq, 0, LinkCategory::Imp, woLighthouse, true); else if (SpecialModelPreq[i] == preBuilder) mainText.addLine(phrases.lookup(QStringLiteral("IMPROVEMENTS"), woPyramids), TextFormat::SmallIconAsPreq, 0, LinkCategory::Imp, woPyramids, true); else if (SpecialModelPreq[i] == preLeo) mainText.addLine(phrases.lookup(QStringLiteral("IMPROVEMENTS"), woLeo), TextFormat::SmallIconAsPreq, 0, LinkCategory::Imp, woLeo, true); if (SpecialModelPreq[i] != preNone) mainText.text(mainText.count() - 1) = formatS(helpText.lookup(QStringLiteral("REQUIRED")), mainText.text(mainText.count() - 1)); } mainText.lineFeed(); mainText.addLine(helpText.lookup(QStringLiteral("MODELNOTE"))); } void HelpDlg::line(Dpi::Canvas &canvas, int i, bool lit) { const int idx = scrollBar->position() + i; if (idx < 0 || idx >= mainText.count()) return; const QString &s = mainText.text(idx); if (s.isEmpty()) return; int x = x0[static_cast(i + 2)]; int y = 2 + i * 24; if (&canvas != &offscreen.canvas()) { x += SideFrame; y += WideFrame; } const HelpLineInfo &lineInfo = mainText.info(idx); const bool isCaption = lineInfo.format == TextFormat::Caption; if (isCaption) canvas.font().setBold(true); const QColor textColor = isCaption ? captionColor : colorFromDelphi(0x000000); biColorTextOut(canvas, textColor, colorFromDelphi(0x7F007F), x, y, s); if (lit) { canvas.pen().setColor(textColor); canvas.moveTo(x + 1, y + 18); canvas.lineTo(x + biColorTextWidth(canvas, s), y + 18); } if (isCaption) canvas.font().setBold(false); } void HelpDlg::paintTerrIcon(int x, int y, int xSrc, int ySrc) { // Cosmetic terrain-icon compositing (uses a TIsoMap instance in the // original) - not ported, no caller in this simplified offscreenPaint. Q_UNUSED(x); Q_UNUSED(y); Q_UNUSED(xSrc); Q_UNUSED(ySrc); } void HelpDlg::offscreenPaint() { FramedDlg::offscreenPaint(); captionColor = colorFromDelphi(0xC08040); Dpi::Canvas &canvas = offscreen.canvas(); canvas.begin(); fillSeamless(canvas, 0, 0, innerWidth, innerHeight, 0, scrollBar->position() * 24, paper); canvas.font().assign(UniFont[static_cast(FontType::Normal)]); for (int i = -2; i <= innerHeight / 24; ++i) { const int idx = scrollBar->position() + i; if (idx < 0 || idx >= mainText.count()) continue; x0[static_cast(i + 2)] = 8; line(canvas, i, i == sel); } canvas.end(); markUsedOffscreen(innerWidth, innerHeight); } void HelpDlg::resizeEvent(QResizeEvent *event) { FramedDlg::resizeEvent(event); ui->searchBtn->move(width() - 67, ui->searchBtn->y()); ui->closeBtn->move(width() - 38, ui->closeBtn->y()); } void HelpDlg::closeEvent(QCloseEvent *event) { // ExtPic.Height := 0; -- the external-link preview bitmap isn't ported. FramedDlg::closeEvent(event); } void HelpDlg::keyPressEvent(QKeyEvent *event) { const QKeySequence pressed(event->keyCombination()); if (KeyBindings::bHelp && pressed.matches(KeyBindings::bHelp->shortCut) == QKeySequence::ExactMatch) { // Swallow (matches the original's empty branch - already viewing help). } else { FramedDlg::keyPressEvent(event); } } void HelpDlg::wheelEvent(QWheelEvent *event) { scrollBar->setPosition(scrollBar->position() - event->angleDelta().y() / 120); sel = -1; offscreenPaint(); update(); } void HelpDlg::mouseMoveEvent(QMouseEvent *event) { const int y = event->position().toPoint().y() - WideFrame; const int x = event->position().toPoint().x(); const int i0 = scrollBar->position(); const int sel0 = sel; if (x >= SideFrame && x < SideFrame + innerWidth && y >= 0 && y < innerHeight && y % 24 >= 8) sel = y / 24; else sel = -1; if (sel >= 0) { const int idx = sel + i0; if (idx >= mainText.count() || (mainText.info(idx).category == LinkCategory::NoLink && mainText.info(idx).index == 0)) sel = -1; } if (sel != sel0) { offscreenPaint(); update(); } FramedDlg::mouseMoveEvent(event); } void HelpDlg::mousePressEvent(QMouseEvent *event) { if (sel >= 0) { const int idx = sel + scrollBar->position(); if (idx < mainText.count()) { const HelpLineInfo &info = mainText.info(idx); if (info.category != LinkCategory::Internet && info.index >= 0) showNewContent(windowMode(), info.category, info.index); } } FramedDlg::mousePressEvent(event); } void HelpDlg::backBtnClicked() { if (histItems.size() > 1) { const HistItem item = histItems.back(); histItems.pop_back(); if (item.kind == LinkCategory::Misc && item.no == static_cast(MiscLinkIndex::SearchResult) && item.searchContent != searchContent) { searchContent = item.searchContent; search(searchContent); } kind = item.kind; no = item.no; prepare(item.pos); offscreenPaint(); update(); } } void HelpDlg::topBtnClicked() { while (histItems.size() > 1) histItems.pop_back(); kind = LinkCategory::Misc; no = static_cast(MiscLinkIndex::Main); prepare(); offscreenPaint(); update(); } void HelpDlg::searchBtnClicked() { auto inputDlg = std::make_unique(nullptr); inputDlg->setWindowTitle(phrase(QStringLiteral("SEARCH"))); inputDlg->editInput()->setText(searchContent); inputDlg->centerToRect(geometry()); if (inputDlg->showModal() == Dpi::ModalResult::Ok && inputDlg->editInput()->text().length() >= 2) { search(inputDlg->editInput()->text()); if (searchResult.count() == 0) { simpleMessage(QStringLiteral("No matches found.")); } else if (searchResult.count() == 1) { const HelpLineInfo &info = searchResult.info(0); showNewContent(windowMode(), info.category, info.index); } else { newSearchContent = inputDlg->editInput()->text(); showNewContent(windowMode(), LinkCategory::Misc, static_cast(MiscLinkIndex::SearchResult)); } } } void HelpDlg::search(const QString &searchString) { searchResult.clear(); // The result list isn't built yet (needs the Help.txt layout engine): // the matches are found but not recorded. int handle = -1; int index = -1; while (helpText.search(searchString, handle, index)) { } } } // namespace Help } // namespace Cevo