浏览代码

Revert "Load template name from user settings"

This reverts commit 73cc606ee2df3cddd81e4371c01a88d5d1c17358.

# Conflicts:
#	lib/rmg/CRmgTemplateStorage.cpp
#	lib/rmg/CRmgTemplateStorage.h
#	mapeditor/windownewmap.cpp
nordsoft 3 年之前
父节点
当前提交
c348c1a053
共有 4 个文件被更改,包括 22 次插入45 次删除
  1. 2 12
      lib/rmg/CRmgTemplateStorage.cpp
  2. 2 4
      lib/rmg/CRmgTemplateStorage.h
  3. 18 26
      mapeditor/windownewmap.cpp
  4. 0 3
      mapeditor/windownewmap.h

+ 2 - 12
lib/rmg/CRmgTemplateStorage.cpp

@@ -32,8 +32,6 @@ void CRmgTemplateStorage::loadObject(std::string scope, std::string name, const
 		templates[fullKey].setId(name);
 		templates[fullKey].serializeJson(handler);
 		templates[fullKey].validate();
-
-		templatesByName[name] = templates[fullKey];
 	}
 	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
 }
 
-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())
 		return nullptr;
 	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 *> result;

+ 2 - 4
lib/rmg/CRmgTemplateStorage.h

@@ -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, size_t index) override;
 	
-	const CRmgTemplate * getTemplate(const std::string & templateFullId) const;
-	const CRmgTemplate * getTemplateByName(const std::string & templateName) const;
+	const CRmgTemplate* getTemplate(const std::string & templateName) const;
 	std::vector<const CRmgTemplate *> getTemplates() const;
 
 private:
-	std::map<std::string, CRmgTemplate> templates; //FIXME: doesn't IHandlerBase cover this?
-	std::map<std::string, CRmgTemplate> templatesByName;
+	std::map<std::string, CRmgTemplate> templates;
 };
 

+ 18 - 26
mapeditor/windownewmap.cpp

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

+ 0 - 3
mapeditor/windownewmap.h

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