mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-11 08:34:52 -07:00
"Play top cards until" action now has option for number of hits (#5229)
* create new dlg window * get thing to work * move validation into dlg * remove nodiscard I'll revert this if someone else complains
This commit is contained in:
parent
315cbc0925
commit
e9b78c1c59
5 changed files with 130 additions and 23 deletions
|
|
@ -48,6 +48,7 @@ set(cockatrice_SOURCES
|
||||||
src/dialogs/dlg_load_deck_from_clipboard.cpp
|
src/dialogs/dlg_load_deck_from_clipboard.cpp
|
||||||
src/dialogs/dlg_load_remote_deck.cpp
|
src/dialogs/dlg_load_remote_deck.cpp
|
||||||
src/dialogs/dlg_manage_sets.cpp
|
src/dialogs/dlg_manage_sets.cpp
|
||||||
|
src/dialogs/dlg_move_top_cards_until.cpp
|
||||||
src/dialogs/dlg_register.cpp
|
src/dialogs/dlg_register.cpp
|
||||||
src/dialogs/dlg_roll_dice.cpp
|
src/dialogs/dlg_roll_dice.cpp
|
||||||
src/dialogs/dlg_settings.cpp
|
src/dialogs/dlg_settings.cpp
|
||||||
|
|
|
||||||
66
cockatrice/src/dialogs/dlg_move_top_cards_until.cpp
Normal file
66
cockatrice/src/dialogs/dlg_move_top_cards_until.cpp
Normal file
|
|
@ -0,0 +1,66 @@
|
||||||
|
#include "dlg_move_top_cards_until.h"
|
||||||
|
|
||||||
|
#include "../game/filters/filter_string.h"
|
||||||
|
#include "trice_limits.h"
|
||||||
|
|
||||||
|
#include <QDialogButtonBox>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QSpinBox>
|
||||||
|
#include <QString>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
DlgMoveTopCardsUntil::DlgMoveTopCardsUntil(QWidget *parent, QString _expr, uint _numberOfHits) : QDialog(parent)
|
||||||
|
{
|
||||||
|
exprLabel = new QLabel(tr("Card name (or search expressions):"));
|
||||||
|
|
||||||
|
exprEdit = new QLineEdit(this);
|
||||||
|
exprEdit->setFocus();
|
||||||
|
exprEdit->setText(_expr);
|
||||||
|
exprLabel->setBuddy(exprEdit);
|
||||||
|
|
||||||
|
numberOfHitsLabel = new QLabel(tr("Number of hits:"));
|
||||||
|
numberOfHitsEdit = new QSpinBox(this);
|
||||||
|
numberOfHitsEdit->setRange(1, 99);
|
||||||
|
numberOfHitsEdit->setValue(_numberOfHits);
|
||||||
|
numberOfHitsLabel->setBuddy(numberOfHitsEdit);
|
||||||
|
|
||||||
|
auto *grid = new QGridLayout;
|
||||||
|
grid->addWidget(numberOfHitsLabel, 0, 0);
|
||||||
|
grid->addWidget(numberOfHitsEdit, 0, 1);
|
||||||
|
|
||||||
|
buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||||
|
connect(buttonBox, &QDialogButtonBox::accepted, this, &DlgMoveTopCardsUntil::validateAndAccept);
|
||||||
|
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
||||||
|
|
||||||
|
auto *mainLayout = new QVBoxLayout;
|
||||||
|
mainLayout->addWidget(exprLabel);
|
||||||
|
mainLayout->addWidget(exprEdit);
|
||||||
|
mainLayout->addItem(grid);
|
||||||
|
mainLayout->addWidget(buttonBox);
|
||||||
|
|
||||||
|
setLayout(mainLayout);
|
||||||
|
setWindowTitle(tr("Put top cards on stack until..."));
|
||||||
|
}
|
||||||
|
|
||||||
|
void DlgMoveTopCardsUntil::validateAndAccept()
|
||||||
|
{
|
||||||
|
auto movingCardsUntilFilter = FilterString(exprEdit->text());
|
||||||
|
if (movingCardsUntilFilter.valid()) {
|
||||||
|
accept();
|
||||||
|
} else {
|
||||||
|
QMessageBox::warning(this, tr("Invalid filter"), movingCardsUntilFilter.error(), QMessageBox::Ok);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QString DlgMoveTopCardsUntil::getExpr() const
|
||||||
|
{
|
||||||
|
return exprEdit->text();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint DlgMoveTopCardsUntil::getNumberOfHits() const
|
||||||
|
{
|
||||||
|
return numberOfHitsEdit->text().toUInt();
|
||||||
|
}
|
||||||
28
cockatrice/src/dialogs/dlg_move_top_cards_until.h
Normal file
28
cockatrice/src/dialogs/dlg_move_top_cards_until.h
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
#ifndef DLG_MOVE_TOP_CARDS_UNTIL_H
|
||||||
|
#define DLG_MOVE_TOP_CARDS_UNTIL_H
|
||||||
|
|
||||||
|
#include <QDialog>
|
||||||
|
#include <QDialogButtonBox>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QSpinBox>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
class DlgMoveTopCardsUntil : public QDialog
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
QLabel *exprLabel, *numberOfHitsLabel;
|
||||||
|
QLineEdit *exprEdit;
|
||||||
|
QSpinBox *numberOfHitsEdit;
|
||||||
|
QDialogButtonBox *buttonBox;
|
||||||
|
|
||||||
|
void validateAndAccept();
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit DlgMoveTopCardsUntil(QWidget *parent = nullptr, QString expr = QString(), uint numberOfHits = 1);
|
||||||
|
QString getExpr() const;
|
||||||
|
uint getNumberOfHits() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DLG_MOVE_TOP_CARDS_UNTIL_H
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
#include "../../client/ui/theme_manager.h"
|
#include "../../client/ui/theme_manager.h"
|
||||||
#include "../../deck/deck_loader.h"
|
#include "../../deck/deck_loader.h"
|
||||||
#include "../../dialogs/dlg_create_token.h"
|
#include "../../dialogs/dlg_create_token.h"
|
||||||
|
#include "../../dialogs/dlg_move_top_cards_until.h"
|
||||||
#include "../../dialogs/dlg_roll_dice.h"
|
#include "../../dialogs/dlg_roll_dice.h"
|
||||||
#include "../../main.h"
|
#include "../../main.h"
|
||||||
#include "../../settings/cache_settings.h"
|
#include "../../settings/cache_settings.h"
|
||||||
|
|
@ -1330,30 +1331,21 @@ void Player::actMoveTopCardsToExile()
|
||||||
|
|
||||||
void Player::actMoveTopCardsUntil()
|
void Player::actMoveTopCardsUntil()
|
||||||
{
|
{
|
||||||
moveTopCardTimer->stop();
|
stopMoveTopCardsUntil();
|
||||||
movingCardsUntil = false;
|
|
||||||
QString expr = previousMovingCardsUntilExpr;
|
DlgMoveTopCardsUntil dlg(game, previousMovingCardsUntilExpr, previousMovingCardsUntilNumberOfHits);
|
||||||
for (;;) {
|
if (!dlg.exec()) {
|
||||||
bool ok;
|
return;
|
||||||
expr = QInputDialog::getText(game, "Put top cards on stack until", "Card name (or search expressions)", {},
|
|
||||||
expr, &ok);
|
|
||||||
if (!ok) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
movingCardsUntilFilter = FilterString(expr);
|
|
||||||
if (movingCardsUntilFilter.valid()) {
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
auto button = QMessageBox::warning(game, "Invalid filter", movingCardsUntilFilter.error());
|
|
||||||
if (button != QMessageBox::Ok) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
previousMovingCardsUntilExpr = expr;
|
|
||||||
|
previousMovingCardsUntilExpr = dlg.getExpr();
|
||||||
|
previousMovingCardsUntilNumberOfHits = dlg.getNumberOfHits();
|
||||||
|
|
||||||
if (zones.value("deck")->getCards().empty()) {
|
if (zones.value("deck")->getCards().empty()) {
|
||||||
movingCardsUntil = false;
|
stopMoveTopCardsUntil();
|
||||||
} else {
|
} else {
|
||||||
|
movingCardsUntilFilter = FilterString(previousMovingCardsUntilExpr);
|
||||||
|
movingCardsUntilCounter = previousMovingCardsUntilNumberOfHits;
|
||||||
movingCardsUntil = true;
|
movingCardsUntil = true;
|
||||||
actMoveTopCardToPlay();
|
actMoveTopCardToPlay();
|
||||||
}
|
}
|
||||||
|
|
@ -1362,13 +1354,30 @@ void Player::actMoveTopCardsUntil()
|
||||||
void Player::moveOneCardUntil(const CardInfoPtr card)
|
void Player::moveOneCardUntil(const CardInfoPtr card)
|
||||||
{
|
{
|
||||||
moveTopCardTimer->stop();
|
moveTopCardTimer->stop();
|
||||||
if (zones.value("deck")->getCards().empty() || card.isNull() || movingCardsUntilFilter.check(card)) {
|
if (zones.value("deck")->getCards().empty() || card.isNull()) {
|
||||||
movingCardsUntil = false;
|
stopMoveTopCardsUntil();
|
||||||
|
} else if (movingCardsUntilFilter.check(card)) {
|
||||||
|
--movingCardsUntilCounter;
|
||||||
|
if (movingCardsUntilCounter > 0) {
|
||||||
|
moveTopCardTimer->start();
|
||||||
|
} else {
|
||||||
|
stopMoveTopCardsUntil();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
moveTopCardTimer->start();
|
moveTopCardTimer->start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Immediately stops any ongoing `play top card to stack until...` process, resetting all variables involved.
|
||||||
|
*/
|
||||||
|
void Player::stopMoveTopCardsUntil()
|
||||||
|
{
|
||||||
|
moveTopCardTimer->stop();
|
||||||
|
movingCardsUntilCounter = 0;
|
||||||
|
movingCardsUntil = false;
|
||||||
|
}
|
||||||
|
|
||||||
void Player::actMoveTopCardToBottom()
|
void Player::actMoveTopCardToBottom()
|
||||||
{
|
{
|
||||||
if (zones.value("deck")->getCards().empty()) {
|
if (zones.value("deck")->getCards().empty()) {
|
||||||
|
|
|
||||||
|
|
@ -267,7 +267,10 @@ private:
|
||||||
bool movingCardsUntil;
|
bool movingCardsUntil;
|
||||||
QTimer *moveTopCardTimer;
|
QTimer *moveTopCardTimer;
|
||||||
QString previousMovingCardsUntilExpr = {};
|
QString previousMovingCardsUntilExpr = {};
|
||||||
|
int previousMovingCardsUntilNumberOfHits = 1;
|
||||||
FilterString movingCardsUntilFilter;
|
FilterString movingCardsUntilFilter;
|
||||||
|
int movingCardsUntilCounter = 0;
|
||||||
|
void stopMoveTopCardsUntil();
|
||||||
|
|
||||||
bool shortcutsActive;
|
bool shortcutsActive;
|
||||||
int defaultNumberTopCards = 1;
|
int defaultNumberTopCards = 1;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue