// 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 #include #include #include #include #include QT_BEGIN_NAMESPACE namespace Ui { class HelpDlg; } QT_END_NAMESPACE namespace Dpi { class Bitmap; } 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 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(m_lines.size()); } const QString &text(int i) const { return m_lines[static_cast(i)]; } QString &text(int i) { return m_lines[static_cast(i)]; } const HelpLineInfo &info(int i) const { return m_info[static_cast(i)]; } private: std::vector m_lines; std::vector 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); // Same idea as prepareAdvance(), for LinkCategory::Imp pages. void prepareImprovement(int imp); // Same idea, for LinkCategory::Ter (single terrain type) pages. void prepareTerrain(int no); // Same idea, for LinkCategory::Feature (unit feature) pages. void prepareFeature(int no); // Same idea, for LinkCategory::Model (special unit) pages. void prepareModel(int no); // Misc front page (navigation hub to every other page kind). void prepareMiscMain(); void prepareMiscGovList(); void prepareMiscJobList(); void prepareMiscCredits(); // Help.pas's DecodeItem(): decodes a ":KEY"/":Xnn" link token (used // inside addTextual()'s markup) into a category + index. void decodeItem(const QString &item, LinkCategory &category, int &index) const; // Help.pas's AddTextual(): parses Help.txt's inline markup (links, // section/caption headers, bullet lists, line breaks) and word-wraps // the result into mainText lines. Used by LinkCategory::Text pages and // a few AddItem()-style single paragraphs elsewhere. void addTextual(const QString &text); void search(const QString &searchString); void line(Dpi::Canvas &canvas, int i, bool lit); void paintTerrIcon(int x, int y, int xSrc, int ySrc); // Help.pas's WaterSign(): draws a big improvement/wonder illustration. // Simplified from the original's per-pixel sky-detecting watermark blend // (2x upscaled, faded into the paper background) to a plain icon blit - // still shows the real illustration, just without the blend effect. void waterSign(int x0, int y0, int iix); void backBtnClicked(); void topBtnClicked(); void searchBtnClicked(); LinkCategory kind = LinkCategory::Misc; int no = static_cast(MiscLinkIndex::Main); int sel = -1; QColor captionColor; QString searchContent; QString newSearchContent; HyperText mainText; HyperText searchResult; StringTable helpText; // Help.pas's ExtPic: the single external illustration bitmap (Help/*.png) // referenced by the currently displayed page's "@filename\" markup. std::unique_ptr extPic; std::vector histItems; PVScrollBar *scrollBar; std::array x0{}; // x0[-2..180], offset by +2 Ui::HelpDlg *ui; }; } // namespace Help } // namespace Cevo