multiple intricate implementations
This commit is contained in:
1 parent
7aa4ea4425
commit
77690cbd96
109 files changed
+2045
-56
No files matched your search
+37
-19
@@ -30,6 +30,8 @@
|
||||
|
||||
#include "Global.h"
|
||||
#include "Messg.h"
|
||||
#include "NoTerm.h"
|
||||
#include "localplayer/LocalPlayer.h"
|
||||
|
||||
#include "Cevo/CevoScreenTools.h"
|
||||
#include "Cevo/CevoTexture.h"
|
||||
@@ -47,19 +49,33 @@
|
||||
|
||||
namespace Cevo {
|
||||
|
||||
namespace {
|
||||
|
||||
// Shortens text until it fits into a dialog of the given width (with margins).
|
||||
QString fitToWidth(QString text, int dialogWidth)
|
||||
{
|
||||
Dpi::Canvas canvas;
|
||||
canvas.font().assign(UniFont[static_cast<std::size_t>(FontType::Normal)]);
|
||||
while (!text.isEmpty() && biColorTextWidth(canvas, text) + 64 > dialogWidth)
|
||||
text.chop(1);
|
||||
return text;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
DirectDlg::DirectDlg(QWidget *parent) : DrawDlg(parent)
|
||||
{
|
||||
setWindowTitle(QStringLiteral("C-evo"));
|
||||
|
||||
GameServer::init([this](GameServer::NotifyId id, int index) { dlgNotify(id, index); });
|
||||
// TODO: these special brains' in-process Client entry points need
|
||||
// Start.pas/LocalPlayer.pas/NoTerm.pas/NetworkServer.pas/
|
||||
// NetworkClient.pas, none of which are ported yet - only the
|
||||
// (purely cosmetic) lookup name is wired up for now.
|
||||
GameServer::brainNoTerm->module.setClient(NoTerm::client);
|
||||
GameServer::brainNoTerm->lookupName = QStringLiteral("AIT");
|
||||
GameServer::brainSuperVirtual->module.setClient(nullptr);
|
||||
GameServer::brainSuperVirtual->lookupName = QStringLiteral("SUPER");
|
||||
GameServer::brainTerm->module.setClient(LocalPlayer::client);
|
||||
GameServer::brainTerm->lookupName = QStringLiteral("HUMAN");
|
||||
if (GameServer::networkEnabled) {
|
||||
// TODO: NetworkServer.pas/NetworkClient.pas (their Client entry points) aren't ported.
|
||||
GameServer::brainNetworkServer->lookupName = QStringLiteral("NETWORK_SERVER");
|
||||
GameServer::brainNetworkClient->lookupName = QStringLiteral("NETWORK_CLIENT");
|
||||
}
|
||||
@@ -86,7 +102,7 @@ void DirectDlg::go()
|
||||
hide();
|
||||
|
||||
if (GameServer::brains.count() == 3) {
|
||||
QMessageBox::information(this, CevoTitle, tr("No AI libraries found."));
|
||||
QMessageBox::information(this, CevoTitle, phrases.lookup(QStringLiteral("NOAI")));
|
||||
close();
|
||||
return;
|
||||
}
|
||||
@@ -124,14 +140,14 @@ void DirectDlg::go()
|
||||
if (QFileInfo(fileName).suffix().prepend('.') == QString::fromLatin1(CevoExt)) {
|
||||
m_quick = true;
|
||||
if (!GameServer::loadGame(fileName, fileName, -1, false)) {
|
||||
simpleMessage(tr("Could not load the file."));
|
||||
simpleMessage(phrases.lookup(QStringLiteral("LOADERR")));
|
||||
close();
|
||||
}
|
||||
} else if (QFileInfo(fileName).suffix().prepend('.') == QString::fromLatin1(CevoMapExt)) {
|
||||
m_quick = true;
|
||||
GameServer::editMap(fileName, fileName, lxmax, lymax, 30);
|
||||
} else {
|
||||
simpleMessage(tr("Could not load the file."));
|
||||
simpleMessage(phrases.lookup(QStringLiteral("LOADERR")));
|
||||
close();
|
||||
}
|
||||
}
|
||||
@@ -155,49 +171,49 @@ void DirectDlg::dlgNotify(GameServer::NotifyId id, int index)
|
||||
case NotifyId::InitLocalHuman:
|
||||
MainTexture->setAge(-1);
|
||||
m_state = -1;
|
||||
m_info = tr("Starting local human player...");
|
||||
m_info = phrases.lookup(QStringLiteral("BUSY_MODLH"));
|
||||
show();
|
||||
update();
|
||||
break;
|
||||
case NotifyId::InitModule:
|
||||
if (isVisible())
|
||||
setInfo(tr("Starting %1...").arg(GameServer::brains[index].name()));
|
||||
setInfo(fitToWidth(formatPhrase(QStringLiteral("BUSY_MOD"), { GameServer::brains[index].name() }), width()));
|
||||
break;
|
||||
case NotifyId::CreateWorld:
|
||||
if (isVisible())
|
||||
setInfo(tr("Creating world..."));
|
||||
setInfo(phrases.lookup(QStringLiteral("BUSY_START")));
|
||||
break;
|
||||
case NotifyId::InitPlayers:
|
||||
if (isVisible())
|
||||
setInfo(tr("Initializing players..."));
|
||||
setInfo(phrases.lookup(QStringLiteral("BUSY_INIT")));
|
||||
break;
|
||||
case NotifyId::DeactivationMissing:
|
||||
simpleMessage(tr("Player %1 did not hand over control.").arg(index));
|
||||
simpleMessage(formatPhrase(QStringLiteral("MISSDEACT"), { QString::number(index) }));
|
||||
break;
|
||||
case NotifyId::SetAiName:
|
||||
// TODO: LocalPlayer.pas (SetAIName) isn't ported yet.
|
||||
LocalPlayer::setAIName(index, GameServer::notifyMessage);
|
||||
break;
|
||||
case NotifyId::Exception:
|
||||
QTimer::singleShot(0, this, [this, index]() {
|
||||
QMessageBox::warning(this, CevoTitle,
|
||||
tr("AI module %1 raised an exception.").arg(GameServer::brains[index].name()));
|
||||
formatPhrase(QStringLiteral("AIEXCEPTION"), { GameServer::brains[index].name() }));
|
||||
});
|
||||
break;
|
||||
case NotifyId::LoadBegin:
|
||||
m_info = tr("Loading...");
|
||||
m_info = phrases.lookup(QStringLiteral("BUSY_LOAD"));
|
||||
setState(0);
|
||||
break;
|
||||
case NotifyId::LoadState:
|
||||
setState(index);
|
||||
break;
|
||||
case NotifyId::DllError:
|
||||
simpleMessage(tr("Could not load AI module %1.").arg(GameServer::brains[index].fileName));
|
||||
simpleMessage(formatPhrase(QStringLiteral("DLLERROR"), { GameServer::brains[index].fileName }));
|
||||
break;
|
||||
case NotifyId::AiError:
|
||||
simpleMessage(tr("AI module error: %1").arg(GameServer::notifyMessage));
|
||||
simpleMessage(formatPhrase(QStringLiteral("AIERROR"), { GameServer::notifyMessage }));
|
||||
break;
|
||||
case NotifyId::ClientError:
|
||||
simpleMessage(tr("Client error in AI module %1.").arg(GameServer::brains[index].fileName));
|
||||
simpleMessage(formatPhrase(QStringLiteral("CLIENTERROR"), { GameServer::brains[index].fileName }));
|
||||
break;
|
||||
case NotifyId::EndInfo:
|
||||
hide();
|
||||
@@ -237,7 +253,9 @@ void DirectDlg::dlgNotify(GameServer::NotifyId id, int index)
|
||||
QTimer::singleShot(0, this, []() { GameServer::nextPlayer(); });
|
||||
break;
|
||||
case NotifyId::DeinitModule:
|
||||
m_info = tr("Unloading %1...").arg(GameServer::brains[index].name());
|
||||
m_info = fitToWidth(
|
||||
phraseToQtFormat(phrases2.lookup(QStringLiteral("BUSY_DEINIT"))).arg(GameServer::brains[index].name()),
|
||||
width());
|
||||
MainTexture->setAge(-1);
|
||||
m_state = -1;
|
||||
show();
|
||||
|
||||
Reference in new issue
Block a user