mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-18 16:32:16 -07:00
cut-and-paste
This commit is contained in:
parent
6309e7e318
commit
462fd23d15
5 changed files with 400 additions and 345 deletions
|
|
@ -149,6 +149,8 @@ set(cockatrice_SOURCES
|
||||||
src/client/tabs/tab_room.cpp
|
src/client/tabs/tab_room.cpp
|
||||||
src/client/tabs/tab_server.cpp
|
src/client/tabs/tab_server.cpp
|
||||||
src/client/tabs/tab_supervisor.cpp
|
src/client/tabs/tab_supervisor.cpp
|
||||||
|
src/client/tabs/deck_view_container.cpp
|
||||||
|
src/client/tabs/deck_view_container.h
|
||||||
src/game/zones/table_zone.cpp
|
src/game/zones/table_zone.cpp
|
||||||
src/client/tapped_out_interface.cpp
|
src/client/tapped_out_interface.cpp
|
||||||
src/client/ui/theme_manager.cpp
|
src/client/ui/theme_manager.cpp
|
||||||
|
|
|
||||||
316
cockatrice/src/client/tabs/deck_view_container.cpp
Normal file
316
cockatrice/src/client/tabs/deck_view_container.cpp
Normal file
|
|
@ -0,0 +1,316 @@
|
||||||
|
#include "deck_view_container.h"
|
||||||
|
|
||||||
|
#include "../../deck/deck_loader.h"
|
||||||
|
#include "../../deck/deck_view.h"
|
||||||
|
#include "../../dialogs/dlg_create_game.h"
|
||||||
|
#include "../../dialogs/dlg_load_deck.h"
|
||||||
|
#include "../../dialogs/dlg_load_remote_deck.h"
|
||||||
|
#include "../../game/cards/card_database.h"
|
||||||
|
#include "../../game/cards/card_database_manager.h"
|
||||||
|
#include "../../game/game_scene.h"
|
||||||
|
#include "../../game/game_view.h"
|
||||||
|
#include "../../game/player/player.h"
|
||||||
|
#include "../../server/message_log_widget.h"
|
||||||
|
#include "../../server/pending_command.h"
|
||||||
|
#include "../../settings/cache_settings.h"
|
||||||
|
#include "../game_logic/abstract_client.h"
|
||||||
|
#include "../ui/picture_loader.h"
|
||||||
|
#include "../ui/window_main.h"
|
||||||
|
#include "pb/command_concede.pb.h"
|
||||||
|
#include "pb/command_deck_select.pb.h"
|
||||||
|
#include "pb/command_ready_start.pb.h"
|
||||||
|
#include "pb/command_set_sideboard_lock.pb.h"
|
||||||
|
#include "pb/command_set_sideboard_plan.pb.h"
|
||||||
|
#include "pb/response_deck_download.pb.h"
|
||||||
|
#include "tab_game.h"
|
||||||
|
#include "trice_limits.h"
|
||||||
|
|
||||||
|
#include <QCompleter>
|
||||||
|
#include <QDockWidget>
|
||||||
|
#include <QFileDialog>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QToolButton>
|
||||||
|
#include <google/protobuf/descriptor.h>
|
||||||
|
|
||||||
|
ToggleButton::ToggleButton(QWidget *parent) : QPushButton(parent), state(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void ToggleButton::paintEvent(QPaintEvent *event)
|
||||||
|
{
|
||||||
|
QPushButton::paintEvent(event);
|
||||||
|
|
||||||
|
QPainter painter(this);
|
||||||
|
QPen pen;
|
||||||
|
pen.setWidth(3);
|
||||||
|
pen.setJoinStyle(Qt::MiterJoin);
|
||||||
|
pen.setColor(state ? Qt::green : Qt::red);
|
||||||
|
painter.setPen(pen);
|
||||||
|
painter.drawRect(QRect(1, 1, width() - 3, height() - 3));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ToggleButton::setState(bool _state)
|
||||||
|
{
|
||||||
|
state = _state;
|
||||||
|
emit stateChanged();
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
DeckViewContainer::DeckViewContainer(int _playerId, TabGame *parent)
|
||||||
|
: QWidget(nullptr), parentGame(parent), playerId(_playerId)
|
||||||
|
{
|
||||||
|
loadLocalButton = new QPushButton;
|
||||||
|
loadRemoteButton = new QPushButton;
|
||||||
|
unloadDeckButton = new QPushButton;
|
||||||
|
unloadDeckButton->setEnabled(false);
|
||||||
|
readyStartButton = new ToggleButton;
|
||||||
|
readyStartButton->setEnabled(false);
|
||||||
|
forceStartGameButton = new QPushButton;
|
||||||
|
forceStartGameButton->setEnabled(parent->isHost());
|
||||||
|
sideboardLockButton = new ToggleButton;
|
||||||
|
sideboardLockButton->setEnabled(false);
|
||||||
|
|
||||||
|
connect(loadLocalButton, SIGNAL(clicked()), this, SLOT(loadLocalDeck()));
|
||||||
|
connect(readyStartButton, SIGNAL(clicked()), this, SLOT(readyStart()));
|
||||||
|
connect(unloadDeckButton, &QPushButton::clicked, this, &DeckViewContainer::unloadDeck);
|
||||||
|
connect(forceStartGameButton, &QPushButton::clicked, this, &DeckViewContainer::forceStart);
|
||||||
|
connect(sideboardLockButton, SIGNAL(clicked()), this, SLOT(sideboardLockButtonClicked()));
|
||||||
|
connect(sideboardLockButton, SIGNAL(stateChanged()), this, SLOT(updateSideboardLockButtonText()));
|
||||||
|
|
||||||
|
if (parentGame->getIsLocalGame()) {
|
||||||
|
loadRemoteButton->setEnabled(false);
|
||||||
|
} else {
|
||||||
|
connect(loadRemoteButton, SIGNAL(clicked()), this, SLOT(loadRemoteDeck()));
|
||||||
|
}
|
||||||
|
|
||||||
|
auto *buttonHBox = new QHBoxLayout;
|
||||||
|
buttonHBox->addWidget(loadLocalButton);
|
||||||
|
buttonHBox->addWidget(loadRemoteButton);
|
||||||
|
buttonHBox->addWidget(unloadDeckButton);
|
||||||
|
buttonHBox->addWidget(readyStartButton);
|
||||||
|
buttonHBox->addWidget(sideboardLockButton);
|
||||||
|
if (forceStartGameButton->isEnabled()) {
|
||||||
|
buttonHBox->addWidget(forceStartGameButton);
|
||||||
|
forceStartGameButton->setEnabled(false);
|
||||||
|
}
|
||||||
|
buttonHBox->setContentsMargins(0, 0, 0, 0);
|
||||||
|
buttonHBox->addStretch();
|
||||||
|
|
||||||
|
deckView = new DeckView;
|
||||||
|
connect(deckView, SIGNAL(newCardAdded(AbstractCardItem *)), this, SIGNAL(newCardAdded(AbstractCardItem *)));
|
||||||
|
connect(deckView, SIGNAL(sideboardPlanChanged()), this, SLOT(sideboardPlanChanged()));
|
||||||
|
deckView->setVisible(false);
|
||||||
|
|
||||||
|
visualDeckStorageWidget = new VisualDeckStorageWidget(this);
|
||||||
|
connect(visualDeckStorageWidget, &VisualDeckStorageWidget::deckPreviewDoubleClicked, this,
|
||||||
|
&DeckViewContainer::replaceDeckStorageWithDeckView);
|
||||||
|
|
||||||
|
deckViewLayout = new QVBoxLayout;
|
||||||
|
deckViewLayout->addLayout(buttonHBox);
|
||||||
|
deckViewLayout->addWidget(deckView);
|
||||||
|
deckViewLayout->addWidget(visualDeckStorageWidget);
|
||||||
|
deckViewLayout->setContentsMargins(0, 0, 0, 0);
|
||||||
|
setLayout(deckViewLayout);
|
||||||
|
|
||||||
|
retranslateUi();
|
||||||
|
connect(&SettingsCache::instance().shortcuts(), SIGNAL(shortCutChanged()), this, SLOT(refreshShortcuts()));
|
||||||
|
refreshShortcuts();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeckViewContainer::retranslateUi()
|
||||||
|
{
|
||||||
|
loadLocalButton->setText(tr("Load deck..."));
|
||||||
|
loadRemoteButton->setText(tr("Load remote deck..."));
|
||||||
|
unloadDeckButton->setText(tr("Unload deck"));
|
||||||
|
readyStartButton->setText(tr("Ready to start"));
|
||||||
|
forceStartGameButton->setText(tr("Force start"));
|
||||||
|
updateSideboardLockButtonText();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeckViewContainer::setButtonsVisible(bool _visible)
|
||||||
|
{
|
||||||
|
loadLocalButton->setVisible(_visible);
|
||||||
|
loadRemoteButton->setVisible(_visible);
|
||||||
|
readyStartButton->setVisible(_visible);
|
||||||
|
forceStartGameButton->setVisible(_visible);
|
||||||
|
sideboardLockButton->setVisible(_visible);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeckViewContainer::updateSideboardLockButtonText()
|
||||||
|
{
|
||||||
|
if (sideboardLockButton->getState()) {
|
||||||
|
sideboardLockButton->setText(tr("Sideboard unlocked"));
|
||||||
|
} else {
|
||||||
|
sideboardLockButton->setText(tr("Sideboard locked"));
|
||||||
|
}
|
||||||
|
// setting text on a button removes its shortcut
|
||||||
|
ShortcutsSettings &shortcuts = SettingsCache::instance().shortcuts();
|
||||||
|
sideboardLockButton->setShortcut(shortcuts.getSingleShortcut("DeckViewContainer/sideboardLockButton"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeckViewContainer::refreshShortcuts()
|
||||||
|
{
|
||||||
|
ShortcutsSettings &shortcuts = SettingsCache::instance().shortcuts();
|
||||||
|
loadLocalButton->setShortcut(shortcuts.getSingleShortcut("DeckViewContainer/loadLocalButton"));
|
||||||
|
loadRemoteButton->setShortcut(shortcuts.getSingleShortcut("DeckViewContainer/loadRemoteButton"));
|
||||||
|
readyStartButton->setShortcut(shortcuts.getSingleShortcut("DeckViewContainer/readyStartButton"));
|
||||||
|
sideboardLockButton->setShortcut(shortcuts.getSingleShortcut("DeckViewContainer/sideboardLockButton"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeckViewContainer::replaceDeckStorageWithDeckView(QMouseEvent *event, DeckPreviewWidget *instance)
|
||||||
|
{
|
||||||
|
Q_UNUSED(event);
|
||||||
|
QString deckString = instance->deckLoader->writeToString_Native();
|
||||||
|
|
||||||
|
if (deckString.length() > MAX_FILE_LENGTH) {
|
||||||
|
QMessageBox::critical(this, tr("Error"), tr("The selected file could not be loaded."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Command_DeckSelect cmd;
|
||||||
|
cmd.set_deck(deckString.toStdString());
|
||||||
|
PendingCommand *pend = parentGame->prepareGameCommand(cmd);
|
||||||
|
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this,
|
||||||
|
SLOT(deckSelectFinished(const Response &)));
|
||||||
|
parentGame->sendGameCommand(pend, playerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeckViewContainer::unloadDeck()
|
||||||
|
{
|
||||||
|
deckView->setVisible(false);
|
||||||
|
visualDeckStorageWidget->setVisible(true);
|
||||||
|
deckViewLayout->update();
|
||||||
|
unloadDeckButton->setEnabled(false);
|
||||||
|
readyStartButton->setEnabled(false);
|
||||||
|
readyStartButton->setState(false);
|
||||||
|
sideboardLockButton->setEnabled(false);
|
||||||
|
sideboardLockButton->setState(false);
|
||||||
|
forceStartGameButton->setEnabled(false);
|
||||||
|
setReadyStart(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeckViewContainer::loadLocalDeck()
|
||||||
|
{
|
||||||
|
DlgLoadDeck dialog(this);
|
||||||
|
if (!dialog.exec())
|
||||||
|
return;
|
||||||
|
|
||||||
|
loadDeckFromFile(dialog.selectedFiles().at(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeckViewContainer::loadDeckFromFile(const QString &filePath)
|
||||||
|
{
|
||||||
|
DeckLoader::FileFormat fmt = DeckLoader::getFormatFromName(filePath);
|
||||||
|
QString deckString;
|
||||||
|
DeckLoader deck;
|
||||||
|
|
||||||
|
bool error = !deck.loadFromFile(filePath, fmt, true);
|
||||||
|
if (!error) {
|
||||||
|
deckString = deck.writeToString_Native();
|
||||||
|
error = deckString.length() > MAX_FILE_LENGTH;
|
||||||
|
}
|
||||||
|
if (error) {
|
||||||
|
QMessageBox::critical(this, tr("Error"), tr("The selected file could not be loaded."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Command_DeckSelect cmd;
|
||||||
|
cmd.set_deck(deckString.toStdString());
|
||||||
|
PendingCommand *pend = parentGame->prepareGameCommand(cmd);
|
||||||
|
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this,
|
||||||
|
SLOT(deckSelectFinished(const Response &)));
|
||||||
|
parentGame->sendGameCommand(pend, playerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeckViewContainer::loadRemoteDeck()
|
||||||
|
{
|
||||||
|
DlgLoadRemoteDeck dlg(parentGame->getClientForPlayer(playerId), this);
|
||||||
|
if (dlg.exec()) {
|
||||||
|
Command_DeckSelect cmd;
|
||||||
|
cmd.set_deck_id(dlg.getDeckId());
|
||||||
|
PendingCommand *pend = parentGame->prepareGameCommand(cmd);
|
||||||
|
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this,
|
||||||
|
SLOT(deckSelectFinished(const Response &)));
|
||||||
|
parentGame->sendGameCommand(pend, playerId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeckViewContainer::deckSelectFinished(const Response &r)
|
||||||
|
{
|
||||||
|
const Response_DeckDownload &resp = r.GetExtension(Response_DeckDownload::ext);
|
||||||
|
DeckLoader newDeck(QString::fromStdString(resp.deck()));
|
||||||
|
// TODO CHANGE THIS TO BE SELECTED BY UUID
|
||||||
|
PictureLoader::cacheCardPixmaps(CardDatabaseManager::getInstance()->getCards(newDeck.getCardList()));
|
||||||
|
setDeck(newDeck);
|
||||||
|
deckView->setVisible(true);
|
||||||
|
visualDeckStorageWidget->setVisible(false);
|
||||||
|
unloadDeckButton->setEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeckViewContainer::readyStart()
|
||||||
|
{
|
||||||
|
Command_ReadyStart cmd;
|
||||||
|
cmd.set_ready(!readyStartButton->getState());
|
||||||
|
parentGame->sendGameCommand(cmd, playerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeckViewContainer::forceStart()
|
||||||
|
{
|
||||||
|
Command_ReadyStart cmd;
|
||||||
|
cmd.set_force_start(true);
|
||||||
|
cmd.set_ready(true);
|
||||||
|
parentGame->sendGameCommand(cmd, playerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeckViewContainer::sideboardLockButtonClicked()
|
||||||
|
{
|
||||||
|
Command_SetSideboardLock cmd;
|
||||||
|
cmd.set_locked(sideboardLockButton->getState());
|
||||||
|
|
||||||
|
parentGame->sendGameCommand(cmd, playerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeckViewContainer::sideboardPlanChanged()
|
||||||
|
{
|
||||||
|
Command_SetSideboardPlan cmd;
|
||||||
|
const QList<MoveCard_ToZone> &newPlan = deckView->getSideboardPlan();
|
||||||
|
for (const auto &i : newPlan)
|
||||||
|
cmd.add_move_list()->CopyFrom(i);
|
||||||
|
parentGame->sendGameCommand(cmd, playerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeckViewContainer::setReadyStart(bool ready)
|
||||||
|
{
|
||||||
|
readyStartButton->setState(ready);
|
||||||
|
deckView->setLocked(ready || !sideboardLockButton->getState());
|
||||||
|
sideboardLockButton->setEnabled(!readyStartButton->getState() && readyStartButton->isEnabled());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the ready start to true, then sends the ready command so the server responds to the update
|
||||||
|
*/
|
||||||
|
void DeckViewContainer::readyAndUpdate()
|
||||||
|
{
|
||||||
|
setReadyStart(true);
|
||||||
|
|
||||||
|
Command_ReadyStart cmd;
|
||||||
|
cmd.set_ready(true);
|
||||||
|
parentGame->sendGameCommand(cmd, playerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeckViewContainer::setSideboardLocked(bool locked)
|
||||||
|
{
|
||||||
|
sideboardLockButton->setState(!locked);
|
||||||
|
deckView->setLocked(readyStartButton->getState() || !sideboardLockButton->getState());
|
||||||
|
if (locked)
|
||||||
|
deckView->resetSideboardPlan();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeckViewContainer::setDeck(const DeckLoader &deck)
|
||||||
|
{
|
||||||
|
deckView->setDeck(deck);
|
||||||
|
readyStartButton->setEnabled(true);
|
||||||
|
sideboardLockButton->setState(false);
|
||||||
|
sideboardLockButton->setEnabled(true);
|
||||||
|
forceStartGameButton->setEnabled(true);
|
||||||
|
}
|
||||||
82
cockatrice/src/client/tabs/deck_view_container.h
Normal file
82
cockatrice/src/client/tabs/deck_view_container.h
Normal file
|
|
@ -0,0 +1,82 @@
|
||||||
|
#ifndef DECK_VIEW_CONTAINER_H
|
||||||
|
#define DECK_VIEW_CONTAINER_H
|
||||||
|
|
||||||
|
#include "../../client/ui/widgets/cards/card_info_frame_widget.h"
|
||||||
|
#include "../../deck/deck_loader.h"
|
||||||
|
#include "pb/event_leave.pb.h"
|
||||||
|
#include "tab.h"
|
||||||
|
|
||||||
|
#include <QCompleter>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <pb/response.pb.h>
|
||||||
|
|
||||||
|
class VisualDeckStorageWidget;
|
||||||
|
class DeckPreviewWidget;
|
||||||
|
class TabGame;
|
||||||
|
class DeckView;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom QButton implementation in order to have the red/green toggling square around the button
|
||||||
|
*/
|
||||||
|
class ToggleButton : public QPushButton
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
private:
|
||||||
|
bool state;
|
||||||
|
signals:
|
||||||
|
void stateChanged();
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit ToggleButton(QWidget *parent = nullptr);
|
||||||
|
bool getState() const
|
||||||
|
{
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
void setState(bool _state);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void paintEvent(QPaintEvent *event) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This widget contains the deck selection view that is used before a game begins.
|
||||||
|
*/
|
||||||
|
class DeckViewContainer : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
private:
|
||||||
|
QVBoxLayout *deckViewLayout;
|
||||||
|
QPushButton *loadLocalButton, *loadRemoteButton, *unloadDeckButton, *forceStartGameButton;
|
||||||
|
ToggleButton *readyStartButton, *sideboardLockButton;
|
||||||
|
DeckView *deckView;
|
||||||
|
VisualDeckStorageWidget *visualDeckStorageWidget;
|
||||||
|
TabGame *parentGame;
|
||||||
|
int playerId;
|
||||||
|
private slots:
|
||||||
|
void replaceDeckStorageWithDeckView(QMouseEvent *event, DeckPreviewWidget *instance);
|
||||||
|
void loadLocalDeck();
|
||||||
|
void loadRemoteDeck();
|
||||||
|
void unloadDeck();
|
||||||
|
void readyStart();
|
||||||
|
void forceStart();
|
||||||
|
void deckSelectFinished(const Response &r);
|
||||||
|
void sideboardPlanChanged();
|
||||||
|
void sideboardLockButtonClicked();
|
||||||
|
void updateSideboardLockButtonText();
|
||||||
|
void refreshShortcuts();
|
||||||
|
signals:
|
||||||
|
void newCardAdded(AbstractCardItem *card);
|
||||||
|
void notIdle();
|
||||||
|
|
||||||
|
public:
|
||||||
|
DeckViewContainer(int _playerId, TabGame *parent);
|
||||||
|
void retranslateUi();
|
||||||
|
void setButtonsVisible(bool _visible);
|
||||||
|
void setReadyStart(bool ready);
|
||||||
|
void readyAndUpdate();
|
||||||
|
void setSideboardLocked(bool locked);
|
||||||
|
void setDeck(const DeckLoader &deck);
|
||||||
|
void loadDeckFromFile(const QString &filePath);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DECK_VIEW_CONTAINER_H
|
||||||
|
|
@ -76,131 +76,6 @@
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <google/protobuf/descriptor.h>
|
#include <google/protobuf/descriptor.h>
|
||||||
|
|
||||||
ToggleButton::ToggleButton(QWidget *parent) : QPushButton(parent), state(false)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void ToggleButton::paintEvent(QPaintEvent *event)
|
|
||||||
{
|
|
||||||
QPushButton::paintEvent(event);
|
|
||||||
|
|
||||||
QPainter painter(this);
|
|
||||||
QPen pen;
|
|
||||||
pen.setWidth(3);
|
|
||||||
pen.setJoinStyle(Qt::MiterJoin);
|
|
||||||
pen.setColor(state ? Qt::green : Qt::red);
|
|
||||||
painter.setPen(pen);
|
|
||||||
painter.drawRect(QRect(1, 1, width() - 3, height() - 3));
|
|
||||||
}
|
|
||||||
|
|
||||||
void ToggleButton::setState(bool _state)
|
|
||||||
{
|
|
||||||
state = _state;
|
|
||||||
emit stateChanged();
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
DeckViewContainer::DeckViewContainer(int _playerId, TabGame *parent)
|
|
||||||
: QWidget(nullptr), parentGame(parent), playerId(_playerId)
|
|
||||||
{
|
|
||||||
loadLocalButton = new QPushButton;
|
|
||||||
loadRemoteButton = new QPushButton;
|
|
||||||
unloadDeckButton = new QPushButton;
|
|
||||||
unloadDeckButton->setEnabled(false);
|
|
||||||
readyStartButton = new ToggleButton;
|
|
||||||
readyStartButton->setEnabled(false);
|
|
||||||
forceStartGameButton = new QPushButton;
|
|
||||||
forceStartGameButton->setEnabled(parent->isHost());
|
|
||||||
sideboardLockButton = new ToggleButton;
|
|
||||||
sideboardLockButton->setEnabled(false);
|
|
||||||
|
|
||||||
connect(loadLocalButton, SIGNAL(clicked()), this, SLOT(loadLocalDeck()));
|
|
||||||
connect(readyStartButton, SIGNAL(clicked()), this, SLOT(readyStart()));
|
|
||||||
connect(unloadDeckButton, &QPushButton::clicked, this, &DeckViewContainer::unloadDeck);
|
|
||||||
connect(forceStartGameButton, &QPushButton::clicked, this, &DeckViewContainer::forceStart);
|
|
||||||
connect(sideboardLockButton, SIGNAL(clicked()), this, SLOT(sideboardLockButtonClicked()));
|
|
||||||
connect(sideboardLockButton, SIGNAL(stateChanged()), this, SLOT(updateSideboardLockButtonText()));
|
|
||||||
|
|
||||||
if (parentGame->getIsLocalGame()) {
|
|
||||||
loadRemoteButton->setEnabled(false);
|
|
||||||
} else {
|
|
||||||
connect(loadRemoteButton, SIGNAL(clicked()), this, SLOT(loadRemoteDeck()));
|
|
||||||
}
|
|
||||||
|
|
||||||
auto *buttonHBox = new QHBoxLayout;
|
|
||||||
buttonHBox->addWidget(loadLocalButton);
|
|
||||||
buttonHBox->addWidget(loadRemoteButton);
|
|
||||||
buttonHBox->addWidget(unloadDeckButton);
|
|
||||||
buttonHBox->addWidget(readyStartButton);
|
|
||||||
buttonHBox->addWidget(sideboardLockButton);
|
|
||||||
if (forceStartGameButton->isEnabled()) {
|
|
||||||
buttonHBox->addWidget(forceStartGameButton);
|
|
||||||
forceStartGameButton->setEnabled(false);
|
|
||||||
}
|
|
||||||
buttonHBox->setContentsMargins(0, 0, 0, 0);
|
|
||||||
buttonHBox->addStretch();
|
|
||||||
|
|
||||||
deckView = new DeckView;
|
|
||||||
connect(deckView, SIGNAL(newCardAdded(AbstractCardItem *)), this, SIGNAL(newCardAdded(AbstractCardItem *)));
|
|
||||||
connect(deckView, SIGNAL(sideboardPlanChanged()), this, SLOT(sideboardPlanChanged()));
|
|
||||||
deckView->setVisible(false);
|
|
||||||
|
|
||||||
visualDeckStorageWidget = new VisualDeckStorageWidget(this);
|
|
||||||
connect(visualDeckStorageWidget, &VisualDeckStorageWidget::deckPreviewDoubleClicked, this,
|
|
||||||
&DeckViewContainer::replaceDeckStorageWithDeckView);
|
|
||||||
|
|
||||||
deckViewLayout = new QVBoxLayout;
|
|
||||||
deckViewLayout->addLayout(buttonHBox);
|
|
||||||
deckViewLayout->addWidget(deckView);
|
|
||||||
deckViewLayout->addWidget(visualDeckStorageWidget);
|
|
||||||
deckViewLayout->setContentsMargins(0, 0, 0, 0);
|
|
||||||
setLayout(deckViewLayout);
|
|
||||||
|
|
||||||
retranslateUi();
|
|
||||||
connect(&SettingsCache::instance().shortcuts(), SIGNAL(shortCutChanged()), this, SLOT(refreshShortcuts()));
|
|
||||||
refreshShortcuts();
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeckViewContainer::retranslateUi()
|
|
||||||
{
|
|
||||||
loadLocalButton->setText(tr("Load deck..."));
|
|
||||||
loadRemoteButton->setText(tr("Load remote deck..."));
|
|
||||||
unloadDeckButton->setText(tr("Unload deck"));
|
|
||||||
readyStartButton->setText(tr("Ready to start"));
|
|
||||||
forceStartGameButton->setText(tr("Force start"));
|
|
||||||
updateSideboardLockButtonText();
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeckViewContainer::setButtonsVisible(bool _visible)
|
|
||||||
{
|
|
||||||
loadLocalButton->setVisible(_visible);
|
|
||||||
loadRemoteButton->setVisible(_visible);
|
|
||||||
readyStartButton->setVisible(_visible);
|
|
||||||
forceStartGameButton->setVisible(_visible);
|
|
||||||
sideboardLockButton->setVisible(_visible);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeckViewContainer::updateSideboardLockButtonText()
|
|
||||||
{
|
|
||||||
if (sideboardLockButton->getState()) {
|
|
||||||
sideboardLockButton->setText(tr("Sideboard unlocked"));
|
|
||||||
} else {
|
|
||||||
sideboardLockButton->setText(tr("Sideboard locked"));
|
|
||||||
}
|
|
||||||
// setting text on a button removes its shortcut
|
|
||||||
ShortcutsSettings &shortcuts = SettingsCache::instance().shortcuts();
|
|
||||||
sideboardLockButton->setShortcut(shortcuts.getSingleShortcut("DeckViewContainer/sideboardLockButton"));
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeckViewContainer::refreshShortcuts()
|
|
||||||
{
|
|
||||||
ShortcutsSettings &shortcuts = SettingsCache::instance().shortcuts();
|
|
||||||
loadLocalButton->setShortcut(shortcuts.getSingleShortcut("DeckViewContainer/loadLocalButton"));
|
|
||||||
loadRemoteButton->setShortcut(shortcuts.getSingleShortcut("DeckViewContainer/loadRemoteButton"));
|
|
||||||
readyStartButton->setShortcut(shortcuts.getSingleShortcut("DeckViewContainer/readyStartButton"));
|
|
||||||
sideboardLockButton->setShortcut(shortcuts.getSingleShortcut("DeckViewContainer/sideboardLockButton"));
|
|
||||||
}
|
|
||||||
|
|
||||||
void TabGame::refreshShortcuts()
|
void TabGame::refreshShortcuts()
|
||||||
{
|
{
|
||||||
ShortcutsSettings &shortcuts = SettingsCache::instance().shortcuts();
|
ShortcutsSettings &shortcuts = SettingsCache::instance().shortcuts();
|
||||||
|
|
@ -300,168 +175,6 @@ void TabGame::refreshShortcuts()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckViewContainer::replaceDeckStorageWithDeckView(QMouseEvent *event, DeckPreviewWidget *instance)
|
|
||||||
{
|
|
||||||
Q_UNUSED(event);
|
|
||||||
QString deckString = instance->deckLoader->writeToString_Native();
|
|
||||||
|
|
||||||
if (deckString.length() > MAX_FILE_LENGTH) {
|
|
||||||
QMessageBox::critical(this, tr("Error"), tr("The selected file could not be loaded."));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Command_DeckSelect cmd;
|
|
||||||
cmd.set_deck(deckString.toStdString());
|
|
||||||
PendingCommand *pend = parentGame->prepareGameCommand(cmd);
|
|
||||||
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this,
|
|
||||||
SLOT(deckSelectFinished(const Response &)));
|
|
||||||
parentGame->sendGameCommand(pend, playerId);
|
|
||||||
visualDeckStorageWidget->setVisible(false);
|
|
||||||
deckView->setVisible(true);
|
|
||||||
deckViewLayout->update();
|
|
||||||
unloadDeckButton->setEnabled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeckViewContainer::unloadDeck()
|
|
||||||
{
|
|
||||||
deckView->setVisible(false);
|
|
||||||
visualDeckStorageWidget->setVisible(true);
|
|
||||||
deckViewLayout->update();
|
|
||||||
unloadDeckButton->setEnabled(false);
|
|
||||||
readyStartButton->setEnabled(false);
|
|
||||||
readyStartButton->setState(false);
|
|
||||||
sideboardLockButton->setEnabled(false);
|
|
||||||
sideboardLockButton->setState(false);
|
|
||||||
forceStartGameButton->setEnabled(false);
|
|
||||||
setReadyStart(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeckViewContainer::loadLocalDeck()
|
|
||||||
{
|
|
||||||
DlgLoadDeck dialog(this);
|
|
||||||
if (!dialog.exec())
|
|
||||||
return;
|
|
||||||
|
|
||||||
loadDeckFromFile(dialog.selectedFiles().at(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeckViewContainer::loadDeckFromFile(const QString &filePath)
|
|
||||||
{
|
|
||||||
DeckLoader::FileFormat fmt = DeckLoader::getFormatFromName(filePath);
|
|
||||||
QString deckString;
|
|
||||||
DeckLoader deck;
|
|
||||||
|
|
||||||
bool error = !deck.loadFromFile(filePath, fmt, true);
|
|
||||||
if (!error) {
|
|
||||||
deckString = deck.writeToString_Native();
|
|
||||||
error = deckString.length() > MAX_FILE_LENGTH;
|
|
||||||
}
|
|
||||||
if (error) {
|
|
||||||
QMessageBox::critical(this, tr("Error"), tr("The selected file could not be loaded."));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Command_DeckSelect cmd;
|
|
||||||
cmd.set_deck(deckString.toStdString());
|
|
||||||
PendingCommand *pend = parentGame->prepareGameCommand(cmd);
|
|
||||||
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this,
|
|
||||||
SLOT(deckSelectFinished(const Response &)));
|
|
||||||
parentGame->sendGameCommand(pend, playerId);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeckViewContainer::loadRemoteDeck()
|
|
||||||
{
|
|
||||||
DlgLoadRemoteDeck dlg(parentGame->getClientForPlayer(playerId), this);
|
|
||||||
if (dlg.exec()) {
|
|
||||||
Command_DeckSelect cmd;
|
|
||||||
cmd.set_deck_id(dlg.getDeckId());
|
|
||||||
PendingCommand *pend = parentGame->prepareGameCommand(cmd);
|
|
||||||
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this,
|
|
||||||
SLOT(deckSelectFinished(const Response &)));
|
|
||||||
parentGame->sendGameCommand(pend, playerId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeckViewContainer::deckSelectFinished(const Response &r)
|
|
||||||
{
|
|
||||||
const Response_DeckDownload &resp = r.GetExtension(Response_DeckDownload::ext);
|
|
||||||
DeckLoader newDeck(QString::fromStdString(resp.deck()));
|
|
||||||
// TODO CHANGE THIS TO BE SELECTED BY UUID
|
|
||||||
PictureLoader::cacheCardPixmaps(CardDatabaseManager::getInstance()->getCards(newDeck.getCardList()));
|
|
||||||
setDeck(newDeck);
|
|
||||||
deckView->setVisible(true);
|
|
||||||
visualDeckStorageWidget->setVisible(false);
|
|
||||||
unloadDeckButton->setEnabled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeckViewContainer::readyStart()
|
|
||||||
{
|
|
||||||
Command_ReadyStart cmd;
|
|
||||||
cmd.set_ready(!readyStartButton->getState());
|
|
||||||
parentGame->sendGameCommand(cmd, playerId);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeckViewContainer::forceStart()
|
|
||||||
{
|
|
||||||
Command_ReadyStart cmd;
|
|
||||||
cmd.set_force_start(true);
|
|
||||||
cmd.set_ready(true);
|
|
||||||
parentGame->sendGameCommand(cmd, playerId);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeckViewContainer::sideboardLockButtonClicked()
|
|
||||||
{
|
|
||||||
Command_SetSideboardLock cmd;
|
|
||||||
cmd.set_locked(sideboardLockButton->getState());
|
|
||||||
|
|
||||||
parentGame->sendGameCommand(cmd, playerId);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeckViewContainer::sideboardPlanChanged()
|
|
||||||
{
|
|
||||||
Command_SetSideboardPlan cmd;
|
|
||||||
const QList<MoveCard_ToZone> &newPlan = deckView->getSideboardPlan();
|
|
||||||
for (const auto &i : newPlan)
|
|
||||||
cmd.add_move_list()->CopyFrom(i);
|
|
||||||
parentGame->sendGameCommand(cmd, playerId);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeckViewContainer::setReadyStart(bool ready)
|
|
||||||
{
|
|
||||||
readyStartButton->setState(ready);
|
|
||||||
deckView->setLocked(ready || !sideboardLockButton->getState());
|
|
||||||
sideboardLockButton->setEnabled(!readyStartButton->getState() && readyStartButton->isEnabled());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the ready start to true, then sends the ready command so the server responds to the update
|
|
||||||
*/
|
|
||||||
void DeckViewContainer::readyAndUpdate()
|
|
||||||
{
|
|
||||||
setReadyStart(true);
|
|
||||||
|
|
||||||
Command_ReadyStart cmd;
|
|
||||||
cmd.set_ready(true);
|
|
||||||
parentGame->sendGameCommand(cmd, playerId);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeckViewContainer::setSideboardLocked(bool locked)
|
|
||||||
{
|
|
||||||
sideboardLockButton->setState(!locked);
|
|
||||||
deckView->setLocked(readyStartButton->getState() || !sideboardLockButton->getState());
|
|
||||||
if (locked)
|
|
||||||
deckView->resetSideboardPlan();
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeckViewContainer::setDeck(const DeckLoader &deck)
|
|
||||||
{
|
|
||||||
deckView->setDeck(deck);
|
|
||||||
readyStartButton->setEnabled(true);
|
|
||||||
sideboardLockButton->setState(false);
|
|
||||||
sideboardLockButton->setEnabled(true);
|
|
||||||
forceStartGameButton->setEnabled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
TabGame::TabGame(TabSupervisor *_tabSupervisor, GameReplay *_replay)
|
TabGame::TabGame(TabSupervisor *_tabSupervisor, GameReplay *_replay)
|
||||||
: Tab(_tabSupervisor), secondsElapsed(0), hostId(-1), localPlayerId(-1),
|
: Tab(_tabSupervisor), secondsElapsed(0), hostId(-1), localPlayerId(-1),
|
||||||
isLocalGame(_tabSupervisor->getIsLocalGame()), spectator(true), judge(false), gameStateKnown(false),
|
isLocalGame(_tabSupervisor->getIsLocalGame()), spectator(true), judge(false), gameStateKnown(false),
|
||||||
|
|
|
||||||
|
|
@ -63,64 +63,6 @@ class LineEditCompleter;
|
||||||
class QDockWidget;
|
class QDockWidget;
|
||||||
class QStackedWidget;
|
class QStackedWidget;
|
||||||
|
|
||||||
class ToggleButton : public QPushButton
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
private:
|
|
||||||
bool state;
|
|
||||||
signals:
|
|
||||||
void stateChanged();
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit ToggleButton(QWidget *parent = nullptr);
|
|
||||||
bool getState() const
|
|
||||||
{
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
void setState(bool _state);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void paintEvent(QPaintEvent *event) override;
|
|
||||||
};
|
|
||||||
|
|
||||||
class DeckViewContainer : public QWidget
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
private:
|
|
||||||
QVBoxLayout *deckViewLayout;
|
|
||||||
QPushButton *loadLocalButton, *loadRemoteButton, *unloadDeckButton, *forceStartGameButton;
|
|
||||||
ToggleButton *readyStartButton, *sideboardLockButton;
|
|
||||||
DeckView *deckView;
|
|
||||||
VisualDeckStorageWidget *visualDeckStorageWidget;
|
|
||||||
TabGame *parentGame;
|
|
||||||
int playerId;
|
|
||||||
private slots:
|
|
||||||
void replaceDeckStorageWithDeckView(QMouseEvent *event, DeckPreviewWidget *instance);
|
|
||||||
void loadLocalDeck();
|
|
||||||
void loadRemoteDeck();
|
|
||||||
void unloadDeck();
|
|
||||||
void readyStart();
|
|
||||||
void forceStart();
|
|
||||||
void deckSelectFinished(const Response &r);
|
|
||||||
void sideboardPlanChanged();
|
|
||||||
void sideboardLockButtonClicked();
|
|
||||||
void updateSideboardLockButtonText();
|
|
||||||
void refreshShortcuts();
|
|
||||||
signals:
|
|
||||||
void newCardAdded(AbstractCardItem *card);
|
|
||||||
void notIdle();
|
|
||||||
|
|
||||||
public:
|
|
||||||
DeckViewContainer(int _playerId, TabGame *parent);
|
|
||||||
void retranslateUi();
|
|
||||||
void setButtonsVisible(bool _visible);
|
|
||||||
void setReadyStart(bool ready);
|
|
||||||
void readyAndUpdate();
|
|
||||||
void setSideboardLocked(bool locked);
|
|
||||||
void setDeck(const DeckLoader &deck);
|
|
||||||
void loadDeckFromFile(const QString &filePath);
|
|
||||||
};
|
|
||||||
|
|
||||||
class TabGame : public Tab
|
class TabGame : public Tab
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue