Spell Out Entire Counter Names With First Letter Capitalized (#3997)

This commit is contained in:
Rocangus 2020-05-17 23:24:17 +02:00 committed by GitHub
parent dc8603596d
commit 2de863f645
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 42 additions and 2 deletions

View file

@ -123,6 +123,7 @@ SET(cockatrice_SOURCES
src/carddbparser/cockatricexml4.cpp
src/filter_string.cpp
src/customlineedit.cpp
src/translatecountername.cpp
${VERSION_STRING_CPP}
)

View file

@ -5,6 +5,7 @@
#include "pb/command_set_counter.pb.h"
#include "player.h"
#include "settingscache.h"
#include "translatecountername.h"
#include <QAction>
#include <QApplication>
@ -32,7 +33,8 @@ AbstractCounter::AbstractCounter(Player *_player,
shortcutActive = false;
if (player->getLocalOrJudge()) {
menu = new TearOffMenu(name);
QString displayName = TranslateCounterName::getDisplayName(_name);
menu = new TearOffMenu(displayName);
aSet = new QAction(this);
connect(aSet, SIGNAL(triggered()), this, SLOT(setCounter()));
menu->addAction(aSet);

View file

@ -7,6 +7,7 @@
#include "pb/serverinfo_user.pb.h"
#include "player.h"
#include "soundengine.h"
#include "translatecountername.h"
#include <utility>
@ -681,9 +682,10 @@ void MessageLogWidget::logSetCounter(Player *player, QString counterName, int va
soundEngine->playSound("life_change");
}
QString counterDisplayName = TranslateCounterName::getDisplayName(counterName);
appendHtmlServerMessage(tr("%1 sets counter %2 to %3 (%4%5).")
.arg(sanitizeHtml(player->getName()))
.arg(QString("<font class=\"blue\">%1</font>").arg(sanitizeHtml(counterName)))
.arg(QString("<font class=\"blue\">%1</font>").arg(sanitizeHtml(counterDisplayName)))
.arg(QString("<font class=\"blue\">%1</font>").arg(value))
.arg(value > oldValue ? "+" : "")
.arg(value - oldValue));

View file

@ -0,0 +1,11 @@
#include "translatecountername.h"
const QMap<QString, QString> TranslateCounterName::translated = {
{"life", QT_TRANSLATE_NOOP("TranslateCounterName", "Life")},
{"w", QT_TRANSLATE_NOOP("TranslateCounterName", "White")},
{"u", QT_TRANSLATE_NOOP("TranslateCounterName", "Blue")},
{"b", QT_TRANSLATE_NOOP("TranslateCounterName", "Black")},
{"r", QT_TRANSLATE_NOOP("TranslateCounterName", "Red")},
{"g", QT_TRANSLATE_NOOP("TranslateCounterName", "Green")},
{"x", QT_TRANSLATE_NOOP("TranslateCounterName", "Colorless")},
{"storm", QT_TRANSLATE_NOOP("TranslateCounterName", "Other")}};

View file

@ -0,0 +1,24 @@
#ifndef TRANSLATECOUNTERNAME_H
#define TRANSLATECOUNTERNAME_H
#include <QString>
#include <QtCore>
class TranslateCounterName
{
Q_DECLARE_TR_FUNCTIONS(TranslateCounterName)
static const QMap<QString, QString> translated;
public:
static QString getDisplayName(const QString &name)
{
if (translated.contains(name)) {
return tr(translated[name].toLatin1());
} else {
return name;
}
}
};
#endif // TRANSLATECOUNTERNAME_H