1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Revert "Load template name from user settings"

This reverts commit 73cc606ee2.

# Conflicts:
#	lib/rmg/CRmgTemplateStorage.cpp
#	lib/rmg/CRmgTemplateStorage.h
#	mapeditor/windownewmap.cpp
This commit is contained in:
nordsoft 2022-09-19 02:46:01 +04:00
parent 3aa19f92a0
commit c348c1a053
4 changed files with 22 additions and 45 deletions

View File

@ -32,8 +32,6 @@ void CRmgTemplateStorage::loadObject(std::string scope, std::string name, const
templates[fullKey].setId(name); templates[fullKey].setId(name);
templates[fullKey].serializeJson(handler); templates[fullKey].serializeJson(handler);
templates[fullKey].validate(); templates[fullKey].validate();
templatesByName[name] = templates[fullKey];
} }
catch(const std::exception & e) catch(const std::exception & e)
{ {
@ -53,22 +51,14 @@ std::vector<JsonNode> CRmgTemplateStorage::loadLegacyData(size_t dataSize)
//it would be cool to load old rmg.txt files //it would be cool to load old rmg.txt files
} }
const CRmgTemplate * CRmgTemplateStorage::getTemplate(const std::string & templateFullId) const const CRmgTemplate * CRmgTemplateStorage::getTemplate(const std::string & templateName) const
{ {
auto iter = templates.find(templateFullId); auto iter = templates.find(templateName);
if(iter==templates.end()) if(iter==templates.end())
return nullptr; return nullptr;
return &iter->second; return &iter->second;
} }
const CRmgTemplate * CRmgTemplateStorage::getTemplateByName(const std::string & templateName) const
{
auto iter = templatesByName.find(templateName);
if(iter == templatesByName.end())
return nullptr;
return &iter->second;
}
std::vector<const CRmgTemplate *> CRmgTemplateStorage::getTemplates() const std::vector<const CRmgTemplate *> CRmgTemplateStorage::getTemplates() const
{ {
std::vector<const CRmgTemplate *> result; std::vector<const CRmgTemplate *> result;

View File

@ -29,12 +29,10 @@ public:
virtual void loadObject(std::string scope, std::string name, const JsonNode & data) override; virtual void loadObject(std::string scope, std::string name, const JsonNode & data) override;
virtual void loadObject(std::string scope, std::string name, const JsonNode & data, size_t index) override; virtual void loadObject(std::string scope, std::string name, const JsonNode & data, size_t index) override;
const CRmgTemplate * getTemplate(const std::string & templateFullId) const; const CRmgTemplate* getTemplate(const std::string & templateName) const;
const CRmgTemplate * getTemplateByName(const std::string & templateName) const;
std::vector<const CRmgTemplate *> getTemplates() const; std::vector<const CRmgTemplate *> getTemplates() const;
private: private:
std::map<std::string, CRmgTemplate> templates; //FIXME: doesn't IHandlerBase cover this? std::map<std::string, CRmgTemplate> templates;
std::map<std::string, CRmgTemplate> templatesByName;
}; };

View File

@ -24,19 +24,14 @@ WindowNewMap::WindowNewMap(QWidget *parent) :
loadUserSettings(); loadUserSettings();
ui->widthTxt->setInputMask("d00"); show();
ui->heightTxt->setInputMask("d00");
//setup initial parameters - can depend on loaded settings //setup initial parameters
mapGenOptions.setWidth(ui->widthTxt->text().toInt()); mapGenOptions.setWidth(ui->widthTxt->text().toInt());
mapGenOptions.setHeight(ui->heightTxt->text().toInt()); mapGenOptions.setHeight(ui->heightTxt->text().toInt());
bool twoLevel = ui->twoLevelCheck->isChecked(); bool twoLevel = ui->twoLevelCheck->isChecked();
mapGenOptions.setHasTwoLevels(twoLevel); mapGenOptions.setHasTwoLevels(twoLevel);
updateTemplateList(); updateTemplateList();
loadLastTemplate();
show();
} }
WindowNewMap::~WindowNewMap() WindowNewMap::~WindowNewMap()
@ -47,7 +42,7 @@ WindowNewMap::~WindowNewMap()
void WindowNewMap::loadUserSettings() void WindowNewMap::loadUserSettings()
{ {
//load last saved settings //load window settings
QSettings s(Ui::teamName, Ui::appName); QSettings s(Ui::teamName, Ui::appName);
auto width = s.value(newMapWidth); auto width = s.value(newMapWidth);
@ -113,22 +108,23 @@ void WindowNewMap::loadUserSettings()
ui->monsterOpt4->setChecked(true); break; ui->monsterOpt4->setChecked(true); break;
} }
} }
}
void WindowNewMap::loadLastTemplate()
{
//this requires already loaded template list
QSettings s(Ui::teamName, Ui::appName);
auto templateName = s.value(newMapTemplate); auto templateName = s.value(newMapTemplate);
if (templateName.isValid()) if (templateName.isValid())
{ {
auto qstr = templateName.toString(); updateTemplateList();
//Template might have been removed, then silently comboBox will be set to empty string auto* templ = VLC->tplh->getTemplate(templateName.toString().toStdString());
auto index = ui->templateCombo->findText(qstr); if (templ)
ui->templateCombo->setCurrentIndex(index); {
on_templateCombo_activated(index); ui->templateCombo->setCurrentText(templateName.toString());
//TODO: validate inside this method
mapGenOptions.setMapTemplate(templ);
}
else
{
//Display problem on status bar
}
} }
} }
@ -167,14 +163,10 @@ void WindowNewMap::saveUserSettings()
s.setValue(newMapMonsterStrength, static_cast<int>(monster)); s.setValue(newMapMonsterStrength, static_cast<int>(monster));
auto templateName = ui->templateCombo->currentText(); auto templateName = ui->templateCombo->currentText();
if (templateName.size() && templateName != defaultTemplate) if (templateName.size())
{ {
s.setValue(newMapTemplate, templateName); s.setValue(newMapTemplate, templateName);
} }
else
{
s.setValue(newMapTemplate, "");
}
} }
void WindowNewMap::on_cancelButton_clicked() void WindowNewMap::on_cancelButton_clicked()
@ -359,7 +351,7 @@ void WindowNewMap::on_templateCombo_activated(int index)
return; return;
} }
auto * templ = VLC->tplh->getTemplateByName(ui->templateCombo->currentText().toStdString()); auto * templ = VLC->tplh->getTemplate(ui->templateCombo->currentText().toStdString());
mapGenOptions.setMapTemplate(templ); mapGenOptions.setMapTemplate(templ);
} }
@ -398,7 +390,7 @@ void WindowNewMap::updateTemplateList()
if(templates.empty()) if(templates.empty())
return; return;
ui->templateCombo->addItem(defaultTemplate); ui->templateCombo->addItem("[default]");
for(auto * templ : templates) for(auto * templ : templates)
{ {

View File

@ -23,8 +23,6 @@ class WindowNewMap : public QDialog
const QString newMapMonsterStrength = "NewMapWindow/MonsterStrength"; const QString newMapMonsterStrength = "NewMapWindow/MonsterStrength";
const QString newMapTemplate = "NewMapWindow/Template"; const QString newMapTemplate = "NewMapWindow/Template";
const QString defaultTemplate = "[default]";
const int playerLimit = 8; const int playerLimit = 8;
const std::map<int, int> players const std::map<int, int> players
@ -85,7 +83,6 @@ private:
void updateTemplateList(); void updateTemplateList();
void loadUserSettings(); void loadUserSettings();
void loadLastTemplate();
void saveUserSettings(); void saveUserSettings();
private: private: