1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-12 02:28:11 +02:00

resource and playername translation

This commit is contained in:
Laserlicht 2025-01-03 00:01:42 +01:00
parent 3e44dd6a88
commit 4aed816b05
7 changed files with 44 additions and 15 deletions

View File

@ -20,6 +20,7 @@
#include "../lib/mapObjects/ObjectTemplate.h" #include "../lib/mapObjects/ObjectTemplate.h"
#include "../lib/mapping/CMap.h" #include "../lib/mapping/CMap.h"
#include "../lib/constants/StringConstants.h" #include "../lib/constants/StringConstants.h"
#include "../lib/texts/CGeneralTextHandler.h"
#include "townbuildingswidget.h" #include "townbuildingswidget.h"
#include "towneventswidget.h" #include "towneventswidget.h"
@ -913,8 +914,10 @@ QTableWidgetItem * Inspector::addProperty(const PlayerColor & value)
if(value == PlayerColor::NEUTRAL) if(value == PlayerColor::NEUTRAL)
str = QObject::tr("neutral"); str = QObject::tr("neutral");
MetaString playerStr;
playerStr.appendName(value);
if(value.isValidPlayer()) if(value.isValidPlayer())
str = QString::fromStdString(GameConstants::PLAYER_COLOR_NAMES[value]); str = QString::fromStdString(playerStr.toString());
auto * item = new QTableWidgetItem(str); auto * item = new QTableWidgetItem(str);
item->setFlags(Qt::NoItemFlags); item->setFlags(Qt::NoItemFlags);
@ -924,7 +927,9 @@ QTableWidgetItem * Inspector::addProperty(const PlayerColor & value)
QTableWidgetItem * Inspector::addProperty(const GameResID & 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->setFlags(Qt::NoItemFlags);
item->setData(Qt::UserRole, QVariant::fromValue(value.getNum())); item->setData(Qt::UserRole, QVariant::fromValue(value.getNum()));
return item; return item;
@ -1003,5 +1008,9 @@ OwnerDelegate::OwnerDelegate(MapController & controller, bool addNeutral)
options.push_back({QObject::tr("neutral"), QVariant::fromValue(PlayerColor::NEUTRAL.getNum()) }); options.push_back({QObject::tr("neutral"), QVariant::fromValue(PlayerColor::NEUTRAL.getNum()) });
for(int p = 0; p < controller.map()->players.size(); ++p) for(int p = 0; p < controller.map()->players.size(); ++p)
if(controller.map()->players[p].canAnyonePlay()) 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()) });
}
} }

View File

