lobby.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. // SPDX-FileCopyrightText: Copyright 2017 Citra Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <memory>
  5. #include <QDialog>
  6. #include <QFutureWatcher>
  7. #include <QSortFilterProxyModel>
  8. #include <QStandardItemModel>
  9. #include "common/announce_multiplayer_room.h"
  10. #include "network/announce_multiplayer_session.h"
  11. #include "network/network.h"
  12. #include "yuzu/multiplayer/validation.h"
  13. namespace Ui {
  14. class Lobby;
  15. }
  16. class LobbyModel;
  17. class LobbyFilterProxyModel;
  18. namespace Core {
  19. class System;
  20. }
  21. namespace Service::Account {
  22. class ProfileManager;
  23. }
  24. /**
  25. * Listing of all public games pulled from services. The lobby should be simple enough for users to
  26. * find the game they want to play, and join it.
  27. */
  28. class Lobby : public QDialog {
  29. Q_OBJECT
  30. public:
  31. explicit Lobby(QWidget* parent, QStandardItemModel* list,
  32. std::shared_ptr<Core::AnnounceMultiplayerSession> session,
  33. Core::System& system_);
  34. ~Lobby() override;
  35. /**
  36. * Updates the lobby with a new game list model.
  37. * This model should be the original model of the game list.
  38. */
  39. void UpdateGameList(QStandardItemModel* list);
  40. void RetranslateUi();
  41. public slots:
  42. /**
  43. * Begin the process to pull the latest room list from web services. After the listing is
  44. * returned from web services, `LobbyRefreshed` will be signalled
  45. */
  46. void RefreshLobby();
  47. private slots:
  48. /**
  49. * Pulls the list of rooms from network and fills out the lobby model with the results
  50. */
  51. void OnRefreshLobby();
  52. /**
  53. * Handler for single clicking on a room in the list. Expands the treeitem to show player
  54. * information for the people in the room
  55. *
  56. * index - The row of the proxy model that the user wants to join.
  57. */
  58. void OnExpandRoom(const QModelIndex&);
  59. /**
  60. * Handler for double clicking on a room in the list. Gathers the host ip and port and attempts
  61. * to connect. Will also prompt for a password in case one is required.
  62. *
  63. * index - The row of the proxy model that the user wants to join.
  64. */
  65. void OnJoinRoom(const QModelIndex&);
  66. signals:
  67. void StateChanged(const Network::RoomMember::State&);
  68. void SaveConfig();
  69. private:
  70. std::string GetProfileUsername();
  71. /**
  72. * Removes all entries in the Lobby before refreshing.
  73. */
  74. void ResetModel();
  75. /**
  76. * Prompts for a password. Returns an empty QString if the user either did not provide a
  77. * password or if the user closed the window.
  78. */
  79. QString PasswordPrompt();
  80. std::unique_ptr<Ui::Lobby> ui;
  81. QStandardItemModel* model{};
  82. QStandardItemModel* game_list{};
  83. LobbyFilterProxyModel* proxy{};
  84. QFutureWatcher<AnnounceMultiplayerRoom::RoomList> room_list_watcher;
  85. std::weak_ptr<Core::AnnounceMultiplayerSession> announce_multiplayer_session;
  86. std::unique_ptr<Service::Account::ProfileManager> profile_manager;
  87. QFutureWatcher<void>* watcher;
  88. Validation validation;
  89. Core::System& system;
  90. Network::RoomNetwork& room_network;
  91. };
  92. /**
  93. * Proxy Model for filtering the lobby
  94. */
  95. class LobbyFilterProxyModel : public QSortFilterProxyModel {
  96. Q_OBJECT;
  97. public:
  98. explicit LobbyFilterProxyModel(QWidget* parent, QStandardItemModel* list);
  99. /**
  100. * Updates the filter with a new game list model.
  101. * This model should be the processed one created by the Lobby.
  102. */
  103. void UpdateGameList(QStandardItemModel* list);
  104. bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const override;
  105. void sort(int column, Qt::SortOrder order) override;
  106. public slots:
  107. void SetFilterOwned(bool);
  108. void SetFilterFull(bool);
  109. void SetFilterSearch(const QString&);
  110. private:
  111. QStandardItemModel* game_list;
  112. bool filter_owned = false;
  113. bool filter_full = false;
  114. QString filter_search;
  115. };