173 lines
6.5 KiB
C++
173 lines
6.5 KiB
C++
// 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.
|
|
|
|
#pragma once
|
|
|
|
#include "Cevo/CevoBaseWin.h"
|
|
#include "Cevo/CevoPVScrollBar.h"
|
|
#include "Cevo/CevoStringTables.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 {
|
|
|
|
// 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)` -
|
|
// 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;
|
|
};
|
|
|
|
// 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(); }
|
|
// Help.pas's `Difficulty` (the game's difficulty level, 0 for none).
|
|
int difficulty = 0;
|
|
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);
|
|
// Builds mainText's body for a single LinkCategory::Adv page (Help.pas's
|
|
// THelpDlg.Prepare's hkAdv branch): prerequisites, and what the advance
|
|
// newly allows (governments/improvements/features/further research).
|
|
void prepareAdvance(int advance);
|
|
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
|