mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-21 01:42:15 -07:00
move validation into dlg
This commit is contained in:
parent
77cdda62dc
commit
a4f2ea197f
3 changed files with 24 additions and 24 deletions
|
|
@ -1,10 +1,12 @@
|
||||||
#include "dlg_move_top_cards_until.h"
|
#include "dlg_move_top_cards_until.h"
|
||||||
|
|
||||||
|
#include "../game/filters/filter_string.h"
|
||||||
#include "trice_limits.h"
|
#include "trice_limits.h"
|
||||||
|
|
||||||
#include <QDialogButtonBox>
|
#include <QDialogButtonBox>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
|
#include <QMessageBox>
|
||||||
#include <QSpinBox>
|
#include <QSpinBox>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
|
@ -30,7 +32,7 @@ DlgMoveTopCardsUntil::DlgMoveTopCardsUntil(QWidget *parent, QString _expr, uint
|
||||||
grid->addWidget(numberOfHitsEdit, 0, 1);
|
grid->addWidget(numberOfHitsEdit, 0, 1);
|
||||||
|
|
||||||
buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||||
connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
|
connect(buttonBox, &QDialogButtonBox::accepted, this, &DlgMoveTopCardsUntil::validateAndAccept);
|
||||||
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
||||||
|
|
||||||
auto *mainLayout = new QVBoxLayout;
|
auto *mainLayout = new QVBoxLayout;
|
||||||
|
|
@ -43,6 +45,16 @@ DlgMoveTopCardsUntil::DlgMoveTopCardsUntil(QWidget *parent, QString _expr, uint
|
||||||
setWindowTitle(tr("Put top cards on stack until..."));
|
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
|
QString DlgMoveTopCardsUntil::getExpr() const
|
||||||
{
|
{
|
||||||
return exprEdit->text();
|
return exprEdit->text();
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,8 @@ class DlgMoveTopCardsUntil : public QDialog
|
||||||
QSpinBox *numberOfHitsEdit;
|
QSpinBox *numberOfHitsEdit;
|
||||||
QDialogButtonBox *buttonBox;
|
QDialogButtonBox *buttonBox;
|
||||||
|
|
||||||
|
void validateAndAccept();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit DlgMoveTopCardsUntil(QWidget *parent = nullptr, QString expr = QString(), uint numberOfHits = 1);
|
explicit DlgMoveTopCardsUntil(QWidget *parent = nullptr, QString expr = QString(), uint numberOfHits = 1);
|
||||||
[[nodiscard]] QString getExpr() const;
|
[[nodiscard]] QString getExpr() const;
|
||||||
|
|
|
||||||
|
|
@ -1333,33 +1333,19 @@ void Player::actMoveTopCardsUntil()
|
||||||
{
|
{
|
||||||
stopMoveTopCardsUntil();
|
stopMoveTopCardsUntil();
|
||||||
|
|
||||||
QString expr = previousMovingCardsUntilExpr;
|
DlgMoveTopCardsUntil dlg(game, previousMovingCardsUntilExpr, previousMovingCardsUntilNumberOfHits);
|
||||||
int numberOfHits = previousMovingCardsUntilNumberOfHits;
|
if (!dlg.exec()) {
|
||||||
for (;;) {
|
return;
|
||||||
DlgMoveTopCardsUntil dlg(game, expr, numberOfHits);
|
|
||||||
if (!dlg.exec()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
expr = dlg.getExpr();
|
|
||||||
numberOfHits = dlg.getNumberOfHits();
|
|
||||||
|
|
||||||
movingCardsUntilFilter = FilterString(expr);
|
|
||||||
if (movingCardsUntilFilter.valid()) {
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
auto button = QMessageBox::warning(game, "Invalid filter", movingCardsUntilFilter.error());
|
|
||||||
if (button != QMessageBox::Ok) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
previousMovingCardsUntilExpr = expr;
|
|
||||||
previousMovingCardsUntilNumberOfHits = numberOfHits;
|
previousMovingCardsUntilExpr = dlg.getExpr();
|
||||||
|
previousMovingCardsUntilNumberOfHits = dlg.getNumberOfHits();
|
||||||
|
|
||||||
if (zones.value("deck")->getCards().empty()) {
|
if (zones.value("deck")->getCards().empty()) {
|
||||||
stopMoveTopCardsUntil();
|
stopMoveTopCardsUntil();
|
||||||
} else {
|
} else {
|
||||||
movingCardsUntilCounter = numberOfHits;
|
movingCardsUntilFilter = FilterString(previousMovingCardsUntilExpr);
|
||||||
|
movingCardsUntilCounter = previousMovingCardsUntilNumberOfHits;
|
||||||
movingCardsUntil = true;
|
movingCardsUntil = true;
|
||||||
actMoveTopCardToPlay();
|
actMoveTopCardToPlay();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue