mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-26 08:33:54 -07:00
almost finished pre-game deck loading
This commit is contained in:
parent
8dcf81654e
commit
cf21528a69
16 changed files with 140 additions and 64 deletions
29
cockatrice/src/deck_picturecacher.cpp
Normal file
29
cockatrice/src/deck_picturecacher.cpp
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#include <QProgressDialog>
|
||||
#include "deck_picturecacher.h"
|
||||
#include "decklist.h"
|
||||
#include "carddatabase.h"
|
||||
#include "main.h"
|
||||
|
||||
void Deck_PictureCacher::cacheHelper(InnerDecklistNode *item, QProgressDialog *progress)
|
||||
{
|
||||
for (int i = 0; i < item->size(); i++) {
|
||||
DecklistCardNode *node = dynamic_cast<DecklistCardNode *>(item->at(i));
|
||||
if (node) {
|
||||
db->getCard(node->getName())->loadPixmap();
|
||||
progress->setValue(progress->value() + 1);
|
||||
} else
|
||||
cacheHelper(dynamic_cast<InnerDecklistNode *>(item->at(i)), progress);
|
||||
}
|
||||
}
|
||||
|
||||
void Deck_PictureCacher::cachePictures(DeckList *deck, QWidget *parent)
|
||||
{
|
||||
int totalCards = deck->getRoot()->recursiveCount();
|
||||
|
||||
QProgressDialog progress(tr("Caching card pictures..."), QString(), 0, totalCards, parent);
|
||||
progress.setMinimumDuration(1000);
|
||||
progress.setWindowModality(Qt::WindowModal);
|
||||
|
||||
cacheHelper(deck->getRoot(), &progress);
|
||||
}
|
||||
|
||||
19
cockatrice/src/deck_picturecacher.h
Normal file
19
cockatrice/src/deck_picturecacher.h
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#ifndef DECK_PICTURECACHER_H
|
||||
#define DECK_PICTURECACHER_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class InnerDecklistNode;
|
||||
class QProgressDialog;
|
||||
class DeckList;
|
||||
class QWidget;
|
||||
|
||||
class Deck_PictureCacher : public QObject {
|
||||
Q_OBJECT
|
||||
private:
|
||||
static void cacheHelper(InnerDecklistNode *item, QProgressDialog *progress);
|
||||
public:
|
||||
static void cachePictures(DeckList *deck, QWidget *parent);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -315,29 +315,6 @@ void DeckListModel::cleanList()
|
|||
reset();
|
||||
}
|
||||
|
||||
void DeckListModel::cacheCardPicturesHelper(InnerDecklistNode *item, QProgressDialog *progress)
|
||||
{
|
||||
for (int i = 0; i < item->size(); i++) {
|
||||
DecklistCardNode *node = dynamic_cast<DecklistCardNode *>(item->at(i));
|
||||
if (node) {
|
||||
db->getCard(node->getName())->loadPixmap();
|
||||
progress->setValue(progress->value() + 1);
|
||||
} else
|
||||
cacheCardPicturesHelper(dynamic_cast<InnerDecklistNode *>(item->at(i)), progress);
|
||||
}
|
||||
}
|
||||
|
||||
void DeckListModel::cacheCardPictures(QWidget *parent)
|
||||
{
|
||||
int totalCards = deckList->getRoot()->recursiveCount();
|
||||
|
||||
QProgressDialog progress(tr("Caching card pictures..."), QString(), 0, totalCards, parent);
|
||||
progress.setMinimumDuration(1000);
|
||||
progress.setWindowModality(Qt::WindowModal);
|
||||
|
||||
cacheCardPicturesHelper(deckList->getRoot(), &progress);
|
||||
}
|
||||
|
||||
void DeckListModel::printDeckListNode(QTextCursor *cursor, InnerDecklistNode *node)
|
||||
{
|
||||
static const int totalColumns = 3;
|
||||
|
|
|
|||
|
|
@ -44,7 +44,6 @@ public:
|
|||
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
|
||||
void cleanList();
|
||||
DeckList *getDeckList() const { return deckList; }
|
||||
void cacheCardPictures(QWidget *parent = 0);
|
||||
private:
|
||||
DeckList *deckList;
|
||||
InnerDecklistNode *root;
|
||||
|
|
@ -55,7 +54,6 @@ private:
|
|||
void debugIndexInfo(const QString &func, const QModelIndex &index) const;
|
||||
void debugShowTree(InnerDecklistNode *node, int depth) const;
|
||||
|
||||
void cacheCardPicturesHelper(InnerDecklistNode *item, QProgressDialog *progress);
|
||||
void printDeckListNode(QTextCursor *cursor, InnerDecklistNode *node);
|
||||
|
||||
template<typename T> T getNode(const QModelIndex &index) const
|
||||
|
|
|
|||
|
|
@ -37,7 +37,6 @@ private:
|
|||
bool started;
|
||||
int currentPhase;
|
||||
|
||||
Player *getActiveLocalPlayer() const;
|
||||
public slots:
|
||||
void activePlayerDrawCard();
|
||||
void activePlayerUntapAll();
|
||||
|
|
@ -107,6 +106,7 @@ public:
|
|||
void restartGameDialog();
|
||||
void hoverCardEvent(CardItem *card);
|
||||
Player *addPlayer(int playerId, const QString &playerName, bool local);
|
||||
Player *getActiveLocalPlayer() const;
|
||||
const QMap<int, Player *> &getPlayers() const { return players; }
|
||||
void queryGameState();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@
|
|||
#include "zoneviewlayout.h"
|
||||
#include "deckview.h"
|
||||
#include "decklist.h"
|
||||
#include "deck_picturecacher.h"
|
||||
#include "protocol_items.h"
|
||||
#include "main.h"
|
||||
|
||||
TabGame::TabGame(Client *_client, int _gameId)
|
||||
|
|
@ -22,12 +24,17 @@ TabGame::TabGame(Client *_client, int _gameId)
|
|||
gameView = new GameView(scene);
|
||||
gameView->hide();
|
||||
|
||||
deckView = new DeckView;
|
||||
loadLocalButton = new QPushButton;
|
||||
loadRemoteButton = new QPushButton;
|
||||
|
||||
DeckList *foo = new DeckList;
|
||||
foo->loadFromFile("/home/brukie/cockatrice/decks/adfb.cod", DeckList::CockatriceFormat);
|
||||
deckView->setDeck(foo);
|
||||
// deckView->hide();
|
||||
QHBoxLayout *buttonHBox = new QHBoxLayout;
|
||||
buttonHBox->addWidget(loadLocalButton);
|
||||
buttonHBox->addWidget(loadRemoteButton);
|
||||
buttonHBox->addStretch();
|
||||
deckView = new DeckView;
|
||||
QVBoxLayout *deckViewLayout = new QVBoxLayout;
|
||||
deckViewLayout->addLayout(buttonHBox);
|
||||
deckViewLayout->addWidget(deckView);
|
||||
|
||||
cardInfo = new CardInfoWidget(db);
|
||||
messageLog = new MessageLogWidget;
|
||||
|
|
@ -50,13 +57,16 @@ TabGame::TabGame(Client *_client, int _gameId)
|
|||
QHBoxLayout *mainLayout = new QHBoxLayout;
|
||||
mainLayout->addWidget(phasesToolbar);
|
||||
mainLayout->addWidget(gameView, 10);
|
||||
mainLayout->addWidget(deckView, 10);
|
||||
mainLayout->addLayout(deckViewLayout, 10);
|
||||
mainLayout->addLayout(verticalLayout);
|
||||
|
||||
aCloseMostRecentZoneView = new QAction(this);
|
||||
connect(aCloseMostRecentZoneView, SIGNAL(triggered()), zoneLayout, SLOT(closeMostRecentZoneView()));
|
||||
addAction(aCloseMostRecentZoneView);
|
||||
|
||||
connect(loadLocalButton, SIGNAL(clicked()), this, SLOT(loadLocalDeck()));
|
||||
connect(loadRemoteButton, SIGNAL(clicked()), this, SLOT(loadRemoteDeck()));
|
||||
|
||||
connect(sayEdit, SIGNAL(returnPressed()), this, SLOT(actSay()));
|
||||
|
||||
// connect(client, SIGNAL(maxPingTime(int, int)), pingWidget, SLOT(setPercentage(int, int)));
|
||||
|
|
@ -81,6 +91,8 @@ TabGame::TabGame(Client *_client, int _gameId)
|
|||
|
||||
void TabGame::retranslateUi()
|
||||
{
|
||||
loadLocalButton->setText(tr("Load &local deck"));
|
||||
loadRemoteButton->setText(tr("Load deck from &server"));
|
||||
sayLabel->setText(tr("&Say:"));
|
||||
cardInfo->retranslateUi();
|
||||
// if (game)
|
||||
|
|
@ -94,3 +106,43 @@ void TabGame::processGameEvent(GameEvent *event)
|
|||
{
|
||||
// game->processGameEvent(event);
|
||||
}
|
||||
|
||||
void TabGame::loadLocalDeck()
|
||||
{
|
||||
QFileDialog dialog(this, tr("Load deck"));
|
||||
QSettings settings;
|
||||
dialog.setDirectory(settings.value("paths/decks").toString());
|
||||
dialog.setNameFilters(DeckList::fileNameFilters);
|
||||
if (!dialog.exec())
|
||||
return;
|
||||
|
||||
QString fileName = dialog.selectedFiles().at(0);
|
||||
DeckList::FileFormat fmt = DeckList::getFormatFromNameFilter(dialog.selectedNameFilter());
|
||||
DeckList *deck = new DeckList;
|
||||
if (!deck->loadFromFile(fileName, fmt)) {
|
||||
delete deck;
|
||||
// Error message
|
||||
return;
|
||||
}
|
||||
|
||||
Command_DeckSelect *cmd = new Command_DeckSelect(gameId, deck, -1);
|
||||
connect(cmd, SIGNAL(finished(ProtocolResponse *)), this, SLOT(deckSelectFinished(ProtocolResponse *)));
|
||||
client->sendCommand(cmd);
|
||||
}
|
||||
|
||||
void TabGame::loadRemoteDeck()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void TabGame::deckSelectFinished(ProtocolResponse *r)
|
||||
{
|
||||
Response_DeckDownload *resp = qobject_cast<Response_DeckDownload *>(r);
|
||||
if (!resp)
|
||||
return;
|
||||
Command_DeckSelect *cmd = static_cast<Command_DeckSelect *>(sender());
|
||||
delete cmd->getDeck();
|
||||
|
||||
Deck_PictureCacher::cachePictures(resp->getDeck(), this);
|
||||
deckView->setDeck(resp->getDeck());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ class QPushButton;
|
|||
class ZoneViewLayout;
|
||||
class ZoneViewWidget;
|
||||
class PhasesToolbar;
|
||||
class ProtocolResponse;
|
||||
|
||||
class TabGame : public QWidget {
|
||||
Q_OBJECT
|
||||
|
|
@ -25,6 +26,7 @@ private:
|
|||
Client *client;
|
||||
int gameId;
|
||||
|
||||
QPushButton *loadLocalButton, *loadRemoteButton;
|
||||
CardInfoWidget *cardInfo;
|
||||
MessageLogWidget *messageLog;
|
||||
QLabel *sayLabel;
|
||||
|
|
@ -37,6 +39,9 @@ private:
|
|||
ZoneViewLayout *zoneLayout;
|
||||
QAction *aCloseMostRecentZoneView;
|
||||
private slots:
|
||||
void loadLocalDeck();
|
||||
void loadRemoteDeck();
|
||||
void deckSelectFinished(ProtocolResponse *r);
|
||||
public:
|
||||
TabGame(Client *_client, int _gameId);
|
||||
void retranslateUi();
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include "carddatabasemodel.h"
|
||||
#include "decklistmodel.h"
|
||||
#include "cardinfowidget.h"
|
||||
#include "deck_picturecacher.h"
|
||||
#include "main.h"
|
||||
|
||||
void SearchLineEdit::keyPressEvent(QKeyEvent *event)
|
||||
|
|
@ -14,11 +15,6 @@ void SearchLineEdit::keyPressEvent(QKeyEvent *event)
|
|||
QLineEdit::keyPressEvent(event);
|
||||
}
|
||||
|
||||
const QStringList WndDeckEditor::fileNameFilters = QStringList()
|
||||
<< QObject::tr("Cockatrice decks (*.cod)")
|
||||
<< QObject::tr("Plain text decks (*.dec *.mwDeck)")
|
||||
<< QObject::tr("All files (*.*)");
|
||||
|
||||
WndDeckEditor::WndDeckEditor(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
{
|
||||
|
|
@ -245,18 +241,12 @@ void WndDeckEditor::actLoadDeck()
|
|||
QFileDialog dialog(this, tr("Load deck"));
|
||||
QSettings settings;
|
||||
dialog.setDirectory(settings.value("paths/decks").toString());
|
||||
dialog.setNameFilters(fileNameFilters);
|
||||
dialog.setNameFilters(DeckList::fileNameFilters);
|
||||
if (!dialog.exec())
|
||||
return;
|
||||
|
||||
QString fileName = dialog.selectedFiles().at(0);
|
||||
DeckList::FileFormat fmt;
|
||||
switch (fileNameFilters.indexOf(dialog.selectedNameFilter())) {
|
||||
case 0: fmt = DeckList::CockatriceFormat; break;
|
||||
case 1: fmt = DeckList::PlainTextFormat; break;
|
||||
default: fmt = DeckList::PlainTextFormat; break;
|
||||
}
|
||||
|
||||
DeckList::FileFormat fmt = DeckList::getFormatFromNameFilter(dialog.selectedNameFilter());
|
||||
DeckList *l = deckModel->getDeckList();
|
||||
if (l->loadFromFile(fileName, fmt)) {
|
||||
lastFileName = fileName;
|
||||
|
|
@ -268,7 +258,7 @@ void WndDeckEditor::actLoadDeck()
|
|||
deckView->resizeColumnToContents(0);
|
||||
setWindowModified(false);
|
||||
|
||||
deckModel->cacheCardPictures(this);
|
||||
Deck_PictureCacher::cachePictures(l, this);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -291,17 +281,12 @@ bool WndDeckEditor::actSaveDeckAs()
|
|||
dialog.setAcceptMode(QFileDialog::AcceptSave);
|
||||
dialog.setConfirmOverwrite(true);
|
||||
dialog.setDefaultSuffix("cod");
|
||||
dialog.setNameFilters(fileNameFilters);
|
||||
dialog.setNameFilters(DeckList::fileNameFilters);
|
||||
if (!dialog.exec())
|
||||
return false;
|
||||
|
||||
QString fileName = dialog.selectedFiles().at(0);
|
||||
DeckList::FileFormat fmt;
|
||||
switch (fileNameFilters.indexOf(dialog.selectedNameFilter())) {
|
||||
case 0: fmt = DeckList::CockatriceFormat; break;
|
||||
case 1: fmt = DeckList::PlainTextFormat; break;
|
||||
default: fmt = DeckList::PlainTextFormat; break;
|
||||
}
|
||||
DeckList::FileFormat fmt = DeckList::getFormatFromNameFilter(dialog.selectedNameFilter());
|
||||
|
||||
if (deckModel->getDeckList()->saveToFile(fileName, fmt)) {
|
||||
lastFileName = fileName;
|
||||
|
|
|
|||
|
|
@ -51,7 +51,6 @@ private:
|
|||
void recursiveExpand(const QModelIndex &index);
|
||||
bool confirmClose();
|
||||
|
||||
static const QStringList fileNameFilters;
|
||||
QString lastFileName;
|
||||
DeckList::FileFormat lastFileFormat;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue