Laserlicht 4 miesięcy temu
rodzic
commit
e819079c0a

+ 3 - 0
mapeditor/CMakeLists.txt

@@ -56,6 +56,7 @@ if(ENABLE_TEMPLATE_EDITOR)
 		templateeditor/templateview.cpp
 		templateeditor/graphicelements.cpp
 		templateeditor/algorithm.cpp
+		templateeditor/terrainselector.cpp
 	)
 endif()
 
@@ -118,6 +119,7 @@ if(ENABLE_TEMPLATE_EDITOR)
 		templateeditor/templateview.h
 		templateeditor/graphicelements.h
 		templateeditor/algorithm.h
+		templateeditor/terrainselector.h
 	)
 endif()
 
@@ -159,6 +161,7 @@ if(ENABLE_TEMPLATE_EDITOR)
 	set(editor_FORMS
 		${editor_FORMS}
 		templateeditor/templateeditor.ui
+		templateeditor/terrainselector.ui
 	)
 endif()
 

+ 3 - 4
mapeditor/templateeditor/templateeditor.cpp

@@ -11,6 +11,7 @@
 #include "templateeditor.h"
 #include "ui_templateeditor.h"
 #include "graphicelements.h"
+#include "terrainselector.h"
 #include "algorithm.h"
 
 #include "../helper.h"
@@ -1011,14 +1012,12 @@ void TemplateEditor::on_pushButtonConnectionAdd_clicked()
 
 void TemplateEditor::on_pushButtonOpenTerrainTypes_clicked()
 {
-	//TODO: Implement dialog
-	QMessageBox::critical(this, tr("Error"), tr("Not implemented yet!"));
+	TerrainSelector::showTerrainSelector(templates[selectedTemplate]->getZones().at(selectedZone)->terrainTypes);
 }
 
 void TemplateEditor::on_pushButtonOpenBannedTerrainTypes_clicked()
 {
-	//TODO: Implement dialog
-	QMessageBox::critical(this, tr("Error"), tr("Not implemented yet!"));
+	TerrainSelector::showTerrainSelector(templates[selectedTemplate]->getZones().at(selectedZone)->bannedTerrains);
 }
 
 void TemplateEditor::on_pushButtonAllowedTowns_clicked()

+ 64 - 0
mapeditor/templateeditor/terrainselector.cpp

@@ -0,0 +1,64 @@
+/*
+ * terrainselector.cpp, part of VCMI engine
+ *
+ * Authors: listed in file AUTHORS in main folder
+ *
+ * License: GNU General Public License v2.0 or later
+ * Full text of license available in license.txt file, in main folder
+ *
+ */
+
+#include "StdInc.h"
+
+#include "terrainselector.h"
+#include "ui_terrainselector.h"
+
+#include "../../lib/GameLibrary.h"
+#include "../../lib/TerrainHandler.h"
+
+TerrainSelector::TerrainSelector(std::set<TerrainId> & terrains) :
+	ui(new Ui::TerrainSelector),
+	terrainsSelected(terrains)
+{
+	ui->setupUi(this);
+
+	setWindowTitle(tr("Terrain Selector"));
+	
+	setWindowModality(Qt::ApplicationModal);
+
+	for(auto const & objectPtr : LIBRARY->terrainTypeHandler->objects)
+	{
+		auto * item = new QListWidgetItem(QString::fromStdString(objectPtr->getNameTranslated()));
+		item->setData(Qt::UserRole, QVariant::fromValue(objectPtr->getIndex()));
+		item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
+		item->setCheckState(terrains.count(objectPtr->getId()) ? Qt::Checked : Qt::Unchecked);
+		ui->listWidgetTerrains->addItem(item);
+	}
+
+	show();
+}
+
+void TerrainSelector::showTerrainSelector(std::set<TerrainId> & terrains)
+{
+	auto * dialog = new TerrainSelector(terrains);
+	dialog->setAttribute(Qt::WA_DeleteOnClose);
+	dialog->exec();
+}
+
+void TerrainSelector::on_buttonBoxResult_accepted()
+{
+	terrainsSelected.clear();
+	for(int i = 0; i < ui->listWidgetTerrains->count(); ++i)
+	{
+		auto * item = ui->listWidgetTerrains->item(i);
+		if(item->checkState() == Qt::Checked)
+			terrainsSelected.insert(item->data(Qt::UserRole).toInt());
+	}
+
+    close();
+}
+
+void TerrainSelector::on_buttonBoxResult_rejected()
+{
+    close();
+}

+ 37 - 0
mapeditor/templateeditor/terrainselector.h

@@ -0,0 +1,37 @@
+/*
+ * terrainselector.h, part of VCMI engine
+ *
+ * Authors: listed in file AUTHORS in main folder
+ *
+ * License: GNU General Public License v2.0 or later
+ * Full text of license available in license.txt file, in main folder
+ *
+ */
+#pragma once
+#include <QWidget>
+
+#include "../StdInc.h"
+#include "../../lib/constants/EntityIdentifiers.h"
+
+namespace Ui {
+class TerrainSelector;
+}
+
+class TerrainSelector : public QDialog
+{
+	Q_OBJECT
+
+public:
+	explicit TerrainSelector(std::set<TerrainId> & terrains);
+
+	static void showTerrainSelector(std::set<TerrainId> & terrains);
+
+private slots:
+	void on_buttonBoxResult_accepted();
+    void on_buttonBoxResult_rejected();
+
+private:
+	Ui::TerrainSelector *ui;
+
+	std::set<TerrainId> & terrainsSelected;
+};

+ 38 - 0
mapeditor/templateeditor/terrainselector.ui

@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>TerrainSelector</class>
+ <widget class="QDialog" name="TerrainSelector">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>499</width>
+    <height>350</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Scenario Properties</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <item>
+    <widget class="QLabel" name="labelTerrains">
+     <property name="text">
+      <string>Select Terrains</string>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QListWidget" name="listWidgetTerrains"/>
+   </item>
+   <item>
+    <widget class="QDialogButtonBox" name="buttonBoxResult">
+     <property name="standardButtons">
+      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>