mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-12 09:04:53 -07:00
Refactor: clean up MessageLogWidget (#5870)
* use constants instead of static methods * make static methods static * remove unused variables
This commit is contained in:
parent
ca73033aea
commit
f7152befec
2 changed files with 30 additions and 77 deletions
|
|
@ -12,74 +12,39 @@
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
const QString &MessageLogWidget::tableConstant() const
|
static const QString TABLE_ZONE_NAME = "table";
|
||||||
{
|
static const QString GRAVE_ZONE_NAME = "grave";
|
||||||
static const QString constant("table");
|
static const QString EXILE_ZONE_NAME = "rfg";
|
||||||
return constant;
|
static const QString HAND_ZONE_NAME = "hand";
|
||||||
}
|
static const QString DECK_ZONE_NAME = "deck";
|
||||||
|
static const QString SIDEBOARD_ZONE_NAME = "sb";
|
||||||
|
static const QString STACK_ZONE_NAME = "stack";
|
||||||
|
|
||||||
const QString &MessageLogWidget::graveyardConstant() const
|
static QString sanitizeHtml(QString dirty)
|
||||||
{
|
|
||||||
static const QString constant("grave");
|
|
||||||
return constant;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QString &MessageLogWidget::exileConstant() const
|
|
||||||
{
|
|
||||||
static const QString constant("rfg");
|
|
||||||
return constant;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QString &MessageLogWidget::handConstant() const
|
|
||||||
{
|
|
||||||
static const QString constant("hand");
|
|
||||||
return constant;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QString &MessageLogWidget::deckConstant() const
|
|
||||||
{
|
|
||||||
static const QString constant("deck");
|
|
||||||
return constant;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QString &MessageLogWidget::sideboardConstant() const
|
|
||||||
{
|
|
||||||
static const QString constant("sb");
|
|
||||||
return constant;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QString &MessageLogWidget::stackConstant() const
|
|
||||||
{
|
|
||||||
static const QString constant("stack");
|
|
||||||
return constant;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString MessageLogWidget::sanitizeHtml(QString dirty) const
|
|
||||||
{
|
{
|
||||||
return dirty.replace("&", "&").replace("<", "<").replace(">", ">").replace("\"", """);
|
return dirty.replace("&", "&").replace("<", "<").replace(">", ">").replace("\"", """);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString MessageLogWidget::cardLink(const QString cardName) const
|
static QString cardLink(const QString &cardName)
|
||||||
{
|
{
|
||||||
return QString("<i><a href=\"card://%1\">%2</a></i>").arg(cardName).arg(cardName);
|
return QString("<i><a href=\"card://%1\">%2</a></i>").arg(cardName).arg(cardName);
|
||||||
}
|
}
|
||||||
|
|
||||||
QPair<QString, QString>
|
QPair<QString, QString> MessageLogWidget::getFromStr(CardZone *zone, QString cardName, int position, bool ownerChange)
|
||||||
MessageLogWidget::getFromStr(CardZone *zone, QString cardName, int position, bool ownerChange) const
|
|
||||||
{
|
{
|
||||||
bool cardNameContainsStartZone = false;
|
bool cardNameContainsStartZone = false;
|
||||||
QString fromStr;
|
QString fromStr;
|
||||||
QString zoneName = zone->getName();
|
QString zoneName = zone->getName();
|
||||||
|
|
||||||
if (zoneName == tableConstant()) {
|
if (zoneName == TABLE_ZONE_NAME) {
|
||||||
fromStr = tr(" from play");
|
fromStr = tr(" from play");
|
||||||
} else if (zoneName == graveyardConstant()) {
|
} else if (zoneName == GRAVE_ZONE_NAME) {
|
||||||
fromStr = tr(" from their graveyard");
|
fromStr = tr(" from their graveyard");
|
||||||
} else if (zoneName == exileConstant()) {
|
} else if (zoneName == EXILE_ZONE_NAME) {
|
||||||
fromStr = tr(" from exile");
|
fromStr = tr(" from exile");
|
||||||
} else if (zoneName == handConstant()) {
|
} else if (zoneName == HAND_ZONE_NAME) {
|
||||||
fromStr = tr(" from their hand");
|
fromStr = tr(" from their hand");
|
||||||
} else if (zoneName == deckConstant()) {
|
} else if (zoneName == DECK_ZONE_NAME) {
|
||||||
if (position == 0) {
|
if (position == 0) {
|
||||||
if (cardName.isEmpty()) {
|
if (cardName.isEmpty()) {
|
||||||
if (ownerChange) {
|
if (ownerChange) {
|
||||||
|
|
@ -117,16 +82,16 @@ MessageLogWidget::getFromStr(CardZone *zone, QString cardName, int position, boo
|
||||||
fromStr = tr(" from their library");
|
fromStr = tr(" from their library");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (zoneName == sideboardConstant()) {
|
} else if (zoneName == SIDEBOARD_ZONE_NAME) {
|
||||||
fromStr = tr(" from sideboard");
|
fromStr = tr(" from sideboard");
|
||||||
} else if (zoneName == stackConstant()) {
|
} else if (zoneName == STACK_ZONE_NAME) {
|
||||||
fromStr = tr(" from the stack");
|
fromStr = tr(" from the stack");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!cardNameContainsStartZone) {
|
if (!cardNameContainsStartZone) {
|
||||||
cardName.clear();
|
cardName.clear();
|
||||||
}
|
}
|
||||||
return QPair<QString, QString>(cardName, fromStr);
|
return {cardName, fromStr};
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageLogWidget::containerProcessingDone()
|
void MessageLogWidget::containerProcessingDone()
|
||||||
|
|
@ -291,9 +256,9 @@ void MessageLogWidget::logMoveCard(Player *player,
|
||||||
bool ownerChanged = startZone->getPlayer() != targetZone->getPlayer();
|
bool ownerChanged = startZone->getPlayer() != targetZone->getPlayer();
|
||||||
|
|
||||||
// do not log if moved within the same zone
|
// do not log if moved within the same zone
|
||||||
if ((startZoneName == tableConstant() && targetZoneName == tableConstant() && !ownerChanged) ||
|
if ((startZoneName == TABLE_ZONE_NAME && targetZoneName == TABLE_ZONE_NAME && !ownerChanged) ||
|
||||||
(startZoneName == handConstant() && targetZoneName == handConstant()) ||
|
(startZoneName == HAND_ZONE_NAME && targetZoneName == HAND_ZONE_NAME) ||
|
||||||
(startZoneName == exileConstant() && targetZoneName == exileConstant())) {
|
(startZoneName == EXILE_ZONE_NAME && targetZoneName == EXILE_ZONE_NAME)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -322,20 +287,20 @@ void MessageLogWidget::logMoveCard(Player *player,
|
||||||
|
|
||||||
QString finalStr;
|
QString finalStr;
|
||||||
bool usesNewX = false;
|
bool usesNewX = false;
|
||||||
if (targetZoneName == tableConstant()) {
|
if (targetZoneName == TABLE_ZONE_NAME) {
|
||||||
soundEngine->playSound("play_card");
|
soundEngine->playSound("play_card");
|
||||||
if (card->getFaceDown()) {
|
if (card->getFaceDown()) {
|
||||||
finalStr = tr("%1 puts %2 into play%3 face down.");
|
finalStr = tr("%1 puts %2 into play%3 face down.");
|
||||||
} else {
|
} else {
|
||||||
finalStr = tr("%1 puts %2 into play%3.");
|
finalStr = tr("%1 puts %2 into play%3.");
|
||||||
}
|
}
|
||||||
} else if (targetZoneName == graveyardConstant()) {
|
} else if (targetZoneName == GRAVE_ZONE_NAME) {
|
||||||
finalStr = tr("%1 puts %2%3 into their graveyard.");
|
finalStr = tr("%1 puts %2%3 into their graveyard.");
|
||||||
} else if (targetZoneName == exileConstant()) {
|
} else if (targetZoneName == EXILE_ZONE_NAME) {
|
||||||
finalStr = tr("%1 exiles %2%3.");
|
finalStr = tr("%1 exiles %2%3.");
|
||||||
} else if (targetZoneName == handConstant()) {
|
} else if (targetZoneName == HAND_ZONE_NAME) {
|
||||||
finalStr = tr("%1 moves %2%3 to their hand.");
|
finalStr = tr("%1 moves %2%3 to their hand.");
|
||||||
} else if (targetZoneName == deckConstant()) {
|
} else if (targetZoneName == DECK_ZONE_NAME) {
|
||||||
if (newX == -1) {
|
if (newX == -1) {
|
||||||
finalStr = tr("%1 puts %2%3 into their library.");
|
finalStr = tr("%1 puts %2%3 into their library.");
|
||||||
} else if (newX >= targetZone->getCards().size()) {
|
} else if (newX >= targetZone->getCards().size()) {
|
||||||
|
|
@ -347,9 +312,9 @@ void MessageLogWidget::logMoveCard(Player *player,
|
||||||
usesNewX = true;
|
usesNewX = true;
|
||||||
finalStr = tr("%1 puts %2%3 into their library %4 cards from the top.");
|
finalStr = tr("%1 puts %2%3 into their library %4 cards from the top.");
|
||||||
}
|
}
|
||||||
} else if (targetZoneName == sideboardConstant()) {
|
} else if (targetZoneName == SIDEBOARD_ZONE_NAME) {
|
||||||
finalStr = tr("%1 moves %2%3 to sideboard.");
|
finalStr = tr("%1 moves %2%3 to sideboard.");
|
||||||
} else if (targetZoneName == stackConstant()) {
|
} else if (targetZoneName == STACK_ZONE_NAME) {
|
||||||
soundEngine->playSound("play_card");
|
soundEngine->playSound("play_card");
|
||||||
finalStr = tr("%1 plays %2%3.");
|
finalStr = tr("%1 plays %2%3.");
|
||||||
}
|
}
|
||||||
|
|
@ -845,6 +810,6 @@ void MessageLogWidget::connectToPlayer(Player *player)
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageLogWidget::MessageLogWidget(TabSupervisor *_tabSupervisor, TabGame *_game, QWidget *parent)
|
MessageLogWidget::MessageLogWidget(TabSupervisor *_tabSupervisor, TabGame *_game, QWidget *parent)
|
||||||
: ChatView(_tabSupervisor, _game, true, parent), mulliganNumber(0), currentContext(MessageContext_None)
|
: ChatView(_tabSupervisor, _game, true, parent), currentContext(MessageContext_None)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,22 +21,10 @@ private:
|
||||||
MessageContext_Mulligan
|
MessageContext_Mulligan
|
||||||
};
|
};
|
||||||
|
|
||||||
int mulliganNumber;
|
|
||||||
Player *mulliganPlayer;
|
|
||||||
MessageContext currentContext;
|
MessageContext currentContext;
|
||||||
QString messagePrefix, messageSuffix;
|
QString messagePrefix, messageSuffix;
|
||||||
|
|
||||||
const QString &tableConstant() const;
|
static QPair<QString, QString> getFromStr(CardZone *zone, QString cardName, int position, bool ownerChange);
|
||||||
const QString &graveyardConstant() const;
|
|
||||||
const QString &exileConstant() const;
|
|
||||||
const QString &handConstant() const;
|
|
||||||
const QString &deckConstant() const;
|
|
||||||
const QString &sideboardConstant() const;
|
|
||||||
const QString &stackConstant() const;
|
|
||||||
|
|
||||||
QString sanitizeHtml(QString dirty) const;
|
|
||||||
QString cardLink(QString cardName) const;
|
|
||||||
QPair<QString, QString> getFromStr(CardZone *zone, QString cardName, int position, bool ownerChange) const;
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void containerProcessingDone();
|
void containerProcessingDone();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue