Laserlicht 3 mesiacov pred
rodič
commit
5f9cba59bc

+ 3 - 0
mapeditor/CMakeLists.txt

@@ -62,6 +62,7 @@ if(ENABLE_TEMPLATE_EDITOR)
 		templateeditor/mineselector.cpp
 		templateeditor/treasureselector.cpp
 		templateeditor/objectselector.cpp
+		templateeditor/townhintselector.cpp
 	)
 endif()
 
@@ -130,6 +131,7 @@ if(ENABLE_TEMPLATE_EDITOR)
 		templateeditor/mineselector.h
 		templateeditor/treasureselector.h
 		templateeditor/objectselector.h
+		templateeditor/townhintselector.h
 	)
 endif()
 
@@ -176,6 +178,7 @@ if(ENABLE_TEMPLATE_EDITOR)
 		templateeditor/mineselector.ui
 		templateeditor/treasureselector.ui
 		templateeditor/objectselector.ui
+		templateeditor/townhintselector.ui
 	)
 endif()
 

+ 3 - 3
mapeditor/templateeditor/objectselector.cpp

@@ -120,7 +120,7 @@ void ObjectSelector::fillBannedObjectCategories()
 
 		ui->tableWidgetBannedObjectCategories->setCellWidget(row, 0, combo);
 
-		auto deleteButton = new QPushButton("Delete");
+		auto deleteButton = new QPushButton(tr("Delete"));
 		ui->tableWidgetBannedObjectCategories->setCellWidget(row, 1, deleteButton);
 		connect(deleteButton, &QPushButton::clicked, this, [this, deleteButton]() {
 			for (int r = 0; r < ui->tableWidgetBannedObjectCategories->rowCount(); ++r) {
@@ -181,7 +181,7 @@ void ObjectSelector::fillBannedObjects()
 
 		ui->tableWidgetBannedObjects->setCellWidget(row, 0, combo);
 
-		auto deleteButton = new QPushButton("Delete");
+		auto deleteButton = new QPushButton(tr("Delete"));
 		ui->tableWidgetBannedObjects->setCellWidget(row, 1, deleteButton);
 		connect(deleteButton, &QPushButton::clicked, this, [this, deleteButton]() {
 			for (int r = 0; r < ui->tableWidgetBannedObjects->rowCount(); ++r) {
@@ -256,7 +256,7 @@ void ObjectSelector::fillCustomObjects()
         spinMaxPerZone->setValue(maxPerZone);
 		ui->tableWidgetObjects->setCellWidget(row, 3, spinMaxPerZone);
 
-		auto deleteButton = new QPushButton("Delete");
+		auto deleteButton = new QPushButton(tr("Delete"));
 		ui->tableWidgetObjects->setCellWidget(row, 4, deleteButton);
 		connect(deleteButton, &QPushButton::clicked, this, [this, deleteButton]() {
 			for (int r = 0; r < ui->tableWidgetObjects->rowCount(); ++r) {

+ 2 - 2
mapeditor/templateeditor/templateeditor.cpp

@@ -17,6 +17,7 @@
 #include "mineselector.h"
 #include "treasureselector.h"
 #include "objectselector.h"
+#include "townhintselector.h"
 #include "GeometryAlgorithm.h"
 
 #include "../helper.h"
@@ -1033,8 +1034,7 @@ void TemplateEditor::on_pushButtonBannedTowns_clicked()
 
 void TemplateEditor::on_pushButtonTownHints_clicked()
 {
-	//TODO: Implement dialog
-	QMessageBox::critical(this, tr("Error"), tr("Not implemented yet!"));
+	TownHintSelector::showTownHintSelector(templates[selectedTemplate]->getZones().at(selectedZone)->townHints);
 }
 
 void TemplateEditor::on_pushButtonAllowedMonsters_clicked()

+ 180 - 0
mapeditor/templateeditor/townhintselector.cpp

@@ -0,0 +1,180 @@
+/*
+ * townhintselector.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 "townhintselector.h"
+#include "ui_townhintselector.h"
+
+std::string joinVector(const std::vector<int>& vec, char delimiter) {
+    std::string result;
+    for (std::size_t i = 0; i < vec.size(); ++i) {
+        result += std::to_string(vec[i]);
+        if (i != vec.size() - 1) {
+            result += delimiter;
+        }
+    }
+    return result;
+}
+
+std::vector<int> splitStringToVector(const std::string& input, char delimiter) {
+    std::vector<int> result;
+    std::string temp;
+
+    for (std::size_t i = 0; i < input.size(); ++i) {
+        if (input[i] == delimiter) {
+            if (!temp.empty()) {
+                result.push_back(std::atoi(temp.c_str()));
+                temp.clear();
+            }
+        } else {
+            temp += input[i];
+        }
+    }
+
+    // Don't forget the last value
+    if (!temp.empty()) {
+        result.push_back(std::atoi(temp.c_str()));
+    }
+
+    return result;
+}
+
+enum modes { UNKNOWN, LIKE_ZONE, NOT_LIKE_ZONE, RELATED_TO_ZONE_TERRAIN };
+
+TownHintSelector::TownHintSelector(std::vector<rmg::ZoneOptions::CTownHints> & townHints) :
+	ui(new Ui::TownHintSelector),
+	townHints(townHints)
+{
+	ui->setupUi(this);
+
+	setWindowTitle(tr("Town hint Selector"));
+	
+	setWindowModality(Qt::ApplicationModal);
+
+	ui->tableWidgetTownHints->setColumnCount(3);
+	ui->tableWidgetTownHints->setRowCount(townHints.size() + 1);
+	ui->tableWidgetTownHints->setHorizontalHeaderLabels({tr("Type"), tr("Value"), tr("Action")});
+	
+	std::map<modes, QString> values = {
+		{ LIKE_ZONE, tr("Like Zone") },
+		{ NOT_LIKE_ZONE, tr("Not like zone (comma seperated)") },
+		{ RELATED_TO_ZONE_TERRAIN, tr("Related to zone terrain") }
+	};
+
+	auto addRow = [this, values](int mode, std::vector<TRmgTemplateZoneId> zones, int row){
+		QComboBox *combo = new QComboBox();
+		for(auto & item : values)
+    		combo->addItem(item.second, QVariant(static_cast<int>(item.first)));
+
+		int index = combo->findData(static_cast<int>(mode));
+		if (index != -1)
+			combo->setCurrentIndex(index);
+
+		ui->tableWidgetTownHints->setCellWidget(row, 0, combo);
+
+		QLineEdit *lineEdit = new QLineEdit;
+		QRegularExpression regex("[0-9,]*");
+		QRegularExpressionValidator *validator = new QRegularExpressionValidator(regex, lineEdit);
+		lineEdit->setValidator(validator);
+		lineEdit->setText(QString::fromStdString(joinVector(zones, ',')));
+		ui->tableWidgetTownHints->setCellWidget(row, 1, lineEdit);
+
+		auto deleteButton = new QPushButton(tr("Delete"));
+		ui->tableWidgetTownHints->setCellWidget(row, 2, deleteButton);
+		connect(deleteButton, &QPushButton::clicked, this, [this, deleteButton]() {
+			for (int r = 0; r < ui->tableWidgetTownHints->rowCount(); ++r) {
+				if (ui->tableWidgetTownHints->cellWidget(r, 2) == deleteButton) {
+					ui->tableWidgetTownHints->removeRow(r);
+					break;
+				}
+			}
+		});
+	};
+
+	for (int row = 0; row < townHints.size(); ++row)
+	{
+		int mode = UNKNOWN;
+		std::vector<TRmgTemplateZoneId> zones;
+		if(townHints[row].likeZone != rmg::ZoneOptions::NO_ZONE)
+		{
+			mode = LIKE_ZONE;
+			zones = { townHints[row].likeZone };
+		}
+		else if(!townHints[row].notLikeZone.empty())
+		{
+			mode = NOT_LIKE_ZONE;
+			zones = townHints[row].notLikeZone;
+			
+		}
+		else if(townHints[row].relatedToZoneTerrain != rmg::ZoneOptions::NO_ZONE)
+		{
+			mode = RELATED_TO_ZONE_TERRAIN;
+			zones = { townHints[row].relatedToZoneTerrain };
+			
+		}
+
+		assert(mode != UNKNOWN);
+
+		addRow(mode, zones, row);
+	}
+
+	auto addButton = new QPushButton("Add");
+	ui->tableWidgetTownHints->setCellWidget(ui->tableWidgetTownHints->rowCount() - 1, 2, addButton);
+	connect(addButton, &QPushButton::clicked, this, [this, addRow]() {
+		ui->tableWidgetTownHints->insertRow(ui->tableWidgetTownHints->rowCount() - 1);
+		addRow(LIKE_ZONE, std::vector<TRmgTemplateZoneId>({ 0 }), ui->tableWidgetTownHints->rowCount() - 2);
+	});
+
+	ui->tableWidgetTownHints->resizeColumnsToContents();
+	ui->tableWidgetTownHints->setColumnWidth(0, 300);
+	ui->tableWidgetTownHints->setColumnWidth(1, 100);
+
+	show();
+}
+
+void TownHintSelector::showTownHintSelector(std::vector<rmg::ZoneOptions::CTownHints> & townHints)
+{
+	auto * dialog = new TownHintSelector(townHints);
+	dialog->setAttribute(Qt::WA_DeleteOnClose);
+	dialog->exec();
+}
+
+void TownHintSelector::on_buttonBoxResult_accepted()
+{
+	townHints.clear();
+	for (int row = 0; row < ui->tableWidgetTownHints->rowCount() - 1; ++row)
+	{
+		auto mode = static_cast<modes>(static_cast<QComboBox *>(ui->tableWidgetTownHints->cellWidget(row, 0))->currentData().toInt());
+		auto text = static_cast<QLineEdit *>(ui->tableWidgetTownHints->cellWidget(row, 1))->text().toStdString();
+		auto values = splitStringToVector(text, ',');
+		
+		rmg::ZoneOptions::CTownHints hint;
+		switch (mode)
+		{
+		case LIKE_ZONE:
+			hint.likeZone = values.at(0);
+			break;
+		case NOT_LIKE_ZONE:
+			hint.notLikeZone = values;
+			break;
+		case RELATED_TO_ZONE_TERRAIN:
+			hint.relatedToZoneTerrain = values.at(0);
+			break;
+		}
+	}
+
+    close();
+}
+
+void TownHintSelector::on_buttonBoxResult_rejected()
+{
+    close();
+}

+ 37 - 0
mapeditor/templateeditor/townhintselector.h

@@ -0,0 +1,37 @@
+/*
+ * townhintselector.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/rmg/CRmgTemplate.h"
+
+namespace Ui {
+class TownHintSelector;
+}
+
+class TownHintSelector : public QDialog
+{
+	Q_OBJECT
+
+public:
+	explicit TownHintSelector(std::vector<rmg::ZoneOptions::CTownHints> & townHints);
+
+	static void showTownHintSelector(std::vector<rmg::ZoneOptions::CTownHints> & townHints);
+
+private slots:
+	void on_buttonBoxResult_accepted();
+    void on_buttonBoxResult_rejected();
+
+private:
+	Ui::TownHintSelector *ui;
+
+	std::vector<rmg::ZoneOptions::CTownHints> & townHints;
+};

+ 38 - 0
mapeditor/templateeditor/townhintselector.ui

@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>TownHintSelector</class>
+ <widget class="QDialog" name="townHintSelector">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>550</width>
+    <height>329</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Select Town hints</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <item>
+    <widget class="QLabel" name="labelTownHints">
+     <property name="text">
+      <string>Town hints</string>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QTableWidget" name="tableWidgetTownHints"/>
+   </item>
+   <item>
+    <widget class="QDialogButtonBox" name="buttonBoxResult">
+     <property name="standardButtons">
+      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>

+ 1 - 1
mapeditor/templateeditor/treasureselector.cpp

@@ -47,7 +47,7 @@ TreasureSelector::TreasureSelector(std::vector<CTreasureInfo> & treasures) :
         spinBoxDensity->setValue(density);
 		ui->tableWidgetTreasures->setCellWidget(row, 2, spinBoxDensity);
 
-		auto deleteButton = new QPushButton("Delete");
+		auto deleteButton = new QPushButton(tr("Delete"));
 		ui->tableWidgetTreasures->setCellWidget(row, 3, deleteButton);
 		connect(deleteButton, &QPushButton::clicked, this, [this, deleteButton]() {
 			for (int r = 0; r < ui->tableWidgetTreasures->rowCount(); ++r) {

+ 2 - 2
mapeditor/translation/german.ts

@@ -212,7 +212,7 @@
     <message>
         <location filename="../campaigneditor/campaignproperties.ui" line="120"/>
         <source>Regions Preset</source>
-        <translation>Regionan-Voreinstellung</translation>
+        <translation>Regionen-Voreinstellung</translation>
     </message>
     <message>
         <location filename="../campaigneditor/campaignproperties.ui" line="137"/>
@@ -3383,7 +3383,7 @@ Fügen Sie sie zu den erforderlichen Mods unter Karte → Allgemeine Einstellung
     <message>
         <location filename="../templateeditor/templateeditor.ui" line="1110"/>
         <source>Banned towns</source>
-        <translation>Verbotene STädte</translation>
+        <translation>Verbotene Städte</translation>
     </message>
     <message>
         <location filename="../templateeditor/templateeditor.ui" line="1117"/>