New visual deck storage (#5290)

* Add TabDeckStorageVisual

* Visual Deck Storage

* Add BannerCard to .cod format, use it in the visual deck storage widget.

* Show filename instead of deckname if deck name is empty.

* Lint.

* Don't delint cmake list through hooks.

* Add deck loading functionality.

* Open Decks on double click, not single click.

* Void event for now.

* Fix build issue with overload?

* Fix build issue with overload?

* Include QDebug.

* Turn the tab into a widget.

* Move the signals down to the widget, move the connections and slots up to the parent widgets.

* No banner card equals an empty CardInfoPtr.

* Add an option to sort by filename or last modified.

* Flip last modified comparison.

* Lint.

* Don't open decks twice in the storage tab.

* Fix unload deck not working by showing/hiding widgets instead of adding/removing to layout.

* Add a search bar.

* Add a card size slider.

* Lint.

* Lint.

* Lint.

* Fix settings mocks.

* No need to QDebug.

* No need to QDebug.

* Member variable.

* Member variable.

* Non-lambda.

* Change set to list conversion.

* Specify overload.

* Include MouseEvent

* Adjust font size dynamically.

* Add an option to show the visual deck storage on database load.

* Fix the close button not working on the tab, add an option to launch the visual deck storage tab to Cockatrice menu.

* Override virtual functions.

* Correct tab text.

* Add a setting to remember last used sorting order for visual deck storage widget.

* Update banner card combo box correctly.

* Fix mocks.

---------

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
Co-authored-by: Zach H <zahalpern+github@gmail.com>
This commit is contained in:
BruebachL 2025-01-06 00:12:20 +01:00 committed by GitHub
parent 7496e79e8c
commit 62f7c7f9ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
30 changed files with 834 additions and 31 deletions

View file

@ -105,6 +105,8 @@ DeckViewContainer::DeckViewContainer(int _playerId, TabGame *parent)
{
loadLocalButton = new QPushButton;
loadRemoteButton = new QPushButton;
unloadDeckButton = new QPushButton;
unloadDeckButton->setEnabled(false);
readyStartButton = new ToggleButton;
readyStartButton->setEnabled(false);
forceStartGameButton = new QPushButton;
@ -114,6 +116,7 @@ DeckViewContainer::DeckViewContainer(int _playerId, TabGame *parent)
connect(loadLocalButton, SIGNAL(clicked()), this, SLOT(loadLocalDeck()));
connect(readyStartButton, SIGNAL(clicked()), this, SLOT(readyStart()));
connect(unloadDeckButton, &QPushButton::clicked, this, &DeckViewContainer::unloadDeck);
connect(forceStartGameButton, &QPushButton::clicked, this, &DeckViewContainer::forceStart);
connect(sideboardLockButton, SIGNAL(clicked()), this, SLOT(sideboardLockButtonClicked()));
connect(sideboardLockButton, SIGNAL(stateChanged()), this, SLOT(updateSideboardLockButtonText()));
@ -127,6 +130,7 @@ DeckViewContainer::DeckViewContainer(int _playerId, TabGame *parent)
auto *buttonHBox = new QHBoxLayout;
buttonHBox->addWidget(loadLocalButton);
buttonHBox->addWidget(loadRemoteButton);
buttonHBox->addWidget(unloadDeckButton);
buttonHBox->addWidget(readyStartButton);
buttonHBox->addWidget(sideboardLockButton);
if (forceStartGameButton->isEnabled()) {
@ -134,13 +138,20 @@ DeckViewContainer::DeckViewContainer(int _playerId, TabGame *parent)
}
buttonHBox->setContentsMargins(0, 0, 0, 0);
buttonHBox->addStretch();
deckView = new DeckView;
connect(deckView, SIGNAL(newCardAdded(AbstractCardItem *)), this, SIGNAL(newCardAdded(AbstractCardItem *)));
connect(deckView, SIGNAL(sideboardPlanChanged()), this, SLOT(sideboardPlanChanged()));
deckView->setVisible(false);
auto *deckViewLayout = new QVBoxLayout;
visualDeckStorageWidget = new VisualDeckStorageWidget(this);
connect(visualDeckStorageWidget, &VisualDeckStorageWidget::imageDoubleClicked, this,
&DeckViewContainer::replaceDeckStorageWithDeckView);
deckViewLayout = new QVBoxLayout;
deckViewLayout->addLayout(buttonHBox);
deckViewLayout->addWidget(deckView);
deckViewLayout->addWidget(visualDeckStorageWidget);
deckViewLayout->setContentsMargins(0, 0, 0, 0);
setLayout(deckViewLayout);
@ -153,6 +164,7 @@ void DeckViewContainer::retranslateUi()
{
loadLocalButton->setText(tr("Load deck..."));
loadRemoteButton->setText(tr("Load remote deck..."));
unloadDeckButton->setText(tr("Unload deck..."));
readyStartButton->setText(tr("Ready to start"));
forceStartGameButton->setText(tr("Force start"));
updateSideboardLockButtonText();
@ -287,6 +299,44 @@ void TabGame::refreshShortcuts()
}
}
void DeckViewContainer::replaceDeckStorageWithDeckView(QMouseEvent *event, DeckPreviewCardPictureWidget *instance)
{
Q_UNUSED(event);
QString fileName = instance->filePath;
DeckLoader::FileFormat fmt = DeckLoader::getFormatFromName(fileName);
QString deckString;
DeckLoader deck;
bool error = !deck.loadFromFile(fileName, fmt);
if (!error) {
deckString = deck.writeToString_Native();
error = deckString.length() > MAX_FILE_LENGTH;
}
if (error) {
QMessageBox::critical(this, tr("Error"), tr("The selected file could not be loaded."));
return;
}
Command_DeckSelect cmd;
cmd.set_deck(deckString.toStdString());
PendingCommand *pend = parentGame->prepareGameCommand(cmd);
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this,
SLOT(deckSelectFinished(const Response &)));
parentGame->sendGameCommand(pend, playerId);
visualDeckStorageWidget->setVisible(false);
deckView->setVisible(true);
deckViewLayout->update();
unloadDeckButton->setEnabled(true);
}
void DeckViewContainer::unloadDeck()
{
deckView->setVisible(false);
visualDeckStorageWidget->setVisible(true);
deckViewLayout->update();
unloadDeckButton->setEnabled(false);
}
void DeckViewContainer::loadLocalDeck()
{
DlgLoadDeck dialog(this);