mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-09 15:54:47 -07:00
minor cleanups and log improvements
This commit is contained in:
parent
52b8a5b0e7
commit
2148005bd1
18 changed files with 215 additions and 306 deletions
|
|
@ -1,160 +1,168 @@
|
|||
#include "messagelogwidget.h"
|
||||
#include "game.h"
|
||||
#include <QScrollBar>
|
||||
#include "player.h"
|
||||
|
||||
QString MessageLogWidget::sanitizeHtml(QString dirty)
|
||||
{
|
||||
return dirty
|
||||
.replace("&", "&")
|
||||
.replace("<", "<")
|
||||
.replace(">", ">");
|
||||
}
|
||||
|
||||
void MessageLogWidget::logConnecting(QString hostname)
|
||||
{
|
||||
appendPlainText(tr("Connecting to %1...").arg(hostname));
|
||||
append(tr("Connecting to %1...").arg(sanitizeHtml(hostname)));
|
||||
}
|
||||
|
||||
void MessageLogWidget::logConnected(const QStringList WelcomeMsg)
|
||||
{
|
||||
appendPlainText(tr("Connected."));
|
||||
append(tr("Connected."));
|
||||
|
||||
QStringListIterator i(WelcomeMsg);
|
||||
while (i.hasNext())
|
||||
appendPlainText(i.next());
|
||||
append(i.next());
|
||||
}
|
||||
|
||||
void MessageLogWidget::logDisconnected()
|
||||
{
|
||||
appendPlainText(tr("Disconnected from server."));
|
||||
append(tr("Disconnected from server."));
|
||||
}
|
||||
|
||||
void MessageLogWidget::logSocketError(const QString &errorString)
|
||||
{
|
||||
appendPlainText(errorString);
|
||||
append(sanitizeHtml(errorString));
|
||||
}
|
||||
|
||||
void MessageLogWidget::logServerError(ServerResponse response)
|
||||
{
|
||||
switch (response) {
|
||||
case RespPassword: appendPlainText(tr("Invalid password.")); break;
|
||||
case RespPassword: append(tr("Invalid password.")); break;
|
||||
default: ;
|
||||
}
|
||||
}
|
||||
|
||||
void MessageLogWidget::logPlayerListReceived(QStringList players)
|
||||
{
|
||||
appendPlainText("---");
|
||||
appendPlainText(tr("You have joined the game. Player list:"));
|
||||
append("---");
|
||||
append(tr("You have joined the game. Player list:"));
|
||||
for (int i = 0; i < players.size(); i++)
|
||||
appendPlainText(players.at(i));
|
||||
appendPlainText("---");
|
||||
append(sanitizeHtml(players.at(i)));
|
||||
append("---");
|
||||
}
|
||||
|
||||
void MessageLogWidget::logJoin(QString playerName)
|
||||
void MessageLogWidget::logJoin(Player *player)
|
||||
{
|
||||
appendPlainText(tr("%1 has joined the game").arg(playerName));
|
||||
append(tr("%1 has joined the game").arg(sanitizeHtml(player->getName())));
|
||||
}
|
||||
|
||||
void MessageLogWidget::logLeave(QString playerName)
|
||||
void MessageLogWidget::logLeave(Player *player)
|
||||
{
|
||||
appendPlainText(tr("%1 has left the game").arg(playerName));
|
||||
append(tr("%1 has left the game").arg(sanitizeHtml(player->getName())));
|
||||
}
|
||||
|
||||
void MessageLogWidget::logReadyStart(QString playerName)
|
||||
void MessageLogWidget::logReadyStart(Player *player)
|
||||
{
|
||||
appendPlainText(tr("%1 is ready to start a new game.").arg(playerName));
|
||||
append(tr("%1 is ready to start a new game.").arg(sanitizeHtml(player->getName())));
|
||||
}
|
||||
|
||||
void MessageLogWidget::logGameStart()
|
||||
{
|
||||
appendPlainText(tr("Game has started."));
|
||||
append(tr("Game has started."));
|
||||
}
|
||||
|
||||
void MessageLogWidget::logSay(QString playerName, QString message)
|
||||
void MessageLogWidget::logSay(Player *player, QString message)
|
||||
{
|
||||
appendHtml(QString("<font color=\"red\">%1:</font> %2").arg(playerName).arg(message));
|
||||
append(QString("<font color=\"red\">%1:</font> %2").arg(sanitizeHtml(player->getName())).arg(sanitizeHtml(message)));
|
||||
}
|
||||
|
||||
void MessageLogWidget::logShuffle(QString playerName)
|
||||
void MessageLogWidget::logShuffle(Player *player)
|
||||
{
|
||||
appendPlainText(tr("%1 shuffles his/her library").arg(playerName));
|
||||
append(tr("%1 shuffles his/her library").arg(sanitizeHtml(player->getName())));
|
||||
}
|
||||
|
||||
void MessageLogWidget::logRollDice(QString playerName, int sides, int roll)
|
||||
void MessageLogWidget::logRollDice(Player *player, int sides, int roll)
|
||||
{
|
||||
appendPlainText(tr("%1 rolled a %2 with a %3-sided dice").arg(playerName).arg(roll).arg(sides));
|
||||
append(tr("%1 rolled a %2 with a %3-sided dice").arg(sanitizeHtml(player->getName())).arg(roll).arg(sides));
|
||||
}
|
||||
|
||||
void MessageLogWidget::logDraw(QString playerName, int number)
|
||||
void MessageLogWidget::logDraw(Player *player, int number)
|
||||
{
|
||||
if (number == 1)
|
||||
appendPlainText(tr("%1 draws a card").arg(playerName));
|
||||
append(tr("%1 draws a card").arg(sanitizeHtml(player->getName())));
|
||||
else
|
||||
appendPlainText(tr("%1 draws %2 cards").arg(playerName).arg(number));
|
||||
append(tr("%1 draws %2 cards").arg(sanitizeHtml(player->getName())).arg(number));
|
||||
}
|
||||
|
||||
void MessageLogWidget::logMoveCard(QString playerName, QString cardName, QString startZone, QString targetZone)
|
||||
void MessageLogWidget::logMoveCard(Player *player, QString cardName, QString startZone, QString targetZone)
|
||||
{
|
||||
appendPlainText(tr("%1 moves %2 from %3 to %4").arg(playerName).arg(cardName).arg(startZone).arg(targetZone));
|
||||
append(tr("%1 moves <font color=\"blue\">%2</font> from %3 to %4").arg(sanitizeHtml(player->getName())).arg(cardName).arg(startZone).arg(targetZone));
|
||||
}
|
||||
|
||||
void MessageLogWidget::logCreateToken(QString playerName, QString cardName)
|
||||
void MessageLogWidget::logCreateToken(Player *player, QString cardName)
|
||||
{
|
||||
appendPlainText(tr("%1 creates token: %2").arg(playerName).arg(cardName));
|
||||
append(tr("%1 creates token: <font color=\"blue\">%2</font>").arg(sanitizeHtml(player->getName())).arg(cardName));
|
||||
}
|
||||
|
||||
void MessageLogWidget::logSetCardCounters(QString playerName, QString cardName, int value, int oldValue)
|
||||
void MessageLogWidget::logSetCardCounters(Player *player, QString cardName, int value, int oldValue)
|
||||
{
|
||||
if (value > oldValue)
|
||||
appendPlainText(tr("%1 places %2 counters on %3 (now %4)").arg(playerName).arg(value - oldValue).arg(cardName).arg(value));
|
||||
append(tr("%1 places %2 counters on <font color=\"blue\">%3</font> (now %4)").arg(sanitizeHtml(player->getName())).arg(value - oldValue).arg(cardName).arg(value));
|
||||
else
|
||||
appendPlainText(tr("%1 removes %2 counters from %3 (now %4)").arg(playerName).arg(oldValue - value).arg(cardName).arg(value));
|
||||
append(tr("%1 removes %2 counters from <font color=\"blue\">%3</font> (now %4)").arg(sanitizeHtml(player->getName())).arg(oldValue - value).arg(cardName).arg(value));
|
||||
}
|
||||
|
||||
void MessageLogWidget::logSetTapped(QString playerName, QString cardName, bool tapped)
|
||||
void MessageLogWidget::logSetTapped(Player *player, QString cardName, bool tapped)
|
||||
{
|
||||
if (cardName == "-1")
|
||||
cardName = tr("his permanents");
|
||||
appendPlainText(tr("%1 %2 %3").arg(playerName).arg(tapped ? "taps" : "untaps").arg(cardName));
|
||||
append(tr("%1 %2 <font color=\"blue\">%3</blue>").arg(sanitizeHtml(player->getName())).arg(tapped ? "taps" : "untaps").arg(cardName));
|
||||
}
|
||||
|
||||
void MessageLogWidget::logSetCounter(QString playerName, QString counterName, int value, int oldValue)
|
||||
void MessageLogWidget::logSetCounter(Player *player, QString counterName, int value, int oldValue)
|
||||
{
|
||||
appendPlainText(tr("%1 sets counter \"%2\" to %3 (%4%5)").arg(playerName).arg(counterName).arg(value).arg(value > oldValue ? "+" : "").arg(value - oldValue));
|
||||
append(tr("%1 sets counter \"%2\" to %3 (%4%5)").arg(sanitizeHtml(player->getName())).arg(counterName).arg(value).arg(value > oldValue ? "+" : "").arg(value - oldValue));
|
||||
}
|
||||
|
||||
void MessageLogWidget::logSetDoesntUntap(QString playerName, QString cardName, bool doesntUntap)
|
||||
void MessageLogWidget::logSetDoesntUntap(Player *player, QString cardName, bool doesntUntap)
|
||||
{
|
||||
if (doesntUntap)
|
||||
appendPlainText(tr("%1 sets %2 to not untap normally.").arg(playerName).arg(cardName));
|
||||
append(tr("%1 sets <font color=\"blue\">%2</font> to not untap normally.").arg(sanitizeHtml(player->getName())).arg(cardName));
|
||||
else
|
||||
appendPlainText(tr("%1 sets %2 to untap normally.").arg(playerName).arg(cardName));
|
||||
append(tr("%1 sets <font color=\"blue\">%2</font> to untap normally.").arg(sanitizeHtml(player->getName())).arg(cardName));
|
||||
}
|
||||
|
||||
void MessageLogWidget::logDumpZone(QString playerName, QString zoneName, QString zoneOwner, int numberCards)
|
||||
void MessageLogWidget::logDumpZone(Player *player, QString zoneName, QString zoneOwner, int numberCards)
|
||||
{
|
||||
if (numberCards)
|
||||
appendPlainText(tr("%1 is looking at the top %2 cards of %3's %4").arg(playerName).arg(numberCards).arg(zoneOwner).arg(zoneName));
|
||||
append(tr("%1 is looking at the top %2 cards of %3's %4").arg(sanitizeHtml(player->getName())).arg(numberCards).arg(zoneOwner).arg(zoneName));
|
||||
else
|
||||
appendPlainText(tr("%1 is looking at %2's %3").arg(playerName).arg(zoneOwner).arg(zoneName));
|
||||
append(tr("%1 is looking at %2's %3").arg(sanitizeHtml(player->getName())).arg(zoneOwner).arg(zoneName));
|
||||
}
|
||||
|
||||
|
||||
void MessageLogWidget::connectToGame(Game *game)
|
||||
{
|
||||
connect(game, SIGNAL(logPlayerListReceived(QStringList)), this, SLOT(logPlayerListReceived(QStringList)));
|
||||
connect(game, SIGNAL(logJoin(QString)), this, SLOT(logJoin(QString)));
|
||||
connect(game, SIGNAL(logLeave(QString)), this, SLOT(logLeave(QString)));
|
||||
connect(game, SIGNAL(logReadyStart(QString)), this, SLOT(logReadyStart(QString)));
|
||||
connect(game, SIGNAL(logJoin(Player *)), this, SLOT(logJoin(Player *)));
|
||||
connect(game, SIGNAL(logLeave(Player *)), this, SLOT(logLeave(Player *)));
|
||||
connect(game, SIGNAL(logReadyStart(Player *)), this, SLOT(logReadyStart(Player *)));
|
||||
connect(game, SIGNAL(logGameStart()), this, SLOT(logGameStart()));
|
||||
connect(game, SIGNAL(logSay(QString, QString)), this, SLOT(logSay(QString, QString)));
|
||||
connect(game, SIGNAL(logShuffle(QString)), this, SLOT(logShuffle(QString)));
|
||||
connect(game, SIGNAL(logRollDice(QString, int, int)), this, SLOT(logRollDice(QString, int, int)));
|
||||
connect(game, SIGNAL(logDraw(QString, int)), this, SLOT(logDraw(QString, int)));
|
||||
connect(game, SIGNAL(logMoveCard(QString, QString, QString, QString)), this, SLOT(logMoveCard(QString, QString, QString, QString)));
|
||||
connect(game, SIGNAL(logCreateToken(QString, QString)), this, SLOT(logCreateToken(QString, QString)));
|
||||
connect(game, SIGNAL(logSetCardCounters(QString, QString, int, int)), this, SLOT(logSetCardCounters(QString, QString, int, int)));
|
||||
connect(game, SIGNAL(logSetTapped(QString, QString, bool)), this, SLOT(logSetTapped(QString, QString, bool)));
|
||||
connect(game, SIGNAL(logSetCounter(QString, QString, int, int)), this, SLOT(logSetCounter(QString, QString, int, int)));
|
||||
connect(game, SIGNAL(logSetDoesntUntap(QString, QString, bool)), this, SLOT(logSetDoesntUntap(QString, QString, bool)));
|
||||
connect(game, SIGNAL(logDumpZone(QString, QString, QString, int)), this, SLOT(logDumpZone(QString, QString, QString, int)));
|
||||
connect(game, SIGNAL(logSay(Player *, QString)), this, SLOT(logSay(Player *, QString)));
|
||||
connect(game, SIGNAL(logShuffle(Player *)), this, SLOT(logShuffle(Player *)));
|
||||
connect(game, SIGNAL(logRollDice(Player *, int, int)), this, SLOT(logRollDice(Player *, int, int)));
|
||||
connect(game, SIGNAL(logDraw(Player *, int)), this, SLOT(logDraw(Player *, int)));
|
||||
connect(game, SIGNAL(logMoveCard(Player *, QString, QString, QString)), this, SLOT(logMoveCard(Player *, QString, QString, QString)));
|
||||
connect(game, SIGNAL(logCreateToken(Player *, QString)), this, SLOT(logCreateToken(Player *, QString)));
|
||||
connect(game, SIGNAL(logSetCardCounters(Player *, QString, int, int)), this, SLOT(logSetCardCounters(Player *, QString, int, int)));
|
||||
connect(game, SIGNAL(logSetTapped(Player *, QString, bool)), this, SLOT(logSetTapped(Player *, QString, bool)));
|
||||
connect(game, SIGNAL(logSetCounter(Player *, QString, int, int)), this, SLOT(logSetCounter(Player *, QString, int, int)));
|
||||
connect(game, SIGNAL(logSetDoesntUntap(Player *, QString, bool)), this, SLOT(logSetDoesntUntap(Player *, QString, bool)));
|
||||
connect(game, SIGNAL(logDumpZone(Player *, QString, QString, int)), this, SLOT(logDumpZone(Player *, QString, QString, int)));
|
||||
}
|
||||
|
||||
MessageLogWidget::MessageLogWidget(QWidget *parent)
|
||||
: QPlainTextEdit(parent)
|
||||
: QTextEdit(parent)
|
||||
{
|
||||
setReadOnly(true);
|
||||
QFont f;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue