More minor issue fixes

* Move Joining state change sooner in the code to prevent an issue where
failing to connect multiple times in a row doesn't change the state (as
it goes from CouldNotConnect -> CouldNotConnect which doesn't trigger a
state changed callback)
* Prevent double clicking too fast on a room in the lobby from causing
issues
* Lobby no longer closes when joining a room
This commit is contained in:
James Rowe 2018-04-19 10:23:39 -06:00
parent 62257e0d79
commit d35693bbbc
5 changed files with 35 additions and 57 deletions

View file

@ -26,7 +26,7 @@ Lobby::Lobby(QWidget* parent, QStandardItemModel* list,
// setup the watcher for background connections
watcher = new QFutureWatcher<void>;
connect(watcher, &QFutureWatcher<void>::finished, this, &Lobby::OnConnection);
connect(watcher, &QFutureWatcher<void>::finished, [&] { joining = false; });
model = new QStandardItemModel(ui->room_list);
proxy = new LobbyFilterProxyModel(this, game_list);
@ -62,8 +62,6 @@ Lobby::Lobby(QWidget* parent, QStandardItemModel* list,
// Actions
connect(this, &Lobby::LobbyRefreshed, this, &Lobby::OnRefreshLobby);
// TODO(jroweboy): change this slot to OnConnected?
connect(this, &Lobby::Connected, p, &MultiplayerState::OnOpenNetworkRoom);
// manually start a refresh when the window is opening
// TODO(jroweboy): if this refresh is slow for people with bad internet, then don't do it as
@ -86,6 +84,10 @@ void Lobby::OnExpandRoom(const QModelIndex& index) {
}
void Lobby::OnJoinRoom(const QModelIndex& source) {
if (joining) {
return;
}
joining = true;
QModelIndex index = source;
// If the user double clicks on a child row (aka the player list) then use the parent instead
if (source.parent() != QModelIndex()) {
@ -301,24 +303,3 @@ void LobbyFilterProxyModel::SetFilterSearch(const QString& filter) {
filter_search = filter;
invalidate();
}
void Lobby::OnConnection() {
if (auto room_member = Network::GetRoomMember().lock()) {
switch (room_member->GetState()) {
case Network::RoomMember::State::CouldNotConnect:
ShowError(NetworkMessage::UNABLE_TO_CONNECT);
break;
case Network::RoomMember::State::NameCollision:
ShowError(NetworkMessage::USERNAME_IN_USE);
break;
case Network::RoomMember::State::Error:
ShowError(NetworkMessage::UNABLE_TO_CONNECT);
break;
case Network::RoomMember::State::Joining:
auto parent = static_cast<MultiplayerState*>(parentWidget());
parent->OnOpenNetworkRoom();
close();
break;
}
}
}