implemented wonders and help stub

This commit is contained in:
Geoffray Levasseur committed 2026-11-03 13:53:55 +01:00
1 parent 5854b17acd
commit f22e49a85d
6 files changed
+557

No files matched your search

+5
View File
@@ -139,6 +139,11 @@ set(PROJECT_SOURCES
game/localplayer/Term.h game/localplayer/Term.h
game/localplayer/Tribes.cpp game/localplayer/Tribes.cpp
game/localplayer/Tribes.h 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} ${TS_FILES}
) )
+37
View File
@@ -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<void(WindowMode, LinkCategory, int)> showNewContent;
} // namespace Help
} // namespace Cevo
+54
View File
@@ -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 <functional>
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<void(WindowMode, LinkCategory, int)> showNewContent;
} // namespace Help
} // namespace Cevo
+326
View File
@@ -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 <QHash>
#include <QMouseEvent>
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<QString, QString> 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<std::int64_t>(x) * x * ((height / 4) * (height / 4)) +
static_cast<std::int64_t>(y) * y * ((width / 4) * (width / 4));
const std::int64_t ax = static_cast<std::int64_t>((65536 / (height / 4)) * (width / 4)) * y;
const bool a = r >= static_cast<std::int64_t>(height / 4) * (height / 2) * (width / 2) * (width / 2);
const bool b = ax < static_cast<std::int64_t>(amax2) * x;
const bool c = ax < static_cast<std::int64_t>(amax0) * x || ax > static_cast<std::int64_t>(amin2) * x;
const bool d = ax > static_cast<std::int64_t>(amin1) * x;
const bool e = ax < static_cast<std::int64_t>(amax1) * x || ax > static_cast<std::int64_t>(amin3) * x;
if (r < static_cast<std::int64_t>(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<std::size_t>(FontType::Caption)]);
QString s = phrase(QStringLiteral("TITLE_WONDERS"));
risedTextOut(canvas, (width() - biColorTextWidth(canvas, s)) / 2 - 1, 7, s);
canvas.font().assign(UniFont[static_cast<std::size_t>(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<std::size_t>(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<std::size_t>(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
+74
View File
@@ -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 <QPoint>
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
+61
View File
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<ui version="4.0">
<class>WondersDlg</class>
<widget class="QWidget" name="WondersDlg">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>480</width>
<height>416</height>
</rect>
</property>
<property name="windowTitle">
<string>C-evo</string>
</property>
<widget class="Cevo::ButtonB" name="closeBtn">
<property name="geometry">
<rect>
<x>442</x>
<y>6</y>
<width>25</width>
<height>25</height>
</rect>
</property>
</widget>
</widget>
<customwidgets>
<customwidget>
<class>Cevo::ButtonB</class>
<extends>QWidget</extends>
<header>Cevo/CevoButtonB.h</header>
</customwidget>
</customwidgets>
<resources/>
</ui>