mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-06 05:23:56 -07:00
[Game Selector] Add button to join game as judge as well as convenience filters and doxygen (#6325)
* Add button to join game as judge as well as convenience filters. Took 1 hour 11 minutes * Change button to filter to games created by buddies, set default filter settings to be very permissive. Took 45 minutes * Remove debug. Took 3 minutes * Update game_selector.cpp * Add spacers, rearrange. Took 20 minutes Took 20 seconds * Add explanation tooltip. Took 39 seconds * Try layouting. Took 14 minutes * Set min size, set spacing for mac os Took 3 minutes * Try without the labels. Took 3 minutes * Don't use labels. Took 5 minutes * Fine-tune. Took 2 minutes * AsJudge Took 4 minutes * Clear up comment. Took 37 seconds * Remove shift hotkey. Took 4 minutes * Spectate as judge. Took 8 minutes * Add checkBox to create game as judge. Took 7 minutes * Fix crash. Took 12 minutes * Rename, fix returns. Took 19 minutes --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
9a3104c5ac
commit
537e29d937
13 changed files with 594 additions and 83 deletions
|
|
@ -1,9 +1,3 @@
|
|||
/**
|
||||
* @file games_model.h
|
||||
* @ingroup Lobby
|
||||
* @brief TODO: Document this.
|
||||
*/
|
||||
|
||||
#ifndef GAMESMODEL_H
|
||||
#define GAMESMODEL_H
|
||||
|
||||
|
|
@ -19,60 +13,107 @@
|
|||
|
||||
class UserListProxy;
|
||||
|
||||
/**
|
||||
* @class GamesModel
|
||||
* @ingroup Lobby
|
||||
* @brief Model storing all available games for display in a QTreeView or QTableView.
|
||||
*
|
||||
* Provides access to game information, supports sorting by different columns,
|
||||
* and updates when new game data is received from the server.
|
||||
*/
|
||||
class GamesModel : public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
QList<ServerInfo_Game> gameList;
|
||||
QMap<int, QString> rooms;
|
||||
QMap<int, GameTypeMap> gameTypes;
|
||||
QList<ServerInfo_Game> gameList; /**< List of games currently displayed. */
|
||||
QMap<int, QString> rooms; /**< Map of room IDs to room names. */
|
||||
QMap<int, GameTypeMap> gameTypes; /**< Map of room IDs to available game types. */
|
||||
|
||||
static const int NUM_COLS = 8;
|
||||
static const int NUM_COLS = 8; /**< Number of columns in the table. */
|
||||
|
||||
public:
|
||||
static const int SORT_ROLE = Qt::UserRole + 1;
|
||||
static const int SORT_ROLE = Qt::UserRole + 1; /**< Role used for sorting. */
|
||||
|
||||
/**
|
||||
* @brief Constructs a GamesModel.
|
||||
* @param _rooms Mapping of room IDs to room names.
|
||||
* @param _gameTypes Mapping of room IDs to their available game types.
|
||||
* @param parent Parent QObject.
|
||||
*/
|
||||
GamesModel(const QMap<int, QString> &_rooms, const QMap<int, GameTypeMap> &_gameTypes, QObject *parent = nullptr);
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override
|
||||
{
|
||||
return parent.isValid() ? 0 : gameList.size();
|
||||
}
|
||||
|
||||
int columnCount(const QModelIndex & /*parent*/ = QModelIndex()) const override
|
||||
{
|
||||
return NUM_COLS;
|
||||
}
|
||||
|
||||
QVariant data(const QModelIndex &index, int role) const override;
|
||||
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
||||
|
||||
/**
|
||||
* @brief Formats the game creation time into a human-readable string.
|
||||
* @param secs Number of seconds since the game started.
|
||||
* @return Short string representing game age (e.g., "new", ">5 min", ">2 hr").
|
||||
*/
|
||||
static const QString getGameCreatedString(const int secs);
|
||||
|
||||
/**
|
||||
* @brief Returns a reference to a specific game by row index.
|
||||
* @param row Row index in the table.
|
||||
* @return Reference to the ServerInfo_Game at the given row.
|
||||
*/
|
||||
const ServerInfo_Game &getGame(int row);
|
||||
|
||||
/**
|
||||
* Update game list with a (possibly new) game.
|
||||
* @brief Updates the game list with a new or updated game.
|
||||
* @param game The ServerInfo_Game object to add or update.
|
||||
*/
|
||||
void updateGameList(const ServerInfo_Game &game);
|
||||
|
||||
/**
|
||||
* @brief Returns the index of the room column.
|
||||
*/
|
||||
int roomColIndex()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the index of the start time column.
|
||||
*/
|
||||
int startTimeColIndex()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the map of game types per room.
|
||||
*/
|
||||
const QMap<int, GameTypeMap> &getGameTypes()
|
||||
{
|
||||
return gameTypes;
|
||||
}
|
||||
};
|
||||
|
||||
class ServerInfo_User;
|
||||
|
||||
/**
|
||||
* @class GamesProxyModel
|
||||
* @ingroup Lobby
|
||||
* @brief Proxy model for filtering and sorting the GamesModel based on user preferences.
|
||||
*
|
||||
* Supports filtering games based on buddies-only, ignored users, password protection,
|
||||
* game types, creator, age, player count, and spectator permissions.
|
||||
*/
|
||||
class GamesProxyModel : public QSortFilterProxyModel
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
const UserListProxy *userListProxy;
|
||||
const UserListProxy *userListProxy; /**< Proxy for checking user ignore/buddy lists. */
|
||||
|
||||
// If adding any additional filters, make sure to update:
|
||||
// - GamesProxyModel()
|
||||
|
|
@ -88,16 +129,25 @@ private:
|
|||
bool hidePasswordProtectedGames;
|
||||
bool hideNotBuddyCreatedGames;
|
||||
bool hideOpenDecklistGames;
|
||||
QString gameNameFilter, creatorNameFilter;
|
||||
QString gameNameFilter;
|
||||
QStringList creatorNameFilters;
|
||||
QSet<int> gameTypeFilter;
|
||||
quint32 maxPlayersFilterMin, maxPlayersFilterMax;
|
||||
QTime maxGameAge;
|
||||
bool showOnlyIfSpectatorsCanWatch, showSpectatorPasswordProtected, showOnlyIfSpectatorsCanChat,
|
||||
showOnlyIfSpectatorsCanSeeHands;
|
||||
bool showOnlyIfSpectatorsCanWatch;
|
||||
bool showSpectatorPasswordProtected;
|
||||
bool showOnlyIfSpectatorsCanChat;
|
||||
bool showOnlyIfSpectatorsCanSeeHands;
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Constructs a GamesProxyModel.
|
||||
* @param parent Parent QObject.
|
||||
* @param _userListProxy Proxy for accessing ignore/buddy lists.
|
||||
*/
|
||||
explicit GamesProxyModel(QObject *parent = nullptr, const UserListProxy *_userListProxy = nullptr);
|
||||
|
||||
// Getters for filter parameters
|
||||
bool getHideBuddiesOnlyGames() const
|
||||
{
|
||||
return hideBuddiesOnlyGames;
|
||||
|
|
@ -130,9 +180,9 @@ public:
|
|||
{
|
||||
return gameNameFilter;
|
||||
}
|
||||
QString getCreatorNameFilter() const
|
||||
QStringList getCreatorNameFilters() const
|
||||
{
|
||||
return creatorNameFilter;
|
||||
return creatorNameFilters;
|
||||
}
|
||||
QSet<int> getGameTypeFilter() const
|
||||
{
|
||||
|
|
@ -166,6 +216,10 @@ public:
|
|||
{
|
||||
return showOnlyIfSpectatorsCanSeeHands;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets all game filters at once.
|
||||
*/
|
||||
void setGameFilters(bool _hideBuddiesOnlyGames,
|
||||
bool _hideIgnoredUserGames,
|
||||
bool _hideFullGames,
|
||||
|
|
@ -174,7 +228,7 @@ public:
|
|||
bool _hideNotBuddyCreatedGames,
|
||||
bool _hideOpenDecklistGames,
|
||||
const QString &_gameNameFilter,
|
||||
const QString &_creatorNameFilter,
|
||||
const QStringList &_creatorNameFilter,
|
||||
const QSet<int> &_gameTypeFilter,
|
||||
int _maxPlayersFilterMin,
|
||||
int _maxPlayersFilterMax,
|
||||
|
|
@ -184,11 +238,123 @@ public:
|
|||
bool _showOnlyIfSpectatorsCanChat,
|
||||
bool _showOnlyIfSpectatorsCanSeeHands);
|
||||
|
||||
// Individual setters
|
||||
void setHideBuddiesOnlyGames(bool value)
|
||||
{
|
||||
hideBuddiesOnlyGames = value;
|
||||
refresh();
|
||||
}
|
||||
void setHideIgnoredUserGames(bool value)
|
||||
{
|
||||
hideIgnoredUserGames = value;
|
||||
refresh();
|
||||
}
|
||||
void setHideFullGames(bool value)
|
||||
{
|
||||
hideFullGames = value;
|
||||
refresh();
|
||||
}
|
||||
void setHideGamesThatStarted(bool value)
|
||||
{
|
||||
hideGamesThatStarted = value;
|
||||
refresh();
|
||||
}
|
||||
void setHidePasswordProtectedGames(bool value)
|
||||
{
|
||||
hidePasswordProtectedGames = value;
|
||||
refresh();
|
||||
}
|
||||
void setHideNotBuddyCreatedGames(bool value)
|
||||
{
|
||||
hideNotBuddyCreatedGames = value;
|
||||
refresh();
|
||||
}
|
||||
void setHideOpenDecklistGames(bool value)
|
||||
{
|
||||
hideOpenDecklistGames = value;
|
||||
refresh();
|
||||
}
|
||||
void setGameNameFilter(const QString &value)
|
||||
{
|
||||
gameNameFilter = value;
|
||||
refresh();
|
||||
}
|
||||
void setCreatorNameFilters(const QStringList &values)
|
||||
{
|
||||
creatorNameFilters = values;
|
||||
refresh();
|
||||
}
|
||||
void setGameTypeFilter(const QSet<int> &value)
|
||||
{
|
||||
gameTypeFilter = value;
|
||||
refresh();
|
||||
}
|
||||
void setMaxPlayersFilterMin(int value)
|
||||
{
|
||||
maxPlayersFilterMin = value;
|
||||
refresh();
|
||||
}
|
||||
void setMaxPlayersFilterMax(int value)
|
||||
{
|
||||
maxPlayersFilterMax = value;
|
||||
refresh();
|
||||
}
|
||||
void setMaxGameAge(const QTime &value)
|
||||
{
|
||||
maxGameAge = value;
|
||||
refresh();
|
||||
}
|
||||
void setShowOnlyIfSpectatorsCanWatch(bool value)
|
||||
{
|
||||
showOnlyIfSpectatorsCanWatch = value;
|
||||
refresh();
|
||||
}
|
||||
void setShowSpectatorPasswordProtected(bool value)
|
||||
{
|
||||
showSpectatorPasswordProtected = value;
|
||||
refresh();
|
||||
}
|
||||
void setShowOnlyIfSpectatorsCanChat(bool value)
|
||||
{
|
||||
showOnlyIfSpectatorsCanChat = value;
|
||||
refresh();
|
||||
}
|
||||
void setShowOnlyIfSpectatorsCanSeeHands(bool value)
|
||||
{
|
||||
showOnlyIfSpectatorsCanSeeHands = value;
|
||||
refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the number of games filtered out by the current filter.
|
||||
*/
|
||||
int getNumFilteredGames() const;
|
||||
|
||||
/**
|
||||
* @brief Resets all filter parameters to default values.
|
||||
*/
|
||||
void resetFilterParameters();
|
||||
|
||||
/**
|
||||
* @brief Returns true if all filter parameters are set to their defaults.
|
||||
*/
|
||||
bool areFilterParametersSetToDefaults() const;
|
||||
|
||||
/**
|
||||
* @brief Loads filter parameters from persistent settings.
|
||||
* @param allGameTypes Mapping of all game types by room ID.
|
||||
*/
|
||||
void loadFilterParameters(const QMap<int, QString> &allGameTypes);
|
||||
|
||||
/**
|
||||
* @brief Saves filter parameters to persistent settings.
|
||||
* @param allGameTypes Mapping of all game types by room ID.
|
||||
*/
|
||||
void saveFilterParameters(const QMap<int, QString> &allGameTypes);
|
||||
|
||||
/**
|
||||
* @brief Refreshes the proxy model (re-applies filters).
|
||||
*/
|
||||
void refresh();
|
||||
|
||||
protected:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue