From 5854b17acde0436b73798a7b041441fb2385698a Mon Sep 17 00:00:00 2001 From: Geoffray Levasseur Date: Tue, 3 Nov 2026 13:48:06 +0100 Subject: [PATCH] implemented rates --- CMakeLists.txt | 3 + game/localplayer/Rates.cpp | 201 +++++++++++++++++++++++++++++++++++++ game/localplayer/Rates.h | 64 ++++++++++++ game/localplayer/Rates.ui | 106 +++++++++++++++++++ 4 files changed, 374 insertions(+) create mode 100644 game/localplayer/Rates.cpp create mode 100644 game/localplayer/Rates.h create mode 100644 game/localplayer/Rates.ui diff --git a/CMakeLists.txt b/CMakeLists.txt index 73a7d34..54165dd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -129,6 +129,9 @@ set(PROJECT_SOURCES game/localplayer/Diplomacy.h game/localplayer/IsoEngine.cpp game/localplayer/IsoEngine.h + game/localplayer/Rates.cpp + game/localplayer/Rates.h + game/localplayer/Rates.ui game/localplayer/TechTree.cpp game/localplayer/TechTree.h game/localplayer/TechTree.ui diff --git a/game/localplayer/Rates.cpp b/game/localplayer/Rates.cpp new file mode 100644 index 0000000..12c3262 --- /dev/null +++ b/game/localplayer/Rates.cpp @@ -0,0 +1,201 @@ +// 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 "Rates.h" +#include "ui_Rates.h" + +#include "Cevo/CevoScreenTools.h" +#include "Cevo/CevoTexture.h" +#include "ClientTools.h" +#include "Term.h" +#include "Tribes.h" + +#include + +namespace Cevo { +namespace Rates { + +namespace { + +constexpr int MessageLineSpacing = 20; + +// 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_RATES"), QStringLiteral("Rates")}, + {QStringLiteral("NORATES"), QStringLiteral("The Statue of Liberty lets your people decide for themselves.")}, + {QStringLiteral("RATES"), QStringLiteral("Set your tax, science and luxury rates.\\(click the arrows)")}, + {QStringLiteral("SCIENCE"), QStringLiteral("Science")}, + {QStringLiteral("LUX"), QStringLiteral("Luxury")}, + {QStringLiteral("TAXRATE"), QStringLiteral("Tax")}, + }; + const auto it = table.constFind(key); + return it != table.constEnd() ? it.value() : key; +} + +} // namespace + +RatesDlg::RatesDlg(QWidget *parent) : BufferedDrawDlg(parent), ui(new Ui::RatesDlg) +{ + ui->setupUi(this); + titleHeight = Dpi::Screen::primaryMonitor().height(); + initButtons(); + + ui->closeBtn->onClick = [this] { close(); }; + ui->taxUpBtn->onClick = [this] { taxLuxBtnClick(0); }; + ui->taxDownBtn->onClick = [this] { taxLuxBtnClick(1); }; + ui->scienceBtn->onClick = [this] { taxLuxBtnClick(2); }; + ui->luxBtn->onClick = [this] { taxLuxBtnClick(3); }; +} + +RatesDlg::~RatesDlg() +{ + delete ui; +} + +void RatesDlg::offscreenPaint() +{ + BufferedDrawDlg::offscreenPaint(); + Dpi::Canvas &canvas = offscreen.canvas(); + canvas.begin(); + + fill(canvas, 0, 0, width(), height(), (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); + + btnFrame(canvas, ui->closeBtn->geometry(), *MainTexture); + canvas.font().assign(UniFont[static_cast(FontType::Caption)]); + QString s = phrase(QStringLiteral("TITLE_RATES")); + risedTextOut(canvas, (width() - biColorTextWidth(canvas, s)) / 2 - 1, 7, s); + + const bool hasLiberty = ClientTools::myRO->Wonder[woLiberty].EffectiveOwner == ClientTools::me; + s = phrase(hasLiberty ? QStringLiteral("NORATES") : QStringLiteral("RATES")); + canvas.font().assign(UniFont[static_cast(FontType::Normal)]); + const int p = s.indexOf(QLatin1Char('\\')); + if (p < 0) { + risedTextOut(canvas, (width() - biColorTextWidth(canvas, s)) / 2, 114, s); + } else { + QString s1 = s.left(p); + risedTextOut(canvas, (width() - biColorTextWidth(canvas, s1)) / 2, 114 - MessageLineSpacing / 2, s1); + s1 = s.mid(p + 1); + risedTextOut(canvas, (width() - biColorTextWidth(canvas, s1)) / 2, + 114 + (MessageLineSpacing - MessageLineSpacing / 2), s1); + } + canvas.font().assign(UniFont[static_cast(FontType::Small)]); + + if (hasLiberty) { + glowFrame(offscreen, width() / 2 - xSizeBig / 2, 52, xSizeBig, ySizeBig, + Tribes::tribe[static_cast(ClientTools::me)]->color); + bitBltBitmap(offscreen, width() / 2 - xSizeBig / 2, 52, xSizeBig, ySizeBig, *bigImp, (woLiberty % 7) * xSizeBig, + (woLiberty / 7 + Term::SystemIconLines) * ySizeBig); + } else { + s = phrase(QStringLiteral("SCIENCE")); + risedTextOut(canvas, 16 + 120 - biColorTextWidth(canvas, s), 44, s); + s = QStringLiteral("%1%").arg(100 - ClientTools::myRO->TaxRate - ClientTools::myRO->LuxRate); + risedTextOut(canvas, 16 + 120 - biColorTextWidth(canvas, s), 60, s); + + // reverse progress bar for science + const int x = 16; + const int y = 81; + const int current = (100 - ClientTools::myRO->LuxRate - ClientTools::myRO->TaxRate) * 120 / 100; + const int max = 120; + frame(canvas, x - 1, y - 1, x + max, y + 7, Qt::black, Qt::black); + rframe(canvas, x - 2, y - 2, x + max + 1, y + 8, MainTexture->colorBevelShade, MainTexture->colorBevelLight); + for (int i = 0; i < current / 8; ++i) + bitBltBitmap(offscreen, x + max - 8 - i * 8, y, 8, 7, HGrSystem->data, 104, 9 + 8 * 2); + bitBltBitmap(offscreen, x + max - current, y, current - 8 * (current / 8), 7, HGrSystem->data, 104, + 9 + 8 * 2); + canvas.brush().setColor(Qt::black); + canvas.fillRect(QRect(x, y, max - current, 7)); + canvas.brush().setStyle(Qt::NoBrush); + + risedTextOut(canvas, 16 + 160, 44, phrase(QStringLiteral("LUX"))); + s = QStringLiteral("%1%").arg(ClientTools::myRO->LuxRate); + risedTextOut(canvas, 16 + 160, 60, s); + paintProgressBar(canvas, 5, 16 + 160, 81, ClientTools::myRO->LuxRate * 120 / 100, 0, 120, *MainTexture); + rframe(canvas, ui->scienceBtn->x() - 1, ui->luxBtn->y() - 1, ui->luxBtn->x() + 12, ui->luxBtn->y() + 12, + MainTexture->colorBevelShade, MainTexture->colorBevelLight); + } + + dLine(canvas, 1, width() - 2, 154, MainTexture->colorBevelShade, MainTexture->colorBevelLight); + risedTextOut(canvas, 16 + 80, 164, phrase(QStringLiteral("TAXRATE"))); + s = QStringLiteral("%1%").arg(ClientTools::myRO->TaxRate); + risedTextOut(canvas, 16 + 80, 180, s); + paintProgressBar(canvas, 0, 16 + 80, 201, ClientTools::myRO->TaxRate * 120 / 100, 0, 120, *MainTexture); + rframe(canvas, ui->taxUpBtn->x() - 1, ui->taxUpBtn->y() - 1, ui->taxUpBtn->x() + 12, ui->taxDownBtn->y() + 12, + MainTexture->colorBevelShade, MainTexture->colorBevelLight); + + canvas.end(); + markUsedOffscreen(width(), height()); +} + +void RatesDlg::resizeEvent(QResizeEvent *event) +{ + BufferedDrawDlg::resizeEvent(event); + ui->closeBtn->move(width() - 38, ui->closeBtn->y()); +} + +void RatesDlg::showEvent(QShowEvent *event) +{ + BufferedDrawDlg::showEvent(event); + setWindowTitle(phrase(QStringLiteral("TITLE_RATES"))); + const bool hasLiberty = ClientTools::myRO->Wonder[woLiberty].EffectiveOwner == ClientTools::me; + ui->scienceBtn->setVisible(!hasLiberty); + ui->luxBtn->setVisible(!hasLiberty); + offscreenPaint(); +} + +void RatesDlg::taxLuxBtnClick(int which) +{ + int newTax = ClientTools::myRO->TaxRate / 10; + int newLux = ClientTools::myRO->LuxRate / 10; + if (which == 0) { // taxUp + if (newTax < 10) + ++newTax; + if (newTax + newLux > 10) + --newLux; + } else if (which == 1 && newTax > 0) { // taxDown + --newTax; + } else if (which == 2 && newLux > 0) { // science + --newLux; + } else if (which == 3 && newLux + newTax < 100) { // lux + ++newLux; + } + if (ClientTools::server(sSetRates, ClientTools::me, newTax + (newLux << 4), nullptr) != eNotChanged) { + ClientTools::cityOptimizer_BeginOfTurn(); + smartUpdateContent(); + // TODO: Term.pas's MainScreen.UpdateViews(True) - not ported yet. + } +} + +} // namespace Rates +} // namespace Cevo diff --git a/game/localplayer/Rates.h b/game/localplayer/Rates.h new file mode 100644 index 0000000..b45634e --- /dev/null +++ b/game/localplayer/Rates.h @@ -0,0 +1,64 @@ +// 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" + +QT_BEGIN_NAMESPACE +namespace Ui { +class RatesDlg; +} +QT_END_NAMESPACE + +namespace Cevo { +namespace Rates { + +// TRatesDlg equivalent: the tax/luxury/science rate slider dialog. UI built +// from Rates.ui (adapted from the original's Rates.lfm). Paints its own +// beveled frame (unlike Diagram/CityType/TechTree) rather than using +// FramedDlg's chrome, so it derives from BufferedDrawDlg directly. +class RatesDlg : public BufferedDrawDlg { + Q_OBJECT +public: + explicit RatesDlg(QWidget *parent = nullptr); + ~RatesDlg() override; + +protected: + void offscreenPaint() override; + void showEvent(QShowEvent *event) override; + void resizeEvent(QResizeEvent *event) override; + +private: + void taxLuxBtnClick(int which); // 0=taxUp, 1=taxDown, 2=science, 3=lux + + Ui::RatesDlg *ui; +}; + +} // namespace Rates +} // namespace Cevo diff --git a/game/localplayer/Rates.ui b/game/localplayer/Rates.ui new file mode 100644 index 0000000..fe5f749 --- /dev/null +++ b/game/localplayer/Rates.ui @@ -0,0 +1,106 @@ + + + + RatesDlg + + + + 0 + 0 + 312 + 223 + + + + C-evo + + + + + 274 + 6 + 25 + 25 + + + + + + + 144 + 64 + 12 + 12 + + + + + + + 156 + 64 + 12 + 12 + + + + + + + 205 + 170 + 12 + 12 + + + + + + + 205 + 182 + 12 + 12 + + + + + + + Cevo::ButtonB + QWidget +
Cevo/CevoButtonB.h
+
+ + Cevo::ButtonC + QWidget +
Cevo/CevoButtonC.h
+
+
+ +