diff --git a/launcher/lobby/lobby.h b/launcher/lobby/lobby.h index 8ebceb448..d42f21d9c 100644 --- a/launcher/lobby/lobby.h +++ b/launcher/lobby/lobby.h @@ -12,7 +12,7 @@ #include #include -const unsigned int ProtocolVersion = 2; +const unsigned int ProtocolVersion = 3; const std::string ProtocolEncoding = "utf8"; class ProtocolError: public std::runtime_error @@ -24,10 +24,10 @@ public: enum ProtocolConsts { //client consts - GREETING, USERNAME, MESSAGE, VERSION, CREATE, JOIN, LEAVE, READY, + GREETING, USERNAME, MESSAGE, VERSION, CREATE, JOIN, LEAVE, KICK, READY, FORCESTART, //server consts - SESSIONS, CREATED, JOINED, KICKED, SRVERROR, CHAT, START, STATUS, HOST, MODS + SESSIONS, CREATED, JOINED, KICKED, SRVERROR, CHAT, START, STATUS, HOST, MODS, CLIENTMODS }; const QMap ProtocolStrings @@ -39,7 +39,9 @@ const QMap ProtocolStrings {CREATE, "%1%2%3%4"}, //last placeholder for the mods {JOIN, "%1%2%3"}, //last placeholder for the mods {LEAVE, "%1"}, //session + {KICK, "%1"}, //player username {READY, "%1"}, //session + {FORCESTART, "%1"}, //session //server consts {CREATED, "CREATED"}, @@ -51,6 +53,7 @@ const QMap ProtocolStrings {STATUS, "STATUS"}, //joined_players:player_name:is_ready {SRVERROR, "ERROR"}, {MODS, "MODS"}, //amount:modname:modversion + {CLIENTMODS, "MODSOTHER"}, //username:amount:modname:modversion {CHAT, "MSG"} //username:message }; diff --git a/launcher/lobby/lobby_moc.cpp b/launcher/lobby/lobby_moc.cpp index deae5b783..2f258d3ca 100644 --- a/launcher/lobby/lobby_moc.cpp +++ b/launcher/lobby/lobby_moc.cpp @@ -12,7 +12,6 @@ Lobby::Lobby(QWidget *parent) : ui(new Ui::Lobby) { ui->setupUi(this); - ui->buttonReady->setEnabled(false); connect(&socketLobby, SIGNAL(text(QString)), this, SLOT(sysMessage(QString))); connect(&socketLobby, SIGNAL(receive(QString)), this, SLOT(dispatchMessage(QString))); @@ -24,6 +23,7 @@ Lobby::Lobby(QWidget *parent) : ui->serverEdit->setText(hostString); ui->userEdit->setText(QString::fromStdString(settings["launcher"]["lobbyUsername"].String())); + ui->kickButton->setVisible(false); } Lobby::~Lobby() @@ -35,6 +35,11 @@ QMap Lobby::buildModsMap() const { QMap result; QObject * mainWindow = qApp->activeWindow(); + if(!mainWindow) + mainWindow = parent(); + if(!mainWindow) + return result; //probably something is really wrong here + while(mainWindow->parent()) mainWindow = mainWindow->parent(); const auto & modlist = qobject_cast(mainWindow)->getModList(); @@ -85,7 +90,6 @@ void Lobby::serverCommand(const ServerCommand & command) try hostSession = args[0]; session = args[0]; sysMessage("new session started"); - ui->buttonReady->setEnabled(true); break; case SESSIONS: @@ -121,12 +125,11 @@ void Lobby::serverCommand(const ServerCommand & command) try if(args[1] == username) { + ui->buttonReady->setText("Ready"); ui->chat->clear(); //cleanup the chat sysMessage(joinStr.arg("you", args[0])); session = args[0]; ui->stackedWidget->setCurrentWidget(command.command == JOINED ? ui->roomPage : ui->sessionsPage); - if(command.command == KICKED) - ui->buttonReady->setEnabled(false); } else { @@ -164,6 +167,15 @@ void Lobby::serverCommand(const ServerCommand & command) try ui->modsList->addItem("No issues detected"); break; } + + case CLIENTMODS: { + protocolAssert(args.size() > 1); + amount = args[1].toInt(); + protocolAssert(amount * 2 == (args.size() - 2)); + + tagPoint = 2; + break; + } case STATUS: @@ -175,7 +187,16 @@ void Lobby::serverCommand(const ServerCommand & command) try ui->playersList->clear(); for(int i = 0; i < amount; ++i, tagPoint += 2) { - ui->playersList->addItem(new QListWidgetItem(QIcon("icons:mod-enabled.png"), args[tagPoint])); + 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) + if(args[tagPoint + 1] == "True") + ui->buttonReady->setText("Not ready"); + else + ui->buttonReady->setText("Ready"); } break; @@ -256,6 +277,7 @@ void Lobby::onDisconnected() ui->stackedWidget->setCurrentWidget(ui->sessionsPage); ui->connectButton->setChecked(false); ui->serverEdit->setEnabled(true); + ui->userEdit->setEnabled(true); ui->newButton->setEnabled(false); ui->joinButton->setEnabled(false); ui->sessionsTable->clear(); @@ -316,6 +338,7 @@ void Lobby::on_connectButton_toggled(bool checked) node["lobbyUsername"].String() = username.toStdString(); ui->serverEdit->setEnabled(false); + ui->userEdit->setEnabled(false); sysMessage("Connecting to " + serverUrl + ":" + QString::number(serverPort)); //show text immediately @@ -327,6 +350,7 @@ void Lobby::on_connectButton_toggled(bool checked) else { ui->serverEdit->setEnabled(true); + ui->userEdit->setEnabled(true); socketLobby.disconnectServer(); } } @@ -349,22 +373,36 @@ void Lobby::on_joinButton_clicked() } } - void Lobby::on_buttonLeave_clicked() { socketLobby.requestLeaveSession(session); } - void Lobby::on_buttonReady_clicked() { + if(ui->buttonReady->text() == "Ready") + ui->buttonReady->setText("Not ready"); + else + ui->buttonReady->setText("Ready"); socketLobby.requestReadySession(session); } - void Lobby::on_sessionsTable_itemSelectionChanged() { auto selection = ui->sessionsTable->selectedItems(); ui->joinButton->setEnabled(!selection.empty()); } +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())); +} + diff --git a/launcher/lobby/lobby_moc.h b/launcher/lobby/lobby_moc.h index 1a81e40a4..c794c5df5 100644 --- a/launcher/lobby/lobby_moc.h +++ b/launcher/lobby/lobby_moc.h @@ -36,6 +36,10 @@ private slots: void on_sessionsTable_itemSelectionChanged(); + void on_playersList_currentRowChanged(int currentRow); + + void on_kickButton_clicked(); + private: QString serverUrl; int serverPort; diff --git a/launcher/lobby/lobby_moc.ui b/launcher/lobby/lobby_moc.ui index bad9b08ab..44d410903 100644 --- a/launcher/lobby/lobby_moc.ui +++ b/launcher/lobby/lobby_moc.ui @@ -147,14 +147,28 @@ - + + + + Ready + + + + + + + Mods mismatch + + + + Leave - + QAbstractItemView::NoEditTriggers @@ -164,37 +178,33 @@ - + QAbstractItemView::NoEditTriggers - QAbstractItemView::NoSelection + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows - - + + - Ready + Kick player - + Players in the room - - - - Mods mismatch - - - diff --git a/launcher/mainwindow_moc.cpp b/launcher/mainwindow_moc.cpp index 9fa3da93f..5b71b9043 100644 --- a/launcher/mainwindow_moc.cpp +++ b/launcher/mainwindow_moc.cpp @@ -122,6 +122,11 @@ void MainWindow::on_startGameButton_clicked() startGame({}); } +void MainWindow::on_tabSelectList_currentRowChanged(int currentRow) +{ + ui->startGameButton->setEnabled(currentRow != TabRows::LOBBY); +} + const CModList & MainWindow::getModList() const { return ui->modlistView->getModList(); diff --git a/launcher/mainwindow_moc.h b/launcher/mainwindow_moc.h index 961227398..0603790de 100644 --- a/launcher/mainwindow_moc.h +++ b/launcher/mainwindow_moc.h @@ -29,6 +29,11 @@ class MainWindow : public QMainWindow private: Ui::MainWindow * ui; void load(); + + enum TabRows + { + MODS = 0, SETTINGS = 1, LOBBY = 2 + }; public: explicit MainWindow(QWidget * parent = 0); @@ -39,4 +44,7 @@ public: public slots: void on_startGameButton_clicked(); + +private slots: + void on_tabSelectList_currentRowChanged(int currentRow); };