Add game filtering for spectator attributes (#4127)
This commit is contained in:
parent
1a94261490
commit
a49c4865bb
8 changed files with 291 additions and 62 deletions
|
@ -27,8 +27,11 @@ DlgFilterGames::DlgFilterGames(const QMap<int, QString> &_allGameTypes,
|
|||
showBuddiesOnlyGames = new QCheckBox(tr("Show '&buddies only' games"));
|
||||
showBuddiesOnlyGames->setChecked(gamesProxyModel->getShowBuddiesOnlyGames());
|
||||
|
||||
unavailableGamesVisibleCheckBox = new QCheckBox(tr("Show &unavailable games"));
|
||||
unavailableGamesVisibleCheckBox->setChecked(gamesProxyModel->getUnavailableGamesVisible());
|
||||
showFullGames = new QCheckBox(tr("Show &full games"));
|
||||
showFullGames->setChecked(gamesProxyModel->getShowFullGames());
|
||||
|
||||
showGamesThatStarted = new QCheckBox(tr("Show games &that have started"));
|
||||
showGamesThatStarted->setChecked(gamesProxyModel->getShowGamesThatStarted());
|
||||
|
||||
showPasswordProtectedGames = new QCheckBox(tr("Show &password protected games"));
|
||||
showPasswordProtectedGames->setChecked(gamesProxyModel->getShowPasswordProtectedGames());
|
||||
|
@ -41,19 +44,19 @@ DlgFilterGames::DlgFilterGames(const QMap<int, QString> &_allGameTypes,
|
|||
maxGameAgeComboBox->addItems(gameAgeMap.values());
|
||||
QTime gameAge = gamesProxyModel->getMaxGameAge();
|
||||
maxGameAgeComboBox->setCurrentIndex(gameAgeMap.keys().indexOf(gameAge)); // index is -1 if unknown
|
||||
QLabel *maxGameAgeLabel = new QLabel(tr("&Newer than:"));
|
||||
auto *maxGameAgeLabel = new QLabel(tr("&Newer than:"));
|
||||
maxGameAgeLabel->setBuddy(maxGameAgeComboBox);
|
||||
|
||||
gameNameFilterEdit = new QLineEdit;
|
||||
gameNameFilterEdit->setText(gamesProxyModel->getGameNameFilter());
|
||||
QLabel *gameNameFilterLabel = new QLabel(tr("Game &description:"));
|
||||
auto *gameNameFilterLabel = new QLabel(tr("Game &description:"));
|
||||
gameNameFilterLabel->setBuddy(gameNameFilterEdit);
|
||||
creatorNameFilterEdit = new QLineEdit;
|
||||
creatorNameFilterEdit->setText(gamesProxyModel->getCreatorNameFilter());
|
||||
QLabel *creatorNameFilterLabel = new QLabel(tr("&Creator name:"));
|
||||
auto *creatorNameFilterLabel = new QLabel(tr("&Creator name:"));
|
||||
creatorNameFilterLabel->setBuddy(creatorNameFilterEdit);
|
||||
|
||||
QGridLayout *generalGrid = new QGridLayout;
|
||||
auto *generalGrid = new QGridLayout;
|
||||
generalGrid->addWidget(gameNameFilterLabel, 0, 0);
|
||||
generalGrid->addWidget(gameNameFilterEdit, 0, 1);
|
||||
generalGrid->addWidget(creatorNameFilterLabel, 1, 0);
|
||||
|
@ -63,12 +66,12 @@ DlgFilterGames::DlgFilterGames(const QMap<int, QString> &_allGameTypes,
|
|||
generalGroupBox = new QGroupBox(tr("General"));
|
||||
generalGroupBox->setLayout(generalGrid);
|
||||
|
||||
QVBoxLayout *gameTypeFilterLayout = new QVBoxLayout;
|
||||
auto *gameTypeFilterLayout = new QVBoxLayout;
|
||||
QMapIterator<int, QString> gameTypesIterator(allGameTypes);
|
||||
while (gameTypesIterator.hasNext()) {
|
||||
gameTypesIterator.next();
|
||||
|
||||
QCheckBox *temp = new QCheckBox(gameTypesIterator.value());
|
||||
auto *temp = new QCheckBox(gameTypesIterator.value());
|
||||
temp->setChecked(gamesProxyModel->getGameTypeFilter().contains(gameTypesIterator.key()));
|
||||
|
||||
gameTypeFilterCheckBoxes.insert(gameTypesIterator.key(), temp);
|
||||
|
@ -79,61 +82,86 @@ DlgFilterGames::DlgFilterGames(const QMap<int, QString> &_allGameTypes,
|
|||
gameTypeFilterGroupBox = new QGroupBox(tr("&Game types"));
|
||||
gameTypeFilterGroupBox->setLayout(gameTypeFilterLayout);
|
||||
} else
|
||||
gameTypeFilterGroupBox = 0;
|
||||
gameTypeFilterGroupBox = nullptr;
|
||||
|
||||
QLabel *maxPlayersFilterMinLabel = new QLabel(tr("at &least:"));
|
||||
auto *maxPlayersFilterMinLabel = new QLabel(tr("at &least:"));
|
||||
maxPlayersFilterMinSpinBox = new QSpinBox;
|
||||
maxPlayersFilterMinSpinBox->setMinimum(1);
|
||||
maxPlayersFilterMinSpinBox->setMaximum(99);
|
||||
maxPlayersFilterMinSpinBox->setValue(gamesProxyModel->getMaxPlayersFilterMin());
|
||||
maxPlayersFilterMinLabel->setBuddy(maxPlayersFilterMinSpinBox);
|
||||
|
||||
QLabel *maxPlayersFilterMaxLabel = new QLabel(tr("at &most:"));
|
||||
auto *maxPlayersFilterMaxLabel = new QLabel(tr("at &most:"));
|
||||
maxPlayersFilterMaxSpinBox = new QSpinBox;
|
||||
maxPlayersFilterMaxSpinBox->setMinimum(1);
|
||||
maxPlayersFilterMaxSpinBox->setMaximum(99);
|
||||
maxPlayersFilterMaxSpinBox->setValue(gamesProxyModel->getMaxPlayersFilterMax());
|
||||
maxPlayersFilterMaxLabel->setBuddy(maxPlayersFilterMaxSpinBox);
|
||||
|
||||
QGridLayout *maxPlayersFilterLayout = new QGridLayout;
|
||||
auto *maxPlayersFilterLayout = new QGridLayout;
|
||||
maxPlayersFilterLayout->addWidget(maxPlayersFilterMinLabel, 0, 0);
|
||||
maxPlayersFilterLayout->addWidget(maxPlayersFilterMinSpinBox, 0, 1);
|
||||
maxPlayersFilterLayout->addWidget(maxPlayersFilterMaxLabel, 1, 0);
|
||||
maxPlayersFilterLayout->addWidget(maxPlayersFilterMaxSpinBox, 1, 1);
|
||||
|
||||
QGroupBox *maxPlayersGroupBox = new QGroupBox(tr("Maximum player count"));
|
||||
auto *maxPlayersGroupBox = new QGroupBox(tr("Maximum player count"));
|
||||
maxPlayersGroupBox->setLayout(maxPlayersFilterLayout);
|
||||
|
||||
QGridLayout *restrictionsLayout = new QGridLayout;
|
||||
restrictionsLayout->addWidget(unavailableGamesVisibleCheckBox, 0, 0);
|
||||
restrictionsLayout->addWidget(showPasswordProtectedGames, 1, 0);
|
||||
restrictionsLayout->addWidget(showBuddiesOnlyGames, 2, 0);
|
||||
restrictionsLayout->addWidget(hideIgnoredUserGames, 3, 0);
|
||||
auto *restrictionsLayout = new QGridLayout;
|
||||
restrictionsLayout->addWidget(showFullGames, 0, 0);
|
||||
restrictionsLayout->addWidget(showGamesThatStarted, 1, 0);
|
||||
restrictionsLayout->addWidget(showPasswordProtectedGames, 2, 0);
|
||||
restrictionsLayout->addWidget(showBuddiesOnlyGames, 3, 0);
|
||||
restrictionsLayout->addWidget(hideIgnoredUserGames, 4, 0);
|
||||
|
||||
QGroupBox *restrictionsGroupBox = new QGroupBox(tr("Restrictions"));
|
||||
auto *restrictionsGroupBox = new QGroupBox(tr("Restrictions"));
|
||||
restrictionsGroupBox->setLayout(restrictionsLayout);
|
||||
|
||||
QGridLayout *leftGrid = new QGridLayout;
|
||||
showOnlyIfSpectatorsCanWatch = new QCheckBox(tr("Show games only if &spectators can watch"));
|
||||
showOnlyIfSpectatorsCanWatch->setChecked(gamesProxyModel->getShowOnlyIfSpectatorsCanWatch());
|
||||
connect(showOnlyIfSpectatorsCanWatch, SIGNAL(toggled(bool)), this, SLOT(toggleSpectatorCheckboxEnabledness(bool)));
|
||||
|
||||
showSpectatorPasswordProtected = new QCheckBox(tr("Show spectator password p&rotected games"));
|
||||
showSpectatorPasswordProtected->setChecked(gamesProxyModel->getShowSpectatorPasswordProtected());
|
||||
showOnlyIfSpectatorsCanChat = new QCheckBox(tr("Show only if spectators can ch&at"));
|
||||
showOnlyIfSpectatorsCanChat->setChecked(gamesProxyModel->getShowOnlyIfSpectatorsCanChat());
|
||||
showOnlyIfSpectatorsCanSeeHands = new QCheckBox(tr("Show only if spectators can see &hands"));
|
||||
showOnlyIfSpectatorsCanSeeHands->setChecked(gamesProxyModel->getShowOnlyIfSpectatorsCanSeeHands());
|
||||
toggleSpectatorCheckboxEnabledness(getShowOnlyIfSpectatorsCanWatch());
|
||||
|
||||
auto *spectatorsLayout = new QGridLayout;
|
||||
spectatorsLayout->addWidget(showOnlyIfSpectatorsCanWatch, 0, 0);
|
||||
spectatorsLayout->addWidget(showSpectatorPasswordProtected, 1, 0);
|
||||
spectatorsLayout->addWidget(showOnlyIfSpectatorsCanChat, 2, 0);
|
||||
spectatorsLayout->addWidget(showOnlyIfSpectatorsCanSeeHands, 3, 0);
|
||||
|
||||
auto *spectatorsGroupBox = new QGroupBox(tr("Spectators"));
|
||||
spectatorsGroupBox->setLayout(spectatorsLayout);
|
||||
|
||||
auto *leftGrid = new QGridLayout;
|
||||
leftGrid->addWidget(generalGroupBox, 0, 0, 1, 2);
|
||||
leftGrid->addWidget(maxPlayersGroupBox, 2, 0, 1, 2);
|
||||
leftGrid->addWidget(restrictionsGroupBox, 3, 0, 1, 2);
|
||||
|
||||
QVBoxLayout *leftColumn = new QVBoxLayout;
|
||||
auto *leftColumn = new QVBoxLayout;
|
||||
leftColumn->addLayout(leftGrid);
|
||||
leftColumn->addStretch();
|
||||
|
||||
QVBoxLayout *rightColumn = new QVBoxLayout;
|
||||
rightColumn->addWidget(gameTypeFilterGroupBox);
|
||||
auto *rightGrid = new QGridLayout;
|
||||
rightGrid->addWidget(gameTypeFilterGroupBox, 0, 0, 1, 1);
|
||||
rightGrid->addWidget(spectatorsGroupBox, 1, 0, 1, 1);
|
||||
auto *rightColumn = new QVBoxLayout;
|
||||
rightColumn->addLayout(rightGrid);
|
||||
|
||||
QHBoxLayout *hbox = new QHBoxLayout;
|
||||
auto *hbox = new QHBoxLayout;
|
||||
hbox->addLayout(leftColumn);
|
||||
hbox->addLayout(rightColumn);
|
||||
|
||||
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
auto *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
connect(buttonBox, SIGNAL(accepted()), this, SLOT(actOk()));
|
||||
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||
|
||||
QVBoxLayout *mainLayout = new QVBoxLayout;
|
||||
auto *mainLayout = new QVBoxLayout;
|
||||
mainLayout->addLayout(hbox);
|
||||
mainLayout->addWidget(buttonBox);
|
||||
|
||||
|
@ -146,14 +174,21 @@ void DlgFilterGames::actOk()
|
|||
accept();
|
||||
}
|
||||
|
||||
bool DlgFilterGames::getUnavailableGamesVisible() const
|
||||
void DlgFilterGames::toggleSpectatorCheckboxEnabledness(bool spectatorsEnabled)
|
||||
{
|
||||
return unavailableGamesVisibleCheckBox->isChecked();
|
||||
showSpectatorPasswordProtected->setDisabled(!spectatorsEnabled);
|
||||
showOnlyIfSpectatorsCanChat->setDisabled(!spectatorsEnabled);
|
||||
showOnlyIfSpectatorsCanSeeHands->setDisabled(!spectatorsEnabled);
|
||||
}
|
||||
|
||||
void DlgFilterGames::setUnavailableGamesVisible(bool _unavailableGamesVisible)
|
||||
bool DlgFilterGames::getShowFullGames() const
|
||||
{
|
||||
unavailableGamesVisibleCheckBox->setChecked(_unavailableGamesVisible);
|
||||
return showFullGames->isChecked();
|
||||
}
|
||||
|
||||
bool DlgFilterGames::getShowGamesThatStarted() const
|
||||
{
|
||||
return showGamesThatStarted->isChecked();
|
||||
}
|
||||
|
||||
bool DlgFilterGames::getShowBuddiesOnlyGames() const
|
||||
|
@ -252,3 +287,23 @@ void DlgFilterGames::setMaxPlayersFilter(int _maxPlayersFilterMin, int _maxPlaye
|
|||
maxPlayersFilterMaxSpinBox->setValue(_maxPlayersFilterMax == -1 ? maxPlayersFilterMaxSpinBox->maximum()
|
||||
: _maxPlayersFilterMax);
|
||||
}
|
||||
|
||||
bool DlgFilterGames::getShowOnlyIfSpectatorsCanWatch() const
|
||||
{
|
||||
return showOnlyIfSpectatorsCanWatch->isChecked();
|
||||
}
|
||||
|
||||
bool DlgFilterGames::getShowSpectatorPasswordProtected() const
|
||||
{
|
||||
return showSpectatorPasswordProtected->isEnabled() && showSpectatorPasswordProtected->isChecked();
|
||||
}
|
||||
|
||||
bool DlgFilterGames::getShowOnlyIfSpectatorsCanChat() const
|
||||
{
|
||||
return showOnlyIfSpectatorsCanChat->isEnabled() && showOnlyIfSpectatorsCanChat->isChecked();
|
||||
}
|
||||
|
||||
bool DlgFilterGames::getShowOnlyIfSpectatorsCanSeeHands() const
|
||||
{
|
||||
return showOnlyIfSpectatorsCanSeeHands->isEnabled() && showOnlyIfSpectatorsCanSeeHands->isChecked();
|
||||
}
|
|
@ -22,7 +22,8 @@ class DlgFilterGames : public QDialog
|
|||
private:
|
||||
QGroupBox *generalGroupBox;
|
||||
QCheckBox *showBuddiesOnlyGames;
|
||||
QCheckBox *unavailableGamesVisibleCheckBox;
|
||||
QCheckBox *showFullGames;
|
||||
QCheckBox *showGamesThatStarted;
|
||||
QCheckBox *showPasswordProtectedGames;
|
||||
QCheckBox *hideIgnoredUserGames;
|
||||
QLineEdit *gameNameFilterEdit;
|
||||
|
@ -32,19 +33,25 @@ private:
|
|||
QSpinBox *maxPlayersFilterMaxSpinBox;
|
||||
QComboBox *maxGameAgeComboBox;
|
||||
|
||||
QCheckBox *showOnlyIfSpectatorsCanWatch;
|
||||
QCheckBox *showSpectatorPasswordProtected;
|
||||
QCheckBox *showOnlyIfSpectatorsCanChat;
|
||||
QCheckBox *showOnlyIfSpectatorsCanSeeHands;
|
||||
|
||||
const QMap<int, QString> &allGameTypes;
|
||||
const GamesProxyModel *gamesProxyModel;
|
||||
|
||||
private slots:
|
||||
void actOk();
|
||||
void toggleSpectatorCheckboxEnabledness(bool spectatorsEnabled);
|
||||
|
||||
public:
|
||||
DlgFilterGames(const QMap<int, QString> &_allGameTypes,
|
||||
const GamesProxyModel *_gamesProxyModel,
|
||||
QWidget *parent = nullptr);
|
||||
|
||||
bool getUnavailableGamesVisible() const;
|
||||
void setUnavailableGamesVisible(bool _unavailableGamesVisible);
|
||||
bool getShowFullGames() const;
|
||||
bool getShowGamesThatStarted() const;
|
||||
bool getShowPasswordProtectedGames() const;
|
||||
void setShowPasswordProtectedGames(bool _passwordProtectedGamesHidden);
|
||||
bool getShowBuddiesOnlyGames() const;
|
||||
|
@ -62,6 +69,10 @@ public:
|
|||
void setMaxPlayersFilter(int _maxPlayersFilterMin, int _maxPlayersFilterMax);
|
||||
const QTime &getMaxGameAge() const;
|
||||
const QMap<QTime, QString> gameAgeMap;
|
||||
bool getShowOnlyIfSpectatorsCanWatch() const;
|
||||
bool getShowSpectatorPasswordProtected() const;
|
||||
bool getShowOnlyIfSpectatorsCanChat() const;
|
||||
bool getShowOnlyIfSpectatorsCanSeeHands() const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -152,7 +152,8 @@ void GameSelector::actSetFilter()
|
|||
return;
|
||||
|
||||
gameListProxyModel->setShowBuddiesOnlyGames(dlg.getShowBuddiesOnlyGames());
|
||||
gameListProxyModel->setUnavailableGamesVisible(dlg.getUnavailableGamesVisible());
|
||||
gameListProxyModel->setShowFullGames(dlg.getShowFullGames());
|
||||
gameListProxyModel->setShowGamesThatStarted(dlg.getShowGamesThatStarted());
|
||||
gameListProxyModel->setShowPasswordProtectedGames(dlg.getShowPasswordProtectedGames());
|
||||
gameListProxyModel->setHideIgnoredUserGames(dlg.getHideIgnoredUserGames());
|
||||
gameListProxyModel->setGameNameFilter(dlg.getGameNameFilter());
|
||||
|
@ -160,6 +161,10 @@ void GameSelector::actSetFilter()
|
|||
gameListProxyModel->setGameTypeFilter(dlg.getGameTypeFilter());
|
||||
gameListProxyModel->setMaxPlayersFilter(dlg.getMaxPlayersFilterMin(), dlg.getMaxPlayersFilterMax());
|
||||
gameListProxyModel->setMaxGameAge(dlg.getMaxGameAge());
|
||||
gameListProxyModel->setShowOnlyIfSpectatorsCanWatch(dlg.getShowOnlyIfSpectatorsCanWatch());
|
||||
gameListProxyModel->setShowSpectatorPasswordProtected(dlg.getShowSpectatorPasswordProtected());
|
||||
gameListProxyModel->setShowOnlyIfSpectatorsCanChat(dlg.getShowOnlyIfSpectatorsCanChat());
|
||||
gameListProxyModel->setShowOnlyIfSpectatorsCanSeeHands(dlg.getShowOnlyIfSpectatorsCanSeeHands());
|
||||
gameListProxyModel->saveFilterParameters(gameTypeMap);
|
||||
|
||||
clearFilterButton->setEnabled(!gameListProxyModel->areFilterParametersSetToDefaults());
|
||||
|
|
|
@ -23,10 +23,15 @@ enum GameListColumn
|
|||
SPECTATORS
|
||||
};
|
||||
|
||||
const bool DEFAULT_UNAVAILABLE_GAMES_VISIBLE = false;
|
||||
const bool DEFAULT_SHOW_FULL_GAMES = false;
|
||||
const bool DEFAULT_SHOW_GAMES_THAT_STARTED = false;
|
||||
const bool DEFAULT_SHOW_PASSWORD_PROTECTED_GAMES = true;
|
||||
const bool DEFAULT_SHOW_BUDDIES_ONLY_GAMES = true;
|
||||
const bool DEFAULT_HIDE_IGNORED_USER_GAMES = false;
|
||||
const bool DEFAULT_SHOW_ONLY_IF_SPECTATORS_CAN_WATCH = false;
|
||||
const bool DEFAULT_SHOW_SPECTATOR_PASSWORD_PROTECTED = true;
|
||||
const bool DEFAULT_SHOW_ONLY_IF_SPECTATORS_CAN_CHAT = false;
|
||||
const bool DEFAULT_SHOW_ONLY_IF_SPECTATORS_CAN_SEE_HANDS = false;
|
||||
const int DEFAULT_MAX_PLAYERS_MIN = 1;
|
||||
const int DEFAULT_MAX_PLAYERS_MAX = 99;
|
||||
constexpr QTime DEFAULT_MAX_GAME_AGE = QTime();
|
||||
|
@ -288,9 +293,15 @@ void GamesProxyModel::setHideIgnoredUserGames(bool _hideIgnoredUserGames)
|
|||
invalidateFilter();
|
||||
}
|
||||
|
||||
void GamesProxyModel::setUnavailableGamesVisible(bool _unavailableGamesVisible)
|
||||
void GamesProxyModel::setShowFullGames(bool _showFullGames)
|
||||
{
|
||||
unavailableGamesVisible = _unavailableGamesVisible;
|
||||
showFullGames = _showFullGames;
|
||||
invalidateFilter();
|
||||
}
|
||||
|
||||
void GamesProxyModel::setShowGamesThatStarted(bool _showGamesThatStarted)
|
||||
{
|
||||
showGamesThatStarted = _showGamesThatStarted;
|
||||
invalidateFilter();
|
||||
}
|
||||
|
||||
|
@ -331,6 +342,30 @@ void GamesProxyModel::setMaxGameAge(const QTime &_maxGameAge)
|
|||
invalidateFilter();
|
||||
}
|
||||
|
||||
void GamesProxyModel::setShowOnlyIfSpectatorsCanWatch(bool _showOnlyIfSpectatorsCanWatch)
|
||||
{
|
||||
showOnlyIfSpectatorsCanWatch = _showOnlyIfSpectatorsCanWatch;
|
||||
invalidateFilter();
|
||||
}
|
||||
|
||||
void GamesProxyModel::setShowSpectatorPasswordProtected(bool _showSpectatorPasswordProtected)
|
||||
{
|
||||
showSpectatorPasswordProtected = _showSpectatorPasswordProtected;
|
||||
invalidateFilter();
|
||||
}
|
||||
|
||||
void GamesProxyModel::setShowOnlyIfSpectatorsCanChat(bool _showOnlyIfSpectatorsCanChat)
|
||||
{
|
||||
showOnlyIfSpectatorsCanChat = _showOnlyIfSpectatorsCanChat;
|
||||
invalidateFilter();
|
||||
}
|
||||
|
||||
void GamesProxyModel::setShowOnlyIfSpectatorsCanSeeHands(bool _showOnlyIfSpectatorsCanSeeHands)
|
||||
{
|
||||
showOnlyIfSpectatorsCanSeeHands = _showOnlyIfSpectatorsCanSeeHands;
|
||||
invalidateFilter();
|
||||
}
|
||||
|
||||
int GamesProxyModel::getNumFilteredGames() const
|
||||
{
|
||||
GamesModel *model = qobject_cast<GamesModel *>(sourceModel());
|
||||
|
@ -348,7 +383,8 @@ int GamesProxyModel::getNumFilteredGames() const
|
|||
|
||||
void GamesProxyModel::resetFilterParameters()
|
||||
{
|
||||
unavailableGamesVisible = DEFAULT_UNAVAILABLE_GAMES_VISIBLE;
|
||||
showFullGames = DEFAULT_SHOW_FULL_GAMES;
|
||||
showGamesThatStarted = DEFAULT_SHOW_GAMES_THAT_STARTED;
|
||||
showPasswordProtectedGames = DEFAULT_SHOW_PASSWORD_PROTECTED_GAMES;
|
||||
showBuddiesOnlyGames = DEFAULT_SHOW_BUDDIES_ONLY_GAMES;
|
||||
hideIgnoredUserGames = DEFAULT_HIDE_IGNORED_USER_GAMES;
|
||||
|
@ -358,24 +394,33 @@ void GamesProxyModel::resetFilterParameters()
|
|||
maxPlayersFilterMin = DEFAULT_MAX_PLAYERS_MIN;
|
||||
maxPlayersFilterMax = DEFAULT_MAX_PLAYERS_MAX;
|
||||
maxGameAge = DEFAULT_MAX_GAME_AGE;
|
||||
showOnlyIfSpectatorsCanWatch = DEFAULT_SHOW_ONLY_IF_SPECTATORS_CAN_WATCH;
|
||||
showSpectatorPasswordProtected = DEFAULT_SHOW_SPECTATOR_PASSWORD_PROTECTED;
|
||||
showOnlyIfSpectatorsCanChat = DEFAULT_SHOW_ONLY_IF_SPECTATORS_CAN_CHAT;
|
||||
showOnlyIfSpectatorsCanSeeHands = DEFAULT_SHOW_ONLY_IF_SPECTATORS_CAN_SEE_HANDS;
|
||||
|
||||
invalidateFilter();
|
||||
}
|
||||
|
||||
bool GamesProxyModel::areFilterParametersSetToDefaults() const
|
||||
{
|
||||
return unavailableGamesVisible == DEFAULT_UNAVAILABLE_GAMES_VISIBLE &&
|
||||
return showFullGames == DEFAULT_SHOW_FULL_GAMES && showGamesThatStarted == DEFAULT_SHOW_GAMES_THAT_STARTED &&
|
||||
showPasswordProtectedGames == DEFAULT_SHOW_PASSWORD_PROTECTED_GAMES &&
|
||||
showBuddiesOnlyGames == DEFAULT_SHOW_BUDDIES_ONLY_GAMES &&
|
||||
hideIgnoredUserGames == DEFAULT_HIDE_IGNORED_USER_GAMES && gameNameFilter.isEmpty() &&
|
||||
creatorNameFilter.isEmpty() && gameTypeFilter.isEmpty() && maxPlayersFilterMin == DEFAULT_MAX_PLAYERS_MIN &&
|
||||
maxPlayersFilterMax == DEFAULT_MAX_PLAYERS_MAX && maxGameAge == DEFAULT_MAX_GAME_AGE;
|
||||
maxPlayersFilterMax == DEFAULT_MAX_PLAYERS_MAX && maxGameAge == DEFAULT_MAX_GAME_AGE &&
|
||||
showOnlyIfSpectatorsCanWatch == DEFAULT_SHOW_ONLY_IF_SPECTATORS_CAN_WATCH &&
|
||||
showSpectatorPasswordProtected == DEFAULT_SHOW_SPECTATOR_PASSWORD_PROTECTED &&
|
||||
showOnlyIfSpectatorsCanChat == DEFAULT_SHOW_ONLY_IF_SPECTATORS_CAN_CHAT &&
|
||||
showOnlyIfSpectatorsCanSeeHands == DEFAULT_SHOW_ONLY_IF_SPECTATORS_CAN_SEE_HANDS;
|
||||
}
|
||||
|
||||
void GamesProxyModel::loadFilterParameters(const QMap<int, QString> &allGameTypes)
|
||||
{
|
||||
GameFiltersSettings &gameFilters = SettingsCache::instance().gameFilters();
|
||||
unavailableGamesVisible = gameFilters.isUnavailableGamesVisible();
|
||||
showFullGames = gameFilters.isShowFullGames();
|
||||
showGamesThatStarted = gameFilters.isShowGamesThatStarted();
|
||||
showPasswordProtectedGames = gameFilters.isShowPasswordProtectedGames();
|
||||
hideIgnoredUserGames = gameFilters.isHideIgnoredUserGames();
|
||||
showBuddiesOnlyGames = gameFilters.isShowBuddiesOnlyGames();
|
||||
|
@ -384,6 +429,10 @@ void GamesProxyModel::loadFilterParameters(const QMap<int, QString> &allGameType
|
|||
maxPlayersFilterMin = gameFilters.getMinPlayers();
|
||||
maxPlayersFilterMax = gameFilters.getMaxPlayers();
|
||||
maxGameAge = gameFilters.getMaxGameAge();
|
||||
showOnlyIfSpectatorsCanWatch = gameFilters.isShowOnlyIfSpectatorsCanWatch();
|
||||
showSpectatorPasswordProtected = gameFilters.isShowSpectatorPasswordProtected();
|
||||
showOnlyIfSpectatorsCanChat = gameFilters.isShowOnlyIfSpectatorsCanChat();
|
||||
showOnlyIfSpectatorsCanSeeHands = gameFilters.isShowOnlyIfSpectatorsCanSeeHands();
|
||||
|
||||
QMapIterator<int, QString> gameTypesIterator(allGameTypes);
|
||||
while (gameTypesIterator.hasNext()) {
|
||||
|
@ -400,7 +449,8 @@ void GamesProxyModel::saveFilterParameters(const QMap<int, QString> &allGameType
|
|||
{
|
||||
GameFiltersSettings &gameFilters = SettingsCache::instance().gameFilters();
|
||||
gameFilters.setShowBuddiesOnlyGames(showBuddiesOnlyGames);
|
||||
gameFilters.setUnavailableGamesVisible(unavailableGamesVisible);
|
||||
gameFilters.setShowFullGames(showFullGames);
|
||||
gameFilters.setShowGamesThatStarted(showGamesThatStarted);
|
||||
gameFilters.setShowPasswordProtectedGames(showPasswordProtectedGames);
|
||||
gameFilters.setHideIgnoredUserGames(hideIgnoredUserGames);
|
||||
gameFilters.setGameNameFilter(gameNameFilter);
|
||||
|
@ -416,6 +466,11 @@ void GamesProxyModel::saveFilterParameters(const QMap<int, QString> &allGameType
|
|||
gameFilters.setMinPlayers(maxPlayersFilterMin);
|
||||
gameFilters.setMaxPlayers(maxPlayersFilterMax);
|
||||
gameFilters.setMaxGameAge(maxGameAge);
|
||||
|
||||
gameFilters.setShowOnlyIfSpectatorsCanWatch(showOnlyIfSpectatorsCanWatch);
|
||||
gameFilters.setShowSpectatorPasswordProtected(showSpectatorPasswordProtected);
|
||||
gameFilters.setShowOnlyIfSpectatorsCanChat(showOnlyIfSpectatorsCanChat);
|
||||
gameFilters.setShowOnlyIfSpectatorsCanSeeHands(showOnlyIfSpectatorsCanSeeHands);
|
||||
}
|
||||
|
||||
bool GamesProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex & /*sourceParent*/) const
|
||||
|
@ -430,7 +485,7 @@ bool GamesProxyModel::filterAcceptsRow(int sourceRow) const
|
|||
#else
|
||||
static const QDate epochDate = QDateTime::fromTime_t(0, Qt::UTC).date();
|
||||
#endif
|
||||
GamesModel *model = qobject_cast<GamesModel *>(sourceModel());
|
||||
auto *model = qobject_cast<GamesModel *>(sourceModel());
|
||||
if (!model)
|
||||
return false;
|
||||
|
||||
|
@ -443,15 +498,13 @@ bool GamesProxyModel::filterAcceptsRow(int sourceRow) const
|
|||
QString::fromStdString(game.creator_info().name()))) {
|
||||
return false;
|
||||
}
|
||||
if (!unavailableGamesVisible) {
|
||||
if (game.player_count() == game.max_players())
|
||||
if (!showFullGames && game.player_count() == game.max_players())
|
||||
return false;
|
||||
if (!showGamesThatStarted && game.started())
|
||||
return false;
|
||||
if (!ownUserIsRegistered)
|
||||
if (game.only_registered())
|
||||
return false;
|
||||
if (game.started())
|
||||
return false;
|
||||
if (!ownUserIsRegistered)
|
||||
if (game.only_registered())
|
||||
return false;
|
||||
}
|
||||
if (!showPasswordProtectedGames && game.with_password())
|
||||
return false;
|
||||
if (!gameNameFilter.isEmpty())
|
||||
|
@ -482,6 +535,17 @@ bool GamesProxyModel::filterAcceptsRow(int sourceRow) const
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (showOnlyIfSpectatorsCanWatch) {
|
||||
if (!game.spectators_allowed())
|
||||
return false;
|
||||
if (!showSpectatorPasswordProtected && game.spectators_need_password())
|
||||
return false;
|
||||
if (showOnlyIfSpectatorsCanChat && !game.spectators_can_chat())
|
||||
return false;
|
||||
if (showOnlyIfSpectatorsCanSeeHands && !game.spectators_omniscient())
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -80,12 +80,15 @@ private:
|
|||
// - filterAcceptsRow()
|
||||
bool showBuddiesOnlyGames;
|
||||
bool hideIgnoredUserGames;
|
||||
bool unavailableGamesVisible;
|
||||
bool showFullGames;
|
||||
bool showGamesThatStarted;
|
||||
bool showPasswordProtectedGames;
|
||||
QString gameNameFilter, creatorNameFilter;
|
||||
QSet<int> gameTypeFilter;
|
||||
quint32 maxPlayersFilterMin, maxPlayersFilterMax;
|
||||
QTime maxGameAge;
|
||||
bool showOnlyIfSpectatorsCanWatch, showSpectatorPasswordProtected, showOnlyIfSpectatorsCanChat,
|
||||
showOnlyIfSpectatorsCanSeeHands;
|
||||
|
||||
public:
|
||||
GamesProxyModel(QObject *parent = nullptr, const TabSupervisor *_tabSupervisor = nullptr);
|
||||
|
@ -100,11 +103,16 @@ public:
|
|||
return hideIgnoredUserGames;
|
||||
}
|
||||
void setHideIgnoredUserGames(bool _hideIgnoredUserGames);
|
||||
bool getUnavailableGamesVisible() const
|
||||
bool getShowFullGames() const
|
||||
{
|
||||
return unavailableGamesVisible;
|
||||
return showFullGames;
|
||||
}
|
||||
void setUnavailableGamesVisible(bool _unavailableGamesVisible);
|
||||
void setShowFullGames(bool _showFullGames);
|
||||
bool getShowGamesThatStarted() const
|
||||
{
|
||||
return showGamesThatStarted;
|
||||
}
|
||||
void setShowGamesThatStarted(bool _showGamesThatStarted);
|
||||
bool getShowPasswordProtectedGames() const
|
||||
{
|
||||
return showPasswordProtectedGames;
|
||||
|
@ -139,6 +147,26 @@ public:
|
|||
return maxGameAge;
|
||||
}
|
||||
void setMaxGameAge(const QTime &_maxGameAge);
|
||||
bool getShowOnlyIfSpectatorsCanWatch() const
|
||||
{
|
||||
return showOnlyIfSpectatorsCanWatch;
|
||||
}
|
||||
void setShowOnlyIfSpectatorsCanWatch(bool _showOnlyIfSpectatorsCanWatch);
|
||||
bool getShowSpectatorPasswordProtected() const
|
||||
{
|
||||
return showSpectatorPasswordProtected;
|
||||
}
|
||||
void setShowSpectatorPasswordProtected(bool _showSpectatorPasswordProtected);
|
||||
bool getShowOnlyIfSpectatorsCanChat() const
|
||||
{
|
||||
return showOnlyIfSpectatorsCanChat;
|
||||
}
|
||||
void setShowOnlyIfSpectatorsCanChat(bool _showOnlyIfSpectatorsCanChat);
|
||||
bool getShowOnlyIfSpectatorsCanSeeHands() const
|
||||
{
|
||||
return showOnlyIfSpectatorsCanSeeHands;
|
||||
}
|
||||
void setShowOnlyIfSpectatorsCanSeeHands(bool _showOnlyIfSpectatorsCanSeeHands);
|
||||
|
||||
int getNumFilteredGames() const;
|
||||
void resetFilterParameters();
|
||||
|
|
|
@ -28,14 +28,25 @@ bool GameFiltersSettings::isShowBuddiesOnlyGames()
|
|||
return previous == QVariant() ? true : previous.toBool();
|
||||
}
|
||||
|
||||
void GameFiltersSettings::setUnavailableGamesVisible(bool enabled)
|
||||
void GameFiltersSettings::setShowFullGames(bool show)
|
||||
{
|
||||
setValue(enabled, "unavailable_games_visible", "filter_games");
|
||||
setValue(show, "show_full_games", "filter_games");
|
||||
}
|
||||
|
||||
bool GameFiltersSettings::isUnavailableGamesVisible()
|
||||
bool GameFiltersSettings::isShowFullGames()
|
||||
{
|
||||
QVariant previous = getValue("unavailable_games_visible", "filter_games");
|
||||
QVariant previous = getValue("show_full_games", "filter_games");
|
||||
return previous == QVariant() ? false : previous.toBool();
|
||||
}
|
||||
|
||||
void GameFiltersSettings::setShowGamesThatStarted(bool show)
|
||||
{
|
||||
setValue(show, "show_games_that_started", "filter_games");
|
||||
}
|
||||
|
||||
bool GameFiltersSettings::isShowGamesThatStarted()
|
||||
{
|
||||
QVariant previous = getValue("show_games_that_started", "filter_games");
|
||||
return previous == QVariant() ? false : previous.toBool();
|
||||
}
|
||||
|
||||
|
@ -129,3 +140,47 @@ bool GameFiltersSettings::isGameTypeEnabled(QString gametype)
|
|||
QVariant previous = getValue("game_type/" + hashGameType(gametype), "filter_games");
|
||||
return previous == QVariant() ? false : previous.toBool();
|
||||
}
|
||||
|
||||
void GameFiltersSettings::setShowOnlyIfSpectatorsCanWatch(bool show)
|
||||
{
|
||||
setValue(show, "show_only_if_spectators_can_watch", "filter_games");
|
||||
}
|
||||
|
||||
bool GameFiltersSettings::isShowOnlyIfSpectatorsCanWatch()
|
||||
{
|
||||
QVariant previous = getValue("show_only_if_spectators_can_watch", "filter_games");
|
||||
return previous == QVariant() ? false : previous.toBool();
|
||||
}
|
||||
|
||||
void GameFiltersSettings::setShowSpectatorPasswordProtected(bool show)
|
||||
{
|
||||
setValue(show, "show_spectator_password_protected", "filter_games");
|
||||
}
|
||||
|
||||
bool GameFiltersSettings::isShowSpectatorPasswordProtected()
|
||||
{
|
||||
QVariant previous = getValue("show_spectator_password_protected", "filter_games");
|
||||
return previous == QVariant() ? true : previous.toBool();
|
||||
}
|
||||
|
||||
void GameFiltersSettings::setShowOnlyIfSpectatorsCanChat(bool show)
|
||||
{
|
||||
setValue(show, "show_only_if_spectators_can_chat", "filter_games");
|
||||
}
|
||||
|
||||
bool GameFiltersSettings::isShowOnlyIfSpectatorsCanChat()
|
||||
{
|
||||
QVariant previous = getValue("show_only_if_spectators_can_chat", "filter_games");
|
||||
return previous == QVariant() ? true : previous.toBool();
|
||||
}
|
||||
|
||||
void GameFiltersSettings::setShowOnlyIfSpectatorsCanSeeHands(bool show)
|
||||
{
|
||||
setValue(show, "show_only_if_spectators_can_see_hands", "filter_games");
|
||||
}
|
||||
|
||||
bool GameFiltersSettings::isShowOnlyIfSpectatorsCanSeeHands()
|
||||
{
|
||||
QVariant previous = getValue("show_only_if_spectators_can_see_hands", "filter_games");
|
||||
return previous == QVariant() ? true : previous.toBool();
|
||||
}
|
|
@ -10,7 +10,8 @@ class GameFiltersSettings : public SettingsManager
|
|||
|
||||
public:
|
||||
bool isShowBuddiesOnlyGames();
|
||||
bool isUnavailableGamesVisible();
|
||||
bool isShowFullGames();
|
||||
bool isShowGamesThatStarted();
|
||||
bool isShowPasswordProtectedGames();
|
||||
bool isHideIgnoredUserGames();
|
||||
QString getGameNameFilter();
|
||||
|
@ -19,10 +20,15 @@ public:
|
|||
int getMaxPlayers();
|
||||
QTime getMaxGameAge();
|
||||
bool isGameTypeEnabled(QString gametype);
|
||||
bool isShowOnlyIfSpectatorsCanWatch();
|
||||
bool isShowSpectatorPasswordProtected();
|
||||
bool isShowOnlyIfSpectatorsCanChat();
|
||||
bool isShowOnlyIfSpectatorsCanSeeHands();
|
||||
|
||||
void setShowBuddiesOnlyGames(bool show);
|
||||
void setHideIgnoredUserGames(bool hide);
|
||||
void setUnavailableGamesVisible(bool enabled);
|
||||
void setShowFullGames(bool show);
|
||||
void setShowGamesThatStarted(bool show);
|
||||
void setShowPasswordProtectedGames(bool show);
|
||||
void setGameNameFilter(QString gameName);
|
||||
void setCreatorNameFilter(QString creatorName);
|
||||
|
@ -31,6 +37,10 @@ public:
|
|||
void setMaxGameAge(const QTime &maxGameAge);
|
||||
void setGameTypeEnabled(QString gametype, bool enabled);
|
||||
void setGameHashedTypeEnabled(QString gametypeHASHED, bool enabled);
|
||||
void setShowOnlyIfSpectatorsCanWatch(bool show);
|
||||
void setShowSpectatorPasswordProtected(bool show);
|
||||
void setShowOnlyIfSpectatorsCanChat(bool show);
|
||||
void setShowOnlyIfSpectatorsCanSeeHands(bool show);
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
|
|
@ -95,7 +95,8 @@ void SettingsCache::translateLegacySettings()
|
|||
|
||||
// Game filters
|
||||
legacySetting.beginGroup("filter_games");
|
||||
gameFilters().setUnavailableGamesVisible(legacySetting.value("unavailable_games_visible").toBool());
|
||||
gameFilters().setShowFullGames(legacySetting.value("unavailable_games_visible").toBool());
|
||||
gameFilters().setShowGamesThatStarted(legacySetting.value("unavailable_games_visible").toBool());
|
||||
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());
|
||||
|
|
Loading…
Reference in a new issue