diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e5f0bc..ed7565e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -154,6 +154,9 @@ set(PROJECT_SOURCES game/localplayer/UnitStat.cpp game/localplayer/UnitStat.h game/localplayer/UnitStat.ui + game/localplayer/MessgEx.cpp + game/localplayer/MessgEx.h + game/localplayer/MessgEx.ui ${TS_FILES} ) diff --git a/game/localplayer/MessgEx.cpp b/game/localplayer/MessgEx.cpp new file mode 100644 index 0000000..c6c37a4 --- /dev/null +++ b/game/localplayer/MessgEx.cpp @@ -0,0 +1,553 @@ +// 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 "MessgEx.h" +#include "ui_MessgEx.h" + +#include "Cevo/CevoScreenTools.h" +#include "Cevo/CevoTexture.h" +#include "Cevo/Protocol.h" +#include "ClientTools.h" +#include "Diagram.h" +#include "Term.h" +#include "Tribes.h" +#include "UnitStat.h" + +#include +#include +#include +#include + +#include "Dpi/DpiPixelPointer.h" + +#include +#include +#include + +namespace Cevo { +namespace MessgEx { + +namespace { +constexpr int LostUnitsPerLine = 6; +MessgExDlg *instance = nullptr; +} // namespace + +MessgExDlg::MessgExDlg(QWidget *parent) : BaseMessgDlg(parent), ui(new Ui::MessgExDlg) +{ + ui->setupUi(this); + iconKind = MessageIconKind::None; + centerTo = 0; + openSound.clear(); + + ui->button1->onClick = [this] { + setModalResult(Dpi::ModalResult::Ok); + close(); + }; + ui->button2->onClick = [this] { + if (kind == MessageKind::OkHelp) + Help::showNewContent(WindowMode::Submodal, helpKind, helpNo); + else if (kind == MessageKind::Model) + UnitStat::showNewContentOwnModel(WindowMode::Submodal, iconIndex); + else { + setModalResult(Dpi::ModalResult::Ignore); + close(); + } + }; + ui->button3->onClick = [this] { + setModalResult(Dpi::ModalResult::Cancel); + close(); + }; + ui->removeBtn->onClick = [this] { + setModalResult(Dpi::ModalResult::No); + close(); + }; +} + +MessgExDlg::~MessgExDlg() +{ + delete ui; +} + +void MessgExDlg::closeEvent(QCloseEvent *event) +{ + iconKind = MessageIconKind::None; + centerTo = 0; + BaseMessgDlg::closeEvent(event); +} + +void MessgExDlg::keyPressEvent(QKeyEvent *event) +{ + if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) { + setModalResult(Dpi::ModalResult::Ok); + close(); + } else if (event->key() == Qt::Key_Escape) { + if (ui->button3->isVisible()) { + setModalResult(Dpi::ModalResult::Cancel); + close(); + } else if (ui->button2->isVisible()) { + setModalResult(Dpi::ModalResult::Ignore); + close(); + } + } else { + BaseMessgDlg::keyPressEvent(event); + } +} + +void MessgExDlg::showEvent(QShowEvent *event) +{ + BaseMessgDlg::showEvent(event); + setWindowTitle(tr("Message")); + + if (iconKind == MessageIconKind::EnemyArmy) + Term::initAllEnemyModels(); + + const bool isMovie = Term::gameMode == cMovie; + ui->button1->setVisible(!isMovie); + ui->button2->setVisible(!isMovie && kind != MessageKind::Ok); + ui->button3->setVisible(!isMovie && kind == MessageKind::YesNoCancel); + ui->removeBtn->setVisible(!isMovie && kind == MessageKind::OkCancelRemove); + ui->eInput->setVisible(!isMovie && kind == MessageKind::Model); + + if (ui->button3->isVisible()) { + ui->button1->move(43, ui->button1->y()); + ui->button2->move(159, ui->button2->y()); + } else if (ui->button2->isVisible()) { + ui->button1->move(101, ui->button1->y()); + ui->button2->move(217, ui->button2->y()); + } else { + ui->button1->move(159, ui->button1->y()); + } + ui->removeBtn->move(width() - 38, ui->removeBtn->y()); + + // TODO: needs Phrases[] (StringTables.pas, not ported yet) - plain + // English literals until localization is ported. + switch (kind) { + case MessageKind::YesNo: + case MessageKind::YesNoCancel: + ui->button1->setCaption(tr("Yes")); + ui->button2->setCaption(tr("No")); + break; + case MessageKind::OkCancel: + case MessageKind::OkCancelRemove: + ui->button1->setCaption(tr("OK")); + ui->button2->setCaption(tr("Cancel")); + break; + default: + ui->button1->setCaption(tr("OK")); + ui->button2->setCaption(tr("Info")); + break; + } + ui->button3->setCaption(tr("Cancel")); + ui->removeBtn->setToolTip(tr("Delete saved game")); + + switch (iconKind) { + case MessageIconKind::Imp: + case MessageIconKind::Model: + case MessageIconKind::Age: + case MessageIconKind::PureIcon: + topSpace = 56; + break; + case MessageIconKind::BigIcon: + topSpace = 152; + break; + case MessageIconKind::EnemyShipComplete: + topSpace = 136; + break; + case MessageIconKind::Book: + topSpace = iconIndex >= 0 ? 84 : 47; + break; + case MessageIconKind::Tribe: + Tribes::tribe[static_cast(iconIndex)]->initAge(ClientTools::getAge(iconIndex)); + if (Tribes::tribe[static_cast(iconIndex)]->faceHGr) + topSpace = 64; + break; + case MessageIconKind::FullControl: + topSpace = 80; + break; + case MessageIconKind::Ship: + topSpace = 240; + break; + default: + topSpace = 0; + break; + } + + splitText(true); + int newHeight = 72 + Border + topSpace + lines * MessageLineSpacing; + if (isMovie) + newHeight -= 32; + if (kind == MessageKind::Model) + newHeight += 36; + if (iconKind == MessageIconKind::MyArmy || iconKind == MessageIconKind::EnemyArmy) { + if (Term::nLostArmy > LostUnitsPerLine * 6) + newHeight += 6 * 48; + else + newHeight += ((Term::nLostArmy - 1) / LostUnitsPerLine + 1) * 48; + } + + const Dpi::Monitor monitor = Dpi::Screen::primaryMonitor(); + int newLeft, newTop; + switch (centerTo) { + case 1: + newLeft = monitor.left() + (monitor.width() - width()) / 4; + newTop = monitor.top() + (monitor.height() - newHeight) * 2 / 3 - Term::MapCenterUp; + break; + case -1: + newLeft = monitor.left() + (monitor.width() - width()) / 4; + newTop = monitor.top() + (monitor.height() - newHeight) / 3 - Term::MapCenterUp; + break; + default: + newLeft = monitor.left() + (monitor.width() - width()) / 2; + newTop = monitor.top() + (monitor.height() - newHeight) / 2 - Term::MapCenterUp; + break; + } + setGeometry(newLeft, newTop, width(), newHeight); + + const auto children = findChildren(QString(), Qt::FindDirectChildrenOnly); + for (QWidget *child : children) + child->move(child->x(), newHeight - (34 + Border)); + if (kind == MessageKind::Model) + ui->eInput->move(ui->eInput->x(), newHeight - (76 + Border)); +} + +Dpi::ModalResult MessgExDlg::showModal() +{ + setWindowTitle(tr("Message")); + if (Term::gameMode == cMovie) { + movieCancelled = false; + show(); + QEventLoop loop; + QTimer timer; + timer.setSingleShot(true); + QObject::connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit); + // Poll for CancelMovie() every 10ms instead of the original's + // Application.ProcessMessages/Sleep(1) busy loop. + QTimer poll; + QObject::connect(&poll, &QTimer::timeout, &loop, [&] { + if (movieCancelled) + loop.quit(); + }); + poll.start(10); + timer.start(1500); + loop.exec(); + hide(); + return Dpi::ModalResult::Ok; + } + return Dpi::Form::showModal(); +} + +void MessgExDlg::cancelMovie() +{ + movieCancelled = true; +} + +void MessgExDlg::paintBook(Dpi::Canvas &canvas, int x, int y, QColor clPage, QColor clCover) +{ + constexpr int xScrewed = 77, yScrewed = 10, wScrewed = 43, hScrewed = 27; + const int width = xSizeBig; + const int height = ySizeBig; + std::vector> screwed; + QRect bookRect; + + if (iconIndex >= 0 && bigImp) { + const int xIcon = (iconIndex % 7) * xSizeBig; + const int yIcon = (iconIndex + Term::SystemIconLines * 7) / 7 * ySizeBig; + screwed.assign(static_cast(wScrewed * hScrewed), std::array{0, 0, 0, 0}); + auto cellAt = [&](int ix, int iy) -> std::array & { + return screwed[static_cast(iy * wScrewed + ix)]; + }; + + Dpi::PixelPointer srcPtr(&bigImp->image(), xIcon, yIcon); + for (int iy = 0; iy < height; ++iy) { + for (int ix = 0; ix < width; ++ix) { + double xR = ix * (37.0 + iy * 5.0 / height) / width; + int xDst = static_cast(xR); + xR -= xDst; + const double x1 = (120 - ix) * (120 - ix) - 10000.0; + double yR = iy * 18.0 / height + x1 * x1 / 4000000.0; + int yDst = static_cast(yR); + yR -= yDst; + + const QRgb srcColor = srcPtr.pixelRGB(); + for (int dx = 0; dx <= 1; ++dx) { + for (int dy = 0; dy <= 1; ++dy) { + double share = dx == 0 ? 1 - xR : xR; + share *= dy == 0 ? 1 - yR : yR; + if (xDst + dx < wScrewed && yDst + dy < hScrewed) { + auto &cell = cellAt(xDst + dx, yDst + dy); + cell[0] += share * qBlue(srcColor); + cell[1] += share * qGreen(srcColor); + cell[2] += share * qRed(srcColor); + cell[3] += share; + } + } + } + srcPtr.nextPixel(); + } + srcPtr.nextLine(); + } + + GraphicSetItem *bigBook = Templates ? Templates->searchByName(QStringLiteral("BigBook")) : nullptr; + bookRect = bigBook ? bigBook->boundsRect() : QRect(); + } else { + GraphicSetItem *smallBook = Templates ? Templates->searchByName(QStringLiteral("SmallBook")) : nullptr; + bookRect = smallBook ? smallBook->boundsRect() : QRect(); + } + + x -= bookRect.width() / 2; + + unshareBitmap(drawBuffer); + drawBufferEnsureSize(bookRect.width(), bookRect.height()); + drawBuffer.canvas().begin(); + // Replicates the already-painted background rather than reading it + // back from the live widget canvas (Qt can't read back mid-paintEvent + // the way the original's GDI-backed BitBltCanvas could) - fill()'s + // tiling phase doesn't depend on the destination offset, so this + // produces an identical result. + fill(drawBuffer.canvas(), 0, 0, bookRect.width(), bookRect.height()); + drawBuffer.canvas().end(); + + if (iconIndex >= 0) { + for (int iy = 0; iy < hScrewed; ++iy) { + for (int ix = 0; ix < wScrewed; ++ix) { + const auto &cell = screwed[static_cast(iy * wScrewed + ix)]; + if (cell[3] > 0.01) { + const int b = static_cast(cell[0] / cell[3]); + const int g = static_cast(cell[1] / cell[3]); + const int r = static_cast(cell[2] / cell[3]); + drawBuffer.image().setPixel(xScrewed + ix, yScrewed + iy, qRgb(r, g, b)); + } + } + } + } + + if (Templates) + imageOpBCC(drawBuffer, Templates->data, 0, 0, bookRect.left(), bookRect.top(), bookRect.width(), + bookRect.height(), colorToDelphi(clCover), colorToDelphi(clPage)); + + canvas.copyRect(QRect(x, y, bookRect.width(), bookRect.height()), drawBuffer.canvas(), + QRect(0, 0, bookRect.width(), bookRect.height())); +} + +void MessgExDlg::paintMyArmy(Dpi::Canvas &canvas) +{ + Q_UNUSED(canvas); + // Empty in the original too. +} + +void MessgExDlg::paintEnemyArmy(Dpi::Canvas &canvas) +{ + int ix = 0; + int iy = 0; + int unitsInLine = std::min(Term::nLostArmy, LostUnitsPerLine); + for (int emix = 0; emix < ClientTools::myRO->nEnemyModel; ++emix) { + const TModelInfo &enemyModel = (*ClientTools::myRO->EnemyModel)[emix]; + for (int count = 0; count < Term::lostArmy[static_cast(emix)]; ++count) { + const int x = width() / 2 + ix * 64 - unitsInLine * 32; + const int y = 26 + Border + topSpace + lines * MessageLineSpacing + iy * 48; + const Tribes::ModelPicture &mp = + Tribes::tribe[static_cast(enemyModel.Owner)]->modelPictureAt(enemyModel.mix); + if (mp.hGr) + sprite(canvas, *mp.hGr, x, y, 64, 48, mp.pix % 10 * 65 + 1, mp.pix / 10 * 49 + 1); + + ++ix; + if (ix == LostUnitsPerLine) { + ix = 0; + ++iy; + if (iy == 6) + return; + unitsInLine = std::min(Term::nLostArmy - LostUnitsPerLine * iy, LostUnitsPerLine); + } + } + } +} + +void MessgExDlg::paintEvent(QPaintEvent *event) +{ + if (iconKind == MessageIconKind::Imp && iconIndex == 27 && MainTexture) { // "YOU WIN" message + const QColor saveLight = MainTexture->colorTextLight; + const QColor saveShade = MainTexture->colorTextShade; + MainTexture->colorTextLight = Qt::black; + MainTexture->colorTextShade = colorFromDelphi(0x0FDBFF); + BaseMessgDlg::paintEvent(event); + MainTexture->colorTextLight = saveLight; + MainTexture->colorTextShade = saveShade; + } else { + BaseMessgDlg::paintEvent(event); + } + + QPainter painter(this); + Dpi::Canvas canvas; + canvas.bind(&painter); + + switch (iconKind) { + case MessageIconKind::Imp: + if (Imp[iconIndex].Kind == ikWonder) { + const int p1 = ClientTools::myRO->Wonder[iconIndex].EffectiveOwner; + unshareBitmap(drawBuffer); + drawBufferEnsureSize(xSizeBig + 16, ySizeBig + 16); + fill(drawBuffer.canvas(), 0, 0, xSizeBig + 16, ySizeBig + 16); + if (bigImp) + bitBltBitmap(drawBuffer, 8, 8, xSizeBig, ySizeBig, *bigImp, (iconIndex % 7) * xSizeBig, + (iconIndex + Term::SystemIconLines * 7) / 7 * ySizeBig); + glowFrame(drawBuffer, 8, 8, xSizeBig, ySizeBig, + p1 < 0 ? QColor(Qt::black) : Tribes::tribe[static_cast(p1)]->color); + canvas.copyRect(QRect(width() / 2 - 36, 16, xSizeBig + 16, ySizeBig + 16), drawBuffer.canvas(), + QRect(0, 0, xSizeBig + 16, ySizeBig + 16)); + } else { + Term::impImage(canvas, width() / 2 - 28, 24, iconIndex); + } + break; + case MessageIconKind::Age: + Term::impImage(canvas, width() / 2 - 28, 24, iconIndex == 0 ? -7 : 24 + iconIndex); + break; + case MessageIconKind::Model: { + const Tribes::ModelPicture &mp = Tribes::tribe[static_cast(ClientTools::me)]->modelPictureAt(iconIndex); + if (bigImp) + frameImage(canvas, *bigImp, width() / 2 - 28, 24, xSizeBig, ySizeBig, 0, 0); + if (mp.hGr) + sprite(canvas, *mp.hGr, width() / 2 - 32, 20, 64, 44, mp.pix % 10 * 65 + 1, mp.pix / 10 * 49 + 1); + break; + } + case MessageIconKind::Book: + if (MainTexture) + paintBook(canvas, width() / 2, 24, MainTexture->colorPage, MainTexture->colorCover); + break; + case MessageIconKind::Tribe: { + Tribes::Tribe &tribe = *Tribes::tribe[static_cast(iconIndex)]; + if (tribe.faceHGr) { + frame(canvas, width() / 2 - 32 - 1, 24 - 1, width() / 2 + 32, 24 + 48, Qt::black, Qt::black); + canvas.copyRect(QRect(width() / 2 - 32, 24, 64, 48), tribe.faceHGr->data.canvas(), + QRect(1 + tribe.facePix % 10 * 65, 1 + tribe.facePix / 10 * 49, 64, 48)); + } + break; + } + case MessageIconKind::PureIcon: + if (bigImp) + frameImage(canvas, *bigImp, width() / 2 - 28, 24, xSizeBig, ySizeBig, (iconIndex % 7) * xSizeBig, + (iconIndex / 7) * ySizeBig); + break; + case MessageIconKind::BigIcon: + if (bigImp) + frameImage(canvas, *bigImp, width() / 2 - 3 * 28, 32, xSizeBig * 3, ySizeBig * 3, + (iconIndex % 2) * 3 * xSizeBig, (iconIndex / 2) * 3 * ySizeBig); + break; + case MessageIconKind::EnemyShipComplete: { + unshareBitmap(drawBuffer); + drawBufferEnsureSize(140, 120); + fill(drawBuffer.canvas(), 0, 0, 140, 120); + GraphicSetItem *departed = Templates ? Templates->searchByName(QStringLiteral("StarshipDeparted")) : nullptr; + if (departed && Templates) + imageOpBCC(drawBuffer, Templates->data, 0, 0, departed->boundsRect().left(), departed->boundsRect().top(), + departed->boundsRect().width(), departed->boundsRect().height(), 0, colorToDelphi(Qt::white)); + canvas.copyRect(QRect((width() - 140) / 2, 24, 140, 120), drawBuffer.canvas(), QRect(0, 0, 140, 120)); + break; + } + case MessageIconKind::MyArmy: + paintMyArmy(canvas); + break; + case MessageIconKind::EnemyArmy: + paintEnemyArmy(canvas); + break; + case MessageIconKind::FullControl: + if (HGrSystem2) + sprite(canvas, *HGrSystem2, width() / 2 - 31, 24, 63, 63, 1, 281); + break; + case MessageIconKind::Ship: + Diagram::paintColonyShip(canvas, iconIndex, 17, width() - 34, 38); + break; + default: + break; + } + + if (ui->eInput->isVisible() && MainTexture) + editFrame(canvas, ui->eInput->geometry(), *MainTexture); + + canvas.unbind(); + + if (!openSound.isEmpty()) { + QTimer::singleShot(0, this, [this] { + // TODO: needs Sound.pas's Play()/Sounds[] item lookup (not + // ported yet). + openSound.clear(); + }); + } +} + +void setInstance(MessgExDlg *dlg) +{ + instance = dlg; +} + +void soundMessageEx(const QString &simpleText, const QString &soundItem) +{ + if (!instance) + return; + instance->messageText = simpleText; + instance->openSound = soundItem; + instance->kind = MessageKind::Ok; + instance->showModal(); +} + +void tribeMessage(int p, const QString &simpleText, const QString &soundItem) +{ + if (!instance) + return; + instance->openSound = soundItem; + instance->messageText = simpleText; + instance->kind = MessageKind::Ok; + instance->iconKind = MessageIconKind::Tribe; + instance->iconIndex = p; + instance->showModal(); +} + +Dpi::ModalResult simpleQuery(MessageKind queryKind, const QString &simpleText, const QString &soundItem) +{ + if (!instance) + return Dpi::ModalResult::None; + instance->messageText = simpleText; + instance->openSound = soundItem; + instance->kind = queryKind; + return instance->showModal(); +} + +void contextMessage(const QString &simpleText, const QString &soundItem, Help::LinkCategory contextKind, + int contextNo) +{ + if (!instance) + return; + instance->messageText = simpleText; + instance->openSound = soundItem; + instance->kind = MessageKind::OkHelp; + instance->helpKind = contextKind; + instance->helpNo = contextNo; + instance->showModal(); +} + +} // namespace MessgEx +} // namespace Cevo diff --git a/game/localplayer/MessgEx.h b/game/localplayer/MessgEx.h new file mode 100644 index 0000000..4d10c45 --- /dev/null +++ b/game/localplayer/MessgEx.h @@ -0,0 +1,109 @@ +// 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/CevoDrawDlg.h" +#include "Help.h" +#include "Messg.h" + +QT_BEGIN_NAMESPACE +namespace Ui { +class MessgExDlg; +} +QT_END_NAMESPACE + +namespace Cevo { +namespace MessgEx { + +enum class MessageIconKind { + None, + Imp, + Model, + Tribe, + Book, + Age, + PureIcon, + MyArmy, + EnemyArmy, + FullControl, + Ship, + BigIcon, + EnemyShipComplete, +}; + +// TMessgExDlg equivalent: the full-featured message/query dialog (icons, +// optional help/model-edit link buttons, a model-rename input, lost-army +// reports). UI built from MessgEx.ui (adapted from the original's +// MessgEx.lfm). +class MessgExDlg : public BaseMessgDlg { + Q_OBJECT +public: + explicit MessgExDlg(QWidget *parent = nullptr); + ~MessgExDlg() override; + + MessageKind kind = MessageKind::Ok; + int iconIndex = 0; + Help::LinkCategory helpKind = Help::LinkCategory::NoLink; + int helpNo = 0; + int centerTo = 0; + MessageIconKind iconKind = MessageIconKind::None; + QString openSound; + + Dpi::ModalResult showModal(); + void cancelMovie(); + +protected: + void paintEvent(QPaintEvent *event) override; + void showEvent(QShowEvent *event) override; + void closeEvent(QCloseEvent *event) override; + void keyPressEvent(QKeyEvent *event) override; + +private: + void paintBook(Dpi::Canvas &canvas, int x, int y, QColor clPage, QColor clCover); + void paintMyArmy(Dpi::Canvas &canvas); + void paintEnemyArmy(Dpi::Canvas &canvas); + + bool movieCancelled = false; + + Ui::MessgExDlg *ui; +}; + +// Equivalent of MessgEx.pas's free functions (SoundMessageEx/TribeMessage/ +// SimpleQuery/ContextMessage) - all need a live MessgExDlg instance +// (Term.pas's `MainScreen.MessgExDlg`), injected via setInstance() once +// Term.pas creates one. +void setInstance(MessgExDlg *dlg); +void soundMessageEx(const QString &simpleText, const QString &soundItem); +void tribeMessage(int p, const QString &simpleText, const QString &soundItem); +Dpi::ModalResult simpleQuery(MessageKind queryKind, const QString &simpleText, const QString &soundItem); +void contextMessage(const QString &simpleText, const QString &soundItem, Help::LinkCategory contextKind, + int contextNo); + +} // namespace MessgEx +} // namespace Cevo diff --git a/game/localplayer/MessgEx.ui b/game/localplayer/MessgEx.ui new file mode 100644 index 0000000..bb1890a --- /dev/null +++ b/game/localplayer/MessgEx.ui @@ -0,0 +1,114 @@ + + + + MessgExDlg + + + + 0 + 0 + 418 + 134 + + + + Message + + + + + 43 + 104 + 100 + 25 + + + + + + + 159 + 104 + 100 + 25 + + + + + + + 275 + 104 + 100 + 25 + + + + + + + 384 + 104 + 25 + 25 + + + + + + + 125 + 64 + 168 + 27 + + + + false + + + + + + Cevo::ButtonA + QWidget +
Cevo/CevoButtonA.h
+
+ + Cevo::ButtonB + QWidget +
Cevo/CevoButtonB.h
+
+ + Dpi::Edit + QLineEdit +
Dpi/DpiStdCtrls.h
+
+
+ +
diff --git a/game/localplayer/Term.cpp b/game/localplayer/Term.cpp index 164b2d8..bc3ac49 100644 --- a/game/localplayer/Term.cpp +++ b/game/localplayer/Term.cpp @@ -101,5 +101,10 @@ void initMyModel(int mix, bool final) ClientTools::myRO->Turn, false, final); } +int gameMode = 0; +std::array lostArmy{}; +int nLostArmy = 0; +std::function initAllEnemyModels = [] {}; + } // namespace Term } // namespace Cevo diff --git a/game/localplayer/Term.h b/game/localplayer/Term.h index 2373890..a83d667 100644 --- a/game/localplayer/Term.h +++ b/game/localplayer/Term.h @@ -135,5 +135,27 @@ extern std::function mainScreenContactRefused; void chooseModelPicture(int p, int mix, int code, int hash, int turn, bool forceNew, bool final); void initMyModel(int mix, bool final); +// Term.pas's `GameMode: Integer;` (cNewGame/cLoadGame/cMovie/... - which +// top-level mode the client is running in). NOT the same thing as +// Database::GameMode (a different, server-side enum of the same name in a +// different Pascal unit) - don't conflate the two. +extern int gameMode; + +// Term.pas's layout constant (MidPanelHeight - TopBarHeight) div 2; the +// two panel-size constants it derives from belong to Term's not-yet-ported +// main window layout, so only the resulting fixed value is pre-seeded here. +constexpr int MapCenterUp = 39; + +// Term.pas's `LostArmy`/`nLostArmy` (model-indexed lost-unit counts shown +// by MessgEx.pas's "army destroyed" report) - stay all-zero until Term.pas +// itself is ported and populates them for real. +extern std::array lostArmy; +extern int nLostArmy; + +// Term.pas's InitAllEnemyModels()/InitEnemyModel(): resolves a picture for +// every known enemy unit model so MessgEx.pas's "enemy army" report can +// draw them. Injection point (default no-op) until Term.pas is ported. +extern std::function initAllEnemyModels; + } // namespace Term } // namespace Cevo diff --git a/game/localplayer/UnitStat.cpp b/game/localplayer/UnitStat.cpp index 7f14377..872dd52 100644 --- a/game/localplayer/UnitStat.cpp +++ b/game/localplayer/UnitStat.cpp @@ -41,6 +41,8 @@ namespace Cevo { namespace UnitStat { +std::function showNewContentOwnModel = [](WindowMode, int) {}; + namespace { constexpr int xView = 71; @@ -174,6 +176,8 @@ UnitStatDlg::UnitStatDlg(QWidget *parent) : BufferedDrawDlg(parent), ui(new Ui:: }; ui->helpBtn->onClick = [this] { Help::showNewContent(WindowMode::Persistent, Help::LinkCategory::Model, 0); }; + UnitStat::showNewContentOwnModel = [this](WindowMode newMode, int mix) { this->showNewContentOwnModel(newMode, mix); }; + onShow = [this] { if (kind == UnitStatDialogKind::EnemyUnit || kind == UnitStatDialogKind::EnemyCityDefense || kind == UnitStatDialogKind::EnemyCity) { diff --git a/game/localplayer/UnitStat.h b/game/localplayer/UnitStat.h index 96638f7..50d3f53 100644 --- a/game/localplayer/UnitStat.h +++ b/game/localplayer/UnitStat.h @@ -32,6 +32,7 @@ #include "Cevo/Protocol.h" #include "IsoEngine.h" +#include #include QT_BEGIN_NAMESPACE @@ -43,6 +44,11 @@ QT_END_NAMESPACE namespace Cevo { namespace UnitStat { +// Mirrors `MainScreen.UnitStatDlg.ShowNewContent_OwnModel(NewMode, Mix)` - +// wired up to a real UnitStatDlg instance's showNewContentOwnModel() once +// one exists (Term.pas isn't ported yet). +extern std::function showNewContentOwnModel; + enum class UnitStatDialogKind { OwnModel, OwnUnit, EnemyModel, EnemyUnit, EnemyCityDefense, EnemyCity }; // TUnitStatDlg equivalent: a unit/model/city-defense stat card. UI built