2018-01-19 14:42:21 +01:00
|
|
|
// Copyright 2017 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <QDialog>
|
|
|
|
#include <QFutureWatcher>
|
|
|
|
#include <QSortFilterProxyModel>
|
|
|
|
#include <QStandardItemModel>
|
2018-04-18 18:29:03 +02:00
|
|
|
#include "citra_qt/multiplayer/validation.h"
|
2018-01-19 14:42:21 +01:00
|
|
|
#include "common/announce_multiplayer_room.h"
|
|
|
|
#include "core/announce_multiplayer_session.h"
|
|
|
|
#include "network/network.h"
|
2018-04-18 07:33:54 +02:00
|
|
|
#include "ui_lobby.h"
|
2018-01-19 14:42:21 +01:00
|
|
|
|
|
|
|
class LobbyModel;
|
|
|
|
class LobbyFilterProxyModel;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Listing of all public games pulled from services. The lobby should be simple enough for users to
|
|
|
|
* find the game they want to play, and join it.
|
|
|
|
*/
|
|
|
|
class Lobby : public QDialog {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit Lobby(QWidget* parent, QStandardItemModel* list,
|
|
|
|
std::shared_ptr<Core::AnnounceMultiplayerSession> session);
|
2018-04-01 08:06:48 +02:00
|
|
|
~Lobby() = default;
|
2018-01-19 14:42:21 +01:00
|
|
|
|
2018-10-09 17:08:33 +02:00
|
|
|
void RetranslateUi();
|
|
|
|
|
2018-01-19 14:42:21 +01:00
|
|
|
public slots:
|
|
|
|
/**
|
|
|
|
* Begin the process to pull the latest room list from web services. After the listing is
|
|
|
|
* returned from web services, `LobbyRefreshed` will be signalled
|
|
|
|
*/
|
|
|
|
void RefreshLobby();
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
/**
|
|
|
|
* Pulls the list of rooms from network and fills out the lobby model with the results
|
|
|
|
*/
|
|
|
|
void OnRefreshLobby();
|
|
|
|
|
2018-04-05 20:07:11 +02:00
|
|
|
/**
|
|
|
|
* Handler for single clicking on a room in the list. Expands the treeitem to show player
|
|
|
|
* information for the people in the room
|
|
|
|
*
|
|
|
|
* index - The row of the proxy model that the user wants to join.
|
|
|
|
*/
|
|
|
|
void OnExpandRoom(const QModelIndex&);
|
|
|
|
|
2018-01-19 14:42:21 +01:00
|
|
|
/**
|
|
|
|
* Handler for double clicking on a room in the list. Gathers the host ip and port and attempts
|
|
|
|
* to connect. Will also prompt for a password in case one is required.
|
|
|
|
*
|
|
|
|
* index - The row of the proxy model that the user wants to join.
|
|
|
|
*/
|
|
|
|
void OnJoinRoom(const QModelIndex&);
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void StateChanged(const Network::RoomMember::State&);
|
|
|
|
|
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* Removes all entries in the Lobby before refreshing.
|
|
|
|
*/
|
|
|
|
void ResetModel();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prompts for a password. Returns an empty QString if the user either did not provide a
|
|
|
|
* password or if the user closed the window.
|
|
|
|
*/
|
2018-04-18 07:06:02 +02:00
|
|
|
QString PasswordPrompt();
|
2018-01-19 14:42:21 +01:00
|
|
|
|
|
|
|
QStandardItemModel* model;
|
|
|
|
QStandardItemModel* game_list;
|
|
|
|
LobbyFilterProxyModel* proxy;
|
|
|
|
|
2018-09-12 18:22:48 +02:00
|
|
|
QFutureWatcher<AnnounceMultiplayerRoom::RoomList> room_list_watcher;
|
2018-01-19 14:42:21 +01:00
|
|
|
std::weak_ptr<Core::AnnounceMultiplayerSession> announce_multiplayer_session;
|
2018-04-18 07:06:02 +02:00
|
|
|
std::unique_ptr<Ui::Lobby> ui;
|
2018-01-19 14:42:21 +01:00
|
|
|
QFutureWatcher<void>* watcher;
|
2018-04-18 18:29:03 +02:00
|
|
|
Validation validation;
|
2018-01-19 14:42:21 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Proxy Model for filtering the lobby
|
|
|
|
*/
|
|
|
|
class LobbyFilterProxyModel : public QSortFilterProxyModel {
|
|
|
|
Q_OBJECT;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit LobbyFilterProxyModel(QWidget* parent, QStandardItemModel* list);
|
|
|
|
bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const override;
|
|
|
|
void sort(int column, Qt::SortOrder order) override;
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void SetFilterOwned(bool);
|
|
|
|
void SetFilterFull(bool);
|
2018-04-19 09:18:45 +02:00
|
|
|
void SetFilterSearch(const QString&);
|
2018-01-19 14:42:21 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
QStandardItemModel* game_list;
|
|
|
|
bool filter_owned = false;
|
|
|
|
bool filter_full = false;
|
2018-04-19 09:18:45 +02:00
|
|
|
QString filter_search;
|
2018-01-19 14:42:21 +01:00
|
|
|
};
|