mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-23 22:37:55 +02:00
map editor multi level support
This commit is contained in:
@@ -247,7 +247,6 @@ MainWindow::MainWindow(QWidget* parent) :
|
||||
ui->menuOpenRecent->setIcon(QIcon{":/icons/document-open-recent.png"});
|
||||
ui->actionSave->setIcon(QIcon{":/icons/document-save.png"});
|
||||
ui->actionNew->setIcon(QIcon{":/icons/document-new.png"});
|
||||
ui->actionLevel->setIcon(QIcon{":/icons/toggle-underground.png"});
|
||||
ui->actionPass->setIcon(QIcon{":/icons/toggle-pass.png"});
|
||||
ui->actionCut->setIcon(QIcon{":/icons/edit-cut.png"});
|
||||
ui->actionCopy->setIcon(QIcon{":/icons/edit-copy.png"});
|
||||
@@ -266,6 +265,54 @@ MainWindow::MainWindow(QWidget* parent) :
|
||||
ui->actionCampaignEditor->setIcon(QIcon{":/icons/mapeditor.64x64.png"});
|
||||
ui->actionTemplateEditor->setIcon(QIcon{":/icons/dice.png"});
|
||||
|
||||
// Add combobox action
|
||||
for (QWidget* c : QList<QWidget*>{ ui->toolBar, ui->menuView })
|
||||
{
|
||||
QWidget* container = new QWidget;
|
||||
QHBoxLayout* layout = new QHBoxLayout(container);
|
||||
layout->setContentsMargins(6, 2, 4, 2);
|
||||
layout->setSpacing(2);
|
||||
|
||||
if (c == ui->menuView)
|
||||
{
|
||||
// Add icon label only for QMenu
|
||||
QLabel* iconLabel = new QLabel;
|
||||
iconLabel->setPixmap(QIcon(":/icons/toggle-underground.png").pixmap(16, 16));
|
||||
iconLabel->setContentsMargins(0, 2, 0, 0);
|
||||
layout->addWidget(iconLabel);
|
||||
}
|
||||
|
||||
// Add the combo box
|
||||
QComboBox* combo = new QComboBox;
|
||||
combo->setFixedHeight(ui->menuView->fontMetrics().height() + 6);
|
||||
connect(combo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this, combo](int index) {
|
||||
for(auto & box : levelComboBoxes)
|
||||
if (box->currentIndex() != index && combo != box)
|
||||
box->setCurrentIndex(index);
|
||||
|
||||
if(!controller.map())
|
||||
return;
|
||||
|
||||
mapLevel = combo->currentIndex();
|
||||
ui->mapView->setScene(controller.scene(mapLevel));
|
||||
ui->minimapView->setScene(controller.miniScene(mapLevel));
|
||||
});
|
||||
layout->addWidget(combo, c == ui->menuView ? 1 : 0);
|
||||
|
||||
// Create the widget action
|
||||
QWidgetAction* comboAction = new QWidgetAction(this);
|
||||
comboAction->setDefaultWidget(container);
|
||||
|
||||
int index = c->actions().indexOf(ui->actionLevel);
|
||||
if (index != -1)
|
||||
{
|
||||
c->removeAction(ui->actionLevel);
|
||||
c->insertAction(c->actions().value(index), comboAction);
|
||||
}
|
||||
|
||||
levelComboBoxes.push_back(combo);
|
||||
}
|
||||
|
||||
#ifndef ENABLE_TEMPLATE_EDITOR
|
||||
ui->actionTemplateEditor->setVisible(false);
|
||||
#endif
|
||||
@@ -387,7 +434,19 @@ void MainWindow::initializeMap(bool isNew)
|
||||
ui->actionMapSettings->setEnabled(true);
|
||||
ui->actionPlayers_settings->setEnabled(true);
|
||||
ui->actionTranslations->setEnabled(true);
|
||||
ui->actionLevel->setEnabled(controller.map()->mapLevels == 2); // TODO: multilevel support
|
||||
for(auto & box : levelComboBoxes)
|
||||
{
|
||||
box->clear();
|
||||
for(int i = 0; i < controller.map()->mapLevels; i++)
|
||||
{
|
||||
if(i == 0)
|
||||
box->addItems({ tr("Surface") });
|
||||
else if(i == 1)
|
||||
box->addItems({ tr("Underground") });
|
||||
else
|
||||
box->addItems({ tr("Level - %1").arg(i + 1) });
|
||||
}
|
||||
}
|
||||
|
||||
//set minimal players count
|
||||
if(isNew)
|
||||
@@ -966,26 +1025,6 @@ void MainWindow::loadObjectsTree()
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_actionLevel_triggered()
|
||||
{
|
||||
if(controller.map() && controller.map()->mapLevels == 2) // TODO: multilevel support
|
||||
{
|
||||
mapLevel = mapLevel ? 0 : 1;
|
||||
ui->mapView->setScene(controller.scene(mapLevel));
|
||||
ui->minimapView->setScene(controller.miniScene(mapLevel));
|
||||
if (mapLevel == 0)
|
||||
{
|
||||
ui->actionLevel->setText(tr("View underground"));
|
||||
ui->actionLevel->setToolTip(tr("View underground"));
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->actionLevel->setText(tr("View surface"));
|
||||
ui->actionLevel->setToolTip(tr("View surface"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_actionUndo_triggered()
|
||||
{
|
||||
QString str(tr("Undo clicked"));
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <QStandardItemModel>
|
||||
#include <QTranslator>
|
||||
#include <QTableWidgetItem>
|
||||
#include <QComboBox>
|
||||
#include "mapcontroller.h"
|
||||
#include "resourceExtractor/ResourceConverter.h"
|
||||
|
||||
@@ -84,8 +85,6 @@ private slots:
|
||||
|
||||
void on_actionNew_triggered();
|
||||
|
||||
void on_actionLevel_triggered();
|
||||
|
||||
void on_actionSave_triggered();
|
||||
|
||||
void on_actionErase_triggered();
|
||||
@@ -197,6 +196,8 @@ private:
|
||||
QGraphicsScene * scenePreview;
|
||||
MapSettings * mapSettings = nullptr;
|
||||
|
||||
QList<QComboBox*> levelComboBoxes;
|
||||
|
||||
QString filename;
|
||||
QString lastSavingDir;
|
||||
bool unsaved = false;
|
||||
|
||||
@@ -45,7 +45,7 @@ MapController::MapController(QObject * parent)
|
||||
|
||||
MapController::MapController(MainWindow * m): main(m)
|
||||
{
|
||||
for(int i : {0, 1})
|
||||
for(int i = 0; i < MAX_LEVELS; i++)
|
||||
{
|
||||
_scenes[i].reset(new MapScene(i));
|
||||
_miniscenes[i].reset(new MinimapScene(i));
|
||||
@@ -56,12 +56,12 @@ MapController::MapController(MainWindow * m): main(m)
|
||||
|
||||
void MapController::connectScenes()
|
||||
{
|
||||
for (int level = 0; level <= 1; level++)
|
||||
for(int i = 0; i < MAX_LEVELS; i++)
|
||||
{
|
||||
//selections for both layers will be handled separately
|
||||
QObject::connect(_scenes[level].get(), &MapScene::selected, [this, level](bool anythingSelected)
|
||||
QObject::connect(_scenes[i].get(), &MapScene::selected, [this, i](bool anythingSelected)
|
||||
{
|
||||
main->onSelectionMade(level, anythingSelected);
|
||||
main->onSelectionMade(i, anythingSelected);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -223,7 +223,7 @@ void MapController::setMap(std::unique_ptr<CMap> cmap)
|
||||
|
||||
repairMap();
|
||||
|
||||
for(int i : {0, 1})
|
||||
for(int i = 0; i < _map->mapLevels; i++)
|
||||
{
|
||||
_scenes[i].reset(new MapScene(i));
|
||||
_miniscenes[i].reset(new MinimapScene(i));
|
||||
@@ -258,12 +258,10 @@ void MapController::initObstaclePainters(CMap * map)
|
||||
|
||||
void MapController::sceneForceUpdate()
|
||||
{
|
||||
_scenes[0]->updateViews();
|
||||
_miniscenes[0]->updateViews();
|
||||
if(_map->mapLevels == 2) // TODO: multilevel support
|
||||
for(int i = 0; i < _map->mapLevels; i++)
|
||||
{
|
||||
_scenes[1]->updateViews();
|
||||
_miniscenes[1]->updateViews();
|
||||
_scenes[i]->updateViews();
|
||||
_miniscenes[i]->updateViews();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -278,7 +276,7 @@ void MapController::resetMapHandler()
|
||||
if(!_mapHandler)
|
||||
_mapHandler.reset(new MapHandler());
|
||||
_mapHandler->reset(map());
|
||||
for(int i : {0, 1})
|
||||
for(int i = 0; i < MAX_LEVELS; i++)
|
||||
{
|
||||
_scenes[i]->initialize(*this);
|
||||
_miniscenes[i]->initialize(*this);
|
||||
|
||||
@@ -100,11 +100,13 @@ private:
|
||||
std::unique_ptr<CMap> _map;
|
||||
std::unique_ptr<MapHandler> _mapHandler;
|
||||
MainWindow * main;
|
||||
mutable std::array<std::unique_ptr<MapScene>, 2> _scenes;
|
||||
mutable std::array<std::unique_ptr<MinimapScene>, 2> _miniscenes;
|
||||
mutable std::map<int, std::unique_ptr<MapScene>> _scenes;
|
||||
mutable std::map<int, std::unique_ptr<MinimapScene>> _miniscenes;
|
||||
std::vector<std::unique_ptr<CGObjectInstance>> _clipboard;
|
||||
int _clipboardShiftIndex = 0;
|
||||
|
||||
const int MAX_LEVELS = 10;
|
||||
|
||||
std::map<TerrainId, std::unique_ptr<EditorObstaclePlacer>> _obstaclePainters;
|
||||
|
||||
void connectScenes();
|
||||
|
||||
@@ -77,8 +77,7 @@ WindowNewMap::WindowNewMap(QWidget *parent) :
|
||||
int height = ui->heightTxt->text().toInt();
|
||||
mapGenOptions.setWidth(width ? width : 1);
|
||||
mapGenOptions.setHeight(height ? height : 1);
|
||||
bool twoLevel = ui->twoLevelCheck->isChecked();
|
||||
mapGenOptions.setLevels(twoLevel ? 2 : 1); // TODO: multilevel support
|
||||
mapGenOptions.setLevels(ui->spinBoxLevels->value());
|
||||
|
||||
updateTemplateList();
|
||||
}
|
||||
@@ -123,7 +122,7 @@ bool WindowNewMap::loadUserSettings()
|
||||
}
|
||||
}
|
||||
|
||||
ui->twoLevelCheck->setChecked(mapGenOptions.getLevels() == 2); // TODO: multilevel support
|
||||
ui->spinBoxLevels->setValue(mapGenOptions.getLevels());
|
||||
|
||||
ui->humanCombo->setCurrentIndex(mapGenOptions.getHumanOrCpuPlayerCount());
|
||||
ui->cpuCombo->setCurrentIndex(mapGenOptions.getCompOnlyPlayerCount());
|
||||
@@ -328,10 +327,12 @@ void WindowNewMap::on_sizeCombo_activated(int index)
|
||||
}
|
||||
|
||||
|
||||
void WindowNewMap::on_twoLevelCheck_stateChanged(int arg1)
|
||||
void WindowNewMap::on_spinBoxLevels_valueChanged(int value)
|
||||
{
|
||||
bool twoLevel = ui->twoLevelCheck->isChecked();
|
||||
mapGenOptions.setLevels(twoLevel ? 2 : 1); // TODO: multilevel support
|
||||
if(value > 2)
|
||||
QMessageBox::warning(this, tr("Multilevel support"), tr("Multilevel support is highly experimental yet. Expect issues.")); // TODO: multilevel support
|
||||
|
||||
mapGenOptions.setLevels(ui->spinBoxLevels->value());
|
||||
updateTemplateList();
|
||||
}
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ private slots:
|
||||
|
||||
void on_sizeCombo_activated(int index);
|
||||
|
||||
void on_twoLevelCheck_stateChanged(int arg1);
|
||||
void on_spinBoxLevels_valueChanged(int value);
|
||||
|
||||
void on_humanCombo_activated(int index);
|
||||
|
||||
|
||||
@@ -270,25 +270,41 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QCheckBox" name="twoLevelCheck">
|
||||
<widget class="QWidget" name="horizontalLayoutWidget_3">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>90</y>
|
||||
<width>277</width>
|
||||
<height>20</height>
|
||||
<x>20</x>
|
||||
<y>86</y>
|
||||
<width>191</width>
|
||||
<height>29</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>96</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_8">
|
||||
<property name="text">
|
||||
<string>Underground</string>
|
||||
<string>Levels</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="spinBoxLevels">
|
||||
<property name="specialValueText">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="suffix">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="prefix">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>1</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QGroupBox" name="randomOptions">
|
||||
<property name="enabled">
|
||||
|
||||
Reference in New Issue
Block a user