1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-18 17:40:48 +02:00
vcmi/launcher/lobby/lobby_moc.cpp

582 lines
15 KiB
C++
Raw Normal View History

2022-11-29 17:42:09 +02:00
/*
* lobby_moc.cpp, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
2022-10-29 19:49:30 +02:00
#include "StdInc.h"
2022-11-12 15:56:03 +02:00
#include "main.h"
2022-10-21 03:53:30 +02:00
#include "lobby_moc.h"
#include "ui_lobby_moc.h"
2022-11-10 02:20:44 +02:00
#include "lobbyroomrequest_moc.h"
2022-10-26 23:39:57 +02:00
#include "../mainwindow_moc.h"
2022-11-17 01:15:26 +02:00
#include "../modManager/cmodlist.h"
2022-10-23 21:24:33 +02:00
#include "../../lib/CConfigHandler.h"
2022-10-21 18:29:27 +02:00
2023-01-03 11:57:51 +02:00
enum GameMode
{
NEW_GAME = 0, LOAD_GAME = 1
};
enum ModResolutionRoles
{
ModNameRole = Qt::UserRole + 1,
ModEnableRole,
ModResolvableRole
};
2022-10-21 03:53:30 +02:00
Lobby::Lobby(QWidget *parent) :
QWidget(parent),
ui(new Ui::Lobby)
{
ui->setupUi(this);
2022-11-16 02:22:48 +02:00
connect(&socketLobby, SIGNAL(text(QString)), this, SLOT(sysMessage(QString)));
2022-10-23 00:55:22 +02:00
connect(&socketLobby, SIGNAL(receive(QString)), this, SLOT(dispatchMessage(QString)));
2022-10-25 03:27:53 +02:00
connect(&socketLobby, SIGNAL(disconnect()), this, SLOT(onDisconnected()));
2022-11-08 02:44:34 +02:00
2022-11-27 01:41:06 +02:00
QString hostString("%1:%2");
hostString = hostString.arg(QString::fromStdString(settings["launcher"]["lobbyUrl"].String()));
hostString = hostString.arg(settings["launcher"]["lobbyPort"].Integer());
2023-09-02 20:53:44 +02:00
namesCompleter.setModel(ui->listUsers->model());
namesCompleter.setCompletionMode(QCompleter::InlineCompletion);
2022-11-27 01:41:06 +02:00
ui->serverEdit->setText(hostString);
2022-11-08 02:44:34 +02:00
ui->userEdit->setText(QString::fromStdString(settings["launcher"]["lobbyUsername"].String()));
2022-11-27 03:35:05 +02:00
ui->kickButton->setVisible(false);
2023-09-02 20:53:44 +02:00
ui->messageEdit->setCompleter(&namesCompleter);
2022-10-21 03:53:30 +02:00
}
void Lobby::changeEvent(QEvent *event)
{
2022-12-29 16:37:38 +02:00
if(event->type() == QEvent::LanguageChange)
{
ui->retranslateUi(this);
}
QWidget::changeEvent(event);
}
2022-10-21 03:53:30 +02:00
Lobby::~Lobby()
{
delete ui;
}
2022-11-17 01:15:26 +02:00
QMap<QString, QString> Lobby::buildModsMap() const
{
QMap<QString, QString> result;
2022-11-17 03:06:23 +02:00
QObject * mainWindow = qApp->activeWindow();
2022-11-27 03:35:05 +02:00
if(!mainWindow)
mainWindow = parent();
if(!mainWindow)
return result; //probably something is really wrong here
2022-11-17 03:06:23 +02:00
while(mainWindow->parent())
mainWindow = mainWindow->parent();
const auto & modlist = qobject_cast<MainWindow*>(mainWindow)->getModList();
2022-11-17 01:15:26 +02:00
for(auto & modname : modlist.getModList())
{
auto mod = modlist.getMod(modname);
if(mod.isEnabled())
{
result[modname] = mod.getValue("version").toString();
}
}
return result;
}
bool Lobby::isModAvailable(const QString & modName, const QString & modVersion) const
{
2022-11-17 03:06:23 +02:00
QObject * mainWindow = qApp->activeWindow();
while(mainWindow->parent())
mainWindow = mainWindow->parent();
const auto & modlist = qobject_cast<MainWindow*>(mainWindow)->getModList();
2022-11-17 01:15:26 +02:00
if(!modlist.hasMod(modName))
return false;
auto mod = modlist.getMod(modName);
return (mod.isInstalled () || mod.isAvailable()) && (mod.getValue("version") == modVersion);
}
2022-10-23 00:55:22 +02:00
void Lobby::serverCommand(const ServerCommand & command) try
2022-10-21 03:53:30 +02:00
{
2022-10-23 00:55:22 +02:00
//initialize variables outside of switch block
2022-10-23 21:10:46 +02:00
const QString statusPlaceholder("%1 %2\n");
2022-10-23 00:55:22 +02:00
const auto & args = command.arguments;
int amount, tagPoint;
QString joinStr;
switch(command.command)
{
2022-10-29 19:10:21 +02:00
case SRVERROR:
2022-10-23 00:55:22 +02:00
protocolAssert(args.size());
2022-11-16 02:22:48 +02:00
chatMessage("System error", args[0], true);
2022-11-17 02:30:43 +02:00
if(authentificationStatus == AuthStatus::AUTH_NONE)
authentificationStatus = AuthStatus::AUTH_ERROR;
2022-10-23 00:55:22 +02:00
break;
case CREATED:
protocolAssert(args.size());
hostSession = args[0];
session = args[0];
2022-11-16 02:22:48 +02:00
sysMessage("new session started");
2022-10-23 00:55:22 +02:00
break;
case SESSIONS:
protocolAssert(args.size());
amount = args[0].toInt();
protocolAssert(amount * 4 == (args.size() - 1));
ui->sessionsTable->setRowCount(amount);
tagPoint = 1;
for(int i = 0; i < amount; ++i)
{
QTableWidgetItem * sessionNameItem = new QTableWidgetItem(args[tagPoint++]);
ui->sessionsTable->setItem(i, 0, sessionNameItem);
int playersJoined = args[tagPoint++].toInt();
int playersTotal = args[tagPoint++].toInt();
QTableWidgetItem * sessionPlayerItem = new QTableWidgetItem(QString("%1/%2").arg(playersJoined).arg(playersTotal));
ui->sessionsTable->setItem(i, 1, sessionPlayerItem);
2022-11-16 21:28:21 +02:00
QTableWidgetItem * sessionProtectedItem = new QTableWidgetItem();
bool isPrivate = (args[tagPoint++] == "True");
sessionProtectedItem->setData(Qt::UserRole, isPrivate);
if(isPrivate)
sessionProtectedItem->setIcon(QIcon("icons:room-private.png"));
2022-10-23 00:55:22 +02:00
ui->sessionsTable->setItem(i, 2, sessionProtectedItem);
}
break;
case JOINED:
case KICKED:
protocolAssert(args.size() == 2);
2023-09-02 20:53:44 +02:00
session = "";
2022-11-16 02:22:48 +02:00
joinStr = (command.command == JOINED ? "%1 joined to the session %2" : "%1 left session %2");
2022-10-23 00:55:22 +02:00
if(args[1] == username)
{
2022-12-26 02:34:10 +02:00
hostModsMap.clear();
2022-11-27 03:35:05 +02:00
ui->buttonReady->setText("Ready");
2022-12-26 00:37:35 +02:00
ui->optNewGame->setChecked(true);
2022-11-16 02:22:48 +02:00
sysMessage(joinStr.arg("you", args[0]));
2022-10-23 21:10:46 +02:00
session = args[0];
2022-12-26 00:37:35 +02:00
bool isHost = command.command == JOINED && hostSession == session;
ui->optNewGame->setEnabled(isHost);
ui->optLoadGame->setEnabled(isHost);
2022-10-23 21:10:46 +02:00
ui->stackedWidget->setCurrentWidget(command.command == JOINED ? ui->roomPage : ui->sessionsPage);
2022-10-23 00:55:22 +02:00
}
else
{
2022-11-16 02:22:48 +02:00
sysMessage(joinStr.arg(args[1], args[0]));
2022-10-23 00:55:22 +02:00
}
break;
2022-11-17 01:15:26 +02:00
case MODS: {
protocolAssert(args.size() > 0);
amount = args[0].toInt();
protocolAssert(amount * 2 == (args.size() - 1));
tagPoint = 1;
for(int i = 0; i < amount; ++i, tagPoint += 2)
2022-12-26 02:34:10 +02:00
hostModsMap[args[tagPoint]] = args[tagPoint + 1];
updateMods();
2022-11-17 01:15:26 +02:00
break;
}
2022-11-27 03:35:05 +02:00
case CLIENTMODS: {
2022-12-26 02:34:10 +02:00
protocolAssert(args.size() >= 1);
2022-11-27 03:35:05 +02:00
amount = args[1].toInt();
protocolAssert(amount * 2 == (args.size() - 2));
tagPoint = 2;
break;
}
2022-11-17 01:15:26 +02:00
2022-10-23 21:10:46 +02:00
case STATUS:
protocolAssert(args.size() > 0);
amount = args[0].toInt();
protocolAssert(amount * 2 == (args.size() - 1));
tagPoint = 1;
2022-11-17 01:15:26 +02:00
ui->playersList->clear();
2022-10-23 21:10:46 +02:00
for(int i = 0; i < amount; ++i, tagPoint += 2)
{
2022-11-27 03:35:05 +02:00
if(args[tagPoint + 1] == "True")
ui->playersList->addItem(new QListWidgetItem(QIcon("icons:mod-enabled.png"), args[tagPoint]));
else
ui->playersList->addItem(new QListWidgetItem(QIcon("icons:mod-disabled.png"), args[tagPoint]));
if(args[tagPoint] == username)
{
2022-11-27 03:35:05 +02:00
if(args[tagPoint + 1] == "True")
ui->buttonReady->setText("Not ready");
else
ui->buttonReady->setText("Ready");
}
2022-10-23 21:10:46 +02:00
}
break;
2022-10-25 03:27:53 +02:00
case START: {
protocolAssert(args.size() == 1);
2022-10-23 21:10:46 +02:00
//actually start game
2022-11-08 02:44:34 +02:00
gameArgs << "--lobby";
2022-11-27 01:41:06 +02:00
gameArgs << "--lobby-address" << serverUrl;
gameArgs << "--lobby-port" << QString::number(serverPort);
2022-12-26 00:37:35 +02:00
gameArgs << "--lobby-username" << username;
gameArgs << "--lobby-gamemode" << QString::number(isLoadGameMode);
2022-11-08 02:44:34 +02:00
gameArgs << "--uuid" << args[0];
2022-11-12 14:46:30 +02:00
startGame(gameArgs);
2022-10-23 21:10:46 +02:00
break;
2022-10-25 03:27:53 +02:00
}
case HOST: {
protocolAssert(args.size() == 2);
2022-11-08 02:44:34 +02:00
gameArgs << "--lobby-host";
gameArgs << "--lobby-uuid" << args[0];
gameArgs << "--lobby-connections" << args[1];
2022-10-25 03:27:53 +02:00
break;
}
2022-10-23 21:10:46 +02:00
2022-11-17 01:15:26 +02:00
case CHAT: {
2022-10-23 00:55:22 +02:00
protocolAssert(args.size() > 1);
QString msg;
for(int i = 1; i < args.size(); ++i)
msg += args[i];
2022-11-16 02:22:48 +02:00
chatMessage(args[0], msg);
2022-10-23 00:55:22 +02:00
break;
2022-11-17 01:15:26 +02:00
}
2022-12-26 00:37:35 +02:00
case HEALTH: {
socketLobby.send(ProtocolStrings[ALIVE]);
break;
}
case USERS: {
protocolAssert(args.size() > 0);
amount = args[0].toInt();
protocolAssert(amount == (args.size() - 1));
ui->listUsers->clear();
for(int i = 0; i < amount; ++i)
{
2023-09-02 20:53:44 +02:00
ui->listUsers->addItem(new QListWidgetItem("@" + args[i + 1]));
2022-12-26 00:37:35 +02:00
}
break;
}
case GAMEMODE: {
protocolAssert(args.size() == 1);
isLoadGameMode = args[0].toInt();
2023-01-03 11:57:51 +02:00
if(isLoadGameMode)
2022-12-26 00:37:35 +02:00
ui->optLoadGame->setChecked(true);
else
ui->optNewGame->setChecked(true);
break;
}
2022-11-17 01:15:26 +02:00
default:
sysMessage("Unknown server command");
2022-10-23 00:55:22 +02:00
}
2022-11-16 21:53:54 +02:00
2022-11-17 02:30:43 +02:00
if(authentificationStatus == AuthStatus::AUTH_ERROR)
2022-11-27 01:41:06 +02:00
{
2022-11-16 21:53:54 +02:00
socketLobby.disconnectServer();
2022-11-27 01:41:06 +02:00
}
2022-11-16 21:53:54 +02:00
else
2022-11-27 01:41:06 +02:00
{
2022-11-17 02:30:43 +02:00
authentificationStatus = AuthStatus::AUTH_OK;
2022-11-27 01:41:06 +02:00
ui->newButton->setEnabled(true);
}
2022-10-23 00:55:22 +02:00
}
catch(const ProtocolError & e)
{
2022-11-16 02:22:48 +02:00
chatMessage("System error", e.what(), true);
2022-10-23 00:55:22 +02:00
}
void Lobby::dispatchMessage(QString txt) try
{
if(txt.isEmpty())
return;
QStringList parseTags = txt.split(":>>");
protocolAssert(parseTags.size() > 1 && parseTags[0].isEmpty() && !parseTags[1].isEmpty());
for(int c = 1; c < parseTags.size(); ++c)
{
QStringList parseArgs = parseTags[c].split(":");
protocolAssert(parseArgs.size() > 1);
auto ctype = ProtocolStrings.key(parseArgs[0]);
parseArgs.pop_front();
ServerCommand cmd(ctype, parseArgs);
serverCommand(cmd);
}
2022-10-21 03:53:30 +02:00
}
2022-10-23 00:55:22 +02:00
catch(const ProtocolError & e)
{
2022-11-16 02:22:48 +02:00
chatMessage("System error", e.what(), true);
2022-10-23 00:55:22 +02:00
}
2022-10-25 03:27:53 +02:00
void Lobby::onDisconnected()
{
2022-11-17 02:30:43 +02:00
authentificationStatus = AuthStatus::AUTH_NONE;
2023-09-02 20:53:44 +02:00
session = "";
2022-10-25 03:27:53 +02:00
ui->stackedWidget->setCurrentWidget(ui->sessionsPage);
ui->connectButton->setChecked(false);
2022-11-27 01:41:06 +02:00
ui->serverEdit->setEnabled(true);
2022-11-27 03:35:05 +02:00
ui->userEdit->setEnabled(true);
2022-11-27 01:41:06 +02:00
ui->newButton->setEnabled(false);
ui->joinButton->setEnabled(false);
2022-12-26 00:37:35 +02:00
ui->sessionsTable->setRowCount(0);
2022-10-25 03:27:53 +02:00
}
2022-10-21 03:53:30 +02:00
2022-11-16 02:22:48 +02:00
void Lobby::chatMessage(QString title, QString body, bool isSystem)
2022-10-21 03:53:30 +02:00
{
2022-11-16 02:22:48 +02:00
QTextCharFormat fmtBody, fmtTitle;
fmtTitle.setFontWeight(QFont::Bold);
if(isSystem)
fmtBody.setFontWeight(QFont::DemiBold);
2022-10-21 03:53:30 +02:00
QTextCursor curs(ui->chat->document());
curs.movePosition(QTextCursor::End);
2022-11-16 02:22:48 +02:00
curs.insertText(title + ": ", fmtTitle);
curs.insertText(body + "\n", fmtBody);
2023-09-02 20:53:44 +02:00
if(ui->chat->verticalScrollBar()->maximum() - ui->chat->verticalScrollBar()->value() > 32)
{
ui->chat->ensureCursorVisible();
ui->chat->verticalScrollBar()->setValue(ui->chat->verticalScrollBar()->maximum());
}
2022-11-16 02:22:48 +02:00
}
void Lobby::sysMessage(QString body)
{
chatMessage("System", body, true);
2022-10-21 03:53:30 +02:00
}
2022-10-23 00:55:22 +02:00
void Lobby::protocolAssert(bool expr)
{
if(!expr)
throw ProtocolError("Protocol error");
}
void Lobby::on_messageEdit_returnPressed()
{
socketLobby.send(ProtocolStrings[MESSAGE].arg(ui->messageEdit->text()));
ui->messageEdit->clear();
}
2022-10-21 18:29:27 +02:00
void Lobby::on_connectButton_toggled(bool checked)
{
if(checked)
{
2023-01-03 11:57:51 +02:00
ui->connectButton->setText(tr("Disconnect"));
2022-11-17 02:30:43 +02:00
authentificationStatus = AuthStatus::AUTH_NONE;
2022-10-23 00:55:22 +02:00
username = ui->userEdit->text();
2022-11-16 02:22:48 +02:00
const int connectionTimeout = settings["launcher"]["connectionTimeout"].Integer();
2022-11-27 01:41:06 +02:00
auto serverStrings = ui->serverEdit->text().split(":");
if(serverStrings.size() != 2)
{
QMessageBox::critical(this, "Connection error", "Server address must have the format URL:port");
return;
}
serverUrl = serverStrings[0];
serverPort = serverStrings[1].toInt();
2022-10-23 21:24:33 +02:00
Settings node = settings.write["launcher"];
2022-11-27 01:41:06 +02:00
node["lobbyUrl"].String() = serverUrl.toStdString();
node["lobbyPort"].Integer() = serverPort;
2022-10-23 21:24:33 +02:00
node["lobbyUsername"].String() = username.toStdString();
2022-11-27 01:41:06 +02:00
ui->serverEdit->setEnabled(false);
2022-11-27 03:35:05 +02:00
ui->userEdit->setEnabled(false);
2022-10-23 21:24:33 +02:00
2022-11-27 01:41:06 +02:00
sysMessage("Connecting to " + serverUrl + ":" + QString::number(serverPort));
2022-11-16 02:42:43 +02:00
//show text immediately
2022-11-16 02:22:48 +02:00
ui->chat->repaint();
2022-11-16 02:42:43 +02:00
qApp->processEvents();
2022-11-16 02:22:48 +02:00
2022-11-27 01:41:06 +02:00
socketLobby.connectServer(serverUrl, serverPort, username, connectionTimeout);
2022-10-21 18:29:27 +02:00
}
else
{
2023-01-03 11:57:51 +02:00
ui->connectButton->setText(tr("Connect"));
2022-11-27 01:41:06 +02:00
ui->serverEdit->setEnabled(true);
2022-11-27 03:35:05 +02:00
ui->userEdit->setEnabled(true);
2022-12-26 00:37:35 +02:00
ui->listUsers->clear();
2022-12-26 02:34:10 +02:00
hostModsMap.clear();
updateMods();
2022-10-21 18:29:27 +02:00
socketLobby.disconnectServer();
}
}
2022-12-26 02:34:10 +02:00
void Lobby::updateMods()
{
ui->modsList->clear();
if(hostModsMap.empty())
return;
2023-01-03 11:57:51 +02:00
auto createModListWidget = [](const QIcon & icon, const QString & label, const QString & name, bool enableFlag, bool resolveFlag)
{
2023-01-03 13:36:26 +02:00
auto * lw = new QListWidgetItem(icon, label);
2023-01-03 11:57:51 +02:00
lw->setData(ModResolutionRoles::ModNameRole, name);
lw->setData(ModResolutionRoles::ModEnableRole, enableFlag);
lw->setData(ModResolutionRoles::ModResolvableRole, resolveFlag);
return lw;
};
2022-12-26 02:34:10 +02:00
auto enabledMods = buildModsMap();
2023-01-03 11:57:51 +02:00
for(const auto & mod : hostModsMap.keys())
2022-12-26 02:34:10 +02:00
{
auto & modValue = hostModsMap[mod];
auto modName = QString("%1 (v%2)").arg(mod, modValue);
if(enabledMods.contains(mod))
{
if(enabledMods[mod] == modValue)
enabledMods.remove(mod); //mod fully matches, remove from list
else
{
2023-01-03 11:57:51 +02:00
//mod version mismatch
ui->modsList->addItem(createModListWidget(QIcon("icons:mod-update.png"), modName, mod, true, false));
2022-12-26 02:34:10 +02:00
}
}
else if(isModAvailable(mod, modValue))
{
2023-01-03 11:57:51 +02:00
//mod is available and needs to be enabled
ui->modsList->addItem(createModListWidget(QIcon("icons:mod-enabled.png"), modName, mod, true, true));
2022-12-26 02:34:10 +02:00
}
else
{
2023-01-03 11:57:51 +02:00
//mod is not available and needs to be installed
ui->modsList->addItem(createModListWidget(QIcon("icons:mod-delete.png"), modName, mod, true, false));
2022-12-26 02:34:10 +02:00
}
}
2023-01-03 11:57:51 +02:00
for(const auto & remainMod : enabledMods.keys())
2022-12-26 02:34:10 +02:00
{
auto modName = QString("%1 (v%2)").arg(remainMod, enabledMods[remainMod]);
2023-01-03 11:57:51 +02:00
//mod needs to be disabled
ui->modsList->addItem(createModListWidget(QIcon("icons:mod-disabled.png"), modName, remainMod, false, true));
2022-12-26 02:34:10 +02:00
}
if(!ui->modsList->count())
{
ui->buttonResolve->setEnabled(false);
2023-01-03 11:57:51 +02:00
ui->modsList->addItem(tr("No issues detected"));
2022-12-26 02:34:10 +02:00
}
else
{
ui->buttonResolve->setEnabled(true);
}
}
2022-10-23 00:55:22 +02:00
void Lobby::on_newButton_clicked()
{
2022-11-17 01:15:26 +02:00
new LobbyRoomRequest(socketLobby, "", buildModsMap(), this);
2022-10-23 00:55:22 +02:00
}
void Lobby::on_joinButton_clicked()
{
auto * item = ui->sessionsTable->item(ui->sessionsTable->currentRow(), 0);
if(item)
2022-11-16 02:42:43 +02:00
{
2022-11-16 21:28:21 +02:00
auto isPrivate = ui->sessionsTable->item(ui->sessionsTable->currentRow(), 2)->data(Qt::UserRole).toBool();
if(isPrivate)
2022-11-17 01:15:26 +02:00
new LobbyRoomRequest(socketLobby, item->text(), buildModsMap(), this);
2022-11-16 02:42:43 +02:00
else
2022-11-17 01:15:26 +02:00
socketLobby.requestJoinSession(item->text(), "", buildModsMap());
2022-11-16 02:42:43 +02:00
}
2022-10-23 00:55:22 +02:00
}
2022-10-23 21:10:46 +02:00
void Lobby::on_buttonLeave_clicked()
{
socketLobby.requestLeaveSession(session);
}
void Lobby::on_buttonReady_clicked()
{
2022-11-27 03:35:05 +02:00
if(ui->buttonReady->text() == "Ready")
ui->buttonReady->setText("Not ready");
else
ui->buttonReady->setText("Ready");
2022-10-23 21:10:46 +02:00
socketLobby.requestReadySession(session);
}
2022-11-27 01:41:06 +02:00
void Lobby::on_sessionsTable_itemSelectionChanged()
{
auto selection = ui->sessionsTable->selectedItems();
ui->joinButton->setEnabled(!selection.empty());
}
2022-11-27 03:35:05 +02:00
void Lobby::on_playersList_currentRowChanged(int currentRow)
{
ui->kickButton->setVisible(ui->playersList->currentItem()
&& currentRow > 0
&& ui->playersList->currentItem()->text() != username);
}
void Lobby::on_kickButton_clicked()
{
if(ui->playersList->currentItem() && ui->playersList->currentItem()->text() != username)
socketLobby.send(ProtocolStrings[KICK].arg(ui->playersList->currentItem()->text()));
}
2022-12-26 00:37:35 +02:00
void Lobby::on_buttonResolve_clicked()
{
2022-12-26 02:34:10 +02:00
QStringList toEnableList, toDisableList;
for(auto * item : ui->modsList->selectedItems())
{
2023-01-03 11:57:51 +02:00
auto modName = item->data(ModResolutionRoles::ModNameRole);
if(modName.isNull())
2022-12-26 02:34:10 +02:00
continue;
2023-01-03 11:57:51 +02:00
bool modToEnable = item->data(ModResolutionRoles::ModEnableRole).toBool();
bool modToResolve = item->data(ModResolutionRoles::ModResolvableRole).toBool();
if(!modToResolve)
2022-12-26 02:34:10 +02:00
continue;
2023-01-03 11:57:51 +02:00
if(modToEnable)
toEnableList << modName.toString();
2022-12-26 02:34:10 +02:00
else
2023-01-03 11:57:51 +02:00
toDisableList << modName.toString();
2022-12-26 02:34:10 +02:00
}
2023-01-03 11:57:51 +02:00
//disabling first, then enabling
2022-12-26 02:34:10 +02:00
for(auto & mod : toDisableList)
emit disableMod(mod);
for(auto & mod : toEnableList)
emit enableMod(mod);
2022-12-26 00:37:35 +02:00
}
void Lobby::on_optNewGame_toggled(bool checked)
{
if(checked)
{
if(isLoadGameMode)
2023-01-03 11:57:51 +02:00
socketLobby.send(ProtocolStrings[HOSTMODE].arg(GameMode::NEW_GAME));
2022-12-26 00:37:35 +02:00
}
}
void Lobby::on_optLoadGame_toggled(bool checked)
{
if(checked)
{
if(!isLoadGameMode)
2023-01-03 11:57:51 +02:00
socketLobby.send(ProtocolStrings[HOSTMODE].arg(GameMode::LOAD_GAME));
2022-12-26 00:37:35 +02:00
}
}
2023-09-02 20:53:44 +02:00
void Lobby::on_chatSwither_clicked()
{
isGlobalChat = session.isEmpty() ? true : !isGlobalChat;
ui->chatSwither->setText(isGlobalChat ? tr("Global chat") : tr("Room chat"));
}