mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-20 17:32: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 "../game/filters/filter_string.h"
|
||||
#include "trice_limits.h"
|
||||
|
||||
#include <QDialogButtonBox>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QMessageBox>
|
||||
#include <QSpinBox>
|
||||
#include <QString>
|
||||
#include <QVBoxLayout>
|
||||
|
|
@ -30,7 +32,7 @@ DlgMoveTopCardsUntil::DlgMoveTopCardsUntil(QWidget *parent, QString _expr, uint
|
|||
grid->addWidget(numberOfHitsEdit, 0, 1);
|
||||
|
||||
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);
|
||||
|
||||
auto *mainLayout = new QVBoxLayout;
|
||||
|
|
@ -43,6 +45,16 @@ DlgMoveTopCardsUntil::DlgMoveTopCardsUntil(QWidget *parent, QString _expr, uint
|
|||
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();
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ class DlgMoveTopCardsUntil : public QDialog
|
|||
QSpinBox *numberOfHitsEdit;
|
||||
QDialogButtonBox *buttonBox;
|
||||
|
||||
void validateAndAccept();
|
||||
|
||||
public:
|
||||
explicit DlgMoveTopCardsUntil(QWidget *parent = nullptr, QString expr = QString(), uint numberOfHits = 1);
|
||||
[[nodiscard]] QString getExpr() const;
|
||||
|
|
|
|||
|
|
@ -1333,33 +1333,19 @@ void Player::actMoveTopCardsUntil()
|
|||
{
|
||||
stopMoveTopCardsUntil();
|
||||
|
||||
QString expr = previousMovingCardsUntilExpr;
|
||||
int numberOfHits = previousMovingCardsUntilNumberOfHits;
|
||||
for (;;) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
DlgMoveTopCardsUntil dlg(game, previousMovingCardsUntilExpr, previousMovingCardsUntilNumberOfHits);
|
||||
if (!dlg.exec()) {
|
||||
return;
|
||||
}
|
||||
previousMovingCardsUntilExpr = expr;
|
||||
previousMovingCardsUntilNumberOfHits = numberOfHits;
|
||||
|
||||
previousMovingCardsUntilExpr = dlg.getExpr();
|
||||
previousMovingCardsUntilNumberOfHits = dlg.getNumberOfHits();
|
||||
|
||||
if (zones.value("deck")->getCards().empty()) {
|
||||
stopMoveTopCardsUntil();
|
||||
} else {
|
||||
movingCardsUntilCounter = numberOfHits;
|
||||
movingCardsUntilFilter = FilterString(previousMovingCardsUntilExpr);
|
||||
movingCardsUntilCounter = previousMovingCardsUntilNumberOfHits;
|
||||
movingCardsUntil = true;
|
||||
actMoveTopCardToPlay();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue