From 4aed816b0562825f56d80aafa01f7dcce687bbf0 Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Fri, 3 Jan 2025 00:01:42 +0100 Subject: [PATCH] resource and playername translation --- mapeditor/inspector/inspector.cpp | 15 ++++++++++++--- mapeditor/inspector/questwidget.cpp | 8 ++++++-- mapeditor/inspector/rewardswidget.cpp | 8 ++++++-- mapeditor/inspector/towneventdialog.cpp | 10 +++++++--- mapeditor/mapsettings/timedevent.cpp | 10 +++++++--- mapeditor/mapsettings/victoryconditions.cpp | 4 +++- mapeditor/playerparams.cpp | 4 +++- 7 files changed, 44 insertions(+), 15 deletions(-) diff --git a/mapeditor/inspector/inspector.cpp b/mapeditor/inspector/inspector.cpp index d6618f711..218ad55fd 100644 --- a/mapeditor/inspector/inspector.cpp +++ b/mapeditor/inspector/inspector.cpp @@ -20,6 +20,7 @@ #include "../lib/mapObjects/ObjectTemplate.h" #include "../lib/mapping/CMap.h" #include "../lib/constants/StringConstants.h" +#include "../lib/texts/CGeneralTextHandler.h" #include "townbuildingswidget.h" #include "towneventswidget.h" @@ -913,8 +914,10 @@ QTableWidgetItem * Inspector::addProperty(const PlayerColor & value) if(value == PlayerColor::NEUTRAL) str = QObject::tr("neutral"); + MetaString playerStr; + playerStr.appendName(value); if(value.isValidPlayer()) - str = QString::fromStdString(GameConstants::PLAYER_COLOR_NAMES[value]); + str = QString::fromStdString(playerStr.toString()); auto * item = new QTableWidgetItem(str); item->setFlags(Qt::NoItemFlags); @@ -924,7 +927,9 @@ QTableWidgetItem * Inspector::addProperty(const PlayerColor & value) QTableWidgetItem * Inspector::addProperty(const GameResID & value) { - auto * item = new QTableWidgetItem(QString::fromStdString(GameConstants::RESOURCE_NAMES[value.toEnum()])); + MetaString str; + str.appendName(value); + auto * item = new QTableWidgetItem(QString::fromStdString(str.toString())); item->setFlags(Qt::NoItemFlags); item->setData(Qt::UserRole, QVariant::fromValue(value.getNum())); return item; @@ -1003,5 +1008,9 @@ OwnerDelegate::OwnerDelegate(MapController & controller, bool addNeutral) options.push_back({QObject::tr("neutral"), QVariant::fromValue(PlayerColor::NEUTRAL.getNum()) }); for(int p = 0; p < controller.map()->players.size(); ++p) if(controller.map()->players[p].canAnyonePlay()) - options.push_back({QString::fromStdString(GameConstants::PLAYER_COLOR_NAMES[p]), QVariant::fromValue(PlayerColor(p).getNum()) }); + { + MetaString str; + str.appendName(PlayerColor(p)); + options.push_back({QString::fromStdString(str.toString()), QVariant::fromValue(PlayerColor(p).getNum()) }); + } } diff --git a/mapeditor/inspector/questwidget.cpp b/mapeditor/inspector/questwidget.cpp index 1a14d7fa1..ff84f8ea7 100644 --- a/mapeditor/inspector/questwidget.cpp +++ b/mapeditor/inspector/questwidget.cpp @@ -43,7 +43,9 @@ QuestWidget::QuestWidget(MapController & _controller, CQuest & _sh, QWidget *par ui->lResources->setRowCount(GameConstants::RESOURCE_QUANTITY - 1); for(int i = 0; i < GameConstants::RESOURCE_QUANTITY - 1; ++i) { - auto * item = new QTableWidgetItem(QString::fromStdString(GameConstants::RESOURCE_NAMES[i])); + MetaString str; + str.appendName(GameResID(i)); + auto * item = new QTableWidgetItem(QString::fromStdString(str.toString())); item->setData(Qt::UserRole, QVariant::fromValue(i)); ui->lResources->setItem(i, 0, item); auto * spinBox = new QSpinBox; @@ -126,7 +128,9 @@ QuestWidget::QuestWidget(MapController & _controller, CQuest & _sh, QWidget *par //fill players for(auto color = PlayerColor(0); color < PlayerColor::PLAYER_LIMIT; ++color) { - auto * item = new QListWidgetItem(QString::fromStdString(GameConstants::PLAYER_COLOR_NAMES[color.getNum()])); + MetaString str; + str.appendName(color); + auto * item = new QListWidgetItem(QString::fromStdString(str.toString())); item->setData(Qt::UserRole, QVariant::fromValue(color.getNum())); item->setFlags(item->flags() | Qt::ItemIsUserCheckable); item->setCheckState(Qt::Unchecked); diff --git a/mapeditor/inspector/rewardswidget.cpp b/mapeditor/inspector/rewardswidget.cpp index 614846d2b..0e3e5bb4f 100644 --- a/mapeditor/inspector/rewardswidget.cpp +++ b/mapeditor/inspector/rewardswidget.cpp @@ -55,9 +55,11 @@ RewardsWidget::RewardsWidget(CMap & m, CRewardableObject & p, QWidget *parent) : ui->lResources->setRowCount(GameConstants::RESOURCE_QUANTITY - 1); for(int i = 0; i < GameConstants::RESOURCE_QUANTITY - 1; ++i) { + MetaString str; + str.appendName(GameResID(i)); for(auto * w : {ui->rResources, ui->lResources}) { - auto * item = new QTableWidgetItem(QString::fromStdString(GameConstants::RESOURCE_NAMES[i])); + auto * item = new QTableWidgetItem(QString::fromStdString(str.toString())); item->setData(Qt::UserRole, QVariant::fromValue(i)); w->setItem(i, 0, item); auto * spinBox = new QSpinBox; @@ -163,7 +165,9 @@ RewardsWidget::RewardsWidget(CMap & m, CRewardableObject & p, QWidget *parent) : //fill players for(auto color = PlayerColor(0); color < PlayerColor::PLAYER_LIMIT; ++color) { - auto * item = new QListWidgetItem(QString::fromStdString(GameConstants::PLAYER_COLOR_NAMES[color.getNum()])); + MetaString str; + str.appendName(color); + auto * item = new QListWidgetItem(QString::fromStdString(str.toString())); item->setData(Qt::UserRole, QVariant::fromValue(color.getNum())); item->setFlags(item->flags() | Qt::ItemIsUserCheckable); item->setCheckState(Qt::Unchecked); diff --git a/mapeditor/inspector/towneventdialog.cpp b/mapeditor/inspector/towneventdialog.cpp index 475c42edc..6ab833be3 100644 --- a/mapeditor/inspector/towneventdialog.cpp +++ b/mapeditor/inspector/towneventdialog.cpp @@ -67,8 +67,10 @@ void TownEventDialog::initPlayers() auto playerList = params.value("players").toList(); for (int i = 0; i < PlayerColor::PLAYER_LIMIT_I; ++i) { + MetaString str; + str.appendName(PlayerColor(i)); bool isAffected = playerList.contains(toQString(PlayerColor(i))); - auto * item = new QListWidgetItem(QString::fromStdString(GameConstants::PLAYER_COLOR_NAMES[i])); + auto * item = new QListWidgetItem(QString::fromStdString(str.toString())); item->setData(MapEditorRoles::PlayerIDRole, QVariant::fromValue(i)); item->setCheckState(isAffected ? Qt::Checked : Qt::Unchecked); ui->playersAffected->addItem(item); @@ -81,13 +83,15 @@ void TownEventDialog::initResources() auto resourcesMap = params.value("resources").toMap(); for (int i = 0; i < GameConstants::RESOURCE_QUANTITY; ++i) { - auto name = QString::fromStdString(GameConstants::RESOURCE_NAMES[i]); + MetaString str; + str.appendName(GameResID(i)); + auto name = QString::fromStdString(str.toString()); auto * item = new QTableWidgetItem(); item->setFlags(item->flags() & ~Qt::ItemIsEditable); item->setText(name); ui->resourcesTable->setItem(i, 0, item); - int val = resourcesMap.value(name).toInt(); + int val = resourcesMap.value(QString::fromStdString(GameConstants::RESOURCE_NAMES[i])).toInt(); auto * edit = new QSpinBox(ui->resourcesTable); edit->setMaximum(i == GameResID::GOLD ? MAXIMUM_GOLD_CHANGE : MAXIMUM_RESOURCE_CHANGE); edit->setMinimum(i == GameResID::GOLD ? -MAXIMUM_GOLD_CHANGE : -MAXIMUM_RESOURCE_CHANGE); diff --git a/mapeditor/mapsettings/timedevent.cpp b/mapeditor/mapsettings/timedevent.cpp index 39b983295..5cc14afe6 100644 --- a/mapeditor/mapsettings/timedevent.cpp +++ b/mapeditor/mapsettings/timedevent.cpp @@ -37,7 +37,9 @@ TimedEvent::TimedEvent(MapController & c, QListWidgetItem * t, QWidget *parent) for(int i = 0; i < PlayerColor::PLAYER_LIMIT_I; ++i) { bool isAffected = playerList.contains(toQString(PlayerColor(i))); - auto * item = new QListWidgetItem(QString::fromStdString(GameConstants::PLAYER_COLOR_NAMES[i])); + MetaString str; + str.appendName(PlayerColor(i)); + auto * item = new QListWidgetItem(QString::fromStdString(str.toString())); item->setData(Qt::UserRole, QVariant::fromValue(i)); item->setCheckState(isAffected ? Qt::Checked : Qt::Unchecked); ui->playersAffected->addItem(item); @@ -46,8 +48,10 @@ TimedEvent::TimedEvent(MapController & c, QListWidgetItem * t, QWidget *parent) ui->resources->setRowCount(GameConstants::RESOURCE_QUANTITY); for(int i = 0; i < GameConstants::RESOURCE_QUANTITY; ++i) { - auto name = QString::fromStdString(GameConstants::RESOURCE_NAMES[i]); - int val = params.value("resources").toMap().value(name).toInt(); + MetaString str; + str.appendName(GameResID(i)); + auto name = QString::fromStdString(str.toString()); + int val = params.value("resources").toMap().value(QString::fromStdString(GameConstants::RESOURCE_NAMES[i])).toInt(); ui->resources->setItem(i, 0, new QTableWidgetItem(name)); auto nval = new QTableWidgetItem(QString::number(val)); nval->setFlags(nval->flags() | Qt::ItemIsEditable); diff --git a/mapeditor/mapsettings/victoryconditions.cpp b/mapeditor/mapsettings/victoryconditions.cpp index d77e2c135..19feff60c 100644 --- a/mapeditor/mapsettings/victoryconditions.cpp +++ b/mapeditor/mapsettings/victoryconditions.cpp @@ -407,7 +407,9 @@ void VictoryConditions::on_victoryComboBox_currentIndexChanged(int index) { for(int resType = 0; resType < GameConstants::RESOURCE_QUANTITY; ++resType) { - auto resName = QString::fromStdString(GameConstants::RESOURCE_NAMES[resType]); + MetaString str; + str.appendName(GameResID(resType)); + auto resName = QString::fromStdString(str.toString()); victoryTypeWidget->addItem(resName, QVariant::fromValue(resType)); } } diff --git a/mapeditor/playerparams.cpp b/mapeditor/playerparams.cpp index bbf32ad56..95ebbcbac 100644 --- a/mapeditor/playerparams.cpp +++ b/mapeditor/playerparams.cpp @@ -29,7 +29,9 @@ PlayerParams::PlayerParams(MapController & ctrl, int playerId, QWidget *parent) { if(i == playerId || !controller.map()->players[i].canAnyonePlay()) { - ui->playerColorCombo->addItem(QString::fromStdString(GameConstants::PLAYER_COLOR_NAMES[i]), QVariant(i)); + MetaString str; + str.appendName(PlayerColor(i)); + ui->playerColorCombo->addItem(QString::fromStdString(str.toString()), QVariant(i)); if(i == playerId) ui->playerColorCombo->setCurrentIndex(index); ++index;