mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-01 19:13:55 -07:00
Add option to share decklists on load. (#6029)
* Add option to share decklists on load. Took 1 hour 58 minutes Took 9 minutes Took 39 minutes * Lint. Took 14 minutes Took 2 minutes * Stuffs Took 39 minutes Took 4 seconds Took 43 minutes * Process local player first. Took 45 minutes * Consider if the setting is set on the game info first. Took 4 minutes * Save an indent level. Took 43 seconds * Don't commit logging config. Took 3 minutes * Remove a debug print. Took 10 seconds Took 7 seconds * Add another optional guard. Took 5 minutes * Hide the tab bar if only one (own deck) is visible. Took 9 minutes * Rename setting label for clarity Took 2 minutes * Capitalization. Took 3 minutes --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
881243da6a
commit
09381575a7
26 changed files with 268 additions and 33 deletions
64
cockatrice/src/game/deckview/tabbed_deck_view_container.cpp
Normal file
64
cockatrice/src/game/deckview/tabbed_deck_view_container.cpp
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
#include "tabbed_deck_view_container.h"
|
||||
|
||||
#include "../../client/tabs/tab_game.h"
|
||||
#include "deck_view.h"
|
||||
|
||||
TabbedDeckViewContainer::TabbedDeckViewContainer(int _playerId, TabGame *parent)
|
||||
: QTabWidget(nullptr), playerId(_playerId), parentGame(parent)
|
||||
{
|
||||
setTabsClosable(true);
|
||||
connect(this, &QTabWidget::tabCloseRequested, this, &TabbedDeckViewContainer::closeTab);
|
||||
|
||||
playerDeckView = new DeckViewContainer(playerId, parentGame);
|
||||
int playerTabIndex = addTab(playerDeckView, "Your Deck");
|
||||
tabBar()->setTabButton(playerTabIndex, QTabBar::RightSide, nullptr);
|
||||
updateTabBarVisibility();
|
||||
}
|
||||
|
||||
void TabbedDeckViewContainer::addOpponentDeckView(const DeckList &opponentDeck, int opponentId, QString opponentName)
|
||||
{
|
||||
if (opponentDeckViews.contains(opponentId)) {
|
||||
opponentDeckViews[opponentId]->setDeck(opponentDeck);
|
||||
} else {
|
||||
auto *opponentDeckView = new DeckView(this);
|
||||
opponentDeckView->setDeck(opponentDeck);
|
||||
|
||||
addTab(opponentDeckView, QString("%1's Deck").arg(opponentName));
|
||||
|
||||
opponentDeckViews.insert(opponentId, opponentDeckView);
|
||||
}
|
||||
updateTabBarVisibility();
|
||||
}
|
||||
|
||||
void TabbedDeckViewContainer::closeTab(int index)
|
||||
{
|
||||
QWidget *widgetToClose = widget(index);
|
||||
|
||||
// Prevent removing the player tab
|
||||
if (widgetToClose == playerDeckView) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove it from map if it's an opponent
|
||||
auto it = opponentDeckViews.begin();
|
||||
while (it != opponentDeckViews.end()) {
|
||||
if (it.value() == widgetToClose) {
|
||||
it = opponentDeckViews.erase(it);
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
removeTab(index);
|
||||
widgetToClose->deleteLater();
|
||||
updateTabBarVisibility();
|
||||
}
|
||||
|
||||
void TabbedDeckViewContainer::updateTabBarVisibility()
|
||||
{
|
||||
if (tabBar()->count() <= 1) {
|
||||
tabBar()->hide();
|
||||
} else {
|
||||
tabBar()->show();
|
||||
}
|
||||
}
|
||||
23
cockatrice/src/game/deckview/tabbed_deck_view_container.h
Normal file
23
cockatrice/src/game/deckview/tabbed_deck_view_container.h
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
#ifndef TABBED_DECK_VIEW_CONTAINER_H
|
||||
#define TABBED_DECK_VIEW_CONTAINER_H
|
||||
#include "deck_view_container.h"
|
||||
|
||||
#include <QTabWidget>
|
||||
|
||||
class TabbedDeckViewContainer : public QTabWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit TabbedDeckViewContainer(int _playerId, TabGame *parent);
|
||||
void closeTab(int index);
|
||||
void updateTabBarVisibility();
|
||||
void addOpponentDeckView(const DeckList &opponentDeck, int opponentId, QString opponentName);
|
||||
int playerId;
|
||||
TabGame *parentGame;
|
||||
DeckViewContainer *playerDeckView;
|
||||
|
||||
QMap<int, DeckView *> opponentDeckViews;
|
||||
};
|
||||
|
||||
#endif // TABBED_DECK_VIEW_CONTAINER_H
|
||||
|
|
@ -161,6 +161,7 @@ void GameSelector::actSetFilter()
|
|||
gameListProxyModel->setHidePasswordProtectedGames(dlg.getHidePasswordProtectedGames());
|
||||
gameListProxyModel->setHideIgnoredUserGames(dlg.getHideIgnoredUserGames());
|
||||
gameListProxyModel->setHideNotBuddyCreatedGames(dlg.getHideNotBuddyCreatedGames());
|
||||
gameListProxyModel->setHideOpenDecklistGames(dlg.getHideOpenDecklistGames());
|
||||
gameListProxyModel->setGameNameFilter(dlg.getGameNameFilter());
|
||||
gameListProxyModel->setCreatorNameFilter(dlg.getCreatorNameFilter());
|
||||
gameListProxyModel->setGameTypeFilter(dlg.getGameTypeFilter());
|
||||
|
|
|
|||
|
|
@ -153,6 +153,8 @@ QVariant GamesModel::data(const QModelIndex &index, int role) const
|
|||
result.append(tr("buddies only"));
|
||||
if (gameentry.only_registered())
|
||||
result.append(tr("reg. users only"));
|
||||
if (gameentry.share_decklists_on_load())
|
||||
result.append(tr("open decklists"));
|
||||
return result.join(", ");
|
||||
}
|
||||
case Qt::DecorationRole: {
|
||||
|
|
@ -320,6 +322,12 @@ void GamesProxyModel::setHideNotBuddyCreatedGames(bool value)
|
|||
invalidateFilter();
|
||||
}
|
||||
|
||||
void GamesProxyModel::setHideOpenDecklistGames(bool _hideOpenDecklistGames)
|
||||
{
|
||||
hideOpenDecklistGames = _hideOpenDecklistGames;
|
||||
invalidateFilter();
|
||||
}
|
||||
|
||||
void GamesProxyModel::setGameNameFilter(const QString &_gameNameFilter)
|
||||
{
|
||||
gameNameFilter = _gameNameFilter;
|
||||
|
|
@ -398,6 +406,7 @@ void GamesProxyModel::resetFilterParameters()
|
|||
hideBuddiesOnlyGames = false;
|
||||
hideIgnoredUserGames = false;
|
||||
hideNotBuddyCreatedGames = false;
|
||||
hideOpenDecklistGames = false;
|
||||
gameNameFilter = QString();
|
||||
creatorNameFilter = QString();
|
||||
gameTypeFilter.clear();
|
||||
|
|
@ -415,7 +424,7 @@ void GamesProxyModel::resetFilterParameters()
|
|||
bool GamesProxyModel::areFilterParametersSetToDefaults() const
|
||||
{
|
||||
return !hideFullGames && !hideGamesThatStarted && !hidePasswordProtectedGames && !hideBuddiesOnlyGames &&
|
||||
!hideIgnoredUserGames && !hideNotBuddyCreatedGames && gameNameFilter.isEmpty() &&
|
||||
!hideOpenDecklistGames && !hideIgnoredUserGames && !hideNotBuddyCreatedGames && gameNameFilter.isEmpty() &&
|
||||
creatorNameFilter.isEmpty() && gameTypeFilter.isEmpty() && maxPlayersFilterMin == DEFAULT_MAX_PLAYERS_MIN &&
|
||||
maxPlayersFilterMax == DEFAULT_MAX_PLAYERS_MAX && maxGameAge == DEFAULT_MAX_GAME_AGE &&
|
||||
!showOnlyIfSpectatorsCanWatch && !showSpectatorPasswordProtected && !showOnlyIfSpectatorsCanChat &&
|
||||
|
|
@ -431,6 +440,7 @@ void GamesProxyModel::loadFilterParameters(const QMap<int, QString> &allGameType
|
|||
hideIgnoredUserGames = gameFilters.isHideIgnoredUserGames();
|
||||
hideBuddiesOnlyGames = gameFilters.isHideBuddiesOnlyGames();
|
||||
hideNotBuddyCreatedGames = gameFilters.isHideNotBuddyCreatedGames();
|
||||
hideOpenDecklistGames = gameFilters.isHideOpenDecklistGames();
|
||||
gameNameFilter = gameFilters.getGameNameFilter();
|
||||
creatorNameFilter = gameFilters.getCreatorNameFilter();
|
||||
maxPlayersFilterMin = gameFilters.getMinPlayers();
|
||||
|
|
@ -461,6 +471,7 @@ void GamesProxyModel::saveFilterParameters(const QMap<int, QString> &allGameType
|
|||
gameFilters.setHidePasswordProtectedGames(hidePasswordProtectedGames);
|
||||
gameFilters.setHideIgnoredUserGames(hideIgnoredUserGames);
|
||||
gameFilters.setHideNotBuddyCreatedGames(hideNotBuddyCreatedGames);
|
||||
gameFilters.setHideOpenDecklistGames(hideOpenDecklistGames);
|
||||
gameFilters.setGameNameFilter(gameNameFilter);
|
||||
gameFilters.setCreatorNameFilter(creatorNameFilter);
|
||||
|
||||
|
|
@ -504,6 +515,9 @@ bool GamesProxyModel::filterAcceptsRow(int sourceRow) const
|
|||
if (hideBuddiesOnlyGames && game.only_buddies()) {
|
||||
return false;
|
||||
}
|
||||
if (hideOpenDecklistGames && game.share_decklists_on_load()) {
|
||||
return false;
|
||||
}
|
||||
if (hideIgnoredUserGames && userListProxy->isUserIgnored(QString::fromStdString(game.creator_info().name()))) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,6 +81,7 @@ private:
|
|||
bool hideGamesThatStarted;
|
||||
bool hidePasswordProtectedGames;
|
||||
bool hideNotBuddyCreatedGames;
|
||||
bool hideOpenDecklistGames;
|
||||
QString gameNameFilter, creatorNameFilter;
|
||||
QSet<int> gameTypeFilter;
|
||||
quint32 maxPlayersFilterMin, maxPlayersFilterMax;
|
||||
|
|
@ -121,6 +122,11 @@ public:
|
|||
return hideNotBuddyCreatedGames;
|
||||
}
|
||||
void setHideNotBuddyCreatedGames(bool value);
|
||||
bool getHideOpenDecklistGames() const
|
||||
{
|
||||
return hideOpenDecklistGames;
|
||||
}
|
||||
void setHideOpenDecklistGames(bool _hideOpenDecklistGames);
|
||||
QString getGameNameFilter() const
|
||||
{
|
||||
return gameNameFilter;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue