Laserlicht 4 mesi fa
parent
commit
824a748373

+ 3 - 0
mapeditor/CMakeLists.txt

@@ -58,6 +58,7 @@ if(ENABLE_TEMPLATE_EDITOR)
 		templateeditor/algorithm.cpp
 		templateeditor/terrainselector.cpp
 		templateeditor/factionselector.cpp
+		templateeditor/mineselector.cpp
 	)
 endif()
 
@@ -122,6 +123,7 @@ if(ENABLE_TEMPLATE_EDITOR)
 		templateeditor/algorithm.h
 		templateeditor/terrainselector.h
 		templateeditor/factionselector.h
+		templateeditor/mineselector.h
 	)
 endif()
 
@@ -165,6 +167,7 @@ if(ENABLE_TEMPLATE_EDITOR)
 		templateeditor/templateeditor.ui
 		templateeditor/terrainselector.ui
 		templateeditor/factionselector.ui
+		templateeditor/mineselector.ui
 	)
 endif()
 

+ 69 - 0
mapeditor/templateeditor/mineselector.cpp

@@ -0,0 +1,69 @@
+/*
+ * mineselector.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 "mineselector.h"
+#include "ui_mineselector.h"
+
+#include "../../lib/GameLibrary.h"
+#include "../../lib/texts/CGeneralTextHandler.h"
+
+auto resources = std::vector<EGameResID>{EGameResID::GOLD, EGameResID::WOOD, EGameResID::MERCURY, EGameResID::ORE, EGameResID::SULFUR, EGameResID::CRYSTAL, EGameResID::GEMS};
+
+MineSelector::MineSelector(std::map<TResource, ui16> & mines) :
+	ui(new Ui::MineSelector),
+	minesSelected(mines)
+{
+	ui->setupUi(this);
+
+	setWindowTitle(tr("Mine Selector"));
+	
+	setWindowModality(Qt::ApplicationModal);
+
+	ui->tableWidgetMines->setColumnCount(2);
+	ui->tableWidgetMines->setRowCount(resources.size());
+	ui->tableWidgetMines->setHorizontalHeaderLabels({tr("Resource"), tr("Mines")});
+	for (int row = 0; row < resources.size(); ++row)
+	{
+		auto name = LIBRARY->generaltexth->translate(TextIdentifier("core.restypes", resources[row].getNum()).get());
+		auto label = new QLabel(QString::fromStdString(name));
+        label->setAlignment(Qt::AlignCenter);
+		ui->tableWidgetMines->setCellWidget(row, 0, label);
+
+		auto spinBox = new QSpinBox();
+        spinBox->setRange(0, 100);
+        spinBox->setValue(mines[resources[row]]);
+		ui->tableWidgetMines->setCellWidget(row, 1, spinBox);
+	}
+	ui->tableWidgetMines->resizeColumnsToContents();
+
+	show();
+}
+
+void MineSelector::showMineSelector(std::map<TResource, ui16> & mines)
+{
+	auto * dialog = new MineSelector(mines);
+	dialog->setAttribute(Qt::WA_DeleteOnClose);
+	dialog->exec();
+}
+
+void MineSelector::on_buttonBoxResult_accepted()
+{
+	for (int row = 0; row < resources.size(); ++row)
+		minesSelected[resources[row]] = static_cast<QSpinBox *>(ui->tableWidgetMines->cellWidget(row, 1))->value();
+
+    close();
+}
+
+void MineSelector::on_buttonBoxResult_rejected()
+{
+    close();
+}

+ 37 - 0
mapeditor/templateeditor/mineselector.h

@@ -0,0 +1,37 @@
+/*
+ * mineselector.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/ResourceSet.h"
+
+namespace Ui {
+class MineSelector;
+}
+
+class MineSelector : public QDialog
+{
+	Q_OBJECT
+
+public:
+	explicit MineSelector(std::map<TResource, ui16> & mines);
+
+	static void showMineSelector(std::map<TResource, ui16> & mines);
+
+private slots:
+	void on_buttonBoxResult_accepted();
+    void on_buttonBoxResult_rejected();
+
+private:
+	Ui::MineSelector *ui;
+
+	std::map<TResource, ui16> & minesSelected;
+};

+ 38 - 0
mapeditor/templateeditor/mineselector.ui

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

+ 3 - 2
mapeditor/templateeditor/templateeditor.cpp

@@ -13,6 +13,7 @@
 #include "graphicelements.h"
 #include "terrainselector.h"
 #include "factionselector.h"
+#include "mineselector.h"
 #include "algorithm.h"
 
 #include "../helper.h"
@@ -1055,8 +1056,8 @@ void TemplateEditor::on_pushButtonTreasure_clicked()
 
 void TemplateEditor::on_pushButtonMines_clicked()
 {
-	//TODO: Implement dialog
-	QMessageBox::critical(this, tr("Error"), tr("Not implemented yet!"));
+	MineSelector::showMineSelector(templates[selectedTemplate]->getZones().at(selectedZone)->mines);
+	updateZoneCards(selectedZone);
 }
 
 void TemplateEditor::on_pushButtonCustomObjects_clicked()

+ 0 - 1
mapeditor/templateeditor/templateeditor.h

@@ -19,7 +19,6 @@
 class CRmgTemplate;
 class CardItem;
 class LineItem;
-class ZoneOptions;
 namespace rmg {
 class ZoneOptions;
 }