Laserlicht 4 miesięcy temu
rodzic
commit
6852a4e26a

+ 3 - 0
mapeditor/CMakeLists.txt

@@ -57,6 +57,7 @@ if(ENABLE_TEMPLATE_EDITOR)
 		templateeditor/graphicelements.cpp
 		templateeditor/graphicelements.cpp
 		templateeditor/algorithm.cpp
 		templateeditor/algorithm.cpp
 		templateeditor/terrainselector.cpp
 		templateeditor/terrainselector.cpp
+		templateeditor/factionselector.cpp
 	)
 	)
 endif()
 endif()
 
 
@@ -120,6 +121,7 @@ if(ENABLE_TEMPLATE_EDITOR)
 		templateeditor/graphicelements.h
 		templateeditor/graphicelements.h
 		templateeditor/algorithm.h
 		templateeditor/algorithm.h
 		templateeditor/terrainselector.h
 		templateeditor/terrainselector.h
+		templateeditor/factionselector.h
 	)
 	)
 endif()
 endif()
 
 
@@ -162,6 +164,7 @@ if(ENABLE_TEMPLATE_EDITOR)
 		${editor_FORMS}
 		${editor_FORMS}
 		templateeditor/templateeditor.ui
 		templateeditor/templateeditor.ui
 		templateeditor/terrainselector.ui
 		templateeditor/terrainselector.ui
+		templateeditor/factionselector.ui
 	)
 	)
 endif()
 endif()
 
 

+ 64 - 0
mapeditor/templateeditor/factionselector.cpp

@@ -0,0 +1,64 @@
+/*
+ * factionselector.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 "factionselector.h"
+#include "ui_factionselector.h"
+
+#include "../../lib/GameLibrary.h"
+#include "../../lib/entities/faction/CTownHandler.h"
+
+FactionSelector::FactionSelector(std::set<FactionID> & factions) :
+	ui(new Ui::FactionSelector),
+	factionsSelected(factions)
+{
+	ui->setupUi(this);
+
+	setWindowTitle(tr("Faction Selector"));
+	
+	setWindowModality(Qt::ApplicationModal);
+
+	for(auto const & objectPtr : LIBRARY->townh->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(factions.count(objectPtr->getId()) ? Qt::Checked : Qt::Unchecked);
+		ui->listWidgetFactions->addItem(item);
+	}
+
+	show();
+}
+
+void FactionSelector::showFactionSelector(std::set<FactionID> & factions)
+{
+	auto * dialog = new FactionSelector(factions);
+	dialog->setAttribute(Qt::WA_DeleteOnClose);
+	dialog->exec();
+}
+
+void FactionSelector::on_buttonBoxResult_accepted()
+{
+	factionsSelected.clear();
+	for(int i = 0; i < ui->listWidgetFactions->count(); ++i)
+	{
+		auto * item = ui->listWidgetFactions->item(i);
+		if(item->checkState() == Qt::Checked)
+			factionsSelected.insert(FactionID(item->data(Qt::UserRole).toInt()));
+	}
+
+    close();
+}
+
+void FactionSelector::on_buttonBoxResult_rejected()
+{
+    close();
+}

+ 37 - 0
mapeditor/templateeditor/factionselector.h

@@ -0,0 +1,37 @@
+/*
+ * factionselector.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 FactionSelector;
+}
+
+class FactionSelector : public QDialog
+{
+	Q_OBJECT
+
+public:
+	explicit FactionSelector(std::set<FactionID> & factions);
+
+	static void showFactionSelector(std::set<FactionID> & factions);
+
+private slots:
+	void on_buttonBoxResult_accepted();
+    void on_buttonBoxResult_rejected();
+
+private:
+	Ui::FactionSelector *ui;
+
+	std::set<FactionID> & factionsSelected;
+};

+ 38 - 0
mapeditor/templateeditor/factionselector.ui

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

+ 5 - 8
mapeditor/templateeditor/templateeditor.cpp

@@ -12,6 +12,7 @@
 #include "ui_templateeditor.h"
 #include "ui_templateeditor.h"
 #include "graphicelements.h"
 #include "graphicelements.h"
 #include "terrainselector.h"
 #include "terrainselector.h"
+#include "factionselector.h"
 #include "algorithm.h"
 #include "algorithm.h"
 
 
 #include "../helper.h"
 #include "../helper.h"
@@ -1022,14 +1023,12 @@ void TemplateEditor::on_pushButtonOpenBannedTerrainTypes_clicked()
 
 
 void TemplateEditor::on_pushButtonAllowedTowns_clicked()
 void TemplateEditor::on_pushButtonAllowedTowns_clicked()
 {
 {
-	//TODO: Implement dialog
-	QMessageBox::critical(this, tr("Error"), tr("Not implemented yet!"));
+	FactionSelector::showFactionSelector(templates[selectedTemplate]->getZones().at(selectedZone)->townTypes);
 }
 }
 
 
 void TemplateEditor::on_pushButtonBannedTowns_clicked()
 void TemplateEditor::on_pushButtonBannedTowns_clicked()
 {
 {
-	//TODO: Implement dialog
-	QMessageBox::critical(this, tr("Error"), tr("Not implemented yet!"));
+	FactionSelector::showFactionSelector(templates[selectedTemplate]->getZones().at(selectedZone)->bannedTownTypes);
 }
 }
 
 
 void TemplateEditor::on_pushButtonTownHints_clicked()
 void TemplateEditor::on_pushButtonTownHints_clicked()
@@ -1040,14 +1039,12 @@ void TemplateEditor::on_pushButtonTownHints_clicked()
 
 
 void TemplateEditor::on_pushButtonAllowedMonsters_clicked()
 void TemplateEditor::on_pushButtonAllowedMonsters_clicked()
 {
 {
-	//TODO: Implement dialog
-	QMessageBox::critical(this, tr("Error"), tr("Not implemented yet!"));
+	FactionSelector::showFactionSelector(templates[selectedTemplate]->getZones().at(selectedZone)->monsterTypes);
 }
 }
 
 
 void TemplateEditor::on_pushButtonBannedMonsters_clicked()
 void TemplateEditor::on_pushButtonBannedMonsters_clicked()
 {
 {
-	//TODO: Implement dialog
-	QMessageBox::critical(this, tr("Error"), tr("Not implemented yet!"));
+	FactionSelector::showFactionSelector(templates[selectedTemplate]->getZones().at(selectedZone)->bannedMonsters);
 }
 }
 
 
 void TemplateEditor::on_pushButtonTreasure_clicked()
 void TemplateEditor::on_pushButtonTreasure_clicked()

+ 1 - 1
mapeditor/templateeditor/terrainselector.ui

@@ -11,7 +11,7 @@
    </rect>
    </rect>
   </property>
   </property>
   <property name="windowTitle">
   <property name="windowTitle">
-   <string>Scenario Properties</string>
+   <string>Select Terrains</string>
   </property>
   </property>
   <layout class="QVBoxLayout" name="verticalLayout">
   <layout class="QVBoxLayout" name="verticalLayout">
    <item>
    <item>