From d65065644e44835c0f02b8f6e4b7fcceffcb19a6 Mon Sep 17 00:00:00 2001 From: Geoffray Levasseur Date: Tue, 3 Nov 2026 17:08:58 +0100 Subject: [PATCH] added select and its deps --- CMakeLists.txt | 3 + game/localplayer/Select.cpp | 1735 +++++++++++++++++++++++++++++++++ game/localplayer/Select.h | 184 ++++ game/localplayer/Select.ui | 101 ++ game/localplayer/Term.cpp | 7 + game/localplayer/Term.h | 19 + game/localplayer/Tribes.cpp | 2 + game/localplayer/UnitStat.cpp | 4 + game/localplayer/UnitStat.h | 2 + 9 files changed, 2057 insertions(+) create mode 100644 game/localplayer/Select.cpp create mode 100644 game/localplayer/Select.h create mode 100644 game/localplayer/Select.ui diff --git a/CMakeLists.txt b/CMakeLists.txt index f4eb559..cbbf61f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -160,6 +160,9 @@ set(PROJECT_SOURCES game/localplayer/CityScreen.cpp game/localplayer/CityScreen.h game/localplayer/CityScreen.ui + game/localplayer/Select.cpp + game/localplayer/Select.h + game/localplayer/Select.ui ${TS_FILES} ) diff --git a/game/localplayer/Select.cpp b/game/localplayer/Select.cpp new file mode 100644 index 0000000..385ca0e --- /dev/null +++ b/game/localplayer/Select.cpp @@ -0,0 +1,1735 @@ +// 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 "Select.h" +#include "ui_Select.h" + +#include "Cevo/CevoScreenTools.h" +#include "Cevo/CevoTexture.h" +#include "ClientTools.h" +#include "Global.h" +#include "Help.h" +#include "Inp.h" +#include "Term.h" +#include "Tribes.h" +#include "UnitStat.h" + +#include +#include +#include +#include +#include +#include + +#include +#include + +namespace Cevo { +namespace Select { + +namespace { + +constexpr int CityNameSpace = 127; +constexpr int ScrollBarWidth = 16; // matches Dpi::ScrollBar's fixed width + +bool mustChoose(ListKind kind) +{ + return kind == ListKind::Tribe || kind == ListKind::StealTech || kind == ListKind::Government; +} + +QString phrase(const QString &key) +{ + static const QHash table = { + {QStringLiteral("BTN_IMPRS"), QStringLiteral("Improvements")}, + {QStringLiteral("BTN_WONDERS"), QStringLiteral("Wonders")}, + {QStringLiteral("BTN_CLASSES"), QStringLiteral("Unit classes")}, + {QStringLiteral("BTN_PAGE"), QStringLiteral("Show events")}, + {QStringLiteral("BTN_SELECT"), QStringLiteral("Select player")}, + {QStringLiteral("FARTECH"), QStringLiteral("Research focus")}, + {QStringLiteral("TECHFOCUS"), QStringLiteral("Research focus: %1")}, + {QStringLiteral("TITLE_CITIES"), QStringLiteral("Cities")}, + {QStringLiteral("TITLE_EVENTS"), QStringLiteral("Events (%1)")}, + {QStringLiteral("SHIFTCLICK"), QStringLiteral("Shift+click for more information")}, + {QStringLiteral("CONSCRIPTS"), QStringLiteral("%1 (conscripts)")}, + {QStringLiteral("NATEXISTS"), QStringLiteral("%1 (already built elsewhere)")}, + {QStringLiteral("PRICECAT_ALLMODEL"), QStringLiteral("All unit designs")}, + {QStringLiteral("PRICECAT_ALLTECH"), QStringLiteral("All advances")}, + {QStringLiteral("NEXUS"), QStringLiteral("Galactic Nexus")}, + {QStringLiteral("NOFARTECH"), QStringLiteral("No research focus")}, + {QStringLiteral("INITUNIT"), QStringLiteral("New unit class")}, + {QStringLiteral("SCIENCEREPORT_EXTINCT"), QStringLiteral("%1 (extinct)")}, + {QStringLiteral("TITLE_PROJECT"), QStringLiteral("Choose project")}, + {QStringLiteral("TITLE_TECHSELECT"), QStringLiteral("Choose advance")}, + {QStringLiteral("TITLE_FARTECH"), QStringLiteral("Choose research focus")}, + {QStringLiteral("FRMILREP"), QStringLiteral("Military report")}, + {QStringLiteral("TITLE_EMODELS"), QStringLiteral("Enemy unit designs")}, + {QStringLiteral("TITLE_TRIBE"), QStringLiteral("Choose nation")}, + {QStringLiteral("TITLE_SCIENCE"), QStringLiteral("Science report")}, + {QStringLiteral("TITLE_CHOOSESHIPPART"), QStringLiteral("Choose ship part")}, + {QStringLiteral("TITLE_CHOOSETECH"), QStringLiteral("Choose advance")}, + {QStringLiteral("TITLE_CHOOSEMODEL"), QStringLiteral("Choose unit design")}, + {QStringLiteral("TITLE_GOV"), QStringLiteral("Choose government")}, + {QStringLiteral("TITLE_SPYMISSION"), QStringLiteral("Choose mission")}, + {QStringLiteral("TITLE_CITYNAME"), QStringLiteral("Rename city")}, + {QStringLiteral("TITLE_MODELNAME"), QStringLiteral("Rename unit design")}, + }; + const auto it = table.constFind(key); + return it != table.constEnd() ? *it : key; +} + +QString advanceName(int advance) +{ + return QStringLiteral("Advance #%1").arg(advance); +} + +QString impName(int iix) +{ + return QStringLiteral("Improvement #%1").arg(iix); +} + +QString governmentName(int gov) +{ + return QStringLiteral("Government #%1").arg(gov); +} + +QString spyMissionName(int mission) +{ + return QStringLiteral("Mission #%1").arg(mission); +} + +} // namespace + +void Layer::addLine(int code, int model, int modelSortValue) +{ + m_lines.push_back(Line{code, model, modelSortValue}); +} + +void Layer::sortModels() +{ + for (std::size_t i = 0; i + 1 < m_lines.size(); ++i) + for (std::size_t j = i + 1; j < m_lines.size(); ++j) + if (m_lines[i].modelSortValue > m_lines[j].modelSortValue) + std::swap(m_lines[i], m_lines[j]); +} + +void Layer::sortTechs() +{ + for (std::size_t i = 0; i + 1 < m_lines.size(); ++i) + if (m_lines[i].code < adMilitary) + for (std::size_t j = i + 1; j < m_lines.size(); ++j) + if (ClientTools::advValue[m_lines[i].code] * nAdv + m_lines[i].code < + ClientTools::advValue[m_lines[j].code] * nAdv + m_lines[j].code) + std::swap(m_lines[i], m_lines[j]); +} + +void Layer::sortCities() +{ + for (std::size_t i = 0; i + 1 < m_lines.size(); ++i) + for (std::size_t j = i + 1; j < m_lines.size(); ++j) + if (Tribes::cityName(ClientTools::myCity[m_lines[i].code].ID) > + Tribes::cityName(ClientTools::myCity[m_lines[j].code].ID)) + std::swap(m_lines[i], m_lines[j]); +} + +ListDlg::ListDlg(QWidget *parent) : FramedDlg(parent), ui(new Ui::ListDlg) +{ + ui->setupUi(this); + initButtons(); + + scrollBar = new PVScrollBar(this); + scrollBar->setBorderSpacing(36, 10, 34); + connect(scrollBar, &PVScrollBar::updated, this, [this] { + selected = -2; + smartUpdateContent(true); + }); + + popup = new QMenu(this); + + ui->layerImprovementsButton->setToolTip(phrase(QStringLiteral("BTN_IMPRS"))); + ui->layerWondersButton->setToolTip(phrase(QStringLiteral("BTN_WONDERS"))); + ui->layerClassesButton->setToolTip(phrase(QStringLiteral("BTN_CLASSES"))); + + ui->closeBtn->onClick = [this] { + closable = true; + close(); + }; + ui->layerImprovementsButton->onClick = [this] { modeBtnClicked(LayerIndex::Improvements); }; + ui->layerWondersButton->onClick = [this] { modeBtnClicked(LayerIndex::Wonders); }; + ui->layerClassesButton->onClick = [this] { modeBtnClicked(LayerIndex::Classes); }; + ui->toggleBtn->onClick = [this] { toggleBtnClicked(); }; + + onCloseQuery = [this] { return closable || !mustChoose(kind); }; + + onShow = [this] { + result = -1; + closable = false; + + if (kind == ListKind::Tribe) { + lineDistance = 21; + maxLines = (MainTexture->height() - (24 + titleHeight + NarrowFrame)) / lineDistance - 1; + } else { + lineDistance = 24; + maxLines = (MainTexture->height() - (24 + titleHeight + WideFrame)) / lineDistance - 1; + } + initLines(); + + multiPage = false; + for (std::size_t i = static_cast(LayerIndex::Wonders); i <= static_cast(LayerIndex::Classes); + ++i) + if (!layers[i].lines().empty()) { + multiPage = true; + break; + } + wideBottom = multiPage || kind == ListKind::Science || + (kind == ListKind::Project || kind == ListKind::Advance || kind == ListKind::FarAdvance); + if ((kind == ListKind::Advance && Term::myData->farTech != Term::adNone) || kind == ListKind::Models || + kind == ListKind::EnemyModels) { + scrollBar->setBorderSpacing(56, 10, 10); + titleHeight = WideFrame + 20; + } else { + scrollBar->setBorderSpacing(36, 10, 34); + titleHeight = WideFrame; + } + + dispLines = static_cast(layers[static_cast(LayerIndex::Improvements)].lines().size()); + for (const Layer &l : layers) + if (static_cast(l.lines().size()) > dispLines) + dispLines = static_cast(l.lines().size()); + if (dispLines > maxLines) + dispLines = maxLines; + innerHeight = lineDistance * (dispLines + 1) + 24; + const int newHeight = innerHeight + titleHeight + (wideBottom ? WideFrame : NarrowFrame); + + techNameSpace = 224; + switch (kind) { + case ListKind::Government: + innerWidth = 272; + break; + case ListKind::Cities: + case ListKind::CityEvents: + innerWidth = 640 - 18; + break; + case ListKind::Tribe: + innerWidth = static_cast(layers[static_cast(LayerIndex::Improvements)].lines().size()) > + maxLines + ? 280 + ScrollBarWidth + : 280; + break; + case ListKind::Science: + innerWidth = 104 - 33 + 15 + 8 + techNameSpace + 24 * nColumn + ScrollBarWidth; + if (innerWidth + 2 * SideFrame > 640) { + techNameSpace += 640 - innerWidth - 2 * SideFrame; + innerWidth = 640 - 2 * SideFrame; + } + break; + case ListKind::Advance: + case ListKind::FarAdvance: + innerWidth = 104 - 33 + 15 + 8 + techNameSpace + 24 + ScrollBarWidth; + break; + case ListKind::ChooseTech: + case ListKind::ChooseEnemyTech: + case ListKind::StealTech: + innerWidth = 104 - 33 + 15 + 8 + techNameSpace + ScrollBarWidth; + break; + default: + innerWidth = 363; + break; + } + resize(innerWidth + 2 * SideFrame, newHeight); + + ui->closeBtn->move(width() - 38, ui->closeBtn->y()); + captionLeft = ui->toggleBtn->x() + ui->toggleBtn->width(); + captionRight = ui->closeBtn->x(); + scrollBar->scrollBar()->setGeometry(SideFrame + innerWidth - ScrollBarWidth, titleHeight, ScrollBarWidth, + lineDistance * dispLines + 48); + + if (windowMode() == WindowMode::Modal) { + int newLeft; + if (kind == ListKind::Tribe) + newLeft = Dpi::Screen::primaryMonitor().left() + + (Dpi::Screen::primaryMonitor().width() - 800) * 3 / 8 + 130; + else + newLeft = Dpi::Screen::primaryMonitor().left() + (Dpi::Screen::primaryMonitor().width() - width()) / 2; + int newTop = Dpi::Screen::primaryMonitor().top() + (Dpi::Screen::primaryMonitor().height() - height()) / 2; + if (kind == ListKind::Project) + newTop += 48; + setGeometry(newLeft, newTop, width(), height()); + } + + ui->layerImprovementsButton->setVisible( + multiPage && !layers[static_cast(LayerIndex::Improvements)].lines().empty()); + ui->layerWondersButton->setVisible(multiPage && + !layers[static_cast(LayerIndex::Wonders)].lines().empty()); + ui->layerClassesButton->setVisible(multiPage && + !layers[static_cast(LayerIndex::Classes)].lines().empty()); + + if (kind == ListKind::Project) { + ui->layerImprovementsButton->move(width() / 2 - (12 + 29), height() - 31); + ui->layerImprovementsButton->setDown(true); + ui->layerWondersButton->move(width() / 2 - (12 - 29), height() - 31); + ui->layerWondersButton->setDown(false); + ui->layerClassesButton->move(width() / 2 - 12, height() - 31); + ui->layerClassesButton->setDown(false); + } + + layer = &layers[static_cast(LayerIndex::Improvements)]; + selected = -2; + scienceNation = -1; + scrollBar->init(static_cast(layer->lines().size()) - 1, dispLines); + + offscreenPaint(); + }; +} + +ListDlg::~ListDlg() +{ + delete ui; +} + +bool ListDlg::renameCity(int cix) +{ + const QString oldName = Tribes::cityName(ClientTools::myCity[cix].ID); + InputDlg dlg; + dlg.setWindowTitle(phrase(QStringLiteral("TITLE_CITYNAME"))); + dlg.editInput()->setText(oldName); + dlg.centerToRect(geometry()); + const Dpi::ModalResult result = dlg.showModal(); + if (result == Dpi::ModalResult::Ok && !dlg.editInput()->text().isEmpty() && + dlg.editInput()->text() != oldName) { + const int id = ClientTools::myCity[cix].ID; + // Simplified vs. the original: renames locally only (no + // cSetCityName network-relay command - Network.pas isn't ported, + // and the rename logic itself is purely client-side in the + // original too, see repo memory). + Tribes::tribe[static_cast(id >> 12)]->setCityName(id & 0xFFF, dlg.editInput()->text()); + return true; + } + return false; +} + +bool ListDlg::renameModel(int mix) +{ + const QString oldName = Tribes::tribe[static_cast(ClientTools::me)]->modelNameAt(mix); + InputDlg dlg; + dlg.setWindowTitle(phrase(QStringLiteral("TITLE_MODELNAME"))); + dlg.editInput()->setText(oldName); + dlg.centerToRect(geometry()); + const Dpi::ModalResult result = dlg.showModal(); + if (result == Dpi::ModalResult::Ok && !dlg.editInput()->text().isEmpty() && + dlg.editInput()->text() != oldName) { + Tribes::tribe[static_cast(ClientTools::me)]->modelNameAt(mix) = dlg.editInput()->text(); + return true; + } + return false; +} + +void ListDlg::initLines() +{ + auto tryAddImpLine = [this](Layer &targetLayer, int project) { + if (ClientTools::server(sSetCityProject - sExecute, ClientTools::me, cixProject, &project) >= rExecuted) + targetLayer.addLine(project); + }; + auto modelSortValue = [](const TModelInfo &modelInfo, bool mixPlayers = false) { + int result = (modelInfo.Domain + 1) << 28 - modelInfo.mix; + if (mixPlayers) + result -= Tribes::modelCode(modelInfo) << 16; + return result; + }; + std::array required{}; + std::function markPreqs = [&](int i) { + required[static_cast(i)] = 1; + if (ClientTools::myRO->Tech[i] < tsSeen) { + if (AdvPreq[i][0] >= 0) + markPreqs(AdvPreq[i][0]); + if (AdvPreq[i][1] >= 0) + markPreqs(AdvPreq[i][1]); + } + }; + + for (Layer &l : layers) { + l.lines().clear(); + l.firstShrinkedLine = std::numeric_limits::max(); + } + + switch (kind) { + case ListKind::Project: { + layers[static_cast(LayerIndex::Improvements)].addLine(cpImp + imTrGoods); + for (int i = nWonder; i < nImp; ++i) + if (Imp[i].Kind == ikCommon) + tryAddImpLine(layers[static_cast(LayerIndex::Improvements)], i + cpImp); + for (int i = nWonder; i < nImp; ++i) + if (Imp[i].Kind != ikCommon && Imp[i].Kind != ikTrGoods && + (ClientTools::myRO->NatBuilt[i] == 0 || Imp[i].Kind == ikNatLocal)) + tryAddImpLine(layers[static_cast(LayerIndex::Improvements)], i + cpImp); + for (int i = 0; i < Term::nCityType; ++i) + if (Term::myData->impOrder[i][0] >= 0) + layers[static_cast(LayerIndex::Improvements)].addLine(cpType + i); + + for (int i = 0; i < nWonder; ++i) + tryAddImpLine(layers[static_cast(LayerIndex::Wonders)], i + cpImp); + + for (int i = 0; i < ClientTools::myRO->nModel; ++i) { + bool ok; + if (ClientTools::myModel[i].Domain == dSea) { + ok = false; + for (int dx = -2; dx <= 2 && !ok; ++dx) + for (int dy = -2; dy <= 2 && !ok; ++dy) + if (std::abs(dx) + std::abs(dy) == 2) { + const int loc1 = ClientTools::dLoc(ClientTools::myCity[cixProject].Loc, dx, dy); + if (loc1 >= 0 && loc1 < ClientTools::g.lx * ClientTools::g.ly && + ((ClientTools::myMap[loc1] & fTerrain) == fShore || + (ClientTools::myMap[loc1] & fCanal) > 0)) + ok = true; + } + } else { + ok = true; + } + if (ok) { + if ((ClientTools::myModel[i].Status & Term::msObsolete) == 0) + layers[static_cast(LayerIndex::Classes)].addLine(i); + if (ClientTools::myModel[i].Status & Term::msAllowConscripts) + layers[static_cast(LayerIndex::Classes)].addLine(i + cpConscripts); + } + } + layers[static_cast(LayerIndex::Classes)].firstShrinkedLine = 0; + break; + } + case ListKind::Advance: { + nColumn = 1; + if (Term::myData->farTech != Term::adNone) { + required.fill(0); + markPreqs(Term::myData->farTech); + } + for (int i = 0; i < nAdv; ++i) { + int dummy = i; + if ((IsFutureTech(i) || ClientTools::myRO->Tech[i] < tsApplicable) && + ClientTools::server(sSetResearch - sExecute, ClientTools::me, i, &dummy) >= rExecuted && + (Term::myData->farTech == Term::adNone || required[static_cast(i)] > 0)) + layers[static_cast(LayerIndex::Improvements)].addLine(i); + } + layers[static_cast(LayerIndex::Improvements)].sortTechs(); + if (layers[static_cast(LayerIndex::Improvements)].lines().empty()) + layers[static_cast(LayerIndex::Improvements)].addLine(Term::adNexus); + bool ok = false; + for (int i = 0; i < nDomains && !ok; ++i) + if (Upgrade[i][0].Preq == preNone || ClientTools::myRO->Tech[Upgrade[i][0].Preq] >= tsApplicable) + ok = true; + if (ok) + layers[static_cast(LayerIndex::Improvements)].addLine(adMilitary); + break; + } + case ListKind::FarAdvance: { + layers[static_cast(LayerIndex::Improvements)].addLine(Term::adNone); + for (int i = 0; i < nAdv; ++i) + if (!IsFutureTech(i) && ClientTools::myRO->Tech[i] < tsApplicable && + (ClientTools::advValue[i] < 2000 || ClientTools::myRO->Tech[adMassProduction] > tsNA) && + (ClientTools::advValue[i] < 1000 || ClientTools::myRO->Tech[adScience] > tsNA)) + layers[static_cast(LayerIndex::Improvements)].addLine(i); + layers[static_cast(LayerIndex::Improvements)].sortTechs(); + break; + } + case ListKind::ChooseTech: { + for (int i = 0; i < nAdv; ++i) + if (!IsFutureTech(i) && ClientTools::myRO->Tech[i] >= tsApplicable && + ClientTools::myRO->EnemyReport[Term::dipMem[static_cast(ClientTools::me)].pContact] + ->Tech[i] < tsSeen) + layers[static_cast(LayerIndex::Improvements)].addLine(i); + layers[static_cast(LayerIndex::Improvements)].sortTechs(); + layers[static_cast(LayerIndex::Improvements)].addLine(adAll); + break; + } + case ListKind::ChooseEnemyTech: { + for (int i = 0; i < nAdv; ++i) + if (!IsFutureTech(i) && ClientTools::myRO->Tech[i] < tsSeen && + ClientTools::myRO->EnemyReport[Term::dipMem[static_cast(ClientTools::me)].pContact] + ->Tech[i] >= tsApplicable) + layers[static_cast(LayerIndex::Improvements)].addLine(i); + layers[static_cast(LayerIndex::Improvements)].sortTechs(); + layers[static_cast(LayerIndex::Improvements)].addLine(adAll); + break; + } + case ListKind::StealTech: { + for (int i = 0; i < nAdv; ++i) { + int dummy = i; + if (ClientTools::server(sStealTech - sExecute, ClientTools::me, i, &dummy) >= rExecuted) + layers[static_cast(LayerIndex::Improvements)].addLine(i); + } + layers[static_cast(LayerIndex::Improvements)].sortTechs(); + break; + } + case ListKind::Science: { + column[0] = ClientTools::me; + nColumn = 1; + for (int enemyType = 0; enemyType <= 2; ++enemyType) + for (int p1 = 0; p1 < nPl; ++p1) + if (ClientTools::myRO->EnemyReport[p1] && + (ClientTools::myRO->EnemyReport[p1]->TurnOfContact >= 0 || + ClientTools::myRO->EnemyReport[p1]->TurnOfCivilReport >= 0)) { + int testEnemyType; + if ((ClientTools::myRO->Alive & (1 << p1)) == 0) + testEnemyType = 2; + else if (ClientTools::myRO->EnemyReport[p1]->TurnOfCivilReport >= ClientTools::myRO->Turn - 1) + testEnemyType = 0; + else + testEnemyType = 1; + if (testEnemyType == enemyType) { + column[static_cast(nColumn)] = p1; + ++nColumn; + } + } + for (int i = 0; i < nAdv; ++i) { + bool ok = ClientTools::myRO->Tech[i] != tsNA || ClientTools::myRO->ResearchTech == i; + for (int j = 1; j < nColumn; ++j) { + const TEnemyReport &er = *ClientTools::myRO->EnemyReport[column[static_cast(j)]]; + if (er.Tech[i] != tsNA || (er.TurnOfCivilReport >= 0 && er.ResearchTech == i)) + ok = true; + } + if (ok) + layers[static_cast(LayerIndex::Improvements)].addLine(i); + } + layers[static_cast(LayerIndex::Improvements)].sortTechs(); + + bool militaryOk = ClientTools::myRO->ResearchTech == adMilitary; + for (int j = 1; j < nColumn && !militaryOk; ++j) { + const TEnemyReport &er = *ClientTools::myRO->EnemyReport[column[static_cast(j)]]; + if ((ClientTools::myRO->Alive & (1 << column[static_cast(j)])) && + er.TurnOfCivilReport >= 0 && er.ResearchTech == adMilitary) + militaryOk = true; + } + if (militaryOk) + layers[static_cast(LayerIndex::Improvements)].addLine(adMilitary); + break; + } + case ListKind::Cities: { + if (IsoEngine::clientMode < scContact) + for (int i = 0; i < ClientTools::myRO->nCity; ++i) + if (ClientTools::myCity[i].Loc >= 0) + layers[static_cast(LayerIndex::Improvements)].addLine(i); + layers[static_cast(LayerIndex::Improvements)].sortCities(); + layers[static_cast(LayerIndex::Improvements)].firstShrinkedLine = 0; + break; + } + case ListKind::CityEvents: { + for (int i = 0; i < ClientTools::myRO->nCity; ++i) + if (ClientTools::myCity[i].Loc >= 0 && + (static_cast(ClientTools::myCity[i].Flags) & Term::cityRepMask) != 0) + layers[static_cast(LayerIndex::Improvements)].addLine(i); + layers[static_cast(LayerIndex::Improvements)].sortCities(); + layers[static_cast(LayerIndex::Improvements)].firstShrinkedLine = 0; + break; + } + case ListKind::Models: { + for (int mix = 0; mix < ClientTools::myRO->nModel; ++mix) { + TModelInfo modelInfo{}; + MakeModelInfo(ClientTools::me, mix, ClientTools::myModel[mix], modelInfo); + layers[static_cast(LayerIndex::Improvements)].addLine(mix, 0, modelSortValue(modelInfo)); + } + layers[static_cast(LayerIndex::Improvements)].sortModels(); + layers[static_cast(LayerIndex::Improvements)].firstShrinkedLine = 0; + break; + } + case ListKind::ChooseModel: { + for (int mix = 3; mix < ClientTools::myRO->nModel; ++mix) { + TModelInfo modelInfo{}; + MakeModelInfo(ClientTools::me, mix, ClientTools::myModel[mix], modelInfo); + bool ok = true; + for (int emix = 0; emix < ClientTools::myRO->nEnemyModel; ++emix) + if ((*ClientTools::myRO->EnemyModel)[emix].Owner == + Term::dipMem[static_cast(ClientTools::me)].pContact && + IsSameModel((*ClientTools::myRO->EnemyModel)[emix], modelInfo)) { + ok = false; + break; + } + if (ok) + layers[static_cast(LayerIndex::Improvements)].addLine(mix, 0, modelSortValue(modelInfo)); + } + layers[static_cast(LayerIndex::Improvements)].sortModels(); + layers[static_cast(LayerIndex::Improvements)].addLine(mixAll); + layers[static_cast(LayerIndex::Improvements)].firstShrinkedLine = 0; + break; + } + case ListKind::ChooseEnemyModel: { + if (ClientTools::myRO->TestFlags & tfUncover) { + int dummy = 0; + ClientTools::server(sGetModels, ClientTools::me, 0, &dummy); + } + std::array modelOk{}; + for (int emix = 0; emix < ClientTools::myRO->nEnemyModel; ++emix) + modelOk[static_cast(emix)] = + (*ClientTools::myRO->EnemyModel)[emix].Owner == + Term::dipMem[static_cast(ClientTools::me)].pContact; + for (int mix = 0; mix < ClientTools::myRO->nModel; ++mix) { + TModelInfo modelInfo{}; + MakeModelInfo(ClientTools::me, mix, ClientTools::myModel[mix], modelInfo); + for (int emix = 0; emix < ClientTools::myRO->nEnemyModel; ++emix) + modelOk[static_cast(emix)] = + modelOk[static_cast(emix)] && + !IsSameModel((*ClientTools::myRO->EnemyModel)[emix], modelInfo); + } + for (int emix = 0; emix < ClientTools::myRO->nEnemyModel; ++emix) + if (modelOk[static_cast(emix)]) { + const int pContact = Term::dipMem[static_cast(ClientTools::me)].pContact; + if (!Tribes::tribe[static_cast(pContact)] + ->modelPictureAt((*ClientTools::myRO->EnemyModel)[emix].mix) + .hGr) + IsoEngine::invokeInitEnemyModel(emix); + layers[static_cast(LayerIndex::Improvements)].addLine( + emix, 0, modelSortValue((*ClientTools::myRO->EnemyModel)[emix])); + } + layers[static_cast(LayerIndex::Improvements)].sortModels(); + layers[static_cast(LayerIndex::Improvements)].addLine(mixAll); + layers[static_cast(LayerIndex::Improvements)].firstShrinkedLine = 0; + break; + } + case ListKind::EnemyModels: { + for (int i = 0; i < ClientTools::myRO->EnemyReport[playerView]->nModelCounted; ++i) { + int model = ClientTools::myRO->nEnemyModel - 1; + while (model >= 0 && !((*ClientTools::myRO->EnemyModel)[model].Owner == playerView && + (*ClientTools::myRO->EnemyModel)[model].mix == i)) + --model; + if (!Tribes::tribe[static_cast(playerView)]->modelPictureAt(i).hGr) + IsoEngine::invokeInitEnemyModel(model); + layers[static_cast(LayerIndex::Improvements)].addLine( + i, model, modelSortValue((*ClientTools::myRO->EnemyModel)[model])); + } + layers[static_cast(LayerIndex::Improvements)].sortModels(); + layers[static_cast(LayerIndex::Improvements)].firstShrinkedLine = 0; + break; + } + case ListKind::AllEnemyModels: { + if ((ClientTools::myRO->TestFlags & tfUncover) || ClientTools::g.Difficulty[ClientTools::me] == 0) { + int dummy = 0; + ClientTools::server(sGetModels, ClientTools::me, 0, &dummy); + } + for (int emix = 0; emix < ClientTools::myRO->nEnemyModel; ++emix) { + const TModelInfo &enemyModel = (*ClientTools::myRO->EnemyModel)[emix]; + if (enemyModel.mix >= 3 && (enemyModel.Kind == mkSelfDeveloped || enemyModel.Kind == mkEnemyDeveloped)) { + Tribes::ModelPicture &picture = + Tribes::tribe[static_cast(enemyModel.Owner)]->modelPictureAt(enemyModel.mix); + if (!picture.hGr) + IsoEngine::invokeInitEnemyModel(emix); + bool ok = true; + if (Term::mainScreenNamesChecked) { + for (Line &existing : layers[static_cast(LayerIndex::Improvements)].lines()) { + const int model = existing.code; + const TModelInfo &testModel = (*ClientTools::myRO->EnemyModel)[model]; + Tribes::ModelPicture &testPicture = + Tribes::tribe[static_cast(testModel.Owner)]->modelPictureAt(testModel.mix); + if (picture.hGr == testPicture.hGr && picture.pix == testPicture.pix && + ClientTools::modelHash(enemyModel) == ClientTools::modelHash(testModel)) { + existing.model = 1; + ok = false; + break; + } + } + } + if (ok) + layers[static_cast(LayerIndex::Improvements)].addLine( + emix, 0, modelSortValue(enemyModel, true)); + } + } + layers[static_cast(LayerIndex::Improvements)].sortModels(); + layers[static_cast(LayerIndex::Improvements)].firstShrinkedLine = 0; + break; + } + case ListKind::Tribe: { + // Simplified: the original lists every predefined civilization + // name bundled with the game (TribeNames, a static resource list + // not ported); lists the nPl in-game nation slots instead. + for (int i = 0; i < nPl; ++i) + layers[static_cast(LayerIndex::Improvements)].addLine(i); + break; + } + case ListKind::ShipPart: { + layers[static_cast(LayerIndex::Improvements)].lines().clear(); + for (int i = 0; i < nShipPart; ++i) + if (ClientTools::myRO->Ship[ClientTools::me].Parts[i] > 0) + layers[static_cast(LayerIndex::Improvements)].addLine(i); + break; + } + case ListKind::EnemyShipPart: { + layers[static_cast(LayerIndex::Improvements)].lines().clear(); + const int pContact = Term::dipMem[static_cast(ClientTools::me)].pContact; + for (int i = 0; i < nShipPart; ++i) + if (ClientTools::myRO->Ship[pContact].Parts[i] > 0) + layers[static_cast(LayerIndex::Improvements)].addLine(i); + break; + } + case ListKind::Government: { + for (int i = 1; i < nGov; ++i) + if (GovPreq[i] != preNA && (GovPreq[i] == preNone || ClientTools::myRO->Tech[GovPreq[i]] >= tsApplicable)) + layers[static_cast(LayerIndex::Improvements)].addLine(i); + break; + } + case ListKind::Mission: { + for (int i = 0; i < nSpyMission; ++i) + layers[static_cast(LayerIndex::Improvements)].addLine(i); + break; + } + default: + break; + } + + if (kind == ListKind::Project && + static_cast(layers[static_cast(LayerIndex::Improvements)].lines().size() + + layers[static_cast(LayerIndex::Wonders)].lines().size() + + layers[static_cast(LayerIndex::Classes)].lines().size()) <= maxLines) { + Layer &improvements = layers[static_cast(LayerIndex::Improvements)]; + Layer &wonders = layers[static_cast(LayerIndex::Wonders)]; + Layer &classes = layers[static_cast(LayerIndex::Classes)]; + for (const Line &l : wonders.lines()) + improvements.addLine(l.code, l.model, l.modelSortValue); + wonders.lines().clear(); + improvements.firstShrinkedLine = static_cast(improvements.lines().size()); + for (const Line &l : classes.lines()) + improvements.addLine(l.code, l.model, l.modelSortValue); + classes.lines().clear(); + } +} + +int ListDlg::onlyChoice(ListKind testKind) +{ + kind = testKind; + initLines(); + const auto &lines = layers[static_cast(LayerIndex::Improvements)].lines(); + if (lines.empty()) + return -2; + if (lines.size() > 1) + return -1; + return lines[0].code; +} + +void ListDlg::paintLine(Dpi::Canvas &ca, int l, bool nonText, bool lit, bool toWidget) +{ + if (!MainTexture || !HGrSystem) + return; + + auto displayProject = [this](int x, int y, int pix) { + if ((pix & (cpType | cpImp)) == 0) { + const Tribes::ModelPicture &mp = + Tribes::tribe[static_cast(ClientTools::me)]->modelPictureAt(pix & cpIndex); + if (mp.hGr) + sprite(offscreen.canvas(), *mp.hGr, x, y, 64, 48, mp.pix % 10 * 65 + 1, mp.pix / 10 * 49 + 1); + } else { + frame(offscreen.canvas(), x + 15, y + 14, x + 16 + Term::xSizeSmall, y + 15 + Term::ySizeSmall, + MainTexture->colorBevelLight, MainTexture->colorBevelShade); + if (!Term::smallImp) + return; + if ((pix & cpType) == 0) { + if ((pix & cpIndex) == imPalace && ClientTools::myRO->Government != gAnarchy) + bitBltBitmap(offscreen, x + 16, y + 15, Term::xSizeSmall, Term::ySizeSmall, *Term::smallImp, + (ClientTools::myRO->Government - 1) * Term::xSizeSmall, Term::ySizeSmall); + else + bitBltBitmap(offscreen, x + 16, y + 15, Term::xSizeSmall, Term::ySizeSmall, *Term::smallImp, + (pix & cpIndex) % 7 * Term::xSizeSmall, + ((pix & cpIndex) + Term::SystemIconLines * 7) / 7 * Term::ySizeSmall); + } else { + bitBltBitmap(offscreen, x + 16, y + 15, Term::xSizeSmall, Term::ySizeSmall, *Term::smallImp, + (3 + (pix & cpIndex)) * Term::xSizeSmall, 0); + } + } + }; + + auto replaceText = [this, &ca, toWidget](int x, int y, int color, const QString &s) { + if (toWidget) { + const int textWidth = biColorTextWidth(ca, s); + int textHeight = ca.textExtent(s).height(); + if (y + textHeight >= titleHeight + innerHeight) + textHeight = titleHeight + innerHeight - y; + fill(ca, x, y, textWidth, textHeight, (MainTexture->width() - width()) / 2, + (MainTexture->height() - height()) / 2); + } + loweredTextOut(ca, color, *MainTexture, x, y, s); + }; + + const int lix = layer->lines()[static_cast(scrollBar->position() + l)].code; + const int y0 = 2 + (l + 1) * lineDistance; + + int ofs; + if (scrollBar->position() + l >= layer->firstShrinkedLine) + ofs = ((scrollBar->position() + l - layer->firstShrinkedLine) & 1) * 33; + else + ofs = 33; + + if (kind == ListKind::Cities || kind == ListKind::CityEvents) { + const TCity &city = ClientTools::myCity[lix]; + int x = 104 - 76; + int y = y0; + if (toWidget) { + x += SideFrame; + y += titleHeight; + } + const int textColor = lit ? colorToDelphi(MainTexture->colorLitText) : -1; + QString s = Tribes::cityName(city.ID); + while (biColorTextWidth(ca, s) > CityNameSpace && s.length() > 1) + s.chop(1); + replaceText(x + 15, y, textColor, s); + + if (nonText) { + Dpi::Canvas &canvas = offscreen.canvas(); + canvas.brush().setStyle(Qt::SolidPattern); + canvas.brush().setColor(Qt::black); + canvas.fillRect(QRect(x - 4 - 11, y + 1, 24, 20)); + canvas.brush().setColor(Qt::white); + canvas.fillRect(QRect(x - 4 - 12, y, 24, 20)); + canvas.brush().setStyle(Qt::NoBrush); + canvas.font().setColor(Qt::black); + const QString sizeText = QString::number(city.Size); + canvas.textOut(x - 4 - canvas.textWidth(sizeText) / 2, y, sizeText); + } + + if (kind == ListKind::CityEvents) { + int first = -1; + for (int j = 0; j < Term::nCityEventPriority; ++j) + if ((static_cast(city.Flags) & Term::cityRepMask & + static_cast(Term::CityEventPriority[static_cast(j)])) != 0) { + first = j; + break; + } + if (first >= 0) { + int i = 0; + std::uint32_t test = 1; + while (test < static_cast(Term::CityEventPriority[static_cast(first)])) { + ++i; + test += test; + } + const QString s2 = Term::cityEventName(i); + replaceText(x + (CityNameSpace + 4 + 40 + 18 + 8), y, textColor, s2); + if (nonText) { + sprite(offscreen.canvas(), *HGrSystem, 105 - 76 + CityNameSpace + 4 + 40, y0 + 1, 18, 18, + 1 + i % 3 * 19, 1 + i / 3 * 19); + int xx = innerWidth - 26; + for (int j = Term::nCityEventPriority - 1; j > first; --j) + if ((static_cast(city.Flags) & Term::cityRepMask & + static_cast(Term::CityEventPriority[static_cast(j)])) != + 0) { + int ii = 0; + std::uint32_t t = 1; + while (t < static_cast(Term::CityEventPriority[static_cast(j)])) { + ++ii; + t += t; + } + if (Term::CityEventPriority[static_cast(j)] == chNoGrowthWarning && + city.Built[imAqueduct] > 0) + ii = 17; + sprite(offscreen.canvas(), *HGrSystem, xx, y0 + 1, 18, 18, 1 + ii % 3 * 19, + 1 + ii / 3 * 19); + xx -= 20; + } + } + } + } else { + TCityReportNew cityReport{}; + cityReport.HypoTiles = -1; + cityReport.HypoTaxRate = -1; + cityReport.HypoLuxuryRate = -1; + ClientTools::server(sGetCityReportNew, ClientTools::me, lix, &cityReport); + int trueFood = city.Food; + int trueProd = city.Prod; + if (Term::supervising) { + trueFood -= cityReport.FoodSurplus; + if (trueFood < 0) + trueFood = 0; + trueProd -= cityReport.Production; + if (trueProd < 0) + trueProd = 0; + } + + QString disorder; + if (city.Flags & chCaptured) + disorder = Term::cityEventName(14); + else if (cityReport.HappinessBalance < 0) + disorder = Term::cityEventName(0); + if (!disorder.isEmpty()) { + if (nonText) { + darkGradient(offscreen.canvas(), 99 + 31 + CityNameSpace + 4, y0 + 2, 131, 3); + offscreen.canvas().font().assign(UniFont[static_cast(FontType::Small)]); + risedTextOut(offscreen.canvas(), 103 + CityNameSpace + 4 + 31, y0 + 1, disorder); + offscreen.canvas().font().assign(UniFont[static_cast(FontType::Normal)]); + } + } else { + QString s2 = QString::number(cityReport.Science); + replaceText(x + CityNameSpace + 4 + 370 + 48 - biColorTextWidth(ca, s2), y, textColor, s2); + s2 = QString::number(cityReport.Production); + replaceText(x + CityNameSpace + 4 + 132 - biColorTextWidth(ca, s2), y, textColor, s2); + if (nonText) { + sprite(offscreen.canvas(), *HGrSystem, x + CityNameSpace + 4 + 370 + 48 + 1, y + 6, 10, 10, 77, + 126); + sprite(offscreen.canvas(), *HGrSystem, x + CityNameSpace + 4 + 132 + 1, y + 6, 10, 10, 88, 115); + } + } + QString s3 = QString::number(ClientTools::cityTaxBalance(lix, cityReport)); + replaceText(x + CityNameSpace + 4 + 370 - biColorTextWidth(ca, s3), y, textColor, s3); + if (nonText) { + sprite(offscreen.canvas(), *HGrSystem, x + CityNameSpace + 4 + 370 + 1, y + 6, 10, 10, 132, 115); + + const bool canGrow = + city.Size < MaxCitySize && ClientTools::myRO->Government != gFuture && + cityReport.FoodSurplus > 0 && + (city.Size < NeedAqueductSize || (city.Built[imAqueduct] == 1 && city.Size < NeedSewerSize) || + city.Built[imSewer] == 1); + const int growth = ClientTools::cutCityFoodSurplus( + cityReport.FoodSurplus, ClientTools::myRO->Government != gAnarchy && (city.Flags & chCaptured) == 0, + ClientTools::myRO->Government, city.Size); + paintRelativeProgressBar(offscreen.canvas(), 1, x + 15 + CityNameSpace + 4, y + 7, 68, trueFood, + growth, cityReport.Storage, canGrow, *MainTexture); + + if (city.Project != cpImp + imTrGoods) { + displayProject(ofs + 104 - 76 + x - 28 + CityNameSpace + 4 + 206 - 60, y0 - 15, city.Project); + + int productionGrowth = cityReport.Production; + if (productionGrowth < 0 || ClientTools::myRO->Government == gAnarchy || + (city.Flags & chCaptured)) + productionGrowth = 0; + paintRelativeProgressBar(offscreen.canvas(), 4, x + CityNameSpace + 4 + 304 - 60 + 9, y + 7, 68, + trueProd, productionGrowth, cityReport.ProjectCost, true, *MainTexture); + } + } + } + } else if (kind == ListKind::Models || kind == ListKind::EnemyModels) { + int x = 104; + int y = y0; + if (toWidget) { + x += SideFrame; + y += titleHeight; + } + const int textColor = lit ? colorToDelphi(MainTexture->colorLitText) : -1; + QString s; + int available = 0; + if (kind == ListKind::Models) { + for (int j = 0; j < ClientTools::myRO->nUn; ++j) + if (ClientTools::myUn[j].Loc >= 0 && ClientTools::myUn[j].mix == lix) + ++available; + s = Term::mainScreenNamesChecked + ? Tribes::tribe[static_cast(ClientTools::me)]->modelNameAt(lix) + : Tribes::tribe[static_cast(ClientTools::me)] + ->tPhrase(QStringLiteral("GENMODEL")) + .arg(lix); + if (nonText) + displayProject(8 + ofs, y0 - 15, lix); + } else { + available = ClientTools::myRO->EnemyReport[playerView]->UnCount[lix]; + s = Term::mainScreenNamesChecked + ? Tribes::tribe[static_cast(playerView)]->modelNameAt(lix) + : Tribes::tribe[static_cast(playerView)] + ->tPhrase(QStringLiteral("GENMODEL")) + .arg(lix); + if (nonText) { + const Tribes::ModelPicture &mp = Tribes::tribe[static_cast(playerView)]->modelPictureAt(lix); + if (mp.hGr) + sprite(offscreen.canvas(), *mp.hGr, 8 + ofs, y0 - 15, 64, 48, mp.pix % 10 * 65 + 1, + mp.pix / 10 * 49 + 1); + } + } + if (available > 0) + replaceText(x + 32 - biColorTextWidth(ca, QString::number(available)), y, textColor, + QString::number(available)); + replaceText(x + 40, y, textColor, s); + } else { + QString s; + switch (kind) { + case ListKind::AllEnemyModels: + case ListKind::ChooseEnemyModel: + if (lix == mixAll) { + s = phrase(QStringLiteral("PRICECAT_ALLMODEL")); + } else { + const TModelInfo &mox = (*ClientTools::myRO->EnemyModel)[lix]; + if (Term::mainScreenNamesChecked) { + s = Tribes::tribe[static_cast(mox.Owner)]->modelNameAt(mox.mix); + if (kind == ListKind::AllEnemyModels && + layers[static_cast(LayerIndex::Improvements)] + .lines()[static_cast(scrollBar->position() + l)] + .model == 0) + s = Tribes::tribe[static_cast(mox.Owner)]->tPhrase(QStringLiteral("OWNED")).arg(s); + } else { + s = Tribes::tribe[static_cast(mox.Owner)]->tPhrase(QStringLiteral("GENMODEL")).arg(mox.mix); + } + if (nonText) { + const Tribes::ModelPicture &mp = Tribes::tribe[static_cast(mox.Owner)]->modelPictureAt(mox.mix); + if (mp.hGr) + sprite(offscreen.canvas(), *mp.hGr, 8 + ofs, y0 - 15, 64, 48, mp.pix % 10 * 65 + 1, + mp.pix / 10 * 49 + 1); + } + } + break; + case ListKind::ChooseModel: + if (lix == mixAll) { + s = phrase(QStringLiteral("PRICECAT_ALLMODEL")); + } else { + s = Tribes::tribe[static_cast(ClientTools::me)]->modelNameAt(lix); + if (nonText) + displayProject(8 + ofs, y0 - 15, lix); + } + break; + case ListKind::Project: { + if (lix & cpType) { + s = impName(lix & cpIndex); // CITYTYPE phrase not ported; reuses imp placeholder naming + } else if ((lix & cpImp) == 0) { + s = Tribes::tribe[static_cast(ClientTools::me)]->modelNameAt(lix & cpIndex); + if (lix & cpConscripts) + s = phrase(QStringLiteral("CONSCRIPTS")).arg(s); + } else { + s = impName(lix & cpIndex); + const int iix = lix & cpIndex; + if (((Imp[iix].Kind == ikNatLocal || Imp[iix].Kind == ikNatGlobal) && + ClientTools::myRO->NatBuilt[iix] > 0) || + ((iix == imPower || iix == imHydro || iix == imNuclear) && + ClientTools::myCity[cixProject].Built[imPower] + ClientTools::myCity[cixProject].Built[imHydro] + + ClientTools::myCity[cixProject].Built[imNuclear] > + 0)) + s = phrase(QStringLiteral("NATEXISTS")).arg(s); + } + if (nonText) + displayProject(8 + ofs, y0 - 15, lix); + break; + } + case ListKind::Advance: + case ListKind::FarAdvance: + case ListKind::Science: + case ListKind::ChooseTech: + case ListKind::ChooseEnemyTech: + case ListKind::StealTech: { + if (lix == adAll) { + s = phrase(QStringLiteral("PRICECAT_ALLTECH")); + } else { + if (lix == Term::adNexus) + s = phrase(QStringLiteral("NEXUS")); + else if (lix == Term::adNone) + s = phrase(QStringLiteral("NOFARTECH")); + else if (lix == adMilitary) + s = phrase(QStringLiteral("INITUNIT")); + else { + s = advanceName(lix); + if (kind == ListKind::Advance && IsFutureTech(lix)) { + if (ClientTools::myRO->Tech[lix] < tsApplicable) + s += QStringLiteral(" 1"); + else + s += QStringLiteral(" %1").arg(ClientTools::myRO->Tech[lix] + 1); + } + } + if (biColorTextWidth(ca, s) > techNameSpace + 8) { + do { + s.chop(1); + } while (biColorTextWidth(ca, s) > techNameSpace + 5 && s.length() > 1); + s += QLatin1Char('.'); + } + + if (nonText) { + if (lix == Term::adNexus) { + frame(offscreen.canvas(), 8 + 16 - 1, y0 - 1, 8 + 16 + 36, y0 + 20, + MainTexture->colorBevelLight, MainTexture->colorBevelShade); + dump(offscreen, *HGrSystem, 8 + 16, y0, 36, 20, 223, 295); + } else if (lix == Term::adNone) { + frame(offscreen.canvas(), 8 + 16 - 1, y0 - 1, 8 + 16 + 36, y0 + 20, + MainTexture->colorBevelLight, MainTexture->colorBevelShade); + dump(offscreen, *HGrSystem, 8 + 16, y0, 36, 20, 260, 295); + } else if (lix == adMilitary) { + frame(offscreen.canvas(), 8 + 16 - 1, y0 - 1, 8 + 16 + 36, y0 + 20, + MainTexture->colorBevelLight, MainTexture->colorBevelShade); + dump(offscreen, *HGrSystem, 8 + 16, y0, 36, 20, 38, 295); + } else { + frame(offscreen.canvas(), 8 + 16 - 1, y0 - 1, 8 + 16 + Term::xSizeSmall, y0 + Term::ySizeSmall, + MainTexture->colorBevelLight, MainTexture->colorBevelShade); + if (Term::advIcon[static_cast(lix)] < 84) { + if (Term::smallImp) + bitBltBitmap(offscreen, 8 + 16, y0, Term::xSizeSmall, Term::ySizeSmall, + *Term::smallImp, + (Term::advIcon[static_cast(lix)] + Term::SystemIconLines * 7) % + 7 * Term::xSizeSmall, + (Term::advIcon[static_cast(lix)] + Term::SystemIconLines * 7) / + 7 * Term::ySizeSmall); + } else { + dump(offscreen, *HGrSystem, 8 + 16, y0, 36, 20, + 1 + (Term::advIcon[static_cast(lix)] - 84) % 8 * 37, + 295 + (Term::advIcon[static_cast(lix)] - 84) / 8 * 21); + } + const int j = ClientTools::advValue[lix] / 1000; + bitBltBitmap(offscreen, 8 + 16 - 4, y0 + 2, 14, 14, HGrSystem->mask, 127 + j * 15, 85, + RasterOp::And); + sprite(offscreen.canvas(), *HGrSystem, 8 + 16 - 5, y0 + 1, 14, 14, 127 + j * 15, 85); + } + } + } + + if (nonText && (kind == ListKind::Advance || kind == ListKind::Science)) { + for (int j = 0; j < nColumn; ++j) { + int icon; + int futureCount = 0; + if (j == 0) { + if (lix == ClientTools::myRO->ResearchTech) { + int cost = 0; + ClientTools::server(sGetTechCost, ClientTools::me, 0, &cost); + icon = 4 + (cost != 0 ? ClientTools::myRO->Research * 4 / cost : 0); + if (icon > 4 + 3) + icon = 4 + 3; + } else if (lix >= adMilitary) { + icon = -1; + } else if (IsFutureTech(lix)) { + icon = -1; + futureCount = ClientTools::myRO->Tech[lix]; + } else if (ClientTools::myRO->Tech[lix] == tsSeen) { + icon = 1; + } else if (ClientTools::myRO->Tech[lix] >= tsApplicable) { + icon = 2; + } else { + icon = -1; + } + } else { + const TEnemyReport &er = *ClientTools::myRO->EnemyReport[column[static_cast(j)]]; + if ((ClientTools::myRO->Alive & (1 << column[static_cast(j)])) && + er.TurnOfCivilReport >= 0 && lix == er.ResearchTech && + (lix == adMilitary || IsFutureTech(lix) || er.Tech[lix] < tsApplicable)) { + icon = 4 + er.ResearchDone / 25; + if (icon > 4 + 3) + icon = 4 + 3; + } else if (lix == adMilitary) { + icon = -1; + } else if (IsFutureTech(lix)) { + icon = -1; + futureCount = er.Tech[lix]; + } else if (er.Tech[lix] >= tsApplicable) { + icon = 2; + } else if (er.Tech[lix] == tsSeen) { + icon = 1; + } else { + icon = -1; + } + } + if (icon >= 0) + sprite(offscreen.canvas(), *HGrSystem, 104 - 33 + 15 + 3 + techNameSpace + 24 * j, y0 + 3, 14, + 14, 67 + icon * 15, 85); + else if (kind == ListKind::Science && futureCount > 0) { + const QString number = QString::number(futureCount); + risedTextOut(ca, 104 - 33 + 15 + 10 + techNameSpace + 24 * j - biColorTextWidth(ca, number) / 2, + y0, number); + } + } + } + break; + } + case ListKind::Tribe: + s = QStringLiteral("Nation #%1").arg(lix + 1); + break; + case ListKind::ShipPart: + s = QStringLiteral("%1 (%2)") + .arg(impName(imShipComp + lix)) + .arg(ClientTools::myRO->Ship[ClientTools::me].Parts[lix]); + if (nonText) + displayProject(8 + ofs, y0 - 15, cpImp + imShipComp + lix); + break; + case ListKind::EnemyShipPart: + s = QStringLiteral("%1 (%2)") + .arg(impName(imShipComp + lix)) + .arg(ClientTools::myRO + ->Ship[Term::dipMem[static_cast(ClientTools::me)].pContact] + .Parts[lix]); + if (nonText) + displayProject(8 + ofs, y0 - 15, cpImp + imShipComp + lix); + break; + case ListKind::Government: + s = governmentName(lix); + if (nonText && Term::smallImp) { + frame(offscreen.canvas(), 8 + 16 - 1, y0 - 15 + 14, 8 + 16 + Term::xSizeSmall, + y0 - 15 + 15 + Term::ySizeSmall, MainTexture->colorBevelLight, MainTexture->colorBevelShade); + bitBltBitmap(offscreen, 8 + 16, y0 - 15 + 15, Term::xSizeSmall, Term::ySizeSmall, *Term::smallImp, + (lix - 1) * Term::xSizeSmall, Term::ySizeSmall); + } + break; + case ListKind::Mission: + s = spyMissionName(lix); + break; + default: + break; + } + + int x; + switch (kind) { + case ListKind::Tribe: + case ListKind::Mission: + x = static_cast(layers[static_cast(LayerIndex::Improvements)].lines().size()) > maxLines + ? (innerWidth - ScrollBarWidth) / 2 - biColorTextWidth(ca, s) / 2 + : innerWidth / 2 - biColorTextWidth(ca, s) / 2; + break; + case ListKind::Advance: + case ListKind::FarAdvance: + case ListKind::Science: + case ListKind::ChooseTech: + case ListKind::ChooseEnemyTech: + case ListKind::StealTech: + case ListKind::Government: + x = 104 - 33; + break; + case ListKind::AllEnemyModels: + x = 104; + break; + default: + x = 104 + 15; + break; + } + int y = y0; + if (toWidget) { + x += SideFrame; + y += titleHeight; + } + const int textColor = lit ? colorToDelphi(MainTexture->colorLitText) : -1; + replaceText(x, y, textColor, s); + } +} + +void ListDlg::offscreenPaint() +{ + switch (kind) { + case ListKind::Cities: + setWindowTitle( + Tribes::tribe[static_cast(ClientTools::me)]->tPhrase(QStringLiteral("TITLE_CITIES"))); + break; + case ListKind::CityEvents: + setWindowTitle(phrase(QStringLiteral("TITLE_EVENTS")).arg(Term::turnToString(ClientTools::myRO->Turn))); + break; + default: + break; + } + + FramedDlg::offscreenPaint(); + if (!MainTexture) + return; + Dpi::Canvas &canvas = offscreen.canvas(); + canvas.begin(); + canvas.font().assign(UniFont[static_cast(FontType::Normal)]); + fillOffscreen(0, 0, innerWidth, innerHeight); + + if (kind == ListKind::Science) { + for (int i = 1; i < nColumn; ++i) { + canvas.pen().setColor(Qt::black); + canvas.moveTo(104 - 33 + 15 + techNameSpace + 24 * i, 0); + canvas.lineTo(104 - 33 + 15 + techNameSpace + 24 * i, innerHeight); + canvas.moveTo(104 - 33 + 15 + techNameSpace + 9 * 2 + 24 * i, 0); + canvas.lineTo(104 - 33 + 15 + techNameSpace + 9 * 2 + 24 * i, innerHeight); + if (ClientTools::myRO->EnemyReport[column[static_cast(i)]]->TurnOfCivilReport >= + ClientTools::myRO->Turn - 1) { + canvas.brush().setStyle(Qt::SolidPattern); + canvas.brush().setColor( + Tribes::tribe[static_cast(column[static_cast(i)])]->color); + canvas.fillRect( + QRect(104 - 33 + 14 + techNameSpace + 24 * i + 1 * 2, 0, 3 + 7 * 2, innerHeight)); + canvas.brush().setStyle(Qt::NoBrush); + } else { + canvas.pen().setColor( + Tribes::tribe[static_cast(column[static_cast(i)])]->color); + for (int j = 1; j <= 8; ++j) { + canvas.moveTo(104 - 33 + 15 + techNameSpace + 24 * i + j * 2, 0); + canvas.lineTo(104 - 33 + 15 + techNameSpace + 24 * i + j * 2, innerHeight); + } + } + } + } + + for (int i = -1; i <= dispLines; ++i) + if (i + scrollBar->position() >= 0 && i + scrollBar->position() < static_cast(layer->lines().size())) + paintLine(canvas, i, true, false, false); + + canvas.end(); + markUsedOffscreen(innerWidth, 8 + 48 + dispLines * lineDistance); +} + +void ListDlg::showNewContent(WindowMode newMode, ListKind listKind) +{ + const bool forceClose = + listKind != kind && !(kind == ListKind::Cities && listKind == ListKind::CityEvents) && + !(kind == ListKind::CityEvents && listKind == ListKind::Cities) && + !(kind == ListKind::Models && listKind == ListKind::EnemyModels) && + !(kind == ListKind::EnemyModels && listKind == ListKind::Models); + + kind = listKind; + modalIndication = !mustChoose(kind); + switch (kind) { + case ListKind::Project: + setWindowTitle(phrase(QStringLiteral("TITLE_PROJECT"))); + break; + case ListKind::Advance: + setWindowTitle(phrase(QStringLiteral("TITLE_TECHSELECT"))); + break; + case ListKind::FarAdvance: + setWindowTitle(phrase(QStringLiteral("TITLE_FARTECH"))); + break; + case ListKind::Models: + case ListKind::EnemyModels: + setWindowTitle(phrase(QStringLiteral("FRMILREP"))); + break; + case ListKind::AllEnemyModels: + setWindowTitle(phrase(QStringLiteral("TITLE_EMODELS"))); + break; + case ListKind::Tribe: + setWindowTitle(phrase(QStringLiteral("TITLE_TRIBE"))); + break; + case ListKind::Science: + setWindowTitle(phrase(QStringLiteral("TITLE_SCIENCE"))); + break; + case ListKind::ShipPart: + case ListKind::EnemyShipPart: + setWindowTitle(phrase(QStringLiteral("TITLE_CHOOSESHIPPART"))); + break; + case ListKind::ChooseTech: + case ListKind::ChooseEnemyTech: + case ListKind::StealTech: + setWindowTitle(phrase(QStringLiteral("TITLE_CHOOSETECH"))); + break; + case ListKind::ChooseModel: + case ListKind::ChooseEnemyModel: + setWindowTitle(phrase(QStringLiteral("TITLE_CHOOSEMODEL"))); + break; + case ListKind::Government: + setWindowTitle(phrase(QStringLiteral("TITLE_GOV"))); + break; + case ListKind::Mission: + setWindowTitle(phrase(QStringLiteral("TITLE_SPYMISSION"))); + break; + default: + break; + } + + helpContext = kind == ListKind::Mission ? QStringLiteral("SPYMISSIONS") : QStringLiteral("CONCEPTS"); + + if (kind == ListKind::Advance) { + ui->toggleBtn->setButtonIndex(13); + ui->toggleBtn->setToolTip(phrase(QStringLiteral("FARTECH"))); + } else if (kind == ListKind::Cities) { + ui->toggleBtn->setButtonIndex(15); + ui->toggleBtn->setToolTip(phrase(QStringLiteral("BTN_PAGE"))); + } else { + ui->toggleBtn->setButtonIndex(28); + ui->toggleBtn->setToolTip(phrase(QStringLiteral("BTN_SELECT"))); + } + + bool showFocus = false; + if (kind == ListKind::Advance) { + if (Term::myData->farTech != Term::adNone) { + showFocus = true; + } else { + for (int i = 0; i < nAdv && !showFocus; ++i) { + int dummy = i; + if (!IsFutureTech(i) && ClientTools::myRO->Tech[i] < tsApplicable && + (ClientTools::advValue[i] < 2000 || ClientTools::myRO->Tech[adMassProduction] > tsNA) && + (ClientTools::advValue[i] < 1000 || ClientTools::myRO->Tech[adScience] > tsNA) && + ClientTools::server(sSetResearch - sExecute, ClientTools::me, i, &dummy) < rExecuted) + showFocus = true; + } + } + } + ui->toggleBtn->setVisible((kind == ListKind::Cities && !Term::supervising) || (kind == ListKind::Advance && showFocus) || + kind == ListKind::Models || kind == ListKind::EnemyModels); + ui->closeBtn->setVisible(!mustChoose(kind)); + + FramedDlg::showNewContent(newMode, forceClose); +} + +void ListDlg::showNewContentCityProject(WindowMode newMode, int cix) +{ + cixProject = cix; + showNewContent(newMode, ListKind::Project); +} + +void ListDlg::showNewContentMilReport(WindowMode newMode, int player) +{ + playerView = player; + showNewContent(newMode, player == ClientTools::me ? ListKind::Models : ListKind::EnemyModels); +} + +void ListDlg::playerClicked(int player) +{ + if (player == ClientTools::me) { + kind = ListKind::Models; + } else { + kind = ListKind::EnemyModels; + playerView = player; + } + initLines(); + selected = -2; + scrollBar->init(static_cast(layer->lines().size()) - 1, dispLines); + offscreenPaint(); + update(); +} + +void ListDlg::modeBtnClicked(LayerIndex index) +{ + ui->layerImprovementsButton->setDown(index == LayerIndex::Improvements); + ui->layerWondersButton->setDown(index == LayerIndex::Wonders); + ui->layerClassesButton->setDown(index == LayerIndex::Classes); + layer = &layers[static_cast(index)]; + + selected = -2; + scrollBar->init(static_cast(layer->lines().size()) - 1, dispLines); + smartUpdateContent(); +} + +void ListDlg::toggleBtnClicked() +{ + switch (kind) { + case ListKind::Advance: + result = Term::adFar; + closable = true; + close(); + break; + case ListKind::Cities: + case ListKind::CityEvents: + kind = kind == ListKind::Cities ? ListKind::CityEvents : ListKind::Cities; + offscreenPaint(); + update(); + break; + case ListKind::Models: + case ListKind::EnemyModels: { + popup->clear(); + if (ClientTools::g.Difficulty[ClientTools::me] > 0) { + QAction *action = + popup->addAction(Tribes::tribe[static_cast(ClientTools::me)]->tPhrase(QStringLiteral("SHORTNAME"))); + action->setCheckable(true); + action->setChecked(kind == ListKind::Models); + connect(action, &QAction::triggered, this, [this] { playerClicked(ClientTools::me); }); + } + for (int p1 = 0; p1 < nPl; ++p1) + if (p1 != ClientTools::me && ClientTools::myRO->EnemyReport[p1] && + ClientTools::myRO->EnemyReport[p1]->TurnOfMilReport >= 0) { + QAction *action = + popup->addAction(Tribes::tribe[static_cast(p1)]->tPhrase(QStringLiteral("SHORTNAME"))); + action->setCheckable(true); + action->setChecked(kind == ListKind::EnemyModels && p1 == playerView); + connect(action, &QAction::triggered, this, [this, p1] { playerClicked(p1); }); + } + popup->popup(mapToGlobal(QPoint(ui->toggleBtn->x(), ui->toggleBtn->y() + ui->toggleBtn->height()))); + break; + } + default: + break; + } +} + +int ListDlg::getSelectionIndex() const +{ + return selected >= 0 ? scrollBar->position() + selected : -1; +} + +void ListDlg::setSelectionIndex(int index) +{ + if (index < 0) + index = 0; + if (index > static_cast(layer->lines().size()) - 1) + index = static_cast(layer->lines().size()) - 1; + + int newSelected = index - scrollBar->position(); + int newScrollBarPos = scrollBar->position(); + + const int over = newSelected - std::min(dispLines, static_cast(layer->lines().size()) - newScrollBarPos); + if (over > 0) { + newScrollBarPos += over; + newSelected -= over; + } + + const int under = -newSelected; + if (under > 0) { + newScrollBarPos -= under; + newSelected += under; + } + + if (newSelected != selected || newScrollBarPos != scrollBar->position()) { + QPainter painter(this); + Dpi::Canvas canvas; + canvas.bind(&painter); + if (selected >= 0) + paintLine(canvas, selected, false, false, true); + scrollBar->setPosition(newScrollBarPos); + selected = newSelected; + paintLine(canvas, selected, false, true, true); + canvas.unbind(); + } +} + +void ListDlg::resizeEvent(QResizeEvent *event) +{ + FramedDlg::resizeEvent(event); + ui->closeBtn->move(width() - 38, ui->closeBtn->y()); +} + +void ListDlg::closeEvent(QCloseEvent *event) +{ + FramedDlg::closeEvent(event); +} + +void ListDlg::keyPressEvent(QKeyEvent *event) +{ + const int key = event->key(); + if (key == Qt::Key_Right) { + if (multiPage && static_cast(layer->index()) <= static_cast(LayerIndex::Classes)) { + const int lastSelectionIndex = getSelectionIndex(); + if (layer == &layers[static_cast(LayerIndex::Improvements)] && + !layers[static_cast(LayerIndex::Classes)].lines().empty()) + layer = &layers[static_cast(LayerIndex::Classes)]; + else if (layer == &layers[static_cast(LayerIndex::Classes)] && + !layers[static_cast(LayerIndex::Wonders)].lines().empty()) + layer = &layers[static_cast(LayerIndex::Wonders)]; + + ui->layerImprovementsButton->setDown(layer == &layers[static_cast(LayerIndex::Improvements)]); + ui->layerWondersButton->setDown(layer == &layers[static_cast(LayerIndex::Wonders)]); + ui->layerClassesButton->setDown(layer == &layers[static_cast(LayerIndex::Classes)]); + scrollBar->init(static_cast(layer->lines().size()) - 1, dispLines); + selected = -1; + setSelectionIndex(lastSelectionIndex); + smartUpdateContent(); + } + } else if (key == Qt::Key_Left) { + if (multiPage && static_cast(layer->index()) > static_cast(LayerIndex::Improvements)) { + const int lastSelectionIndex = getSelectionIndex(); + if (layer == &layers[static_cast(LayerIndex::Wonders)] && + !layers[static_cast(LayerIndex::Classes)].lines().empty()) + layer = &layers[static_cast(LayerIndex::Classes)]; + else if (layer == &layers[static_cast(LayerIndex::Classes)] && + !layers[static_cast(LayerIndex::Improvements)].lines().empty()) + layer = &layers[static_cast(LayerIndex::Improvements)]; + + ui->layerImprovementsButton->setDown(layer == &layers[static_cast(LayerIndex::Improvements)]); + ui->layerWondersButton->setDown(layer == &layers[static_cast(LayerIndex::Wonders)]); + ui->layerClassesButton->setDown(layer == &layers[static_cast(LayerIndex::Classes)]); + scrollBar->init(static_cast(layer->lines().size()) - 1, dispLines); + selected = -1; + setSelectionIndex(lastSelectionIndex); + smartUpdateContent(); + } + } else if (key == Qt::Key_Up) { + setSelectionIndex(getSelectionIndex() - 1); + } else if (key == Qt::Key_Down) { + setSelectionIndex(getSelectionIndex() + 1); + } else if (key == Qt::Key_Home) { + setSelectionIndex(0); + } else if (key == Qt::Key_End) { + setSelectionIndex(static_cast(layer->lines().size())); + } else if (key == Qt::Key_PageUp) { + setSelectionIndex(getSelectionIndex() - scrollBar->pageSize()); + } else if (key == Qt::Key_PageDown) { + setSelectionIndex(getSelectionIndex() + scrollBar->pageSize()); + } else if (key == Qt::Key_Return) { + QMouseEvent fakeEvent(QEvent::MouseButtonPress, QPointF(0, 0), QPointF(0, 0), Qt::LeftButton, Qt::LeftButton, + Qt::NoModifier); + mousePressEvent(&fakeEvent); + } else if (key == Qt::Key_F3 && (kind == ListKind::Cities || kind == ListKind::CityEvents)) { + toggleBtnClicked(); + } else if ((key == Qt::Key_Escape || key == Qt::Key_Return) && !ui->closeBtn->isVisible()) { + // prevent closing + } else { + FramedDlg::keyPressEvent(event); + } +} + +void ListDlg::ecoChange() +{ + if (isVisible() && kind == ListKind::Cities) + smartUpdateContent(); +} + +void ListDlg::techChange() +{ + if (isVisible() && kind == ListKind::Science) { + if (onShow) + onShow(); + update(); + } +} + +void ListDlg::addCity() +{ + if (isVisible() && kind == ListKind::Cities) { + if (onShow) + onShow(); + update(); + } +} + +void ListDlg::removeUnit() +{ + if (isVisible() && kind == ListKind::Models) + smartUpdateContent(); +} + +void ListDlg::mouseMoveEvent(QMouseEvent *event) +{ + if (!MainTexture) { + FramedDlg::mouseMoveEvent(event); + return; + } + const int x = event->position().toPoint().x(); + const int y = event->position().toPoint().y() - titleHeight; + const int i0 = scrollBar->position(); + const int sel0 = selected; + if (x >= SideFrame && x < SideFrame + innerWidth && y >= 0 && y < innerHeight && y % lineDistance >= 4 && + y % lineDistance < 20) + selected = y / lineDistance - 1; + else + selected = -2; + if (selected < -1 || selected > dispLines || selected + i0 < 0 || + selected + i0 >= static_cast(layer->lines().size())) + selected = -2; + if (selected != sel0) { + QPainter painter(this); + Dpi::Canvas canvas; + canvas.bind(&painter); + if (sel0 != -2) + paintLine(canvas, sel0, false, false, true); + if (selected != -2) + paintLine(canvas, selected, false, true, true); + canvas.unbind(); + } + + if (kind == ListKind::Science) { + const int oldScienceNation = scienceNation; + scienceNation = -1; + if (x >= SideFrame + (104 - 33 + 15 + techNameSpace) && + (x - SideFrame - (104 - 33 + 15 + techNameSpace)) % 24 <= 18 && y >= 0 && y < innerHeight) { + const int iColumn = (x - SideFrame - (104 - 33 + 15 + techNameSpace)) / 24; + if (iColumn >= 1 && iColumn < nColumn) + scienceNation = column[static_cast(iColumn)]; + } + if (scienceNation != oldScienceNation) { + QPainter painter(this); + Dpi::Canvas canvas; + canvas.bind(&painter); + fill(canvas, 9, height() - 29, width() - 18, 24, (MainTexture->width() - width()) / 2, + (MainTexture->height() - height()) / 2); + if (scienceNation >= 0) { + QString s = Tribes::tribe[static_cast(scienceNation)]->tPhrase(QStringLiteral("SHORTNAME")); + if ((ClientTools::myRO->Alive & (1 << scienceNation)) == 0) + s = phrase(QStringLiteral("SCIENCEREPORT_EXTINCT")).arg(s); + else if (ClientTools::myRO->EnemyReport[scienceNation]->TurnOfCivilReport < ClientTools::myRO->Turn - 1) + s += QStringLiteral(" (%1)").arg( + Term::turnToString(ClientTools::myRO->EnemyReport[scienceNation]->TurnOfCivilReport)); + const int xScreen = (width() - biColorTextWidth(canvas, s)) / 2; + loweredTextOut(canvas, -1, *MainTexture, xScreen + 10, height() - 29, s); + // Simplified vs. the original's ImageOp_BCC-tinted + // ScienceNationDot graphic (which read back the live + // canvas mid-paint) - draws a flat nation-color swatch. + canvas.brush().setStyle(Qt::SolidPattern); + canvas.brush().setColor(Tribes::tribe[static_cast(scienceNation)]->color); + canvas.fillRect(QRect(xScreen - 10, height() - 27, 17, 17)); + canvas.brush().setStyle(Qt::NoBrush); + } + canvas.unbind(); + } + } +} + +void ListDlg::mousePressEvent(QMouseEvent *event) +{ + int lix = -1; + if (scrollBar->position() + selected >= 0) + lix = layer->lines()[static_cast(scrollBar->position() + selected)].code; + + bool shift = event->modifiers() & Qt::ShiftModifier; + if (kind == ListKind::Science || kind == ListKind::Cities || kind == ListKind::CityEvents || + kind == ListKind::Models || kind == ListKind::EnemyModels || kind == ListKind::AllEnemyModels) + shift = true; // don't close the list window for "live report" kinds + + if (event->button() == Qt::LeftButton && !shift) { + if (selected != -2) { + result = lix; + closable = true; + close(); + } + } else if (event->button() == Qt::LeftButton && shift) { + if (selected == -2) + return; + switch (kind) { + case ListKind::Cities: + Term::mainScreenZoomToCity(ClientTools::myCity[lix].Loc, false, 0); + break; + case ListKind::CityEvents: + Term::mainScreenZoomToCity(ClientTools::myCity[lix].Loc, false, + static_cast(static_cast(ClientTools::myCity[lix].Flags) & + Term::cityRepMask)); + break; + case ListKind::Models: + case ListKind::ChooseModel: + if (lix != mixAll) + UnitStat::showNewContentOwnModel(WindowMode::Persistent, lix); + break; + case ListKind::EnemyModels: + UnitStat::showNewContentEnemyModel( + WindowMode::Persistent, + layers[static_cast(LayerIndex::Improvements)] + .lines()[static_cast(scrollBar->position() + selected)] + .model); + break; + case ListKind::AllEnemyModels: + case ListKind::ChooseEnemyModel: + if (lix != mixAll) + UnitStat::showNewContentEnemyModel(WindowMode::Persistent, lix); + break; + case ListKind::Advance: + case ListKind::FarAdvance: + case ListKind::Science: + case ListKind::ChooseTech: + case ListKind::ChooseEnemyTech: + case ListKind::StealTech: + if (lix == adMilitary) + // TODO: needs a live HelpDlg instance's textIndex('MILRES') + // (MainScreen singleton not ported) - opens the text page + // list instead of the exact targeted entry. + Help::showNewContent(WindowMode::Persistent, Help::LinkCategory::Text, 0); + else if (lix < adMilitary) + Help::showNewContent(WindowMode::Persistent, Help::LinkCategory::Adv, lix); + break; + case ListKind::Project: + if (lix == cpImp + imTrGoods) + Help::showNewContent(WindowMode::Persistent, Help::LinkCategory::Text, 0); + else if ((lix & (cpImp | cpType)) == 0) + UnitStat::showNewContentOwnModel(WindowMode::Persistent, lix & cpIndex); + else if ((lix & cpType) == 0 && lix != cpImp + imTrGoods) + Help::showNewContent(WindowMode::Persistent, Help::LinkCategory::Imp, lix & cpIndex); + break; + case ListKind::Government: + Help::showNewContent(WindowMode::Persistent, Help::LinkCategory::Misc, + static_cast(Help::MiscLinkIndex::GovList)); + break; + default: + break; + } + } else if (event->button() == Qt::RightButton) { + if (selected == -2) + return; + if (kind == ListKind::Cities || kind == ListKind::CityEvents) { + if (renameCity(lix)) { + smartUpdateContent(); + Term::mainScreenRepaintAll(); + } + } else if (kind == ListKind::Models) { + if (renameModel(lix)) { + smartUpdateContent(); + Term::mainScreenRepaintAll(); + } + } + } +} + +} // namespace Select +} // namespace Cevo diff --git a/game/localplayer/Select.h b/game/localplayer/Select.h new file mode 100644 index 0000000..6537776 --- /dev/null +++ b/game/localplayer/Select.h @@ -0,0 +1,184 @@ +// 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/CevoPVScrollBar.h" +#include "Cevo/Protocol.h" + +#include + +#include +#include +#include + +QT_BEGIN_NAMESPACE +namespace Ui { +class ListDlg; +} +QT_END_NAMESPACE + +namespace Cevo { +namespace Select { + +// TListKind equivalent: which of the 21 flavors of list this dialog +// currently renders. +enum class ListKind { + Project, + Advance, + FarAdvance, + Cities, + CityEvents, + Models, + EnemyModels, + AllEnemyModels, + Tribe, + Science, + ShipPart, + EnemyShipPart, + ChooseTech, + ChooseEnemyTech, + ChooseModel, + ChooseEnemyModel, + ChooseCity, + ChooseEnemyCity, + StealTech, + Government, + Mission, +}; + +// TLayerIndex equivalent: kProject splits its lines across up to 3 pages. +enum class LayerIndex { Improvements, Wonders, Classes }; + +// Select.pas's own const block (also referenced from CityScreen.pas via +// `uses Select` as `cpType` - that file ported earlier than this one, so +// it got its own `Term::cpType` copy of the same value; both must stay in +// sync if this value is ever revisited). +constexpr int cpType = 0x10000; +constexpr int mixAll = 0x10000; +constexpr int adAll = 0x10000; + +// TLine equivalent - a plain value type (no owning-pointer indirection +// needed, unlike the original's TObjectList; that was only there +// because Delphi's TObjectList couldn't hold plain records). +struct Line { + int code = 0; + int model = 0; + int modelSortValue = 0; +}; + +// TLayer equivalent. +class Layer { +public: + explicit Layer(LayerIndex index = LayerIndex::Improvements) : m_index(index) {} + + LayerIndex index() const { return m_index; } + std::vector &lines() { return m_lines; } + const std::vector &lines() const { return m_lines; } + + void addLine(int code, int model = 0, int modelSortValue = 0); + void sortModels(); + void sortCities(); + void sortTechs(); + + int firstShrinkedLine = std::numeric_limits::max(); + +private: + LayerIndex m_index; + std::vector m_lines; +}; + +// TListDlg/TModalSelectDlg equivalent: a generic, paged, scrollable list +// dialog used for project/tech/city/model/tribe/government/mission +// selection and for the city/enemy-model/tech report browsers. +class ListDlg : public FramedDlg { + Q_OBJECT +public: + explicit ListDlg(QWidget *parent = nullptr); + ~ListDlg() override; + + void offscreenPaint() override; + void showNewContent(WindowMode newMode, ListKind listKind); + void showNewContentCityProject(WindowMode newMode, int cix); + void showNewContentMilReport(WindowMode newMode, int player); + void ecoChange(); + void techChange(); + void addCity(); + void removeUnit(); + bool renameCity(int cix); + bool renameModel(int mix); + // -2: empty, -1: ambiguous, other: the only choice. + int onlyChoice(ListKind testKind); + + int result = -1; + +protected: + void closeEvent(QCloseEvent *event) override; + void mouseMoveEvent(QMouseEvent *event) override; + void mousePressEvent(QMouseEvent *event) override; + void keyPressEvent(QKeyEvent *event) override; + void resizeEvent(QResizeEvent *event) override; + +private: + void initLines(); + void paintLine(Dpi::Canvas &canvas, int l, bool nonText, bool lit, bool toWidget); + int getSelectionIndex() const; + void setSelectionIndex(int index); + void modeBtnClicked(LayerIndex index); + void toggleBtnClicked(); + void playerClicked(int player); + + ListKind kind = ListKind::Mission; + int lineDistance = 0; + int maxLines = 0; + int cixProject = 0; + int playerView = 0; + int selected = -2; + int dispLines = 0; + Layer *layer = nullptr; + int nColumn = 0; + int techNameSpace = 0; + int scienceNation = -1; + std::array layers{Layer(LayerIndex::Improvements), Layer(LayerIndex::Wonders), + Layer(LayerIndex::Classes)}; + std::array column{}; + bool closable = false; + bool multiPage = false; + PVScrollBar *scrollBar = nullptr; + QMenu *popup = nullptr; + + Ui::ListDlg *ui; +}; + +// TModalSelectDlg = TListDlg - same class, used modally for city-project +// selection (matches Term::modalSelectDlgShowCityProject's shape already). +using ModalSelectDlg = ListDlg; + +} // namespace Select +} // namespace Cevo diff --git a/game/localplayer/Select.ui b/game/localplayer/Select.ui new file mode 100644 index 0000000..d5f450f --- /dev/null +++ b/game/localplayer/Select.ui @@ -0,0 +1,101 @@ + + + + ListDlg + + + + 0 + 0 + 381 + 262 + + + + C-evo + + + + + 343 + 6 + 25 + 25 + + + + + + + 344 + 224 + 25 + 25 + + + + + + + 312 + 224 + 25 + 25 + + + + + + + 280 + 224 + 25 + 25 + + + + + + + 13 + 6 + 25 + 25 + + + + + + + Cevo::ButtonB + QWidget +
Cevo/CevoButtonB.h
+
+
+ +
diff --git a/game/localplayer/Term.cpp b/game/localplayer/Term.cpp index 13e9e94..c1cefe7 100644 --- a/game/localplayer/Term.cpp +++ b/game/localplayer/Term.cpp @@ -105,6 +105,13 @@ void initMyModel(int mix, bool final) int gameMode = 0; int age = 0; +std::uint32_t cityRepMask = ~static_cast(chPopIncrease) & ~static_cast(chCaptured) & + ~static_cast(chNoGrowthWarning); +std::array advIcon = [] { + std::array result; + result.fill(-1); + return result; +}(); std::array lostArmy{}; int nLostArmy = 0; std::function initAllEnemyModels = [] {}; diff --git a/game/localplayer/Term.h b/game/localplayer/Term.h index 68111a9..f2a8a67 100644 --- a/game/localplayer/Term.h +++ b/game/localplayer/Term.h @@ -37,6 +37,7 @@ #include #include +#include #include namespace Cevo { @@ -50,6 +51,11 @@ namespace Term { // added into this same namespace/file set once its turn comes. constexpr int nCityType = 4; +// Term.pas's own pseudo-advance ids (adjacent to Protocol.pas's adMilitary +// = 0x800) used by the tech-selection dialog (Select.pas). +constexpr int adNone = 0x801; +constexpr int adFar = 0x802; +constexpr int adNexus = 0x803; // icons.bmp properties: lines of system icons before improvements start. constexpr int xSizeSmall = 36; constexpr int ySizeSmall = 20; @@ -148,6 +154,19 @@ extern int gameMode; // `clkAge0 + Age`). Stays 0 until Term.pas is ported and updates it. extern int age; +// Term.pas's `CityRepMask: Cardinal;` (user-configurable "which city +// events to report" bitmask, persisted via QSettings in the original - +// not wired to settings here yet, just the documented default value). +extern std::uint32_t cityRepMask; + +// Term.pas's `AdvIcon: array[0..nAdv-1] of Integer;` (per-advance icon +// index into SmallImp/HGrSystem, computed by a Term.pas init routine not +// yet ported) - stays -1 ("no icon assigned yet") for every entry until +// Term.pas is ported; harmless if read before that (just selects an +// arbitrary/wrong icon, not a crash - same "pre-seed stays default" policy +// as lostArmy[]/nLostArmy). +extern std::array advIcon; + // 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. diff --git a/game/localplayer/Tribes.cpp b/game/localplayer/Tribes.cpp index fc5938c..5fbddbb 100644 --- a/game/localplayer/Tribes.cpp +++ b/game/localplayer/Tribes.cpp @@ -388,6 +388,8 @@ QString Tribe::tPhrase(const QString &item) const {QStringLiteral("FRSTART_NOTREATY"), QStringLiteral("Greetings.")}, {QStringLiteral("FRSTART_PEACE"), QStringLiteral("Greetings, friend.")}, {QStringLiteral("WONDEROWNER"), QStringLiteral("built by the #A")}, + {QStringLiteral("GENMODEL"), QStringLiteral("Model #%1")}, + {QStringLiteral("OWNED"), QStringLiteral("%1 (owned)")}, }; const auto it = table.constFind(item); return tString(it != table.constEnd() ? it.value() : item); diff --git a/game/localplayer/UnitStat.cpp b/game/localplayer/UnitStat.cpp index 872dd52..a65cc63 100644 --- a/game/localplayer/UnitStat.cpp +++ b/game/localplayer/UnitStat.cpp @@ -42,6 +42,7 @@ namespace Cevo { namespace UnitStat { std::function showNewContentOwnModel = [](WindowMode, int) {}; +std::function showNewContentEnemyModel = [](WindowMode, int) {}; namespace { @@ -177,6 +178,9 @@ 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); }; + UnitStat::showNewContentEnemyModel = [this](WindowMode newMode, int emix) { + this->showNewContentEnemyModel(newMode, emix); + }; onShow = [this] { if (kind == UnitStatDialogKind::EnemyUnit || kind == UnitStatDialogKind::EnemyCityDefense || diff --git a/game/localplayer/UnitStat.h b/game/localplayer/UnitStat.h index 50d3f53..49a7a75 100644 --- a/game/localplayer/UnitStat.h +++ b/game/localplayer/UnitStat.h @@ -48,6 +48,8 @@ namespace UnitStat { // wired up to a real UnitStatDlg instance's showNewContentOwnModel() once // one exists (Term.pas isn't ported yet). extern std::function showNewContentOwnModel; +// Mirrors `MainScreen.UnitStatDlg.ShowNewContent_EnemyModel(NewMode, Emix)`. +extern std::function showNewContentEnemyModel; enum class UnitStatDialogKind { OwnModel, OwnUnit, EnemyModel, EnemyUnit, EnemyCityDefense, EnemyCity };