first pass of help implementation
This commit is contained in:
1 parent
1667e18dda
commit
b5085fd11f
3 files changed
+617
-9
No files matched your search
+148
-9
@@ -29,26 +29,165 @@
|
||||
#pragma once
|
||||
|
||||
#include "Cevo/CevoBaseWin.h"
|
||||
#include "Cevo/CevoPVScrollBar.h"
|
||||
|
||||
#include <QColor>
|
||||
#include <QString>
|
||||
|
||||
#include <array>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui {
|
||||
class HelpDlg;
|
||||
}
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace Cevo {
|
||||
namespace Help {
|
||||
|
||||
// PORT STATUS: Help.pas itself (~2300 lines, the in-game encyclopedia) is
|
||||
// deliberately deferred - it needs StringTables.pas (not ported) for its
|
||||
// actual content. This file only pre-seeds the handful of symbols other
|
||||
// leaf dialogs need to request a help page; extend this same file in
|
||||
// place when Help.pas's real turn comes, do not create a second
|
||||
// Help-ish file.
|
||||
|
||||
// Help.pas's `TLinkCategory` (which help-content section to jump to).
|
||||
enum class LinkCategory { NoLink, Adv, Imp, Ter, Feature, Internet, Model, Misc, Text };
|
||||
|
||||
// Mirrors `MainScreen.HelpDlg.ShowNewContent(NewMode, Category, Index)` -
|
||||
// null (no-op) until Term.pas is ported and wires this up to a real
|
||||
// THelpDlg instance.
|
||||
// wired up to a real HelpDlg instance's showNewContent() once one exists
|
||||
// (Term.pas, which owns the one true instance, isn't ported yet).
|
||||
extern std::function<void(WindowMode, LinkCategory, int)> showNewContent;
|
||||
|
||||
// Help.pas's `TMiscLinkIndex` (link indices for category Misc).
|
||||
enum class MiscLinkIndex { Main, Credits, GovList, JobList, SearchResult };
|
||||
|
||||
// Help.pas's `TTextFormat` (how a hypertext line's icon/layout is drawn).
|
||||
enum class TextFormat {
|
||||
Normal, Caption, SmallIcon, BigIcon, AdvIcon, Ter, BigTer, Feature, Dot, NormalDot, Domain, Section, BigFeature,
|
||||
Exp, AITStat, External, Model, Normal64, Illu, Logo, TerImp, RightIcon, AdvIconAsPreq, SmallIconAsPreq,
|
||||
SpecialIcon, Gov,
|
||||
};
|
||||
|
||||
// THelpLineInfo equivalent: per-line metadata stored alongside each
|
||||
// QString in a HyperText list.
|
||||
struct HelpLineInfo {
|
||||
TextFormat format = TextFormat::Normal;
|
||||
int picPix = 0;
|
||||
LinkCategory category = LinkCategory::NoLink;
|
||||
int index = 0;
|
||||
bool crossLink = false;
|
||||
};
|
||||
|
||||
// THyperText equivalent: a list of displayable lines, each with its own
|
||||
// HelpLineInfo (TStringList+Objects in the original).
|
||||
class HyperText {
|
||||
public:
|
||||
void addLine(const QString &s = QString(), TextFormat format = TextFormat::Normal, int picPix = 0,
|
||||
LinkCategory linkCategory = LinkCategory::NoLink, int linkIndex = 0, bool crossLink = false);
|
||||
void lineFeed() { addLine(); }
|
||||
void appendList(const HyperText &source);
|
||||
void clear();
|
||||
|
||||
int count() const { return static_cast<int>(m_lines.size()); }
|
||||
const QString &text(int i) const { return m_lines[static_cast<std::size_t>(i)]; }
|
||||
QString &text(int i) { return m_lines[static_cast<std::size_t>(i)]; }
|
||||
const HelpLineInfo &info(int i) const { return m_info[static_cast<std::size_t>(i)]; }
|
||||
|
||||
private:
|
||||
std::vector<QString> m_lines;
|
||||
std::vector<HelpLineInfo> m_info;
|
||||
};
|
||||
|
||||
// THistItem equivalent: one navigation history entry.
|
||||
struct HistItem {
|
||||
LinkCategory kind = LinkCategory::NoLink;
|
||||
int no = 0;
|
||||
int pos = 0;
|
||||
QString searchContent;
|
||||
};
|
||||
|
||||
// Minimal stand-in for StringTables.pas's TStringTable (not ported) - a
|
||||
// key->text lookup with handle-based indirection and full-text search.
|
||||
// Since Help/Help.txt's real content isn't available without a
|
||||
// StringTables.pas port, every lookup returns a disclosed placeholder and
|
||||
// search() never matches anything.
|
||||
class StringTable {
|
||||
public:
|
||||
void loadFromFile(const QString &fileName) { Q_UNUSED(fileName); }
|
||||
QString operator[](const QString &key) const { return key; }
|
||||
int getHandle(const QString &key) const
|
||||
{
|
||||
Q_UNUSED(key);
|
||||
return -1;
|
||||
}
|
||||
QString lookupByHandle(int handle) const
|
||||
{
|
||||
Q_UNUSED(handle);
|
||||
return QString();
|
||||
}
|
||||
bool search(const QString &searchString, int &handle, int &index) const
|
||||
{
|
||||
Q_UNUSED(searchString);
|
||||
Q_UNUSED(handle);
|
||||
Q_UNUSED(index);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
// THelpDlg equivalent: the in-game encyclopedia/hypertext browser. UI built
|
||||
// from Help.ui (adapted from the original's Help.lfm). The real content
|
||||
// (Help/Help.txt via StringTables.pas) isn't available, so prepare()/
|
||||
// offscreenPaint() render a simplified, disclosed-placeholder version of
|
||||
// each page rather than the original's full icon-rich layout - the
|
||||
// history/search/scrolling/link-click machinery itself is faithful.
|
||||
class HelpDlg : public FramedDlg {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit HelpDlg(QWidget *parent = nullptr);
|
||||
~HelpDlg() override;
|
||||
|
||||
void clearHistory() { histItems.clear(); }
|
||||
void showNewContent(WindowMode newMode, LinkCategory category, int index);
|
||||
int textIndex(const QString &item) const { return helpText.getHandle(item); }
|
||||
|
||||
protected:
|
||||
void offscreenPaint() override;
|
||||
void resizeEvent(QResizeEvent *event) override;
|
||||
void closeEvent(QCloseEvent *event) override;
|
||||
void keyPressEvent(QKeyEvent *event) override;
|
||||
void wheelEvent(QWheelEvent *event) override;
|
||||
void mouseMoveEvent(QMouseEvent *event) override;
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
|
||||
private:
|
||||
void prepare(int sbPos = 0);
|
||||
void search(const QString &searchString);
|
||||
void line(Dpi::Canvas &canvas, int i, bool lit);
|
||||
void paintTerrIcon(int x, int y, int xSrc, int ySrc);
|
||||
// Placeholder for the original's pixel-level water-reflection effect
|
||||
// on wonder/illustration icons - purely cosmetic, not yet ported.
|
||||
void waterSign(int x0, int y0, int iix)
|
||||
{
|
||||
Q_UNUSED(x0);
|
||||
Q_UNUSED(y0);
|
||||
Q_UNUSED(iix);
|
||||
}
|
||||
void backBtnClicked();
|
||||
void topBtnClicked();
|
||||
void searchBtnClicked();
|
||||
|
||||
LinkCategory kind = LinkCategory::Misc;
|
||||
int no = static_cast<int>(MiscLinkIndex::Main);
|
||||
int sel = -1;
|
||||
QColor captionColor;
|
||||
QString searchContent;
|
||||
QString newSearchContent;
|
||||
HyperText mainText;
|
||||
HyperText searchResult;
|
||||
StringTable helpText;
|
||||
std::vector<HistItem> histItems;
|
||||
PVScrollBar *scrollBar;
|
||||
std::array<int, 183> x0{}; // x0[-2..180], offset by +2
|
||||
|
||||
Ui::HelpDlg *ui;
|
||||
};
|
||||
|
||||
} // namespace Help
|
||||
} // namespace Cevo
|
||||
Reference in new issue
Block a user