almost finished pre-game deck loading

This commit is contained in:
Max-Wilhelm Bruker 2009-11-22 01:30:16 +01:00
parent 8dcf81654e
commit cf21528a69
16 changed files with 140 additions and 64 deletions

View file

@ -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();

View file

@ -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();

View file

@ -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)

View file

@ -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; }

View file

@ -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)