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

+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: