mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-03 03:53:56 -07:00
Load deck from clipboard in Game Lobby (#5950)
This commit is contained in:
parent
d729df5cba
commit
50d3dfb98b
5 changed files with 47 additions and 12 deletions
|
|
@ -4,6 +4,7 @@
|
||||||
#include "../../client/ui/picture_loader/picture_loader.h"
|
#include "../../client/ui/picture_loader/picture_loader.h"
|
||||||
#include "../../deck/deck_loader.h"
|
#include "../../deck/deck_loader.h"
|
||||||
#include "../../dialogs/dlg_load_deck.h"
|
#include "../../dialogs/dlg_load_deck.h"
|
||||||
|
#include "../../dialogs/dlg_load_deck_from_clipboard.h"
|
||||||
#include "../../dialogs/dlg_load_remote_deck.h"
|
#include "../../dialogs/dlg_load_remote_deck.h"
|
||||||
#include "../../server/pending_command.h"
|
#include "../../server/pending_command.h"
|
||||||
#include "../../settings/cache_settings.h"
|
#include "../../settings/cache_settings.h"
|
||||||
|
|
@ -52,6 +53,7 @@ DeckViewContainer::DeckViewContainer(int _playerId, TabGame *parent)
|
||||||
{
|
{
|
||||||
loadLocalButton = new QPushButton;
|
loadLocalButton = new QPushButton;
|
||||||
loadRemoteButton = new QPushButton;
|
loadRemoteButton = new QPushButton;
|
||||||
|
loadFromClipboardButton = new QPushButton;
|
||||||
unloadDeckButton = new QPushButton;
|
unloadDeckButton = new QPushButton;
|
||||||
readyStartButton = new ToggleButton;
|
readyStartButton = new ToggleButton;
|
||||||
forceStartGameButton = new QPushButton;
|
forceStartGameButton = new QPushButton;
|
||||||
|
|
@ -59,6 +61,7 @@ DeckViewContainer::DeckViewContainer(int _playerId, TabGame *parent)
|
||||||
|
|
||||||
connect(loadLocalButton, &QPushButton::clicked, this, &DeckViewContainer::loadLocalDeck);
|
connect(loadLocalButton, &QPushButton::clicked, this, &DeckViewContainer::loadLocalDeck);
|
||||||
connect(loadRemoteButton, &QPushButton::clicked, this, &DeckViewContainer::loadRemoteDeck);
|
connect(loadRemoteButton, &QPushButton::clicked, this, &DeckViewContainer::loadRemoteDeck);
|
||||||
|
connect(loadFromClipboardButton, &QPushButton::clicked, this, &DeckViewContainer::loadFromClipboard);
|
||||||
connect(readyStartButton, &QPushButton::clicked, this, &DeckViewContainer::readyStart);
|
connect(readyStartButton, &QPushButton::clicked, this, &DeckViewContainer::readyStart);
|
||||||
connect(unloadDeckButton, &QPushButton::clicked, this, &DeckViewContainer::unloadDeck);
|
connect(unloadDeckButton, &QPushButton::clicked, this, &DeckViewContainer::unloadDeck);
|
||||||
connect(forceStartGameButton, &QPushButton::clicked, this, &DeckViewContainer::forceStart);
|
connect(forceStartGameButton, &QPushButton::clicked, this, &DeckViewContainer::forceStart);
|
||||||
|
|
@ -68,6 +71,7 @@ DeckViewContainer::DeckViewContainer(int _playerId, TabGame *parent)
|
||||||
auto *buttonHBox = new QHBoxLayout;
|
auto *buttonHBox = new QHBoxLayout;
|
||||||
buttonHBox->addWidget(loadLocalButton);
|
buttonHBox->addWidget(loadLocalButton);
|
||||||
buttonHBox->addWidget(loadRemoteButton);
|
buttonHBox->addWidget(loadRemoteButton);
|
||||||
|
buttonHBox->addWidget(loadFromClipboardButton);
|
||||||
buttonHBox->addWidget(unloadDeckButton);
|
buttonHBox->addWidget(unloadDeckButton);
|
||||||
buttonHBox->addWidget(readyStartButton);
|
buttonHBox->addWidget(readyStartButton);
|
||||||
buttonHBox->addWidget(sideboardLockButton);
|
buttonHBox->addWidget(sideboardLockButton);
|
||||||
|
|
@ -118,6 +122,7 @@ void DeckViewContainer::retranslateUi()
|
||||||
{
|
{
|
||||||
loadLocalButton->setText(tr("Load deck..."));
|
loadLocalButton->setText(tr("Load deck..."));
|
||||||
loadRemoteButton->setText(tr("Load remote deck..."));
|
loadRemoteButton->setText(tr("Load remote deck..."));
|
||||||
|
loadFromClipboardButton->setText(tr("Load from clipboard..."));
|
||||||
unloadDeckButton->setText(tr("Unload deck"));
|
unloadDeckButton->setText(tr("Unload deck"));
|
||||||
readyStartButton->setText(tr("Ready to start"));
|
readyStartButton->setText(tr("Ready to start"));
|
||||||
forceStartGameButton->setText(tr("Force start"));
|
forceStartGameButton->setText(tr("Force start"));
|
||||||
|
|
@ -148,6 +153,7 @@ void DeckViewContainer::switchToDeckSelectView()
|
||||||
|
|
||||||
setVisibility(loadLocalButton, true);
|
setVisibility(loadLocalButton, true);
|
||||||
setVisibility(loadRemoteButton, !parentGame->getIsLocalGame());
|
setVisibility(loadRemoteButton, !parentGame->getIsLocalGame());
|
||||||
|
setVisibility(loadFromClipboardButton, true);
|
||||||
setVisibility(unloadDeckButton, false);
|
setVisibility(unloadDeckButton, false);
|
||||||
setVisibility(readyStartButton, false);
|
setVisibility(readyStartButton, false);
|
||||||
setVisibility(sideboardLockButton, false);
|
setVisibility(sideboardLockButton, false);
|
||||||
|
|
@ -172,6 +178,7 @@ void DeckViewContainer::switchToDeckLoadedView()
|
||||||
|
|
||||||
setVisibility(loadLocalButton, false);
|
setVisibility(loadLocalButton, false);
|
||||||
setVisibility(loadRemoteButton, false);
|
setVisibility(loadRemoteButton, false);
|
||||||
|
setVisibility(loadFromClipboardButton, false);
|
||||||
setVisibility(unloadDeckButton, true);
|
setVisibility(unloadDeckButton, true);
|
||||||
setVisibility(readyStartButton, true);
|
setVisibility(readyStartButton, true);
|
||||||
setVisibility(sideboardLockButton, true);
|
setVisibility(sideboardLockButton, true);
|
||||||
|
|
@ -198,6 +205,7 @@ void DeckViewContainer::refreshShortcuts()
|
||||||
ShortcutsSettings &shortcuts = SettingsCache::instance().shortcuts();
|
ShortcutsSettings &shortcuts = SettingsCache::instance().shortcuts();
|
||||||
loadLocalButton->setShortcut(shortcuts.getSingleShortcut("DeckViewContainer/loadLocalButton"));
|
loadLocalButton->setShortcut(shortcuts.getSingleShortcut("DeckViewContainer/loadLocalButton"));
|
||||||
loadRemoteButton->setShortcut(shortcuts.getSingleShortcut("DeckViewContainer/loadRemoteButton"));
|
loadRemoteButton->setShortcut(shortcuts.getSingleShortcut("DeckViewContainer/loadRemoteButton"));
|
||||||
|
loadFromClipboardButton->setShortcut(shortcuts.getSingleShortcut("DeckViewContainer/loadFromClipboardButton"));
|
||||||
unloadDeckButton->setShortcut(shortcuts.getSingleShortcut("DeckViewContainer/unloadDeckButton"));
|
unloadDeckButton->setShortcut(shortcuts.getSingleShortcut("DeckViewContainer/unloadDeckButton"));
|
||||||
readyStartButton->setShortcut(shortcuts.getSingleShortcut("DeckViewContainer/readyStartButton"));
|
readyStartButton->setShortcut(shortcuts.getSingleShortcut("DeckViewContainer/readyStartButton"));
|
||||||
sideboardLockButton->setShortcut(shortcuts.getSingleShortcut("DeckViewContainer/sideboardLockButton"));
|
sideboardLockButton->setShortcut(shortcuts.getSingleShortcut("DeckViewContainer/sideboardLockButton"));
|
||||||
|
|
@ -249,19 +257,27 @@ void DeckViewContainer::loadLocalDeck()
|
||||||
void DeckViewContainer::loadDeckFromFile(const QString &filePath)
|
void DeckViewContainer::loadDeckFromFile(const QString &filePath)
|
||||||
{
|
{
|
||||||
DeckLoader::FileFormat fmt = DeckLoader::getFormatFromName(filePath);
|
DeckLoader::FileFormat fmt = DeckLoader::getFormatFromName(filePath);
|
||||||
QString deckString;
|
|
||||||
DeckLoader deck;
|
DeckLoader deck;
|
||||||
|
|
||||||
bool error = !deck.loadFromFile(filePath, fmt, true);
|
bool success = deck.loadFromFile(filePath, fmt, true);
|
||||||
if (!error) {
|
|
||||||
deckString = deck.writeToString_Native();
|
if (!success) {
|
||||||
error = deckString.length() > MAX_FILE_LENGTH;
|
|
||||||
}
|
|
||||||
if (error) {
|
|
||||||
QMessageBox::critical(this, tr("Error"), tr("The selected file could not be loaded."));
|
QMessageBox::critical(this, tr("Error"), tr("The selected file could not be loaded."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
loadDeckFromDeckLoader(&deck);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeckViewContainer::loadDeckFromDeckLoader(const DeckLoader *deck)
|
||||||
|
{
|
||||||
|
QString deckString = deck->writeToString_Native();
|
||||||
|
|
||||||
|
if (deckString.length() > MAX_FILE_LENGTH) {
|
||||||
|
QMessageBox::critical(this, tr("Error"), tr("Deck is greater than maximum file size."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Command_DeckSelect cmd;
|
Command_DeckSelect cmd;
|
||||||
cmd.set_deck(deckString.toStdString());
|
cmd.set_deck(deckString.toStdString());
|
||||||
PendingCommand *pend = parentGame->prepareGameCommand(cmd);
|
PendingCommand *pend = parentGame->prepareGameCommand(cmd);
|
||||||
|
|
@ -281,6 +297,18 @@ void DeckViewContainer::loadRemoteDeck()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DeckViewContainer::loadFromClipboard()
|
||||||
|
{
|
||||||
|
auto dlg = DlgLoadDeckFromClipboard(this);
|
||||||
|
|
||||||
|
if (!dlg.exec()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DeckLoader *deck = dlg.getDeckList();
|
||||||
|
loadDeckFromDeckLoader(deck);
|
||||||
|
}
|
||||||
|
|
||||||
void DeckViewContainer::deckSelectFinished(const Response &r)
|
void DeckViewContainer::deckSelectFinished(const Response &r)
|
||||||
{
|
{
|
||||||
const Response_DeckDownload &resp = r.GetExtension(Response_DeckDownload::ext);
|
const Response_DeckDownload &resp = r.GetExtension(Response_DeckDownload::ext);
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,8 @@ class DeckViewContainer : public QWidget
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
QVBoxLayout *deckViewLayout;
|
QVBoxLayout *deckViewLayout;
|
||||||
QPushButton *loadLocalButton, *loadRemoteButton, *unloadDeckButton, *forceStartGameButton;
|
QPushButton *loadLocalButton, *loadRemoteButton, *loadFromClipboardButton;
|
||||||
|
QPushButton *unloadDeckButton, *forceStartGameButton;
|
||||||
ToggleButton *readyStartButton, *sideboardLockButton;
|
ToggleButton *readyStartButton, *sideboardLockButton;
|
||||||
DeckView *deckView;
|
DeckView *deckView;
|
||||||
VisualDeckStorageWidget *visualDeckStorageWidget;
|
VisualDeckStorageWidget *visualDeckStorageWidget;
|
||||||
|
|
@ -58,6 +59,7 @@ private slots:
|
||||||
void switchToDeckLoadedView();
|
void switchToDeckLoadedView();
|
||||||
void loadLocalDeck();
|
void loadLocalDeck();
|
||||||
void loadRemoteDeck();
|
void loadRemoteDeck();
|
||||||
|
void loadFromClipboard();
|
||||||
void unloadDeck();
|
void unloadDeck();
|
||||||
void readyStart();
|
void readyStart();
|
||||||
void forceStart();
|
void forceStart();
|
||||||
|
|
@ -81,6 +83,7 @@ public:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void loadDeckFromFile(const QString &filePath);
|
void loadDeckFromFile(const QString &filePath);
|
||||||
|
void loadDeckFromDeckLoader(const DeckLoader *deck);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DECK_VIEW_CONTAINER_H
|
#endif // DECK_VIEW_CONTAINER_H
|
||||||
|
|
|
||||||
|
|
@ -267,6 +267,10 @@ private:
|
||||||
{"DeckViewContainer/loadRemoteButton", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Load Remote Deck..."),
|
{"DeckViewContainer/loadRemoteButton", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Load Remote Deck..."),
|
||||||
parseSequenceString("Ctrl+Alt+O"),
|
parseSequenceString("Ctrl+Alt+O"),
|
||||||
ShortcutGroup::Game_Lobby)},
|
ShortcutGroup::Game_Lobby)},
|
||||||
|
{"DeckViewContainer/loadFromClipboardButton",
|
||||||
|
ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Load Deck from Clipboard..."),
|
||||||
|
parseSequenceString("Ctrl+Shift+V"),
|
||||||
|
ShortcutGroup::Game_Lobby)},
|
||||||
{"DeckViewContainer/unloadDeckButton", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Unload Deck"),
|
{"DeckViewContainer/unloadDeckButton", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Unload Deck"),
|
||||||
parseSequenceString("Ctrl+Alt+U"),
|
parseSequenceString("Ctrl+Alt+U"),
|
||||||
ShortcutGroup::Game_Lobby)},
|
ShortcutGroup::Game_Lobby)},
|
||||||
|
|
|
||||||
|
|
@ -441,7 +441,7 @@ bool DeckList::readElement(QXmlStreamReader *xml)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckList::write(QXmlStreamWriter *xml)
|
void DeckList::write(QXmlStreamWriter *xml) const
|
||||||
{
|
{
|
||||||
xml->writeStartElement("cockatrice_deck");
|
xml->writeStartElement("cockatrice_deck");
|
||||||
xml->writeAttribute("version", "1");
|
xml->writeAttribute("version", "1");
|
||||||
|
|
@ -508,7 +508,7 @@ bool DeckList::loadFromString_Native(const QString &nativeString)
|
||||||
return loadFromXml(&xml);
|
return loadFromXml(&xml);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DeckList::writeToString_Native()
|
QString DeckList::writeToString_Native() const
|
||||||
{
|
{
|
||||||
QString result;
|
QString result;
|
||||||
QXmlStreamWriter xml(&result);
|
QXmlStreamWriter xml(&result);
|
||||||
|
|
|
||||||
|
|
@ -345,10 +345,10 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
bool readElement(QXmlStreamReader *xml);
|
bool readElement(QXmlStreamReader *xml);
|
||||||
void write(QXmlStreamWriter *xml);
|
void write(QXmlStreamWriter *xml) const;
|
||||||
bool loadFromXml(QXmlStreamReader *xml);
|
bool loadFromXml(QXmlStreamReader *xml);
|
||||||
bool loadFromString_Native(const QString &nativeString);
|
bool loadFromString_Native(const QString &nativeString);
|
||||||
QString writeToString_Native();
|
QString writeToString_Native() const;
|
||||||
bool loadFromFile_Native(QIODevice *device);
|
bool loadFromFile_Native(QIODevice *device);
|
||||||
bool saveToFile_Native(QIODevice *device);
|
bool saveToFile_Native(QIODevice *device);
|
||||||
bool loadFromStream_Plain(QTextStream &stream, bool preserveMetadata);
|
bool loadFromStream_Plain(QTextStream &stream, bool preserveMetadata);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue