1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-02-03 13:01:33 +02:00

code improvement

This commit is contained in:
Andrey Filipenkov 2022-09-26 16:37:31 +03:00
parent 4205701f96
commit f0b909f772
6 changed files with 29 additions and 45 deletions

View File

@ -44,10 +44,6 @@ CSavingScreen::CSavingScreen()
buttonStart->assignedKeys.insert(SDLK_RETURN);
}
CSavingScreen::~CSavingScreen()
{
}
const CMapInfo * CSavingScreen::getMapInfo()
{
return localMi.get();

View File

@ -27,7 +27,6 @@ public:
std::shared_ptr<CMapInfo> localMi;
CSavingScreen();
~CSavingScreen();
void changeSelection(std::shared_ptr<CMapInfo> to);
void saveGame();

View File

@ -562,10 +562,11 @@ void CSystemOptionsWindow::selectGameRes()
std::vector<std::string> items;
const JsonNode & texts = CGI->generaltexth->localizedTexts["systemOptions"]["resolutionMenu"];
for( config::CConfigHandler::GuiOptionsMap::value_type& value : conf.guiOptions)
for(const auto & it : conf.guiOptions)
{
std::string resX = boost::lexical_cast<std::string>(value.first.first);
std::string resY = boost::lexical_cast<std::string>(value.first.second);
const auto & resolution = it.first;
std::string resX = boost::lexical_cast<std::string>(resolution.first);
std::string resY = boost::lexical_cast<std::string>(resolution.second);
items.push_back(resX + 'x' + resY);
}

View File

@ -16,7 +16,7 @@ static QVariantMap JsonToMap(const JsonMap & json)
QVariantMap map;
for(auto & entry : json)
{
map.insert(QString::fromUtf8(entry.first.c_str()), JsonUtils::toVariant(entry.second));
map.insert(QString::fromStdString(entry.first), JsonUtils::toVariant(entry.second));
}
return map;
}
@ -60,22 +60,16 @@ QVariant toVariant(const JsonNode & node)
{
switch(node.getType())
{
break;
case JsonNode::JsonType::DATA_NULL:
return QVariant();
break;
case JsonNode::JsonType::DATA_BOOL:
return QVariant(node.Bool());
break;
case JsonNode::JsonType::DATA_FLOAT:
return QVariant(node.Float());
break;
case JsonNode::JsonType::DATA_STRING:
return QVariant(QString::fromUtf8(node.String().c_str()));
break;
return QVariant(QString::fromStdString(node.String()));
case JsonNode::JsonType::DATA_VECTOR:
return JsonToList(node.Vector());
break;
case JsonNode::JsonType::DATA_STRUCT:
return JsonToMap(node.Struct());
}
@ -85,19 +79,15 @@ QVariant toVariant(const JsonNode & node)
QVariant JsonFromFile(QString filename)
{
QFile file(filename);
file.open(QFile::ReadOnly);
auto data = file.readAll();
if(!file.open(QFile::ReadOnly))
{
logGlobal->error("Failed to open file %s. Reason: %s", qUtf8Printable(filename), qUtf8Printable(file.errorString()));
return {};
}
if(data.size() == 0)
{
logGlobal->error("Failed to open file %s", filename.toUtf8().data());
return QVariant();
}
else
{
JsonNode node(data.data(), data.size());
return toVariant(node);
}
const auto data = file.readAll();
JsonNode node(data.data(), data.size());
return toVariant(node);
}
JsonNode toJson(QVariant object)

View File

@ -291,7 +291,7 @@ bool CModManager::doInstallMod(QString modname, QString archivePath)
bool CModManager::doUninstallMod(QString modname)
{
ResourceID resID(std::string("Mods/") + modname.toUtf8().data(), EResType::DIRECTORY);
ResourceID resID(std::string("Mods/") + modname.toStdString(), EResType::DIRECTORY);
// Get location of the mod, in case-insensitive way
QString modDir = pathToQString(*CResourceHandler::get()->getResourceName(resID));
@ -300,7 +300,7 @@ bool CModManager::doUninstallMod(QString modname)
QDir modFullDir(modDir);
if(!removeModDir(modDir))
return addError(modname, "Mod is located in protected directory, plase remove it manually:\n" + modFullDir.absolutePath());
return addError(modname, "Mod is located in protected directory, please remove it manually:\n" + modFullDir.absolutePath());
CResourceHandler::get("initial")->updateFilteredFiles([](const std::string &){ return true; });
loadMods();

View File

@ -19,6 +19,14 @@
#include "../../lib/CConfigHandler.h"
#include "../../lib/VCMIDirs.h"
namespace
{
QString resolutionToString(const QSize & resolution)
{
return QString{"%1x%2"}.arg(resolution.width()).arg(resolution.height());
}
}
/// List of encoding which can be selected from Launcher.
/// Note that it is possible to specify enconding manually in settings.json
static const std::string knownEncodingsList[] = //TODO: remove hardcode
@ -39,12 +47,7 @@ void CSettingsView::setDisplayList()
QStringList list;
for (const auto screen : QGuiApplication::screens())
{
QString string;
const auto & rect = screen->geometry();
QTextStream(&string) << screen->name() << " - " << rect.width() << "x" << rect.height();
list << string;
}
list << QString{"%1 - %2"}.arg(screen->name(), resolutionToString(screen->size()));
if(list.count() < 2)
{
@ -79,15 +82,10 @@ void CSettingsView::loadSettings()
ui->checkBoxFullScreen->setChecked(settings["video"]["realFullscreen"].Bool());
#endif
int friendlyAIIndex = ui->comboBoxFriendlyAI->findText(QString::fromUtf8(settings["server"]["friendlyAI"].String().c_str()));
int neutralAIIndex = ui->comboBoxNeutralAI->findText(QString::fromUtf8(settings["server"]["neutralAI"].String().c_str()));
int enemyAIIndex = ui->comboBoxEnemyAI->findText(QString::fromUtf8(settings["server"]["enemyAI"].String().c_str()));
int playerAIIndex = ui->comboBoxPlayerAI->findText(QString::fromUtf8(settings["server"]["playerAI"].String().c_str()));
ui->comboBoxFriendlyAI->setCurrentIndex(friendlyAIIndex);
ui->comboBoxNeutralAI->setCurrentIndex(neutralAIIndex);
ui->comboBoxEnemyAI->setCurrentIndex(enemyAIIndex);
ui->comboBoxPlayerAI->setCurrentIndex(playerAIIndex);
ui->comboBoxFriendlyAI->setCurrentText(QString::fromStdString(settings["server"]["friendlyAI"].String()));
ui->comboBoxNeutralAI->setCurrentText(QString::fromStdString(settings["server"]["neutralAI"].String()));
ui->comboBoxEnemyAI->setCurrentText(QString::fromStdString(settings["server"]["enemyAI"].String()));
ui->comboBoxPlayerAI->setCurrentText(QString::fromStdString(settings["server"]["playerAI"].String()));
ui->spinBoxNetworkPort->setValue(settings["server"]["port"].Integer());