almost finished pre-game deck loading
This commit is contained in:
parent
8dcf81654e
commit
cf21528a69
16 changed files with 140 additions and 64 deletions
|
@ -23,6 +23,7 @@ HEADERS += src/counter.h \
|
|||
src/game.h \
|
||||
src/carddatabase.h \
|
||||
src/gameview.h \
|
||||
src/deck_picturecacher.h \
|
||||
src/decklistmodel.h \
|
||||
src/dlg_startgame.h \
|
||||
src/cardinfowidget.h \
|
||||
|
@ -69,6 +70,7 @@ SOURCES += src/counter.cpp \
|
|||
src/game.cpp \
|
||||
src/carddatabase.cpp \
|
||||
src/gameview.cpp \
|
||||
src/deck_picturecacher.cpp \
|
||||
src/decklistmodel.cpp \
|
||||
src/dlg_startgame.cpp \
|
||||
src/cardinfowidget.cpp \
|
||||
|
|
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;
|
||||
|
||||
|
|
|
@ -173,6 +173,11 @@ QVector<QPair<int, int> > InnerDecklistNode::sort(Qt::SortOrder order)
|
|||
return result;
|
||||
}
|
||||
|
||||
const QStringList DeckList::fileNameFilters = QStringList()
|
||||
<< QObject::tr("Cockatrice decks (*.cod)")
|
||||
<< QObject::tr("Plain text decks (*.dec *.mwDeck)")
|
||||
<< QObject::tr("All files (*.*)");
|
||||
|
||||
DeckList::DeckList(QObject *parent)
|
||||
: QObject(parent), currentZone(0)
|
||||
{
|
||||
|
@ -341,6 +346,15 @@ bool DeckList::saveToFile(const QString &fileName, FileFormat fmt)
|
|||
return result;
|
||||
}
|
||||
|
||||
DeckList::FileFormat DeckList::getFormatFromNameFilter(const QString &selectedNameFilter)
|
||||
{
|
||||
switch (fileNameFilters.indexOf(selectedNameFilter)) {
|
||||
case 0: return CockatriceFormat;
|
||||
case 1: return PlainTextFormat;
|
||||
}
|
||||
return PlainTextFormat;
|
||||
}
|
||||
|
||||
void DeckList::cleanList()
|
||||
{
|
||||
root->clearTree();
|
||||
|
|
|
@ -95,6 +95,7 @@ public slots:
|
|||
void setName(const QString &_name = QString()) { name = _name; }
|
||||
void setComments(const QString &_comments = QString()) { comments = _comments; }
|
||||
public:
|
||||
static const QStringList fileNameFilters;
|
||||
DeckList(QObject *parent = 0);
|
||||
~DeckList();
|
||||
QString getName() const { return name; }
|
||||
|
@ -112,8 +113,7 @@ public:
|
|||
bool saveToFile_Plain(QIODevice *device);
|
||||
bool loadFromFile(const QString &fileName, FileFormat fmt);
|
||||
bool saveToFile(const QString &fileName, FileFormat fmt);
|
||||
bool loadDialog(QWidget *parent = 0);
|
||||
bool saveDialog(QWidget *parent = 0);
|
||||
static FileFormat getFormatFromNameFilter(const QString &selectedNameFilter);
|
||||
|
||||
void cleanList();
|
||||
|
||||
|
|
|
@ -141,7 +141,7 @@ void Command_DeckUpload::writeElement(QXmlStreamWriter *xml)
|
|||
}
|
||||
|
||||
Command_DeckSelect::Command_DeckSelect(int _gameId, DeckList *_deck, int _deckId)
|
||||
: GameCommand("deck_upload", _gameId), deck(_deck), deckId(_deckId), readFinished(false)
|
||||
: GameCommand("deck_select", _gameId), deck(_deck), deckId(_deckId), readFinished(false)
|
||||
{
|
||||
setParameter("deck_id", _deckId);
|
||||
}
|
||||
|
@ -299,11 +299,6 @@ Response_DeckDownload::Response_DeckDownload(int _cmdId, ResponseCode _responseC
|
|||
{
|
||||
}
|
||||
|
||||
Response_DeckDownload::~Response_DeckDownload()
|
||||
{
|
||||
delete deck;
|
||||
}
|
||||
|
||||
bool Response_DeckDownload::readElement(QXmlStreamReader *xml)
|
||||
{
|
||||
if (readFinished)
|
||||
|
|
|
@ -212,7 +212,6 @@ protected:
|
|||
void writeElement(QXmlStreamWriter *xml);
|
||||
public:
|
||||
Response_DeckDownload(int _cmdId = -1, ResponseCode _responseCode = RespOk, DeckList *_deck = 0);
|
||||
~Response_DeckDownload();
|
||||
int getItemId() const { return ItemId_Response_DeckDownload; }
|
||||
static ProtocolItem *newItem() { return new Response_DeckDownload; }
|
||||
DeckList *getDeck() const { return deck; }
|
||||
|
|
|
@ -263,7 +263,8 @@ ResponseCode Server_ProtocolHandler::cmdDeckSelect(Command_DeckSelect *cmd, Serv
|
|||
|
||||
game->sendGameEvent(new Event_DeckSelect(-1, player->getPlayerId(), cmd->getDeckId()));
|
||||
|
||||
return RespOk;
|
||||
sendProtocolItem(new Response_DeckDownload(cmd->getCmdId(), RespOk, deck));
|
||||
return RespNothing;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdSay(Command_Say *cmd, Server_Game *game, Server_Player *player)
|
||||
|
|
|
@ -316,5 +316,6 @@ ResponseCode ServerSocketInterface::cmdDeckDownload(Command_DeckDownload *cmd)
|
|||
return r;
|
||||
}
|
||||
sendProtocolItem(new Response_DeckDownload(cmd->getCmdId(), RespOk, deck));
|
||||
delete deck;
|
||||
return RespNothing;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue