From e4c7102b85b443889c0da10e5c4c4ddeec23d761 Mon Sep 17 00:00:00 2001 From: Geoffray Levasseur Date: Tue, 3 Nov 2026 15:40:54 +0100 Subject: [PATCH] unitstat implementation with its requirements --- game/localplayer/IsoEngine.cpp | 5 + game/localplayer/IsoEngine.h | 4 + game/localplayer/Term.cpp | 2 + game/localplayer/Term.h | 12 + game/localplayer/UnitStat.cpp | 615 +++++++++++++++++++++++++++++++++ game/localplayer/UnitStat.h | 85 +++++ game/localplayer/UnitStat.ui | 96 +++++ 7 files changed, 819 insertions(+) create mode 100644 game/localplayer/UnitStat.cpp create mode 100644 game/localplayer/UnitStat.h create mode 100644 game/localplayer/UnitStat.ui diff --git a/game/localplayer/IsoEngine.cpp b/game/localplayer/IsoEngine.cpp index 8df83c7..bc0993b 100644 --- a/game/localplayer/IsoEngine.cpp +++ b/game/localplayer/IsoEngine.cpp @@ -93,6 +93,11 @@ void init(InitEnemyModelEvent initEnemyModelHandler) onInitEnemyModel = std::move(initEnemyModelHandler); } +bool invokeInitEnemyModel(int emix) +{ + return !onInitEnemyModel || onInitEnemyModel(emix); +} + void CitiesPictures::prepare(GraphicSet *hGrCities, int xxt, int yyt) { for (int age = 2; age <= 3; ++age) { diff --git a/game/localplayer/IsoEngine.h b/game/localplayer/IsoEngine.h index b4d41e2..cfcc8bd 100644 --- a/game/localplayer/IsoEngine.h +++ b/game/localplayer/IsoEngine.h @@ -234,6 +234,10 @@ private: bool isJungle(int y); void init(InitEnemyModelEvent initEnemyModelHandler); +// Calls the handler registered via init() (true if none registered, i.e. +// "nothing to do, proceed"), for other LocalPlayer files that need +// Term.pas's `InitEnemyModel` without re-registering their own handler. +bool invokeInitEnemyModel(int emix); } // namespace IsoEngine } // namespace Cevo diff --git a/game/localplayer/Term.cpp b/game/localplayer/Term.cpp index a3d95b4..164b2d8 100644 --- a/game/localplayer/Term.cpp +++ b/game/localplayer/Term.cpp @@ -36,6 +36,8 @@ namespace Term { PersistentData *myData = nullptr; Dpi::Bitmap *smallImp = nullptr; +bool mainScreenNamesChecked = true; +Dpi::Bitmap buffer; ClientTools::SaveOptions optionChecked = 0; bool supervising = false; std::array dipMem{}; diff --git a/game/localplayer/Term.h b/game/localplayer/Term.h index 6b59416..2373890 100644 --- a/game/localplayer/Term.h +++ b/game/localplayer/Term.h @@ -53,6 +53,18 @@ constexpr int xSizeSmall = 36; constexpr int ySizeSmall = 20; constexpr int SystemIconLines = 2; +// TModel.Status bit flags. +constexpr int msObsolete = 0x1; +constexpr int msAllowConscripts = 0x2; + +// Term.pas's `MainScreen.mNames.Checked` (menu checkbox: show real model +// names vs. generic "Model #n" names) - defaults to the more useful true. +extern bool mainScreenNamesChecked; +// Term.pas's `Buffer: TBitmap` - a shared general-purpose scratch bitmap; +// callers must setSize() it themselves before use (no central owner +// resizes it yet since Term.pas's own usage isn't ported). +extern Dpi::Bitmap buffer; + // Term.pas's `TPersistentData` (per-player persisted client-side settings, // e.g. city build-order preferences) - only the fields some leaf dialog // needs are ported so far; add more as needed. diff --git a/game/localplayer/UnitStat.cpp b/game/localplayer/UnitStat.cpp new file mode 100644 index 0000000..7f14377 --- /dev/null +++ b/game/localplayer/UnitStat.cpp @@ -0,0 +1,615 @@ +// 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 "UnitStat.h" +#include "ui_UnitStat.h" + +#include "Cevo/CevoTexture.h" +#include "ClientTools.h" +#include "Global.h" +#include "Help.h" +#include "Term.h" +#include "Tribes.h" + +#include + +namespace Cevo { +namespace UnitStat { + +namespace { + +constexpr int xView = 71; +constexpr int xTotal = 20; +constexpr int StatDown = 112; +constexpr int yImp = 133; + +constexpr int wCommon = 208; +constexpr int hOwnModel = 293; +constexpr int hEnemyModel = 236; +constexpr int hEnemyUnit = 212; +constexpr int hEnemyCityDefense = 320; +constexpr int hEnemyCity = 166; +constexpr int hMax = 320; + +// 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("UNITSPECIAL"), QStringLiteral("Special unit")}, + {QStringLiteral("CONTROLS6"), QStringLiteral("Special unit controls")}, + {QStringLiteral("UNITSTRENGTH"), QStringLiteral("Attack/Defense")}, + {QStringLiteral("UNITSPEED"), QStringLiteral("Speed")}, + {QStringLiteral("UNITCOST"), QStringLiteral("Cost")}, + {QStringLiteral("UNITADOPT"), QStringLiteral("Adopted")}, + {QStringLiteral("UNITINTRO"), QStringLiteral("Introduced")}, + {QStringLiteral("UNITBUILT"), QStringLiteral("Built")}, + {QStringLiteral("UNITLOST"), QStringLiteral("Lost")}, + {QStringLiteral("UNITINPROD"), QStringLiteral("In production")}, + {QStringLiteral("UNITAVAILABLE"), QStringLiteral("Available")}, + {QStringLiteral("UNITDESTROYED"), QStringLiteral("Destroyed")}, + {QStringLiteral("UNITKNOWN"), QStringLiteral("Known")}, + {QStringLiteral("BTN_OBSOLETE"), QStringLiteral("Mark as obsolete")}, + {QStringLiteral("BTN_NONOBSOLETE"), QStringLiteral("Mark as not obsolete")}, + {QStringLiteral("BTN_NOCONSCRIPTS"), QStringLiteral("Allow conscripts")}, + {QStringLiteral("BTN_ALLOWCONSCRIPTS"), QStringLiteral("Disallow conscripts")}, + }; + const auto it = table.constFind(key); + return it != table.constEnd() ? it.value() : key; +} + +void featureBar(Dpi::Canvas &canvas, int x, int y, const TModelInfo &mi, const Texture &) +{ + darkGradient(canvas, x - 6, y + 1, 180, 1); + if (mi.Kind >= 0x10) { + const QString s = phrase(QStringLiteral("UNITSPECIAL")); + canvas.font().setColor(Qt::black); + canvas.textOut(x - 1, y + 1, s); + canvas.font().setColor(QColor(0xB0, 0xB0, 0xB0)); + canvas.textOut(x - 2, y, s); + return; + } + + canvas.font().setColor(Qt::black); + int dx = 2; + for (int i = 3; i < nFeature; ++i) { + int num = 0; + switch (i) { + case mcSeaTrans: if (mi.Domain == dSea) num = mi.TTrans; break; + case mcCarrier: if (mi.Domain == dSea) num = mi.ATrans_Fuel; break; + case mcBombs: num = mi.Bombs; break; + case mcFuel: if (mi.Domain == dAir) num = mi.ATrans_Fuel; break; + case mcAirTrans: if (mi.Domain == dAir) num = mi.TTrans; break; + default: + if (i >= mcFirstNonCap && (mi.Cap & (1u << (i - mcFirstNonCap)))) + num = 1; + break; + } + if (num > 0 && (i != mcSE || (mi.Cap & (1u << (mcNP - mcFirstNonCap))) == 0)) { + if (num > 1) { + const QString s = QString::number(num); + const int w = canvas.textWidth(s); + canvas.brush().setColor(Qt::white); + canvas.fillRect(QRect(x - 3 + dx, y + 2, w + 2, 14)); + canvas.brush().setStyle(Qt::NoBrush); + canvas.textOut(x - 3 + dx + 1, y, s); + dx += w + 1; + } + canvas.brush().setColor(QColor(0xC0, 0xC0, 0xC0)); + canvas.frameRect(QRect(x - 3 + dx, y + 2, 15, 14)); + canvas.brush().setStyle(Qt::NoBrush); + sprite(canvas, *HGrSystem, x - 1 + dx, y + 4, 10, 10, 66 + i % 11 * 11, 137 + i / 11 * 11); + dx += 15; + } + } +} + +void numberBarS(Dpi::Canvas &canvas, int x, int y, const QString &cap, const QString &s, const Texture &texture) +{ + dLine(canvas, x - 2, x + 170, y + 16, texture.colorBevelShade, texture.colorBevelLight); + loweredTextOut(canvas, -1, texture, x - 2, y, cap); + risedTextOut(canvas, x + 170 - biColorTextWidth(canvas, s), y, s); +} + +} // namespace + +UnitStatDlg::UnitStatDlg(QWidget *parent) : BufferedDrawDlg(parent), ui(new Ui::UnitStatDlg) +{ + ui->setupUi(this); + noMap = std::make_unique(); + titleHeight = Dpi::Screen::primaryMonitor().height(); + initButtons(); + + back.setSize(5 * wCommon, hMax); + back.canvas().begin(); + back.canvas().fillRect(QRect(0, 0, back.width(), back.height())); + back.canvas().end(); + tmpl.loadFromFile(getGraphicsDir() + QStringLiteral("/Unit") + PngExt); + + ui->closeBtn->onClick = [this] { close(); }; + ui->switchBtn->onClick = [this] { + ClientTools::myModel[mixShow].Status ^= Term::msObsolete; + if (ClientTools::myModel[mixShow].Status & Term::msObsolete) { + ui->switchBtn->setButtonIndex(12); + ui->switchBtn->setToolTip(phrase(QStringLiteral("BTN_OBSOLETE"))); + } else { + ui->switchBtn->setButtonIndex(11); + ui->switchBtn->setToolTip(phrase(QStringLiteral("BTN_NONOBSOLETE"))); + } + }; + ui->conscriptsBtn->onClick = [this] { + ClientTools::myModel[mixShow].Status ^= Term::msAllowConscripts; + if ((ClientTools::myModel[mixShow].Status & Term::msAllowConscripts) == 0) { + ui->conscriptsBtn->setButtonIndex(30); + ui->conscriptsBtn->setToolTip(phrase(QStringLiteral("BTN_NOCONSCRIPTS"))); + } else { + ui->conscriptsBtn->setButtonIndex(29); + ui->conscriptsBtn->setToolTip(phrase(QStringLiteral("BTN_ALLOWCONSCRIPTS"))); + } + }; + ui->helpBtn->onClick = [this] { Help::showNewContent(WindowMode::Persistent, Help::LinkCategory::Model, 0); }; + + onShow = [this] { + if (kind == UnitStatDialogKind::EnemyUnit || kind == UnitStatDialogKind::EnemyCityDefense || + kind == UnitStatDialogKind::EnemyCity) { + if (ClientTools::myMap[unitLoc] & fUnit) { + if (euixShow < 0) { + euixShow = ClientTools::myRO->nEnemyUn - 1; + while (euixShow >= 0 && (*ClientTools::myRO->EnemyUn)[euixShow].Loc != unitLoc) + --euixShow; + Q_ASSERT(euixShow >= 0); + } + const TUnitInfo &eu = (*ClientTools::myRO->EnemyUn)[euixShow]; + mox = &(*ClientTools::myRO->EnemyModel)[eu.emix]; + if (!Tribes::tribe[eu.Owner]->modelPictureAt(eu.mix).hGr) + IsoEngine::invokeInitEnemyModel(eu.emix); + } else { + mox = nullptr; + } + if (kind == UnitStatDialogKind::EnemyCityDefense || kind == UnitStatDialogKind::EnemyCity) { + ecixShow = ClientTools::myRO->nEnemyCity - 1; + while (ecixShow >= 0 && (*ClientTools::myRO->EnemyCity)[ecixShow].Loc != unitLoc) + --ecixShow; + Q_ASSERT(ecixShow >= 0); + } + } + + int newHeight = hOwnModel; + switch (kind) { + case UnitStatDialogKind::OwnModel: newHeight = hOwnModel; break; + case UnitStatDialogKind::OwnUnit: newHeight = hEnemyUnit; break; + case UnitStatDialogKind::EnemyModel: newHeight = hEnemyModel; break; + case UnitStatDialogKind::EnemyUnit: newHeight = hEnemyUnit; break; + case UnitStatDialogKind::EnemyCityDefense: newHeight = hEnemyCityDefense; break; + case UnitStatDialogKind::EnemyCity: newHeight = hEnemyCity; break; + } + resize(width(), newHeight); + + if (kind == UnitStatDialogKind::OwnModel || kind == UnitStatDialogKind::EnemyModel) { + move(userLeft, userTop); + } else { + const Dpi::Monitor monitor = Dpi::Screen::primaryMonitor(); + move(monitor.left() + (monitor.width() - width()) / 2, monitor.top() + (monitor.height() - newHeight) / 2); + } + + ui->switchBtn->setVisible(!Term::supervising && kind == UnitStatDialogKind::OwnModel); + ui->conscriptsBtn->setVisible(!Term::supervising && kind == UnitStatDialogKind::OwnModel && + ClientTools::myRO->Tech[adConscription] >= tsApplicable && + ClientTools::myModel[mixShow].Domain == dGround && + ClientTools::myModel[mixShow].Kind < mkScout); + + bool isSpecialUnit = false; + if (kind == UnitStatDialogKind::EnemyCity || kind == UnitStatDialogKind::EnemyCityDefense) { + setWindowTitle(Tribes::cityName((*ClientTools::myRO->EnemyCity)[ecixShow].ID)); + } else { + int owner = ClientTools::me; + int mix = mixShow; + switch (kind) { + case UnitStatDialogKind::OwnModel: + owner = ClientTools::me; + mix = mixShow; + isSpecialUnit = ClientTools::myModel[mix].Kind >= 0x10; + break; + case UnitStatDialogKind::OwnUnit: + owner = ClientTools::me; + mix = ClientTools::myUn[uixShow].mix; + isSpecialUnit = ClientTools::myModel[mix].Kind >= 0x10; + break; + default: + owner = mox->Owner; + mix = mox->mix; + isSpecialUnit = mox->Kind >= 0x10; + break; + } + if (Term::mainScreenNamesChecked) + setWindowTitle(Tribes::tribe[owner]->modelNameAt(mix)); + else + setWindowTitle(Tribes::tribe[owner]->tPhrase(QStringLiteral("GENMODEL")).arg(mix)); + } + if (isSpecialUnit) + ui->helpBtn->setToolTip(phrase(QStringLiteral("CONTROLS6"))); + ui->helpBtn->setVisible(isSpecialUnit); + offscreenPaint(); + }; +} + +UnitStatDlg::~UnitStatDlg() +{ + delete ui; +} + +void UnitStatDlg::closeEvent(QCloseEvent *event) +{ + if (kind == UnitStatDialogKind::OwnModel || kind == UnitStatDialogKind::EnemyModel) { + userLeft = x(); + userTop = y(); + } + BufferedDrawDlg::closeEvent(event); +} + +void UnitStatDlg::checkAge() +{ + if (!MainTexture) + return; + if (MainTexture->age() != agePrepared) { + agePrepared = MainTexture->age(); + bitBltBitmap(back, 0, 0, wCommon, hOwnModel, MainTexture->image(), (MainTexture->width() - wCommon) / 2, + (MainTexture->height() - hOwnModel) / 2); + bitBltBitmap(back, wCommon, 0, wCommon, hEnemyModel, MainTexture->image(), (MainTexture->width() - wCommon) / 2, + (MainTexture->height() - hEnemyModel) / 2); + bitBltBitmap(back, 2 * wCommon, 0, wCommon, hEnemyUnit, MainTexture->image(), + (MainTexture->width() - wCommon) / 2, (MainTexture->height() - hEnemyUnit) / 2); + bitBltBitmap(back, 3 * wCommon, 0, wCommon, hEnemyCityDefense, MainTexture->image(), + (MainTexture->width() - wCommon) / 2, (MainTexture->height() - hEnemyCityDefense) / 2); + bitBltBitmap(back, 4 * wCommon, 0, wCommon, hEnemyCity, MainTexture->image(), + (MainTexture->width() - wCommon) / 2, (MainTexture->height() - hEnemyCity) / 2); + imageOpB(back, tmpl, 0, 0, 0, 0, 5 * wCommon, hMax); + } +} + +void UnitStatDlg::showNewContentOwnModel(WindowMode newMode, int mix) +{ + kind = UnitStatDialogKind::OwnModel; + mixShow = mix; + showNewContent(newMode); +} + +void UnitStatDlg::showNewContentOwnUnit(WindowMode newMode, int uix) +{ + kind = UnitStatDialogKind::OwnUnit; + uixShow = uix; + showNewContent(newMode); +} + +void UnitStatDlg::showNewContentEnemyUnit(WindowMode newMode, int euix) +{ + kind = UnitStatDialogKind::EnemyUnit; + euixShow = euix; + unitLoc = (*ClientTools::myRO->EnemyUn)[euix].Loc; + showNewContent(newMode); +} + +void UnitStatDlg::showNewContentEnemyLoc(WindowMode newMode, int loc) +{ + kind = UnitStatDialogKind::EnemyUnit; + unitLoc = loc; + euixShow = -1; + showNewContent(newMode); +} + +void UnitStatDlg::showNewContentEnemyModel(WindowMode newMode, int emix) +{ + kind = UnitStatDialogKind::EnemyModel; + mox = &(*ClientTools::myRO->EnemyModel)[emix]; + showNewContent(newMode); +} + +void UnitStatDlg::showNewContentEnemyCity(WindowMode newMode, int loc) +{ + kind = (ClientTools::myMap[loc] & fUnit) ? UnitStatDialogKind::EnemyCityDefense : UnitStatDialogKind::EnemyCity; + unitLoc = loc; + euixShow = -1; + showNewContent(newMode); +} + +void UnitStatDlg::offscreenPaint() +{ + BufferedDrawDlg::offscreenPaint(); + if (!MainTexture) + return; + + auto isToCount = [this](int emix) { + const TModelInfo &em = (*ClientTools::myRO->EnemyModel)[emix]; + if (Term::mainScreenNamesChecked) { + const Tribes::ModelPicture &testPicture = Tribes::tribe[em.Owner]->modelPictureAt(em.mix); + const Tribes::ModelPicture &picture = Tribes::tribe[mox->Owner]->modelPictureAt(mox->mix); + return picture.hGr == testPicture.hGr && picture.pix == testPicture.pix && + ClientTools::modelHash(*mox) == ClientTools::modelHash(em); + } + return em.Owner == mox->Owner && em.mix == mox->mix; + }; + + Dpi::Canvas &canvas = offscreen.canvas(); + canvas.begin(); + + int yView, yTotal; + switch (kind) { + case UnitStatDialogKind::OwnModel: + bitBltBitmap(offscreen, 0, 0, wCommon, hOwnModel, back, 0, 0); + yView = 13; yTotal = 92; + break; + case UnitStatDialogKind::EnemyModel: + bitBltBitmap(offscreen, 0, 0, wCommon, hEnemyModel, back, wCommon, 0); + yView = 13; yTotal = 92; + break; + case UnitStatDialogKind::EnemyUnit: + case UnitStatDialogKind::OwnUnit: + bitBltBitmap(offscreen, 0, 0, wCommon, hEnemyUnit, back, 2 * wCommon, 0); + yView = 13; yTotal = 123; + break; + case UnitStatDialogKind::EnemyCityDefense: + bitBltBitmap(offscreen, 0, 0, wCommon, hEnemyCityDefense, back, 3 * wCommon, 0); + yView = 171; yTotal = 231; + break; + default: // EnemyCity + bitBltBitmap(offscreen, 0, 0, wCommon, hEnemyCity, back, 4 * wCommon, 0); + yView = 171; yTotal = 231; + break; + } + markUsedOffscreen(width(), height()); + ui->helpBtn->move(ui->helpBtn->x(), yTotal + 22); + + if (kind == UnitStatDialogKind::EnemyCityDefense || kind == UnitStatDialogKind::EnemyCity) { + const TCityInfo &ci = (*ClientTools::myRO->EnemyCity)[ecixShow]; + int cnt = 0; + for (int i = 0; i <= 3; ++i) + if (ci.Flags & (2 << i)) + ++cnt; + int x = (wCommon - cnt * Term::xSizeSmall) / 2 - (cnt - 1) * 2; + for (int i = 0; i <= 3; ++i) { + if (ci.Flags & (2 << i)) { + int j = imWalls; + switch (i) { + case 0: j = imWalls; break; + case 1: j = imCoastalFort; break; + case 2: j = imMissileBat; break; + case 3: j = imBunker; break; + } + frame(canvas, x - 1, yImp - 1, x + Term::xSizeSmall, yImp + Term::ySizeSmall, + MainTexture->colorBevelLight, MainTexture->colorBevelShade); + if (Term::smallImp) + bitBltBitmap(offscreen, x, yImp, Term::xSizeSmall, Term::ySizeSmall, *Term::smallImp, + j % 7 * Term::xSizeSmall, (j + Term::SystemIconLines * 7) / 7 * Term::ySizeSmall); + x += Term::xSizeSmall + 4; + } + } + } + + int available = 0, inProd = 0, destroyed = 0; + if (kind == UnitStatDialogKind::EnemyModel) { + if (ClientTools::g.Difficulty[ClientTools::me] == 0) { + for (int loc = 0; loc < ClientTools::g.lx * ClientTools::g.ly; ++loc) { + if (ClientTools::myMap[loc] & fUnit) { + int cnt = 0; + ClientTools::server(sGetUnits, ClientTools::me, loc, &cnt); + for (int uix = 0; uix < cnt; ++uix) + if (isToCount((*ClientTools::myRO->EnemyUn)[ClientTools::myRO->nEnemyUn + uix].emix)) + ++available; + } + } + } else { + for (int uix = 0; uix < ClientTools::myRO->nEnemyUn; ++uix) + if ((*ClientTools::myRO->EnemyUn)[uix].Loc >= 0 && + isToCount((*ClientTools::myRO->EnemyUn)[uix].emix)) + ++available; + } + for (int emix = 0; emix < ClientTools::myRO->nEnemyModel; ++emix) + if (isToCount(emix)) + destroyed += (*ClientTools::myRO->EnemyModel)[emix].Lost; + } else { + for (int uix = 0; uix < ClientTools::myRO->nUn; ++uix) + if (ClientTools::myUn[uix].Loc >= 0 && ClientTools::myUn[uix].mix == mixShow) + ++available; + for (int cix = 0; cix < ClientTools::myRO->nCity; ++cix) + if (ClientTools::myCity[cix].Loc >= 0 && + (ClientTools::myCity[cix].Project & (cpImp + cpIndex)) == mixShow) + ++inProd; + } + + canvas.font().assign(UniFont[static_cast(FontType::Small)]); + if (kind == UnitStatDialogKind::EnemyCityDefense || kind == UnitStatDialogKind::EnemyCity) { + const TCityInfo &ci = (*ClientTools::myRO->EnemyCity)[ecixShow]; + noMap->setOutput(&offscreen); + noMap->paintCity(width() / 2, 53, ci, false); + const QString s = Tribes::tribe[ci.Owner]->tPhrase(QStringLiteral("UNITOWNER")); + loweredTextOut(canvas, -1, *MainTexture, (width() - biColorTextWidth(canvas, s)) / 2, 105, s); + } + + if (kind != UnitStatDialogKind::EnemyCity) { + TUnitInfo unitInfo{}; + TModelInfo mi{}; + if (kind == UnitStatDialogKind::OwnModel) { + MakeModelInfo(ClientTools::me, mixShow, ClientTools::myModel[mixShow], mi); + } else if (kind == UnitStatDialogKind::OwnUnit) { + MakeUnitInfo(ClientTools::me, ClientTools::myUn[uixShow], unitInfo); + MakeModelInfo(ClientTools::me, ClientTools::myUn[uixShow].mix, ClientTools::myModel[ClientTools::myUn[uixShow].mix], mi); + } else { + mi = *mox; + if (kind == UnitStatDialogKind::EnemyUnit || kind == UnitStatDialogKind::EnemyCityDefense) + unitInfo = (*ClientTools::myRO->EnemyUn)[euixShow]; + } + + const Tribes::ModelPicture &mp = Tribes::tribe[mi.Owner]->modelPictureAt(mi.mix); + if (kind == UnitStatDialogKind::OwnUnit || kind == UnitStatDialogKind::EnemyUnit || + kind == UnitStatDialogKind::EnemyCityDefense) { + canvas.brush().setColor(HGrSystem->data.image().pixelColor(98, 67)); + canvas.fillRect(QRect(xView, yView, 64, 16)); + canvas.brush().setStyle(Qt::NoBrush); + + int tx, ty; + if ((ClientTools::myMap[unitInfo.Loc] & fTerrain) >= static_cast(fForest)) { + tx = 1 + 2 * (noMap->xxt * 2 + 1); + ty = 1 + noMap->yyt + 2 * (noMap->yyt * 3 + 1); + } else { + tx = static_cast(ClientTools::myMap[unitInfo.Loc] & fTerrain) * (noMap->xxt * 2 + 1) + 1; + ty = 1 + noMap->yyt; + } + Term::buffer.setSize(std::max(Term::buffer.width(), noMap->xxt * 2), std::max(Term::buffer.height(), noMap->yyt * 2)); + Dpi::Canvas &bufCanvas = Term::buffer.canvas(); + bufCanvas.begin(); + for (int j = -1; j <= 1; ++j) { + for (int i = -1; i <= 1; ++i) { + if (((i + j) & 1) == 0) { + sprite(bufCanvas, *noMap->hGrTerrain, i * noMap->xxt, j * noMap->yyt, noMap->xxt * 2, + noMap->yyt * 2, tx, ty); + if ((ClientTools::myMap[unitInfo.Loc] & (fTerrain | fSpecial)) == + static_cast(fGrass | fSpecial1)) + sprite(bufCanvas, *noMap->hGrTerrain, i * noMap->xxt, j * noMap->yyt, noMap->xxt * 2, + noMap->yyt * 2, 1 + 2 * (noMap->xxt * 2 + 1), 1 + noMap->yyt + 1 * (noMap->yyt * 3 + 1)); + else if ((ClientTools::myMap[unitInfo.Loc] & fTerrain) == static_cast(fForest) && + IsoEngine::isJungle(unitInfo.Loc / ClientTools::g.lx)) + sprite(bufCanvas, *noMap->hGrTerrain, i * noMap->xxt, j * noMap->yyt, noMap->xxt * 2, + noMap->yyt * 2, 1 + 7 * (noMap->xxt * 2 + 1), 1 + noMap->yyt + 19 * (noMap->yyt * 3 + 1)); + else if ((ClientTools::myMap[unitInfo.Loc] & fTerrain) >= static_cast(fForest)) + sprite(bufCanvas, *noMap->hGrTerrain, i * noMap->xxt, j * noMap->yyt, noMap->xxt * 2, + noMap->yyt * 2, 1 + 7 * (noMap->xxt * 2 + 1), + 1 + noMap->yyt + + 2 * static_cast(2 + (ClientTools::myMap[unitInfo.Loc] & fTerrain) - fForest) * + (noMap->yyt * 3 + 1)); + } + } + } + bufCanvas.end(); + bitBltBitmap(offscreen, xView, yView + 16, 64, 32, Term::buffer, 1, 0); + + sprite(canvas, *mp.hGr, xView, yView, 64, 48, mp.pix % 10 * 65 + 1, mp.pix / 10 * 49 + 1); + if (unitInfo.Flags & unFortified) + sprite(canvas, *Tribes::hGrStdUnits, xView, yView, IsoEngine::xxu * 2, IsoEngine::yyu * 2, + 1 + 6 * (IsoEngine::xxu * 2 + 1), 1); + frameImage(canvas, HGrSystem->data, xView - 20, yView + 5, 12, 14, + 121 + unitInfo.Exp / 50 * 13, 28); + if (unitInfo.Health < 100) { + const QString s = QString::number(unitInfo.Health) + QLatin1Char('%'); + lightGradient(canvas, xView - 45, yView + 24, 38, + colorFromDelphi(((ClientTools::colorOfHealth(unitInfo.Health) & 0xFEFEFE) >> 2) * 3)); + risedTextOut(canvas, xView - 45 + 20 - biColorTextWidth(canvas, s) / 2, yView + 23, s); + } + if (kind == UnitStatDialogKind::EnemyUnit) { + const QString s = Tribes::tribe[mox->Owner]->tPhrase(QStringLiteral("UNITOWNER")); + loweredTextOut(canvas, -1, *MainTexture, (width() - biColorTextWidth(canvas, s)) / 2, yView + 80, s); + } + } else { + frameImage(canvas, *bigImp, xView + 4, yView, 56, 40, 0, 0); + sprite(canvas, *mp.hGr, xView, yView - 4, 64, 44, mp.pix % 10 * 65 + 1, mp.pix / 10 * 49 + 1); + } + + darkGradient(canvas, xTotal - 6, yTotal + 1, 180, 2); + risedTextOut(canvas, xTotal - 2, yTotal, phrase(QStringLiteral("UNITSTRENGTH"))); + QString s = QString::number(mi.Attack) + QLatin1Char('/') + QString::number(mi.Defense); + risedTextOut(canvas, xTotal + 170 - biColorTextWidth(canvas, s), yTotal, s); + featureBar(canvas, xTotal, yTotal + 19, mi, *MainTexture); + numberBarS(canvas, xTotal, yTotal + 38, phrase(QStringLiteral("UNITSPEED")), movementToString(mi.Speed), + *MainTexture); + loweredTextOut(canvas, -1, *MainTexture, xTotal - 2, yTotal + 57, phrase(QStringLiteral("UNITCOST"))); + dLine(canvas, xTotal - 2, xTotal + 170, yTotal + 57 + 16, MainTexture->colorBevelShade, + MainTexture->colorBevelLight); + s = ClientTools::g.Difficulty[ClientTools::me] == 0 + ? QString::number(mi.Cost) + : QString::number(mi.Cost * BuildCostMod[ClientTools::g.Difficulty[ClientTools::me]] / 12); + risedTextOut(canvas, xTotal + 159 - biColorTextWidth(canvas, s), yTotal + 57, s); + sprite(canvas, *HGrSystem, xTotal + 160, yTotal + 57 + 5, 10, 10, 88, 115); + + if (kind == UnitStatDialogKind::OwnModel) { + const TModel &m = ClientTools::myModel[mixShow]; + if (m.IntroTurn > 0) { + loweredTextOut(canvas, -1, *MainTexture, xTotal - 2, yTotal + StatDown - 19, + phrase(m.Kind == mkEnemyDeveloped ? QStringLiteral("UNITADOPT") + : QStringLiteral("UNITINTRO"))); + dLine(canvas, xTotal - 2, xTotal + 170, (yTotal + StatDown - 19) + 16, MainTexture->colorTextShade, + MainTexture->colorTextLight); + const QString introS = Term::turnToString(m.IntroTurn); + risedTextOut(canvas, xTotal + 170 - biColorTextWidth(canvas, introS), yTotal + StatDown - 19, introS); + } + + numberBar(canvas, xTotal, yTotal + StatDown, phrase(QStringLiteral("UNITBUILT")), m.Built, *MainTexture); + if (m.Lost > 0) + numberBar(canvas, xTotal, yTotal + StatDown + 19, phrase(QStringLiteral("UNITLOST")), m.Lost, + *MainTexture); + if (inProd > 0) + numberBar(canvas, xTotal, yTotal + StatDown + 57, phrase(QStringLiteral("UNITINPROD")), inProd, + *MainTexture); + if (available > 0) + numberBar(canvas, xTotal, yTotal + StatDown + 38, phrase(QStringLiteral("UNITAVAILABLE")), available, + *MainTexture); + + if (m.Status & Term::msObsolete) { + ui->switchBtn->setButtonIndex(12); + ui->switchBtn->setToolTip(phrase(QStringLiteral("BTN_OBSOLETE"))); + } else { + ui->switchBtn->setButtonIndex(11); + ui->switchBtn->setToolTip(phrase(QStringLiteral("BTN_NONOBSOLETE"))); + } + if ((m.Status & Term::msAllowConscripts) == 0) { + ui->conscriptsBtn->setButtonIndex(30); + ui->conscriptsBtn->setToolTip(phrase(QStringLiteral("BTN_NOCONSCRIPTS"))); + } else { + ui->conscriptsBtn->setButtonIndex(29); + ui->conscriptsBtn->setToolTip(phrase(QStringLiteral("BTN_ALLOWCONSCRIPTS"))); + } + } else if (kind == UnitStatDialogKind::EnemyModel) { + if (destroyed > 0) + numberBar(canvas, xTotal, yTotal + StatDown - 19, phrase(QStringLiteral("UNITDESTROYED")), destroyed, + *MainTexture); + if (available > 0) + numberBar(canvas, xTotal, yTotal + StatDown, phrase(QStringLiteral("UNITKNOWN")), available, + *MainTexture); + } + } + + canvas.font().assign(UniFont[static_cast(FontType::Normal)]); + int yCaption = yView + 46; + switch (kind) { + case UnitStatDialogKind::OwnModel: + case UnitStatDialogKind::EnemyModel: + yCaption = yView + 46; + break; + case UnitStatDialogKind::EnemyUnit: + case UnitStatDialogKind::OwnUnit: + yCaption = yView + 54; + break; + default: + yCaption = 79; + break; + } + risedTextOut(canvas, (width() - biColorTextWidth(canvas, windowTitle())) / 2, yCaption, windowTitle()); + + canvas.end(); +} + +} // namespace UnitStat +} // namespace Cevo diff --git a/game/localplayer/UnitStat.h b/game/localplayer/UnitStat.h new file mode 100644 index 0000000..96638f7 --- /dev/null +++ b/game/localplayer/UnitStat.h @@ -0,0 +1,85 @@ +// 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 "IsoEngine.h" + +#include + +QT_BEGIN_NAMESPACE +namespace Ui { +class UnitStatDlg; +} +QT_END_NAMESPACE + +namespace Cevo { +namespace UnitStat { + +enum class UnitStatDialogKind { OwnModel, OwnUnit, EnemyModel, EnemyUnit, EnemyCityDefense, EnemyCity }; + +// TUnitStatDlg equivalent: a unit/model/city-defense stat card. UI built +// from UnitStat.ui (adapted from the original's UnitStat.lfm). +class UnitStatDlg : public BufferedDrawDlg { + Q_OBJECT +public: + explicit UnitStatDlg(QWidget *parent = nullptr); + ~UnitStatDlg() override; + + void checkAge(); + void showNewContentOwnModel(WindowMode newMode, int mix); + void showNewContentOwnUnit(WindowMode newMode, int uix); + void showNewContentEnemyUnit(WindowMode newMode, int euix); + void showNewContentEnemyLoc(WindowMode newMode, int loc); + void showNewContentEnemyModel(WindowMode newMode, int emix); + void showNewContentEnemyCity(WindowMode newMode, int loc); + +protected: + void offscreenPaint() override; + void closeEvent(QCloseEvent *event) override; + +private: + int mixShow = 0; // for OwnModel/OwnUnit + int uixShow = 0; + int euixShow = -1; + int ecixShow = -1; + int unitLoc = 0; + int agePrepared = -2; + const TModelInfo *mox = nullptr; // for EnemyModel/EnemyUnit/EnemyCityDefense + UnitStatDialogKind kind = UnitStatDialogKind::OwnModel; + Dpi::Bitmap back; + Dpi::Bitmap tmpl; + std::unique_ptr noMap; + + Ui::UnitStatDlg *ui; +}; + +} // namespace UnitStat +} // namespace Cevo diff --git a/game/localplayer/UnitStat.ui b/game/localplayer/UnitStat.ui new file mode 100644 index 0000000..1fc05d9 --- /dev/null +++ b/game/localplayer/UnitStat.ui @@ -0,0 +1,96 @@ + + + + UnitStatDlg + + + + 0 + 0 + 208 + 326 + + + + C-evo + + + + + 12 + 29 + 25 + 25 + + + + + + + 177 + 6 + 25 + 25 + + + + + + + 43 + 29 + 25 + 25 + + + + + + + 178 + 145 + 12 + 12 + + + + + + + Cevo::ButtonB + QWidget +
Cevo/CevoButtonB.h
+
+ + Cevo::ButtonC + QWidget +
Cevo/CevoButtonC.h
+
+
+ +