From f22e49a85d42e173d0ff8ed13dd40eb9d1fb325d Mon Sep 17 00:00:00 2001 From: Geoffray Levasseur Date: Tue, 3 Nov 2026 13:53:55 +0100 Subject: [PATCH] implemented wonders and help stub --- CMakeLists.txt | 5 + game/localplayer/Help.cpp | 37 ++++ game/localplayer/Help.h | 54 ++++++ game/localplayer/Wonders.cpp | 326 +++++++++++++++++++++++++++++++++++ game/localplayer/Wonders.h | 74 ++++++++ game/localplayer/Wonders.ui | 61 +++++++ 6 files changed, 557 insertions(+) create mode 100644 game/localplayer/Help.cpp create mode 100644 game/localplayer/Help.h create mode 100644 game/localplayer/Wonders.cpp create mode 100644 game/localplayer/Wonders.h create mode 100644 game/localplayer/Wonders.ui diff --git a/CMakeLists.txt b/CMakeLists.txt index 54165dd..8f99bd6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -139,6 +139,11 @@ set(PROJECT_SOURCES game/localplayer/Term.h game/localplayer/Tribes.cpp game/localplayer/Tribes.h + game/localplayer/Help.cpp + game/localplayer/Help.h + game/localplayer/Wonders.cpp + game/localplayer/Wonders.h + game/localplayer/Wonders.ui ${TS_FILES} ) diff --git a/game/localplayer/Help.cpp b/game/localplayer/Help.cpp new file mode 100644 index 0000000..df52bdc --- /dev/null +++ b/game/localplayer/Help.cpp @@ -0,0 +1,37 @@ +// 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. + +#include "Help.h" + +namespace Cevo { +namespace Help { + +std::function showNewContent; + +} // namespace Help +} // namespace Cevo diff --git a/game/localplayer/Help.h b/game/localplayer/Help.h new file mode 100644 index 0000000..8208684 --- /dev/null +++ b/game/localplayer/Help.h @@ -0,0 +1,54 @@ +// 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 + +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. +extern std::function showNewContent; + +} // namespace Help +} // namespace Cevo diff --git a/game/localplayer/Wonders.cpp b/game/localplayer/Wonders.cpp new file mode 100644 index 0000000..339c8aa --- /dev/null +++ b/game/localplayer/Wonders.cpp @@ -0,0 +1,326 @@ +// 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. + +#include "Wonders.h" +#include "ui_Wonders.h" + +#include "Cevo/CevoScreenTools.h" +#include "Cevo/CevoTexture.h" +#include "ClientTools.h" +#include "Help.h" +#include "Term.h" +#include "Tribes.h" + +#include "Dpi/DpiPixelPointer.h" + +#include +#include + +namespace Cevo { +namespace Wonders { + +namespace { + +constexpr QPoint RingPosition[21] = { + QPoint(-80, -32), // Pyramids + QPoint(80, -32), // Zeus + QPoint(0, -64), // Gardens + QPoint(0, 0), // Colossus + QPoint(0, 64), // Lighthouse + QPoint(-80, 32), // GrLibrary + QPoint(-90, 114), // Oracle + QPoint(80, 32), // Sun + QPoint(90, -114), // Leo + QPoint(-180, 0), // Magellan + QPoint(90, 114), // Mich + QPoint(0, 0), // (11) + QPoint(180, 0), // Newton + QPoint(-90, -114), // Bach + QPoint(0, 0), // (14) + QPoint(-160, -64), // Liberty + QPoint(0, 128), // Eiffel + QPoint(160, -64), // Hoover + QPoint(-160, 64), // Shinkansen + QPoint(0, -128), // Manhattan + QPoint(160, 64), // Mir +}; + +// Phrases/Phrases2 (StringTables.pas) aren't ported; disclosed +// plain-English placeholders for this dialog's own text. +QString phrase(const QString &key) +{ + static const QHash table = { + {QStringLiteral("TITLE_WONDERS"), QStringLiteral("World Wonders")}, + {QStringLiteral("NOWONDER"), QStringLiteral("No wonder built yet")}, + {QStringLiteral("DESTROYED"), QStringLiteral("Destroyed")}, + {QStringLiteral("EXPIRED"), QStringLiteral("Expired")}, + }; + const auto it = table.constFind(key); + return it != table.constEnd() ? it.value() : key; +} + +} // namespace + +WondersDlg::WondersDlg(QWidget *parent) : BufferedDrawDlg(parent), ui(new Ui::WondersDlg) +{ + ui->setupUi(this); + ui->closeBtn->setButtonIndex(0); + ui->closeBtn->onClick = [this] { close(); }; + initButtons(); +} + +WondersDlg::~WondersDlg() +{ + delete ui; +} + +void WondersDlg::paintBackgroundShape() +{ + constexpr int Darken = 24; + constexpr int amax0 = 15734; + constexpr int amin1 = 19413; + constexpr int amax1 = 62191; + constexpr int amin2 = 69061; + constexpr int amax2 = 221246; + constexpr int amin3 = 272977; + constexpr int width = 180; + constexpr int height = 128; + + auto darken = [](QRgb px) { + auto channel = [](int c) { c -= Darken; return c < 0 ? 0 : c; }; + return qRgb(channel(qRed(px)), channel(qGreen(px)), channel(qBlue(px))); + }; + + QImage &image = offscreen.image(); + Dpi::PixelPointer line0(&image, center.x(), center.y()); + Dpi::PixelPointer line1(&image, center.x(), center.y() - 1); + Dpi::PixelPointer line2(&image, center.x() - 1, center.y()); + Dpi::PixelPointer line3(&image, center.x() - 1, center.y() - 1); + + for (int y = 0; y < height; ++y) { + for (int x = 0; x < width; ++x) { + const std::int64_t r = static_cast(x) * x * ((height / 4) * (height / 4)) + + static_cast(y) * y * ((width / 4) * (width / 4)); + const std::int64_t ax = static_cast((65536 / (height / 4)) * (width / 4)) * y; + const bool a = r >= static_cast(height / 4) * (height / 2) * (width / 2) * (width / 2); + const bool b = ax < static_cast(amax2) * x; + const bool c = ax < static_cast(amax0) * x || ax > static_cast(amin2) * x; + const bool d = ax > static_cast(amin1) * x; + const bool e = ax < static_cast(amax1) * x || ax > static_cast(amin3) * x; + if (r < static_cast(8) * height * width * width && ((a && b && c) || (d && e))) { + line0.setPixelRGB(darken(line0.pixelRGB())); + line1.setPixelRGB(darken(line1.pixelRGB())); + line2.setPixelRGB(darken(line2.pixelRGB())); + line3.setPixelRGB(darken(line3.pixelRGB())); + } + line0.nextPixel(); + line1.nextPixel(); + line2.previousPixel(); + line3.previousPixel(); + } + line0.nextLine(); + line1.previousLine(); + line2.nextLine(); + line3.previousLine(); + } +} + +void WondersDlg::darkIcon(int i) +{ + const int x0Dst = width() / 2 - xSizeBig / 2 + RingPosition[i].x(); + const int y0Dst = height() / 2 - ySizeBig / 2 + RingPosition[i].y(); + const int x0Src = (i % 7) * xSizeBig; + const int y0Src = (i / 7 + Term::SystemIconLines) * ySizeBig; + Dpi::PixelPointer src(&bigImp->image(), x0Src, y0Src); + Dpi::PixelPointer dst(&offscreen.image(), x0Dst, y0Dst); + for (int y = 0; y < ySizeBig; ++y) { + for (int x = 0; x < xSizeBig; ++x) { + const QRgb s = src.pixelRGB(); + const int darkenAmount = ((255 - qBlue(s)) * 3 + (255 - qGreen(s)) * 15 + (255 - qRed(s)) * 9) / 128; + auto channel = [darkenAmount](int c) { c -= darkenAmount; return c < 0 ? 0 : c; }; + const QRgb d = dst.pixelRGB(); + dst.setPixelRGB(qRgb(channel(qRed(d)), channel(qGreen(d)), channel(qBlue(d)))); + src.nextPixel(); + dst.nextPixel(); + } + src.nextLine(); + dst.nextLine(); + } +} + +void WondersDlg::glow(int i, QColor glowColor) +{ + glowFrame(offscreen, width() / 2 - xSizeBig / 2 + RingPosition[i].x(), + height() / 2 - ySizeBig / 2 + RingPosition[i].y(), xSizeBig, ySizeBig, glowColor); +} + +void WondersDlg::offscreenPaint() +{ + BufferedDrawDlg::offscreenPaint(); + if (!MainTexture || !bigImp) + return; + + Dpi::Canvas &canvas = offscreen.canvas(); + canvas.begin(); + fill(canvas, 3, 3, width() - 6, height() - 6, (MainTexture->width() - width()) / 2, + (MainTexture->height() - height()) / 2); + frame(canvas, 0, 0, width() - 1, height() - 1, Qt::black, Qt::black); + frame(canvas, 1, 1, width() - 2, height() - 2, MainTexture->colorBevelLight, MainTexture->colorBevelShade); + frame(canvas, 2, 2, width() - 3, height() - 3, MainTexture->colorBevelLight, MainTexture->colorBevelShade); + corner(canvas, 1, 1, 0, *MainTexture); + corner(canvas, width() - 9, 1, 1, *MainTexture); + corner(canvas, 1, height() - 9, 2, *MainTexture); + corner(canvas, width() - 9, height() - 9, 3, *MainTexture); + + btnFrame(canvas, ui->closeBtn->geometry(), *MainTexture); + + canvas.font().assign(UniFont[static_cast(FontType::Caption)]); + QString s = phrase(QStringLiteral("TITLE_WONDERS")); + risedTextOut(canvas, (width() - biColorTextWidth(canvas, s)) / 2 - 1, 7, s); + canvas.font().assign(UniFont[static_cast(FontType::Normal)]); + + center = QPoint(width() / 2, height() / 2); + paintBackgroundShape(); + + bool haveWonder = false; + for (int i = 0; i <= 20; ++i) { + if (Imp[i].Preq == preNA) + continue; + switch (ClientTools::myRO->Wonder[i].CityID) { + case WonderNotBuiltYet: + fill(canvas, center.x() - xSizeBig / 2 + RingPosition[i].x() - 3, + center.y() - ySizeBig / 2 + RingPosition[i].y() - 3, xSizeBig + 6, ySizeBig + 6, + (MainTexture->width() - width()) / 2, (MainTexture->height() - height()) / 2); + break; + case WonderDestroyed: + haveWonder = true; + bitBltBitmap(offscreen, center.x() - xSizeBig / 2 + RingPosition[i].x(), + center.y() - ySizeBig / 2 + RingPosition[i].y(), xSizeBig, ySizeBig, *bigImp, 0, + (Term::SystemIconLines + 3) * ySizeBig); + break; + default: + haveWonder = true; + bitBltBitmap(offscreen, center.x() - xSizeBig / 2 + RingPosition[i].x(), + center.y() - ySizeBig / 2 + RingPosition[i].y(), xSizeBig, ySizeBig, *bigImp, + (i % 7) * xSizeBig, (i / 7 + Term::SystemIconLines) * ySizeBig); + break; + } + } + + for (int i = 0; i <= 20; ++i) { + if (Imp[i].Preq == preNA) + continue; + switch (ClientTools::myRO->Wonder[i].CityID) { + case WonderNotBuiltYet: + darkIcon(i); + break; + case WonderDestroyed: + glow(i, Qt::black); + break; + default: + if (ClientTools::myRO->Wonder[i].EffectiveOwner >= 0) + glow(i, Tribes::tribe[static_cast(ClientTools::myRO->Wonder[i].EffectiveOwner)]->color); + else + glow(i, Qt::black); + break; + } + } + + if (!haveWonder) { + s = phrase(QStringLiteral("NOWONDER")); + risedTextOut(canvas, center.x() - biColorTextWidth(canvas, s) / 2, center.y() - canvas.textHeight(s) / 2, s); + } + canvas.end(); + + markUsedOffscreen(width(), height()); +} + +void WondersDlg::vpaint(Dpi::Canvas &canvas) +{ + BufferedDrawDlg::vpaint(canvas); + if (selection < 0 || !MainTexture) + return; + + QString s = QStringLiteral("Wonder #%1").arg(selection); + if (ClientTools::myRO->Wonder[selection].CityID != WonderDestroyed) + s = QStringLiteral("%1 (%2)").arg(s, Tribes::cityName(ClientTools::myRO->Wonder[selection].CityID)); + loweredTextOut(canvas, -1, *MainTexture, (width() - biColorTextWidth(canvas, s)) / 2, height() - 3 - 36 - 10, s); + + if (ClientTools::myRO->Wonder[selection].CityID == WonderDestroyed) + s = phrase(QStringLiteral("DESTROYED")); + else if (ClientTools::myRO->Wonder[selection].EffectiveOwner < 0) + s = phrase(QStringLiteral("EXPIRED")); + else + s = Tribes::tribe[static_cast(ClientTools::myRO->Wonder[selection].EffectiveOwner)]->tPhrase( + QStringLiteral("WONDEROWNER")); + loweredTextOut(canvas, -1, *MainTexture, (width() - biColorTextWidth(canvas, s)) / 2, height() - 3 - 36 + 10, s); +} + +void WondersDlg::showEvent(QShowEvent *event) +{ + BufferedDrawDlg::showEvent(event); + setWindowTitle(phrase(QStringLiteral("TITLE_WONDERS"))); + selection = -1; + offscreenPaint(); +} + +void WondersDlg::resizeEvent(QResizeEvent *event) +{ + BufferedDrawDlg::resizeEvent(event); + ui->closeBtn->move(width() - 38, ui->closeBtn->y()); +} + +void WondersDlg::mouseMoveEvent(QMouseEvent *event) +{ + const int x = event->pos().x(); + const int y = event->pos().y(); + const int oldSelection = selection; + selection = -1; + for (int i = 0; i <= 20; ++i) { + if (Imp[i].Preq != preNA && x >= center.x() - xSizeBig / 2 + RingPosition[i].x() && + x < center.x() + xSizeBig / 2 + RingPosition[i].x() && + y >= center.y() - ySizeBig / 2 + RingPosition[i].y() && + y < center.y() + ySizeBig / 2 + RingPosition[i].y()) { + selection = i; + break; + } + } + if (selection != oldSelection) + update(); + BufferedDrawDlg::mouseMoveEvent(event); +} + +void WondersDlg::mousePressEvent(QMouseEvent *event) +{ + if (selection >= 0 && Help::showNewContent) + Help::showNewContent(windowModeMakePersistent(windowMode()), Help::LinkCategory::Imp, selection); + BufferedDrawDlg::mousePressEvent(event); +} + +} // namespace Wonders +} // namespace Cevo diff --git a/game/localplayer/Wonders.h b/game/localplayer/Wonders.h new file mode 100644 index 0000000..0a4d9fa --- /dev/null +++ b/game/localplayer/Wonders.h @@ -0,0 +1,74 @@ +// 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 + +QT_BEGIN_NAMESPACE +namespace Ui { +class WondersDlg; +} +QT_END_NAMESPACE + +namespace Cevo { +namespace Wonders { + +// TWondersDlg equivalent: shows all 21 wonders arranged in a ring, each +// dimmed/glowing/darkened depending on built/destroyed/not-yet-built +// status. UI built from Wonders.ui (adapted from the original's +// Wonders.lfm). +class WondersDlg : public BufferedDrawDlg { + Q_OBJECT +public: + explicit WondersDlg(QWidget *parent = nullptr); + ~WondersDlg() override; + +protected: + void offscreenPaint() override; + void vpaint(Dpi::Canvas &canvas) override; + void showEvent(QShowEvent *event) override; + void resizeEvent(QResizeEvent *event) override; + void mouseMoveEvent(QMouseEvent *event) override; + void mousePressEvent(QMouseEvent *event) override; + +private: + void darkIcon(int i); + void glow(int i, QColor glowColor); + void paintBackgroundShape(); + + int selection = -1; + QPoint center; + + Ui::WondersDlg *ui; +}; + +} // namespace Wonders +} // namespace Cevo diff --git a/game/localplayer/Wonders.ui b/game/localplayer/Wonders.ui new file mode 100644 index 0000000..6b2fa57 --- /dev/null +++ b/game/localplayer/Wonders.ui @@ -0,0 +1,61 @@ + + + + WondersDlg + + + + 0 + 0 + 480 + 416 + + + + C-evo + + + + + 442 + 6 + 25 + 25 + + + + + + + Cevo::ButtonB + QWidget +
Cevo/CevoButtonB.h
+
+
+ +