mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-08 02:53:25 -08:00
Some checks are pending
CodeQL / Analyze (cpp) (push) Waiting to run
CodeQL / Analyze (actions) (push) Waiting to run
Build Desktop / Configure (push) Waiting to run
Build Desktop / Debian 13 (push) Blocked by required conditions
Build Desktop / Debian 12 (push) Blocked by required conditions
Build Desktop / Fedora 44 (push) Blocked by required conditions
Build Desktop / Fedora 43 (push) Blocked by required conditions
Build Desktop / Servatrice_Debian 12 (push) Blocked by required conditions
Build Desktop / Ubuntu 24.04 (push) Blocked by required conditions
Build Desktop / Ubuntu 26.04 (push) Blocked by required conditions
Build Desktop / Arch (push) Blocked by required conditions
Build Desktop / Ubuntu 26.04 cover (push) Blocked by required conditions
Build Desktop / macOS 13 Intel (push) Blocked by required conditions
Build Desktop / macOS 14 (push) Blocked by required conditions
Build Desktop / macOS 15 (push) Blocked by required conditions
Build Desktop / macOS 26 Debug (push) Blocked by required conditions
Build Desktop / Windows 10 (push) Blocked by required conditions
Build Docker / Servatrice (arm) (push) Waiting to run
Build Docker / Servatrice (x86) (push) Waiting to run
Build Docker / Publish multi-platform Servatrice image (push) Blocked by required conditions
* [GameSelector] Persist quick-filter toolbar edits and repair filter settings migration - Save game-filter parameters on toolbar changes, debounced with flush on close - Repair pre-camelCase gamefilters.ini keys in place on startup - Map the legacy creator-name filter to hostNameFilter - Balance begin/endFilterChange in GamesProxyModel::refresh - Align the hideIgnoredUserGames default between model and settings - Cover the migration with regression tests * [Review] Address RickyRister comments on filter persistence - Rename game-type prefix constants to SCREAMING_SNAKE to match MIGRATION_SENTINEL_KEY and project style - Document why GameSelector destructor flushes a pending debounced filter save (toolbar path has no other writer) --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
242 lines
8.6 KiB
C++
242 lines
8.6 KiB
C++
#ifndef GAMESELECTOR_H
|
|
#define GAMESELECTOR_H
|
|
|
|
#include "game_type_map.h"
|
|
|
|
#include <QGroupBox>
|
|
#include <QTimer>
|
|
#include <qtmetamacros.h>
|
|
// IWYU pragma: keep
|
|
// ServerInfo_User appears by value and inside QList in slot signatures, so the
|
|
// moc-generated code needs the complete type.
|
|
#include <libcockatrice/protocol/pb/serverinfo_user.pb.h>
|
|
|
|
class QTreeView;
|
|
class GamesModel;
|
|
class GamesProxyModel;
|
|
class QPushButton;
|
|
class AbstractClient;
|
|
class TabSupervisor;
|
|
class TabRoom;
|
|
class ServerInfo_Game;
|
|
class Response;
|
|
class Event_AddToList;
|
|
class Event_RemoveFromList;
|
|
class GameSelectorQuickFilterToolBar;
|
|
class QModelIndex;
|
|
class QPoint;
|
|
class QString;
|
|
class QWidget;
|
|
class ServerInfo_User;
|
|
template <class Key, class T> class QMap;
|
|
template <typename T> class QList;
|
|
|
|
/**
|
|
* @class GameSelector
|
|
* @ingroup Lobby
|
|
* @brief Provides a widget for displaying, filtering, joining, spectating, and creating games in a room.
|
|
*
|
|
* The GameSelector displays all available games in a QTreeView. It supports filtering,
|
|
* creating, joining, spectating, and viewing game details. Integrates with TabSupervisor
|
|
* and TabRoom for room and game management.
|
|
*/
|
|
class GameSelector : public QGroupBox
|
|
{
|
|
Q_OBJECT
|
|
private slots:
|
|
/**
|
|
* @brief Opens a dialog to set filters for the game list.
|
|
*
|
|
* Updates the proxy model with selected filter parameters and refreshes the displayed game list.
|
|
*/
|
|
void actSetFilter();
|
|
void checkClearFilterButtonState();
|
|
|
|
/**
|
|
* @brief Clears all filters applied to the game list.
|
|
*
|
|
* Resets the proxy model to show all games.
|
|
*/
|
|
void actClearFilter();
|
|
|
|
/**
|
|
* @brief Opens the dialog to create a new game in the current room.
|
|
*/
|
|
void actCreate();
|
|
|
|
/**
|
|
* @brief Joins the currently selected game as a player.
|
|
*/
|
|
void actJoin();
|
|
/**
|
|
* @brief Joins the currently selected game as a judge.
|
|
*/
|
|
void actJoinAsJudge();
|
|
|
|
/**
|
|
* @brief Joins the currently selected game as a spectator.
|
|
*/
|
|
void actJoinAsSpectator();
|
|
void actJoinAsJudgeSpectator();
|
|
|
|
/**
|
|
* @brief Shows the custom context menu for a game when right-clicked.
|
|
* @param point The point at which the context menu is requested.
|
|
*/
|
|
void customContextMenu(const QPoint &point);
|
|
|
|
/**
|
|
* @brief Slot called when the selected game changes.
|
|
* @param current The currently selected index.
|
|
* @param previous The previously selected index.
|
|
*
|
|
* Updates the enabled/disabled state of buttons depending on the selected game.
|
|
*/
|
|
void actSelectedGameChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
|
|
|
/**
|
|
* @brief Processes server responses for join or spectate commands.
|
|
* @param response The response from the server.
|
|
*
|
|
* Displays error messages for failed join/spectate attempts.
|
|
*/
|
|
void checkResponse(const Response &response);
|
|
|
|
/**
|
|
* @brief Refreshes the game list when the ignore list is received from the server.
|
|
* @param _ignoreList The list of users being ignored.
|
|
*/
|
|
void ignoreListReceived(const QList<ServerInfo_User> &_ignoreList);
|
|
|
|
/**
|
|
* @brief Processes events where a user is added to a list (e.g., ignore or buddy).
|
|
* @param event The event information.
|
|
*/
|
|
void processAddToListEvent(const Event_AddToList &event);
|
|
|
|
/**
|
|
* @brief Processes events where a user is removed from a list (e.g., ignore or buddy).
|
|
* @param event The event information.
|
|
*/
|
|
void processRemoveFromListEvent(const Event_RemoveFromList &event);
|
|
|
|
signals:
|
|
/**
|
|
* @brief Emitted when a game has been successfully joined.
|
|
* @param gameId The ID of the joined game.
|
|
*/
|
|
void gameJoined(int gameId);
|
|
|
|
private:
|
|
AbstractClient *client; /**< The network client used to communicate with the server. */
|
|
TabSupervisor *tabSupervisor; /**< Reference to TabSupervisor for managing tabs and rooms. */
|
|
TabRoom *room; /**< The current room. */
|
|
|
|
QTreeView *gameListView; /**< View widget for displaying the game list. */
|
|
GamesModel *gameListModel; /**< Model containing all games. */
|
|
GamesProxyModel *gameListProxyModel; /**< Proxy model for filtering and sorting the game list. */
|
|
|
|
GameSelectorQuickFilterToolBar *quickFilterToolBar;
|
|
|
|
QPushButton *filterButton; /**< Button to open the filter dialog. */
|
|
QPushButton *clearFilterButton; /**< Button to clear active filters. */
|
|
QPushButton *createButton; /**< Button to create a new game (only if room is set). */
|
|
QPushButton *joinButton; /**< Button to join the selected game. */
|
|
QPushButton *joinAsJudgeButton; /**< Button to join the selected game as a judge. */
|
|
QPushButton *spectateButton; /**< Button to spectate the selected game. */
|
|
QPushButton *joinAsJudgeSpectatorButton; /**< Button to join the selected game as a spectating judge. */
|
|
|
|
const bool showFilters; /**< Determines whether filter buttons are displayed. */
|
|
GameTypeMap gameTypeMap; /**< Mapping of game types for the current room. */
|
|
|
|
QTimer filterSaveDebounceTimer; /**< Delays persisting quick-filter edits so typing does not rewrite the settings
|
|
file on every keystroke. */
|
|
|
|
/**
|
|
* @brief Updates the widget title to reflect the current number of displayed games.
|
|
*
|
|
* Shows the number of visible games versus total games if filters are enabled.
|
|
*/
|
|
void updateTitle();
|
|
|
|
/**
|
|
* @brief Disables create/join/spectate buttons.
|
|
*/
|
|
void disableButtons();
|
|
|
|
/**
|
|
* @brief Enables buttons for the currently selected game.
|
|
*/
|
|
void enableButtons();
|
|
|
|
/**
|
|
* @brief Enables buttons for a specific game index.
|
|
* @param current The index of the currently selected game.
|
|
*/
|
|
void enableButtonsForIndex(const QModelIndex ¤t);
|
|
|
|
/**
|
|
* @brief Performs the join or spectate action for the currently selected game.
|
|
* @param asSpectator True to join as a spectator, false to join as a player.
|
|
* @param asJudge True to join as a judge, false to join as a player.
|
|
*
|
|
* Handles password prompts, overrides, and sending the join command to the server.
|
|
*/
|
|
void joinGame(bool asSpectator = false, bool asJudge = false);
|
|
|
|
/**
|
|
* @brief Performs the join or spectate action for a specific game.
|
|
* @param game The game to join.
|
|
* @param asSpectator True to join as a spectator, false to join as a player.
|
|
* @param asJudge True to join as a judge, false to join as a player.
|
|
*
|
|
* Unlike the selection-based overload, this does not depend on the game being
|
|
* visible in the filtered game list.
|
|
*/
|
|
void joinGame(const ServerInfo_Game &game, bool asSpectator = false, bool asJudge = false);
|
|
|
|
public:
|
|
/**
|
|
* @brief Constructs a GameSelector widget.
|
|
* @param _client The network client used to communicate with the server.
|
|
* @param _tabSupervisor Reference to TabSupervisor for managing tabs and rooms.
|
|
* @param _room Pointer to the current room; nullptr if no room is selected.
|
|
* @param _rooms Map of room IDs to room names.
|
|
* @param _gameTypes Map of room IDs to their available game types.
|
|
* @param restoresettings Whether to restore filter settings from previous sessions.
|
|
* @param _showfilters Whether to display filter buttons.
|
|
* @param parent Parent QWidget.
|
|
*/
|
|
GameSelector(AbstractClient *_client,
|
|
TabSupervisor *_tabSupervisor,
|
|
TabRoom *_room,
|
|
const QMap<int, QString> &_rooms,
|
|
const QMap<int, GameTypeMap> &_gameTypes,
|
|
const bool restoresettings,
|
|
const bool _showfilters,
|
|
QWidget *parent = nullptr);
|
|
~GameSelector() override;
|
|
|
|
/**
|
|
* @brief Updates UI text for translation/localization.
|
|
*/
|
|
void retranslateUi();
|
|
|
|
/**
|
|
* @brief Updates or adds a game entry in the list.
|
|
* @param info The ServerInfo_Game object containing information about the game to update.
|
|
*/
|
|
void processGameInfo(const ServerInfo_Game &info);
|
|
/**
|
|
* @brief Finds a game by ID and joins or spectates it.
|
|
* @param gameId The ID of the game to join.
|
|
* @param asSpectator True to join as a spectator, false to join as a player.
|
|
* @return True if the game was found and joined, false otherwise.
|
|
*
|
|
* Unlike the selection-based overload, this does not depend on the game
|
|
* being visible in the filtered game list.
|
|
*/
|
|
bool joinGameById(int gameId, bool asSpectator = false);
|
|
};
|
|
|
|
#endif
|