mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Add map converter
This commit is contained in:
parent
9631176e58
commit
53dadc6dc3
@ -313,7 +313,7 @@ void MainWindow::initializeMap(bool isNew)
|
||||
onPlayersChanged();
|
||||
}
|
||||
|
||||
bool MainWindow::openMap(const QString & filenameSelect)
|
||||
std::unique_ptr<CMap> MainWindow::openMapInternal(const QString & filenameSelect)
|
||||
{
|
||||
QFileInfo fi(filenameSelect);
|
||||
std::string fname = fi.fileName().toStdString();
|
||||
@ -327,14 +327,9 @@ bool MainWindow::openMap(const QString & filenameSelect)
|
||||
CResourceHandler::addFilesystem("local", "mapEditor", mapEditorFilesystem);
|
||||
|
||||
if(!CResourceHandler::get("mapEditor")->existsResource(resId))
|
||||
{
|
||||
QMessageBox::warning(this, tr("Failed to open map"), tr("Cannot open map from this folder"));
|
||||
return false;
|
||||
}
|
||||
throw std::runtime_error("Cannot open map from this folder");
|
||||
|
||||
CMapService mapService;
|
||||
try
|
||||
{
|
||||
if(auto header = mapService.loadMapHeader(resId))
|
||||
{
|
||||
auto missingMods = CMapService::verifyMapHeaderMods(*header);
|
||||
@ -345,8 +340,17 @@ bool MainWindow::openMap(const QString & filenameSelect)
|
||||
if(!modList.empty())
|
||||
throw ModIncompatibility(modList);
|
||||
|
||||
controller.setMap(mapService.loadMap(resId));
|
||||
return mapService.loadMap(resId);
|
||||
}
|
||||
else
|
||||
throw std::runtime_error("Corrupted map");
|
||||
}
|
||||
|
||||
bool MainWindow::openMap(const QString & filenameSelect)
|
||||
{
|
||||
try
|
||||
{
|
||||
controller.setMap(openMapInternal(filenameSelect));
|
||||
}
|
||||
catch(const ModIncompatibility & e)
|
||||
{
|
||||
@ -356,7 +360,7 @@ bool MainWindow::openMap(const QString & filenameSelect)
|
||||
}
|
||||
catch(const std::exception & e)
|
||||
{
|
||||
QMessageBox::critical(this, "Failed to open map", e.what());
|
||||
QMessageBox::critical(this, "Failed to open map", tr(e.what()));
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -423,7 +427,7 @@ void MainWindow::on_actionSave_as_triggered()
|
||||
if(!controller.map())
|
||||
return;
|
||||
|
||||
auto filenameSelect = QFileDialog::getSaveFileName(this, tr("Save map"), "", tr("VCMI maps (*.vmap)"));
|
||||
auto filenameSelect = QFileDialog::getSaveFileName(this, tr("Save map"), lastSavingDir, tr("VCMI maps (*.vmap)"));
|
||||
|
||||
if(filenameSelect.isNull())
|
||||
return;
|
||||
@ -432,6 +436,7 @@ void MainWindow::on_actionSave_as_triggered()
|
||||
return;
|
||||
|
||||
filename = filenameSelect;
|
||||
lastSavingDir = filenameSelect.remove(QUrl(filenameSelect).fileName());
|
||||
|
||||
saveMap();
|
||||
}
|
||||
@ -449,15 +454,8 @@ void MainWindow::on_actionSave_triggered()
|
||||
return;
|
||||
|
||||
if(filename.isNull())
|
||||
{
|
||||
auto filenameSelect = QFileDialog::getSaveFileName(this, tr("Save map"), "", tr("VCMI maps (*.vmap)"));
|
||||
|
||||
if(filenameSelect.isNull())
|
||||
return;
|
||||
|
||||
filename = filenameSelect;
|
||||
}
|
||||
|
||||
on_actionSave_as_triggered();
|
||||
else
|
||||
saveMap();
|
||||
}
|
||||
|
||||
@ -1250,3 +1248,29 @@ void MainWindow::on_actionTranslations_triggered()
|
||||
translationsDialog->show();
|
||||
}
|
||||
|
||||
void MainWindow::on_actionh3m_coverter_triggered()
|
||||
{
|
||||
auto mapFiles = QFileDialog::getOpenFileNames(this, tr("Select maps to covert"),
|
||||
QString::fromStdString(VCMIDirs::get().userCachePath().make_preferred().string()),
|
||||
tr("HoMM3 maps(*.h3m)"));
|
||||
if(mapFiles.empty())
|
||||
return;
|
||||
|
||||
auto saveDirectory = QFileDialog::getExistingDirectory(this, tr("Choose directory to save coverted maps"), QCoreApplication::applicationDirPath());
|
||||
if(saveDirectory.isEmpty())
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
for(auto & m : mapFiles)
|
||||
{
|
||||
CMapService mapService;
|
||||
mapService.saveMap(openMapInternal(m), (saveDirectory + QFileInfo(m).fileName()).toStdString());
|
||||
}
|
||||
}
|
||||
catch(const std::exception & e)
|
||||
{
|
||||
QMessageBox::critical(this, tr("Failed to convert the map. Abort operation"), tr(e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,6 +32,8 @@ class MainWindow : public QMainWindow
|
||||
QTranslator translator;
|
||||
#endif
|
||||
|
||||
std::unique_ptr<CMap> openMapInternal(const QString &);
|
||||
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = nullptr);
|
||||
~MainWindow();
|
||||
@ -119,6 +121,8 @@ private slots:
|
||||
|
||||
void on_actionTranslations_triggered();
|
||||
|
||||
void on_actionh3m_coverter_triggered();
|
||||
|
||||
public slots:
|
||||
|
||||
void treeViewSelected(const QModelIndex &selected, const QModelIndex &deselected);
|
||||
@ -155,7 +159,7 @@ private:
|
||||
ObjectBrowserProxyModel * objectBrowser = nullptr;
|
||||
QGraphicsScene * scenePreview;
|
||||
|
||||
QString filename;
|
||||
QString filename, lastSavingDir;
|
||||
bool unsaved = false;
|
||||
|
||||
QStandardItemModel objectsModel;
|
||||
|
@ -63,6 +63,7 @@
|
||||
<addaction name="actionSave"/>
|
||||
<addaction name="actionSave_as"/>
|
||||
<addaction name="actionExport"/>
|
||||
<addaction name="actionh3m_coverter"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuMap">
|
||||
<property name="title">
|
||||
@ -1254,6 +1255,11 @@
|
||||
<string>Ctrl+T</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionh3m_coverter">
|
||||
<property name="text">
|
||||
<string>h3m coverter</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
|
Loading…
Reference in New Issue
Block a user