implemented main window

This commit is contained in:
Geoffray Levasseur committed 2026-11-04 14:48:04 +01:00
1 parent a11ce3005c
commit 5d5a502976
11 files changed
+2876 -37

No files matched your search

+3
View File
@@ -151,6 +151,9 @@ set(PROJECT_SOURCES
game/localplayer/Term.h
game/localplayer/Term.MainScreen.cpp
game/localplayer/Term.MainScreen.Client.cpp
game/localplayer/Term.MainScreen.Panel.cpp
game/localplayer/Term.MainScreen.Turn.cpp
game/localplayer/Term.MainScreen.Window.cpp
game/localplayer/Term.MainScreen.h
game/localplayer/LocalPlayer.cpp
game/localplayer/LocalPlayer.h
-1
View File
@@ -96,7 +96,6 @@ extern int unFocus; // index into myUn[], -1 if none
extern bool blinkOn;
extern bool destinationMarkOn;
extern int clientMode;
constexpr int cMovieTurn = -1; // placeholder until Term.pas defines its real ClientMode enum
// IsoEngine.pas's own `var MapOptions: TMapOptions;` (the TYPE itself,
// MapOption/MapOptions, is declared in ClientTools.h since that's where the
+2
View File
@@ -197,6 +197,8 @@ ListDlg::ListDlg(QWidget *parent) : FramedDlg(parent), ui(new Ui::ListDlg)
maxLines = (MainTexture->height() - (24 + titleHeight + WideFrame)) / lineDistance - 1;
}
initLines();
// resize() below repaints the content, which needs the current layer
layer = &layers[static_cast<std::size_t>(LayerIndex::Improvements)];
multiPage = false;
for (std::size_t i = static_cast<std::size_t>(LayerIndex::Wonders); i <= static_cast<std::size_t>(LayerIndex::Classes);
+206 -17
View File
@@ -53,6 +53,7 @@
#include "Tribes.h"
#include <QApplication>
#include <QThread>
#include <algorithm>
#include <cstring>
@@ -134,17 +135,9 @@ void initPersistentData(PersistentData &data)
} // namespace
void MainScreen::endNego()
{
if (negoDlg().isVisible())
negoDlg().close();
// TODO: the end-of-turn button and panel repaint need the main window (not ported).
clientMode = -1;
m_idle = false;
}
void MainScreen::client(int command, int newPlayer, void *data)
{
qWarning("TMPDEBUG client(%x, %d)", command, newPlayer);
TNewGameData &g = ClientTools::g;
const auto intData = [data] { return *static_cast<int *>(data); };
const auto isLocalSession = [] { return !ClientTools::isMultiPlayerGame(); };
@@ -152,7 +145,7 @@ void MainScreen::client(int command, int newPlayer, void *data)
if (command == cTurn || command == cResume || command == cContinue || command == cMovieTurn ||
command == scContact || (command >= scDipStart && command <= scDipBreak)) {
supervising = g.Difficulty[newPlayer] == 0;
// TODO: ArrangeMidPanel() needs the main window layout (not ported).
arrangeMidPanel();
}
switch (command) {
@@ -207,14 +200,17 @@ void MainScreen::client(int command, int newPlayer, void *data)
g = *static_cast<TNewGameData *>(data);
ClientTools::me = -1;
m_pLogo = -1;
clientMode = -1;
setClientMode(-1);
setMapOptions();
m_mainMap->pDebugMap = -1;
m_idle = false;
m_jump.fill(0);
if (m_startRunning)
m_jump[0] = 999999;
gameMode = command;
grExt.resetPixUsed();
// TODO: MainMap/NoMap.Reset and SetMapOptions need the main map (not ported).
m_mainMap->reset();
m_noMap->reset();
Tribes::init();
getTribeList();
for (int p1 = 0; p1 < nPl; ++p1) {
@@ -230,14 +226,20 @@ void MainScreen::client(int command, int newPlayer, void *data)
m_helpDlg->clearHistory();
if (m_cityDlg)
m_cityDlg->reset();
// TODO: MiniMap sizing and the area buttons' visibility need the main window (not ported).
m_miniMap->size = QPoint(g.lx, g.ly);
m_miniMap->bitmap.setSize(m_miniMap->size.x() * 2, m_miniMap->size.y());
for (int i = 0; i < nPl; ++i) {
Tribes::tribe[static_cast<std::size_t>(i)].reset();
tribeOriginal[static_cast<std::size_t>(i)] = false;
}
toldSlavery = -1;
m_repaintOnResize = false;
m_closable = false;
m_firstMovieTurn = true;
m_menuArea->setVisible(gameMode != cMovie);
m_treasuryArea->setVisible(gameMode < cMovie);
m_researchArea->setVisible(gameMode < cMovie);
m_managementArea->setVisible(gameMode < cMovie);
return;
case cGetReady:
@@ -310,19 +312,206 @@ void MainScreen::client(int command, int newPlayer, void *data)
m_startRunning = !m_idle && m_jump[0] > 0; // AI called Reload
ClientTools::me = -1;
m_idle = false;
clientMode = -1;
// TODO: hiding the unit/terrain/EOT/movie buttons and the scrollbar reset need the main window.
setClientMode(-1);
m_unitInfoBtn->setVisible(false);
m_unitBtn->setVisible(false);
m_terrainBtn->setVisible(false);
for (ButtonB *button : m_movieSpeedBtn)
button->setVisible(false);
m_eot->setVisible(false);
for (ButtonC *button : { m_mapBtn0, m_mapBtn1, m_mapBtn4, m_mapBtn5, m_mapBtn6 })
button->setVisible(false);
if (m_verticalScrollBar)
m_verticalScrollBar->init(0, 1);
for (auto &tribe : Tribes::tribe)
tribe.reset();
Tribes::done();
m_repaintOnResize = false;
m_closable = true;
close();
return;
case cShowGame:
for (Dpi::Bitmap *bitmap : { &m_panel, &m_topBar }) {
Dpi::Canvas &canvas = bitmap->canvas();
canvas.brush().setColor(Qt::black);
canvas.fillRect(QRect(0, 0, bitmap->width(), bitmap->height()));
canvas.brush().setStyle(Qt::NoBrush);
canvas.end();
}
show();
updateNow();
resizeControls();
m_repaintOnResize = true;
m_xw = 0;
m_yw = m_ywcenter;
return;
case cShowTurnChange:
if (intData() >= 0)
if (intData() >= 0) {
m_pLogo = intData();
// TODO: repainting the AI logo needs the main window (not ported).
update(m_xRightPanel + 10 - (16 + 64), height() - PanelHeight, 64, 64);
}
return;
case cTurn:
case cResume:
case cContinue:
if (!m_gameOK) {
ClientTools::server(sResign, newPlayer, 0, nullptr);
return;
}
setClientMode(command);
m_pTurn = newPlayer;
m_pLogo = newPlayer;
if (command == cResume) { // init non-original model pictures (maybe tribes not found)
for (int p1 = 0; p1 < nPl; ++p1) {
if (!g.RO[p1])
continue;
ClientTools::itsMeAgain(p1);
for (int mix = 0; mix < ClientTools::myRO->nModel; ++mix) {
if (!Tribes::tribe[static_cast<std::size_t>(ClientTools::me)]->modelPictureAt(mix).hGr)
initMyModel(mix, true);
}
}
ClientTools::me = -1;
}
if (m_jump[static_cast<std::size_t>(m_pTurn)] > 0)
QCoreApplication::processEvents();
if (m_jump[static_cast<std::size_t>(m_pTurn)] > 0) {
if ((g.RO[newPlayer]->Happened & phGameEnd) != 0)
m_jump[static_cast<std::size_t>(m_pTurn)] = 0;
else
--m_jump[static_cast<std::size_t>(m_pTurn)];
}
{
bool skipTurn = m_jump[static_cast<std::size_t>(m_pTurn)] > 0;
if (skipTurn) {
ClientTools::itsMeAgain(newPlayer);
myData = static_cast<PersistentData *>(g.RO[newPlayer]->Data);
setTroopLoc(-1);
miniMapPaint();
initAllEnemyModels(); // necessary for correct replay
if (!endTurn(true))
skipTurn = false;
}
if (!skipTurn) {
if ((clientMode < scDipStart || clientMode > scDipBreak) && m_negoDlg && m_negoDlg->isVisible())
m_negoDlg->close();
m_skipped = false; // always show my moves during my turn
m_idle = true;
initTurn(newPlayer);
dipMem[static_cast<std::size_t>(ClientTools::me)].pContact = -1;
}
}
return;
case cMovieTurn:
setClientMode(command);
m_pTurn = newPlayer;
m_pLogo = -1;
m_skipped = false; // always show my moves during my turn
m_idle = true;
if (m_firstMovieTurn) {
checkMovieSpeedBtnState();
m_firstMovieTurn = false;
}
initTurn(newPlayer);
QCoreApplication::processEvents();
if (m_movieSpeed == 4) {
QThread::msleep(75);
// this break will ensure speed of fast forward does not depend on cpu speed
QCoreApplication::processEvents();
}
return;
case cMovieEndTurn:
rememberPeaceViolation();
m_pTurn = -1;
m_pLogo = -1;
m_mapValid = false;
setClientMode(-1);
m_idle = false;
m_skipped = false;
return;
case cEditMap:
setClientMode(cEditMap);
setMapOptions();
m_mainMap->pDebugMap = -1;
ClientTools::itsMeAgain(0);
myData = nullptr;
m_unitInfoBtn->setVisible(false);
m_unitBtn->setVisible(false);
m_terrainBtn->setVisible(false);
for (ButtonB *button : m_movieSpeedBtn)
button->setVisible(false);
m_eot->setVisible(false);
helpDlg().difficulty = 0;
m_brushType = fGrass;
// TODO: UpdateInterface (mFillMap.Enabled) belongs to the menus, which are not ported.
m_brushLoc = -1;
m_edited = false;
IsoEngine::unFocus = -1;
m_markCityLoc = -1;
m_tracking = false;
m_turnComplete = false;
m_mapValid = false;
resizeControls();
setTroopLoc(-1);
m_idle = true;
return;
case scContact:
dipMem[static_cast<std::size_t>(newPlayer)].pContact = intData();
if (m_jump[static_cast<std::size_t>(newPlayer)] > 0) {
dipCall(scReject);
} else {
setClientMode(command);
initTurn(newPlayer);
myData->toldContact |= 1 << intData();
// don't tell about new nation when already contacted by them
MessgEx::MessgExDlg &dlg = messgExDlg();
dlg.openSound = QStringLiteral("CONTACT_%1").arg(ClientTools::myRO->EnemyReport[intData()]->Attitude);
dlg.messageText = Tribes::tribe[static_cast<std::size_t>(intData())]->tPhrase(QStringLiteral("FRCONTACT"));
dlg.kind = MessageKind::YesNo;
dlg.iconKind = MessgEx::MessageIconKind::Tribe;
dlg.iconIndex = intData();
if (dlg.showModal() == Dpi::ModalResult::Ok) {
negoDlg().respond();
DipMemEntry &mem = dipMem[static_cast<std::size_t>(ClientTools::me)];
mem.deliveredPrices.reset();
mem.receivedPrices.reset();
dipCall(scDipStart);
} else {
dipCall(scReject);
endNego();
}
}
return;
case scDipStart:
case scDipNotice:
case scDipAccept:
case scDipCancelTreaty:
case scDipOffer:
case scDipBreak:
setClientMode(command);
initTurn(newPlayer);
if (command == scDipOffer) {
receivedOffer = *static_cast<TOffer *>(data);
initAllEnemyModels();
}
// TODO: the sounds played for scDipStart/scDipCancelTreaty/scDipAccept (sound is not ported).
if (command == scDipAccept) { // remember delivered and received prices
DipMemEntry &mem = dipMem[static_cast<std::size_t>(ClientTools::me)];
for (int i = 0; i < mem.sentOffer.nDeliver; ++i)
mem.deliveredPrices.set(static_cast<std::size_t>(mem.sentOffer.Price[i] >> 24));
for (int i = 0; i < mem.sentOffer.nCost; ++i)
mem.receivedPrices.set(static_cast<std::size_t>(mem.sentOffer.Price[mem.sentOffer.nDeliver + i] >> 24));
}
negoDlg().start();
m_idle = true;
return;
case cShowCancelTreaty:
+694
View File
@@ -0,0 +1,694 @@
// TMainScreen.PanelPaint (Term.pas): the top bar and the bottom panel
// (mini map frame, selected unit, units on the tile, terrain info, buttons).
#include "Term.MainScreen.h"
#include "Cevo/CevoGraphicSet.h"
#include "Cevo/CevoScreenTools.h"
#include "Cevo/CevoTexture.h"
#include "Global.h"
#include <algorithm>
namespace Cevo {
namespace Term {
namespace {
QString terrainPhrase(int index)
{
return phrases.lookup(QStringLiteral("TERRAIN"), index);
}
QString twoTerrains(int first, int second)
{
return formatPhrase(QStringLiteral("TWOTERRAINS"), { terrainPhrase(first), terrainPhrase(second) });
}
QString unitMovementString(const TUn &un)
{
QString result = movementToString(un.Movement);
if (un.Master >= 0) {
result = QStringLiteral("(%1)").arg(result);
} else {
const TModel &model = ClientTools::myModel[un.mix];
if (model.Domain == dAir && model.Kind != mkSpecial_Glider)
result = QStringLiteral("%1(%2)").arg(result).arg(un.Fuel);
}
return result;
}
// Name of what a map editor brush paints.
QString brushName(std::uint32_t brushType)
{
switch (brushType) {
case fDesert:
case fPrairie:
case fTundra:
case fArctic:
case fSwamp:
case fHills:
case fMountains:
return terrainPhrase(static_cast<int>(brushType));
case fShore:
return twoTerrains(fOcean, fShore);
case fGrass:
return twoTerrains(fGrass, fGrass + 12);
case fForest:
return twoTerrains(fForest, fJungle);
case fRiver:
return phrases[QStringLiteral("RIVER")];
case fDeadLands:
case fDeadLands | fCobalt:
case fDeadLands | fUranium:
case fDeadLands | fMercury:
return terrainPhrase(3 * 12 + static_cast<int>(brushType >> 25));
case fPrefStartPos:
return phrases[QStringLiteral("MAP_PREFSTART")];
case fStartPos:
return phrases[QStringLiteral("MAP_START")];
case fPoll:
return phrases[QStringLiteral("POLL")];
default: {
int index = 0;
switch (brushType) {
case fRoad: index = 1; break;
case fRR: index = 2; break;
case tiIrrigation: index = 4; break;
case tiFarm: index = 5; break;
case tiMine: index = 7; break;
case fCanal: index = 8; break;
case tiFort: index = 10; break;
case tiBase: index = 12; break;
default: break;
}
return phrases.lookup(QStringLiteral("JOBRESULT"), index);
}
}
}
} // namespace
void MainScreen::panelPaint()
{
if (!ClientTools::myRO || m_panel.width() <= 1 || !MainTexture)
return;
paintPanelBackground();
if (clientMode == cEditMap)
paintPanelBrushes();
else if (m_troopLoc >= 0)
paintPanelTroops();
paintPanelButtons();
m_eot->setBack(m_panel.canvas(), m_eot->x(), m_eot->y() - (height() - PanelHeight));
m_panel.canvas().end();
invalidateRect(0, height() - PanelHeight, width(), height());
paintTopBar();
}
void MainScreen::paintPanelBackground()
{
const int lx = ClientTools::g.lx;
const int ly = ClientTools::g.ly;
const int cw = width();
Dpi::Canvas &canvas = m_panel.canvas();
const Texture &texture = *MainTexture;
fill(canvas, 0, 3, m_xMidPanel + 7 - 10, PanelHeight - 3, texture.width() - (m_xMidPanel + 7 - 10),
texture.height() - PanelHeight);
fill(canvas, m_xRightPanel + 10 - 7, 3, m_panel.width() - m_xRightPanel - 10 + 7, PanelHeight - 3,
-(m_xRightPanel + 10 - 7), texture.height() - PanelHeight);
fillLarge(canvas, m_xMidPanel - 2, PanelHeight - MidPanelHeight, m_xRightPanel + 2, PanelHeight, cw / 2);
canvas.brush().setStyle(Qt::NoBrush);
canvas.pen().setColor(Qt::black);
canvas.moveTo(0, 0);
canvas.lineTo(m_xMidPanel + 7 - 8, 0);
canvas.lineTo(m_xMidPanel + 7 - 8, PanelHeight - MidPanelHeight);
canvas.lineTo(m_xRightPanel, PanelHeight - MidPanelHeight);
canvas.lineTo(m_xRightPanel, 0);
canvas.lineTo(cw, 0);
canvas.pen().setColor(texture.colorBevelLight);
canvas.moveTo(m_xMidPanel + 7 - 9, PanelHeight - MidPanelHeight + 2);
canvas.lineTo(m_xRightPanel + 10 - 8, PanelHeight - MidPanelHeight + 2);
canvas.pen().setColor(texture.colorBevelLight);
canvas.moveTo(0, 1);
canvas.lineTo(m_xMidPanel + 7 - 9, 1);
canvas.pen().setColor(texture.colorBevelShade);
canvas.lineTo(m_xMidPanel + 7 - 9, PanelHeight - MidPanelHeight + 1);
canvas.pen().setColor(texture.colorBevelLight);
canvas.lineTo(m_xRightPanel + 10 - 9, PanelHeight - MidPanelHeight + 1);
canvas.pen().setColor(texture.colorBevelLight);
canvas.lineTo(m_xRightPanel + 10 - 9, 1);
canvas.lineTo(cw, 1);
canvas.moveTo(cw, 2);
canvas.lineTo(m_xRightPanel + 10 - 8, 2);
canvas.lineTo(m_xRightPanel + 10 - 8, PanelHeight);
canvas.moveTo(0, 2);
canvas.lineTo(m_xMidPanel + 7 - 10, 2);
canvas.pen().setColor(texture.colorBevelShade);
canvas.lineTo(m_xMidPanel + 7 - 10, PanelHeight);
corner(canvas, m_xMidPanel + 7 - 16, 1, 1, texture);
corner(canvas, m_xRightPanel + 10 - 9, 1, 0, texture);
if (clientMode != cEditMap) {
if (supervising) {
frame(canvas, cw - XPalace - 1, YPalace - 1, cw - XPalace + xSizeBig, YPalace + ySizeBig,
colorFromDelphi(0xB0B0B0), colorFromDelphi(0xFFFFFF));
rframe(canvas, cw - XPalace - 2, YPalace - 2, cw - XPalace + xSizeBig + 1, YPalace + ySizeBig + 1,
colorFromDelphi(0xFFFFFF), colorFromDelphi(0xB0B0B0));
bitBltBitmap(m_panel, cw - XPalace, YPalace, xSizeBig, ySizeBig, HGrSystem2->data, 70, 123);
} else if (ClientTools::myRO->NatBuilt[imPalace] > 0) {
impImage(canvas, cw - XPalace, YPalace, imPalace, -1, gameMode != cMovie);
} else {
impImage(canvas, cw - XPalace, YPalace, 21, -1, gameMode != cMovie);
}
}
if (gameMode == cMovie) {
frame(canvas, m_xMini + 1, m_yMini + 1, m_xMini + 2 + lx * 2, m_yMini + 2 + ly, Qt::black, Qt::black);
} else {
frame(canvas, m_xMini + 1, m_yMini + 1, m_xMini + 2 + lx * 2, m_yMini + 2 + ly, colorFromDelphi(0xB0B0B0),
colorFromDelphi(0xFFFFFF));
rframe(canvas, m_xMini, m_yMini, m_xMini + 3 + lx * 2, m_yMini + 3 + ly, colorFromDelphi(0xFFFFFF),
colorFromDelphi(0xB0B0B0));
}
copyMiniToPanel();
if (clientMode != cEditMap) { // MapBtn icons
for (int i = 0; i <= 5; ++i) {
if (i != 3)
dump(m_panel, *HGrSystem, m_xMini + lx - 42 + 16 * i, PanelHeight - 26, 8, 8, 121 + i * 9, 61);
}
}
}
void MainScreen::paintPanelBrushes()
{
Dpi::Canvas &canvas = m_panel.canvas();
const Texture &texture = *MainTexture;
const int xxt = m_noMapPanel->xxt;
const int yyt = m_noMapPanel->yyt;
GraphicSet *hGrTerrain = m_noMapPanel->hGrTerrain;
const int position = m_verticalScrollBar ? m_verticalScrollBar->position() : 0;
for (int i = 0; i < m_trRow; ++i)
m_trix[static_cast<std::size_t>(i)] = -1;
int count = 0;
for (const std::uint32_t brush : BrushTypes) {
if (count >= m_trRow * position && count < m_trRow * (position + 1)) {
const int slot = count - m_trRow * position;
m_trix[static_cast<std::size_t>(slot)] = static_cast<int>(brush);
const int x = slot * m_trPitch;
QPoint srcBase(-1, 0);
QPoint src;
if (brush <= 8) {
src = QPoint(static_cast<int>(brush), 0);
} else if (brush <= 30) {
srcBase = QPoint(2, 2);
src = QPoint(0, 2 * static_cast<int>(brush) - 15);
} else if (brush == fRiver) {
src = QPoint(7, 14);
} else if (brush == fRoad) {
src = QPoint(0, 9);
} else if (brush == fRR) {
src = QPoint(0, 10);
} else if (brush == fCanal) {
src = QPoint(0, 11);
} else if (brush == fPoll) {
src = QPoint(6, 12);
} else if (brush == fDeadLands || brush == (fDeadLands | fCobalt) || brush == (fDeadLands | fUranium)
|| brush == (fDeadLands | fMercury)) {
srcBase = QPoint(6, 2);
src = QPoint(8, 12 + static_cast<int>(brush >> 25));
} else if (brush == tiIrrigation || brush == tiFarm || brush == tiMine || brush == tiBase) {
src = QPoint(static_cast<int>(brush >> 12) - 1, 12);
} else if (brush == tiFort) {
src = QPoint(3, 12);
srcBase = QPoint(7, 12);
} else if (brush == fPrefStartPos) {
src = QPoint(0, 1);
} else if (brush == fStartPos) {
src = QPoint(0, 2);
}
if (srcBase.x() >= 0)
sprite(canvas, *hGrTerrain, m_xTroop + 2 + x, YTroop + 9 - yyt, xxt * 2, yyt * 3,
1 + srcBase.x() * (xxt * 2 + 1), 1 + srcBase.y() * (yyt * 3 + 1));
sprite(canvas, *hGrTerrain, m_xTroop + 2 + x, YTroop + 9 - yyt, xxt * 2, yyt * 3,
1 + src.x() * (xxt * 2 + 1), 1 + src.y() * (yyt * 3 + 1));
if (brush == m_brushType) {
frame(canvas, m_xTroop + 2 + x, YTroop + 7 - yyt / 2, m_xTroop + 2 * xxt + x, YTroop + 2 * yyt + 11,
Qt::black, Qt::black);
frame(canvas, m_xTroop + 1 + x, YTroop + 6 - yyt / 2, m_xTroop + 2 * xxt - 1 + x,
YTroop + 2 * yyt + 10, texture.colorMark, texture.colorMark);
}
}
++count;
}
loweredTextOut(canvas, -1, texture, m_xTroop + 1, PanelHeight - 19, brushName(m_brushType));
}
void MainScreen::paintPanelSelectedUnit()
{
Dpi::Canvas &canvas = m_panel.canvas();
const Texture &texture = *MainTexture;
const int me = ClientTools::me;
const TUn &un = ClientTools::myUn[IsoEngine::unFocus];
if (me < 0 || me >= nPl)
return;
// display info about selected unit
const int mixShow = un.Job == jCity ? -1 : un.mix; // building site
Tribes::Tribe &tribe = *Tribes::tribe[static_cast<std::size_t>(me)];
const Tribes::ModelPicture &picture = tribe.modelPictureAt(mixShow);
if (picture.hGr)
sprite(canvas, *picture.hGr, m_xMidPanel + 7 + 12, YTroop + 1, 64, 48, picture.pix % 10 * 65 + 1,
picture.pix / 10 * 49 + 1);
if ((un.Flags & unFortified) && Tribes::hGrStdUnits)
sprite(canvas, *Tribes::hGrStdUnits, m_xMidPanel + 7 + 12, YTroop + 1, IsoEngine::xxu * 2,
IsoEngine::yyu * 2, 1 + 6 * (IsoEngine::xxu * 2 + 1), 1);
makeBlue(m_panel, m_xMidPanel + 7 + 12 + 10, YTroop - 13, 44, 12);
QString s = unitMovementString(un);
risedTextOut(canvas, m_xMidPanel + 7 + 12 + 32 - biColorTextWidth(canvas, s) / 2, YTroop - 16, s);
const int health = un.Health;
s = QStringLiteral("%1%").arg(health);
lightGradient(canvas, m_xMidPanel + 7 + 12 + 7, PanelHeight - 22, (health + 1) / 2,
colorFromDelphi(((ClientTools::colorOfHealth(health) & 0xFEFEFE) >> 2) * 3));
if (health < 100)
lightGradient(canvas, m_xMidPanel + 7 + 12 + 7 + (health + 1) / 2, PanelHeight - 22, 50 - (health + 1) / 2,
Qt::black);
risedTextOut(canvas, m_xMidPanel + 7 + 12 + 32 - biColorTextWidth(canvas, s) / 2, PanelHeight - 23, s);
frameImage(canvas, HGrSystem->data, m_xMidPanel + 7 + XUnitText, YTroop + 15, 12, 14, 121 + un.Exp / ExpCost * 13,
28);
s = tribe.modelNameAt(un.Job == jCity ? -1 : un.mix);
if (un.Home >= 0) {
loweredTextOut(canvas, -1, texture, m_xMidPanel + 7 + XUnitText + 18, YTroop + 5, s);
loweredTextOut(canvas, -1, texture, m_xMidPanel + 7 + XUnitText + 18, YTroop + 21,
QStringLiteral("(%1)").arg(Tribes::cityName(ClientTools::myCity[un.Home].ID)));
} else {
loweredTextOut(canvas, -1, texture, m_xMidPanel + 7 + XUnitText + 18, YTroop + 13, s);
}
}
void MainScreen::paintPanelTroops()
{
Dpi::Canvas &canvas = m_panel.canvas();
const Texture &texture = *MainTexture;
const int me = ClientTools::me;
const std::uint32_t *myMap = ClientTools::myMap;
const TUn *myUn = ClientTools::myUn;
const int position = m_verticalScrollBar ? m_verticalScrollBar->position() : 0;
canvas.brush().setStyle(Qt::NoBrush);
if (IsoEngine::unFocus >= 0)
paintPanelSelectedUnit();
if (IsoEngine::unFocus >= 0 && myUn[IsoEngine::unFocus].Loc != m_troopLoc) { // divide panel
const int x = m_smallScreen && !supervising ? m_xTroop - 8 : m_xTroop - 152;
canvas.pen().setColor(texture.colorBevelShade);
canvas.moveTo(x - 1, PanelHeight - MidPanelHeight + 2);
canvas.lineTo(x - 1, PanelHeight);
canvas.pen().setColor(texture.colorBevelLight);
canvas.moveTo(x, PanelHeight - MidPanelHeight + 2);
canvas.lineTo(x, PanelHeight);
}
for (int i = 0; i < 24; ++i)
m_trix[static_cast<std::size_t>(i)] = -1;
if (myMap[m_troopLoc] & fUnit) {
if (myMap[m_troopLoc] & fOwned) {
if (m_trCnt > 1 || IsoEngine::unFocus < 0 || myUn[IsoEngine::unFocus].Loc != m_troopLoc) {
loweredTextOut(canvas, -1, texture, m_xTroop + 10, PanelHeight - 24,
phrases[QStringLiteral("PRESENT")]);
int uixDefender = -1;
ClientTools::server(sGetDefender, me, m_troopLoc, &uixDefender);
int count = 0;
for (int prio = 1; prio >= 0; --prio) {
for (int uix = 0; uix < ClientTools::myRO->nUn; ++uix) {
if ((uix == uixDefender) != (prio != 0))
continue;
const TUn &unx = myUn[uix];
if (unx.Loc != m_troopLoc)
continue; // display own units
if (count >= m_trRow * position && count < m_trRow * (position + 1) && me >= 0 && me < nPl) {
const int slot = count - m_trRow * position;
m_trix[static_cast<std::size_t>(slot)] = uix;
TUnitInfo unitInfo;
MakeUnitInfo(me, unx, unitInfo);
const int x = slot * m_trPitch;
if (uix == IsoEngine::unFocus) {
frame(canvas, m_xTroop + 4 + x, YTroop + 3, m_xTroop + 64 + x, YTroop + 47, Qt::black,
Qt::black);
frame(canvas, m_xTroop + 3 + x, YTroop + 2, m_xTroop + 63 + x, YTroop + 46,
texture.colorMark, texture.colorMark);
} else if (unx.Master >= 0 && unx.Master == IsoEngine::unFocus) {
cframe(canvas, m_xTroop + 4 + x, YTroop + 3, m_xTroop + 64 + x, YTroop + 47, 8,
Qt::black);
cframe(canvas, m_xTroop + 3 + x, YTroop + 2, m_xTroop + 63 + x, YTroop + 46, 8,
texture.colorMark);
}
m_noMapPanel->setOutput(&m_panel);
m_noMapPanel->paintUnit(m_xTroop + 2 + x, YTroop + 1, unitInfo, unx.Status);
if (clientMode < scContact
&& (unx.Job > jNone
|| (unx.Status & (IsoEngine::usStay | IsoEngine::usRecover | IsoEngine::usGoto))
!= 0))
sprite(canvas, *HGrSystem, m_xTroop + 2 + 60 - 20 + x, YTroop + 35, 20, 20, 81, 25);
if (!supervising) {
makeBlue(m_panel, m_xTroop + 2 + 10 + x, YTroop - 13, 44, 12);
const QString s = unitMovementString(unx);
risedTextOut(canvas, m_xTroop + x + 34 - biColorTextWidth(canvas, s) / 2, YTroop - 16,
s);
}
}
++count;
}
}
Q_ASSERT(count == m_trCnt);
}
} else {
loweredTextOut(canvas, -1, texture, m_xTroop + 8, PanelHeight - 24, phrases[QStringLiteral("PRESENT")]);
int count = 0;
ClientTools::server(sGetUnits, me, m_troopLoc, &count);
for (int i = 0; i < count; ++i) {
if (i >= m_trRow * position && i < m_trRow * (position + 1)) { // display enemy units
m_trix[static_cast<std::size_t>(i - m_trRow * position)] = i;
const int x = (i - m_trRow * position) * m_trPitch;
m_noMapPanel->setOutput(&m_panel);
m_noMapPanel->paintUnit(m_xTroop + 2 + x, YTroop + 1,
(*ClientTools::myRO->EnemyUn)[ClientTools::myRO->nEnemyUn + i], 0);
}
}
}
}
if (!m_smallScreen || supervising)
paintPanelTerrain();
if (m_terrainBtn->isVisible())
rframe(canvas, m_terrainBtn->x() - 1, m_terrainBtn->y() - height() + (PanelHeight - 1),
m_terrainBtn->x() + m_terrainBtn->width(),
m_terrainBtn->y() + m_terrainBtn->height() - height() + PanelHeight, texture.colorBevelShade,
texture.colorBevelLight);
}
void MainScreen::paintPanelTerrain()
{
Dpi::Canvas &canvas = m_panel.canvas();
const Texture &texture = *MainTexture;
const std::uint32_t *myMap = ClientTools::myMap;
const TUn *myUn = ClientTools::myUn;
paintZoomedTile(m_panel, m_xTerrain - m_noMapPanel->xxt * 2, 110 - m_noMapPanel->yyt * 3, m_troopLoc);
if (IsoEngine::unFocus >= 0 && myUn[IsoEngine::unFocus].Job != jNone) {
int jobFocus = myUn[IsoEngine::unFocus].Job;
TJobProgressData jobProgressData;
ClientTools::server(sGetJobProgress, ClientTools::me, myUn[IsoEngine::unFocus].Loc, jobProgressData);
makeBlue(m_panel, m_xTerrain - 72, 148 - 17, 144, 31);
paintRelativeProgressBar(canvas, 3, m_xTerrain - 68, 148 + 3, 63, jobProgressData[jobFocus].Done,
jobProgressData[jobFocus].NextTurnPlus, jobProgressData[jobFocus].Required, true,
texture);
QString s = QStringLiteral("%1/%2")
.arg(movementToString(jobProgressData[jobFocus].Done))
.arg(movementToString(jobProgressData[jobFocus].Required));
risedTextOut(canvas, m_xTerrain + 6, 148 - 3, s);
const std::uint32_t focusTile = myMap[myUn[IsoEngine::unFocus].Loc];
if (jobFocus == jRoad && (focusTile & fRiver))
jobFocus = nJob + 0;
else if (jobFocus == jRR && (focusTile & fRiver))
jobFocus = nJob + 1;
else if (jobFocus == jClear) {
if ((focusTile & fTerrain) == fForest)
jobFocus = nJob + 2;
else if ((focusTile & fTerrain) == fDesert)
jobFocus = nJob + 3;
else
jobFocus = nJob + 4;
}
s = phrases.lookup(QStringLiteral("JOBRESULT"), jobFocus);
risedTextOut(canvas, m_xTerrain - biColorTextWidth(canvas, s) / 2, 148 - 19, s);
}
QString s;
const std::uint32_t tile = myMap[m_troopLoc];
if ((tile & (fTerrain | fSpecial)) == (fGrass | fSpecial1))
s = terrainPhrase(fGrass + 12);
else if (tile & fDeadLands)
s = terrainPhrase(3 * 12);
else if ((tile & fTerrain) == fForest && IsoEngine::isJungle(m_troopLoc / ClientTools::g.lx))
s = terrainPhrase(fJungle);
else
s = terrainPhrase(static_cast<int>(tile & fTerrain));
risedTextOut(canvas, m_xTerrain - biColorTextWidth(canvas, s) / 2, 99, s);
}
void MainScreen::paintPanelButtons()
{
Dpi::Canvas &canvas = m_panel.canvas();
const Texture &texture = *MainTexture;
const int yOffset = PanelHeight - height();
const auto paintButtonB = [&](ButtonB *button) {
if (!button->isVisible())
return;
dump(m_panel, *HGrSystem, button->x(), button->y() + yOffset, 25, 25, 169, 243);
sprite(canvas, *HGrSystem, button->x(), button->y() + yOffset, 25, 25, 1 + 26 * button->buttonIndex(), 337);
rframe(canvas, button->x() - 1, button->y() + yOffset - 1, button->x() + button->width(),
button->y() + button->height() + yOffset, texture.colorBevelShade, texture.colorBevelLight);
};
paintButtonB(m_unitBtn);
paintButtonB(m_unitInfoBtn);
paintButtonB(m_terrainBtn);
for (ButtonB *button : m_movieSpeedBtn)
paintButtonB(button);
if (clientMode != cEditMap) {
for (ButtonC *button : { m_mapBtn0, m_mapBtn1, m_mapBtn4, m_mapBtn5, m_mapBtn6 }) {
if (!button->isVisible())
continue;
dump(m_panel, *HGrSystem, button->x(), button->y() + yOffset, 12, 12, 169,
178 + 13 * button->buttonIndex());
rframe(canvas, button->x() - 1, button->y() + yOffset - 1, button->x() + button->width(),
button->y() + button->height() + yOffset, texture.colorBevelShade, texture.colorBevelLight);
}
}
}
void MainScreen::paintTopBar()
{
Dpi::Canvas &canvas = m_topBar.canvas();
const Texture &texture = *MainTexture;
const TPlayerContext &ro = *ClientTools::myRO;
const int cw = width();
const int xTreasurySection = cw / 2 - 172;
const int xResearchSection = cw / 2;
// ClientWidth div 2 + 68 = maximum to right
fillLarge(canvas, 0, 0, cw, TopBarHeight - 3, cw / 2);
canvas.brush().setStyle(Qt::NoBrush);
canvas.pen().setColor(Qt::black);
canvas.moveTo(0, TopBarHeight - 1);
canvas.lineTo(cw, TopBarHeight - 1);
canvas.pen().setColor(texture.colorBevelShade);
canvas.moveTo(0, TopBarHeight - 2);
canvas.lineTo(cw, TopBarHeight - 2);
canvas.moveTo(0, TopBarHeight - 3);
canvas.lineTo(cw, TopBarHeight - 3);
frame(canvas, 40, -1, xTreasurySection - 1, TopBarHeight - 7, texture.colorBevelShade, texture.colorBevelLight);
frame(canvas, xResearchSection + 332, -1, cw, TopBarHeight - 7, texture.colorBevelShade, texture.colorBevelLight);
canvas.end(); // the image operations below work on the pixels directly
const auto templateOp = [&](const char *itemName, int x, int y, int color1, int color2) {
if (const GraphicSetItem *item = Templates ? Templates->searchByName(QLatin1String(itemName)) : nullptr)
imageOpBCC(m_topBar, Templates->data, x, y, item->left, item->top, item->width, item->height, color1,
color2);
};
if (gameMode != cMovie)
templateOp("MenuLogo", 2, 1, 0xBFBF20, 0x4040DF);
if (ro.nCity > 0) {
int trueMoney = ro.Money;
int trueResearch = ro.Research;
if (supervising) { // normalize values from after-turn state
trueMoney = std::max(0, trueMoney - taxSum);
trueResearch = std::max(0, trueResearch - scienceSum);
}
// treasury section
templateOp("Treasury", xTreasurySection + 8, 1, 0x40A040, 0x4030C0);
loweredTextOut(canvas, -1, texture, xTreasurySection + 48, 0, QStringLiteral("%1%c").arg(trueMoney));
if (ro.Government != gAnarchy) {
templateOp("Change", xTreasurySection + 48, 22, 0x0000C0, 0x0080C0);
const QString s = formatPhrase(
taxSum >= 0 ? QStringLiteral("MONEYGAINPOS") : QStringLiteral("MONEYGAINNEG"),
{ QString::number(taxSum) });
loweredTextOut(canvas, -1, texture, xTreasurySection + 48 + 15, 18, s);
}
// research section
templateOp("Research", xResearchSection + 8, 1, 0xFF0000, 0x00FFE0);
int costFactor = 0;
if (myData->farTech != adNexus) {
if (ro.ResearchTech < 0)
costFactor = 2;
else if (ro.ResearchTech == adMilitary || ro.Tech[ro.ResearchTech] == tsSeen)
costFactor = 1;
else if (IsFutureTech(ro.ResearchTech))
costFactor = ro.Government == gFuture ? 4 : 8;
else
costFactor = 2;
int techCost = 0;
ClientTools::server(sGetTechCost, ClientTools::me, 0, &techCost);
costFactor *= 22; // length of progress bar
paintRelativeProgressBar(canvas, 2, xResearchSection + 48 + 1, 26, costFactor, trueResearch, scienceSum,
techCost, true, texture);
QString s;
if (ro.ResearchTech < 0) {
s = phrases[QStringLiteral("SCIENCE")];
} else if (ro.ResearchTech == adMilitary) {
s = phrases[QStringLiteral("INITUNIT")];
} else {
s = phrases.lookup(QStringLiteral("ADVANCES"), ro.ResearchTech);
if (IsFutureTech(ro.ResearchTech))
s += QStringLiteral(" %1").arg(ro.Tech[ro.ResearchTech] >= 1 ? ro.Tech[ro.ResearchTech] + 1 : 1);
}
loweredTextOut(canvas, -1, texture, xResearchSection + 48, 0, s);
}
if (myData->farTech != adNexus && scienceSum > 0) {
templateOp("Change", xResearchSection + 48 + costFactor + 11, 22, 0x0000C0, 0x0080C0);
loweredTextOut(canvas, -1, texture, xResearchSection + 48 + costFactor + 26, 18,
formatPhrase(QStringLiteral("TECHGAIN"), { QString::number(scienceSum) }));
}
}
if (clientMode != cEditMap) {
canvas.font().assign(UniFont[static_cast<std::size_t>(FontType::Caption)]);
const QString s = turnToString(ro.Turn);
risedTextOut(canvas, 40 + (xTreasurySection - 40 - biColorTextWidth(canvas, s)) / 2, 6, s);
canvas.font().assign(UniFont[static_cast<std::size_t>(FontType::Normal)]);
}
canvas.end();
invalidateRect(0, 0, cw, TopBarHeight);
}
void MainScreen::paintZoomedTile(Dpi::Bitmap &dst, int x, int y, int loc)
{
IsoEngine::IsoMap &map = *m_noMapPanel;
const int xxt = map.xxt;
const int yyt = map.yyt;
Dpi::Canvas &canvas = dst.canvas();
const auto terrainSprite = [&](int xDst, int yDst, int xSrc, int ySrc) {
sprite(canvas, *map.hGrTerrain, x + xDst, y + yDst, xxt * 2, yyt * 3, 1 + xSrc * (xxt * 2 + 1),
1 + ySrc * (yyt * 3 + 1));
};
const auto terrainSprite4 = [&](int xSrc, int ySrc) {
sprite(canvas, *map.hGrTerrain, x + xxt, y + yyt + 2, xxt * 2, yyt * 2 - 2, 1 + xSrc * (xxt * 2 + 1),
3 + yyt + ySrc * (yyt * 3 + 1));
sprite(canvas, *map.hGrTerrain, x + 4, y + 2 * yyt, xxt * 2 - 4, yyt * 2, 5 + xSrc * (xxt * 2 + 1),
1 + yyt + ySrc * (yyt * 3 + 1));
sprite(canvas, *map.hGrTerrain, x + xxt * 2, y + 2 * yyt, xxt * 2 - 4, yyt * 2, 1 + xSrc * (xxt * 2 + 1),
1 + yyt + ySrc * (yyt * 3 + 1));
sprite(canvas, *map.hGrTerrain, x + xxt, y + yyt * 3, xxt * 2, yyt * 2 - 2, 1 + xSrc * (xxt * 2 + 1),
1 + yyt + ySrc * (yyt * 3 + 1));
};
std::uint32_t tile = ClientTools::myMap[loc];
if (tile & fCity) {
tile |= ClientTools::myRO->Tech[adRailroad] >= tsApplicable ? static_cast<std::uint32_t>(fRR)
: static_cast<std::uint32_t>(fRoad);
bool supermarket = false;
if (tile & fOwned) {
int cix = ClientTools::myRO->nCity - 1;
while (cix >= 0 && ClientTools::myCity[cix].Loc != loc)
--cix;
Q_ASSERT(cix >= 0);
supermarket = cix >= 0 && ClientTools::myCity[cix].Built[imSupermarket] > 0;
}
tile |= supermarket ? static_cast<std::uint32_t>(tiFarm) : static_cast<std::uint32_t>(tiIrrigation);
}
const std::uint32_t terrain = tile & fTerrain;
if (terrain >= fForest)
terrainSprite4(2, 2);
else
terrainSprite4(static_cast<int>(terrain), 0);
if (terrain >= fForest) {
const int ySrc = terrain == fForest && IsoEngine::isJungle(loc / ClientTools::g.lx)
? 18
: 3 + 2 * static_cast<int>(terrain - fForest);
terrainSprite(xxt, 0, 6, ySrc);
terrainSprite(0, yyt, 3, ySrc);
terrainSprite(xxt * 2, yyt, 4, ySrc + 1);
terrainSprite(xxt, yyt * 2, 1, ySrc + 1);
}
// irrigation
switch (tile & fTerImp) {
case tiIrrigation:
terrainSprite(xxt, 0, 0, 12);
terrainSprite(xxt * 2, yyt, 0, 12);
break;
case tiFarm:
terrainSprite(xxt, 0, 1, 12);
terrainSprite(xxt * 2, yyt, 1, 12);
break;
default:
break;
}
// river/canal/road/railroad
if (tile & fRiver) {
terrainSprite(0, yyt, 2, 14);
terrainSprite(xxt, yyt * 2, 2, 14);
}
if (tile & fCanal) {
terrainSprite(xxt, 0, 7, 11);
terrainSprite(xxt, 0, 3, 11);
terrainSprite(xxt * 2, yyt, 7, 11);
terrainSprite(xxt * 2, yyt, 3, 11);
}
if (tile & fRR) {
terrainSprite(xxt * 2, yyt, 1, 10);
terrainSprite(xxt * 2, yyt, 5, 10);
terrainSprite(xxt, yyt * 2, 1, 10);
terrainSprite(xxt, yyt * 2, 5, 10);
} else if (tile & fRoad) {
terrainSprite(xxt * 2, yyt, 8, 9);
terrainSprite(xxt * 2, yyt, 5, 9);
terrainSprite(xxt, yyt * 2, 1, 9);
terrainSprite(xxt, yyt * 2, 5, 9);
}
if (tile & fPoll)
terrainSprite(xxt, yyt * 2, 6, 12);
// special
const int special = static_cast<int>((tile & fSpecial) >> 5);
if ((tile & (fTerrain | fSpecial)) == (fGrass | fSpecial1)) {
terrainSprite4(2, 1);
} else if (tile & fSpecial) {
if (terrain < fForest)
terrainSprite(0, yyt, static_cast<int>(terrain), special);
else if (terrain == fForest && IsoEngine::isJungle(loc / ClientTools::g.lx))
terrainSprite(0, yyt, 8, 17 + special);
else
terrainSprite(0, yyt, 8, 2 + static_cast<int>(terrain - fForest) * 2 + special);
} else if (tile & fDeadLands) {
terrainSprite4(6, 2);
terrainSprite(xxt, yyt, 8, 12 + static_cast<int>((tile >> 25) & 3));
}
// other improvements
switch (tile & fTerImp) {
case tiMine:
terrainSprite(xxt, 0, 2, 12);
break;
case tiFort:
terrainSprite(xxt, 0, 7, 12);
terrainSprite(xxt, 0, 3, 12);
break;
case tiBase:
terrainSprite(xxt, 0, 4, 12);
break;
default:
break;
}
}
} // namespace Term
} // namespace Cevo
+944
View File
@@ -0,0 +1,944 @@
// TMainScreen.InitTurn, NextUnit, EndTurn, ZoomToCity and CityClosed (Term.pas).
//
// PORT STATUS / deviations:
// - sound (Play, SoundPreload) is not ported;
// - the menu check marks the original reads (mRepScreens, mWaitTurn, ...) are
// read from optionChecked, which the menus will keep in sync;
// - InitTurn's continuation of multi-turn goto/terrain enhancement needs
// MoveUnit (not ported) and is marked TODO.
#include "Term.MainScreen.h"
#include "Cevo/CevoScreenTools.h"
#include "Cevo/CevoTexture.h"
#include "Global.h"
#include "Messg.h"
#include <QApplication>
#include <QTimer>
namespace Cevo {
namespace Term {
namespace {
struct AdvBookIconEntry {
int adv;
int icon;
};
constexpr std::array<AdvBookIconEntry, 16> AdvBookIcon = { {
{ adPolytheism, woZeus },
{ adBronzeWorking, woColossus },
{ adMapMaking, woLighthouse },
{ adPoetry, imTheater },
{ adMonotheism, woMich },
{ adPhilosophy, woLeo },
{ adTheoryOfGravity, woNewton },
{ adSteel, woEiffel },
{ adDemocracy, woLiberty },
{ adAutomobile, imHighways },
{ adSanitation, imSewer },
{ adElectronics, woHoover },
{ adNuclearFission, woManhattan },
{ adRecycling, imRecycling },
{ adComputers, imResLab },
{ adSpaceFlight, woMir },
} };
// Fills a (Pascal or Qt style) phrase template with arguments.
QString formatPhraseText(const QString &text, const QStringList &args)
{
QString result = phraseToQtFormat(text);
for (const QString &arg : args)
result = result.arg(arg);
return result;
}
bool isResourceUnused(int cix, int needFood, int needProd)
{
TCityAreaInfo cityAreaInfo;
ClientTools::server(sGetCityAreaInfo, ClientTools::me, cix, &cityAreaInfo);
for (int dy = -3; dy <= 3; ++dy) {
for (int dx = -3; dx <= 3; ++dx) {
if (((dx + dy) & 1) == 0 && dx * dx * dy * dy < 81) {
const int fix = ((dy + 3) << 2) + ((dx + 3) >> 1);
if ((ClientTools::myCity[cix].Tiles & (1u << fix)) == 0 // not used yet
&& cityAreaInfo.Available[fix] == faAvailable) { // usable
TTileInfo tileInfo;
tileInfo.ExplCity = cix;
ClientTools::server(sGetHypoCityTileInfo, ClientTools::me,
ClientTools::dLoc(ClientTools::myCity[cix].Loc, dx, dy), &tileInfo);
if (tileInfo.Food >= needFood && tileInfo.Prod >= needProd)
return true;
}
}
}
}
return false;
}
} // namespace
void MainScreen::initTurn(int newPlayer)
{
TNewGameData &g = ClientTools::g;
const auto clearBitmap = [](Dpi::Bitmap &bitmap) {
Dpi::Canvas &canvas = bitmap.canvas();
canvas.brush().setColor(Qt::black);
canvas.fillRect(QRect(0, 0, bitmap.width(), bitmap.height()));
canvas.brush().setStyle(Qt::NoBrush);
canvas.end();
};
const std::array<ButtonC *, 5> mapButtons = { m_mapBtn0, m_mapBtn1, m_mapBtn4, m_mapBtn5, m_mapBtn6 };
if (ClientTools::isMultiPlayerGame() && newPlayer != ClientTools::me) {
m_unitInfoBtn->setVisible(false);
m_unitBtn->setVisible(false);
m_terrainBtn->setVisible(false);
m_eot->setVisible(false);
}
if (ClientTools::isMultiPlayerGame() && newPlayer != ClientTools::me
&& (g.RO[0]->Happened & phShipComplete) == 0) { // inter player screen
for (ButtonC *button : mapButtons)
button->setVisible(false);
ClientTools::me = -1;
MainTexture->setAge(-1);
clearBitmap(m_panel);
clearBitmap(m_topBar);
update();
const QString s = turnToString(g.RO[0]->Turn);
if (supervising)
simpleMessage(formatPhrase(QStringLiteral("SUPERTURN"), { s }));
else
simpleMessage(Tribes::tribe[static_cast<std::size_t>(newPlayer)]->tPhrase(QStringLiteral("TURN")).arg(s));
}
for (ButtonC *button : mapButtons)
button->setVisible(true);
ClientTools::itsMeAgain(newPlayer);
const int me = ClientTools::me;
const TPlayerContext &ro = *ClientTools::myRO;
myData = static_cast<PersistentData *>(g.RO[newPlayer]->Data);
if (me == 0 && (ro.Turn == 0 || clientMode == cResume))
update(); // colorize empty space
if (!supervising) {
age = ClientTools::getAge(me);
if (MainTexture->age() != age) {
MainTexture->setAge(age);
m_eot->update(); // has visible background parts in its bounds
}
if (clientMode == cMovieTurn)
m_eot->setButtonIndex(eotCancel);
else if (clientMode < scContact)
m_eot->setButtonIndex(eotGray);
else
m_eot->setButtonIndex(eotBackToNego);
} else {
age = 0;
MainTexture->setAge(-1);
m_eot->setButtonIndex(clientMode == cMovieTurn ? eotCancel : eotBlinkOn);
}
// TODO: InitCityMark(MainTexture) - the city mark sprite is not ported.
if (m_cityDlg)
m_cityDlg->checkAge();
if (m_natStatDlg)
m_natStatDlg->checkAge();
if (m_unitStatDlg)
m_unitStatDlg->checkAge();
if (m_helpDlg)
m_helpDlg->difficulty = g.Difficulty[me];
IsoEngine::unFocus = -1;
m_markCityLoc = -1;
IsoEngine::blinkOn = false;
m_blinkTime = -1;
m_tracking = false;
m_turnComplete = false;
if (toldSlavery < 0 || ((toldSlavery == 1) != (ro.Wonder[woPyramids].EffectiveOwner >= 0))) {
toldSlavery = ro.Wonder[woPyramids].EffectiveOwner >= 0 ? 1 : 0;
for (int p1 = 0; p1 < nPl; ++p1) {
Tribes::Tribe *tribe = Tribes::tribe[static_cast<std::size_t>(p1)].get();
if (tribe && tribe->mixSlaves >= 0) { // replace unit picture
Tribes::ModelPictureInfo picture;
picture.mix = tribe->mixSlaves;
picture.pix = toldSlavery == 1 ? pixSlaves : pixNoSlaves;
picture.hash = 0;
picture.grName = QStringLiteral("StdUnits");
tribe->setModelPicture(picture, true);
}
}
}
if (!supervising && clientMode == cTurn) {
for (int cix = 0; cix < ro.nCity; ++cix) {
TCity &city = ClientTools::myCity[cix];
if (city.Loc >= 0 && (ro.Turn == 0 || (city.Flags & chFounded) != 0))
city.Status = (city.Status & ~csResourceWeightsMask) | (3 << 4);
// new city, set to maximum growth
}
}
if (clientMode == cTurn || clientMode == cContinue)
ClientTools::cityOptimizer_BeginOfTurn(); // maybe peace was made or has ended
ClientTools::sumCities(taxSum, scienceSum);
if (clientMode == cMovieTurn) {
m_unitInfoBtn->setVisible(false);
m_unitBtn->setVisible(false);
m_terrainBtn->setVisible(false);
m_eot->setToolTip(phrases[QStringLiteral("BTN_STOP")]);
m_eot->setVisible(true);
} else if (clientMode < scContact) {
m_unitInfoBtn->setVisible(IsoEngine::unFocus >= 0);
m_unitBtn->setVisible(IsoEngine::unFocus >= 0);
checkTerrainBtnVisible();
m_turnComplete = supervising;
m_eot->setToolTip(phrases[QStringLiteral("BTN_ENDTURN")]);
m_eot->setVisible(ClientTools::server(sTurn - sExecute, me, 0, nullptr) >= rExecuted);
} else {
m_unitInfoBtn->setVisible(false);
m_unitBtn->setVisible(false);
m_terrainBtn->setVisible(false);
m_eot->setToolTip(phrases[QStringLiteral("BTN_NEGO")]);
m_eot->setVisible(true);
}
setTroopLoc(-1);
m_mapValid = false;
int newAgeCenterTo = 0;
if (((ro.Turn == 0 && !supervising) || ClientTools::isMultiPlayerGame() || clientMode == cResume)
&& ro.nCity > 0) {
int loc1 = ClientTools::myCity[0].Loc;
if (clientMode == cTurn && ro.Turn == 0) {
// move city out of center to not be covered by welcome screen
const int dx = std::min(5, m_mapWidth / (m_mainMap->xxt * 5));
const int dy = std::min(5, m_mapHeight / (m_mainMap->yyt * 5));
if (loc1 >= g.lx * g.ly / 2) {
newAgeCenterTo = -1;
loc1 = ClientTools::dLoc(loc1, -dx, -dy);
} else {
newAgeCenterTo = 1;
loc1 = ClientTools::dLoc(loc1, -dx, dy);
}
}
centre(loc1);
}
applyToVisibleForms(FormAction::Enable);
bool showCityList = false;
bool updatePanel = false;
int newGovAvailable = -1;
// The rest of the turn start is skipped by the early exits below (game end / extinct).
const auto finishEarly = [this] { m_turnComplete = true; };
if (clientMode != cResume) {
paintAll();
if ((ro.Happened & phChangeGov) != 0 && ro.NatBuilt[imPalace] > 0)
impImage(m_panel.canvas(), width() - XPalace, YPalace, imPalace, gAnarchy);
// first turn after anarchy -- don't show despotism palace!
updateNow();
applyToVisibleForms(FormAction::Update);
MessgEx::MessgExDlg &dlg = messgExDlg();
if ((ro.Happened & phGameEnd) != 0) { // game ended
int winners = 0;
if ((ro.Happened & phExtinct) != 0) {
dlg.openSound = QStringLiteral("MSG_GAMEOVER");
dlg.messageText = Tribes::tribe[static_cast<std::size_t>(me)]->tPhrase(QStringLiteral("GAMEOVER"));
dlg.iconKind = MessgEx::MessageIconKind::BigIcon;
dlg.iconIndex = 8;
} else if ((ro.Happened & phShipComplete) != 0) {
for (int p1 = 0; p1 < nPl; ++p1) {
if (((1 << p1) & ro.Alive) != 0) {
winners |= 1 << p1;
for (int i = 0; i < nShipPart; ++i) {
if (ro.Ship[p1].Parts[i] < ShipNeed[i])
winners &= ~(1 << p1);
}
}
}
Q_ASSERT(winners != 0);
if ((winners & (1 << me)) != 0) {
QString s;
for (int p1 = 0; p1 < nPl; ++p1) {
if (p1 != me && ((1 << p1) & winners) != 0) {
const QString shortName =
Tribes::tribe[static_cast<std::size_t>(p1)]->tPhrase(QStringLiteral("SHORTNAME"));
s = s.isEmpty() ? shortName
: formatPhrase(QStringLiteral("SHAREDWIN_CONCAT"), { s, shortName });
}
}
dlg.openSound = QStringLiteral("MSG_YOUWIN");
dlg.messageText = Tribes::tribe[static_cast<std::size_t>(me)]->tPhrase(QStringLiteral("MYSPACESHIP"));
if (!s.isEmpty())
dlg.messageText += QLatin1Char('\\') + formatPhrase(QStringLiteral("SHAREDWIN"), { s });
dlg.iconKind = MessgEx::MessageIconKind::BigIcon;
dlg.iconIndex = 9;
} else {
Q_ASSERT(me == 0);
dlg.openSound = QStringLiteral("MSG_GAMEOVER");
dlg.messageText.clear();
for (int p1 = 0; p1 < nPl; ++p1) {
if ((winners & (1 << p1)) != 0)
dlg.messageText +=
Tribes::tribe[static_cast<std::size_t>(p1)]->tPhrase(QStringLiteral("SPACESHIP1"));
}
dlg.messageText += QLatin1Char('\\') + phrases[QStringLiteral("SPACESHIP2")];
dlg.iconKind = MessgEx::MessageIconKind::EnemyShipComplete;
}
} else { // time up
Q_ASSERT(me == 0);
dlg.openSound = QStringLiteral("MSG_GAMEOVER");
dlg.messageText = !supervising ? Tribes::tribe[static_cast<std::size_t>(me)]->tPhrase(
QStringLiteral("TIMEUP"))
: phrases[QStringLiteral("TIMEUPSUPER")];
dlg.iconKind = MessgEx::MessageIconKind::Imp;
dlg.iconIndex = 22;
}
dlg.kind = MessageKind::Ok;
dlg.showModal();
if ((ro.Happened & phExtinct) == 0 && (ro.Happened & phShipComplete) == 0)
diaDlg().showNewContentCharts(WindowMode::Modal);
finishEarly();
return;
}
if (!supervising && ((1 << me) & ro.Alive) == 0) {
finishEarly();
return;
}
if (clientMode == cContinue && (dipMem[static_cast<std::size_t>(me)].sentCommand & 0xFF0F) == scContact) {
// contact was refused
if (ro.Treaty[dipMem[static_cast<std::size_t>(me)].pContact] >= trPeace)
contactRefused(dipMem[static_cast<std::size_t>(me)].pContact, QStringLiteral("FRREJECTED"));
else
MessgEx::soundMessageEx(Tribes::tribe[static_cast<std::size_t>(dipMem[static_cast<std::size_t>(me)].pContact)]->tPhrase(
QStringLiteral("FRREJECTED")),
QStringLiteral("NEGO_REJECTED"));
}
if (!supervising && age > myData->toldAge && (age > 0 || clientMode != cMovieTurn)) {
Tribes::Tribe &tribe = *Tribes::tribe[static_cast<std::size_t>(me)];
if (age == 0) {
if (phrases2FallenBackToEnglish)
dlg.messageText = tribe.tPhrase(QStringLiteral("AGE0"))
.arg(turnToString(ro.Turn))
.arg(Tribes::cityName(ClientTools::myCity[0].ID));
else
dlg.messageText = tribe.tString(phraseToQtFormat(phrases2[QStringLiteral("AGE0")]))
.arg(turnToString(ro.Turn));
} else {
dlg.messageText =
tribe.tPhrase(QStringLiteral("AGE%1").arg(age)).arg(turnToString(ro.Turn));
}
dlg.iconKind = MessgEx::MessageIconKind::Age;
dlg.iconIndex = age;
dlg.kind = MessageKind::Ok;
dlg.centerTo = newAgeCenterTo;
dlg.openSound = QStringLiteral("AGE_%1").arg(age);
QApplication::processEvents();
dlg.showModal();
myData->toldAge = age;
if (age > 0)
myData->toldTech[AgePreq[age]] = static_cast<std::int8_t>(ro.Tech[AgePreq[age]]);
}
if (myData->toldAlive != ro.Alive) {
for (int p1 = 0; p1 < nPl; ++p1) {
if (((myData->toldAlive - ro.Alive) & (1 << p1)) != 0) {
dlg.openSound = QStringLiteral("MSG_EXTINCT");
dlg.messageText = Tribes::tribe[static_cast<std::size_t>(p1)]
->tPhrase(QStringLiteral("EXTINCT"))
.arg(turnToString(ro.Turn));
if (ro.Alive == (1 << me))
dlg.messageText += phrases[QStringLiteral("EXTINCTALL")];
dlg.kind = MessageKind::Ok;
dlg.iconKind = MessgEx::MessageIconKind::Imp;
dlg.iconIndex = 21;
dlg.showModal();
}
}
if (clientMode != cMovieTurn && !supervising)
diaDlg().showNewContentCharts(WindowMode::Modal);
}
// tell changes of own credibility
if (!supervising) {
if (roughCredibility(ro.Credibility) != roughCredibility(myData->toldOwnCredibility)) {
const QString s = roughCredibility(ro.Credibility) > roughCredibility(myData->toldOwnCredibility)
? phrases[QStringLiteral("CREDUP")]
: phrases[QStringLiteral("CREDDOWN")];
MessgEx::tribeMessage(me,
formatPhraseText(s, { phrases.lookup(QStringLiteral("CREDIBILITY"),
roughCredibility(ro.Credibility)) }),
QString());
}
myData->toldOwnCredibility = ro.Credibility;
}
for (int i = 0; i < nWonder; ++i) {
bool ownWonder = false;
for (int cix = 0; cix < ro.nCity; ++cix) {
if (ClientTools::myCity[cix].Loc >= 0 && ClientTools::myCity[cix].ID == ro.Wonder[i].CityID) {
ownWonder = true;
break;
}
}
const QString wonderName = phrases.lookup(QStringLiteral("IMPROVEMENTS"), i);
const auto wonderDialog = [&](const QString &sound, const QString &text) {
dlg.openSound = sound;
dlg.messageText = text;
dlg.kind = MessageKind::OkHelp;
dlg.helpKind = Help::LinkCategory::Imp;
dlg.helpNo = i;
dlg.iconKind = MessgEx::MessageIconKind::Imp;
dlg.iconIndex = i;
dlg.showModal();
};
if (ro.Wonder[i].CityID != myData->toldWonders[static_cast<std::size_t>(i)].CityID) {
if (ro.Wonder[i].CityID == WonderDestroyed) { // tell about destroyed wonders
wonderDialog(QStringLiteral("WONDER_DESTROYED"),
formatPhraseText(phrases[QStringLiteral("WONDERDEST")], { wonderName }));
} else {
if (i == woManhattan) {
if (ro.Wonder[i].EffectiveOwner > me)
myData->coldWarStart = ro.Turn - 1;
else
myData->coldWarStart = ro.Turn;
}
if (!ownWonder) { // tell about newly built wonders
QString sound;
QString s;
if (i == woManhattan) {
sound = QStringLiteral("MSG_COLDWAR");
s = Tribes::tribe[static_cast<std::size_t>(ro.Wonder[i].EffectiveOwner)]->tPhrase(
QStringLiteral("COLDWAR"));
} else if (ro.Wonder[i].EffectiveOwner >= 0) {
sound = QStringLiteral("WONDER_BUILT");
s = Tribes::tribe[static_cast<std::size_t>(ro.Wonder[i].EffectiveOwner)]->tPhrase(
QStringLiteral("WONDERBUILT"));
} else {
sound = QStringLiteral("MSG_DEFAULT");
s = phraseToQtFormat(phrases[QStringLiteral("WONDERBUILTEXP")]);
// already expired when built
}
wonderDialog(sound, formatPhraseText(s, { wonderName, Tribes::cityName(ro.Wonder[i].CityID) }));
}
}
} else if (ro.Wonder[i].EffectiveOwner != myData->toldWonders[static_cast<std::size_t>(i)].EffectiveOwner
&& ro.Wonder[i].CityID > WonderDestroyed) {
if (ro.Wonder[i].EffectiveOwner < 0) {
if (i != woMir) // tell about expired wonders
wonderDialog(QStringLiteral("WONDER_EXPIRED"),
formatPhraseText(phrases[QStringLiteral("WONDEREXP")],
{ wonderName, Tribes::cityName(ro.Wonder[i].CityID) }));
} else if (myData->toldWonders[static_cast<std::size_t>(i)].EffectiveOwner >= 0 && !ownWonder) {
// tell about capture of wonders
wonderDialog(QStringLiteral("WONDER_CAPTURED"),
formatPhraseText(Tribes::tribe[static_cast<std::size_t>(ro.Wonder[i].EffectiveOwner)]
->tPhrase(QStringLiteral("WONDERCAPT")),
{ wonderName, Tribes::cityName(ro.Wonder[i].CityID) }));
}
}
}
if (ro.Turn == myData->coldWarStart + ColdWarTurns) {
MessgEx::soundMessageEx(phrases[QStringLiteral("COLDWAREND")], QStringLiteral("MSG_DEFAULT"));
myData->coldWarStart = -ColdWarTurns - 1;
}
tellNewModels();
} // clientMode != cResume
myData->toldAlive = ro.Alive;
std::memcpy(myData->toldWonders.data(), ro.Wonder, sizeof(myData->toldWonders));
if (clientMode != cResume) { // tell about new techs
MessgEx::MessgExDlg &dlg = messgExDlg();
for (int ad = 0; ad < nAdv; ++ad) {
if (((ro.TestFlags & tfAllTechs) == 0
&& ((ro.Tech[ad] >= tsApplicable) != (myData->toldTech[static_cast<std::size_t>(ad)] >= tsApplicable)))
|| (IsFutureTech(ad) && ro.Tech[ad] != myData->toldTech[static_cast<std::size_t>(ad)])) {
if (gameMode != cMovie)
dlg.openSound = QStringLiteral("NEWADVANCE_%1").arg(age);
QString item2 = phrases.lookup(QStringLiteral("ADVANCES"), ad);
if (IsFutureTech(ad))
item2 += QStringLiteral(" %1").arg(ro.Tech[ad]);
dlg.messageText = formatPhrase(QStringLiteral("RESEARCH_GENERAL"), { item2 });
dlg.kind = MessageKind::OkHelp;
dlg.helpKind = Help::LinkCategory::Adv;
dlg.helpNo = ad;
dlg.iconKind = MessgEx::MessageIconKind::Book;
dlg.iconIndex = -1;
for (const AdvBookIconEntry &entry : AdvBookIcon) {
if (entry.adv == ad)
dlg.iconIndex = entry.icon;
}
dlg.showModal();
myData->toldTech[static_cast<std::size_t>(ad)] = static_cast<std::int8_t>(ro.Tech[ad]);
for (int i = gMonarchy; i < nGov; ++i) {
if (GovPreq[i] == ad)
newGovAvailable = i;
}
}
}
}
if (clientMode == cTurn) {
if ((ro.Happened & phTech) != 0 && myData->farTech != adNexus)
chooseResearch();
if ((ro.Happened & phChangeGov) != 0) {
modalSelectDlg().showNewContent(WindowMode::Modal, Select::ListKind::Government);
ClientTools::server(sSetGovernment, me, modalSelectDlg().result, nullptr);
ClientTools::cityOptimizer_BeginOfTurn();
updatePanel = true;
}
}
if (!supervising && (clientMode == cTurn || clientMode == cMovieTurn)) {
for (int cix = 0; cix < ro.nCity; ++cix)
ClientTools::myCity[cix].Status &= ~csToldBombard;
}
if ((clientMode == cTurn || clientMode == cMovieTurn) && ro.Government != gAnarchy) {
// tell what happened in cities
MessgEx::MessgExDlg &dlg = messgExDlg();
for (int wondersOnly = 1; wondersOnly >= 0; --wondersOnly) {
for (int cix = 0; cix < ro.nCity; ++cix) {
TCity &city = ClientTools::myCity[cix];
if (!(ro.Turn > 0 && city.Loc >= 0 && (city.Flags & chCaptured) == 0
&& ((wondersOnly != 0)
== ((city.Flags & chProduction) != 0 && (city.Project0 & cpImp) != 0
&& (city.Project0 & cpIndex) < nWonder))))
continue;
if (wondersOnly != 0) { // tell about newly built wonder
dlg.openSound = QStringLiteral("WONDER_BUILT");
dlg.messageText = formatPhraseText(
Tribes::tribe[static_cast<std::size_t>(me)]->tPhrase(QStringLiteral("WONDERBUILTOWN")),
{ phrases.lookup(QStringLiteral("IMPROVEMENTS"), city.Project0 & cpIndex),
Tribes::cityName(city.ID) });
dlg.kind = MessageKind::OkHelp;
dlg.helpKind = Help::LinkCategory::Imp;
dlg.helpNo = city.Project0 & cpIndex;
dlg.iconKind = MessgEx::MessageIconKind::Imp;
dlg.iconIndex = city.Project0 & cpIndex;
dlg.showModal();
}
if (!supervising && clientMode == cTurn) {
bool allowCityScreen = true;
if ((city.Status & 7) != 0 && (city.Project & (cpImp + cpIndex)) == cpImp + imTrGoods) {
if (myData->impOrder[static_cast<std::size_t>((city.Status & 7) - 1)][0] >= 0) {
if (ClientTools::autoBuild(cix, myData->impOrder[static_cast<std::size_t>((city.Status & 7) - 1)]))
allowCityScreen = false;
else if ((city.Flags & chProduction) != 0)
city.Flags = (city.Flags & ~chProduction) | chAllImpsMade;
} else {
city.Flags |= chTypeDel;
}
}
if ((city.Size >= NeedAqueductSize && ro.Tech[Imp[imAqueduct].Preq] < tsApplicable)
|| (city.Size >= NeedSewerSize && ro.Tech[Imp[imSewer].Preq] < tsApplicable))
city.Flags &= ~chNoGrowthWarning; // don't remind of unknown building
if ((city.Flags & chNoSettlerProd) == 0)
city.Status &= ~csToldDelay;
else if ((city.Status & csToldDelay) == 0)
city.Status |= csToldDelay;
else
city.Flags &= ~chNoSettlerProd;
if (ClientTools::hasSaveOption(optionChecked, ClientTools::soRepScreens)) {
if ((city.Flags & cityRepMask) != 0 && allowCityScreen) { // show what happened in cities
setTroopLoc(city.Loc);
m_markCityLoc = city.Loc;
panelPaint();
cityDlg().closeAction = CityScreen::CityCloseAction::None;
cityDlg().showNewContent(WindowMode::Modal, city.Loc, city.Flags & cityRepMask);
updatePanel = true;
}
} else if ((city.Flags & cityRepMask) != 0) {
showCityList = true;
}
}
}
}
}
if (clientMode == cTurn && newGovAvailable >= 0) {
MessgEx::MessgExDlg &dlg = messgExDlg();
dlg.messageText = formatPhrase(QStringLiteral("AUTOREVOLUTION"),
{ phrases.lookup(QStringLiteral("GOVERNMENT"), newGovAvailable) });
dlg.kind = MessageKind::YesNo;
dlg.iconKind = MessgEx::MessageIconKind::PureIcon;
dlg.iconIndex = 6 + newGovAvailable;
if (dlg.showModal() == Dpi::ModalResult::Ok)
ClientTools::server(sRevolution, me, 0, nullptr);
}
if (clientMode == cTurn || clientMode == cMovieTurn) {
if ((ro.Happened & phGliderLost) != 0)
MessgEx::contextMessage(phrases[QStringLiteral("GLIDERLOST")], QStringLiteral("MSG_DEFAULT"),
Help::LinkCategory::Model, 200);
if ((ro.Happened & phPlaneLost) != 0)
MessgEx::contextMessage(phrases[QStringLiteral("PLANELOST")], QStringLiteral("MSG_DEFAULT"),
Help::LinkCategory::Feature, mcFuel);
if ((ro.Happened & phPeaceEvacuation) != 0) {
for (int p1 = 0; p1 < nPl; ++p1) {
if (((1 << p1) & myData->peaceEvaHappened) != 0)
MessgEx::soundMessageEx(
Tribes::tribe[static_cast<std::size_t>(p1)]->tPhrase(QStringLiteral("WITHDRAW")),
QStringLiteral("MSG_DEFAULT"));
}
}
if ((ro.Happened & phPeaceViolation) != 0) {
for (int p1 = 0; p1 < nPl; ++p1) {
if (((1 << p1) & ro.Alive) != 0 && ro.EvaStart[p1] == ro.Turn)
MessgEx::soundMessageEx(Tribes::tribe[static_cast<std::size_t>(p1)]
->tPhrase(QStringLiteral("VIOLATION"))
.arg(turnToString(ro.Turn + PeaceEvaTurns - 1)),
QStringLiteral("MSG_WITHDRAW"));
}
}
tellNewContacts();
}
if (clientMode == cMovieTurn) {
updateNow();
} else if (clientMode == cTurn) {
if (updatePanel)
updateViews();
QApplication::processEvents();
if (!supervising) {
for (int uix = 0; uix < ro.nUn; ++uix) {
TUn &un = ClientTools::myUn[uix];
if (un.Loc < 0)
continue;
if ((un.Flags & unWithdrawn) != 0)
un.Status = 0;
if (un.Health == 100)
un.Status &= ~IsoEngine::usRecover;
if (un.Master >= 0 || ClientTools::unitExhausted(uix))
un.Status &= ~usWaiting;
else
un.Status |= usWaiting;
checkToldNoReturn(uix);
// TODO: continuing multi-turn goto (GetMoveAdvice + MoveUnit) and terrain enhancement
// (ProcessEnhancement) needs MoveUnit, which is not ported yet.
}
}
}
m_haveStrategyAdvice = false;
m_goOnPhase = true;
if (supervising || gameMode == cMovie) {
setTroopLoc(-1);
paintAll();
} else {
if (clientMode >= scContact)
setUnFocus(-1);
else
nextUnit(-1, false);
if (IsoEngine::unFocus < 0) {
unStartLoc = -1;
if (ClientTools::isMultiPlayerGame() || clientMode == cResume) {
if (ro.nCity > 0)
focusOnLoc(ClientTools::myCity[0].Loc);
else
focusOnLoc(g.lx * g.ly / 2);
}
setTroopLoc(-1);
panelPaint();
}
if (showCityList)
listDlg().showNewContent(WindowMode::Persistent, Select::ListKind::CityEvents);
}
}
void MainScreen::nextUnit(int nearLoc, bool autoTurn)
{
if (clientMode >= scContact)
return;
const TPlayerContext &ro = *ClientTools::myRO;
TUn *myUn = ClientTools::myUn;
IsoEngine::destinationMarkOn = false;
paintDestination();
int newFocus = -1;
for (int gotoOnly = m_goOnPhase ? 1 : 0; gotoOnly >= 0; --gotoOnly) {
newFocus = -1;
double dist = 0;
for (int i = 1; i <= ro.nUn; ++i) {
const int uix = (IsoEngine::unFocus + i) % ro.nUn;
if (myUn[uix].Loc >= 0 && myUn[uix].Job == jNone
&& (myUn[uix].Status & (IsoEngine::usStay | IsoEngine::usRecover | usWaiting)) == usWaiting
&& (gotoOnly == 0 || (myUn[uix].Status & IsoEngine::usGoto) != 0)) {
if (nearLoc < 0) {
newFocus = uix;
break;
}
const double testDist = ClientTools::distance(nearLoc, myUn[uix].Loc);
if (newFocus < 0 || testDist < dist) {
newFocus = uix;
dist = testDist;
}
}
}
if (gotoOnly != 0) {
if (newFocus < 0)
m_goOnPhase = false;
else
break;
}
}
if (newFocus >= 0) {
setUnFocus(newFocus);
setTroopLoc(myUn[newFocus].Loc);
focusOnLoc(m_troopLoc, flRepaintPanel);
} else if (autoTurn && !ClientTools::hasSaveOption(optionChecked, ClientTools::soWaitTurn)) {
m_turnComplete = true;
setUnFocus(-1);
setTroopLoc(-1);
QTimer::singleShot(0, this, [this] { endTurn(); });
} else {
// TODO: Play('TURNEND') when the turn becomes complete (sound is not ported).
m_turnComplete = true;
setUnFocus(-1);
setTroopLoc(-1);
panelPaint();
}
}
bool MainScreen::endTurn(bool wasSkipped)
{
TNewGameData &g = ClientTools::g;
const int me = ClientTools::me;
if (clientMode >= scDipOffer)
return false;
if (supervising && me != 0) {
applyToVisibleForms(FormAction::Close);
ClientTools::itsMeAgain(0);
}
const TPlayerContext &ro = *ClientTools::myRO;
TUn *myUn = ClientTools::myUn;
ClientTools::cityOptimizer_EndOfTurn();
if (!wasSkipped) { // check warnings
// need to move planes home?
for (int uix = 0; uix < ro.nUn; ++uix) {
TUn &un = myUn[uix];
if (un.Loc >= 0 && ClientTools::myModel[un.mix].Domain == dAir && (un.Status & usToldNoReturn) == 0
&& un.Master < 0 && (ClientTools::myMap[un.Loc] & fCity) == 0
&& (ClientTools::myMap[un.Loc] & fTerImp) != static_cast<std::uint32_t>(tiBase)) {
TPlaneReturnData planeReturnData;
planeReturnData.Fuel = un.Fuel;
planeReturnData.Loc = un.Loc;
planeReturnData.Movement = 0; // end turn without further movement?
if (ClientTools::server(sGetPlaneReturn, me, uix, &planeReturnData) == eNoWay) {
int centerLoc = un.Loc + g.lx * 6;
// centering the unit itself would make it covered by the query dialog
while (centerLoc >= g.lx * g.ly)
centerLoc -= g.lx * 2;
centre(centerLoc);
setTroopLoc(-1);
paintAll();
const QString msgItem = ClientTools::myModel[un.mix].Kind == mkSpecial_Glider
? QStringLiteral("LOWFUEL_GLIDER")
: QStringLiteral("LOWFUEL");
if (MessgEx::simpleQuery(MessageKind::YesNo, phrases[msgItem], QStringLiteral("WARNING_LOWSUPPORT"))
!= Dpi::ModalResult::Ok) {
setUnFocus(uix);
setTroopLoc(un.Loc);
panelPaint();
return false;
}
myUn[uix].Status |= usToldNoReturn;
}
}
}
if (!supervising && (ro.TestFlags & tfImmImprove) == 0 && ro.Government != gAnarchy
&& ro.Money + taxSum < 0 && ro.TaxRate < 100) { // low funds!
MessgEx::MessgExDlg &dlg = messgExDlg();
dlg.openSound = QStringLiteral("WARNING_LOWFUNDS");
dlg.messageText = phrases[QStringLiteral("LOWFUNDS")];
dlg.kind = MessageKind::YesNo;
dlg.iconKind = MessgEx::MessageIconKind::Imp;
dlg.iconIndex = imTrGoods;
if (dlg.showModal() != Dpi::ModalResult::Ok)
return false;
}
if (ro.Government != gAnarchy) {
for (int cix = 0; cix < ro.nCity; ++cix) {
TCity &city = ClientTools::myCity[cix];
if (city.Loc < 0 || (city.Flags & chCaptured) != 0)
continue;
bool zoom = false;
TCityReport cityReport;
cityReport.HypoTiles = -1;
cityReport.HypoTax = -1;
cityReport.HypoLux = -1;
ClientTools::server(sGetCityReport, me, cix, &cityReport);
MessgEx::MessgExDlg &dlg = messgExDlg();
if (cityReport.Working - cityReport.Happy > (city.Size >> 1) && (city.Flags & chCaptured) <= 0x10000) {
dlg.openSound = QStringLiteral("WARNING_DISORDER");
const QString msgItem = (city.Status & csResourceWeightsMask) == 0
? QStringLiteral("DISORDER")
: QStringLiteral("DISORDER_UNREST");
dlg.messageText = formatPhrase(msgItem, { Tribes::cityName(city.ID) });
dlg.kind = MessageKind::YesNo;
zoom = dlg.showModal() != Dpi::ModalResult::Ok;
}
if (!zoom && city.Food + cityReport.FoodRep - cityReport.Eaten < 0) {
dlg.openSound = QStringLiteral("WARNING_FAMINE");
QString msgItem;
if ((city.Status & csResourceWeightsMask) == 0)
msgItem = QStringLiteral("FAMINE");
else if (cityReport.Deployed != 0 && isResourceUnused(cix, 1, 0))
msgItem = QStringLiteral("FAMINE_UNREST");
else
msgItem = QStringLiteral("FAMINE_TILES");
dlg.messageText = formatPhrase(msgItem, { Tribes::cityName(city.ID) });
dlg.kind = MessageKind::YesNo;
dlg.iconKind = MessgEx::MessageIconKind::Imp;
dlg.iconIndex = 22;
zoom = dlg.showModal() != Dpi::ModalResult::Ok;
}
if (!zoom && cityReport.ProdRep < cityReport.Support) {
dlg.openSound = QStringLiteral("WARNING_LOWSUPPORT");
QString msgItem;
if ((city.Status & csResourceWeightsMask) == 0)
msgItem = QStringLiteral("LOWSUPPORT");
else if (cityReport.Deployed != 0 && isResourceUnused(cix, 0, 1))
msgItem = QStringLiteral("LOWSUPPORT_UNREST");
else
msgItem = QStringLiteral("LOWSUPPORT_TILES");
dlg.messageText = formatPhrase(msgItem, { Tribes::cityName(city.ID) });
dlg.kind = MessageKind::YesNo;
dlg.iconKind = MessgEx::MessageIconKind::Imp;
dlg.iconIndex = 29;
zoom = dlg.showModal() != Dpi::ModalResult::Ok;
}
if (zoom) { // zoom to city
zoomToCity(city.Loc);
return false;
}
}
}
if ((ro.Happened & phTech) != 0 && ro.ResearchTech < 0 && myData->farTech != adNexus) {
if (!chooseResearch())
return false;
}
}
rememberPeaceViolation();
setUnFocus(-1);
for (int uix = 0; uix < ro.nUn; ++uix)
myUn[uix].Status &= usPersistent;
cityDlg().closeAction = CityScreen::CityCloseAction::None;
if (ClientTools::isMultiPlayerGame()) {
applyToVisibleForms(FormAction::Close); // close windows for next player
} else {
if (cityDlg().isVisible())
cityDlg().close();
if (unitStatDlg().isVisible())
unitStatDlg().close();
}
applyToVisibleForms(FormAction::Disable);
if (ClientTools::server(sTurn, m_pTurn, 0, nullptr) >= rExecuted) {
m_eot->setToolTip(phrases[m_jump[static_cast<std::size_t>(m_pTurn)] > 0 ? QStringLiteral("BTN_STOP")
: QStringLiteral("BTN_SKIP")]);
setTroopLoc(-1);
m_pTurn = -1;
m_pLogo = -1;
m_unitInfoBtn->setVisible(false);
m_unitBtn->setVisible(false);
m_terrainBtn->setVisible(false);
m_eot->setButtonIndex(eotCancel);
m_eot->setVisible(true);
m_mapValid = false;
panelPaint();
updateNow();
setClientMode(-1);
m_idle = false;
m_skipped = wasSkipped;
for (int p1 = 1; p1 < nPl; ++p1) {
if (g.RO[p1]) {
m_skipped = true; // don't show enemy moves in hotseat mode
break;
}
}
return true;
}
panelPaint();
return false;
}
void MainScreen::endNego()
{
if (negoDlg().isVisible())
negoDlg().close();
m_haveStrategyAdvice = false;
m_eot->setButtonIndex(eotCancel);
m_eot->setVisible(true);
panelPaint();
updateNow();
setClientMode(-1);
m_idle = false;
}
bool MainScreen::zoomToCity(int loc, bool nextUnitOnClose, int showEvent)
{
const bool result = (ClientTools::myMap[loc] & (fOwned | fSpiedOut)) != 0;
if (result) {
CityScreen::CityDlg &dlg = cityDlg();
if (clientMode >= scContact) {
dlg.closeAction = CityScreen::CityCloseAction::None;
dlg.restoreUnFocus = -1;
} else if (nextUnitOnClose) {
dlg.closeAction = CityScreen::CityCloseAction::StepFocus;
dlg.restoreUnFocus = -1;
} else if (!dlg.isVisible()) {
dlg.closeAction = CityScreen::CityCloseAction::RestoreFocus;
dlg.restoreUnFocus = IsoEngine::unFocus;
}
setUnFocus(-1);
setTroopLoc(loc);
m_markCityLoc = loc;
panelPaint();
dlg.showNewContent(WindowMode::Persistent, loc, static_cast<std::uint32_t>(showEvent));
}
return result;
}
void MainScreen::cityClosed(int activateUix, bool stepFocus, bool selectFocus)
{
if (supervising) {
setTroopLoc(-1);
panelPaint();
} else if (activateUix >= 0) {
setUnFocus(activateUix);
setTroopLoc(ClientTools::myUn[activateUix].Loc);
if (selectFocus)
focusOnLoc(m_troopLoc, flRepaintPanel);
else
panelPaint();
} else if (stepFocus) {
nextUnit(m_troopLoc, true);
} else {
setTroopLoc(-1);
panelPaint();
}
}
} // namespace Term
} // namespace Cevo
+780
View File
@@ -0,0 +1,780 @@
// 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.
//
// TMainScreen's window layer (Term.pas): controls, layout, the map view paint
// pipeline, scrolling and the helpers that locate tiles on screen.
//
// Deviations from the original, all caused by the move from direct GDI/LCL
// canvas painting to Qt's retained paintEvent:
// - the map is always repainted completely when the view moves (the original
// scrolled the previous picture with ScrollDC and only painted the exposed
// strips);
// - the unit "blink" tile of PaintLocTemp is kept in m_blinkTile and drawn on
// top of the map layer by paintEvent instead of being blitted onto the
// screen;
// - the shared global Offscreen/OffscreenUser handover is gone, the window
// owns its map buffer.
#include "Term.MainScreen.h"
#include "Cevo/CevoGraphicSet.h"
#include "Cevo/CevoScreenTools.h"
#include "Cevo/CevoTexture.h"
#include "Global.h"
#include <QApplication>
#include <QCloseEvent>
#include <QCursor>
#include <QPainter>
#include <QRect>
#include <QWheelEvent>
#include <algorithm>
namespace Cevo {
namespace Term {
namespace {
constexpr int ScrollBarWidth = 16;
constexpr int BrushTypeCount = 26;
QString controlsHint(int tag)
{
return phrases.lookup(QStringLiteral("CONTROLS"), (tag & 0xFF) - 1);
}
} // namespace
void MainScreen::createControls()
{
const auto makeButtonB = [this](int tag, int index, bool permanent) {
auto *button = new ButtonB(this);
button->setProperty("tag", tag);
button->setButtonIndex(index);
button->setPermanent(permanent);
button->setVisible(false);
if ((tag & 0xFF) != 0)
button->setToolTip(controlsHint(tag));
return button;
};
const auto makeButtonC = [this](int tag, int index) {
auto *button = new ButtonC(this);
button->setProperty("tag", tag);
button->setVisible(false);
if ((tag & 0xFF) != 0)
button->setToolTip(controlsHint(tag));
if (index != 1)
index = static_cast<int>((mapOptionChecked >> (tag >> 8)) & 1) + 2;
button->setButtonIndex(index);
return button;
};
const auto makeArea = [this](const QString &hint) {
auto *area = new Area(this);
if (!phrases2FallenBackToEnglish)
area->setToolTip(hint);
return area;
};
m_unitBtn = makeButtonB(14, 2, false);
m_unitInfoBtn = makeButtonB(15, 7, false);
m_terrainBtn = makeButtonB(28, 3, false);
for (int i = 0; i < 4; ++i)
m_movieSpeedBtn[static_cast<std::size_t>(i)] = makeButtonB((i + 1) << 8, 24 + i, true);
m_mapBtn0 = makeButtonC(51, 2);
m_mapBtn1 = makeButtonC(291, 2);
m_mapBtn4 = makeButtonC(1028, 1);
m_mapBtn5 = makeButtonC(1328, 2);
m_mapBtn6 = makeButtonC(1541, 1);
m_eot = new EOTButton(this);
m_eot->setVisible(false);
m_menuArea = makeArea(phrases2[QStringLiteral("BTN_MENU")]);
m_menuArea->setGeometry(2, 1, 36, 36);
m_treasuryArea = makeArea(phrases2[QStringLiteral("TIP_TREASURY")]);
m_treasuryArea->resize(164, 36);
m_researchArea = makeArea(phrases[QStringLiteral("SCIENCE")]);
m_researchArea->resize(240, 36);
m_managementArea = makeArea(phrases2[QStringLiteral("BTN_MANAGE")]);
m_managementArea->resize(56, 40);
initButtons();
if (Templates)
m_eot->setTemplate(&Templates->data);
m_timer = new QTimer(this);
m_timer->setInterval(50);
connect(m_timer, &QTimer::timeout, this, &MainScreen::timerTick);
}
void MainScreen::resizeControls()
{
const int w = width();
const int h = height();
const int lx = ClientTools::g.lx;
const int ly = ClientTools::g.ly;
const int xxt = m_mainMap->xxt;
const int yyt = m_mainMap->yyt;
createOffscreen(m_offscreen, w, h);
m_mainMap->setOutput(&m_offscreen);
m_offscreen.canvas().font().assign(UniFont[static_cast<std::size_t>(FontType::Small)]);
m_smallScreen = w < 1024;
const int maxMapWidth = (lx * 2 - 3) * xxt; // avoids the same tile being visible left and right
if (w <= maxMapWidth) {
m_mapWidth = w;
m_mapOffset = 0;
} else {
m_mapWidth = maxMapWidth;
m_mapOffset = (w - m_mapWidth) / 2;
}
m_mapHeight = h - TopBarHeight - PanelHeight + Overlap;
m_panel.setSize(w, PanelHeight);
m_topBar.setSize(w, TopBarHeight);
const int miniFrame = (LxmaxXxx - ly) / 2;
m_xMidPanel = (lx + miniFrame) * 2 + 1;
m_xRightPanel = w - LeftPanelWidth - 10;
m_trPitch = clientMode == cEditMap ? 2 * xxt : 66;
m_xMini = miniFrame - 5;
m_yMini = (PanelHeight - 26 - LxmaxXxx) / 2 + miniFrame;
m_ywmax = (ly - m_mapHeight / yyt + 1) & ~1;
m_ywcenter = -((m_mapHeight - yyt * (ly - 1)) / (4 * yyt)) * 2;
// only for ywmax <= 0
if (m_ywmax <= 0)
m_yw = m_ywcenter;
else if (m_yw < 0)
m_yw = 0;
else if (m_yw > m_ywmax)
m_yw = m_ywmax;
m_unitInfoBtn->move(m_xMidPanel + 7 + 99, h - 29);
m_unitBtn->move(m_xMidPanel + 7 + 99 + 31, h - 29);
m_terrainBtn->move(m_xMidPanel + 7 + 99 + 62, h - 29);
m_movieSpeedBtn[0]->move(w / 2 - 62, h - 91);
m_movieSpeedBtn[1]->move(w / 2 - 62 + 29, h - 91);
m_movieSpeedBtn[2]->move(w / 2 - 62 + 2 * 29, h - 91);
m_movieSpeedBtn[3]->move(w / 2 - 62 + 3 * 29 + 12, h - 91);
m_eot->move(w - 62, h - 64);
if (m_verticalScrollBar) {
m_verticalScrollBar->setBorderSpacing(h - YTroop - 24, w - m_xRightPanel + 8, 8);
auto *scrollBar = m_verticalScrollBar->scrollBar();
scrollBar->setGeometry(m_xRightPanel + 10 - 14 - ScrollBarWidth, h - MidPanelHeight + 8, ScrollBarWidth,
h - m_verticalScrollBar->marginTop() - m_verticalScrollBar->marginBottom());
}
m_mapBtn0->move(m_xMini + lx - 44, h - 15);
m_mapBtn1->move(m_xMini + lx - 28, h - 15);
m_mapBtn5->move(m_xMini + lx - 12, h - 15);
m_mapBtn4->move(m_xMini + lx + 20, h - 15);
m_mapBtn6->move(m_xMini + lx + 36, h - 15);
m_treasuryArea->move(w / 2 - 172, 1);
m_researchArea->move(w / 2, 1);
m_managementArea->move(w - XPalace, TopBarHeight + m_mapHeight - Overlap + YPalace);
arrangeMidPanel();
if (m_repaintOnResize)
repaintAll();
setTroopLoc(m_troopLoc);
}
void MainScreen::arrangeMidPanel()
{
if (clientMode == cEditMap) {
m_xTroop = m_xMidPanel + 15;
} else {
const int xxt = m_mainMap->xxt;
if (supervising)
m_xTerrain = m_xMidPanel + 2 * xxt + 14;
else if (width() < 1280)
m_xTerrain = width() / 2 + (1280 - width()) / 3;
else
m_xTerrain = width() / 2;
m_xTroop = m_xTerrain + 2 * xxt + 12;
// not perfect but we assume almost no one is still playing on a 800x600 screen
if (m_smallScreen && !supervising)
m_xTroop = m_xRightPanel + 10 - 3 * 66 - ScrollBarWidth - 19 - 4;
}
m_trRow = (m_xRightPanel + 10 - m_xTroop - ScrollBarWidth - 19) / m_trPitch;
}
void MainScreen::resizeEvent(QResizeEvent *event)
{
DrawDlg::resizeEvent(event);
if (ClientTools::g.lx <= 0 || ClientTools::g.ly <= 0)
return;
if (m_lastResizeWidth == width() && m_lastResizeHeight == height())
return;
m_lastResizeWidth = width();
m_lastResizeHeight = height();
resizeControls();
}
void MainScreen::showEvent(QShowEvent *event)
{
DrawDlg::showEvent(event);
m_lastResizeWidth = -1;
if (ClientTools::g.lx > 0 && ClientTools::g.ly > 0) {
m_lastResizeWidth = width();
m_lastResizeHeight = height();
resizeControls(); // places the mini map correctly according to its size
}
m_timer->start();
}
void MainScreen::closeEvent(QCloseEvent *event)
{
DrawDlg::closeEvent(event);
if (!event->isAccepted())
return;
m_timer->stop();
}
// ---- painting ----
void MainScreen::invalidateRect(int left, int top, int right, int bottom)
{
const QRect rect(left, top, right - left, bottom - top);
m_dirty += rect;
update(rect);
}
void MainScreen::updateNow()
{
if (m_dirty.isEmpty())
return;
const QRegion region = m_dirty;
m_dirty = QRegion();
repaint(region);
}
void MainScreen::paintEvent(QPaintEvent *)
{
m_dirty = QRegion();
if (ClientTools::g.lx <= 0 || m_mapWidth <= 0)
return;
mainOffscreenPaint();
QPainter painter(this);
const int cw = width();
const int ch = height();
const int mapBottom = TopBarHeight + m_mapHeight - Overlap;
const auto blit = [&painter](int x, int y, const Dpi::Bitmap &src, int xSrc, int ySrc, int w, int h) {
if (w > 0 && h > 0)
painter.drawImage(QPoint(x, y), src.image(), QRect(xSrc, ySrc, w, h));
};
if (m_mapOffset > 0 || m_mapOffset + m_mapWidth < cw) { // pillarbox: make left and right border black
const QColor color = ClientTools::me < 0 ? QColor(Qt::black) : colorFromDelphi(EmptySpaceColor);
if (m_xMidPanel > m_mapOffset) {
painter.fillRect(QRect(0, TopBarHeight, m_mapOffset, m_mapHeight - Overlap), color);
} else {
painter.fillRect(QRect(0, TopBarHeight, m_xMidPanel, m_mapHeight - Overlap), color);
painter.fillRect(QRect(m_xMidPanel, TopBarHeight, m_mapOffset - m_xMidPanel, m_mapHeight), color);
}
if (m_xRightPanel < m_mapOffset + m_mapWidth) {
painter.fillRect(QRect(m_mapOffset + m_mapWidth, TopBarHeight,
cw - (m_mapOffset + m_mapWidth), m_mapHeight - Overlap),
color);
} else {
painter.fillRect(QRect(m_mapOffset + m_mapWidth, TopBarHeight,
m_xRightPanel - (m_mapOffset + m_mapWidth), m_mapHeight),
color);
painter.fillRect(QRect(m_xRightPanel, TopBarHeight, cw - m_xRightPanel, m_mapHeight - Overlap), color);
}
}
painter.save();
painter.setClipRect(QRect(m_mapOffset, TopBarHeight, m_mapWidth, m_mapHeight), Qt::IntersectClip);
blit(m_mapOffset, TopBarHeight, m_offscreen, 0, 0, m_mapWidth, m_mapHeight);
if (m_blinkTileValid)
painter.drawImage(m_blinkTilePos + QPoint(m_mapOffset, TopBarHeight), m_blinkTile.image());
painter.restore();
blit(0, 0, m_topBar, 0, 0, cw, TopBarHeight);
blit(0, mapBottom, m_panel, 0, 0, m_xMidPanel, Overlap);
blit(m_xRightPanel, mapBottom, m_panel, m_xRightPanel, 0, m_panel.width() - m_xRightPanel, Overlap);
blit(0, TopBarHeight + m_mapHeight, m_panel, 0, Overlap, m_panel.width(), PanelHeight - Overlap);
if (m_pLogo >= 0 && ClientTools::g.RO[m_pLogo] == nullptr && m_aiLogo[static_cast<std::size_t>(m_pLogo)])
painter.drawImage(QPoint(m_xRightPanel + 10 - (16 + 64), ch - PanelHeight),
m_aiLogo[static_cast<std::size_t>(m_pLogo)]->image());
}
void MainScreen::mainOffscreenPaint()
{
if (ClientTools::me < 0) {
Dpi::Canvas &canvas = m_offscreen.canvas();
canvas.brush().setColor(Qt::black);
canvas.fillRect(QRect(0, 0, m_mapWidth, m_mapHeight));
canvas.brush().setStyle(Qt::NoBrush);
return;
}
m_mainMap->setPaintBounds(0, 0, m_mapWidth, m_mapHeight);
if (m_mapValid && m_xwd == m_xw && m_ywd == m_yw)
return; // map window not moved
processRect(m_xw, m_yw, m_mapWidth / m_mainMap->xxt, m_mapHeight / m_mainMap->yyt, prPaint | prInvalidate);
invalidateRect(m_xMidPanel, TopBarHeight + m_mapHeight - Overlap, m_xRightPanel, TopBarHeight + m_mapHeight);
m_xwd = m_xw;
m_ywd = m_yw;
m_mapValid = true;
}
void MainScreen::miniMapPaint()
{
m_miniMap->paint(ClientTools::myMap, m_mapWidth, clientMode, m_mainMap->xxt, m_xwMini);
}
void MainScreen::paintAll()
{
mainOffscreenPaint();
m_xwMini = m_xw;
m_ywMini = m_yw;
miniMapPaint();
panelPaint();
}
void MainScreen::repaintAll()
{
if (!m_mainMap || ClientTools::g.lx <= 0 || m_mapWidth <= 0)
return;
invalidateRect(0, TopBarHeight, width(), TopBarHeight + m_mapHeight);
m_mapValid = false;
paintAll();
}
void MainScreen::invalidateMiniMap()
{
const int lx = ClientTools::g.lx;
const int ly = ClientTools::g.ly;
invalidateRect(m_xMini + 2, TopBarHeight + m_mapHeight - Overlap + m_yMini + 2, m_xMini + 2 + lx * 2,
TopBarHeight + m_mapHeight - Overlap + m_yMini + 2 + ly);
}
void MainScreen::paintAllMaps()
{
mainOffscreenPaint();
m_xwMini = m_xw;
m_ywMini = m_yw;
miniMapPaint();
copyMiniToPanel();
invalidateMiniMap();
}
void MainScreen::copyMiniToPanel()
{
const int lx = ClientTools::g.lx;
const int ly = ClientTools::g.ly;
const int xxt = m_mainMap->xxt;
const int yyt = m_mainMap->yyt;
bitBltBitmap(m_panel, m_xMini + 2, m_yMini + 2, lx * 2, ly, m_miniMap->bitmap, 0, 0);
Dpi::Canvas &canvas = m_panel.canvas();
if (m_markCityLoc >= 0) {
// TODO: the city mark sprite (InitCityMark/CityMark2) is not ported yet.
} else if (m_ywmax <= 0) {
frame(canvas, m_xMini + 2 + lx - m_mapWidth / (xxt * 2), m_yMini + 2, m_xMini + 1 + lx + m_mapWidth / (xxt * 2),
m_yMini + 2 + ly - 1, MainTexture->colorMark, MainTexture->colorMark);
} else {
frame(canvas, m_xMini + 2 + lx - m_mapWidth / (xxt * 2), m_yMini + 2 + m_yw,
m_xMini + 1 + lx + m_mapWidth / (xxt * 2), m_yMini + m_yw + m_mapHeight / yyt, MainTexture->colorMark,
MainTexture->colorMark);
}
}
void MainScreen::processRect(int x0, int y0, int nx, int ny, int options)
{
const int lx = ClientTools::g.lx;
const int xxt = m_mainMap->xxt;
const int yyt = m_mainMap->yyt;
int xl = nx * xxt + xxt;
int yl = ny * yyt + yyt * 2;
int xs = (x0 - m_xw) * (xxt * 2) + (y0 & 1) * xxt - lx * (xxt * 2);
// |xs+xl/2-MapWidth/2| -> min
while (std::abs(2 * (xs + lx * (xxt * 2)) + xl - m_mapWidth) < std::abs(2 * xs + xl - m_mapWidth))
xs += lx * (xxt * 2);
const int ys = (y0 - m_yw) * yyt - yyt;
if (xs + xl > m_mapWidth)
xl = m_mapWidth - xs;
if (ys + yl > m_mapHeight)
yl = m_mapHeight - ys;
if (xl <= 0 || yl <= 0)
return;
if (options & prPaint) {
if (options & prAutoBounds)
m_mainMap->setPaintBounds(xs, ys, xs + xl, ys + yl);
m_mainMap->paint(xs, ys, x0 + lx * y0, nx, ny, -1, -1);
m_blinkTileValid = false;
}
if (options & prInvalidate)
invalidateRect(m_mapOffset + xs, TopBarHeight + ys, m_mapOffset + xs + xl, TopBarHeight + ys + yl);
}
void MainScreen::paintLoc(int loc, int radius)
{
if (!m_mapValid)
return;
const int lx = ClientTools::g.lx;
const int yLoc = (loc + lx * 1024) / lx - 1024;
const int x0 = (loc + ((yLoc & 1) - 2 * radius + lx * 1024) / 2) % lx;
processRect(x0, yLoc - 2 * radius, 4 * radius + 1, 4 * radius + 1, prPaint | prAutoBounds | prInvalidate);
updateNow();
}
void MainScreen::paintLocBeforeMove(int fromLoc)
{
if (!m_mapValid)
return;
const int lx = ClientTools::g.lx;
const int yLoc = (fromLoc + lx * 1024) / lx - 1024;
const int x0 = (fromLoc + ((yLoc & 1) + lx * 1024) / 2) % lx;
processRect(x0, yLoc, 1, 1, prPaint | prAutoBounds);
}
void MainScreen::paintLocTemp(int loc, PaintLocTempStyle style)
{
if (!m_mapValid)
return;
const int lx = ClientTools::g.lx;
const int xxt = m_noMap->xxt;
const int yyt = m_noMap->yyt;
if (m_blinkTile.width() != 2 * xxt || m_blinkTile.height() != 3 * yyt) {
m_blinkTile.setSize(2 * xxt, 3 * yyt);
m_blinkTile.canvas().font().assign(UniFont[static_cast<std::size_t>(FontType::Small)]);
}
const int y0 = loc / lx;
const int x0 = loc % lx;
int xMap = (x0 - m_xw) * (xxt * 2) + (y0 & 1) * xxt - lx * (xxt * 2);
// |xMap+xxt-MapWidth/2| -> min
while (std::abs(2 * (xMap + lx * (xxt * 2)) + 2 * xxt - m_mapWidth) < std::abs(2 * xMap + 2 * xxt - m_mapWidth))
xMap += lx * (xxt * 2);
const int yMap = (y0 - m_yw) * yyt - yyt;
m_noMap->setOutput(&m_blinkTile);
m_noMap->setPaintBounds(0, 0, 2 * xxt, 3 * yyt);
m_noMap->paint(0, 0, loc, 1, 1, -1, -1, style == PaintLocTempStyle::Blink);
m_blinkTile.canvas().end();
m_blinkTilePos = QPoint(xMap, yMap);
m_blinkTileValid = true;
invalidateRect(m_mapOffset + xMap, TopBarHeight + yMap, m_mapOffset + xMap + 2 * xxt,
TopBarHeight + yMap + 3 * yyt);
updateNow();
}
void MainScreen::paintDestination()
{
if (IsoEngine::unFocus >= 0 && (ClientTools::myUn[IsoEngine::unFocus].Status & IsoEngine::usGoto)) {
const int destination = ClientTools::myUn[IsoEngine::unFocus].Status >> 16;
if (destination != 0x7FFF && destination != ClientTools::myUn[IsoEngine::unFocus].Loc)
paintLocTemp(destination, PaintLocTempStyle::Blink);
}
}
// ---- scrolling and coordinates ----
void MainScreen::scroll(int dx, int dy)
{
const int lx = ClientTools::g.lx;
m_xw = (m_xw + lx + dx) % lx;
if (m_ywmax > 0) {
m_yw += 2 * dy;
if (m_yw < 0)
m_yw = 0;
else if (m_yw > m_ywmax)
m_yw = m_ywmax;
}
paintAllMaps();
updateNow();
}
void MainScreen::setMapPos(int loc, QPoint mapPos)
{
const int lx = ClientTools::g.lx;
const int xxt = m_mainMap->xxt;
const int yyt = m_mainMap->yyt;
m_xw = (loc % lx) - (mapPos.x() - ((xxt * 2) * ((loc / lx) & 1)) / 2) / (xxt * 2);
m_xw = (m_xw + lx) % lx;
if (m_ywmax <= 0) {
m_yw = m_ywcenter;
} else {
m_yw = (loc / lx - (mapPos.y() * 2) / (yyt * 2) + 1) & ~1;
if (m_yw < 0)
m_yw = 0;
else if (m_yw > m_ywmax)
m_yw = m_ywmax;
}
}
void MainScreen::centre(int loc)
{
setMapPos(loc, QPoint(m_mapWidth / 2, m_mapHeight / 2));
}
int MainScreen::locationOfScreenPixel(int x, int y) const
{
const int lx = ClientTools::g.lx;
const int xxt = m_mainMap->xxt;
const int yyt = m_mainMap->yyt;
const int qx = (x * (yyt * 2) + y * (xxt * 2) + xxt * yyt * 2) / (xxt * yyt * 4) - 1;
const int qy = (y * (xxt * 2) - x * (yyt * 2) - xxt * yyt * 2 + 4000 * xxt * yyt) / (xxt * yyt * 4) - 999;
return (m_xw + (qx - qy + 2048) / 2 - 1024 + lx) % lx + lx * (m_yw + qx + qy);
}
int MainScreen::getCenterLoc() const
{
const int lx = ClientTools::g.lx;
return (m_xw + m_mapWidth / (m_mainMap->xxt * 4)) % lx + (m_yw + m_mapHeight / (m_mainMap->yyt * 2)) * lx;
}
void MainScreen::focusOnLoc(int loc, int options)
{
const int lx = ClientTools::g.lx;
const int xxt = m_mainMap->xxt;
const int yyt = m_mainMap->yyt;
const int dx = lx + 1 - (m_xw - loc + lx * 1024 + 1) % lx;
const bool outside = dx >= (m_mapWidth + 1) / (xxt * 2) - 2
|| (m_ywmax > 0
&& ((m_yw > 0 && loc / lx <= m_yw + 1)
|| (m_yw < m_ywmax && loc / lx >= m_yw + (m_mapHeight - 1) / yyt - 2)));
bool changed = true;
if (outside) {
centre(loc);
paintAllMaps();
} else if (!m_mapValid) {
paintAllMaps();
} else {
changed = false;
}
if (options & flRepaintPanel)
panelPaint();
if (changed && (options & flImmUpdate))
updateNow();
}
void MainScreen::setTroopLoc(int loc)
{
m_troopLoc = loc;
m_trRow = (m_xRightPanel + 10 - m_xTroop - ScrollBarWidth - 19) / m_trPitch;
m_trCnt = 0;
int trixFocus = -1;
if (!ClientTools::myRO)
return;
if (clientMode == cEditMap) {
m_trCnt = BrushTypeCount;
} else if (loc >= 0 && (ClientTools::myMap[loc] & fUnit) != 0) {
if (ClientTools::myMap[loc] & fOwned) { // count own units here
int uixDefender = -1;
ClientTools::server(sGetDefender, ClientTools::me, m_troopLoc, &uixDefender);
for (int prio = 1; prio >= 0; --prio) {
for (int uix = 0; uix < ClientTools::myRO->nUn; ++uix) {
if (((uix == uixDefender) == (prio != 0)) && ClientTools::myUn[uix].Loc == loc) {
if (uix == IsoEngine::unFocus)
trixFocus = m_trCnt;
++m_trCnt;
}
}
}
} else { // count enemy units here
ClientTools::server(sGetUnits, ClientTools::me, loc, &m_trCnt);
}
}
if (!m_verticalScrollBar)
return;
if (m_trCnt == 0) {
m_verticalScrollBar->init(0, 1);
} else {
const int trRow = std::max(1, m_trRow);
m_verticalScrollBar->init((m_trCnt + trRow - 1) / trRow, 1);
if (m_verticalScrollBar->max() >= m_verticalScrollBar->pageSize() && trixFocus >= 0)
m_verticalScrollBar->setPosition(trixFocus / trRow);
}
}
void MainScreen::setUnFocus(int uix)
{
Q_ASSERT(!(uix >= 0 && supervising));
if (uix != IsoEngine::unFocus) {
IsoEngine::destinationMarkOn = false;
paintDestination();
if (uix >= 0)
unStartLoc = ClientTools::myUn[uix].Loc;
IsoEngine::blinkOn = false;
m_blinkTime = -1;
if (IsoEngine::unFocus >= 0) {
const int loc0 = ClientTools::myUn[IsoEngine::unFocus].Loc;
if (uix < 0 || loc0 != ClientTools::myUn[uix].Loc) {
IsoEngine::unFocus = -1;
paintLoc(loc0);
}
}
IsoEngine::unFocus = uix;
}
m_unitInfoBtn->setVisible(IsoEngine::unFocus >= 0);
m_unitBtn->setVisible(IsoEngine::unFocus >= 0);
checkTerrainBtnVisible();
}
void MainScreen::checkTerrainBtnVisible()
{
if (IsoEngine::unFocus >= 0) {
const TUn &un = ClientTools::myUn[IsoEngine::unFocus];
const TModel &model = ClientTools::myModel[un.mix];
const std::uint32_t tile = ClientTools::myMap[un.Loc];
m_terrainBtn->setVisible((tile & fCity) == 0 && un.Master < 0
&& (model.Kind == mkSettler
|| (model.Kind == mkSlaves
&& ClientTools::myRO->Wonder[woPyramids].EffectiveOwner >= 0)));
} else {
m_terrainBtn->setVisible(false);
}
}
void MainScreen::checkMovieSpeedBtnState()
{
const bool movie = gameMode == cMovie;
for (int i = 0; i < 4; ++i) {
ButtonB *button = m_movieSpeedBtn[static_cast<std::size_t>(i)];
if (movie)
button->setDown(m_movieSpeed == i + 1);
button->setVisible(movie);
}
}
void MainScreen::setMapOptions()
{
m_miniMap->mapOptions = mapOptionChecked;
IsoEngine::mapOptions = mapOptionChecked;
if (clientMode == cEditMap)
IsoEngine::mapOptions |= 1u << ClientTools::moEditMode;
if (m_locCodesChecked)
IsoEngine::mapOptions |= 1u << ClientTools::moLocCodes;
}
void MainScreen::setTileSize(IsoEngine::TileSize tileSize, int loc, QPoint mapPos)
{
m_mainMap->setTileSize(tileSize);
m_noMap->setTileSize(tileSize);
m_lastResizeWidth = -1; // force repaint on resize
resizeControls();
setMapPos(loc, mapPos);
paintAllMaps();
applyToVisibleForms(FormAction::SmartUpdateContent);
}
void MainScreen::setTileSizeCenter(IsoEngine::TileSize tileSize)
{
setTileSize(tileSize, getCenterLoc(), QPoint(m_mapWidth / 2, m_mapHeight / 2));
}
void MainScreen::wheelEvent(QWheelEvent *event)
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
const QPoint pos = event->position().toPoint();
#else
const QPoint pos = event->pos();
#endif
const int delta = event->angleDelta().y();
if (delta == 0 || ClientTools::g.lx <= 0 || m_mapWidth <= 0)
return;
if (pos.y() > height() - MidPanelHeight && pos.y() < height()) {
if (m_verticalScrollBar && m_verticalScrollBar->scrollBar()->isVisible()) {
const int position = std::clamp(m_verticalScrollBar->position() + (delta > 0 ? -1 : 1), 0,
std::max(0, m_verticalScrollBar->max() - 1));
m_verticalScrollBar->setPosition(position);
}
} else {
const IsoEngine::TileSize current = m_mainMap->tileSize();
const int loc = locationOfScreenPixel(pos.x() - m_mapOffset, pos.y() - TopBarHeight);
const QPoint mapPos(pos.x() - m_mapOffset, pos.y() - TopBarHeight);
if (delta > 0 && current != IsoEngine::TileSize::Big)
setTileSize(static_cast<IsoEngine::TileSize>(static_cast<int>(current) + 1), loc, mapPos);
else if (delta < 0 && current != IsoEngine::TileSize::Small)
setTileSize(static_cast<IsoEngine::TileSize>(static_cast<int>(current) - 1), loc, mapPos);
}
event->accept();
}
// ---- timer ----
void MainScreen::timerTick()
{
if (!m_idle || ClientTools::me < 0 || gameMode == cMovie)
return;
QWidget *active = QApplication::activeWindow();
auto *activeDlg = qobject_cast<BufferedDrawDlg *>(active);
const bool dialogOpen = QApplication::activeModalWidget() != nullptr
|| (activeDlg && activeDlg->windowMode() != WindowMode::Persistent);
if (dialogOpen) {
m_blinkTime = BlinkOnTime + BlinkOffTime - 1;
if (!IsoEngine::blinkOn) {
IsoEngine::blinkOn = true;
if (IsoEngine::unFocus >= 0)
paintLocTemp(ClientTools::myUn[IsoEngine::unFocus].Loc);
else if (m_turnComplete && !supervising)
m_eot->setButtonIndexFast(eotBlinkOn);
}
return;
}
constexpr int ScrollWidth = 5;
if (active && !ClientTools::hasSaveOption(optionChecked, ClientTools::soScrollOff)) {
const int scrollSpeed = ClientTools::hasSaveOption(optionChecked, ClientTools::soScrollFast) ? 2 : 1;
int dx = 0;
int dy = 0;
const QPoint mousePos = mapFromGlobal(QCursor::pos());
if (mousePos.y() < height() - PanelHeight) {
if (mousePos.x() >= 0 && mousePos.x() <= ScrollWidth)
dx = -scrollSpeed; // scroll left
else if (mousePos.x() <= width() && mousePos.x() >= width() - ScrollWidth - 1)
dx = scrollSpeed; // scroll right
}
if (mousePos.y() >= 0 && mousePos.y() <= ScrollWidth)
dy = -scrollSpeed; // scroll up
else if (mousePos.y() <= height() && mousePos.y() >= height() - ScrollWidth - 1
&& mousePos.x() >= m_terrainBtn->x() + m_terrainBtn->width()
&& mousePos.x() < m_xRightPanel + 10 - 8)
dy = scrollSpeed; // scroll down
if (dx != 0 || dy != 0) {
if (auto *activeForm = qobject_cast<Dpi::Form *>(active); activeForm && activeForm != this
&& activeForm->onDeactivate)
activeForm->onDeactivate();
scroll(dx, dy);
}
}
m_blinkTime = (m_blinkTime + 1) % (BlinkOnTime + BlinkOffTime);
IsoEngine::blinkOn = m_blinkTime >= BlinkOffTime;
IsoEngine::destinationMarkOn = true;
if (IsoEngine::unFocus >= 0) {
if (m_blinkTime == 0 || m_blinkTime == BlinkOffTime) {
paintLocTemp(ClientTools::myUn[IsoEngine::unFocus].Loc, PaintLocTempStyle::Blink);
paintDestination();
}
} else if (m_turnComplete && !supervising) {
if (m_blinkTime == 0)
m_eot->setButtonIndexFast(eotBlinkOff);
else if (m_blinkTime == BlinkOffTime)
m_eot->setButtonIndexFast(eotBlinkOn);
}
}
} // namespace Term
} // namespace Cevo
+57 -16
View File
@@ -35,7 +35,7 @@
#include <QApplication>
#include <QDir>
#include <QFileInfo>
#include <algorithm>
#include <cstdlib>
@@ -47,15 +47,32 @@ MainScreen::MainScreen(QWidget *parent) : DrawDlg(parent)
mainScreen = this;
IsoEngine::init([](int emix) { return initEnemyModel(emix); });
mainScreenZoomToCity = [this](int loc, bool nextUnitOnClose, int showEvent) {
Q_UNUSED(nextUnitOnClose);
Q_UNUSED(showEvent);
// TODO: needs the real main map (not ported yet) to actually
// scroll/focus the view - just opens the city dialog for now.
cityDlg().showNewContent(WindowMode::Persistent, loc, 0);
return true;
// Unlike the dialogs, the main screen is a normal resizable window.
setWindowFlag(Qt::FramelessWindowHint, false);
setWindowTitle(QStringLiteral("C-evo"));
setMinimumSize(800, 480);
resize(800, 480);
setAttribute(Qt::WA_OpaquePaintEvent);
onCloseQuery = [this] {
// TODO: when not closable, idle and playing, the original resigns (mResign.Click).
return m_closable;
};
m_mainMap = std::make_unique<IsoEngine::IsoMap>();
m_noMap = std::make_unique<IsoEngine::IsoMap>();
m_noMapPanel = std::make_unique<IsoEngine::IsoMap>();
m_miniMap = std::make_unique<MiniMap>();
m_panel.canvas().font().assign(UniFont[static_cast<std::size_t>(FontType::Small)]);
m_topBar.canvas().font().assign(UniFont[static_cast<std::size_t>(FontType::Normal)]);
m_offscreen.canvas().font().assign(UniFont[static_cast<std::size_t>(FontType::Small)]);
createControls();
mainScreenZoomToCity = [this](int loc, bool nextUnitOnClose, int showEvent) {
return zoomToCity(loc, nextUnitOnClose, showEvent);
};
mainScreenCityClosed = [this](int activateUix, bool stepFocus, bool selectFocus) {
cityClosed(activateUix, stepFocus, selectFocus);
};
mainScreenCityClosed = [](int, bool, bool) {};
mainScreenUpdateViews = [this](bool updateCityScreen) { updateViews(updateCityScreen); };
mainScreenRepaintAll = [this] { repaintAll(); };
mainScreenDipCall = [this](int command) { return dipCall(command); };
@@ -396,18 +413,28 @@ int MainScreen::offerCall(TOffer &offer)
void MainScreen::updateViews(bool updateCityScreen)
{
ClientTools::sumCities(taxSum, scienceSum);
// TODO: needs PanelPaint/the real main map (not ported yet).
panelPaint();
listDlg().ecoChange();
natStatDlg().ecoChange();
if (updateCityScreen)
cityDlg().smartUpdateContent();
}
void MainScreen::setAIName(int, const QString &)
void MainScreen::setAIName(int p, const QString &name)
{
// TODO: AILogo[]/GetAppSharePath() (per-player AI logo bitmap) - not
// ported, no consumer reads it yet either (main window/panel not
// ported); no-op for now.
auto &logo = m_aiLogo[static_cast<std::size_t>(p)];
if (name.isEmpty()) {
logo.reset();
return;
}
if (!logo)
logo = std::make_unique<Dpi::Bitmap>();
const QString fileName = getAppSharePath(name + QLatin1String(PngExt));
if (!QFileInfo::exists(fileName)) {
logo.reset();
return;
}
logo->loadFromFile(fileName);
}
bool MainScreen::contactRefused(int p, const QString &item)
@@ -437,9 +464,11 @@ bool MainScreen::contactRefused(int p, const QString &item)
void MainScreen::getTribeList()
{
unusedTribeFiles.clear();
const QDir dir(localizedFilePath(QStringLiteral("Tribes")));
const QString ext = QLatin1String(CevoTribeExt);
const QStringList files = dir.entryList({QLatin1Char('*') + ext}, QDir::Files, QDir::Name);
const QStringList filter = {QLatin1Char('*') + ext};
QStringList files = QDir(localizedFilePath(QStringLiteral("Tribes"))).entryList(filter, QDir::Files, QDir::Name);
if (files.isEmpty()) // a localization may only translate some of the tribes
files = QDir(getAppSharePath(QStringLiteral("Tribes"))).entryList(filter, QDir::Files, QDir::Name);
for (const QString &file : files) {
const QString baseName = file.left(file.length() - ext.length());
QString name;
@@ -547,11 +576,23 @@ void MainScreen::initModule()
unusedTribeFiles.clear();
Tribes::hGrStdUnits = loadGraphicSet(QStringLiteral("StdUnits") + QLatin1String(PngExt));
initSmallImp();
m_verticalScrollBar = std::make_unique<PVScrollBar>(this);
m_verticalScrollBar->scrollBar()->hide();
connect(m_verticalScrollBar.get(), &PVScrollBar::updated, this, [this] {
// Do not scroll with the mouse wheel to and above the max value.
if (m_verticalScrollBar->position() > m_verticalScrollBar->max() - 1)
m_verticalScrollBar->setPosition(std::max(0, m_verticalScrollBar->max() - 1));
panelPaint();
updateNow();
});
if (ClientTools::g.lx > 0)
resizeControls();
}
void MainScreen::doneModule()
{
unusedTribeFiles.clear();
m_verticalScrollBar.reset();
}
void MainScreen::rememberPeaceViolation()
+143 -3
View File
@@ -44,13 +44,20 @@
// include all 17 dialog headers below.
#include "Battle.h"
#include "Cevo/CevoArea.h"
#include "Cevo/CevoButtonB.h"
#include "Cevo/CevoButtonC.h"
#include "Cevo/CevoEOTButton.h"
#include "Cevo/CevoPVScrollBar.h"
#include "CityScreen.h"
#include "CityType.h"
#include "Diagram.h"
#include "Draft.h"
#include "Enhance.h"
#include "Help.h"
#include "IsoEngine.h"
#include "Log.h"
#include "MiniMap.h"
#include "MessgEx.h"
#include "NatStat.h"
#include "Nego.h"
@@ -61,6 +68,11 @@
#include "UnitStat.h"
#include "Wonders.h"
#include <QPoint>
#include <QRegion>
#include <QTimer>
#include <array>
#include <memory>
namespace Cevo {
@@ -103,9 +115,8 @@ public:
// ecoChange()/CityDlg::smartUpdateContent()) runs for now.
void updateViews(bool updateCityScreen = false);
bool contactRefused(int p, const QString &item);
// TODO: needs the real main map/panel (not ported yet) - no-op until
// then (matches the original's RepaintAll()'s sole purpose).
void repaintAll() {}
// Repaints the map, minimap and panel from scratch.
void repaintAll();
void setAIName(int p, const QString &name);
void rememberPeaceViolation();
// Term.pas's GetTribeList(): fills unusedTribeFiles from the Tribes directory.
@@ -123,8 +134,137 @@ public:
void client(int command, int newPlayer, void *data);
// Term.pas's EndNego(): leaves the negotiation screen.
void endNego();
// Term.pas's ZoomToCity()/CityClosed(): open the city screen for a city
// and refocus once it is closed.
bool zoomToCity(int loc, bool nextUnitOnClose = false, int showEvent = 0);
void cityClosed(int activateUix, bool stepFocus = false, bool selectFocus = false);
// ---- Map view (Term.MainScreen.Window.cpp) ----
// Scrolls the base map position by (dx, dy) tiles and repaints.
void scroll(int dx, int dy);
// Puts location `loc` at pixel `mapPos` of the map view.
void setMapPos(int loc, QPoint mapPos);
void centre(int loc);
int locationOfScreenPixel(int x, int y) const;
int getCenterLoc() const;
void setTroopLoc(int loc);
void paintLoc(int loc, int radius = 0);
void paintLocBeforeMove(int fromLoc);
void paintLocTemp(int loc, PaintLocTempStyle style = PaintLocTempStyle::Normal);
void paintDestination();
void paintAll();
void paintAllMaps();
void panelPaint();
void setUnFocus(int uix);
void focusOnLoc(int loc, int options = 0);
void setTileSize(IsoEngine::TileSize tileSize, int loc, QPoint mapPos);
void setTileSizeCenter(IsoEngine::TileSize tileSize);
void checkTerrainBtnVisible();
void checkMovieSpeedBtnState();
void setMapOptions();
protected:
void paintEvent(QPaintEvent *event) override;
void resizeEvent(QResizeEvent *event) override;
void showEvent(QShowEvent *event) override;
void closeEvent(QCloseEvent *event) override;
void wheelEvent(QWheelEvent *event) override;
private:
void createControls();
void resizeControls();
void arrangeMidPanel();
void mainOffscreenPaint();
void miniMapPaint();
void copyMiniToPanel();
void processRect(int x0, int y0, int nx, int ny, int options);
void timerTick();
void invalidateRect(int left, int top, int right, int bottom);
void invalidateMiniMap();
void initTurn(int newPlayer);
void nextUnit(int nearLoc, bool autoTurn);
bool endTurn(bool wasSkipped = false);
void paintTopBar();
void paintPanelBackground();
void paintPanelBrushes();
void paintPanelSelectedUnit();
void paintPanelTroops();
void paintPanelTerrain();
void paintPanelButtons();
void paintZoomedTile(Dpi::Bitmap &dst, int x, int y, int loc);
// Immediately repaints what invalidateRect() collected (Pascal's Update).
void updateNow();
// Map view state (Term.pas's private fields of the same names).
int m_xw = 0; // base map x
int m_yw = 0; // base map y
int m_xwd = 0;
int m_ywd = 0;
int m_xwMini = 0;
int m_ywMini = 0;
int m_xMidPanel = 0;
int m_xRightPanel = 0;
int m_xTroop = 0;
int m_xTerrain = 0;
int m_xMini = 0;
int m_yMini = 0;
int m_ywmax = 0;
int m_ywcenter = 0;
int m_troopLoc = -1;
int m_trCnt = 0;
int m_trRow = 0;
int m_trPitch = 66;
int m_mapWidth = 0;
int m_mapOffset = 0;
int m_mapHeight = 0;
int m_blinkTime = 0;
int m_markCityLoc = -1;
int m_brushLoc = -1;
bool m_edited = false;
std::uint32_t m_brushType = fGrass;
std::array<int, 64> m_trix{}; // what each visible panel slot shows (unit index or brush)
bool m_mapValid = false;
bool m_smallScreen = false;
bool m_turnComplete = false;
bool m_tracking = false;
bool m_skipped = false;
bool m_goOnPhase = false;
bool m_haveStrategyAdvice = false;
int m_pTurn = -1;
bool m_repaintOnResize = false;
bool m_locCodesChecked = false;
QRegion m_dirty;
std::array<std::unique_ptr<Dpi::Bitmap>, nPl> m_aiLogo;
int m_lastResizeWidth = 0;
int m_lastResizeHeight = 0;
Dpi::Bitmap m_offscreen; // the map view, window-sized
Dpi::Bitmap m_panel;
Dpi::Bitmap m_topBar;
// Temporarily painted tile (unit blink), drawn over the map layer.
Dpi::Bitmap m_blinkTile;
QPoint m_blinkTilePos;
bool m_blinkTileValid = false;
std::unique_ptr<IsoEngine::IsoMap> m_mainMap;
std::unique_ptr<IsoEngine::IsoMap> m_noMap;
std::unique_ptr<IsoEngine::IsoMap> m_noMapPanel;
std::unique_ptr<MiniMap> m_miniMap;
std::unique_ptr<PVScrollBar> m_verticalScrollBar;
ButtonB *m_unitBtn = nullptr;
ButtonB *m_unitInfoBtn = nullptr;
ButtonB *m_terrainBtn = nullptr;
std::array<ButtonB *, 4> m_movieSpeedBtn{};
ButtonC *m_mapBtn0 = nullptr;
ButtonC *m_mapBtn1 = nullptr;
ButtonC *m_mapBtn4 = nullptr;
ButtonC *m_mapBtn5 = nullptr;
ButtonC *m_mapBtn6 = nullptr;
EOTButton *m_eot = nullptr;
Area *m_menuArea = nullptr;
Area *m_treasuryArea = nullptr;
Area *m_researchArea = nullptr;
Area *m_managementArea = nullptr;
QTimer *m_timer = nullptr;
// Term.pas's implementation-level state (Jump/pLogo/GameOK/Idle/...).
std::array<int, nPl> m_jump{};
int m_pLogo = -1;
+9
View File
@@ -318,6 +318,15 @@ ModelNameInfo unpackModelNameInfo(const void *data)
int clientMode = -1;
std::vector<TribeNameEntry> tribeNames;
void setClientMode(int value)
{
clientMode = value;
IsoEngine::clientMode = value;
}
ClientTools::MapOptions mapOptionChecked = 1u << ClientTools::moCityNames;
int unStartLoc = -1;
Tribes::ModelPictureInfo unpackModelPictureInfo(const void *data)
{
const auto *bytes = static_cast<const unsigned char *>(data);
+38
View File
@@ -83,6 +83,7 @@ constexpr int cSetCityName = 0x9200;
// TUn.Status bit flags not already in IsoEngine.h.
constexpr int usWaiting = 0x02;
constexpr int usToldNoReturn = 0x100;
constexpr int usPersistent = 0x01 | 0x04 | 0x08 | 0x10 | static_cast<int>(0xFFFF0000u);
// Index of the slaves/no-slaves pictures in StdUnits.
constexpr int pixSlaves = 0;
@@ -207,6 +208,43 @@ constexpr int PanelHeight = 168;
constexpr int MidPanelHeight = 120;
// (MidPanelHeight - TopBarHeight) div 2 = (120 - 41) div 2 = 39.
constexpr int MapCenterUp = (MidPanelHeight - TopBarHeight) / 2;
constexpr int Overlap = PanelHeight - MidPanelHeight;
constexpr int LeftPanelWidth = 70;
constexpr int LxmaxXxx = 130;
constexpr int YTroop = PanelHeight - 83;
constexpr int XPalace = 66;
constexpr int YPalace = 24;
constexpr int XUnitText = 80;
constexpr int BlinkOnTime = 12;
constexpr int BlinkOffTime = 6;
constexpr int EmptySpaceColor = 0x101010;
// ProcessRect options.
constexpr int prPaint = 0x0001;
constexpr int prAutoBounds = 0x0002;
constexpr int prInvalidate = 0x0004;
enum class PaintLocTempStyle { Normal, Blink };
// Terrain brushes of the map editor.
constexpr std::array<std::uint32_t, 26> BrushTypes = {
fPrefStartPos, fStartPos, fShore, fGrass, fTundra, fPrairie, fDesert, fSwamp, fForest, fHills, fMountains,
fArctic, fDeadLands, fDeadLands | fCobalt, fDeadLands | fUranium, fDeadLands | fMercury, fRiver, fRoad, fRR,
fCanal, tiIrrigation, tiFarm, tiMine, fPoll, tiFort, tiBase
};
// FocusOnLoc options.
constexpr int flRepaintPanel = 0x0001;
constexpr int flImmUpdate = 0x0002;
// Term.pas's `MapOptionChecked`: map display options chosen by the user
// (default: city names).
extern ClientTools::MapOptions mapOptionChecked;
// Term.pas's `UnStartLoc`: location where the focused unit started its turn.
extern int unStartLoc;
// Sets Term::clientMode and the copy IsoEngine reads.
void setClientMode(int value);
// Term.pas's `LostArmy`/`nLostArmy` (model-indexed lost-unit counts shown
// by MessgEx.pas's "army destroyed" report) - stay all-zero until Term.pas