mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-12-17 22:38:43 +00:00
Changed: #1301 Added dialog with a list of landscapes and operations (setActive, save, saveAs, delete).
This commit is contained in:
parent
46b4ff3a6d
commit
90464fa2f2
4 changed files with 265 additions and 28 deletions
|
@ -222,10 +222,11 @@ void ZoneBuilder::deleteZoneRegion(int id)
|
|||
{
|
||||
if ((0 <= id) && (id < int(m_landscapeItems.size())))
|
||||
{
|
||||
if (m_landscapeItems.at(id).rectItem != 0)
|
||||
delete m_landscapeItems.at(id).rectItem;
|
||||
m_landscapeScene->delZoneRegion(m_landscapeItems.at(id).zoneRegionObject->ligoZoneRegion());
|
||||
delete m_landscapeItems.at(id).zoneRegionObject;
|
||||
delete m_landscapeItems.at(id).builderZoneRegion;
|
||||
delete m_landscapeItems.at(id).rectItem;
|
||||
m_landscapeItems.erase(m_landscapeItems.begin() + id);
|
||||
calcMask();
|
||||
}
|
||||
|
@ -236,10 +237,13 @@ void ZoneBuilder::setCurrentZoneRegion(int id)
|
|||
if ((0 <= id) && (id < int(m_landscapeItems.size())))
|
||||
{
|
||||
if (currentIdZoneRegion() != -1)
|
||||
m_landscapeItems.at(m_currentZoneRegion).rectItem = m_landscapeScene->createLayerBlackout(currentZoneRegion()->ligoZoneRegion());
|
||||
m_currentZoneRegion = id;
|
||||
{
|
||||
NLLIGO::CZoneRegion &ligoRegion = m_landscapeItems.at(m_currentZoneRegion).zoneRegionObject->ligoZoneRegion();
|
||||
m_landscapeItems.at(m_currentZoneRegion).rectItem = m_landscapeScene->createLayerBlackout(ligoRegion);
|
||||
}
|
||||
delete m_landscapeItems.at(id).rectItem;
|
||||
m_landscapeItems.at(id).rectItem = 0;
|
||||
m_currentZoneRegion = id;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -33,15 +33,20 @@
|
|||
|
||||
// Qt includes
|
||||
#include <QtCore/QSettings>
|
||||
#include <QtGui/QMenu>
|
||||
#include <QtGui/QFileDialog>
|
||||
#include <QtGui/QMessageBox>
|
||||
|
||||
namespace LandscapeEditor
|
||||
{
|
||||
|
||||
static const int LANDSCAPE_ID = 32;
|
||||
int NewLandCounter = 0;
|
||||
QString _lastDir;
|
||||
|
||||
LandscapeEditorWindow::LandscapeEditorWindow(QWidget *parent)
|
||||
: QMainWindow(parent),
|
||||
m_currentRow(-1),
|
||||
m_landscapeScene(0),
|
||||
m_zoneBuilder(0),
|
||||
m_undoStack(0),
|
||||
|
@ -53,7 +58,7 @@ LandscapeEditorWindow::LandscapeEditorWindow(QWidget *parent)
|
|||
m_landscapeScene = new LandscapeScene(this);
|
||||
|
||||
m_zoneBuilder = new ZoneBuilder(m_landscapeScene, m_ui.zoneListWidget, m_undoStack);
|
||||
m_zoneBuilder->init("e:/-nel-/install/continents/newbieland", true);
|
||||
m_zoneBuilder->init("e:/-nel-/install/continents/newbieland", false);
|
||||
m_ui.zoneListWidget->setZoneBuilder(m_zoneBuilder);
|
||||
m_ui.zoneListWidget->updateUi();
|
||||
|
||||
|
@ -63,6 +68,12 @@ LandscapeEditorWindow::LandscapeEditorWindow(QWidget *parent)
|
|||
m_oglWidget = new QGLWidget(QGLFormat(QGL::DoubleBuffer | QGL::SampleBuffers));
|
||||
m_ui.graphicsView->setViewport(m_oglWidget);
|
||||
|
||||
m_ui.newLandAction->setIcon(QIcon(Core::Constants::ICON_NEW));
|
||||
m_ui.saveAction->setIcon(QIcon(Core::Constants::ICON_SAVE));
|
||||
m_ui.saveLandAction->setIcon(QIcon(Core::Constants::ICON_SAVE));
|
||||
m_ui.saveAsLandAction->setIcon(QIcon(Core::Constants::ICON_SAVE_AS));
|
||||
m_ui.deleteLandAction->setEnabled(false);
|
||||
|
||||
createMenus();
|
||||
createToolBars();
|
||||
readSettings();
|
||||
|
@ -71,6 +82,16 @@ LandscapeEditorWindow::LandscapeEditorWindow(QWidget *parent)
|
|||
connect(m_ui.projectSettingsAction, SIGNAL(triggered()), this, SLOT(openProjectSettings()));
|
||||
connect(m_ui.snapshotAction, SIGNAL(triggered()), this, SLOT(openSnapshotDialog()));
|
||||
connect(m_ui.enableGridAction, SIGNAL(toggled(bool)), m_ui.graphicsView, SLOT(setVisibleGrid(bool)));
|
||||
|
||||
connect(m_ui.newLandAction, SIGNAL(triggered()), this, SLOT(newLand()));
|
||||
connect(m_ui.setActiveLandAction, SIGNAL(triggered()), this, SLOT(setActiveLand()));
|
||||
connect(m_ui.saveLandAction, SIGNAL(triggered()), this, SLOT(saveSelectedLand()));
|
||||
connect(m_ui.saveAsLandAction, SIGNAL(triggered()), this, SLOT(saveAsSelectedLand()));
|
||||
connect(m_ui.deleteLandAction, SIGNAL(triggered()), this, SLOT(deleteSelectedLand()));
|
||||
|
||||
connect(m_ui.landscapesListWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(customContextMenu()));
|
||||
m_ui.landscapesListWidget->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
|
||||
}
|
||||
|
||||
LandscapeEditorWindow::~LandscapeEditorWindow()
|
||||
|
@ -97,17 +118,9 @@ void LandscapeEditorWindow::open()
|
|||
_lastDir = QFileInfo(list.front()).absolutePath();
|
||||
Q_FOREACH(QString fileName, fileNames)
|
||||
{
|
||||
int id = m_zoneBuilder->createZoneRegion(fileName);
|
||||
if (id == -1)
|
||||
{
|
||||
QMessageBox::critical(this, "Landscape Editor", "Cannot add this zone because it overlaps existing ones");
|
||||
continue;
|
||||
}
|
||||
ZoneRegionObject *zoneRegion = m_zoneBuilder->zoneRegion(id);
|
||||
m_ui.graphicsView->centerOn(zoneRegion->ligoZoneRegion().getMinX() * m_landscapeScene->cellSize(),
|
||||
abs(zoneRegion->ligoZoneRegion().getMinY()) * m_landscapeScene->cellSize());
|
||||
|
||||
m_zoneBuilder->setCurrentZoneRegion(id);
|
||||
int row = createLandscape(fileName);
|
||||
if (row != -1)
|
||||
setActiveLandscape(row);
|
||||
}
|
||||
}
|
||||
setCursor(Qt::ArrowCursor);
|
||||
|
@ -115,16 +128,7 @@ void LandscapeEditorWindow::open()
|
|||
|
||||
void LandscapeEditorWindow::save()
|
||||
{
|
||||
ZoneRegionObject *zoneRegion = m_zoneBuilder->currentZoneRegion();
|
||||
if (zoneRegion->fileName().empty())
|
||||
{
|
||||
QString fileName = QFileDialog::getSaveFileName(this,
|
||||
tr("Save NeL Ligo land file"), _lastDir,
|
||||
tr("NeL Ligo land file (*.land)"));
|
||||
if (!fileName.isEmpty())
|
||||
zoneRegion->setFileName(fileName.toStdString());
|
||||
}
|
||||
zoneRegion->save();
|
||||
saveLandscape(m_currentRow, true);
|
||||
}
|
||||
|
||||
void LandscapeEditorWindow::openProjectSettings()
|
||||
|
@ -184,6 +188,133 @@ void LandscapeEditorWindow::openSnapshotDialog()
|
|||
delete dialog;
|
||||
}
|
||||
|
||||
void LandscapeEditorWindow::customContextMenu()
|
||||
{
|
||||
if (m_ui.landscapesListWidget->currentRow() == -1)
|
||||
return;
|
||||
QMenu *popurMenu = new QMenu(this);
|
||||
popurMenu->addAction(m_ui.setActiveLandAction);
|
||||
popurMenu->addAction(m_ui.saveLandAction);
|
||||
popurMenu->addAction(m_ui.saveAsLandAction);
|
||||
popurMenu->addAction(m_ui.deleteLandAction);
|
||||
popurMenu->exec(QCursor::pos());
|
||||
delete popurMenu;
|
||||
}
|
||||
|
||||
void LandscapeEditorWindow::newLand()
|
||||
{
|
||||
createLandscape(QString());
|
||||
}
|
||||
|
||||
void LandscapeEditorWindow::setActiveLand()
|
||||
{
|
||||
setActiveLandscape(m_ui.landscapesListWidget->currentRow());
|
||||
}
|
||||
|
||||
void LandscapeEditorWindow::saveSelectedLand()
|
||||
{
|
||||
saveLandscape(m_ui.landscapesListWidget->currentRow(), true);
|
||||
}
|
||||
|
||||
void LandscapeEditorWindow::saveAsSelectedLand()
|
||||
{
|
||||
saveLandscape(m_ui.landscapesListWidget->currentRow(), false);
|
||||
}
|
||||
|
||||
void LandscapeEditorWindow::deleteSelectedLand()
|
||||
{
|
||||
int row = m_ui.landscapesListWidget->currentRow();
|
||||
QListWidgetItem *item = m_ui.landscapesListWidget->item(row);
|
||||
if (row == m_currentRow)
|
||||
{
|
||||
if (row == 0)
|
||||
++row;
|
||||
else
|
||||
--row;
|
||||
setActiveLandscape(row);
|
||||
}
|
||||
m_zoneBuilder->deleteZoneRegion(item->data(LANDSCAPE_ID).toInt());
|
||||
m_ui.landscapesListWidget->removeItemWidget(item);
|
||||
delete item;
|
||||
if (m_ui.landscapesListWidget->count() == 1)
|
||||
m_ui.deleteLandAction->setEnabled(false);
|
||||
}
|
||||
|
||||
int LandscapeEditorWindow::createLandscape(const QString &fileName)
|
||||
{
|
||||
int id;
|
||||
if (fileName.isEmpty())
|
||||
id = m_zoneBuilder->createZoneRegion();
|
||||
else
|
||||
id = m_zoneBuilder->createZoneRegion(fileName);
|
||||
|
||||
if (id == -1)
|
||||
{
|
||||
QMessageBox::critical(this, "Landscape Editor", "Cannot add this zone because it overlaps existing ones");
|
||||
return -1;
|
||||
}
|
||||
ZoneRegionObject *zoneRegion = m_zoneBuilder->zoneRegion(id);
|
||||
m_ui.graphicsView->centerOn(zoneRegion->ligoZoneRegion().getMinX() * m_landscapeScene->cellSize(),
|
||||
abs(zoneRegion->ligoZoneRegion().getMinY()) * m_landscapeScene->cellSize());
|
||||
|
||||
QListWidgetItem *item;
|
||||
if (fileName.isEmpty())
|
||||
item = new QListWidgetItem(QString("NewLandscape%1").arg(NewLandCounter++), m_ui.landscapesListWidget);
|
||||
else
|
||||
item = new QListWidgetItem(fileName, m_ui.landscapesListWidget);
|
||||
|
||||
item->setData(LANDSCAPE_ID, id);
|
||||
item->setFont(QFont("SansSerif", 9, QFont::Normal));
|
||||
|
||||
if (m_ui.landscapesListWidget->count() > 1)
|
||||
m_ui.deleteLandAction->setEnabled(true);
|
||||
|
||||
return m_ui.landscapesListWidget->count() - 1;
|
||||
}
|
||||
|
||||
void LandscapeEditorWindow::setActiveLandscape(int row)
|
||||
{
|
||||
if ((0 <= row) && (row < m_ui.landscapesListWidget->count()))
|
||||
{
|
||||
if (m_currentRow != -1)
|
||||
{
|
||||
QListWidgetItem *item = m_ui.landscapesListWidget->item(m_currentRow);
|
||||
item->setFont(QFont("SansSerif", 9, QFont::Normal));
|
||||
}
|
||||
QListWidgetItem *item = m_ui.landscapesListWidget->item(row);
|
||||
item->setFont(QFont("SansSerif", 9, QFont::Bold));
|
||||
m_zoneBuilder->setCurrentZoneRegion(item->data(LANDSCAPE_ID).toInt());
|
||||
m_currentRow = row;
|
||||
}
|
||||
}
|
||||
|
||||
void LandscapeEditorWindow::saveLandscape(int row, bool force)
|
||||
{
|
||||
if ((0 <= row) && (row < m_ui.landscapesListWidget->count()))
|
||||
{
|
||||
QListWidgetItem *item = m_ui.landscapesListWidget->item(row);
|
||||
ZoneRegionObject *regionObject = m_zoneBuilder->zoneRegion(item->data(LANDSCAPE_ID).toInt());
|
||||
if ((!force) || (regionObject->fileName().empty()))
|
||||
{
|
||||
QString fileName = QFileDialog::getSaveFileName(this,
|
||||
tr("Save NeL Ligo land file"), _lastDir,
|
||||
tr("NeL Ligo land file (*.land)"));
|
||||
if (!fileName.isEmpty())
|
||||
{
|
||||
regionObject->setFileName(fileName.toStdString());
|
||||
regionObject->save();
|
||||
regionObject->setModified(false);
|
||||
item->setText(fileName);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
regionObject->save();
|
||||
regionObject->setModified(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LandscapeEditorWindow::showEvent(QShowEvent *showEvent)
|
||||
{
|
||||
QMainWindow::showEvent(showEvent);
|
||||
|
@ -202,7 +333,23 @@ void LandscapeEditorWindow::createToolBars()
|
|||
//QAction *action = menuManager->action(Core::Constants::NEW);
|
||||
//m_ui.fileToolBar->addAction(action);
|
||||
QAction *action = menuManager->action(Core::Constants::OPEN);
|
||||
m_ui.fileToolBar->addAction(m_ui.newLandAction);
|
||||
m_ui.fileToolBar->addAction(action);
|
||||
m_ui.fileToolBar->addAction(m_ui.saveAction);
|
||||
|
||||
const char * const UNDO = "ObjectViewerQt.Undo";
|
||||
const char * const REDO = "ObjectViewerQt.Redo";
|
||||
|
||||
//action = menuManager->action(Core::Constants::UNDO);
|
||||
action = menuManager->action(UNDO);
|
||||
if (action != 0)
|
||||
m_ui.undoToolBar->addAction(action);
|
||||
|
||||
//action = menuManager->action(Core::Constants::REDO);
|
||||
action = menuManager->action(REDO);
|
||||
if (action != 0)
|
||||
m_ui.undoToolBar->addAction(action);
|
||||
|
||||
//action = menuManager->action(Core::Constants::SAVE);
|
||||
//m_ui.fileToolBar->addAction(action);
|
||||
//action = menuManager->action(Core::Constants::SAVE_AS);
|
||||
|
|
|
@ -49,6 +49,12 @@ public Q_SLOTS:
|
|||
private Q_SLOTS:
|
||||
void openProjectSettings();
|
||||
void openSnapshotDialog();
|
||||
void customContextMenu();
|
||||
void newLand();
|
||||
void setActiveLand();
|
||||
void saveSelectedLand();
|
||||
void saveAsSelectedLand();
|
||||
void deleteSelectedLand();
|
||||
|
||||
protected:
|
||||
virtual void showEvent(QShowEvent *showEvent);
|
||||
|
@ -59,6 +65,11 @@ private:
|
|||
void readSettings();
|
||||
void writeSettings();
|
||||
|
||||
void setActiveLandscape(int row);
|
||||
void saveLandscape(int row, bool force);
|
||||
int createLandscape(const QString &fileName);
|
||||
|
||||
int m_currentRow;
|
||||
LandscapeScene *m_landscapeScene;
|
||||
ZoneBuilder *m_zoneBuilder;
|
||||
QUndoStack *m_undoStack;
|
||||
|
|
|
@ -62,7 +62,7 @@
|
|||
</attribute>
|
||||
<widget class="LandscapeEditor::ListZonesWidget" name="zoneListWidget"/>
|
||||
</widget>
|
||||
<widget class="QToolBar" name="landToolBar">
|
||||
<widget class="QToolBar" name="undoToolBar">
|
||||
<property name="windowTitle">
|
||||
<string>toolBar_2</string>
|
||||
</property>
|
||||
|
@ -72,9 +72,40 @@
|
|||
<attribute name="toolBarBreak">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<addaction name="saveAction"/>
|
||||
<addaction name="snapshotAction"/>
|
||||
</widget>
|
||||
<widget class="QDockWidget" name="landscapesDockWidget">
|
||||
<property name="windowTitle">
|
||||
<string>Landscapes</string>
|
||||
</property>
|
||||
<attribute name="dockWidgetArea">
|
||||
<number>1</number>
|
||||
</attribute>
|
||||
<widget class="QWidget" name="dockWidgetContents">
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<property name="margin">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="spacing">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QListWidget" name="landscapesListWidget"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QToolBar" name="zoneToolBar">
|
||||
<property name="windowTitle">
|
||||
<string>toolBar</string>
|
||||
</property>
|
||||
<attribute name="toolBarArea">
|
||||
<enum>TopToolBarArea</enum>
|
||||
</attribute>
|
||||
<attribute name="toolBarBreak">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<addaction name="projectSettingsAction"/>
|
||||
<addaction name="snapshotAction"/>
|
||||
<addaction name="enableGridAction"/>
|
||||
</widget>
|
||||
<action name="projectSettingsAction">
|
||||
|
@ -113,6 +144,50 @@
|
|||
<string>Save</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="setActiveLandAction">
|
||||
<property name="icon">
|
||||
<iconset resource="landscape_editor.qrc">
|
||||
<normaloff>:/icons/ic_nel_zone.png</normaloff>:/icons/ic_nel_zone.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Set active</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Set active selected landscape</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="saveLandAction">
|
||||
<property name="text">
|
||||
<string>Save</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Save selected landscape</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="saveAsLandAction">
|
||||
<property name="text">
|
||||
<string>Save As landscape</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Save as selected landscape</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="deleteLandAction">
|
||||
<property name="text">
|
||||
<string>Delete</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Delete selected landscape</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="newLandAction">
|
||||
<property name="text">
|
||||
<string>New</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Create new landscape</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
|
|
Loading…
Reference in a new issue