diff --git a/game/localplayer/CityScreen.cpp b/game/localplayer/CityScreen.cpp index c3a19fb..7380679 100644 --- a/game/localplayer/CityScreen.cpp +++ b/game/localplayer/CityScreen.cpp @@ -1287,7 +1287,8 @@ void CityDlg::mousePressEvent(QMouseEvent *event) int iix = imix[static_cast(i)]; if (iix >= 0) { if (shift) { - Help::showNewContent(windowModeMakePersistent(windowMode()), Help::LinkCategory::Imp, iix); + if (auto *dlg = Term::mainScreenHelpDlg()) + dlg->showNewContent(windowModeMakePersistent(windowMode()), Help::LinkCategory::Imp, iix); } else if (IsoEngine::clientMode < scContact) { if (auto *dlg = Term::mainScreenMessgExDlg()) { dlg->iconKind = MessgEx::MessageIconKind::Imp; diff --git a/game/localplayer/Draft.cpp b/game/localplayer/Draft.cpp index a7ff9a9..0080d56 100644 --- a/game/localplayer/Draft.cpp +++ b/game/localplayer/Draft.cpp @@ -474,7 +474,8 @@ void DraftDlg::mousePressEvent(QMouseEvent *event) const int i = (y - yFeature) / LinePitch; const int c = code[static_cast(i)]; if (x >= xFeature - 21 && x < width() && (event->modifiers() & Qt::ShiftModifier)) { - Help::showNewContent(windowModeMakePersistent(windowMode()), Help::LinkCategory::Feature, c); + if (auto *dlg = Term::mainScreenHelpDlg()) + dlg->showNewContent(windowModeMakePersistent(windowMode()), Help::LinkCategory::Feature, c); } else if (!isFeatureAuto(c)) { if (c < mcFirstNonCap && x >= xFeature - 21 && x < xFeature - 21 + 12) { incCap = c; diff --git a/game/localplayer/Enhance.cpp b/game/localplayer/Enhance.cpp index a7dc44c..a1b87be 100644 --- a/game/localplayer/Enhance.cpp +++ b/game/localplayer/Enhance.cpp @@ -353,11 +353,12 @@ void EnhanceDlg::resizeEvent(QResizeEvent *event) void EnhanceDlg::keyPressEvent(QKeyEvent *event) { const QKeySequence pressed(event->key() | event->modifiers()); - if (KeyBindings::bHelp && pressed.matches(KeyBindings::bHelp->shortCut) == QKeySequence::ExactMatch) + if (KeyBindings::bHelp && pressed.matches(KeyBindings::bHelp->shortCut) == QKeySequence::ExactMatch) { // TODO: needs a live HelpDlg instance's textIndex() (Term.pas's // MainScreen.HelpDlg isn't ported yet) - placeholder text index. - Help::showNewContent(windowModeMakePersistent(windowMode()), Help::LinkCategory::Text, 0); - else + if (auto *dlg = Term::mainScreenHelpDlg()) + dlg->showNewContent(windowModeMakePersistent(windowMode()), Help::LinkCategory::Text, 0); + } else FramedDlg::keyPressEvent(event); } diff --git a/game/localplayer/MessgEx.cpp b/game/localplayer/MessgEx.cpp index 503bd80..c49256e 100644 --- a/game/localplayer/MessgEx.cpp +++ b/game/localplayer/MessgEx.cpp @@ -72,9 +72,10 @@ MessgExDlg::MessgExDlg(QWidget *parent) : BaseMessgDlg(parent), ui(new Ui::Messg close(); }; ui->button2->onClick = [this] { - if (kind == MessageKind::OkHelp) - Help::showNewContent(WindowMode::Submodal, helpKind, helpNo); - else if (kind == MessageKind::Model) + if (kind == MessageKind::OkHelp) { + if (auto *dlg = Term::mainScreenHelpDlg()) + dlg->showNewContent(WindowMode::Submodal, helpKind, helpNo); + } else if (kind == MessageKind::Model) UnitStat::showNewContentOwnModel(WindowMode::Submodal, iconIndex); else { setModalResult(Dpi::ModalResult::Ignore); diff --git a/game/localplayer/Select.cpp b/game/localplayer/Select.cpp index 049d0a8..c15b21c 100644 --- a/game/localplayer/Select.cpp +++ b/game/localplayer/Select.cpp @@ -1696,25 +1696,32 @@ void ListDlg::mousePressEvent(QMouseEvent *event) case ListKind::ChooseTech: case ListKind::ChooseEnemyTech: case ListKind::StealTech: - if (lix == adMilitary) + if (lix == adMilitary) { // TODO: needs a live HelpDlg instance's textIndex('MILRES') // (MainScreen singleton not ported) - opens the text page // list instead of the exact targeted entry. - Help::showNewContent(WindowMode::Persistent, Help::LinkCategory::Text, 0); - else if (lix < adMilitary) - Help::showNewContent(WindowMode::Persistent, Help::LinkCategory::Adv, lix); + if (auto *dlg = Term::mainScreenHelpDlg()) + dlg->showNewContent(WindowMode::Persistent, Help::LinkCategory::Text, 0); + } else if (lix < adMilitary) { + if (auto *dlg = Term::mainScreenHelpDlg()) + dlg->showNewContent(WindowMode::Persistent, Help::LinkCategory::Adv, lix); + } break; case ListKind::Project: - if (lix == cpImp + imTrGoods) - Help::showNewContent(WindowMode::Persistent, Help::LinkCategory::Text, 0); - else if ((lix & (cpImp | cpType)) == 0) + if (lix == cpImp + imTrGoods) { + if (auto *dlg = Term::mainScreenHelpDlg()) + dlg->showNewContent(WindowMode::Persistent, Help::LinkCategory::Text, 0); + } else if ((lix & (cpImp | cpType)) == 0) { UnitStat::showNewContentOwnModel(WindowMode::Persistent, lix & cpIndex); - else if ((lix & cpType) == 0 && lix != cpImp + imTrGoods) - Help::showNewContent(WindowMode::Persistent, Help::LinkCategory::Imp, lix & cpIndex); + } else if ((lix & cpType) == 0 && lix != cpImp + imTrGoods) { + if (auto *dlg = Term::mainScreenHelpDlg()) + dlg->showNewContent(WindowMode::Persistent, Help::LinkCategory::Imp, lix & cpIndex); + } break; case ListKind::Government: - Help::showNewContent(WindowMode::Persistent, Help::LinkCategory::Misc, - static_cast(Help::MiscLinkIndex::GovList)); + if (auto *dlg = Term::mainScreenHelpDlg()) + dlg->showNewContent(WindowMode::Persistent, Help::LinkCategory::Misc, + static_cast(Help::MiscLinkIndex::GovList)); break; default: break; diff --git a/game/localplayer/Term.MainScreen.cpp b/game/localplayer/Term.MainScreen.cpp index 4a33160..c5c0e54 100644 --- a/game/localplayer/Term.MainScreen.cpp +++ b/game/localplayer/Term.MainScreen.cpp @@ -90,6 +90,7 @@ MainScreen::MainScreen(QWidget *parent) : DrawDlg(parent) mainScreenMessgExDlg = [this] { return &messgExDlg(); }; mainScreenModalSelectDlg = [this] { return &modalSelectDlg(); }; mainScreenNatStatDlg = [this] { return &natStatDlg(); }; + mainScreenHelpDlg = [this] { return &helpDlg(); }; mainScreenOfferCall = [this](const TOffer &offer) { TOffer mutableOffer = offer; return offerCall(mutableOffer); diff --git a/game/localplayer/Term.cpp b/game/localplayer/Term.cpp index dc4533b..92a93b6 100644 --- a/game/localplayer/Term.cpp +++ b/game/localplayer/Term.cpp @@ -487,14 +487,17 @@ QString cityEventName(int i) void helpOnTerrain(int loc, WindowMode newMode) { + auto *dlg = mainScreenHelpDlg(); + if (!dlg) + return; if (ClientTools::myMap[loc] & fDeadLands) { - Help::showNewContent(newMode, Help::LinkCategory::Ter, 3 * 12); + dlg->showNewContent(newMode, Help::LinkCategory::Ter, 3 * 12); } else if ((ClientTools::myMap[loc] & fTerrain) == fForest && IsoEngine::isJungle(loc / ClientTools::g.lx)) { - Help::showNewContent(newMode, Help::LinkCategory::Ter, fJungle + (ClientTools::myMap[loc] >> 5 & 3) * 12); + dlg->showNewContent(newMode, Help::LinkCategory::Ter, fJungle + (ClientTools::myMap[loc] >> 5 & 3) * 12); } else { - Help::showNewContent(newMode, Help::LinkCategory::Ter, - (ClientTools::myMap[loc] & fTerrain) + (ClientTools::myMap[loc] >> 5 & 3) * 12); + dlg->showNewContent(newMode, Help::LinkCategory::Ter, + (ClientTools::myMap[loc] & fTerrain) + (ClientTools::myMap[loc] >> 5 & 3) * 12); } } @@ -507,6 +510,7 @@ std::function listDlgRenameCity = [](int) { return false; }; std::function mainScreenMessgExDlg = [] { return static_cast(nullptr); }; std::function mainScreenModalSelectDlg = [] { return static_cast(nullptr); }; std::function mainScreenNatStatDlg = [] { return static_cast(nullptr); }; +std::function mainScreenHelpDlg = [] { return static_cast(nullptr); }; std::function mainScreenOfferCall = [](const TOffer &) { return eInvalid; }; TOffer receivedOffer{}; diff --git a/game/localplayer/Term.h b/game/localplayer/Term.h index 6cbe1ca..acacb8a 100644 --- a/game/localplayer/Term.h +++ b/game/localplayer/Term.h @@ -32,6 +32,7 @@ #include "Cevo/CevoScreenTools.h" #include "Cevo/Protocol.h" #include "ClientTools.h" +#include "Help.h" #include "MessgEx.h" #include "NatStat.h" #include "Select.h" @@ -311,6 +312,10 @@ extern std::function mainScreenMessgExDlg; // modalSelectDlgShowCityProject above for the city-project-only variant). extern std::function mainScreenModalSelectDlg; extern std::function mainScreenNatStatDlg; +// Mirrors `MainScreen.HelpDlg` dialog access - unlike the bare +// `Help::showNewContent` global (only bound once a HelpDlg exists), this +// forces lazy construction of the one true instance on first use. +extern std::function mainScreenHelpDlg; // Mirrors `MainScreen.OfferCall(var Offer: TOffer): Integer` - returns // eInvalid by default. extern std::function mainScreenOfferCall; diff --git a/game/localplayer/UnitStat.cpp b/game/localplayer/UnitStat.cpp index a65cc63..2ac41c3 100644 --- a/game/localplayer/UnitStat.cpp +++ b/game/localplayer/UnitStat.cpp @@ -175,7 +175,10 @@ UnitStatDlg::UnitStatDlg(QWidget *parent) : BufferedDrawDlg(parent), ui(new Ui:: ui->conscriptsBtn->setToolTip(phrase(QStringLiteral("BTN_ALLOWCONSCRIPTS"))); } }; - ui->helpBtn->onClick = [this] { Help::showNewContent(WindowMode::Persistent, Help::LinkCategory::Model, 0); }; + ui->helpBtn->onClick = [this] { + if (auto *dlg = Term::mainScreenHelpDlg()) + dlg->showNewContent(WindowMode::Persistent, Help::LinkCategory::Model, 0); + }; UnitStat::showNewContentOwnModel = [this](WindowMode newMode, int mix) { this->showNewContentOwnModel(newMode, mix); }; UnitStat::showNewContentEnemyModel = [this](WindowMode newMode, int emix) { diff --git a/game/localplayer/Wonders.cpp b/game/localplayer/Wonders.cpp index 3d561d8..811883c 100644 --- a/game/localplayer/Wonders.cpp +++ b/game/localplayer/Wonders.cpp @@ -314,8 +314,10 @@ void WondersDlg::mouseMoveEvent(QMouseEvent *event) void WondersDlg::mousePressEvent(QMouseEvent *event) { - if (selection >= 0 && Help::showNewContent) - Help::showNewContent(windowModeMakePersistent(windowMode()), Help::LinkCategory::Imp, selection); + if (selection >= 0) { + if (auto *dlg = Term::mainScreenHelpDlg()) + dlg->showNewContent(windowModeMakePersistent(windowMode()), Help::LinkCategory::Imp, selection); + } BufferedDrawDlg::mousePressEvent(event); }