citra-emu
/
citra-canary
Archived
1
0
Fork 0

Merge pull request #3676 from jroweboy/minor-mp-ui-fix

Minor multiplayer ui fixes
This commit is contained in:
James Rowe 2018-04-27 10:00:21 -06:00 committed by GitHub
commit 252e5f173d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 26 additions and 23 deletions

View File

@ -13,6 +13,7 @@
#include "citra_qt/game_list_p.h" #include "citra_qt/game_list_p.h"
#include "citra_qt/multiplayer/client_room.h" #include "citra_qt/multiplayer/client_room.h"
#include "citra_qt/multiplayer/message.h" #include "citra_qt/multiplayer/message.h"
#include "citra_qt/multiplayer/state.h"
#include "common/logging/log.h" #include "common/logging/log.h"
#include "core/announce_multiplayer_session.h" #include "core/announce_multiplayer_session.h"
#include "ui_client_room.h" #include "ui_client_room.h"
@ -57,11 +58,8 @@ void ClientRoomWindow::OnStateChange(const Network::RoomMember::State& state) {
} }
void ClientRoomWindow::Disconnect() { void ClientRoomWindow::Disconnect() {
if (!NetworkMessage::WarnDisconnect()) { auto parent = static_cast<MultiplayerState*>(parentWidget());
return; if (parent->OnCloseRoom()) {
}
if (auto member = Network::GetRoomMember().lock()) {
member->Leave();
ui->chat->AppendStatusMessage(tr("Disconnected")); ui->chat->AppendStatusMessage(tr("Disconnected"));
close(); close();
} }

View File

@ -51,8 +51,14 @@ void DirectConnectWindow::Connect() {
return; return;
} }
if (const auto member = Network::GetRoomMember().lock()) { if (const auto member = Network::GetRoomMember().lock()) {
if (member->IsConnected() && !NetworkMessage::WarnDisconnect()) { // Prevent the user from trying to join a room while they are already joining.
if (member->GetState() == Network::RoomMember::State::Joining) {
return; return;
} else if (member->GetState() == Network::RoomMember::State::Joined) {
// And ask if they want to leave the room if they are already in one.
if (!NetworkMessage::WarnDisconnect()) {
return;
}
} }
} }
switch (static_cast<ConnectionType>(ui->connection_type->currentIndex())) { switch (static_cast<ConnectionType>(ui->connection_type->currentIndex())) {

View File

@ -74,7 +74,9 @@ void HostRoomWindow::Host() {
return; return;
} }
if (auto member = Network::GetRoomMember().lock()) { if (auto member = Network::GetRoomMember().lock()) {
if (member->IsConnected()) { if (member->GetState() == Network::RoomMember::State::Joining) {
return;
} else if (member->GetState() == Network::RoomMember::State::Joined) {
auto parent = static_cast<MultiplayerState*>(parentWidget()); auto parent = static_cast<MultiplayerState*>(parentWidget());
if (!parent->OnCloseRoom()) { if (!parent->OnCloseRoom()) {
close(); close();

View File

@ -26,7 +26,6 @@ Lobby::Lobby(QWidget* parent, QStandardItemModel* list,
// setup the watcher for background connections // setup the watcher for background connections
watcher = new QFutureWatcher<void>; watcher = new QFutureWatcher<void>;
connect(watcher, &QFutureWatcher<void>::finished, [&] { joining = false; });
model = new QStandardItemModel(ui->room_list); model = new QStandardItemModel(ui->room_list);
proxy = new LobbyFilterProxyModel(this, game_list); proxy = new LobbyFilterProxyModel(this, game_list);
@ -51,7 +50,6 @@ Lobby::Lobby(QWidget* parent, QStandardItemModel* list,
ui->nickname->setText(UISettings::values.nickname); ui->nickname->setText(UISettings::values.nickname);
// UI Buttons // UI Buttons
MultiplayerState* p = reinterpret_cast<MultiplayerState*>(parent);
connect(ui->refresh_list, &QPushButton::pressed, this, &Lobby::RefreshLobby); connect(ui->refresh_list, &QPushButton::pressed, this, &Lobby::RefreshLobby);
connect(ui->games_owned, &QCheckBox::stateChanged, proxy, connect(ui->games_owned, &QCheckBox::stateChanged, proxy,
&LobbyFilterProxyModel::SetFilterOwned); &LobbyFilterProxyModel::SetFilterOwned);
@ -84,10 +82,17 @@ void Lobby::OnExpandRoom(const QModelIndex& index) {
} }
void Lobby::OnJoinRoom(const QModelIndex& source) { void Lobby::OnJoinRoom(const QModelIndex& source) {
if (joining) { if (const auto member = Network::GetRoomMember().lock()) {
// Prevent the user from trying to join a room while they are already joining.
if (member->GetState() == Network::RoomMember::State::Joining) {
return;
} else if (member->GetState() == Network::RoomMember::State::Joined) {
// And ask if they want to leave the room if they are already in one.
if (!NetworkMessage::WarnDisconnect()) {
return; return;
} }
joining = true; }
}
QModelIndex index = source; QModelIndex index = source;
// If the user double clicks on a child row (aka the player list) then use the parent instead // If the user double clicks on a child row (aka the player list) then use the parent instead
if (source.parent() != QModelIndex()) { if (source.parent() != QModelIndex()) {
@ -97,13 +102,6 @@ void Lobby::OnJoinRoom(const QModelIndex& source) {
NetworkMessage::ShowError(NetworkMessage::USERNAME_NOT_VALID); NetworkMessage::ShowError(NetworkMessage::USERNAME_NOT_VALID);
return; return;
} }
if (const auto member = Network::GetRoomMember().lock()) {
if (member->IsConnected()) {
if (!NetworkMessage::WarnDisconnect()) {
return;
}
}
}
// Get a password to pass if the room is password protected // Get a password to pass if the room is password protected
QModelIndex password_index = proxy->index(index.row(), Column::ROOM_NAME); QModelIndex password_index = proxy->index(index.row(), Column::ROOM_NAME);

View File

@ -89,7 +89,6 @@ private:
std::unique_ptr<Ui::Lobby> ui; std::unique_ptr<Ui::Lobby> ui;
QFutureWatcher<void>* watcher; QFutureWatcher<void>* watcher;
Validation validation; Validation validation;
bool joining = false;
}; };
/** /**

View File

@ -147,6 +147,7 @@ bool MultiplayerState::OnCloseRoom() {
// if you are in a room, leave it // if you are in a room, leave it
if (auto member = Network::GetRoomMember().lock()) { if (auto member = Network::GetRoomMember().lock()) {
member->Leave(); member->Leave();
NGLOG_DEBUG(Frontend, "Left the room (as a client)");
} }
// if you are hosting a room, also stop hosting // if you are hosting a room, also stop hosting
@ -155,6 +156,7 @@ bool MultiplayerState::OnCloseRoom() {
} }
room->Destroy(); room->Destroy();
announce_multiplayer_session->Stop(); announce_multiplayer_session->Stop();
NGLOG_DEBUG(Frontend, "Closed the room (as a server)");
} }
return true; return true;
} }

View File

@ -5,6 +5,7 @@
#pragma once #pragma once
#include <QWidget> #include <QWidget>
#include "core/announce_multiplayer_session.h"
#include "network/network.h" #include "network/network.h"
class QStandardItemModel; class QStandardItemModel;
@ -13,9 +14,6 @@ class HostRoomWindow;
class ClientRoomWindow; class ClientRoomWindow;
class DirectConnectWindow; class DirectConnectWindow;
class ClickableLabel; class ClickableLabel;
namespace Core {
class AnnounceMultiplayerSession;
}
class MultiplayerState : public QWidget { class MultiplayerState : public QWidget {
Q_OBJECT; Q_OBJECT;