lobby.h 3.6 KB

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