From 1cb45433a2abae3c47c5a6979790bfb6764813a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Br=C3=BCbach?= Date: Sat, 15 Nov 2025 22:30:16 +0100 Subject: [PATCH] Change button to filter to games created by buddies, set default filter settings to be very permissive. Took 45 minutes --- .../widgets/dialogs/dlg_filter_games.cpp | 6 +-- .../widgets/dialogs/dlg_filter_games.h | 2 +- .../widgets/server/game_selector.cpp | 4 +- .../game_selector_quick_filter_toolbar.cpp | 38 ++++++++++++------- .../game_selector_quick_filter_toolbar.h | 8 +++- .../interface/widgets/server/games_model.cpp | 27 ++++++++----- .../interface/widgets/server/games_model.h | 13 ++++--- .../settings/game_filters_settings.cpp | 26 ++++++------- .../settings/game_filters_settings.h | 4 +- 9 files changed, 76 insertions(+), 52 deletions(-) diff --git a/cockatrice/src/interface/widgets/dialogs/dlg_filter_games.cpp b/cockatrice/src/interface/widgets/dialogs/dlg_filter_games.cpp index 0c5191f99..40dea9cb8 100644 --- a/cockatrice/src/interface/widgets/dialogs/dlg_filter_games.cpp +++ b/cockatrice/src/interface/widgets/dialogs/dlg_filter_games.cpp @@ -56,7 +56,7 @@ DlgFilterGames::DlgFilterGames(const QMap &_allGameTypes, auto *gameNameFilterLabel = new QLabel(tr("Game &description:")); gameNameFilterLabel->setBuddy(gameNameFilterEdit); creatorNameFilterEdit = new QLineEdit; - creatorNameFilterEdit->setText(gamesProxyModel->getCreatorNameFilter()); + creatorNameFilterEdit->setText(gamesProxyModel->getCreatorNameFilters().join(", ")); auto *creatorNameFilterLabel = new QLabel(tr("&Creator name:")); creatorNameFilterLabel->setBuddy(creatorNameFilterEdit); @@ -232,9 +232,9 @@ QString DlgFilterGames::getGameNameFilter() const return gameNameFilterEdit->text(); } -QString DlgFilterGames::getCreatorNameFilter() const +QStringList DlgFilterGames::getCreatorNameFilters() const { - return creatorNameFilterEdit->text(); + return creatorNameFilterEdit->text().split(",", Qt::SkipEmptyParts); } QSet DlgFilterGames::getGameTypeFilter() const diff --git a/cockatrice/src/interface/widgets/dialogs/dlg_filter_games.h b/cockatrice/src/interface/widgets/dialogs/dlg_filter_games.h index ab07a02d4..37b208749 100644 --- a/cockatrice/src/interface/widgets/dialogs/dlg_filter_games.h +++ b/cockatrice/src/interface/widgets/dialogs/dlg_filter_games.h @@ -71,7 +71,7 @@ public: bool getHideNotBuddyCreatedGames() const; QString getGameNameFilter() const; void setGameNameFilter(const QString &_gameNameFilter); - QString getCreatorNameFilter() const; + QStringList getCreatorNameFilters() const; void setCreatorNameFilter(const QString &_creatorNameFilter); QSet getGameTypeFilter() const; void setGameTypeFilter(const QSet &_gameTypeFilter); diff --git a/cockatrice/src/interface/widgets/server/game_selector.cpp b/cockatrice/src/interface/widgets/server/game_selector.cpp index 9befef008..dbf295915 100644 --- a/cockatrice/src/interface/widgets/server/game_selector.cpp +++ b/cockatrice/src/interface/widgets/server/game_selector.cpp @@ -76,7 +76,7 @@ GameSelector::GameSelector(AbstractClient *_client, gameListView->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents); - quickFilterToolBar = new GameSelectorQuickFilterToolBar(this, gameListProxyModel, gameTypeMap); + quickFilterToolBar = new GameSelectorQuickFilterToolBar(this, tabSupervisor, gameListProxyModel, gameTypeMap); filterButton = new QPushButton; filterButton->setIcon(QPixmap("theme:icons/search")); @@ -169,7 +169,7 @@ void GameSelector::actSetFilter() gameListProxyModel->setGameFilters( dlg.getHideBuddiesOnlyGames(), dlg.getHideIgnoredUserGames(), dlg.getHideFullGames(), dlg.getHideGamesThatStarted(), dlg.getHidePasswordProtectedGames(), dlg.getHideNotBuddyCreatedGames(), - dlg.getHideOpenDecklistGames(), dlg.getGameNameFilter(), dlg.getCreatorNameFilter(), dlg.getGameTypeFilter(), + dlg.getHideOpenDecklistGames(), dlg.getGameNameFilter(), dlg.getCreatorNameFilters(), dlg.getGameTypeFilter(), dlg.getMaxPlayersFilterMin(), dlg.getMaxPlayersFilterMax(), dlg.getMaxGameAge(), dlg.getShowOnlyIfSpectatorsCanWatch(), dlg.getShowSpectatorPasswordProtected(), dlg.getShowOnlyIfSpectatorsCanChat(), dlg.getShowOnlyIfSpectatorsCanSeeHands()); diff --git a/cockatrice/src/interface/widgets/server/game_selector_quick_filter_toolbar.cpp b/cockatrice/src/interface/widgets/server/game_selector_quick_filter_toolbar.cpp index b08d2da13..46f1ed39d 100644 --- a/cockatrice/src/interface/widgets/server/game_selector_quick_filter_toolbar.cpp +++ b/cockatrice/src/interface/widgets/server/game_selector_quick_filter_toolbar.cpp @@ -1,6 +1,7 @@ #include "game_selector_quick_filter_toolbar.h" #include "games_model.h" +#include "user/user_list_manager.h" #include #include @@ -9,23 +10,32 @@ #include GameSelectorQuickFilterToolBar::GameSelectorQuickFilterToolBar(QWidget *parent, + TabSupervisor *_tabSupervisor, GamesProxyModel *_model, const QMap &allGameTypes) - : QWidget(parent), model(_model) + : QWidget(parent), tabSupervisor(_tabSupervisor), model(_model) { mainLayout = new QHBoxLayout(this); searchBar = new QLineEdit(this); - searchBar->setText(model->getCreatorNameFilter()); - connect(searchBar, &QLineEdit::textChanged, this, - [this](const QString &text) { model->setCreatorNameFilter(text); }); + searchBar->setText(model->getCreatorNameFilters().join(", ")); + connect(searchBar, &QLineEdit::textChanged, this, [this](const QString &text) { model->setGameNameFilter(text); }); - hideGamesWithoutBuddiesCheckBox = new QCheckBox(this); - hideGamesWithoutBuddiesCheckBox->setChecked(model->getHideBuddiesOnlyGames()); - hideGamesWithoutBuddiesLabel = new QLabel(this); - hideGamesWithoutBuddiesLabel->setBuddy(hideGamesWithoutBuddiesCheckBox); - connect(hideGamesWithoutBuddiesCheckBox, &QCheckBox::toggled, this, - [this](bool checked) { model->setHideBuddiesOnlyGames(checked); }); + hideGamesNotCreatedByBuddiesCheckBox = new QCheckBox(this); + hideGamesNotCreatedByBuddiesCheckBox->setChecked(model->getHideBuddiesOnlyGames()); + hideGamesNotCreatedByBuddiesLabel = new QLabel(this); + hideGamesNotCreatedByBuddiesLabel->setBuddy(hideGamesNotCreatedByBuddiesCheckBox); + connect(hideGamesNotCreatedByBuddiesCheckBox, &QCheckBox::toggled, this, [this](bool checked) { + if (checked) { + QStringList buddyNames; + for (auto buddy : tabSupervisor->getUserListManager()->getBuddyList().values()) { + buddyNames << QString::fromStdString(buddy.name()); + } + model->setCreatorNameFilters(buddyNames); + } else { + model->setCreatorNameFilters({}); + } + }); hideFullGamesCheckBox = new QCheckBox(this); hideFullGamesCheckBox->setChecked(model->getHideFullGames()); @@ -76,8 +86,8 @@ GameSelectorQuickFilterToolBar::GameSelectorQuickFilterToolBar(QWidget *parent, }); mainLayout->addWidget(searchBar); - mainLayout->addWidget(hideGamesWithoutBuddiesLabel); - mainLayout->addWidget(hideGamesWithoutBuddiesCheckBox); + mainLayout->addWidget(hideGamesNotCreatedByBuddiesLabel); + mainLayout->addWidget(hideGamesNotCreatedByBuddiesCheckBox); mainLayout->addWidget(hideFullGamesLabel); mainLayout->addWidget(hideFullGamesCheckBox); mainLayout->addWidget(hideStartedGamesLabel); @@ -92,8 +102,8 @@ GameSelectorQuickFilterToolBar::GameSelectorQuickFilterToolBar(QWidget *parent, void GameSelectorQuickFilterToolBar::retranslateUi() { - searchBar->setPlaceholderText(tr("Filter by creator name...")); - hideGamesWithoutBuddiesLabel->setText(tr("Hide buddies only games")); + searchBar->setPlaceholderText(tr("Filter by game name...")); + hideGamesNotCreatedByBuddiesLabel->setText(tr("Hide games not created by buddies")); hideFullGamesLabel->setText(tr("Hide full games")); hideStartedGamesLabel->setText(tr("Hide started games")); filterToFormatLabel->setText(tr("Filter to format")); diff --git a/cockatrice/src/interface/widgets/server/game_selector_quick_filter_toolbar.h b/cockatrice/src/interface/widgets/server/game_selector_quick_filter_toolbar.h index a66d12a90..5e7c1f224 100644 --- a/cockatrice/src/interface/widgets/server/game_selector_quick_filter_toolbar.h +++ b/cockatrice/src/interface/widgets/server/game_selector_quick_filter_toolbar.h @@ -1,5 +1,7 @@ #ifndef COCKATRICE_GAME_SELECTOR_QUICK_FILTER_TOOLBAR_H #define COCKATRICE_GAME_SELECTOR_QUICK_FILTER_TOOLBAR_H + +#include "../tabs/tab_supervisor.h" #include "games_model.h" #include @@ -16,18 +18,20 @@ class GameSelectorQuickFilterToolBar : public QWidget public: explicit GameSelectorQuickFilterToolBar(QWidget *parent, + TabSupervisor *tabSupervisor, GamesProxyModel *model, const QMap &allGameTypes); void retranslateUi(); private: + TabSupervisor *tabSupervisor; GamesProxyModel *model; QHBoxLayout *mainLayout; QLineEdit *searchBar; - QCheckBox *hideGamesWithoutBuddiesCheckBox; - QLabel *hideGamesWithoutBuddiesLabel; + QCheckBox *hideGamesNotCreatedByBuddiesCheckBox; + QLabel *hideGamesNotCreatedByBuddiesLabel; QCheckBox *hideFullGamesCheckBox; QLabel *hideFullGamesLabel; QCheckBox *hideStartedGamesCheckBox; diff --git a/cockatrice/src/interface/widgets/server/games_model.cpp b/cockatrice/src/interface/widgets/server/games_model.cpp index 4c68390c9..82f5ee5f3 100644 --- a/cockatrice/src/interface/widgets/server/games_model.cpp +++ b/cockatrice/src/interface/widgets/server/games_model.cpp @@ -294,7 +294,7 @@ void GamesProxyModel::setGameFilters(bool _hideBuddiesOnlyGames, bool _hideNotBuddyCreatedGames, bool _hideOpenDecklistGames, const QString &_gameNameFilter, - const QString &_creatorNameFilter, + const QStringList &_creatorNameFilters, const QSet &_gameTypeFilter, int _maxPlayersFilterMin, int _maxPlayersFilterMax, @@ -315,7 +315,7 @@ void GamesProxyModel::setGameFilters(bool _hideBuddiesOnlyGames, hideNotBuddyCreatedGames = _hideNotBuddyCreatedGames; hideOpenDecklistGames = _hideOpenDecklistGames; gameNameFilter = _gameNameFilter; - creatorNameFilter = _creatorNameFilter; + creatorNameFilters = _creatorNameFilters; gameTypeFilter = _gameTypeFilter; maxPlayersFilterMin = _maxPlayersFilterMin; maxPlayersFilterMax = _maxPlayersFilterMax; @@ -348,15 +348,15 @@ int GamesProxyModel::getNumFilteredGames() const void GamesProxyModel::resetFilterParameters() { - setGameFilters(false, false, false, false, false, false, false, QString(), QString(), {}, DEFAULT_MAX_PLAYERS_MIN, - DEFAULT_MAX_PLAYERS_MAX, DEFAULT_MAX_GAME_AGE, false, false, false, false); + setGameFilters(false, false, false, false, false, false, false, QString(), QStringList(), {}, + DEFAULT_MAX_PLAYERS_MIN, DEFAULT_MAX_PLAYERS_MAX, DEFAULT_MAX_GAME_AGE, false, false, false, false); } bool GamesProxyModel::areFilterParametersSetToDefaults() const { return !hideFullGames && !hideGamesThatStarted && !hidePasswordProtectedGames && !hideBuddiesOnlyGames && !hideOpenDecklistGames && !hideIgnoredUserGames && !hideNotBuddyCreatedGames && gameNameFilter.isEmpty() && - creatorNameFilter.isEmpty() && gameTypeFilter.isEmpty() && maxPlayersFilterMin == DEFAULT_MAX_PLAYERS_MIN && + creatorNameFilters.isEmpty() && gameTypeFilter.isEmpty() && maxPlayersFilterMin == DEFAULT_MAX_PLAYERS_MIN && maxPlayersFilterMax == DEFAULT_MAX_PLAYERS_MAX && maxGameAge == DEFAULT_MAX_GAME_AGE && !showOnlyIfSpectatorsCanWatch && !showSpectatorPasswordProtected && !showOnlyIfSpectatorsCanChat && !showOnlyIfSpectatorsCanSeeHands; @@ -379,7 +379,7 @@ void GamesProxyModel::loadFilterParameters(const QMap &allGameType gameFilters.isHideFullGames(), gameFilters.isHideGamesThatStarted(), gameFilters.isHidePasswordProtectedGames(), gameFilters.isHideNotBuddyCreatedGames(), gameFilters.isHideOpenDecklistGames(), gameFilters.getGameNameFilter(), - gameFilters.getCreatorNameFilter(), newGameTypeFilter, gameFilters.getMinPlayers(), + gameFilters.getCreatorNameFilters(), newGameTypeFilter, gameFilters.getMinPlayers(), gameFilters.getMaxPlayers(), gameFilters.getMaxGameAge(), gameFilters.isShowOnlyIfSpectatorsCanWatch(), gameFilters.isShowSpectatorPasswordProtected(), gameFilters.isShowOnlyIfSpectatorsCanChat(), gameFilters.isShowOnlyIfSpectatorsCanSeeHands()); @@ -396,7 +396,7 @@ void GamesProxyModel::saveFilterParameters(const QMap &allGameType gameFilters.setHideNotBuddyCreatedGames(hideNotBuddyCreatedGames); gameFilters.setHideOpenDecklistGames(hideOpenDecklistGames); gameFilters.setGameNameFilter(gameNameFilter); - gameFilters.setCreatorNameFilter(creatorNameFilter); + gameFilters.setCreatorNameFilters(creatorNameFilters); QMapIterator gameTypeIterator(allGameTypes); while (gameTypeIterator.hasNext()) { @@ -459,9 +459,18 @@ bool GamesProxyModel::filterAcceptsRow(int sourceRow) const if (!gameNameFilter.isEmpty()) if (!QString::fromStdString(game.description()).contains(gameNameFilter, Qt::CaseInsensitive)) return false; - if (!creatorNameFilter.isEmpty()) - if (!QString::fromStdString(game.creator_info().name()).contains(creatorNameFilter, Qt::CaseInsensitive)) + if (!creatorNameFilters.isEmpty()) { + qInfo() << "Creator Name filters: " << creatorNameFilters; + bool found = false; + for (auto createNameFilter : creatorNameFilters) { + if (QString::fromStdString(game.creator_info().name()).contains(createNameFilter, Qt::CaseInsensitive)) { + found = true; + } + } + if (!found) { return false; + } + } QSet gameTypes; for (int i = 0; i < game.game_types_size(); ++i) diff --git a/cockatrice/src/interface/widgets/server/games_model.h b/cockatrice/src/interface/widgets/server/games_model.h index c9d329704..c704befcc 100644 --- a/cockatrice/src/interface/widgets/server/games_model.h +++ b/cockatrice/src/interface/widgets/server/games_model.h @@ -129,7 +129,8 @@ private: bool hidePasswordProtectedGames; bool hideNotBuddyCreatedGames; bool hideOpenDecklistGames; - QString gameNameFilter, creatorNameFilter; + QString gameNameFilter; + QStringList creatorNameFilters; QSet gameTypeFilter; quint32 maxPlayersFilterMin, maxPlayersFilterMax; QTime maxGameAge; @@ -179,9 +180,9 @@ public: { return gameNameFilter; } - QString getCreatorNameFilter() const + QStringList getCreatorNameFilters() const { - return creatorNameFilter; + return creatorNameFilters; } QSet getGameTypeFilter() const { @@ -227,7 +228,7 @@ public: bool _hideNotBuddyCreatedGames, bool _hideOpenDecklistGames, const QString &_gameNameFilter, - const QString &_creatorNameFilter, + const QStringList &_creatorNameFilter, const QSet &_gameTypeFilter, int _maxPlayersFilterMin, int _maxPlayersFilterMax, @@ -278,9 +279,9 @@ public: gameNameFilter = value; refresh(); } - void setCreatorNameFilter(const QString &value) + void setCreatorNameFilters(const QStringList &values) { - creatorNameFilter = value; + creatorNameFilters = values; refresh(); } void setGameTypeFilter(const QSet &value) diff --git a/libcockatrice_settings/libcockatrice/settings/game_filters_settings.cpp b/libcockatrice_settings/libcockatrice/settings/game_filters_settings.cpp index 2da9b9bc3..e5db3010d 100644 --- a/libcockatrice_settings/libcockatrice/settings/game_filters_settings.cpp +++ b/libcockatrice_settings/libcockatrice/settings/game_filters_settings.cpp @@ -25,7 +25,7 @@ void GameFiltersSettings::setHideBuddiesOnlyGames(bool hide) bool GameFiltersSettings::isHideBuddiesOnlyGames() { QVariant previous = getValue("hide_buddies_only_games"); - return previous == QVariant() || previous.toBool(); + return previous == QVariant() ? false : previous.toBool(); } void GameFiltersSettings::setHideFullGames(bool hide) @@ -36,7 +36,7 @@ void GameFiltersSettings::setHideFullGames(bool hide) bool GameFiltersSettings::isHideFullGames() { QVariant previous = getValue("hide_full_games"); - return !(previous == QVariant()) && previous.toBool(); + return previous == QVariant() ? false : previous.toBool(); } void GameFiltersSettings::setHideGamesThatStarted(bool hide) @@ -47,7 +47,7 @@ void GameFiltersSettings::setHideGamesThatStarted(bool hide) bool GameFiltersSettings::isHideGamesThatStarted() { QVariant previous = getValue("hide_games_that_started"); - return !(previous == QVariant()) && previous.toBool(); + return previous == QVariant() ? false : previous.toBool(); } void GameFiltersSettings::setHidePasswordProtectedGames(bool hide) @@ -58,7 +58,7 @@ void GameFiltersSettings::setHidePasswordProtectedGames(bool hide) bool GameFiltersSettings::isHidePasswordProtectedGames() { QVariant previous = getValue("hide_password_protected_games"); - return previous == QVariant() || previous.toBool(); + return previous == QVariant() ? false : previous.toBool(); } void GameFiltersSettings::setHideIgnoredUserGames(bool hide) @@ -69,7 +69,7 @@ void GameFiltersSettings::setHideIgnoredUserGames(bool hide) bool GameFiltersSettings::isHideIgnoredUserGames() { QVariant previous = getValue("hide_ignored_user_games"); - return !(previous == QVariant()) && previous.toBool(); + return previous == QVariant() ? true : previous.toBool(); } void GameFiltersSettings::setHideNotBuddyCreatedGames(bool hide) @@ -80,7 +80,7 @@ void GameFiltersSettings::setHideNotBuddyCreatedGames(bool hide) bool GameFiltersSettings::isHideNotBuddyCreatedGames() { QVariant previous = getValue("hide_not_buddy_created_games"); - return !(previous == QVariant()) && previous.toBool(); + return previous == QVariant() ? false : previous.toBool(); } void GameFiltersSettings::setHideOpenDecklistGames(bool hide) @@ -91,7 +91,7 @@ void GameFiltersSettings::setHideOpenDecklistGames(bool hide) bool GameFiltersSettings::isHideOpenDecklistGames() { QVariant previous = getValue("hide_open_decklist_games"); - return !(previous == QVariant()) && previous.toBool(); + return previous == QVariant() ? false : previous.toBool(); } void GameFiltersSettings::setGameNameFilter(QString gameName) @@ -104,14 +104,14 @@ QString GameFiltersSettings::getGameNameFilter() return getValue("game_name_filter").toString(); } -void GameFiltersSettings::setCreatorNameFilter(QString creatorName) +void GameFiltersSettings::setCreatorNameFilters(QStringList creatorName) { setValue(creatorName, "creator_name_filter"); } -QString GameFiltersSettings::getCreatorNameFilter() +QStringList GameFiltersSettings::getCreatorNameFilters() { - return getValue("creator_name_filter").toString(); + return getValue("creator_name_filter").toStringList(); } void GameFiltersSettings::setMinPlayers(int min) @@ -182,7 +182,7 @@ void GameFiltersSettings::setShowSpectatorPasswordProtected(bool show) bool GameFiltersSettings::isShowSpectatorPasswordProtected() { QVariant previous = getValue("show_spectator_password_protected"); - return previous == QVariant() ? true : previous.toBool(); + return previous == QVariant() ? false : previous.toBool(); } void GameFiltersSettings::setShowOnlyIfSpectatorsCanChat(bool show) @@ -193,7 +193,7 @@ void GameFiltersSettings::setShowOnlyIfSpectatorsCanChat(bool show) bool GameFiltersSettings::isShowOnlyIfSpectatorsCanChat() { QVariant previous = getValue("show_only_if_spectators_can_chat"); - return previous == QVariant() ? true : previous.toBool(); + return previous == QVariant() ? false : previous.toBool(); } void GameFiltersSettings::setShowOnlyIfSpectatorsCanSeeHands(bool show) @@ -204,5 +204,5 @@ void GameFiltersSettings::setShowOnlyIfSpectatorsCanSeeHands(bool show) bool GameFiltersSettings::isShowOnlyIfSpectatorsCanSeeHands() { QVariant previous = getValue("show_only_if_spectators_can_see_hands"); - return previous == QVariant() ? true : previous.toBool(); + return previous == QVariant() ? false : previous.toBool(); } \ No newline at end of file diff --git a/libcockatrice_settings/libcockatrice/settings/game_filters_settings.h b/libcockatrice_settings/libcockatrice/settings/game_filters_settings.h index ef2d802fd..d62fea03d 100644 --- a/libcockatrice_settings/libcockatrice/settings/game_filters_settings.h +++ b/libcockatrice_settings/libcockatrice/settings/game_filters_settings.h @@ -24,7 +24,7 @@ public: bool isHideNotBuddyCreatedGames(); bool isHideOpenDecklistGames(); QString getGameNameFilter(); - QString getCreatorNameFilter(); + QStringList getCreatorNameFilters(); int getMinPlayers(); int getMaxPlayers(); QTime getMaxGameAge(); @@ -42,7 +42,7 @@ public: void setHidePasswordProtectedGames(bool hide); void setHideNotBuddyCreatedGames(bool hide); void setGameNameFilter(QString gameName); - void setCreatorNameFilter(QString creatorName); + void setCreatorNameFilters(QStringList creatorName); void setMinPlayers(int min); void setMaxPlayers(int max); void setMaxGameAge(const QTime &maxGameAge);