Hide games created/hosted by people on your Ignore List (#3883)
* Implement filter for games created by ignored users.
This commit is contained in:
parent
7bfefee073
commit
0f18fa9546
9 changed files with 99 additions and 4 deletions
|
@ -25,6 +25,9 @@ DlgFilterGames::DlgFilterGames(const QMap<int, QString> &_allGameTypes,
|
|||
showPasswordProtectedGames = new QCheckBox(tr("Show &password protected games"));
|
||||
showPasswordProtectedGames->setChecked(gamesProxyModel->getShowPasswordProtectedGames());
|
||||
|
||||
hideIgnoredUserGames = new QCheckBox(tr("Hide '&ignored user' games"));
|
||||
hideIgnoredUserGames->setChecked(gamesProxyModel->getHideIgnoredUserGames());
|
||||
|
||||
gameNameFilterEdit = new QLineEdit;
|
||||
gameNameFilterEdit->setText(gamesProxyModel->getGameNameFilter());
|
||||
QLabel *gameNameFilterLabel = new QLabel(tr("Game &description:"));
|
||||
|
@ -87,6 +90,7 @@ DlgFilterGames::DlgFilterGames(const QMap<int, QString> &_allGameTypes,
|
|||
restrictionsLayout->addWidget(unavailableGamesVisibleCheckBox, 0, 0);
|
||||
restrictionsLayout->addWidget(showPasswordProtectedGames, 1, 0);
|
||||
restrictionsLayout->addWidget(showBuddiesOnlyGames, 2, 0);
|
||||
restrictionsLayout->addWidget(hideIgnoredUserGames, 3, 0);
|
||||
|
||||
QGroupBox *restrictionsGroupBox = new QGroupBox(tr("Restrictions"));
|
||||
restrictionsGroupBox->setLayout(restrictionsLayout);
|
||||
|
@ -154,6 +158,16 @@ void DlgFilterGames::setShowPasswordProtectedGames(bool _passwordProtectedGamesH
|
|||
showPasswordProtectedGames->setChecked(_passwordProtectedGamesHidden);
|
||||
}
|
||||
|
||||
bool DlgFilterGames::getHideIgnoredUserGames() const
|
||||
{
|
||||
return hideIgnoredUserGames->isChecked();
|
||||
}
|
||||
|
||||
void DlgFilterGames::setHideIgnoredUserGames(bool _hideIgnoredUserGames)
|
||||
{
|
||||
hideIgnoredUserGames->setChecked(_hideIgnoredUserGames);
|
||||
}
|
||||
|
||||
QString DlgFilterGames::getGameNameFilter() const
|
||||
{
|
||||
return gameNameFilterEdit->text();
|
||||
|
|
|
@ -20,6 +20,7 @@ private:
|
|||
QCheckBox *showBuddiesOnlyGames;
|
||||
QCheckBox *unavailableGamesVisibleCheckBox;
|
||||
QCheckBox *showPasswordProtectedGames;
|
||||
QCheckBox *hideIgnoredUserGames;
|
||||
QLineEdit *gameNameFilterEdit;
|
||||
QLineEdit *creatorNameFilterEdit;
|
||||
QMap<int, QCheckBox *> gameTypeFilterCheckBoxes;
|
||||
|
@ -43,6 +44,8 @@ public:
|
|||
void setShowPasswordProtectedGames(bool _passwordProtectedGamesHidden);
|
||||
bool getShowBuddiesOnlyGames() const;
|
||||
void setShowBuddiesOnlyGames(bool _showBuddiesOnlyGames);
|
||||
bool getHideIgnoredUserGames() const;
|
||||
void setHideIgnoredUserGames(bool _hideIgnoredUserGames);
|
||||
QString getGameNameFilter() const;
|
||||
void setGameNameFilter(const QString &_gameNameFilter);
|
||||
QString getCreatorNameFilter() const;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "gameselector.h"
|
||||
#include "abstractclient.h"
|
||||
#include "dlg_creategame.h"
|
||||
#include "dlg_filter_games.h"
|
||||
#include "gamesmodel.h"
|
||||
|
@ -8,6 +9,7 @@
|
|||
#include "pending_command.h"
|
||||
#include "tab_room.h"
|
||||
#include "tab_supervisor.h"
|
||||
#include "tab_userlists.h"
|
||||
#include <QApplication>
|
||||
#include <QCheckBox>
|
||||
#include <QDebug>
|
||||
|
@ -32,7 +34,7 @@ GameSelector::GameSelector(AbstractClient *_client,
|
|||
gameListView = new QTreeView;
|
||||
gameListModel = new GamesModel(_rooms, _gameTypes, this);
|
||||
if (showfilters) {
|
||||
gameListProxyModel = new GamesProxyModel(this, tabSupervisor->isOwnUserRegistered());
|
||||
gameListProxyModel = new GamesProxyModel(this, tabSupervisor);
|
||||
gameListProxyModel->setSourceModel(gameListModel);
|
||||
gameListProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
|
||||
gameListView->setModel(gameListProxyModel);
|
||||
|
@ -107,6 +109,32 @@ GameSelector::GameSelector(AbstractClient *_client,
|
|||
connect(gameListView->selectionModel(), SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)), this,
|
||||
SLOT(actSelectedGameChanged(const QModelIndex &, const QModelIndex &)));
|
||||
connect(gameListView, SIGNAL(activated(const QModelIndex &)), this, SLOT(actJoin()));
|
||||
|
||||
connect(client, SIGNAL(ignoreListReceived(const QList<ServerInfo_User> &)), this,
|
||||
SLOT(ignoreListReceived(const QList<ServerInfo_User> &)));
|
||||
connect(client, SIGNAL(addToListEventReceived(const Event_AddToList &)), this,
|
||||
SLOT(processAddToListEvent(const Event_AddToList &)));
|
||||
connect(client, SIGNAL(removeFromListEventReceived(const Event_RemoveFromList &)), this,
|
||||
SLOT(processRemoveFromListEvent(const Event_RemoveFromList &)));
|
||||
}
|
||||
|
||||
void GameSelector::ignoreListReceived(const QList<ServerInfo_User> &)
|
||||
{
|
||||
gameListProxyModel->refresh();
|
||||
}
|
||||
|
||||
void GameSelector::processAddToListEvent(const Event_AddToList &event)
|
||||
{
|
||||
if (event.list_name() == "ignore") {
|
||||
gameListProxyModel->refresh();
|
||||
}
|
||||
}
|
||||
|
||||
void GameSelector::processRemoveFromListEvent(const Event_RemoveFromList &event)
|
||||
{
|
||||
if (event.list_name() == "ignore") {
|
||||
gameListProxyModel->refresh();
|
||||
}
|
||||
}
|
||||
|
||||
void GameSelector::actSetFilter()
|
||||
|
@ -121,6 +149,7 @@ void GameSelector::actSetFilter()
|
|||
gameListProxyModel->setShowBuddiesOnlyGames(dlg.getShowBuddiesOnlyGames());
|
||||
gameListProxyModel->setUnavailableGamesVisible(dlg.getUnavailableGamesVisible());
|
||||
gameListProxyModel->setShowPasswordProtectedGames(dlg.getShowPasswordProtectedGames());
|
||||
gameListProxyModel->setHideIgnoredUserGames(dlg.getHideIgnoredUserGames());
|
||||
gameListProxyModel->setGameNameFilter(dlg.getGameNameFilter());
|
||||
gameListProxyModel->setCreatorNameFilter(dlg.getCreatorNameFilter());
|
||||
gameListProxyModel->setGameTypeFilter(dlg.getGameTypeFilter());
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include "gametypemap.h"
|
||||
#include <QGroupBox>
|
||||
#include <common/pb/event_add_to_list.pb.h>
|
||||
#include <common/pb/event_remove_from_list.pb.h>
|
||||
|
||||
class QTreeView;
|
||||
class GamesModel;
|
||||
|
@ -25,6 +27,10 @@ private slots:
|
|||
void actJoin();
|
||||
void actSelectedGameChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
||||
void checkResponse(const Response &response);
|
||||
|
||||
void ignoreListReceived(const QList<ServerInfo_User> &_ignoreList);
|
||||
void processAddToListEvent(const Event_AddToList &event);
|
||||
void processRemoveFromListEvent(const Event_RemoveFromList &event);
|
||||
signals:
|
||||
void gameJoined(int gameId);
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
#include "pb/serverinfo_game.pb.h"
|
||||
#include "pixmapgenerator.h"
|
||||
#include "settingscache.h"
|
||||
#include "tab_userlists.h"
|
||||
#include "userlist.h"
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QDebug>
|
||||
|
@ -253,8 +255,9 @@ void GamesModel::updateGameList(const ServerInfo_Game &game)
|
|||
endInsertRows();
|
||||
}
|
||||
|
||||
GamesProxyModel::GamesProxyModel(QObject *parent, bool _ownUserIsRegistered)
|
||||
: QSortFilterProxyModel(parent), ownUserIsRegistered(_ownUserIsRegistered), showBuddiesOnlyGames(false),
|
||||
GamesProxyModel::GamesProxyModel(QObject *parent, const TabSupervisor *_tabSupervisor)
|
||||
: QSortFilterProxyModel(parent), ownUserIsRegistered(_tabSupervisor->isOwnUserRegistered()),
|
||||
tabSupervisor(_tabSupervisor), showBuddiesOnlyGames(false), hideIgnoredUserGames(false),
|
||||
unavailableGamesVisible(false), showPasswordProtectedGames(true), maxPlayersFilterMin(-1), maxPlayersFilterMax(-1)
|
||||
{
|
||||
setSortRole(GamesModel::SORT_ROLE);
|
||||
|
@ -267,6 +270,12 @@ void GamesProxyModel::setShowBuddiesOnlyGames(bool _showBuddiesOnlyGames)
|
|||
invalidateFilter();
|
||||
}
|
||||
|
||||
void GamesProxyModel::setHideIgnoredUserGames(bool _hideIgnoredUserGames)
|
||||
{
|
||||
hideIgnoredUserGames = _hideIgnoredUserGames;
|
||||
invalidateFilter();
|
||||
}
|
||||
|
||||
void GamesProxyModel::setUnavailableGamesVisible(bool _unavailableGamesVisible)
|
||||
{
|
||||
unavailableGamesVisible = _unavailableGamesVisible;
|
||||
|
@ -323,6 +332,7 @@ void GamesProxyModel::loadFilterParameters(const QMap<int, QString> &allGameType
|
|||
|
||||
unavailableGamesVisible = settingsCache->gameFilters().isUnavailableGamesVisible();
|
||||
showPasswordProtectedGames = settingsCache->gameFilters().isShowPasswordProtectedGames();
|
||||
hideIgnoredUserGames = settingsCache->gameFilters().isHideIgnoredUserGames();
|
||||
gameNameFilter = settingsCache->gameFilters().getGameNameFilter();
|
||||
maxPlayersFilterMin = settingsCache->gameFilters().getMinPlayers();
|
||||
maxPlayersFilterMax = settingsCache->gameFilters().getMaxPlayers();
|
||||
|
@ -343,6 +353,7 @@ void GamesProxyModel::saveFilterParameters(const QMap<int, QString> &allGameType
|
|||
settingsCache->gameFilters().setShowBuddiesOnlyGames(showBuddiesOnlyGames);
|
||||
settingsCache->gameFilters().setUnavailableGamesVisible(unavailableGamesVisible);
|
||||
settingsCache->gameFilters().setShowPasswordProtectedGames(showPasswordProtectedGames);
|
||||
settingsCache->gameFilters().setHideIgnoredUserGames(hideIgnoredUserGames);
|
||||
settingsCache->gameFilters().setGameNameFilter(gameNameFilter);
|
||||
|
||||
QMapIterator<int, QString> gameTypeIterator(allGameTypes);
|
||||
|
@ -367,6 +378,10 @@ bool GamesProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex & /*sour
|
|||
if (!showBuddiesOnlyGames && game.only_buddies()) {
|
||||
return false;
|
||||
}
|
||||
if (hideIgnoredUserGames && tabSupervisor->getUserListsTab()->getIgnoreList()->getUsers().contains(
|
||||
QString::fromStdString(game.creator_info().name()))) {
|
||||
return false;
|
||||
}
|
||||
if (!unavailableGamesVisible) {
|
||||
if (game.player_count() == game.max_players())
|
||||
return false;
|
||||
|
@ -398,3 +413,8 @@ bool GamesProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex & /*sour
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
void GamesProxyModel::refresh()
|
||||
{
|
||||
invalidateFilter();
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "gametypemap.h"
|
||||
#include "pb/serverinfo_game.pb.h"
|
||||
#include "tab_supervisor.h"
|
||||
#include <QAbstractTableModel>
|
||||
#include <QList>
|
||||
#include <QSet>
|
||||
|
@ -65,7 +66,9 @@ class GamesProxyModel : public QSortFilterProxyModel
|
|||
Q_OBJECT
|
||||
private:
|
||||
bool ownUserIsRegistered;
|
||||
const TabSupervisor *tabSupervisor;
|
||||
bool showBuddiesOnlyGames;
|
||||
bool hideIgnoredUserGames;
|
||||
bool unavailableGamesVisible;
|
||||
bool showPasswordProtectedGames;
|
||||
QString gameNameFilter, creatorNameFilter;
|
||||
|
@ -75,13 +78,18 @@ private:
|
|||
static const int DEFAULT_MAX_PLAYERS_MAX = 99;
|
||||
|
||||
public:
|
||||
GamesProxyModel(QObject *parent = nullptr, bool _ownUserIsRegistered = false);
|
||||
GamesProxyModel(QObject *parent = nullptr, const TabSupervisor *_tabSupervisor = nullptr);
|
||||
|
||||
bool getShowBuddiesOnlyGames() const
|
||||
{
|
||||
return showBuddiesOnlyGames;
|
||||
}
|
||||
void setShowBuddiesOnlyGames(bool _showBuddiesOnlyGames);
|
||||
bool getHideIgnoredUserGames() const
|
||||
{
|
||||
return hideIgnoredUserGames;
|
||||
}
|
||||
void setHideIgnoredUserGames(bool _hideIgnoredUserGames);
|
||||
bool getUnavailableGamesVisible() const
|
||||
{
|
||||
return unavailableGamesVisible;
|
||||
|
@ -119,6 +127,7 @@ public:
|
|||
void resetFilterParameters();
|
||||
void loadFilterParameters(const QMap<int, QString> &allGameTypes);
|
||||
void saveFilterParameters(const QMap<int, QString> &allGameTypes);
|
||||
void refresh();
|
||||
|
||||
protected:
|
||||
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
|
||||
|
|
|
@ -48,6 +48,17 @@ bool GameFiltersSettings::isShowPasswordProtectedGames()
|
|||
return previous == QVariant() ? true : previous.toBool();
|
||||
}
|
||||
|
||||
void GameFiltersSettings::setHideIgnoredUserGames(bool hide)
|
||||
{
|
||||
setValue(hide, "hide_ignored_user_games", "filter_games");
|
||||
}
|
||||
|
||||
bool GameFiltersSettings::isHideIgnoredUserGames()
|
||||
{
|
||||
QVariant previous = getValue("hide_ignored_user_games", "filter_games");
|
||||
return previous == QVariant() ? false : previous.toBool();
|
||||
}
|
||||
|
||||
void GameFiltersSettings::setGameNameFilter(QString gameName)
|
||||
{
|
||||
setValue(gameName, "game_name_filter", "filter_games");
|
||||
|
|
|
@ -12,12 +12,14 @@ public:
|
|||
bool isShowBuddiesOnlyGames();
|
||||
bool isUnavailableGamesVisible();
|
||||
bool isShowPasswordProtectedGames();
|
||||
bool isHideIgnoredUserGames();
|
||||
QString getGameNameFilter();
|
||||
int getMinPlayers();
|
||||
int getMaxPlayers();
|
||||
bool isGameTypeEnabled(QString gametype);
|
||||
|
||||
void setShowBuddiesOnlyGames(bool show);
|
||||
void setHideIgnoredUserGames(bool hide);
|
||||
void setUnavailableGamesVisible(bool enabled);
|
||||
void setShowPasswordProtectedGames(bool show);
|
||||
void setGameNameFilter(QString gameName);
|
||||
|
|
|
@ -95,6 +95,7 @@ void SettingsCache::translateLegacySettings()
|
|||
gameFilters().setShowPasswordProtectedGames(legacySetting.value("show_password_protected_games").toBool());
|
||||
gameFilters().setGameNameFilter(legacySetting.value("game_name_filter").toString());
|
||||
gameFilters().setShowBuddiesOnlyGames(legacySetting.value("show_buddies_only_games").toBool());
|
||||
gameFilters().setHideIgnoredUserGames(legacySetting.value("hide_ignored_user_games").toBool());
|
||||
gameFilters().setMinPlayers(legacySetting.value("min_players").toInt());
|
||||
|
||||
if (legacySetting.value("max_players").toInt() > 1)
|
||||
|
|
Loading…
Reference in a new issue