From 2de863f64552b46540d6d657f0c6544614199f7d Mon Sep 17 00:00:00 2001 From: Rocangus Date: Sun, 17 May 2020 23:24:17 +0200 Subject: [PATCH] Spell Out Entire Counter Names With First Letter Capitalized (#3997) --- cockatrice/CMakeLists.txt | 1 + cockatrice/src/abstractcounter.cpp | 4 +++- cockatrice/src/messagelogwidget.cpp | 4 +++- cockatrice/src/translatecountername.cpp | 11 +++++++++++ cockatrice/src/translatecountername.h | 24 ++++++++++++++++++++++++ 5 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 cockatrice/src/translatecountername.cpp create mode 100644 cockatrice/src/translatecountername.h diff --git a/cockatrice/CMakeLists.txt b/cockatrice/CMakeLists.txt index 1c1a97e4..fea627f8 100644 --- a/cockatrice/CMakeLists.txt +++ b/cockatrice/CMakeLists.txt @@ -123,6 +123,7 @@ SET(cockatrice_SOURCES src/carddbparser/cockatricexml4.cpp src/filter_string.cpp src/customlineedit.cpp + src/translatecountername.cpp ${VERSION_STRING_CPP} ) diff --git a/cockatrice/src/abstractcounter.cpp b/cockatrice/src/abstractcounter.cpp index 3050803e..eff49ce2 100644 --- a/cockatrice/src/abstractcounter.cpp +++ b/cockatrice/src/abstractcounter.cpp @@ -5,6 +5,7 @@ #include "pb/command_set_counter.pb.h" #include "player.h" #include "settingscache.h" +#include "translatecountername.h" #include #include @@ -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); diff --git a/cockatrice/src/messagelogwidget.cpp b/cockatrice/src/messagelogwidget.cpp index e0e83b25..43f307a2 100644 --- a/cockatrice/src/messagelogwidget.cpp +++ b/cockatrice/src/messagelogwidget.cpp @@ -7,6 +7,7 @@ #include "pb/serverinfo_user.pb.h" #include "player.h" #include "soundengine.h" +#include "translatecountername.h" #include @@ -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("%1").arg(sanitizeHtml(counterName))) + .arg(QString("%1").arg(sanitizeHtml(counterDisplayName))) .arg(QString("%1").arg(value)) .arg(value > oldValue ? "+" : "") .arg(value - oldValue)); diff --git a/cockatrice/src/translatecountername.cpp b/cockatrice/src/translatecountername.cpp new file mode 100644 index 00000000..0f281388 --- /dev/null +++ b/cockatrice/src/translatecountername.cpp @@ -0,0 +1,11 @@ +#include "translatecountername.h" + +const QMap 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")}}; diff --git a/cockatrice/src/translatecountername.h b/cockatrice/src/translatecountername.h new file mode 100644 index 00000000..a098a8a7 --- /dev/null +++ b/cockatrice/src/translatecountername.h @@ -0,0 +1,24 @@ +#ifndef TRANSLATECOUNTERNAME_H +#define TRANSLATECOUNTERNAME_H + +#include +#include + +class TranslateCounterName +{ + Q_DECLARE_TR_FUNCTIONS(TranslateCounterName) + + static const QMap translated; + +public: + static QString getDisplayName(const QString &name) + { + if (translated.contains(name)) { + return tr(translated[name].toLatin1()); + } else { + return name; + } + } +}; + +#endif // TRANSLATECOUNTERNAME_H