mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-11 00:24:47 -07:00
Refactor: move last token info into struct (#5808)
* add override * refactor token info into struct * correct default destroy value
This commit is contained in:
parent
0bd53d6dc7
commit
56bbd8a172
4 changed files with 45 additions and 56 deletions
|
|
@ -224,27 +224,11 @@ void DlgCreateToken::actReject()
|
||||||
reject();
|
reject();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DlgCreateToken::getName() const
|
TokenInfo DlgCreateToken::getTokenInfo() const
|
||||||
{
|
{
|
||||||
return nameEdit->text();
|
return {.name = nameEdit->text(),
|
||||||
}
|
.color = colorEdit->itemData(colorEdit->currentIndex()).toString(),
|
||||||
|
.pt = ptEdit->text(),
|
||||||
QString DlgCreateToken::getColor() const
|
.annotation = annotationEdit->text(),
|
||||||
{
|
.destroy = destroyCheckBox->isChecked()};
|
||||||
return QString(colorEdit->itemData(colorEdit->currentIndex()).toChar());
|
|
||||||
}
|
|
||||||
|
|
||||||
QString DlgCreateToken::getPT() const
|
|
||||||
{
|
|
||||||
return ptEdit->text();
|
|
||||||
}
|
|
||||||
|
|
||||||
QString DlgCreateToken::getAnnotation() const
|
|
||||||
{
|
|
||||||
return annotationEdit->text();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DlgCreateToken::getDestroy() const
|
|
||||||
{
|
|
||||||
return destroyCheckBox->isChecked();
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,19 +17,24 @@ class CardDatabaseModel;
|
||||||
class TokenDisplayModel;
|
class TokenDisplayModel;
|
||||||
class CardInfoPictureWidget;
|
class CardInfoPictureWidget;
|
||||||
|
|
||||||
|
struct TokenInfo
|
||||||
|
{
|
||||||
|
QString name;
|
||||||
|
QString color;
|
||||||
|
QString pt;
|
||||||
|
QString annotation;
|
||||||
|
bool destroy = true;
|
||||||
|
};
|
||||||
|
|
||||||
class DlgCreateToken : public QDialog
|
class DlgCreateToken : public QDialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit DlgCreateToken(const QStringList &_predefinedTokens, QWidget *parent = nullptr);
|
explicit DlgCreateToken(const QStringList &_predefinedTokens, QWidget *parent = nullptr);
|
||||||
QString getName() const;
|
TokenInfo getTokenInfo() const;
|
||||||
QString getColor() const;
|
|
||||||
QString getPT() const;
|
|
||||||
QString getAnnotation() const;
|
|
||||||
bool getDestroy() const;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void closeEvent(QCloseEvent *event);
|
void closeEvent(QCloseEvent *event) override;
|
||||||
private slots:
|
private slots:
|
||||||
void tokenSelectionChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
void tokenSelectionChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
||||||
void updateSearch(const QString &search);
|
void updateSearch(const QString &search);
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@
|
||||||
#include "../../client/tabs/tab_game.h"
|
#include "../../client/tabs/tab_game.h"
|
||||||
#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_move_top_cards_until.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"
|
||||||
|
|
@ -109,9 +108,9 @@ void PlayerArea::setPlayerZoneId(int _playerZoneId)
|
||||||
}
|
}
|
||||||
|
|
||||||
Player::Player(const ServerInfo_User &info, int _id, bool _local, bool _judge, TabGame *_parent)
|
Player::Player(const ServerInfo_User &info, int _id, bool _local, bool _judge, TabGame *_parent)
|
||||||
: QObject(_parent), game(_parent), movingCardsUntil(false), shortcutsActive(false), lastTokenDestroy(true),
|
: QObject(_parent), game(_parent), movingCardsUntil(false), shortcutsActive(false), lastTokenTableRow(0), id(_id),
|
||||||
lastTokenTableRow(0), id(_id), active(false), local(_local), judge(_judge), mirrored(false), handVisible(false),
|
active(false), local(_local), judge(_judge), mirrored(false), handVisible(false), conceded(false), zoneId(0),
|
||||||
conceded(false), zoneId(0), dialogSemaphore(false), deck(nullptr)
|
dialogSemaphore(false), deck(nullptr)
|
||||||
{
|
{
|
||||||
userInfo = new ServerInfo_User;
|
userInfo = new ServerInfo_User;
|
||||||
userInfo->CopyFrom(info);
|
userInfo->CopyFrom(info);
|
||||||
|
|
@ -1826,37 +1825,35 @@ void Player::actCreateToken()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
lastTokenName = dlg.getName();
|
lastTokenInfo = dlg.getTokenInfo();
|
||||||
lastTokenPT = dlg.getPT();
|
|
||||||
CardInfoPtr correctedCard = CardDatabaseManager::getInstance()->guessCard(lastTokenName);
|
CardInfoPtr correctedCard = CardDatabaseManager::getInstance()->guessCard(lastTokenInfo.name);
|
||||||
if (correctedCard) {
|
if (correctedCard) {
|
||||||
lastTokenName = correctedCard->getName();
|
lastTokenInfo.name = correctedCard->getName();
|
||||||
lastTokenTableRow = TableZone::clampValidTableRow(2 - correctedCard->getTableRow());
|
lastTokenTableRow = TableZone::clampValidTableRow(2 - correctedCard->getTableRow());
|
||||||
if (lastTokenPT.isEmpty()) {
|
if (lastTokenInfo.pt.isEmpty()) {
|
||||||
lastTokenPT = correctedCard->getPowTough();
|
lastTokenInfo.pt = correctedCard->getPowTough();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lastTokenColor = dlg.getColor();
|
|
||||||
lastTokenAnnotation = dlg.getAnnotation();
|
|
||||||
lastTokenDestroy = dlg.getDestroy();
|
|
||||||
aCreateAnotherToken->setEnabled(true);
|
aCreateAnotherToken->setEnabled(true);
|
||||||
aCreateAnotherToken->setText(tr("C&reate another %1 token").arg(lastTokenName));
|
aCreateAnotherToken->setText(tr("C&reate another %1 token").arg(lastTokenInfo.name));
|
||||||
actCreateAnotherToken();
|
actCreateAnotherToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::actCreateAnotherToken()
|
void Player::actCreateAnotherToken()
|
||||||
{
|
{
|
||||||
if (lastTokenName.isEmpty()) {
|
if (lastTokenInfo.name.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Command_CreateToken cmd;
|
Command_CreateToken cmd;
|
||||||
cmd.set_zone("table");
|
cmd.set_zone("table");
|
||||||
cmd.set_card_name(lastTokenName.toStdString());
|
cmd.set_card_name(lastTokenInfo.name.toStdString());
|
||||||
cmd.set_color(lastTokenColor.toStdString());
|
cmd.set_color(lastTokenInfo.color.toStdString());
|
||||||
cmd.set_pt(lastTokenPT.toStdString());
|
cmd.set_pt(lastTokenInfo.pt.toStdString());
|
||||||
cmd.set_annotation(lastTokenAnnotation.toStdString());
|
cmd.set_annotation(lastTokenInfo.annotation.toStdString());
|
||||||
cmd.set_destroy_on_zone_change(lastTokenDestroy);
|
cmd.set_destroy_on_zone_change(lastTokenInfo.destroy);
|
||||||
cmd.set_x(-1);
|
cmd.set_x(-1);
|
||||||
cmd.set_y(lastTokenTableRow);
|
cmd.set_y(lastTokenTableRow);
|
||||||
|
|
||||||
|
|
@ -4180,12 +4177,13 @@ void Player::setLastToken(CardInfoPtr cardInfo)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
lastTokenName = cardInfo->getName();
|
lastTokenInfo = {.name = cardInfo->getName(),
|
||||||
lastTokenColor = cardInfo->getColors().isEmpty() ? QString() : cardInfo->getColors().left(1).toLower();
|
.color = cardInfo->getColors().isEmpty() ? QString() : cardInfo->getColors().left(1).toLower(),
|
||||||
lastTokenPT = cardInfo->getPowTough();
|
.pt = cardInfo->getPowTough(),
|
||||||
lastTokenAnnotation = SettingsCache::instance().getAnnotateTokens() ? cardInfo->getText() : "";
|
.annotation = SettingsCache::instance().getAnnotateTokens() ? cardInfo->getText() : "",
|
||||||
|
.destroy = true};
|
||||||
|
|
||||||
lastTokenTableRow = TableZone::clampValidTableRow(2 - cardInfo->getTableRow());
|
lastTokenTableRow = TableZone::clampValidTableRow(2 - cardInfo->getTableRow());
|
||||||
lastTokenDestroy = true;
|
aCreateAnotherToken->setText(tr("C&reate another %1 token").arg(lastTokenInfo.name));
|
||||||
aCreateAnotherToken->setText(tr("C&reate another %1 token").arg(lastTokenName));
|
|
||||||
aCreateAnotherToken->setEnabled(true);
|
aCreateAnotherToken->setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
#define PLAYER_H
|
#define PLAYER_H
|
||||||
|
|
||||||
#include "../../client/tearoff_menu.h"
|
#include "../../client/tearoff_menu.h"
|
||||||
|
#include "../../dialogs/dlg_create_token.h"
|
||||||
#include "../board/abstract_graphics_item.h"
|
#include "../board/abstract_graphics_item.h"
|
||||||
#include "../cards/card_database.h"
|
#include "../cards/card_database.h"
|
||||||
#include "../filters/filter_string.h"
|
#include "../filters/filter_string.h"
|
||||||
|
|
@ -291,9 +292,10 @@ private:
|
||||||
int defaultNumberTopCardsToPlaceBelow = 1;
|
int defaultNumberTopCardsToPlaceBelow = 1;
|
||||||
int defaultNumberBottomCards = 1;
|
int defaultNumberBottomCards = 1;
|
||||||
int defaultNumberDieRoll = 20;
|
int defaultNumberDieRoll = 20;
|
||||||
QString lastTokenName, lastTokenColor, lastTokenPT, lastTokenAnnotation;
|
|
||||||
bool lastTokenDestroy;
|
TokenInfo lastTokenInfo;
|
||||||
int lastTokenTableRow;
|
int lastTokenTableRow;
|
||||||
|
|
||||||
ServerInfo_User *userInfo;
|
ServerInfo_User *userInfo;
|
||||||
int id;
|
int id;
|
||||||
bool active;
|
bool active;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue