Browse Source

Use ptr to identify rmg template

nordsoft 3 years ago
parent
commit
097fe2584b
4 changed files with 24 additions and 12 deletions
  1. 18 0
      mapeditor/StdInc.h
  2. 1 4
      mapeditor/inspector/inspector.cpp
  3. 1 4
      mapeditor/mainwindow.cpp
  4. 4 4
      mapeditor/windownewmap.cpp

+ 18 - 0
mapeditor/StdInc.h

@@ -13,6 +13,24 @@
 #include <QString>
 #include <QFile>
 
+using NumericPointer = unsigned long long;
+
+template<class Type>
+NumericPointer data_cast(Type * _pointer)
+{
+	static_assert(sizeof(Type *) == sizeof(NumericPointer),
+				  "Compilied for 64 bit arcitecture. Use NumericPointer = unsigned int");
+	return reinterpret_cast<NumericPointer>(_pointer);
+}
+
+template<class Type>
+Type * data_cast(NumericPointer _numeric)
+{
+	static_assert(sizeof(Type *) == sizeof(NumericPointer),
+				  "Compilied for 64 bit arcitecture. Use NumericPointer = unsigned int");
+	return reinterpret_cast<Type *>(_numeric);
+}
+
 inline QString pathToQString(const boost::filesystem::path & path)
 {
 #ifdef VCMI_WINDOWS

+ 1 - 4
mapeditor/inspector/inspector.cpp

@@ -573,10 +573,7 @@ void Inspector::setProperty(CGCreature * o, const QString & key, const QVariant
 //===============IMPLEMENT PROPERTY VALUE TYPE============================
 QTableWidgetItem * Inspector::addProperty(CGObjectInstance * value)
 {
-	using NumericPointer = unsigned long long;
-	static_assert(sizeof(CGObjectInstance *) == sizeof(NumericPointer),
-				  "Compilied for 64 bit arcitecture. Use NumericPointer = unsigned int");
-	return new QTableWidgetItem(QString::number(reinterpret_cast<NumericPointer>(value)));
+	return new QTableWidgetItem(QString::number(data_cast<CGObjectInstance>(value)));
 }
 
 QTableWidgetItem * Inspector::addProperty(Inspector::PropertyEditorPlaceholder value)

+ 1 - 4
mapeditor/mainwindow.cpp

@@ -924,10 +924,7 @@ void MainWindow::on_inspectorWidget_itemChanged(QTableWidgetItem *item)
 
 	//get identifier
 	auto identifier = tableWidget->item(0, 1)->text();
-	static_assert(sizeof(CGObjectInstance *) == sizeof(decltype(identifier.toLongLong())),
-			"Compilied for 64 bit arcitecture. Use .toInt() method");
-
-	CGObjectInstance * obj = reinterpret_cast<CGObjectInstance *>(identifier.toLongLong());
+	CGObjectInstance * obj = data_cast<CGObjectInstance>(identifier.toLongLong());
 
 	//get parameter name
 	auto param = tableWidget->item(r, c - 1)->text();

+ 4 - 4
mapeditor/windownewmap.cpp

@@ -350,8 +350,8 @@ void WindowNewMap::on_templateCombo_activated(int index)
 		mapGenOptions.setMapTemplate(nullptr);
 		return;
 	}
-
-	auto * templ = VLC->tplh->getTemplate(ui->templateCombo->currentText().toStdString());
+	
+	auto * templ = data_cast<const CRmgTemplate>(ui->templateCombo->currentData().toLongLong());
 	mapGenOptions.setMapTemplate(templ);
 }
 
@@ -390,11 +390,11 @@ void WindowNewMap::updateTemplateList()
 	if(templates.empty())
 		return;
 
-	ui->templateCombo->addItem("[default]");
+	ui->templateCombo->addItem("[default]", 0);
 
 	for(auto * templ : templates)
 	{
-		ui->templateCombo->addItem(QString::fromStdString(templ->getName()));
+		ui->templateCombo->addItem(QString::fromStdString(templ->getName()), data_cast(templ));
 	}
 
 	ui->templateCombo->setCurrentIndex(0);