// 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