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)];
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;
+2 -1
View File
@@ -474,7 +474,8 @@ void DraftDlg::mousePressEvent(QMouseEvent *event)
const int i = (y - yFeature) / LinePitch;
const int c = code[static_cast<std::size_t>(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;
+4 -3
View File
@@ -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);
}
+4 -3
View File
@@ -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);
+17 -10
View File
@@ -1696,24 +1696,31 @@ 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,
if (auto *dlg = Term::mainScreenHelpDlg())
dlg->showNewContent(WindowMode::Persistent, Help::LinkCategory::Misc,
static_cast<int>(Help::MiscLinkIndex::GovList));
break;
default:
+1
View File
@@ -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);
+7 -3
View File
@@ -487,13 +487,16 @@ 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,
dlg->showNewContent(newMode, Help::LinkCategory::Ter,
(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<Select::ListDlg *()> mainScreenModalSelectDlg = [] { return static_cast<Select::ListDlg *>(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; };
TOffer receivedOffer{};
+5
View File
@@ -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<MessgEx::MessgExDlg *()> mainScreenMessgExDlg;
// modalSelectDlgShowCityProject above for the city-project-only variant).
extern std::function<Select::ListDlg *()> mainScreenModalSelectDlg;
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
// eInvalid by default.
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->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) {
+4 -2
View File
@@ -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);
}