mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-18 16:32:16 -07:00
Add deck loading functionality.
This commit is contained in:
parent
c0cfc92e3d
commit
a0a7ca6a7b
6 changed files with 86 additions and 10 deletions
|
|
@ -160,6 +160,7 @@ set(cockatrice_SOURCES
|
|||
src/game/zones/view_zone_widget.cpp
|
||||
src/game/zones/view_zone.cpp
|
||||
src/client/tabs/visual_deck_storage/tab_deck_storage_visual.cpp
|
||||
src/client/ui/widgets/cards/deck_preview_card_picture_widget.cpp
|
||||
${VERSION_STRING_CPP}
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -11,8 +11,10 @@
|
|||
#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 "pb/command_deck_del.pb.h"
|
||||
|
||||
#include <QAction>
|
||||
|
|
@ -55,6 +57,8 @@ TabDeckStorageVisual::TabDeckStorageVisual(TabSupervisor *_tabSupervisor, Abstra
|
|||
aDeleteLocalDeck->setIcon(QPixmap("theme:icons/remove_row"));
|
||||
connect(aDeleteLocalDeck, SIGNAL(triggered()), this, SLOT(actDeleteLocalDeck()));
|
||||
|
||||
connect(this, &TabDeckStorageVisual::openDeckEditor, tabSupervisor, &TabSupervisor::addDeckEditorTab);
|
||||
|
||||
leftToolBar->addAction(aOpenLocalDeck);
|
||||
leftToolBar->addAction(aDeleteLocalDeck);
|
||||
retranslateUi();
|
||||
|
|
@ -90,27 +94,25 @@ QStringList TabDeckStorageVisual::getBannerCardsForDecks()
|
|||
deck_loader->loadFromFile(file, DeckLoader::CockatriceFormat);
|
||||
deck_list_model->setDeckList(new DeckLoader(*deck_loader));
|
||||
|
||||
auto *display = new CardInfoPictureWithTextOverlayWidget(flow_widget, true);
|
||||
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()
|
||||
void TabDeckStorageVisual::actOpenLocalDeck(QMouseEvent *event, DeckPreviewCardPictureWidget *instance)
|
||||
{
|
||||
QModelIndex curLeft = localDirView->selectionModel()->currentIndex();
|
||||
if (localDirModel->isDir(curLeft))
|
||||
return;
|
||||
QString filePath = localDirModel->filePath(curLeft);
|
||||
|
||||
qDebug() << event;
|
||||
DeckLoader deckLoader;
|
||||
if (!deckLoader.loadFromFile(filePath, DeckLoader::CockatriceFormat))
|
||||
if (!deckLoader.loadFromFile(instance->filePath, DeckLoader::CockatriceFormat))
|
||||
return;
|
||||
|
||||
emit openDeckEditor(&deckLoader);
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
#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/general/layout_containers/flow_widget.h"
|
||||
#include "../tab.h"
|
||||
|
||||
|
|
@ -38,7 +40,7 @@ private:
|
|||
QString getTargetPath() const;
|
||||
QStringList getBannerCardsForDecks();
|
||||
private slots:
|
||||
void actOpenLocalDeck();
|
||||
void actOpenLocalDeck(QMouseEvent *event, DeckPreviewCardPictureWidget *instance);
|
||||
void actDeleteLocalDeck();
|
||||
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
#include <QSize>
|
||||
#include <QTextOption>
|
||||
|
||||
class CardInfoPictureWithTextOverlayWidget final : public CardInfoPictureWidget
|
||||
class CardInfoPictureWithTextOverlayWidget : public CardInfoPictureWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,37 @@
|
|||
#include "deck_preview_card_picture_widget.h"
|
||||
|
||||
#include <QFontMetrics>
|
||||
#include <QPainterPath>
|
||||
#include <QStylePainter>
|
||||
#include <QTextOption>
|
||||
|
||||
/**
|
||||
* @brief Constructs a CardPictureWithTextOverlay widget.
|
||||
* @param parent The parent widget.
|
||||
* @param hoverToZoomEnabled If this widget will spawn a larger widget when hovered over.
|
||||
* @param textColor The color of the overlay text.
|
||||
* @param outlineColor The color of the outline around the text.
|
||||
* @param fontSize The font size of the overlay text.
|
||||
* @param alignment The alignment of the text within the overlay.
|
||||
*
|
||||
* Sets the widget's size policy and default border style.
|
||||
*/
|
||||
DeckPreviewCardPictureWidget::DeckPreviewCardPictureWidget(QWidget *parent,
|
||||
const bool hoverToZoomEnabled,
|
||||
const QColor &textColor,
|
||||
const QColor &outlineColor,
|
||||
const int fontSize,
|
||||
const Qt::Alignment alignment)
|
||||
: CardInfoPictureWithTextOverlayWidget(parent, hoverToZoomEnabled, textColor, outlineColor, fontSize, alignment)
|
||||
{
|
||||
}
|
||||
|
||||
void DeckPreviewCardPictureWidget::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
emit imageClicked(event, this);
|
||||
}
|
||||
|
||||
void DeckPreviewCardPictureWidget::setFilePath(const QString &_filePath)
|
||||
{
|
||||
filePath = _filePath;
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
#ifndef DECK_PREVIEW_CARD_PICTURE_WIDGET_H
|
||||
#define DECK_PREVIEW_CARD_PICTURE_WIDGET_H
|
||||
|
||||
#include "card_info_picture_with_text_overlay_widget.h"
|
||||
|
||||
#include <QColor>
|
||||
#include <QSize>
|
||||
#include <QTextOption>
|
||||
|
||||
class DeckPreviewCardPictureWidget final : public CardInfoPictureWithTextOverlayWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DeckPreviewCardPictureWidget(QWidget *parent = nullptr,
|
||||
bool hoverToZoomEnabled = false,
|
||||
const QColor &textColor = Qt::white,
|
||||
const QColor &outlineColor = Qt::black,
|
||||
int fontSize = 12,
|
||||
Qt::Alignment alignment = Qt::AlignCenter);
|
||||
|
||||
QString filePath;
|
||||
|
||||
signals:
|
||||
void imageClicked(QMouseEvent *event, DeckPreviewCardPictureWidget *instance);
|
||||
|
||||
public slots:
|
||||
void setFilePath(const QString &filePath);
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
};
|
||||
|
||||
#endif // DECK_PREVIEW_CARD_PICTURE_WIDGET_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue