199 lines
8.6 KiB
C++
199 lines
8.6 KiB
C++
// 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 <QHash>
|
|
|
|
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<QString, QString> 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); };
|
|
onShow = [this] {
|
|
setWindowTitle(phrase(QStringLiteral("TITLE_RATES")));
|
|
const bool hasLiberty = ClientTools::myRO->Wonder[woLiberty].EffectiveOwner == ClientTools::me;
|
|
ui->scienceBtn->setVisible(!hasLiberty);
|
|
ui->luxBtn->setVisible(!hasLiberty);
|
|
offscreenPaint();
|
|
};
|
|
}
|
|
|
|
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<std::size_t>(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<std::size_t>(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<std::size_t>(FontType::Small)]);
|
|
|
|
if (hasLiberty) {
|
|
glowFrame(offscreen, width() / 2 - xSizeBig / 2, 52, xSizeBig, ySizeBig,
|
|
Tribes::tribe[static_cast<std::size_t>(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::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
|