From 1667e18dda65029def7c588f1297e9cbaca2280d Mon Sep 17 00:00:00 2001 From: Geoffray Levasseur Date: Tue, 3 Nov 2026 14:25:34 +0100 Subject: [PATCH] added draft and natstat with their requirements --- CMakeLists.txt | 6 + game/localplayer/ClientTools.h | 33 +++ game/localplayer/Draft.cpp | 525 +++++++++++++++++++++++++++++++++ game/localplayer/Draft.h | 80 +++++ game/localplayer/Draft.ui | 111 +++++++ game/localplayer/NatStat.cpp | 483 ++++++++++++++++++++++++++++++ game/localplayer/NatStat.h | 87 ++++++ game/localplayer/NatStat.ui | 121 ++++++++ game/localplayer/Term.cpp | 53 ++++ game/localplayer/Term.h | 43 +++ 10 files changed, 1542 insertions(+) create mode 100644 game/localplayer/Draft.cpp create mode 100644 game/localplayer/Draft.h create mode 100644 game/localplayer/Draft.ui create mode 100644 game/localplayer/NatStat.cpp create mode 100644 game/localplayer/NatStat.h create mode 100644 game/localplayer/NatStat.ui diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f99bd6..a0df049 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -144,6 +144,12 @@ set(PROJECT_SOURCES game/localplayer/Wonders.cpp game/localplayer/Wonders.h game/localplayer/Wonders.ui + game/localplayer/NatStat.cpp + game/localplayer/NatStat.h + game/localplayer/NatStat.ui + game/localplayer/Draft.cpp + game/localplayer/Draft.h + game/localplayer/Draft.ui ${TS_FILES} ) diff --git a/game/localplayer/ClientTools.h b/game/localplayer/ClientTools.h index 8feaa4f..b1be3a0 100644 --- a/game/localplayer/ClientTools.h +++ b/game/localplayer/ClientTools.h @@ -61,6 +61,39 @@ inline bool hasMapOption(MapOptions options, MapOption option) return (options & (1u << option)) != 0; } +// TSaveOption/TSaveOptions: Term.pas's user-configurable UI preferences +// bitset (same bit-position-not-ordinal convention as MapOption above). +enum SaveOption { + soAlEffectiveMovesOnly = 0, + soEnMoves = 1, + soEnAttacks = 2, + soEnNoMoves = 3, + soWaitTurn = 4, + soEffectiveMovesOnly = 5, + soEnFastMoves = 6, + soSlowMoves = 7, + soFastMoves = 8, + soVeryFastMoves = 9, + soNames = 10, + soRepList = 11, + soRepScreens = 12, + soSoundOff = 13, + soSoundOn = 14, + soSoundOnAlt = 15, + soScrollSlow = 16, + soScrollFast = 17, + soScrollOff = 18, + soAlSlowMoves = 19, + soAlFastMoves = 20, + soAlNoMoves = 21, + soTellAI = 30, +}; +using SaveOptions = std::uint32_t; +inline bool hasSaveOption(SaveOptions options, SaveOption option) +{ + return (options & (1u << option)) != 0; +} + using TImpOrder = std::array; using TEnhancementJobs = std::uint8_t[12][8]; // Pascal's `set of 0..39`; bit i set means "treat Server() result code i as diff --git a/game/localplayer/Draft.cpp b/game/localplayer/Draft.cpp new file mode 100644 index 0000000..a7ff9a9 --- /dev/null +++ b/game/localplayer/Draft.cpp @@ -0,0 +1,525 @@ +// 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 "Draft.h" +#include "ui_Draft.h" + +#include "Cevo/CevoScreenTools.h" +#include "Cevo/CevoTexture.h" +#include "Global.h" +#include "Help.h" +#include "Term.h" +#include "Tribes.h" + +#include +#include + +namespace Cevo { +namespace Draft { + +namespace { + +constexpr int MaxLines0 = 11; +constexpr int LinePitch = 20; +constexpr int xDomain = 30; +constexpr int yDomain0 = 464; +constexpr int DomainPitch = 40; +constexpr int xFeature = 38; +constexpr int yFeature0 = 42; +constexpr int xWeight = 100; +constexpr int yWeight0 = 271; +constexpr int xTotal = 20; +constexpr int xTotal2 = 34; +constexpr int yTotal0 = 354; +constexpr int xView = 17; +constexpr int yView0 = 283; + +// 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_DRAFT"), QStringLiteral("Unit Design")}, + {QStringLiteral("BTN_OK"), QStringLiteral("OK")}, + {QStringLiteral("DOMAIN0"), QStringLiteral("Ground units")}, + {QStringLiteral("DOMAIN1"), QStringLiteral("Sea units")}, + {QStringLiteral("DOMAIN2"), QStringLiteral("Air units")}, + {QStringLiteral("UNITSTRENGTH"), QStringLiteral("Strength")}, + {QStringLiteral("UNITTRANSPORT"), QStringLiteral("Transport")}, + {QStringLiteral("UNITSPEED"), QStringLiteral("Speed")}, + {QStringLiteral("UNITCOST"), QStringLiteral("Cost")}, + }; + const auto it = table.constFind(key); + return it != table.constEnd() ? it.value() : key; +} + +QString phraseFeature(int code) +{ + // Feature names (StringTables.pas) aren't ported. + return QStringLiteral("Feature #%1").arg(code); +} + +QString phraseCostDiff(int difficulty) +{ + return QStringLiteral("Cost (difficulty %1)").arg(difficulty); +} + +void imageOpBCCItem(Dpi::Bitmap &dst, Dpi::Bitmap &src, const QPoint &pos, const QRect &srcRect, int color1, + int color2) +{ + imageOpBCC(dst, src, pos.x(), pos.y(), srcRect.left(), srcRect.top(), srcRect.width(), srcRect.height(), color1, + color2); +} + +bool isFeatureAuto(int feature) +{ + return (AutoFeature & (1u << feature)) != 0; +} + +} // namespace + +DraftDlg::DraftDlg(QWidget *parent) : BufferedDrawDlg(parent), ui(new Ui::DraftDlg) +{ + ui->setupUi(this); + initButtons(); + helpContext = QStringLiteral("CLASSES"); + setWindowTitle(phrase(QStringLiteral("TITLE_DRAFT"))); + ui->okBtn->setCaption(phrase(QStringLiteral("BTN_OK"))); + + ui->groundArea->setToolTip(phrase(QStringLiteral("DOMAIN0"))); + ui->seaArea->setToolTip(phrase(QStringLiteral("DOMAIN1"))); + ui->airArea->setToolTip(phrase(QStringLiteral("DOMAIN2"))); + + back.setSize(width(), height()); + back.canvas().begin(); + back.canvas().fillRect(QRect(0, 0, back.width(), back.height())); + back.canvas().end(); + tmpl.loadFromFile(getGraphicsDir() + QStringLiteral("/MiliRes") + PngExt); + + ui->closeBtn->onClick = [this] { + setModalResult(Dpi::ModalResult::Cancel); + close(); + }; + ui->okBtn->onClick = [this] { + setModalResult(Dpi::ModalResult::Ok); + close(); + }; + + onShow = [this] { + domain = dGround; + while (domain < dAir && Upgrade[domain][0].Preq != preNone && + ClientTools::myRO->Tech[Upgrade[domain][0].Preq] < tsApplicable) + ++domain; + + maxLines = 0; + for (int d = 0; d < nDomains; ++d) { + if (Upgrade[d][0].Preq == preNone || ClientTools::myRO->Tech[Upgrade[d][0].Preq] >= tsApplicable) { + int count = 0; + for (int i = 0; i < nFeature; ++i) + if (isFeatureInList(d, i)) + ++count; + if (count > maxLines) + maxLines = count; + } + } + cut = (MaxLines0 - maxLines) * LinePitch; + ui->okBtn->move(ui->okBtn->x(), 477 - cut); + yDomain = yDomain0 - cut; + yWeight = yWeight0 - cut; + yTotal = yTotal0 - cut; + yView = yView0 - cut; + + if (windowMode() == WindowMode::Modal) + centerToScreen(tmpl.width(), tmpl.height() - cut); + + setDomain(domain); + ClientTools::server(sCreateDevModel, ClientTools::me, domain, nullptr); + ClientTools::myModel[ClientTools::myRO->nModel] = ClientTools::myRO->DevModel; + Term::initMyModel(ClientTools::myRO->nModel, false); + offscreenPaint(); + incCap = -1; + decCap = -1; + }; +} + +DraftDlg::~DraftDlg() +{ + delete ui; +} + +void DraftDlg::showNewContent(WindowMode newMode) +{ + BufferedDrawDlg::showNewContent(newMode); +} + +bool DraftDlg::isFeatureInList(int d, int i) const +{ + return !isFeatureAuto(i) && (1u << d & Feature[i].Domains) != 0 && Feature[i].Preq != preNA && + (Feature[i].Preq == preNone || + (Feature[i].Preq == preSun && ClientTools::myRO->Wonder[woSun].EffectiveOwner == ClientTools::me) || + (Feature[i].Preq >= 0 && ClientTools::myRO->Tech[Feature[i].Preq] >= tsApplicable)); +} + +void DraftDlg::setDomain(int d) +{ + auto prio = [](int fix) { + const int featurePreq = Feature[fix].Preq; + int result; + if (fix < mcFirstNonCap) + result = 10000 + fix; + else if (featurePreq == preNone) + result = 20000; + else if (featurePreq < 0) + result = 40000; + else + result = 30000 + ClientTools::advValue[static_cast(featurePreq)]; + if (!isFeatureAuto(fix)) + result += 90000; + return result; + }; + + domain = d; + lines = 0; + for (int i = 0; i < nFeature; ++i) { + if (isFeatureInList(domain, i)) { + code[static_cast(lines)] = i; + ++lines; + } + } + yFeature = yFeature0 + (maxLines - lines) * LinePitch / 2; + + for (int i = 0; i < lines - 1; ++i) + for (int j = i + 1; j < lines; ++j) + if (prio(code[static_cast(i)]) > prio(code[static_cast(j)])) + std::swap(code[static_cast(i)], code[static_cast(j)]); +} + +void DraftDlg::offscreenPaint() +{ + BufferedDrawDlg::offscreenPaint(); + if (!MainTexture) + return; + + unshareBitmap(back); + + resize(width(), tmpl.height() - cut); + if (height() > MainTexture->height()) { + bitBltBitmap(back, 0, 0, width(), 64, MainTexture->image(), (MainTexture->width() - width()) / 2, + MainTexture->height() - 64); + bitBltBitmap(back, 0, 64, width(), height() - 64, MainTexture->image(), (MainTexture->width() - width()) / 2, + 0); + } else { + bitBltBitmap(back, 0, 0, width(), height(), MainTexture->image(), (MainTexture->width() - width()) / 2, + (MainTexture->height() - height()) / 2); + } + imageOpB(back, tmpl, 0, 0, 0, 0, tmpl.width(), 64); + imageOpB(back, tmpl, 0, 64, 0, 64 + cut, tmpl.width(), tmpl.height() - 64 - cut); + + bitBltBitmap(offscreen, 0, 0, width(), height(), back, 0, 0); + + Dpi::Canvas &canvas = offscreen.canvas(); + canvas.begin(); + canvas.font().assign(UniFont[static_cast(FontType::Caption)]); + risedTextOut(canvas, 10, 7, windowTitle()); + canvas.font().assign(UniFont[static_cast(FontType::Small)]); + + auto domainAvailable = [](int d) { + return Upgrade[d][0].Preq == preNone || ClientTools::myRO->Tech[Upgrade[d][0].Preq] >= tsApplicable; + }; + + int domainCount = 0; + for (int d = 0; d < nDomains; ++d) + if (domainAvailable(d)) + ++domainCount; + if (domainCount > 1) { + for (int d = 0; d < nDomains; ++d) { + if (domainAvailable(d)) { + const int x = xDomain + d * DomainPitch; + imageOpBCC(offscreen, Templates->data, x, yDomain, 142, 246 + 37 * d, 36, 36, 0, + d == domain ? 0x00C0FF : 0x606060); + } + } + frame(canvas, xDomain - 11, yDomain - 3, xDomain + 2 * DomainPitch + 46, yDomain + 38, + colorFromDelphi(0xB0B0B0), Qt::white); + rframe(canvas, xDomain - 12, yDomain - 4, xDomain + 2 * DomainPitch + 47, yDomain + 39, Qt::white, + colorFromDelphi(0xB0B0B0)); + } + ui->groundArea->move(ui->groundArea->x(), yDomain); + ui->groundArea->setVisible(domainAvailable(dGround)); + ui->seaArea->move(ui->seaArea->x(), yDomain); + ui->seaArea->setVisible(domainAvailable(dSea)); + ui->airArea->move(ui->airArea->x(), yDomain); + ui->airArea->setVisible(domainAvailable(dAir)); + + const TModel &devModel = ClientTools::myRO->DevModel; + + // strength bar + { + int y = yTotal; + darkGradient(canvas, xTotal - 6, y + 1, 184, 2); + darkGradient(canvas, xTotal2 + 172, y + 1, 95, 2); + risedTextOut(canvas, xTotal - 2, y, phrase(QStringLiteral("UNITSTRENGTH"))); + risedTextOut(canvas, xTotal + 112 + 30, y, QStringLiteral("x%1").arg(devModel.MStrength)); + risedTextOut(canvas, xTotal2 + 148 + 30, y, QStringLiteral("=")); + const QString s = QStringLiteral("%1/%2").arg(devModel.Attack).arg(devModel.Defense); + risedTextOut(canvas, xTotal2 + 170 + 64 + 30 - biColorTextWidth(canvas, s), y, s); + + // transport bar + if (devModel.MTrans > 0) { + y = yTotal + 19; + darkGradient(canvas, xTotal - 6, y + 1, 184, 1); + darkGradient(canvas, xTotal2 + 172, y + 1, 95, 1); + risedTextOut(canvas, xTotal - 2, y, phrase(QStringLiteral("UNITTRANSPORT"))); + risedTextOut(canvas, xTotal + 112 + 30, y, QStringLiteral("x%1").arg(devModel.MTrans)); + risedTextOut(canvas, xTotal2 + 148 + 30, y, QStringLiteral("=")); + + canvas.font().setColor(Qt::black); + int dx = -237 - 30; + for (int i = mcFirstNonCap - 1; i >= 3; --i) { + if (i == mcSeaTrans || i == mcCarrier || i == mcAirTrans) { + const int num = devModel.Cap[i] * devModel.MTrans; + if (num > 0) { + dx += 15; + canvas.brush().setColor(colorFromDelphi(0xC0C0C0)); + canvas.frameRect(QRect(xTotal2 - 3 - dx, y + 2, 14, 14)); + canvas.brush().setStyle(Qt::NoBrush); + sprite(canvas, *HGrSystem, xTotal2 - 1 - dx, y + 4, 10, 10, 66 + i % 11 * 11, + 137 + i / 11 * 11); + if (num > 1) { + const QString countText = QString::number(num); + const int w = canvas.textWidth(countText); + dx += w + 1; + canvas.brush().setColor(Qt::white); + canvas.fillRect(QRect(xTotal2 - 3 - dx, y + 2, w + 2, 14)); + canvas.brush().setStyle(Qt::NoBrush); + canvas.textOut(xTotal2 - 3 - dx + 1, y, countText); + } + } + } + } + } + + // speed bar + y = yTotal + 38; + loweredTextOut(canvas, -1, *MainTexture, xTotal - 2, y, phrase(QStringLiteral("UNITSPEED"))); + dLine(canvas, xTotal - 2, xTotal + 174, y + 16, MainTexture->colorBevelShade, MainTexture->colorBevelLight); + dLine(canvas, xTotal2 + 176, xTotal2 + 263, y + 16, MainTexture->colorBevelShade, + MainTexture->colorBevelLight); + QString s2 = movementToString(devModel.Speed); + risedTextOut(canvas, xTotal2 + 170 + 64 + 30 - canvas.textWidth(s2), y, s2); + + // cost bar + y = yTotal + 57; + loweredTextOut(canvas, -1, *MainTexture, xTotal - 2, y, phrase(QStringLiteral("UNITCOST"))); + loweredTextOut(canvas, -1, *MainTexture, xTotal + 112 + 30, y, QStringLiteral("x%1").arg(devModel.MCost)); + loweredTextOut(canvas, -1, *MainTexture, xTotal2 + 148 + 30, y, QStringLiteral("=")); + dLine(canvas, xTotal - 2, xTotal + 174, y + 16, MainTexture->colorBevelShade, MainTexture->colorBevelLight); + dLine(canvas, xTotal2 + 176, xTotal2 + 263, y + 16, MainTexture->colorBevelShade, + MainTexture->colorBevelLight); + QString s3 = QString::number(devModel.Cost); + risedTextOut(canvas, xTotal2 + 170 + 64 + 30 - 12 - canvas.textWidth(s3), y, s3); + sprite(canvas, *HGrSystem, xTotal2 + 170 + 54 + 30, y + 4, 10, 10, 88, 115); + + if (ClientTools::g.Difficulty[ClientTools::me] != 2) { + y = yTotal + 76; + loweredTextOut(canvas, -1, *MainTexture, xTotal - 2, y, + phraseCostDiff(ClientTools::g.Difficulty[ClientTools::me])); + loweredTextOut(canvas, -1, *MainTexture, xTotal2 + 148 + 30, y, QStringLiteral("=")); + dLine(canvas, xTotal - 2, xTotal + 174, y + 16, MainTexture->colorBevelShade, + MainTexture->colorBevelLight); + dLine(canvas, xTotal2 + 176, xTotal2 + 263, y + 16, MainTexture->colorBevelShade, + MainTexture->colorBevelLight); + QString s4 = QString::number(devModel.Cost * BuildCostMod[ClientTools::g.Difficulty[ClientTools::me]] / 12); + risedTextOut(canvas, xTotal2 + 170 + 64 + 30 - 12 - canvas.textWidth(s4), y, s4); + sprite(canvas, *HGrSystem, xTotal2 + 170 + 54 + 30, y + 4, 10, 10, 88, 115); + } + } + + // weight display + GraphicSetItem *weightOn = Templates->searchByName(QStringLiteral("WeightOn")); + GraphicSetItem *weightOff = Templates->searchByName(QStringLiteral("WeightOff")); + for (int i = 0; i < devModel.MaxWeight; ++i) { + GraphicSetItem *item = i < devModel.Weight ? weightOn : weightOff; + if (item) + imageOpBCCItem(offscreen, Templates->data, QPoint(xWeight + 20 * i, yWeight), item->boundsRect(), 0, + 0x949494); + } + + for (int i = 0; i < lines; ++i) { + const int c = code[static_cast(i)]; + if (!isFeatureAuto(c)) { + if (c < mcFirstNonCap) { + bitBltBitmap(offscreen, xFeature - 21, yFeature + 2 + LinePitch * i, 12, 12, HGrSystem->data, 169, + 172); + bitBltBitmap(offscreen, xFeature - 9, yFeature + 2 + LinePitch * i, 12, 12, HGrSystem->data, 169, 159); + rframe(canvas, xFeature - 22, yFeature + 1 + LinePitch * i, xFeature + 3, yFeature + 14 + LinePitch * i, + MainTexture->colorBevelShade, MainTexture->colorBevelLight); + } else { + bitBltBitmap(offscreen, xFeature - 9, yFeature + 2 + LinePitch * i, 12, 12, HGrSystem->data, 169, + 185 + 13 * devModel.Cap[c]); + rframe(canvas, xFeature - 10, yFeature + 1 + LinePitch * i, xFeature + 3, yFeature + 14 + LinePitch * i, + MainTexture->colorBevelShade, MainTexture->colorBevelLight); + } + + lightGradient(canvas, xFeature + 34, yFeature + LinePitch * i, 50, HGrSystem->data.image().pixelColor(187, 137)); + int capWeight = (domain == dGround && c == mcDefense) ? 2 : Feature[c].Weight; + const int n = capWeight + Feature[c].Cost; + int d = 6; + while (n > 0 && (n - 1) * d * 2 > 48 - 10) + --d; + for (int j = 0; j < n; ++j) { + if (j < capWeight) + sprite(canvas, *HGrSystem, xFeature + 54 + (j * 2 + 1 - n) * d, yFeature + 2 + LinePitch * i + 1, + 10, 10, 88, 126); + else + sprite(canvas, *HGrSystem, xFeature + 54 + (j * 2 + 1 - n) * d, yFeature + 2 + LinePitch * i + 1, + 10, 10, 88, 115); + } + } + darkGradient(canvas, xFeature + 17, yFeature + LinePitch * i, 16, 1); + frame(canvas, xFeature + 18, yFeature + 1 + LinePitch * i, xFeature + 31, yFeature + 14 + LinePitch * i, + colorFromDelphi(0xC0C0C0), colorFromDelphi(0xC0C0C0)); + sprite(canvas, *HGrSystem, xFeature + 20, yFeature + 3 + LinePitch * i, 10, 10, 66 + c % 11 * 11, + 137 + c / 11 * 11); + + const int textColor = devModel.Cap[c] > 0 ? colorToDelphi(MainTexture->colorLitText) : -1; + if (c < mcFirstNonCap) + loweredTextOut(canvas, textColor, *MainTexture, xFeature + 7, yFeature + LinePitch * i - 1, + QString::number(devModel.Cap[c])); + loweredTextOut(canvas, textColor, *MainTexture, xFeature + 88, yFeature + LinePitch * i - 1, phraseFeature(c)); + } + + // free features + int j = 0; + for (int i = 0; i < nFeature; ++i) { + if (isFeatureAuto(i) && (1u << domain & Feature[i].Domains) != 0 && Feature[i].Preq != preNA && + ((Feature[i].Preq == preSun && ClientTools::myRO->Wonder[woSun].EffectiveOwner == ClientTools::me) || + (Feature[i].Preq >= 0 && ClientTools::myRO->Tech[Feature[i].Preq] >= tsApplicable)) && + !(Feature[i].Preq == adSteamEngine && ClientTools::myRO->Tech[adNuclearPower] >= tsApplicable)) { + darkGradient(canvas, xWeight + 4, yWeight + 32 + LinePitch * j, 16, 1); + frame(canvas, xWeight + 5, yWeight + 33 + LinePitch * j, xWeight + 18, yWeight + 47 + LinePitch * j, + colorFromDelphi(0xC0C0C0), colorFromDelphi(0xC0C0C0)); + sprite(canvas, *HGrSystem, xWeight + 7, yWeight + 36 + LinePitch * j, 10, 10, 66 + i % 11 * 11, + 137 + i / 11 * 11); + loweredTextOut(canvas, -1, *MainTexture, xWeight + 26, yWeight + 31 + LinePitch * j, phraseFeature(i)); + ++j; + } + } + + if (bigImp) { + Tribes::Tribe &me = *Tribes::tribe[static_cast(ClientTools::me)]; + Tribes::ModelPicture &mp = me.modelPictureAt(ClientTools::myRO->nModel); + frameImage(canvas, *bigImp, xView + 4, yView + 4, xSizeBig, ySizeBig, 0, 0); + if (mp.hGr) + sprite(canvas, *mp.hGr, xView, yView, 64, 44, mp.pix % 10 * 65 + 1, mp.pix / 10 * 49 + 1); + } + + canvas.end(); + markUsedOffscreen(width(), height()); +} + +void DraftDlg::resizeEvent(QResizeEvent *event) +{ + BufferedDrawDlg::resizeEvent(event); + ui->closeBtn->move(width() - 31, ui->closeBtn->y()); +} + +void DraftDlg::mousePressEvent(QMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) { + const int x = event->pos().x(); + const int y = event->pos().y(); + + auto domainAvailable = [](int d) { + return Upgrade[d][0].Preq == preNone || ClientTools::myRO->Tech[Upgrade[d][0].Preq] >= tsApplicable; + }; + + for (int d = 0; d < nDomains; ++d) { + if (d != domain && domainAvailable(d) && x >= xDomain + d * DomainPitch && + x < xDomain + d * DomainPitch + 36 && y >= yDomain && y < yDomain + 36) { + setDomain(d); + ClientTools::server(sCreateDevModel, ClientTools::me, domain, nullptr); + ClientTools::myModel[ClientTools::myRO->nModel] = ClientTools::myRO->DevModel; + Term::initMyModel(ClientTools::myRO->nModel, false); + smartUpdateContent(); + } + } + + if (y >= yFeature && y < yFeature + LinePitch * lines) { + const int i = (y - yFeature) / LinePitch; + const int c = code[static_cast(i)]; + if (x >= xFeature - 21 && x < width() && (event->modifiers() & Qt::ShiftModifier)) { + Help::showNewContent(windowModeMakePersistent(windowMode()), Help::LinkCategory::Feature, c); + } else if (!isFeatureAuto(c)) { + if (c < mcFirstNonCap && x >= xFeature - 21 && x < xFeature - 21 + 12) { + incCap = c; + bitBltBitmap(offscreen, xFeature - 21, yFeature + 2 + LinePitch * i, 12, 12, HGrSystem->data, 182, + 172); + smartInvalidate(); + } else if (x >= xFeature - 9 && x < xFeature - 9 + 12) { + decCap = c; + if (c < mcFirstNonCap) + bitBltBitmap(offscreen, xFeature - 9, yFeature + 2 + LinePitch * i, 12, 12, HGrSystem->data, + 182, 159); + else + bitBltBitmap(offscreen, xFeature - 9, yFeature + 2 + LinePitch * i, 12, 12, HGrSystem->data, + 182, 185 + 13 * ClientTools::myRO->DevModel.Cap[c]); + smartInvalidate(); + } + } + } + } + BufferedDrawDlg::mousePressEvent(event); +} + +void DraftDlg::mouseReleaseEvent(QMouseEvent *event) +{ + if (incCap >= 0) { + const int newValue = ClientTools::myRO->DevModel.Cap[incCap] + 1; + ClientTools::server(sSetDevModelCap + (newValue << 4), ClientTools::me, incCap, nullptr); + ClientTools::myModel[ClientTools::myRO->nModel] = ClientTools::myRO->DevModel; + Term::initMyModel(ClientTools::myRO->nModel, false); + smartUpdateContent(); + incCap = -1; + } else if (decCap >= 0) { + if (decCap >= mcFirstNonCap || ClientTools::myRO->DevModel.Cap[decCap] > 0) { + int newValue = ClientTools::myRO->DevModel.Cap[decCap] - 1; + if (decCap >= mcFirstNonCap) + newValue = -newValue; + ClientTools::server(sSetDevModelCap + (newValue << 4), ClientTools::me, decCap, nullptr); + ClientTools::myModel[ClientTools::myRO->nModel] = ClientTools::myRO->DevModel; + Term::initMyModel(ClientTools::myRO->nModel, false); + } + smartUpdateContent(); + decCap = -1; + } + BufferedDrawDlg::mouseReleaseEvent(event); +} + +} // namespace Draft +} // namespace Cevo diff --git a/game/localplayer/Draft.h b/game/localplayer/Draft.h new file mode 100644 index 0000000..ce5146a --- /dev/null +++ b/game/localplayer/Draft.h @@ -0,0 +1,80 @@ +// 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 "Cevo/Protocol.h" + +#include + +QT_BEGIN_NAMESPACE +namespace Ui { +class DraftDlg; +} +QT_END_NAMESPACE + +namespace Cevo { +namespace Draft { + +// TDraftDlg equivalent: the new-unit-type "draft" designer (pick a domain, +// tune feature capability levels, see live strength/cost/speed totals). UI +// built from Draft.ui (adapted from the original's Draft.lfm). +class DraftDlg : public BufferedDrawDlg { + Q_OBJECT +public: + explicit DraftDlg(QWidget *parent = nullptr); + ~DraftDlg() override; + + void showNewContent(WindowMode newMode); + +protected: + void offscreenPaint() override; + void resizeEvent(QResizeEvent *event) override; + void mousePressEvent(QMouseEvent *event) override; + void mouseReleaseEvent(QMouseEvent *event) override; + +private: + bool isFeatureInList(int d, int i) const; + void setDomain(int d); + + int domain = dGround; + int maxLines = 0; + int lines = 0; + int cut = 0; + int yDomain = 0, yFeature = 0, yWeight = 0, yTotal = 0, yView = 0; + int incCap = -1, decCap = -1; + std::array code{}; + Dpi::Bitmap tmpl; + Dpi::Bitmap back; + + Ui::DraftDlg *ui; +}; + +} // namespace Draft +} // namespace Cevo diff --git a/game/localplayer/Draft.ui b/game/localplayer/Draft.ui new file mode 100644 index 0000000..2f8e082 --- /dev/null +++ b/game/localplayer/Draft.ui @@ -0,0 +1,111 @@ + + + + DraftDlg + + + + 0 + 0 + 315 + 511 + + + + C-evo + + + + + 196 + 477 + 100 + 25 + + + + + + + 284 + 6 + 25 + 25 + + + + + + + 30 + 464 + 36 + 36 + + + + + + + 70 + 464 + 36 + 36 + + + + + + + 110 + 464 + 36 + 36 + + + + + + + Cevo::ButtonA + QWidget +
Cevo/CevoButtonA.h
+
+ + Cevo::ButtonB + QWidget +
Cevo/CevoButtonB.h
+
+ + Cevo::Area + QWidget +
Cevo/CevoArea.h
+
+
+ +
diff --git a/game/localplayer/NatStat.cpp b/game/localplayer/NatStat.cpp new file mode 100644 index 0000000..b763ff8 --- /dev/null +++ b/game/localplayer/NatStat.cpp @@ -0,0 +1,483 @@ +// 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 "NatStat.h" +#include "ui_NatStat.h" + +#include "Cevo/CevoScreenTools.h" +#include "Cevo/CevoTexture.h" +#include "ClientTools.h" +#include "Global.h" +#include "IsoEngine.h" +#include "Term.h" +#include "Tribes.h" + +#include +#include +#include + +#include + +namespace Cevo { +namespace NatStat { + +namespace { + +constexpr int xIcon = 326; +constexpr int yIcon = 49; +constexpr int xAttrib = 96; +constexpr int yAttrib = 40; +constexpr int xRelation = 16; +constexpr int yRelation = 110; +constexpr int PaperShade = 3; +constexpr int ReportLines = 12; +constexpr int LineSpacing = 22; +constexpr int xReport = 24; +constexpr int yReport = 165; +constexpr int wReport = 352; +constexpr int hReport = ReportLines * LineSpacing; + +// 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("BTN_SELECT"), QStringLiteral("Select nation")}, + {QStringLiteral("BTN_DIALOG"), QStringLiteral("Negotiate")}, + {QStringLiteral("FRSTATPOP"), QStringLiteral("Population: %1")}, + {QStringLiteral("FRSTATTER"), QStringLiteral("Territory: %1")}, + {QStringLiteral("FRSTATTECH"), QStringLiteral("Advances researched: %1")}, + {QStringLiteral("FRSTATEXP"), QStringLiteral("Land explored: %1%")}, + {QStringLiteral("FROLDCIVILREP"), QStringLiteral("Last report: %1")}, + {QStringLiteral("FRTREASURY"), QStringLiteral("Treasury: %1")}, + {QStringLiteral("FRRELATIONS"), QStringLiteral("Relations:")}, + {QStringLiteral("FRCOLDWAR"), QStringLiteral("We are in a cold war.")}, + {QStringLiteral("FRMYANARCHY"), QStringLiteral("We are in anarchy.")}, + {QStringLiteral("FRANARCHY"), QStringLiteral("They are in anarchy.")}, + {QStringLiteral("FREXTINCT"), QStringLiteral("Extinct since")}, + {QStringLiteral("FRCREDIBILITY"), QStringLiteral("Credibility: %1")}, + {QStringLiteral("FRNOCONTACT"), QStringLiteral("No contact")}, + {QStringLiteral("FRTREATY"), QStringLiteral("Treaty:")}, + {QStringLiteral("FRNOVISIT"), QStringLiteral("Never visited")}, + {QStringLiteral("FRLASTCONTACT"), QStringLiteral("Last contact:")}, + {QStringLiteral("FRNOCIVILREP"), QStringLiteral("No civil report available.")}, + {QStringLiteral("MENU_TELLAI"), QStringLiteral("Tell AI")}, + }; + const auto it = table.constFind(key); + return it != table.constEnd() ? it.value() : key; +} + +QString phraseGovernment(int government) +{ + return QStringLiteral("government #%1 ").arg(government); +} + +QString phraseCredibility(int roughCredibility) +{ + static const QHash table = { + {0, QStringLiteral("poor")}, {1, QStringLiteral("fair")}, {2, QStringLiteral("good")}, + {3, QStringLiteral("perfect")}, + }; + const auto it = table.constFind(roughCredibility); + return it != table.constEnd() ? it.value() : QString(); +} + +QString phraseTreaty(int treaty) +{ + static const QHash table = { + {trNoContact, QStringLiteral("no contact")}, {trNone, QStringLiteral("none")}, + {trCeaseFire, QStringLiteral("cease-fire")}, {trPeace, QStringLiteral("peace")}, + {trFriendlyContact, QStringLiteral("friendly")}, {trAlliance, QStringLiteral("alliance")}, + }; + const auto it = table.constFind(treaty); + return it != table.constEnd() ? it.value() : QString(); +} + +} // namespace + +NatStatDlg::NatStatDlg(QWidget *parent) : BufferedDrawDlg(parent), ui(new Ui::NatStatDlg) +{ + ui->setupUi(this); + initButtons(); + ui->contactBtn->setTemplate(Templates ? &Templates->data : nullptr); + ui->contactBtn->setButtonIndex(3); + helpContext = QStringLiteral("DIPLOMACY"); + ui->toggleBtn->setToolTip(phrase(QStringLiteral("BTN_SELECT"))); + ui->contactBtn->setToolTip(phrase(QStringLiteral("BTN_DIALOG"))); + + back.setSize(width(), height()); + back.canvas().begin(); + back.canvas().fillRect(QRect(0, 0, back.width(), back.height())); + back.canvas().end(); + + tmpl.loadFromFile(getGraphicsDir() + QStringLiteral("/Nation") + PngExt); + + popup = new QMenu(this); + + ui->closeBtn->onClick = [this] { close(); }; + ui->toggleBtn->onClick = [this] { toggleBtnClicked(); }; + ui->contactBtn->onClick = [this] { dialogBtnClicked(); }; + ui->scrollUpBtn->onClick = [this] { + if (linesDown > 0) { + --linesDown; + smartUpdateContent(); + } + }; + ui->scrollDownBtn->onClick = [this] { + if (linesDown + ReportLines < reportText.size()) { + ++linesDown; + smartUpdateContent(); + } + }; + ui->tellAIBtn->onClick = [this] { tellAIBtnClicked(); }; + + onShow = [this] { + if (pView == ClientTools::me) { + selfReport.TurnOfCivilReport = ClientTools::myRO->Turn; + selfReport.TurnOfMilReport = ClientTools::myRO->Turn; + std::copy(std::begin(ClientTools::myRO->Treaty), std::end(ClientTools::myRO->Treaty), + std::begin(selfReport.Treaty)); + selfReport.Government = ClientTools::myRO->Government; + selfReport.Money = ClientTools::myRO->Money; + currentReport = &selfReport; + } else { + currentReport = ClientTools::myRO->EnemyReport[pView]; + } + if (currentReport->TurnOfCivilReport >= 0) + generateReportText(); + showContact = pView != ClientTools::me && !(Term::supervising && ClientTools::me == 0); + contactEnabled = + showContact && !Term::supervising && (1u << pView & static_cast(ClientTools::myRO->Alive)) != 0; + ui->contactBtn->setVisible(contactEnabled && (ClientTools::myRO->Happened & phGameEnd) == 0 && + IsoEngine::clientMode < scContact); + const bool showScroll = + currentReport->TurnOfCivilReport >= 0 && reportText.size() > ReportLines; + ui->scrollUpBtn->setVisible(showScroll); + ui->scrollDownBtn->setVisible(showScroll); + ui->tellAIBtn->setButtonIndex( + ClientTools::hasSaveOption(Term::optionChecked, ClientTools::soTellAI) ? 3 : 2); + setWindowTitle(Tribes::tribe[static_cast(pView)]->tPhrase(QStringLiteral("TITLE_NATION"))); + linesDown = 0; + offscreenPaint(); + }; +} + +NatStatDlg::~NatStatDlg() +{ + delete ui; +} + +void NatStatDlg::checkAge() +{ + if (!MainTexture) + return; + if (MainTexture->age() != agePrepared) { + agePrepared = MainTexture->age(); + bitBltBitmap(back, 0, 0, width(), height(), MainTexture->image(), (MainTexture->width() - width()) / 2, + (MainTexture->height() - height()) / 2); + imageOpB(back, tmpl, 0, 0, 0, 0, width(), height()); + } +} + +void NatStatDlg::showNewContent(WindowMode newMode, int p) +{ + if (p < 0) { + if (IsoEngine::clientMode >= scContact) { + pView = Term::dipMem[static_cast(ClientTools::me)].pContact; + } else { + pView = 0; + while (pView < nPl && (ClientTools::myRO->Treaty[pView] < trNone || + (1u << pView & static_cast(ClientTools::myRO->Alive)) == 0)) + ++pView; + if (pView >= nPl) + pView = ClientTools::me; + } + } else { + pView = p; + } + BufferedDrawDlg::showNewContent(newMode); +} + +void NatStatDlg::playerClicked(int p) +{ + showNewContent(windowMode(), p); +} + +void NatStatDlg::generateReportText() +{ + std::vector list(static_cast(ClientTools::myRO->Turn + 2)); + + auto statText = [&](int no) -> QString { + if (currentReport->TurnOfCivilReport >= 0 && + ClientTools::server(sGetChart + (no << 4), ClientTools::me, pView, list.data()) >= rExecuted) { + const int i = list[static_cast(currentReport->TurnOfCivilReport)]; + switch (no) { + case stPop: return phrase(QStringLiteral("FRSTATPOP")).arg(i); + case stTerritory: return phrase(QStringLiteral("FRSTATTER")).arg(i); + case stScience: return phrase(QStringLiteral("FRSTATTECH")).arg(i / nAdv); + case stExplore: + return phrase(QStringLiteral("FRSTATEXP")).arg(i * 100 / (ClientTools::g.lx * ClientTools::g.ly)); + default: return QString(); + } + } + return QString(); + }; + + reportText.clear(); + reportText.append(QString()); + if (ClientTools::myRO->Turn - currentReport->TurnOfCivilReport > 1 && + (1u << pView & static_cast(ClientTools::myRO->Alive)) != 0) { + reportText.append(phrase(QStringLiteral("FROLDCIVILREP")).arg(Term::turnToString(currentReport->TurnOfCivilReport))); + reportText.append(QString()); + } + + if ((1u << pView & static_cast(ClientTools::myRO->Alive)) != 0) { + reportText.append(phrase(QStringLiteral("FRTREASURY")).arg(currentReport->Money)); + reportText.append(statText(stPop)); + reportText.append(statText(stTerritory)); + } + reportText.append(statText(stScience)); + reportText.append(statText(stExplore)); + + bool hasContact = false; + for (int p1 = 0; p1 < nPl; ++p1) + if (p1 != ClientTools::me && currentReport->Treaty[p1] > trNoContact) { + hasContact = true; + break; + } + if (hasContact) { + reportText.append(QString()); + reportText.append(phrase(QStringLiteral("FRRELATIONS"))); + for (int extinctPart = 0; extinctPart <= 1; ++extinctPart) { + for (int treaty = trAlliance; treaty >= trNone; --treaty) { + for (int p1 = 0; p1 < nPl; ++p1) { + if (p1 != ClientTools::me && currentReport->Treaty[p1] == treaty && + ((1u << p1 & static_cast(ClientTools::myRO->Alive)) == 0) == (extinctPart != 0)) { + QString s = Tribes::tribe[static_cast(p1)]->tString(phraseTreaty(treaty)); + if (extinctPart) + s = QLatin1Char('(') + s + QLatin1Char(')'); + reportText.append(s); + } + } + } + } + } + reportText.append(QString()); +} + +void NatStatDlg::offscreenPaint() +{ + BufferedDrawDlg::offscreenPaint(); + checkAge(); + + const bool extinct = (1u << pView & static_cast(ClientTools::myRO->Alive)) == 0; + + bitBltBitmap(offscreen, 0, 0, width(), height(), back, 0, 0); + + Dpi::Canvas &canvas = offscreen.canvas(); + canvas.begin(); + canvas.font().assign(UniFont[static_cast(FontType::Caption)]); + risedTextOut(canvas, 40, 7, windowTitle()); + canvas.font().assign(UniFont[static_cast(FontType::Normal)]); + + Tribes::Tribe &tribe = *Tribes::tribe[static_cast(pView)]; + tribe.initAge(ClientTools::getAge(pView)); + if (tribe.faceHGr) { + bitBltBitmap(offscreen, 18, yIcon - 4, 64, 48, tribe.faceHGr->data, 1 + tribe.facePix % 10 * 65, + 1 + tribe.facePix / 10 * 49); + frame(canvas, 18 - 1, yIcon - 4 - 1, 18 + 64, yIcon - 4 + 48, Qt::black, Qt::black); + } + + if (pView == ClientTools::me || !extinct) + loweredTextOut(canvas, -1, *MainTexture, xAttrib, yAttrib, + phraseGovernment(currentReport->Government) + QStringLiteral("and")); + + if (pView == ClientTools::me) { + loweredTextOut(canvas, -1, *MainTexture, xAttrib, yAttrib + 19, + phraseCredibility(Term::roughCredibility(ClientTools::myRO->Credibility))); + loweredTextOut(canvas, -1, *MainTexture, xAttrib, yAttrib + 38, + phrase(QStringLiteral("FRCREDIBILITY")).arg(ClientTools::myRO->Credibility)); + } else { + if (extinct) { + loweredTextOut(canvas, -1, *MainTexture, xAttrib, yAttrib + 9, phrase(QStringLiteral("FREXTINCT"))); + loweredTextOut(canvas, -1, *MainTexture, xAttrib, yAttrib + 28, + Term::turnToString(currentReport->TurnOfCivilReport)); + } else { + loweredTextOut(canvas, -1, *MainTexture, xAttrib, yAttrib + 19, + phraseCredibility(Term::roughCredibility(currentReport->Credibility))); + loweredTextOut(canvas, -1, *MainTexture, xAttrib, yAttrib + 38, + phrase(QStringLiteral("FRCREDIBILITY")).arg(currentReport->Credibility)); + } + + if (ClientTools::myRO->Treaty[pView] == trNoContact) { + const QString s = phrase(QStringLiteral("FRNOCONTACT")); + loweredTextOut(canvas, -1, *MainTexture, (width() - biColorTextWidth(canvas, s)) / 2, yRelation + 9, s); + } else if (showContact) { + loweredTextOut(canvas, -1, *MainTexture, xRelation, yRelation, phrase(QStringLiteral("FRTREATY"))); + loweredTextOut(canvas, -1, *MainTexture, width() / 2, yRelation, + phraseTreaty(ClientTools::myRO->Treaty[pView])); + if (currentReport->TurnOfContact < 0) { + loweredTextOut(canvas, -1, *MainTexture, width() / 2, yRelation + 19, + phrase(QStringLiteral("FRNOVISIT"))); + } else { + loweredTextOut(canvas, -1, *MainTexture, xRelation, yRelation + 19, + phrase(QStringLiteral("FRLASTCONTACT"))); + loweredTextOut(canvas, -1, *MainTexture, width() / 2, yRelation + 19, + Term::turnToString(currentReport->TurnOfContact)); + } + } + + if (extinct && bigImp) + frameImage(canvas, *bigImp, xIcon, yIcon, xSizeBig, ySizeBig, 0, 200, false); + } + + if (currentReport->TurnOfCivilReport >= 0) { + fillSeamless(canvas, xReport, yReport, wReport, hReport, 0, 0, paper); + canvas.brush().setColor(MainTexture->colorBevelShade); + canvas.fillRect(QRect(xReport + wReport, yReport + PaperShade, PaperShade, hReport)); + canvas.fillRect(QRect(xReport + PaperShade, yReport + hReport, wReport + PaperShade - PaperShade, PaperShade)); + canvas.brush().setStyle(Qt::NoBrush); + + int y = 0; + for (int i = 0; i < reportText.size(); ++i) { + if (i >= linesDown && i < linesDown + ReportLines) { + const QString &s = reportText.at(i); + if (!s.isEmpty()) + biColorTextOut(canvas, Colors->image().pixelColor(clkMisc, cliPaperText), colorFromDelphi(0x7F007F), + xReport + 8, yReport + LineSpacing * y, s); + ++y; + } + } + } else { + const QString s = phrase(QStringLiteral("FRNOCIVILREP")); + risedTextOut(canvas, (width() - biColorTextWidth(canvas, s)) / 2, yReport + hReport / 2 - 10, s); + } + + if (ClientTools::hasSaveOption(Term::optionChecked, ClientTools::soTellAI)) { + // Server(sGetAIInfo,...) returning a live AI-credits string isn't wired here yet. + loweredTextOut(canvas, -1, *MainTexture, 42, 445, QString()); + } else { + loweredTextOut(canvas, -2, *MainTexture, 42, 445, phrase(QStringLiteral("MENU_TELLAI"))); + } + + ui->contactBtn->setBack(canvas, ui->contactBtn->x(), ui->contactBtn->y()); + canvas.end(); + + markUsedOffscreen(width(), height()); +} + +void NatStatDlg::dialogBtnClicked() +{ + const int contactResult = Term::mainScreenDipCall(scContact + (pView << 4)); + if (contactResult < rExecuted) { + if (contactResult == eColdWar) { + // SoundMessage(...) - Messg.pas's sound-message variant isn't wired here yet. + } else if (ClientTools::myRO->Government == gAnarchy) { + // "We are in anarchy" - Messg.pas sound message, not wired here yet. + } else if (contactResult == eAnarchy) { + if (ClientTools::myRO->Treaty[pView] >= trPeace) { + if (Term::mainScreenContactRefused(pView, QStringLiteral("FRANARCHY"))) + smartUpdateContent(); + } + } + } else { + close(); + } +} + +void NatStatDlg::toggleBtnClicked() +{ + popup->clear(); + + if (ClientTools::g.Difficulty[ClientTools::me] != 0) { + QAction *action = popup->addAction( + Tribes::tribe[static_cast(ClientTools::me)]->tPhrase(QStringLiteral("TITLE_NATION"))); + action->setCheckable(true); + action->setChecked(ClientTools::me == pView); + connect(action, &QAction::triggered, this, [this] { playerClicked(ClientTools::me); }); + } + + for (int extinctPart = 0; extinctPart <= 1; ++extinctPart) { + const int startCount = popup->actions().size(); + for (int p1 = 0; p1 < nPl; ++p1) { + const bool aliveMatch = (1u << p1 & static_cast(ClientTools::myRO->Alive)) != 0 && + ClientTools::myRO->Treaty[p1] >= trNone; + const bool extinctMatch = ClientTools::g.Difficulty[p1] > 0 && + (1u << p1 & static_cast(ClientTools::myRO->Alive)) == 0; + if ((extinctPart != 0 && extinctMatch) || (extinctPart == 0 && aliveMatch)) { + QString caption = Tribes::tribe[static_cast(p1)]->tPhrase(QStringLiteral("TITLE_NATION")); + if (extinctPart) + caption = QLatin1Char('(') + caption + QLatin1Char(')'); + QAction *action = popup->addAction(caption); + action->setCheckable(true); + action->setChecked(p1 == pView); + connect(action, &QAction::triggered, this, [this, p1] { playerClicked(p1); }); + } + } + if (startCount > 0 && popup->actions().size() > startCount) + popup->insertSeparator(popup->actions().at(startCount)); + } + + popup->popup(mapToGlobal(QPoint(ui->toggleBtn->x(), ui->toggleBtn->y() + ui->toggleBtn->height()))); +} + +void NatStatDlg::tellAIBtnClicked() +{ + Term::optionChecked ^= (1u << ClientTools::soTellAI); + ui->tellAIBtn->setButtonIndex(ClientTools::hasSaveOption(Term::optionChecked, ClientTools::soTellAI) ? 3 : 2); + smartUpdateContent(); +} + +void NatStatDlg::ecoChange() +{ + if (isVisible() && pView == ClientTools::me) { + selfReport.Government = ClientTools::myRO->Government; + selfReport.Money = ClientTools::myRO->Money; + smartUpdateContent(); + } +} + +void NatStatDlg::keyPressEvent(QKeyEvent *event) +{ + if (event->key() == Qt::Key_F9) { + int i = 0; + do { + pView = (pView + 1) % nPl; + ++i; + } while (i < nPl && !((1u << pView & static_cast(ClientTools::myRO->Alive)) != 0 && + ClientTools::myRO->Treaty[pView] >= trNone)); + if (i >= nPl) + pView = ClientTools::me; + playerClicked(pView); + } else { + BufferedDrawDlg::keyPressEvent(event); + } +} + +} // namespace NatStat +} // namespace Cevo diff --git a/game/localplayer/NatStat.h b/game/localplayer/NatStat.h new file mode 100644 index 0000000..84c45b7 --- /dev/null +++ b/game/localplayer/NatStat.h @@ -0,0 +1,87 @@ +// 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 "Cevo/Protocol.h" + +#include + +class QMenu; + +QT_BEGIN_NAMESPACE +namespace Ui { +class NatStatDlg; +} +QT_END_NAMESPACE + +namespace Cevo { +namespace NatStat { + +// TNatStatDlg equivalent: a nation's nation-status report (treasury, stats, +// relations, leader portrait). UI built from NatStat.ui (adapted from the +// original's NatStat.lfm). +class NatStatDlg : public BufferedDrawDlg { + Q_OBJECT +public: + explicit NatStatDlg(QWidget *parent = nullptr); + ~NatStatDlg() override; + + void showNewContent(WindowMode newMode, int p = -1); + void checkAge(); + void ecoChange(); + +protected: + void offscreenPaint() override; + +private: + void generateReportText(); + void toggleBtnClicked(); + void playerClicked(int p); + void dialogBtnClicked(); + void tellAIBtnClicked(); + void keyPressEvent(QKeyEvent *event) override; + + int pView = 0; + int agePrepared = -2; + int linesDown = 0; + TEnemyReport selfReport{}; + const TEnemyReport *currentReport = nullptr; + bool showContact = false; + bool contactEnabled = false; + Dpi::Bitmap back; + Dpi::Bitmap tmpl; + QStringList reportText; + + QMenu *popup; + Ui::NatStatDlg *ui; +}; + +} // namespace NatStat +} // namespace Cevo diff --git a/game/localplayer/NatStat.ui b/game/localplayer/NatStat.ui new file mode 100644 index 0000000..4b6124d --- /dev/null +++ b/game/localplayer/NatStat.ui @@ -0,0 +1,121 @@ + + + + NatStatDlg + + + + 0 + 0 + 400 + 480 + + + + C-evo + + + + + 6 + 6 + 25 + 25 + + + + + + + 369 + 6 + 25 + 25 + + + + + + + 381 + 278 + 12 + 12 + + + + + + + 381 + 290 + 12 + 12 + + + + + + + 330 + 45 + 48 + 48 + + + + + + + 24 + 450 + 12 + 12 + + + + + + + Cevo::ButtonB + QWidget +
Cevo/CevoButtonB.h
+
+ + Cevo::ButtonC + QWidget +
Cevo/CevoButtonC.h
+
+ + Cevo::EOTButton + QWidget +
Cevo/CevoEOTButton.h
+
+
+ +
diff --git a/game/localplayer/Term.cpp b/game/localplayer/Term.cpp index 4aacd29..a3d95b4 100644 --- a/game/localplayer/Term.cpp +++ b/game/localplayer/Term.cpp @@ -28,11 +28,40 @@ #include "Term.h" +#include "Global.h" +#include "Tribes.h" + namespace Cevo { namespace Term { PersistentData *myData = nullptr; Dpi::Bitmap *smallImp = nullptr; +ClientTools::SaveOptions optionChecked = 0; +bool supervising = false; +std::array dipMem{}; +std::function mainScreenDipCall = [](int) { return eInvalid; }; +std::function mainScreenContactRefused = [](int, const QString &) { return false; }; + +int roughCredibility(int credibility) +{ + if (credibility <= 69) + return 0; + if (credibility <= 89) + return 1; + if (credibility <= 99) + return 2; + return 3; +} + +QString turnToString(int turn) +{ + if (!generateNames) + return QString::number(turn); + const int year = turnToYear(turn); + // Phrases['BC']/['AD'] (StringTables.pas) aren't ported; disclosed + // plain-English fallback format. + return year < 0 ? QStringLiteral("%1 BC").arg(-year) : QStringLiteral("AD %1").arg(year); +} void impImage(Dpi::Canvas &canvas, int x, int y, int iix, int government, bool isControl) { @@ -46,5 +75,29 @@ void impImage(Dpi::Canvas &canvas, int x, int y, int iix, int government, bool i (iix + SystemIconLines * 7) / 7 * ySizeBig, isControl); } +void chooseModelPicture(int p, int mix, int code, int hash, int turn, bool forceNew, bool final) +{ + Tribes::ModelPictureInfo picture; + picture.trix = p; + picture.mix = mix; + picture.hash = hash; + const bool isNew = Tribes::tribe[static_cast(p)]->chooseModelPicture(picture, code, turn, forceNew); + if (final) { + Tribes::tribe[static_cast(p)]->setModelPicture(picture, isNew); + } else { + Tribes::ModelPicture &mp = Tribes::tribe[static_cast(p)]->modelPictureAt(mix); + mp.hGr = loadGraphicSet(picture.grName); + mp.pix = picture.pix; + } +} + +void initMyModel(int mix, bool final) +{ + TModelInfo mi{}; + MakeModelInfo(ClientTools::me, mix, ClientTools::myModel[mix], mi); + chooseModelPicture(ClientTools::me, mix, Tribes::modelCode(mi), ClientTools::modelHash(mi), + ClientTools::myRO->Turn, false, final); +} + } // namespace Term } // namespace Cevo diff --git a/game/localplayer/Term.h b/game/localplayer/Term.h index e6b23e3..6b59416 100644 --- a/game/localplayer/Term.h +++ b/game/localplayer/Term.h @@ -32,7 +32,10 @@ #include "Cevo/Protocol.h" #include "ClientTools.h" +#include + #include +#include namespace Cevo { namespace Term { @@ -80,5 +83,45 @@ extern Dpi::Bitmap *smallImp; // from bigImp, substituting the age-specific palace graphic for imPalace. void impImage(Dpi::Canvas &canvas, int x, int y, int iix, int government = -1, bool isControl = false); +// Term.pas's `OptionChecked: TSaveOptions;` (user-configurable UI options). +extern ClientTools::SaveOptions optionChecked; +// Term.pas's `Supervising: Boolean;` (true when controlling player 0 is +// just observing rather than playing a nation). +extern bool supervising; + +// Term.pas's `TDipMem` (per-nation negotiation session memory) - only the +// one field (`pContact`) anything needs so far. +struct DipMemEntry { + int pContact = -1; +}; +extern std::array dipMem; + +// Term.pas's RoughCredibility(): buckets a 0..100 credibility value into a +// 4-level rating (0..3) for display. +int roughCredibility(int credibility); + +// ScreenTools.pas's TurnToString(): turnToYear() formatted as " BC"/"AD +// " (or the plain turn number if `generateNames` is off). Lives here +// rather than in the widget-layer CevoScreenTools.h since it needs +// Global::generateNames (a game-layer symbol widget/ mustn't depend on). +QString turnToString(int turn); + +// Term.pas's `MainScreen: TMainScreen` instance isn't ported; these mirror +// its DipCall()/ContactRefused() methods as injection points other leaf +// dialogs can call into once Term.pas/Nego.pas exist. Default to safe +// no-ops (DipCall "not executed", ContactRefused "not refused") so callers +// relying on them just see "nothing happened" rather than crashing. +extern std::function mainScreenDipCall; +extern std::function mainScreenContactRefused; + +// Term.pas's ChooseModelPicture()/InitMyModel(): assigns a visual "picture" +// to a developed/enemy unit model. Simplified - always takes the +// "non-original tribe" path (dispatches straight through +// Tribe::setModelPicture()) since the network cSet*ModelPicture command +// plumbing isn't ported, and the mkSlaves (Code==74) special case isn't +// handled either (narrow edge case, not reached by anything ported so far). +void chooseModelPicture(int p, int mix, int code, int hash, int turn, bool forceNew, bool final); +void initMyModel(int mix, bool final); + } // namespace Term } // namespace Cevo