mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-19 17:02:15 -07:00
Turn the tab into a widget.
This commit is contained in:
parent
f8db3017ff
commit
29943d9127
7 changed files with 120 additions and 73 deletions
|
|
@ -161,6 +161,7 @@ set(cockatrice_SOURCES
|
||||||
src/game/zones/view_zone.cpp
|
src/game/zones/view_zone.cpp
|
||||||
src/client/tabs/visual_deck_storage/tab_deck_storage_visual.cpp
|
src/client/tabs/visual_deck_storage/tab_deck_storage_visual.cpp
|
||||||
src/client/ui/widgets/cards/deck_preview_card_picture_widget.cpp
|
src/client/ui/widgets/cards/deck_preview_card_picture_widget.cpp
|
||||||
|
src/client/ui/widgets/visual_deck_storage/visual_deck_storage_widget.cpp
|
||||||
${VERSION_STRING_CPP}
|
${VERSION_STRING_CPP}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -133,13 +133,16 @@ DeckViewContainer::DeckViewContainer(int _playerId, TabGame *parent)
|
||||||
}
|
}
|
||||||
buttonHBox->setContentsMargins(0, 0, 0, 0);
|
buttonHBox->setContentsMargins(0, 0, 0, 0);
|
||||||
buttonHBox->addStretch();
|
buttonHBox->addStretch();
|
||||||
|
|
||||||
deckView = new DeckView;
|
deckView = new DeckView;
|
||||||
connect(deckView, SIGNAL(newCardAdded(AbstractCardItem *)), this, SIGNAL(newCardAdded(AbstractCardItem *)));
|
connect(deckView, SIGNAL(newCardAdded(AbstractCardItem *)), this, SIGNAL(newCardAdded(AbstractCardItem *)));
|
||||||
connect(deckView, SIGNAL(sideboardPlanChanged()), this, SLOT(sideboardPlanChanged()));
|
connect(deckView, SIGNAL(sideboardPlanChanged()), this, SLOT(sideboardPlanChanged()));
|
||||||
|
|
||||||
|
visualDeckStorageWidget = new VisualDeckStorageWidget(this);
|
||||||
|
|
||||||
auto *deckViewLayout = new QVBoxLayout;
|
auto *deckViewLayout = new QVBoxLayout;
|
||||||
deckViewLayout->addLayout(buttonHBox);
|
deckViewLayout->addLayout(buttonHBox);
|
||||||
deckViewLayout->addWidget(deckView);
|
deckViewLayout->addWidget(visualDeckStorageWidget);
|
||||||
deckViewLayout->setContentsMargins(0, 0, 0, 0);
|
deckViewLayout->setContentsMargins(0, 0, 0, 0);
|
||||||
setLayout(deckViewLayout);
|
setLayout(deckViewLayout);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include "../../client/tearoff_menu.h"
|
#include "../../client/tearoff_menu.h"
|
||||||
#include "../../game/player/player.h"
|
#include "../../game/player/player.h"
|
||||||
|
#include "../ui/widgets/visual_deck_storage/visual_deck_storage_widget.h"
|
||||||
#include "pb/event_leave.pb.h"
|
#include "pb/event_leave.pb.h"
|
||||||
#include "pb/serverinfo_game.pb.h"
|
#include "pb/serverinfo_game.pb.h"
|
||||||
#include "tab.h"
|
#include "tab.h"
|
||||||
|
|
@ -89,6 +90,7 @@ private:
|
||||||
QPushButton *loadLocalButton, *loadRemoteButton, *forceStartGameButton;
|
QPushButton *loadLocalButton, *loadRemoteButton, *forceStartGameButton;
|
||||||
ToggleButton *readyStartButton, *sideboardLockButton;
|
ToggleButton *readyStartButton, *sideboardLockButton;
|
||||||
DeckView *deckView;
|
DeckView *deckView;
|
||||||
|
VisualDeckStorageWidget *visualDeckStorageWidget;
|
||||||
TabGame *parentGame;
|
TabGame *parentGame;
|
||||||
int playerId;
|
int playerId;
|
||||||
private slots:
|
private slots:
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,6 @@
|
||||||
#include "tab_deck_storage_visual.h"
|
#include "tab_deck_storage_visual.h"
|
||||||
|
|
||||||
#include "../../../deck/deck_list_model.h"
|
|
||||||
#include "../../../deck/deck_loader.h"
|
|
||||||
#include "../../../deck/deck_view.h"
|
|
||||||
#include "../../../game/cards/card_database_manager.h"
|
|
||||||
#include "../../../game/cards/card_database_model.h"
|
#include "../../../game/cards/card_database_model.h"
|
||||||
#include "../../../main.h"
|
|
||||||
#include "../../../settings/cache_settings.h"
|
|
||||||
#include "../../dbconverter/src/mocks.h"
|
|
||||||
#include "../../ui/picture_loader.h"
|
|
||||||
#include "../../ui/widgets/cards/card_info_picture_widget.h"
|
|
||||||
#include "../../ui/widgets/cards/card_info_picture_with_text_overlay_widget.h"
|
|
||||||
#include "../../ui/widgets/cards/deck_preview_card_picture_widget.h"
|
|
||||||
#include "../../ui/widgets/general/layout_containers/flow_widget.h"
|
|
||||||
#include "../../ui/widgets/general/layout_containers/overlap_widget.h"
|
|
||||||
#include "../tab_supervisor.h"
|
#include "../tab_supervisor.h"
|
||||||
#include "pb/command_deck_del.pb.h"
|
#include "pb/command_deck_del.pb.h"
|
||||||
|
|
||||||
|
|
@ -36,17 +23,15 @@ TabDeckStorageVisual::TabDeckStorageVisual(TabSupervisor *_tabSupervisor, Abstra
|
||||||
deck_list_model = new DeckListModel(this);
|
deck_list_model = new DeckListModel(this);
|
||||||
deck_list_model->setObjectName("visualDeckModel");
|
deck_list_model->setObjectName("visualDeckModel");
|
||||||
|
|
||||||
flow_widget = new FlowWidget(this, Qt::ScrollBarAlwaysOff, Qt::ScrollBarPolicy::ScrollBarAsNeeded);
|
QWidget *container = new QWidget(this);
|
||||||
this->setCentralWidget(flow_widget);
|
QVBoxLayout *layout = new QVBoxLayout(container);
|
||||||
|
container->setLayout(layout);
|
||||||
// Start adding our Widgets to our FlowLayout...
|
this->setCentralWidget(container);
|
||||||
|
|
||||||
getBannerCardsForDecks();
|
|
||||||
|
|
||||||
leftToolBar = new QToolBar;
|
leftToolBar = new QToolBar;
|
||||||
leftToolBar->setOrientation(Qt::Horizontal);
|
leftToolBar->setOrientation(Qt::Horizontal);
|
||||||
leftToolBar->setIconSize(QSize(32, 32));
|
leftToolBar->setIconSize(QSize(32, 32));
|
||||||
QHBoxLayout *leftToolBarLayout = new QHBoxLayout;
|
QHBoxLayout *leftToolBarLayout = new QHBoxLayout(this);
|
||||||
leftToolBarLayout->addStretch();
|
leftToolBarLayout->addStretch();
|
||||||
leftToolBarLayout->addWidget(leftToolBar);
|
leftToolBarLayout->addWidget(leftToolBar);
|
||||||
leftToolBarLayout->addStretch();
|
leftToolBarLayout->addStretch();
|
||||||
|
|
@ -62,6 +47,12 @@ TabDeckStorageVisual::TabDeckStorageVisual(TabSupervisor *_tabSupervisor, Abstra
|
||||||
|
|
||||||
leftToolBar->addAction(aOpenLocalDeck);
|
leftToolBar->addAction(aOpenLocalDeck);
|
||||||
leftToolBar->addAction(aDeleteLocalDeck);
|
leftToolBar->addAction(aDeleteLocalDeck);
|
||||||
|
|
||||||
|
visualDeckStorageWidget = new VisualDeckStorageWidget(this);
|
||||||
|
|
||||||
|
layout->addWidget(leftToolBar);
|
||||||
|
layout->addWidget(visualDeckStorageWidget);
|
||||||
|
|
||||||
retranslateUi();
|
retranslateUi();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -77,37 +68,7 @@ QString TabDeckStorageVisual::getTargetPath() const
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList TabDeckStorageVisual::getBannerCardsForDecks()
|
|
||||||
{
|
|
||||||
QStringList allFiles;
|
|
||||||
|
|
||||||
// QDirIterator with QDir::Files and QDir::NoSymLinks ensures only files are listed (no directories or symlinks)
|
|
||||||
QDirIterator it(SettingsCache::instance().getDeckPath(), QDir::Files | QDir::NoSymLinks,
|
|
||||||
QDirIterator::Subdirectories);
|
|
||||||
|
|
||||||
while (it.hasNext()) {
|
|
||||||
allFiles << it.next(); // Add each file path to the list
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (const QString &file, allFiles) {
|
|
||||||
qDebug() << file;
|
|
||||||
auto deck_loader = new DeckLoader();
|
|
||||||
deck_loader->loadFromFile(file, DeckLoader::CockatriceFormat);
|
|
||||||
deck_list_model->setDeckList(new DeckLoader(*deck_loader));
|
|
||||||
|
|
||||||
auto *display = new DeckPreviewCardPictureWidget(flow_widget, true);
|
|
||||||
qDebug() << "Banner card is: " << deck_loader->getBannerCard();
|
|
||||||
display->setCard(CardDatabaseManager::getInstance()->getCard(deck_loader->getBannerCard()));
|
|
||||||
display->setOverlayText(deck_loader->getName().isEmpty() ? QFileInfo(deck_loader->getLastFileName()).fileName()
|
|
||||||
: deck_loader->getName());
|
|
||||||
display->setFontSize(24);
|
|
||||||
display->setFilePath(deck_loader->getLastFileName());
|
|
||||||
connect(display, &DeckPreviewCardPictureWidget::imageClicked, this, &TabDeckStorageVisual::actOpenLocalDeck);
|
|
||||||
flow_widget->addWidget(display);
|
|
||||||
}
|
|
||||||
|
|
||||||
return QStringList("lol");
|
|
||||||
}
|
|
||||||
|
|
||||||
void TabDeckStorageVisual::actOpenLocalDeck(QMouseEvent *event, DeckPreviewCardPictureWidget *instance)
|
void TabDeckStorageVisual::actOpenLocalDeck(QMouseEvent *event, DeckPreviewCardPictureWidget *instance)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,8 @@
|
||||||
|
|
||||||
#include "../../../deck/deck_list_model.h"
|
#include "../../../deck/deck_list_model.h"
|
||||||
#include "../../../deck/deck_view.h"
|
#include "../../../deck/deck_view.h"
|
||||||
#include "../../ui/layouts/flow_layout.h"
|
|
||||||
#include "../../ui/layouts/overlap_layout.h"
|
|
||||||
#include "../../ui/widgets/cards/card_info_picture_with_text_overlay_widget.h"
|
|
||||||
#include "../../ui/widgets/cards/deck_preview_card_picture_widget.h"
|
#include "../../ui/widgets/cards/deck_preview_card_picture_widget.h"
|
||||||
#include "../../ui/widgets/general/layout_containers/flow_widget.h"
|
#include "../../ui/widgets/visual_deck_storage/visual_deck_storage_widget.h"
|
||||||
#include "../tab.h"
|
#include "../tab.h"
|
||||||
|
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
|
|
@ -23,26 +20,9 @@ class CommandContainer;
|
||||||
class Response;
|
class Response;
|
||||||
class DeckLoader;
|
class DeckLoader;
|
||||||
|
|
||||||
class TabDeckStorageVisual : public Tab
|
class TabDeckStorageVisual final : public Tab
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
|
||||||
AbstractClient *client;
|
|
||||||
QTreeView *localDirView;
|
|
||||||
QFileSystemModel *localDirModel;
|
|
||||||
QToolBar *leftToolBar;
|
|
||||||
QGroupBox *leftGroupBox;
|
|
||||||
FlowWidget *flow_widget;
|
|
||||||
DeckListModel *deck_list_model;
|
|
||||||
QMap<QString, DeckViewCardContainer *> cardContainers;
|
|
||||||
|
|
||||||
QAction *aOpenLocalDeck, *aDeleteLocalDeck;
|
|
||||||
QString getTargetPath() const;
|
|
||||||
QStringList getBannerCardsForDecks();
|
|
||||||
private slots:
|
|
||||||
void actOpenLocalDeck(QMouseEvent *event, DeckPreviewCardPictureWidget *instance);
|
|
||||||
void actDeleteLocalDeck();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TabDeckStorageVisual(TabSupervisor *_tabSupervisor, AbstractClient *_client);
|
TabDeckStorageVisual(TabSupervisor *_tabSupervisor, AbstractClient *_client);
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
|
|
@ -54,6 +34,22 @@ public slots:
|
||||||
void cardUpdateFinished(int exitCode, QProcess::ExitStatus exitStatus);
|
void cardUpdateFinished(int exitCode, QProcess::ExitStatus exitStatus);
|
||||||
signals:
|
signals:
|
||||||
void openDeckEditor(const DeckLoader *deckLoader);
|
void openDeckEditor(const DeckLoader *deckLoader);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QWidget *container;
|
||||||
|
QHBoxLayout *layout;
|
||||||
|
AbstractClient *client;
|
||||||
|
QTreeView *localDirView;
|
||||||
|
QFileSystemModel *localDirModel;
|
||||||
|
QToolBar *leftToolBar;
|
||||||
|
QGroupBox *leftGroupBox;
|
||||||
|
VisualDeckStorageWidget *visualDeckStorageWidget;
|
||||||
|
DeckListModel *deck_list_model;
|
||||||
|
QAction *aOpenLocalDeck, *aDeleteLocalDeck;
|
||||||
|
QString getTargetPath() const;
|
||||||
|
private slots:
|
||||||
|
void actOpenLocalDeck(QMouseEvent *event, DeckPreviewCardPictureWidget *instance);
|
||||||
|
void actDeleteLocalDeck();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,58 @@
|
||||||
|
#include "visual_deck_storage_widget.h"
|
||||||
|
|
||||||
|
#include "../../../../deck/deck_loader.h"
|
||||||
|
#include "../../../../game/cards/card_database_manager.h"
|
||||||
|
#include "../../../../settings/cache_settings.h"
|
||||||
|
#include "../../../ui/widgets/cards/deck_preview_card_picture_widget.h"
|
||||||
|
|
||||||
|
#include <QDirIterator>
|
||||||
|
|
||||||
|
VisualDeckStorageWidget::VisualDeckStorageWidget(QWidget *parent) : QWidget(parent)
|
||||||
|
{
|
||||||
|
deckListModel = new DeckListModel(this);
|
||||||
|
deckListModel->setObjectName("visualDeckModel");
|
||||||
|
|
||||||
|
layout = new QHBoxLayout(this);
|
||||||
|
|
||||||
|
flowWidget = new FlowWidget(this, Qt::ScrollBarAlwaysOff, Qt::ScrollBarPolicy::ScrollBarAsNeeded);
|
||||||
|
layout->addWidget(flowWidget);
|
||||||
|
|
||||||
|
getBannerCardsForDecks();
|
||||||
|
|
||||||
|
// TODO: Move this to class that uses this widget (The tab one, in this instance, distinct from the game one)
|
||||||
|
// connect(this, &TabDeckStorageVisual::openDeckEditor, tabSupervisor, &TabSupervisor::addDeckEditorTab);
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList VisualDeckStorageWidget::getBannerCardsForDecks()
|
||||||
|
{
|
||||||
|
QStringList allFiles;
|
||||||
|
|
||||||
|
// QDirIterator with QDir::Files and QDir::NoSymLinks ensures only files are listed (no directories or symlinks)
|
||||||
|
QDirIterator it(SettingsCache::instance().getDeckPath(), QDir::Files | QDir::NoSymLinks,
|
||||||
|
QDirIterator::Subdirectories);
|
||||||
|
|
||||||
|
while (it.hasNext()) {
|
||||||
|
allFiles << it.next(); // Add each file path to the list
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (const QString &file, allFiles) {
|
||||||
|
qDebug() << file;
|
||||||
|
auto deckLoader = new DeckLoader();
|
||||||
|
deckLoader->loadFromFile(file, DeckLoader::CockatriceFormat);
|
||||||
|
deckListModel->setDeckList(new DeckLoader(*deckLoader));
|
||||||
|
|
||||||
|
auto *display = new DeckPreviewCardPictureWidget(flowWidget, true);
|
||||||
|
qDebug() << "Banner card is: " << deckLoader->getBannerCard();
|
||||||
|
display->setCard(CardDatabaseManager::getInstance()->getCard(deckLoader->getBannerCard()));
|
||||||
|
display->setOverlayText(deckLoader->getName().isEmpty() ? QFileInfo(deckLoader->getLastFileName()).fileName()
|
||||||
|
: deckLoader->getName());
|
||||||
|
display->setFontSize(24);
|
||||||
|
display->setFilePath(deckLoader->getLastFileName());
|
||||||
|
|
||||||
|
// TODO: Connect these to the parent.
|
||||||
|
// connect(display, &DeckPreviewCardPictureWidget::imageClicked, this, &TabDeckStorageVisual::actOpenLocalDeck);
|
||||||
|
flowWidget->addWidget(display);
|
||||||
|
}
|
||||||
|
|
||||||
|
return QStringList("lol");
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
#ifndef VISUAL_DECK_STORAGE_WIDGET_H
|
||||||
|
#define VISUAL_DECK_STORAGE_WIDGET_H
|
||||||
|
|
||||||
|
#include "../../../../deck/deck_list_model.h"
|
||||||
|
#include "../../../../deck/deck_view.h"
|
||||||
|
#include "../../../ui/widgets/general/layout_containers/flow_widget.h"
|
||||||
|
|
||||||
|
#include <QFileSystemModel>
|
||||||
|
|
||||||
|
class VisualDeckStorageWidget final : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit VisualDeckStorageWidget(QWidget *parent);
|
||||||
|
void retranslateUi();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QHBoxLayout *layout;
|
||||||
|
FlowWidget *flowWidget;
|
||||||
|
DeckListModel *deckListModel;
|
||||||
|
QMap<QString, DeckViewCardContainer *> cardContainers;
|
||||||
|
|
||||||
|
QStringList getBannerCardsForDecks();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // VISUAL_DECK_STORAGE_WIDGET_H
|
||||||
Loading…
Add table
Add a link
Reference in a new issue