improve help implementation

This commit is contained in:
Geoffray Levasseur committed 2026-11-07 13:25:21 +01:00
1 parent 2dcc63875d
commit 9ef24e3a9e
10 files changed
+50 -24

No files matched your search

+2 -1
View File
@@ -1287,7 +1287,8 @@ void CityDlg::mousePressEvent(QMouseEvent *event)
int iix = imix[static_cast<std::size_t>(i)]; int iix = imix[static_cast<std::size_t>(i)];
if (iix >= 0) { if (iix >= 0) {
if (shift) { 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) { } else if (IsoEngine::clientMode < scContact) {
if (auto *dlg = Term::mainScreenMessgExDlg()) { if (auto *dlg = Term::mainScreenMessgExDlg()) {
dlg->iconKind = MessgEx::MessageIconKind::Imp; dlg->iconKind = MessgEx::MessageIconKind::Imp;
+2 -1
View File
@@ -474,7 +474,8 @@ void DraftDlg::mousePressEvent(QMouseEvent *event)
const int i = (y - yFeature) / LinePitch; const int i = (y - yFeature) / LinePitch;
const int c = code[static_cast<std::size_t>(i)]; const int c = code[static_cast<std::size_t>(i)];
if (x >= xFeature - 21 && x < width() && (event->modifiers() & Qt::ShiftModifier)) { 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)) { } else if (!isFeatureAuto(c)) {
if (c < mcFirstNonCap && x >= xFeature - 21 && x < xFeature - 21 + 12) { if (c < mcFirstNonCap && x >= xFeature - 21 && x < xFeature - 21 + 12) {
incCap = c; incCap = c;
+4 -3
View File
@@ -353,11 +353,12 @@ void EnhanceDlg::resizeEvent(QResizeEvent *event)
void EnhanceDlg::keyPressEvent(QKeyEvent *event) void EnhanceDlg::keyPressEvent(QKeyEvent *event)
{ {
const QKeySequence pressed(event->key() | event->modifiers()); 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 // TODO: needs a live HelpDlg instance's textIndex() (Term.pas's
// MainScreen.HelpDlg isn't ported yet) - placeholder text index. // MainScreen.HelpDlg isn't ported yet) - placeholder text index.
Help::showNewContent(windowModeMakePersistent(windowMode()), Help::LinkCategory::Text, 0); if (auto *dlg = Term::mainScreenHelpDlg())
else dlg->showNewContent(windowModeMakePersistent(windowMode()), Help::LinkCategory::Text, 0);
} else
FramedDlg::keyPressEvent(event); FramedDlg::keyPressEvent(event);
} }
+4 -3
View File
@@ -72,9 +72,10 @@ MessgExDlg::MessgExDlg(QWidget *parent) : BaseMessgDlg(parent), ui(new Ui::Messg
close(); close();
}; };
ui->button2->onClick = [this] { ui->button2->onClick = [this] {
if (kind == MessageKind::OkHelp) if (kind == MessageKind::OkHelp) {
Help::showNewContent(WindowMode::Submodal, helpKind, helpNo); if (auto *dlg = Term::mainScreenHelpDlg())
else if (kind == MessageKind::Model) dlg->showNewContent(WindowMode::Submodal, helpKind, helpNo);
} else if (kind == MessageKind::Model)
UnitStat::showNewContentOwnModel(WindowMode::Submodal, iconIndex); UnitStat::showNewContentOwnModel(WindowMode::Submodal, iconIndex);
else { else {
setModalResult(Dpi::ModalResult::Ignore); setModalResult(Dpi::ModalResult::Ignore);
+17 -10
View File
@@ -1696,24 +1696,31 @@ void ListDlg::mousePressEvent(QMouseEvent *event)
case ListKind::ChooseTech: case ListKind::ChooseTech:
case ListKind::ChooseEnemyTech: case ListKind::ChooseEnemyTech:
case ListKind::StealTech: case ListKind::StealTech:
if (lix == adMilitary) if (lix == adMilitary) {
// TODO: needs a live HelpDlg instance's textIndex('MILRES') // TODO: needs a live HelpDlg instance's textIndex('MILRES')
// (MainScreen singleton not ported) - opens the text page // (MainScreen singleton not ported) - opens the text page
// list instead of the exact targeted entry. // list instead of the exact targeted entry.
Help::showNewContent(WindowMode::Persistent, Help::LinkCategory::Text, 0); if (auto *dlg = Term::mainScreenHelpDlg())
else if (lix < adMilitary) dlg->showNewContent(WindowMode::Persistent, Help::LinkCategory::Text, 0);
Help::showNewContent(WindowMode::Persistent, Help::LinkCategory::Adv, lix); } else if (lix < adMilitary) {
if (auto *dlg = Term::mainScreenHelpDlg())
dlg->showNewContent(WindowMode::Persistent, Help::LinkCategory::Adv, lix);
}
break; break;
case ListKind::Project: case ListKind::Project:
if (lix == cpImp + imTrGoods) if (lix == cpImp + imTrGoods) {
Help::showNewContent(WindowMode::Persistent, Help::LinkCategory::Text, 0); if (auto *dlg = Term::mainScreenHelpDlg())
else if ((lix & (cpImp | cpType)) == 0) dlg->showNewContent(WindowMode::Persistent, Help::LinkCategory::Text, 0);
} else if ((lix & (cpImp | cpType)) == 0) {
UnitStat::showNewContentOwnModel(WindowMode::Persistent, lix & cpIndex); UnitStat::showNewContentOwnModel(WindowMode::Persistent, lix & cpIndex);
else if ((lix & cpType) == 0 && lix != cpImp + imTrGoods) } else if ((lix & cpType) == 0 && lix != cpImp + imTrGoods) {
Help::showNewContent(WindowMode::Persistent, Help::LinkCategory::Imp, lix & cpIndex); if (auto *dlg = Term::mainScreenHelpDlg())
dlg->showNewContent(WindowMode::Persistent, Help::LinkCategory::Imp, lix & cpIndex);
}
break; break;
case ListKind::Government: case ListKind::Government:
Help::showNewContent(WindowMode::Persistent, Help::LinkCategory::Misc, if (auto *dlg = Term::mainScreenHelpDlg())
dlg->showNewContent(WindowMode::Persistent, Help::LinkCategory::Misc,
static_cast<int>(Help::MiscLinkIndex::GovList)); static_cast<int>(Help::MiscLinkIndex::GovList));
break; break;
default: default:
+1
View File
@@ -90,6 +90,7 @@ MainScreen::MainScreen(QWidget *parent) : DrawDlg(parent)
mainScreenMessgExDlg = [this] { return &messgExDlg(); }; mainScreenMessgExDlg = [this] { return &messgExDlg(); };
mainScreenModalSelectDlg = [this] { return &modalSelectDlg(); }; mainScreenModalSelectDlg = [this] { return &modalSelectDlg(); };
mainScreenNatStatDlg = [this] { return &natStatDlg(); }; mainScreenNatStatDlg = [this] { return &natStatDlg(); };
mainScreenHelpDlg = [this] { return &helpDlg(); };
mainScreenOfferCall = [this](const TOffer &offer) { mainScreenOfferCall = [this](const TOffer &offer) {
TOffer mutableOffer = offer; TOffer mutableOffer = offer;
return offerCall(mutableOffer); return offerCall(mutableOffer);
+7 -3
View File
@@ -487,13 +487,16 @@ QString cityEventName(int i)
void helpOnTerrain(int loc, WindowMode newMode) void helpOnTerrain(int loc, WindowMode newMode)
{ {
auto *dlg = mainScreenHelpDlg();
if (!dlg)
return;
if (ClientTools::myMap[loc] & fDeadLands) { 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 && } else if ((ClientTools::myMap[loc] & fTerrain) == fForest &&
IsoEngine::isJungle(loc / ClientTools::g.lx)) { 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 { } else {
Help::showNewContent(newMode, Help::LinkCategory::Ter, dlg->showNewContent(newMode, Help::LinkCategory::Ter,
(ClientTools::myMap[loc] & fTerrain) + (ClientTools::myMap[loc] >> 5 & 3) * 12); (ClientTools::myMap[loc] & fTerrain) + (ClientTools::myMap[loc] >> 5 & 3) * 12);
} }
} }
@@ -507,6 +510,7 @@ std::function<bool(int)> listDlgRenameCity = [](int) { return false; };
std::function<MessgEx::MessgExDlg *()> mainScreenMessgExDlg = [] { return static_cast<MessgEx::MessgExDlg *>(nullptr); }; std::function<MessgEx::MessgExDlg *()> mainScreenMessgExDlg = [] { return static_cast<MessgEx::MessgExDlg *>(nullptr); };
std::function<Select::ListDlg *()> mainScreenModalSelectDlg = [] { return static_cast<Select::ListDlg *>(nullptr); }; std::function<Select::ListDlg *()> mainScreenModalSelectDlg = [] { return static_cast<Select::ListDlg *>(nullptr); };
std::function<NatStat::NatStatDlg *()> mainScreenNatStatDlg = [] { return static_cast<NatStat::NatStatDlg *>(nullptr); }; std::function<NatStat::NatStatDlg *()> mainScreenNatStatDlg = [] { return static_cast<NatStat::NatStatDlg *>(nullptr); };
std::function<Help::HelpDlg *()> mainScreenHelpDlg = [] { return static_cast<Help::HelpDlg *>(nullptr); };
std::function<int(const TOffer &)> mainScreenOfferCall = [](const TOffer &) { return eInvalid; }; std::function<int(const TOffer &)> mainScreenOfferCall = [](const TOffer &) { return eInvalid; };
TOffer receivedOffer{}; TOffer receivedOffer{};
+5
View File
@@ -32,6 +32,7 @@
#include "Cevo/CevoScreenTools.h" #include "Cevo/CevoScreenTools.h"
#include "Cevo/Protocol.h" #include "Cevo/Protocol.h"
#include "ClientTools.h" #include "ClientTools.h"
#include "Help.h"
#include "MessgEx.h" #include "MessgEx.h"
#include "NatStat.h" #include "NatStat.h"
#include "Select.h" #include "Select.h"
@@ -311,6 +312,10 @@ extern std::function<MessgEx::MessgExDlg *()> mainScreenMessgExDlg;
// modalSelectDlgShowCityProject above for the city-project-only variant). // modalSelectDlgShowCityProject above for the city-project-only variant).
extern std::function<Select::ListDlg *()> mainScreenModalSelectDlg; extern std::function<Select::ListDlg *()> mainScreenModalSelectDlg;
extern std::function<NatStat::NatStatDlg *()> mainScreenNatStatDlg; extern std::function<NatStat::NatStatDlg *()> 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<Help::HelpDlg *()> mainScreenHelpDlg;
// Mirrors `MainScreen.OfferCall(var Offer: TOffer): Integer` - returns // Mirrors `MainScreen.OfferCall(var Offer: TOffer): Integer` - returns
// eInvalid by default. // eInvalid by default.
extern std::function<int(const TOffer &offer)> mainScreenOfferCall; extern std::function<int(const TOffer &offer)> mainScreenOfferCall;
+4 -1
View File
@@ -175,7 +175,10 @@ UnitStatDlg::UnitStatDlg(QWidget *parent) : BufferedDrawDlg(parent), ui(new Ui::
ui->conscriptsBtn->setToolTip(phrase(QStringLiteral("BTN_ALLOWCONSCRIPTS"))); 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::showNewContentOwnModel = [this](WindowMode newMode, int mix) { this->showNewContentOwnModel(newMode, mix); };
UnitStat::showNewContentEnemyModel = [this](WindowMode newMode, int emix) { UnitStat::showNewContentEnemyModel = [this](WindowMode newMode, int emix) {
+4 -2
View File
@@ -314,8 +314,10 @@ void WondersDlg::mouseMoveEvent(QMouseEvent *event)
void WondersDlg::mousePressEvent(QMouseEvent *event) void WondersDlg::mousePressEvent(QMouseEvent *event)
{ {
if (selection >= 0 && Help::showNewContent) if (selection >= 0) {
Help::showNewContent(windowModeMakePersistent(windowMode()), Help::LinkCategory::Imp, selection); if (auto *dlg = Term::mainScreenHelpDlg())
dlg->showNewContent(windowModeMakePersistent(windowMode()), Help::LinkCategory::Imp, selection);
}
BufferedDrawDlg::mousePressEvent(event); BufferedDrawDlg::mousePressEvent(event);
} }