@ -43,7 +43,9 @@ QuestWidget::QuestWidget(MapController & _controller, CQuest & _sh, QWidget *par
ui->lResources->setRowCount(GameConstants::RESOURCE_QUANTITY - 1); ui->lResources->setRowCount(GameConstants::RESOURCE_QUANTITY - 1);
for(int i = 0; i < GameConstants::RESOURCE_QUANTITY - 1; ++i) 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)); item->setData(Qt::UserRole, QVariant::fromValue(i));
ui->lResources->setItem(i, 0, item); ui->lResources->setItem(i, 0, item);
auto * spinBox = new QSpinBox; auto * spinBox = new QSpinBox;
@ -126,7 +128,9 @@ QuestWidget::QuestWidget(MapController & _controller, CQuest & _sh, QWidget *par
//fill players //fill players
for(auto color = PlayerColor(0); color < PlayerColor::PLAYER_LIMIT; ++color) 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->setData(Qt::UserRole, QVariant::fromValue(color.getNum()));
item->setFlags(item->flags() | Qt::ItemIsUserCheckable); item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
item->setCheckState(Qt::Unchecked); item->setCheckState(Qt::Unchecked);

View File

@ -55,9 +55,11 @@ RewardsWidget::RewardsWidget(CMap & m, CRewardableObject & p, QWidget *parent) :
ui->lResources->setRowCount(GameConstants::RESOURCE_QUANTITY - 1); ui->lResources->setRowCount(GameConstants::RESOURCE_QUANTITY - 1);
for(int i = 0; i < GameConstants::RESOURCE_QUANTITY - 1; ++i) for(int i = 0; i < GameConstants::RESOURCE_QUANTITY - 1; ++i)
{ {
MetaString str;
str.appendName(GameResID(i));
for(auto * w : {ui->rResources, ui->lResources}) 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)); item->setData(Qt::UserRole, QVariant::fromValue(i));
w->setItem(i, 0, item); w->setItem(i, 0, item);
auto * spinBox = new QSpinBox; auto * spinBox = new QSpinBox;
@ -163,7 +165,9 @@ RewardsWidget::RewardsWidget(CMap & m, CRewardableObject & p, QWidget *parent) :
//fill players //fill players
for(auto color = PlayerColor(0); color < PlayerColor::PLAYER_LIMIT; ++color) 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->setData(Qt::UserRole, QVariant::fromValue(color.getNum()));
item->setFlags(item->flags() | Qt::ItemIsUserCheckable); item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
item->setCheckState(Qt::Unchecked); item->setCheckState(Qt::Unchecked);

View File

@ -67,8 +67,10 @@ void TownEventDialog::initPlayers()
auto playerList = params.value("players").toList(); auto playerList = params.value("players").toList();
for (int i = 0; i < PlayerColor::PLAYER_LIMIT_I; ++i) for (int i = 0; i < PlayerColor::PLAYER_LIMIT_I; ++i)
{ {
MetaString str;
str.appendName(PlayerColor(i));
bool isAffected = playerList.contains(toQString(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->setData(MapEditorRoles::PlayerIDRole, QVariant::fromValue(i));
item->setCheckState(isAffected ? Qt::Checked : Qt::Unchecked); item->setCheckState(isAffected ? Qt::Checked : Qt::Unchecked);
ui->playersAffected->addItem(item); ui->playersAffected->addItem(item);
@ -81,13 +83,15 @@ void TownEventDialog::initResources()
auto resourcesMap = params.value("resources").toMap(); auto resourcesMap = params.value("resources").toMap();
for (int i = 0; i < GameConstants::RESOURCE_QUANTITY; ++i) 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(); auto * item = new QTableWidgetItem();
item->setFlags(item->flags() & ~Qt::ItemIsEditable); item->setFlags(item->flags() & ~Qt::ItemIsEditable);
item->setText(name); item->setText(name);
ui->resourcesTable->setItem(i, 0, item); 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); auto * edit = new QSpinBox(ui->resourcesTable);
edit->setMaximum(i == GameResID::GOLD ? MAXIMUM_GOLD_CHANGE : MAXIMUM_RESOURCE_CHANGE); edit->setMaximum(i == GameResID::GOLD ? MAXIMUM_GOLD_CHANGE : MAXIMUM_RESOURCE_CHANGE);
edit->setMinimum(i == GameResID::GOLD ? -MAXIMUM_GOLD_CHANGE : -MAXIMUM_RESOURCE_CHANGE); edit->setMinimum(i == GameResID::GOLD ? -MAXIMUM_GOLD_CHANGE : -MAXIMUM_RESOURCE_CHANGE);

View File

@ -37,7 +37,9 @@ TimedEvent::TimedEvent(MapController & c, QListWidgetItem * t, QWidget *parent)
for(int i = 0; i < PlayerColor::PLAYER_LIMIT_I; ++i) for(int i = 0; i < PlayerColor::PLAYER_LIMIT_I; ++i)
{ {
bool isAffected = playerList.contains(toQString(PlayerColor(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->setData(Qt::UserRole, QVariant::fromValue(i));
item->setCheckState(isAffected ? Qt::Checked : Qt::Unchecked); item->setCheckState(isAffected ? Qt::Checked : Qt::Unchecked);
ui->playersAffected->addItem(item); ui->playersAffected->addItem(item);
@ -46,8 +48,10 @@ TimedEvent::TimedEvent(MapController & c, QListWidgetItem * t, QWidget *parent)
ui->resources->setRowCount(GameConstants::RESOURCE_QUANTITY); ui->resources->setRowCount(GameConstants::RESOURCE_QUANTITY);
for(int i = 0; i < GameConstants::RESOURCE_QUANTITY; ++i) for(int i = 0; i < GameConstants::RESOURCE_QUANTITY; ++i)
{ {
auto name = QString::fromStdString(GameConstants::RESOURCE_NAMES[i]); MetaString str;
int val = params.value("resources").toMap().value(name).toInt(); 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)); ui->resources->setItem(i, 0, new QTableWidgetItem(name));
auto nval = new QTableWidgetItem(QString::number(val)); auto nval = new QTableWidgetItem(QString::number(val));
nval->setFlags(nval->flags() | Qt::ItemIsEditable); nval->setFlags(nval->flags() | Qt::ItemIsEditable);

View File

@ -407,7 +407,9 @@ void VictoryConditions::on_victoryComboBox_currentIndexChanged(int index)
{ {
for(int resType = 0; resType < GameConstants::RESOURCE_QUANTITY; ++resType) 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)); victoryTypeWidget->addItem(resName, QVariant::fromValue(resType));
} }
} }

View File

@ -29,7 +29,9 @@ PlayerParams::PlayerParams(MapController & ctrl, int playerId, QWidget *parent)
{ {
if(i == playerId || !controller.map()->players[i].canAnyonePlay()) 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) if(i == playerId)
ui->playerColorCombo->setCurrentIndex(index); ui->playerColorCombo->setCurrentIndex(index);
++index; ++index;