Changed: #1301 Improved Landscape plugin.
This commit is contained in:
parent
f7603d1084
commit
add8aa0450
10 changed files with 138 additions and 99 deletions
|
@ -7,3 +7,4 @@ ADD_SUBDIRECTORY(disp_sheet_id)
|
||||||
ADD_SUBDIRECTORY(object_viewer)
|
ADD_SUBDIRECTORY(object_viewer)
|
||||||
ADD_SUBDIRECTORY(zone_painter)
|
ADD_SUBDIRECTORY(zone_painter)
|
||||||
ADD_SUBDIRECTORY(georges_editor)
|
ADD_SUBDIRECTORY(georges_editor)
|
||||||
|
ADD_SUBDIRECTORY(world_editor)
|
|
@ -40,7 +40,7 @@ SOURCE_GROUP(QtGeneratedMocQrcSrc FILES ${OVQT_PLUGIN_LANDSCAPE_EDITOR_MOC_SRC}
|
||||||
SOURCE_GROUP("Landscape Editor Plugin" FILES ${SRC})
|
SOURCE_GROUP("Landscape Editor Plugin" FILES ${SRC})
|
||||||
SOURCE_GROUP("OVQT Extension System" FILES ${OVQT_EXT_SYS_SRC})
|
SOURCE_GROUP("OVQT Extension System" FILES ${OVQT_EXT_SYS_SRC})
|
||||||
|
|
||||||
ADD_LIBRARY(ovqt_plugin_landscape_editor MODULE ${SRC}
|
ADD_LIBRARY(ovqt_plugin_landscape_editor SHARED ${SRC}
|
||||||
${OVQT_PLUGIN_LANDSCAPE_EDITOR_MOC_SRC}
|
${OVQT_PLUGIN_LANDSCAPE_EDITOR_MOC_SRC}
|
||||||
${OVQT_EXT_SYS_SRC}
|
${OVQT_EXT_SYS_SRC}
|
||||||
${OVQT_PLUGIN_LANDSCAPE_EDITOR_UI_HDRS}
|
${OVQT_PLUGIN_LANDSCAPE_EDITOR_UI_HDRS}
|
||||||
|
|
|
@ -26,11 +26,11 @@
|
||||||
// Qt includes
|
// Qt includes
|
||||||
#include <QtCore/QDir>
|
#include <QtCore/QDir>
|
||||||
#include <QtGui/QMessageBox>
|
#include <QtGui/QMessageBox>
|
||||||
#include <QtGui/QApplication>
|
|
||||||
#include <QtGui/QProgressDialog>
|
#include <QtGui/QProgressDialog>
|
||||||
|
|
||||||
namespace LandscapeEditor
|
namespace LandscapeEditor
|
||||||
{
|
{
|
||||||
|
int LandCounter = 0;
|
||||||
|
|
||||||
ZoneBuilder::ZoneBuilder(LandscapeScene *landscapeScene, ListZonesWidget *listZonesWidget, QUndoStack *undoStack)
|
ZoneBuilder::ZoneBuilder(LandscapeScene *landscapeScene, ListZonesWidget *listZonesWidget, QUndoStack *undoStack)
|
||||||
: m_currentZoneRegion(-1),
|
: m_currentZoneRegion(-1),
|
||||||
|
@ -117,7 +117,7 @@ void ZoneBuilder::addZone(sint32 posX, sint32 posY)
|
||||||
if ((m_listZonesWidget == 0) || (m_undoStack == 0))
|
if ((m_listZonesWidget == 0) || (m_undoStack == 0))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (m_landscapeItems.empty())
|
if (m_landscapeMap.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Check zone name
|
// Check zone name
|
||||||
|
@ -125,7 +125,7 @@ void ZoneBuilder::addZone(sint32 posX, sint32 posY)
|
||||||
if (zoneName.empty())
|
if (zoneName.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
BuilderZoneRegion *builderZoneRegion = m_landscapeItems.at(m_currentZoneRegion).builderZoneRegion;
|
BuilderZoneRegion *builderZoneRegion = m_landscapeMap.value(m_currentZoneRegion).builderZoneRegion;
|
||||||
builderZoneRegion->init(this);
|
builderZoneRegion->init(this);
|
||||||
|
|
||||||
uint8 rot = uint8(m_listZonesWidget->currentRot());
|
uint8 rot = uint8(m_listZonesWidget->currentRot());
|
||||||
|
@ -161,13 +161,13 @@ void ZoneBuilder::delZone(const sint32 posX, const sint32 posY)
|
||||||
if ((m_listZonesWidget == 0) || (m_undoStack == 0))
|
if ((m_listZonesWidget == 0) || (m_undoStack == 0))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (m_landscapeItems.empty())
|
if (m_landscapeMap.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_titleAction = QString("Del zone %1,%2").arg(posX).arg(posY);
|
m_titleAction = QString("Del zone %1,%2").arg(posX).arg(posY);
|
||||||
m_createdAction = false;
|
m_createdAction = false;
|
||||||
|
|
||||||
BuilderZoneRegion *builderZoneRegion = m_landscapeItems.at(m_currentZoneRegion).builderZoneRegion;
|
BuilderZoneRegion *builderZoneRegion = m_landscapeMap.value(m_currentZoneRegion).builderZoneRegion;
|
||||||
|
|
||||||
builderZoneRegion->init(this);
|
builderZoneRegion->init(this);
|
||||||
builderZoneRegion->del(posX, posY);
|
builderZoneRegion->del(posX, posY);
|
||||||
|
@ -176,24 +176,22 @@ void ZoneBuilder::delZone(const sint32 posX, const sint32 posY)
|
||||||
|
|
||||||
int ZoneBuilder::createZoneRegion()
|
int ZoneBuilder::createZoneRegion()
|
||||||
{
|
{
|
||||||
int newId = m_landscapeItems.size();
|
|
||||||
LandscapeItem landItem;
|
LandscapeItem landItem;
|
||||||
landItem.zoneRegionObject = new ZoneRegionObject();
|
landItem.zoneRegionObject = new ZoneRegionObject();
|
||||||
landItem.builderZoneRegion = new BuilderZoneRegion(newId);
|
landItem.builderZoneRegion = new BuilderZoneRegion(LandCounter);
|
||||||
landItem.builderZoneRegion->init(this);
|
landItem.builderZoneRegion->init(this);
|
||||||
landItem.rectItem = 0;
|
landItem.rectItem = m_landscapeScene->createLayerBlackout(landItem.zoneRegionObject->ligoZoneRegion());
|
||||||
|
|
||||||
newZone();
|
m_landscapeMap.insert(LandCounter, landItem);
|
||||||
m_landscapeItems.push_back(landItem);
|
|
||||||
if (m_currentZoneRegion == -1)
|
if (m_currentZoneRegion == -1)
|
||||||
setCurrentZoneRegion(newId);
|
setCurrentZoneRegion(LandCounter);
|
||||||
|
|
||||||
return newId;
|
calcMask();
|
||||||
|
return LandCounter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ZoneBuilder::createZoneRegion(const QString &fileName)
|
int ZoneBuilder::createZoneRegion(const QString &fileName)
|
||||||
{
|
{
|
||||||
int newId = m_landscapeItems.size();
|
|
||||||
LandscapeItem landItem;
|
LandscapeItem landItem;
|
||||||
landItem.zoneRegionObject = new ZoneRegionObject();
|
landItem.zoneRegionObject = new ZoneRegionObject();
|
||||||
landItem.zoneRegionObject->load(fileName.toStdString());
|
landItem.zoneRegionObject->load(fileName.toStdString());
|
||||||
|
@ -203,48 +201,52 @@ int ZoneBuilder::createZoneRegion(const QString &fileName)
|
||||||
delete landItem.zoneRegionObject;
|
delete landItem.zoneRegionObject;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
landItem.builderZoneRegion = new BuilderZoneRegion(newId);
|
landItem.builderZoneRegion = new BuilderZoneRegion(LandCounter);
|
||||||
landItem.builderZoneRegion->init(this);
|
landItem.builderZoneRegion->init(this);
|
||||||
|
|
||||||
newZone();
|
|
||||||
m_landscapeItems.push_back(landItem);
|
|
||||||
|
|
||||||
m_landscapeScene->addZoneRegion(landItem.zoneRegionObject->ligoZoneRegion());
|
m_landscapeScene->addZoneRegion(landItem.zoneRegionObject->ligoZoneRegion());
|
||||||
m_landscapeItems.at(newId).rectItem = m_landscapeScene->createLayerBlackout(landItem.zoneRegionObject->ligoZoneRegion());
|
landItem.rectItem = m_landscapeScene->createLayerBlackout(landItem.zoneRegionObject->ligoZoneRegion());
|
||||||
|
m_landscapeMap.insert(LandCounter, landItem);
|
||||||
|
|
||||||
if (m_currentZoneRegion == -1)
|
if (m_currentZoneRegion == -1)
|
||||||
setCurrentZoneRegion(newId);
|
setCurrentZoneRegion(LandCounter);
|
||||||
|
|
||||||
return newId;
|
calcMask();
|
||||||
|
return LandCounter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZoneBuilder::deleteZoneRegion(int id)
|
void ZoneBuilder::deleteZoneRegion(int id)
|
||||||
{
|
{
|
||||||
if ((0 <= id) && (id < int(m_landscapeItems.size())))
|
if (m_landscapeMap.contains(id))
|
||||||
{
|
{
|
||||||
if (m_landscapeItems.at(id).rectItem != 0)
|
if (m_landscapeMap.value(id).rectItem != 0)
|
||||||
delete m_landscapeItems.at(id).rectItem;
|
delete m_landscapeMap.value(id).rectItem;
|
||||||
m_landscapeScene->delZoneRegion(m_landscapeItems.at(id).zoneRegionObject->ligoZoneRegion());
|
m_landscapeScene->delZoneRegion(m_landscapeMap.value(id).zoneRegionObject->ligoZoneRegion());
|
||||||
delete m_landscapeItems.at(id).zoneRegionObject;
|
delete m_landscapeMap.value(id).zoneRegionObject;
|
||||||
delete m_landscapeItems.at(id).builderZoneRegion;
|
delete m_landscapeMap.value(id).builderZoneRegion;
|
||||||
m_landscapeItems.erase(m_landscapeItems.begin() + id);
|
m_landscapeMap.remove(id);
|
||||||
calcMask();
|
calcMask();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
nlwarning("Landscape (id %i) not found", id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZoneBuilder::setCurrentZoneRegion(int id)
|
void ZoneBuilder::setCurrentZoneRegion(int id)
|
||||||
{
|
{
|
||||||
if ((0 <= id) && (id < int(m_landscapeItems.size())))
|
if (m_landscapeMap.contains(id))
|
||||||
{
|
{
|
||||||
if (currentIdZoneRegion() != -1)
|
if (currentIdZoneRegion() != -1)
|
||||||
{
|
{
|
||||||
NLLIGO::CZoneRegion &ligoRegion = m_landscapeItems.at(m_currentZoneRegion).zoneRegionObject->ligoZoneRegion();
|
NLLIGO::CZoneRegion &ligoRegion = m_landscapeMap.value(m_currentZoneRegion).zoneRegionObject->ligoZoneRegion();
|
||||||
m_landscapeItems.at(m_currentZoneRegion).rectItem = m_landscapeScene->createLayerBlackout(ligoRegion);
|
m_landscapeMap[m_currentZoneRegion].rectItem = m_landscapeScene->createLayerBlackout(ligoRegion);
|
||||||
}
|
}
|
||||||
delete m_landscapeItems.at(id).rectItem;
|
delete m_landscapeMap.value(id).rectItem;
|
||||||
m_landscapeItems.at(id).rectItem = 0;
|
m_landscapeMap[id].rectItem = 0;
|
||||||
m_currentZoneRegion = id;
|
m_currentZoneRegion = id;
|
||||||
|
calcMask();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
nlwarning("Landscape (id %i) not found", id);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ZoneBuilder::currentIdZoneRegion() const
|
int ZoneBuilder::currentIdZoneRegion() const
|
||||||
|
@ -254,27 +256,27 @@ int ZoneBuilder::currentIdZoneRegion() const
|
||||||
|
|
||||||
ZoneRegionObject *ZoneBuilder::currentZoneRegion() const
|
ZoneRegionObject *ZoneBuilder::currentZoneRegion() const
|
||||||
{
|
{
|
||||||
return m_landscapeItems.at(m_currentZoneRegion).zoneRegionObject;
|
return m_landscapeMap.value(m_currentZoneRegion).zoneRegionObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ZoneBuilder::countZoneRegion() const
|
int ZoneBuilder::countZoneRegion() const
|
||||||
{
|
{
|
||||||
return m_landscapeItems.size();
|
return m_landscapeMap.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
ZoneRegionObject *ZoneBuilder::zoneRegion(int id) const
|
ZoneRegionObject *ZoneBuilder::zoneRegion(int id) const
|
||||||
{
|
{
|
||||||
return m_landscapeItems.at(id).zoneRegionObject;
|
return m_landscapeMap.value(id).zoneRegionObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZoneBuilder::ligoData(LigoData &data, const ZonePosition &zonePos)
|
void ZoneBuilder::ligoData(LigoData &data, const ZonePosition &zonePos)
|
||||||
{
|
{
|
||||||
m_landscapeItems.at(zonePos.region).zoneRegionObject->ligoData(data, zonePos.x, zonePos.y);
|
m_landscapeMap.value(zonePos.region).zoneRegionObject->ligoData(data, zonePos.x, zonePos.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZoneBuilder::setLigoData(LigoData &data, const ZonePosition &zonePos)
|
void ZoneBuilder::setLigoData(LigoData &data, const ZonePosition &zonePos)
|
||||||
{
|
{
|
||||||
m_landscapeItems.at(zonePos.region).zoneRegionObject->setLigoData(data, zonePos.x, zonePos.y);
|
m_landscapeMap.value(zonePos.region).zoneRegionObject->setLigoData(data, zonePos.x, zonePos.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZoneBuilder::initZoneBank (const QString &pathName)
|
bool ZoneBuilder::initZoneBank (const QString &pathName)
|
||||||
|
@ -307,25 +309,6 @@ QString ZoneBuilder::dataPath() const
|
||||||
return m_lastPathName;
|
return m_lastPathName;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZoneBuilder::newZone()
|
|
||||||
{
|
|
||||||
// Select starting point for the moment 0,0
|
|
||||||
sint32 x = 0, y = 0;
|
|
||||||
|
|
||||||
// If there are some zone already present increase x until free
|
|
||||||
for (size_t i = 0; i < m_landscapeItems.size(); ++i)
|
|
||||||
{
|
|
||||||
const NLLIGO::CZoneRegion &zoneRegion = m_landscapeItems.at(i).zoneRegionObject->ligoZoneRegion();
|
|
||||||
const std::string &zoneName = zoneRegion.getName (x, y);
|
|
||||||
if ((zoneName != STRING_OUT_OF_BOUND) && (zoneName != STRING_UNUSED))
|
|
||||||
{
|
|
||||||
++x;
|
|
||||||
i = -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
calcMask();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ZoneBuilder::getZoneMask(sint32 x, sint32 y)
|
bool ZoneBuilder::getZoneMask(sint32 x, sint32 y)
|
||||||
{
|
{
|
||||||
if ((x < m_minX) || (x > m_maxX) ||
|
if ((x < m_minX) || (x > m_maxX) ||
|
||||||
|
@ -346,12 +329,14 @@ void ZoneBuilder::calcMask()
|
||||||
m_minY = m_minX = 1000000;
|
m_minY = m_minX = 1000000;
|
||||||
m_maxY = m_maxX = -1000000;
|
m_maxY = m_maxX = -1000000;
|
||||||
|
|
||||||
if (m_landscapeItems.size() == 0)
|
if (m_landscapeMap.size() == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (size_t i = 0; i < m_landscapeItems.size(); ++i)
|
QMapIterator<int, LandscapeItem> i(m_landscapeMap);
|
||||||
|
while (i.hasNext())
|
||||||
{
|
{
|
||||||
const NLLIGO::CZoneRegion ®ion = m_landscapeItems.at(i).zoneRegionObject->ligoZoneRegion();
|
i.next();
|
||||||
|
const NLLIGO::CZoneRegion ®ion = i.value().zoneRegionObject->ligoZoneRegion();
|
||||||
|
|
||||||
if (m_minX > region.getMinX())
|
if (m_minX > region.getMinX())
|
||||||
m_minX = region.getMinX();
|
m_minX = region.getMinX();
|
||||||
|
@ -370,10 +355,13 @@ void ZoneBuilder::calcMask()
|
||||||
{
|
{
|
||||||
m_zoneMask[x - m_minX + (y - m_minY) * stride] = true;
|
m_zoneMask[x - m_minX + (y - m_minY) * stride] = true;
|
||||||
|
|
||||||
for (size_t i = 0; i < m_landscapeItems.size(); ++i)
|
QMapIterator<int, LandscapeItem> it(m_landscapeMap);
|
||||||
if (int(i) != m_currentZoneRegion)
|
while (it.hasNext())
|
||||||
|
{
|
||||||
|
it.next();
|
||||||
|
if (int(it.key()) != m_currentZoneRegion)
|
||||||
{
|
{
|
||||||
const NLLIGO::CZoneRegion ®ion = zoneRegion(i)->ligoZoneRegion();
|
const NLLIGO::CZoneRegion ®ion = it.value().zoneRegionObject->ligoZoneRegion();
|
||||||
|
|
||||||
const std::string &rSZone = region.getName (x, y);
|
const std::string &rSZone = region.getName (x, y);
|
||||||
if ((rSZone != STRING_OUT_OF_BOUND) && (rSZone != STRING_UNUSED))
|
if ((rSZone != STRING_OUT_OF_BOUND) && (rSZone != STRING_UNUSED))
|
||||||
|
@ -381,21 +369,24 @@ void ZoneBuilder::calcMask()
|
||||||
m_zoneMask[x - m_minX + (y - m_minY) * stride] = false;
|
m_zoneMask[x - m_minX + (y - m_minY) * stride] = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZoneBuilder::getZoneAmongRegions(ZonePosition &zonePos, BuilderZoneRegion *builderZoneRegionFrom, sint32 x, sint32 y)
|
bool ZoneBuilder::getZoneAmongRegions(ZonePosition &zonePos, BuilderZoneRegion *builderZoneRegionFrom, sint32 x, sint32 y)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < m_landscapeItems.size(); ++i)
|
QMapIterator<int, LandscapeItem> it(m_landscapeMap);
|
||||||
|
while (it.hasNext())
|
||||||
{
|
{
|
||||||
const NLLIGO::CZoneRegion ®ion = m_landscapeItems.at(i).zoneRegionObject->ligoZoneRegion();
|
it.next();
|
||||||
|
const NLLIGO::CZoneRegion ®ion = it.value().zoneRegionObject->ligoZoneRegion();
|
||||||
if ((x < region.getMinX()) || (x > region.getMaxX()) ||
|
if ((x < region.getMinX()) || (x > region.getMaxX()) ||
|
||||||
(y < region.getMinY()) || (y > region.getMaxY()))
|
(y < region.getMinY()) || (y > region.getMaxY()))
|
||||||
continue;
|
continue;
|
||||||
if (region.getName(x, y) != STRING_UNUSED)
|
if (region.getName(x, y) != STRING_UNUSED)
|
||||||
{
|
{
|
||||||
builderZoneRegionFrom = m_landscapeItems.at(i).builderZoneRegion;
|
builderZoneRegionFrom = it.value().builderZoneRegion;
|
||||||
zonePos = ZonePosition(x, y, i);
|
zonePos = ZonePosition(x, y, it.key());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -435,9 +426,11 @@ void ZoneBuilder::checkEndMacro()
|
||||||
|
|
||||||
bool ZoneBuilder::checkOverlaps(const NLLIGO::CZoneRegion &newZoneRegion)
|
bool ZoneBuilder::checkOverlaps(const NLLIGO::CZoneRegion &newZoneRegion)
|
||||||
{
|
{
|
||||||
for (size_t j = 0; j < m_landscapeItems.size(); ++j)
|
QMapIterator<int, LandscapeItem> it(m_landscapeMap);
|
||||||
|
while (it.hasNext())
|
||||||
{
|
{
|
||||||
const NLLIGO::CZoneRegion &zoneRegion = m_landscapeItems.at(j).zoneRegionObject->ligoZoneRegion();
|
it.next();
|
||||||
|
const NLLIGO::CZoneRegion &zoneRegion = it.value().zoneRegionObject->ligoZoneRegion();
|
||||||
for (sint32 y = zoneRegion.getMinY(); y <= zoneRegion.getMaxY(); ++y)
|
for (sint32 y = zoneRegion.getMinY(); y <= zoneRegion.getMaxY(); ++y)
|
||||||
for (sint32 x = zoneRegion.getMinX(); x <= zoneRegion.getMaxX(); ++x)
|
for (sint32 x = zoneRegion.getMinX(); x <= zoneRegion.getMaxX(); ++x)
|
||||||
{
|
{
|
||||||
|
|
|
@ -85,7 +85,6 @@ public:
|
||||||
bool init(const QString &pathName, bool bMakeAZone);
|
bool init(const QString &pathName, bool bMakeAZone);
|
||||||
|
|
||||||
void calcMask();
|
void calcMask();
|
||||||
void newZone();
|
|
||||||
bool getZoneMask (sint32 x, sint32 y);
|
bool getZoneMask (sint32 x, sint32 y);
|
||||||
bool getZoneAmongRegions(ZonePosition &zonePos, BuilderZoneRegion *builderZoneRegionFrom, sint32 x, sint32 y);
|
bool getZoneAmongRegions(ZonePosition &zonePos, BuilderZoneRegion *builderZoneRegionFrom, sint32 x, sint32 y);
|
||||||
|
|
||||||
|
@ -150,7 +149,8 @@ private:
|
||||||
QString m_lastPathName;
|
QString m_lastPathName;
|
||||||
|
|
||||||
int m_currentZoneRegion;
|
int m_currentZoneRegion;
|
||||||
std::vector<LandscapeItem> m_landscapeItems;
|
//std::vector<LandscapeItem> m_landscapeItems;
|
||||||
|
QMap<int, LandscapeItem> m_landscapeMap;
|
||||||
|
|
||||||
bool m_createdAction;
|
bool m_createdAction;
|
||||||
QString m_titleAction;
|
QString m_titleAction;
|
||||||
|
|
|
@ -75,7 +75,7 @@ QString LandscapeEditorPlugin::name() const
|
||||||
|
|
||||||
QString LandscapeEditorPlugin::version() const
|
QString LandscapeEditorPlugin::version() const
|
||||||
{
|
{
|
||||||
return "0.0.1";
|
return "0.1";
|
||||||
}
|
}
|
||||||
|
|
||||||
QString LandscapeEditorPlugin::vendor() const
|
QString LandscapeEditorPlugin::vendor() const
|
||||||
|
|
|
@ -46,7 +46,7 @@ QString _lastDir;
|
||||||
|
|
||||||
LandscapeEditorWindow::LandscapeEditorWindow(QWidget *parent)
|
LandscapeEditorWindow::LandscapeEditorWindow(QWidget *parent)
|
||||||
: QMainWindow(parent),
|
: QMainWindow(parent),
|
||||||
m_currentRow(-1),
|
m_currentItem(0),
|
||||||
m_landscapeScene(0),
|
m_landscapeScene(0),
|
||||||
m_zoneBuilder(0),
|
m_zoneBuilder(0),
|
||||||
m_undoStack(0),
|
m_undoStack(0),
|
||||||
|
@ -65,8 +65,7 @@ LandscapeEditorWindow::LandscapeEditorWindow(QWidget *parent)
|
||||||
m_landscapeScene->setZoneBuilder(m_zoneBuilder);
|
m_landscapeScene->setZoneBuilder(m_zoneBuilder);
|
||||||
m_ui.graphicsView->setScene(m_landscapeScene);
|
m_ui.graphicsView->setScene(m_landscapeScene);
|
||||||
//m_oglWidget = new QGLWidget(QGLFormat(QGL::DoubleBuffer));
|
//m_oglWidget = new QGLWidget(QGLFormat(QGL::DoubleBuffer));
|
||||||
m_oglWidget = new QGLWidget(QGLFormat(QGL::DoubleBuffer | QGL::SampleBuffers));
|
//m_ui.graphicsView->setViewport(m_oglWidget);
|
||||||
m_ui.graphicsView->setViewport(m_oglWidget);
|
|
||||||
|
|
||||||
m_ui.newLandAction->setIcon(QIcon(Core::Constants::ICON_NEW));
|
m_ui.newLandAction->setIcon(QIcon(Core::Constants::ICON_NEW));
|
||||||
m_ui.saveAction->setIcon(QIcon(Core::Constants::ICON_SAVE));
|
m_ui.saveAction->setIcon(QIcon(Core::Constants::ICON_SAVE));
|
||||||
|
@ -128,7 +127,7 @@ void LandscapeEditorWindow::open()
|
||||||
|
|
||||||
void LandscapeEditorWindow::save()
|
void LandscapeEditorWindow::save()
|
||||||
{
|
{
|
||||||
saveLandscape(m_currentRow, true);
|
saveLandscape(m_ui.landscapesListWidget->row(m_currentItem), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LandscapeEditorWindow::openProjectSettings()
|
void LandscapeEditorWindow::openProjectSettings()
|
||||||
|
@ -203,7 +202,9 @@ void LandscapeEditorWindow::customContextMenu()
|
||||||
|
|
||||||
void LandscapeEditorWindow::newLand()
|
void LandscapeEditorWindow::newLand()
|
||||||
{
|
{
|
||||||
createLandscape(QString());
|
int row = createLandscape(QString());
|
||||||
|
if (row != -1)
|
||||||
|
setActiveLandscape(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LandscapeEditorWindow::setActiveLand()
|
void LandscapeEditorWindow::setActiveLand()
|
||||||
|
@ -224,8 +225,9 @@ void LandscapeEditorWindow::saveAsSelectedLand()
|
||||||
void LandscapeEditorWindow::deleteSelectedLand()
|
void LandscapeEditorWindow::deleteSelectedLand()
|
||||||
{
|
{
|
||||||
int row = m_ui.landscapesListWidget->currentRow();
|
int row = m_ui.landscapesListWidget->currentRow();
|
||||||
|
int current_row = m_ui.landscapesListWidget->row(m_currentItem);
|
||||||
QListWidgetItem *item = m_ui.landscapesListWidget->item(row);
|
QListWidgetItem *item = m_ui.landscapesListWidget->item(row);
|
||||||
if (row == m_currentRow)
|
if (row == current_row)
|
||||||
{
|
{
|
||||||
if (row == 0)
|
if (row == 0)
|
||||||
++row;
|
++row;
|
||||||
|
@ -236,6 +238,7 @@ void LandscapeEditorWindow::deleteSelectedLand()
|
||||||
m_zoneBuilder->deleteZoneRegion(item->data(LANDSCAPE_ID).toInt());
|
m_zoneBuilder->deleteZoneRegion(item->data(LANDSCAPE_ID).toInt());
|
||||||
m_ui.landscapesListWidget->removeItemWidget(item);
|
m_ui.landscapesListWidget->removeItemWidget(item);
|
||||||
delete item;
|
delete item;
|
||||||
|
|
||||||
if (m_ui.landscapesListWidget->count() == 1)
|
if (m_ui.landscapesListWidget->count() == 1)
|
||||||
m_ui.deleteLandAction->setEnabled(false);
|
m_ui.deleteLandAction->setEnabled(false);
|
||||||
}
|
}
|
||||||
|
@ -276,15 +279,13 @@ void LandscapeEditorWindow::setActiveLandscape(int row)
|
||||||
{
|
{
|
||||||
if ((0 <= row) && (row < m_ui.landscapesListWidget->count()))
|
if ((0 <= row) && (row < m_ui.landscapesListWidget->count()))
|
||||||
{
|
{
|
||||||
if (m_currentRow != -1)
|
if (m_currentItem != 0)
|
||||||
{
|
m_currentItem->setFont(QFont("SansSerif", 9, QFont::Normal));
|
||||||
QListWidgetItem *item = m_ui.landscapesListWidget->item(m_currentRow);
|
|
||||||
item->setFont(QFont("SansSerif", 9, QFont::Normal));
|
|
||||||
}
|
|
||||||
QListWidgetItem *item = m_ui.landscapesListWidget->item(row);
|
QListWidgetItem *item = m_ui.landscapesListWidget->item(row);
|
||||||
item->setFont(QFont("SansSerif", 9, QFont::Bold));
|
item->setFont(QFont("SansSerif", 9, QFont::Bold));
|
||||||
m_zoneBuilder->setCurrentZoneRegion(item->data(LANDSCAPE_ID).toInt());
|
m_zoneBuilder->setCurrentZoneRegion(item->data(LANDSCAPE_ID).toInt());
|
||||||
m_currentRow = row;
|
m_currentItem = item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -337,16 +338,11 @@ void LandscapeEditorWindow::createToolBars()
|
||||||
m_ui.fileToolBar->addAction(action);
|
m_ui.fileToolBar->addAction(action);
|
||||||
m_ui.fileToolBar->addAction(m_ui.saveAction);
|
m_ui.fileToolBar->addAction(m_ui.saveAction);
|
||||||
|
|
||||||
const char * const UNDO = "ObjectViewerQt.Undo";
|
action = menuManager->action(Core::Constants::UNDO);
|
||||||
const char * const REDO = "ObjectViewerQt.Redo";
|
|
||||||
|
|
||||||
//action = menuManager->action(Core::Constants::UNDO);
|
|
||||||
action = menuManager->action(UNDO);
|
|
||||||
if (action != 0)
|
if (action != 0)
|
||||||
m_ui.undoToolBar->addAction(action);
|
m_ui.undoToolBar->addAction(action);
|
||||||
|
|
||||||
//action = menuManager->action(Core::Constants::REDO);
|
action = menuManager->action(Core::Constants::REDO);
|
||||||
action = menuManager->action(REDO);
|
|
||||||
if (action != 0)
|
if (action != 0)
|
||||||
m_ui.undoToolBar->addAction(action);
|
m_ui.undoToolBar->addAction(action);
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,7 @@ private:
|
||||||
void saveLandscape(int row, bool force);
|
void saveLandscape(int row, bool force);
|
||||||
int createLandscape(const QString &fileName);
|
int createLandscape(const QString &fileName);
|
||||||
|
|
||||||
int m_currentRow;
|
QListWidgetItem *m_currentItem;
|
||||||
LandscapeScene *m_landscapeScene;
|
LandscapeScene *m_landscapeScene;
|
||||||
ZoneBuilder *m_zoneBuilder;
|
ZoneBuilder *m_zoneBuilder;
|
||||||
QUndoStack *m_undoStack;
|
QUndoStack *m_undoStack;
|
||||||
|
|
|
@ -38,6 +38,18 @@
|
||||||
<property name="dragMode">
|
<property name="dragMode">
|
||||||
<enum>QGraphicsView::NoDrag</enum>
|
<enum>QGraphicsView::NoDrag</enum>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="transformationAnchor">
|
||||||
|
<enum>QGraphicsView::AnchorUnderMouse</enum>
|
||||||
|
</property>
|
||||||
|
<property name="resizeAnchor">
|
||||||
|
<enum>QGraphicsView::AnchorUnderMouse</enum>
|
||||||
|
</property>
|
||||||
|
<property name="viewportUpdateMode">
|
||||||
|
<enum>QGraphicsView::FullViewportUpdate</enum>
|
||||||
|
</property>
|
||||||
|
<property name="optimizationFlags">
|
||||||
|
<set>QGraphicsView::DontSavePainterState</set>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include <QtGui/QPainter>
|
#include <QtGui/QPainter>
|
||||||
#include <QtGui/QGraphicsPixmapItem>
|
#include <QtGui/QGraphicsPixmapItem>
|
||||||
#include <QtGui/QGraphicsSimpleTextItem>
|
#include <QtGui/QGraphicsSimpleTextItem>
|
||||||
|
#include <QApplication>
|
||||||
|
|
||||||
namespace LandscapeEditor
|
namespace LandscapeEditor
|
||||||
{
|
{
|
||||||
|
@ -34,11 +35,13 @@ static const int ZONE_NAME = 0;
|
||||||
static const int LAYER_ZONES = 2;
|
static const int LAYER_ZONES = 2;
|
||||||
static const int LAYER_EMPTY_ZONES = 3;
|
static const int LAYER_EMPTY_ZONES = 3;
|
||||||
static const int LAYER_BLACKOUT = 4;
|
static const int LAYER_BLACKOUT = 4;
|
||||||
|
const char * const LAYER_BLACKOUT_NAME = "blackout";
|
||||||
|
|
||||||
LandscapeScene::LandscapeScene(QObject *parent)
|
LandscapeScene::LandscapeScene(QObject *parent)
|
||||||
: QGraphicsScene(parent),
|
: QGraphicsScene(parent),
|
||||||
m_mouseX(0.0),
|
m_mouseX(0.0),
|
||||||
m_mouseY(0.0),
|
m_mouseY(0.0),
|
||||||
|
m_mouseButton(Qt::NoButton),
|
||||||
m_zoneBuilder(0)
|
m_zoneBuilder(0)
|
||||||
{
|
{
|
||||||
m_cellSize = 160;
|
m_cellSize = 160;
|
||||||
|
@ -154,7 +157,7 @@ QGraphicsItem *LandscapeScene::createItemZone(const LigoData &data, const ZonePo
|
||||||
// The size graphics item should be equal or proportional m_cellSize
|
// The size graphics item should be equal or proportional m_cellSize
|
||||||
item->setScale(float(m_cellSize) / m_zoneBuilder->pixmapDatabase()->textureSize());
|
item->setScale(float(m_cellSize) / m_zoneBuilder->pixmapDatabase()->textureSize());
|
||||||
|
|
||||||
//item->setData(ZONE_NAME, QString(data.zoneName.c_str()));
|
item->setData(ZONE_NAME, QString(data.zoneName.c_str()));
|
||||||
|
|
||||||
// for not full item zone
|
// for not full item zone
|
||||||
item->setZValue(LAYER_ZONES);
|
item->setZValue(LAYER_ZONES);
|
||||||
|
@ -198,13 +201,14 @@ QGraphicsRectItem *LandscapeScene::createLayerBlackout(const NLLIGO::CZoneRegion
|
||||||
Qt::NoPen, QBrush(QColor(0, 0, 0, 50)));
|
Qt::NoPen, QBrush(QColor(0, 0, 0, 50)));
|
||||||
|
|
||||||
rectItem->setZValue(LAYER_BLACKOUT);
|
rectItem->setZValue(LAYER_BLACKOUT);
|
||||||
|
rectItem->setData(ZONE_NAME, QString(LAYER_BLACKOUT_NAME));
|
||||||
return rectItem;
|
return rectItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LandscapeScene::deleteItemZone(const ZonePosition &zonePos)
|
void LandscapeScene::deleteItemZone(const ZonePosition &zonePos)
|
||||||
{
|
{
|
||||||
QGraphicsItem *item = itemAt(zonePos.x * m_cellSize, abs(zonePos.y) * m_cellSize);
|
QGraphicsItem *item = itemAt(zonePos.x * m_cellSize, abs(zonePos.y) * m_cellSize);
|
||||||
if (item != 0)
|
if ((item != 0) && (item->data(ZONE_NAME).toString() != QString(LAYER_BLACKOUT_NAME)))
|
||||||
{
|
{
|
||||||
removeItem(item);
|
removeItem(item);
|
||||||
delete item;
|
delete item;
|
||||||
|
@ -282,30 +286,60 @@ void LandscapeScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||||
if ((x < 0) || (y < 0))
|
if ((x < 0) || (y < 0))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
sint32 posX = sint32(floor(x / m_cellSize));
|
m_posX = sint32(floor(x / m_cellSize));
|
||||||
sint32 posY = sint32(-floor(y / m_cellSize));
|
m_posY = sint32(-floor(y / m_cellSize));
|
||||||
|
|
||||||
if (mouseEvent->button() == Qt::LeftButton)
|
if (mouseEvent->button() == Qt::LeftButton)
|
||||||
m_zoneBuilder->addZone(posX, posY);
|
m_zoneBuilder->addZone(m_posX, m_posY);
|
||||||
else if (mouseEvent->button() == Qt::RightButton)
|
else if (mouseEvent->button() == Qt::RightButton)
|
||||||
m_zoneBuilder->delZone(posX, posY);
|
m_zoneBuilder->delZone(m_posX, m_posY);
|
||||||
|
|
||||||
|
m_mouseButton = mouseEvent->button();
|
||||||
|
|
||||||
QGraphicsScene::mousePressEvent(mouseEvent);
|
QGraphicsScene::mousePressEvent(mouseEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LandscapeScene::mouseMoveEvent(QGraphicsSceneMouseEvent * mouseEvent)
|
void LandscapeScene::mouseMoveEvent(QGraphicsSceneMouseEvent * mouseEvent)
|
||||||
{
|
{
|
||||||
|
qreal x = mouseEvent->scenePos().rx();
|
||||||
|
qreal y = mouseEvent->scenePos().ry();
|
||||||
|
|
||||||
|
sint32 posX = sint32(floor(x / m_cellSize));
|
||||||
|
sint32 posY = sint32(-floor(y / m_cellSize));
|
||||||
|
|
||||||
|
if ((m_posX != posX || m_posY != posY) &&
|
||||||
|
(m_mouseButton == Qt::LeftButton ||
|
||||||
|
m_mouseButton == Qt::RightButton))
|
||||||
|
{
|
||||||
|
if (m_mouseButton == Qt::LeftButton)
|
||||||
|
m_zoneBuilder->addZone(posX, posY);
|
||||||
|
else if (m_mouseButton == Qt::RightButton)
|
||||||
|
m_zoneBuilder->delZone(posX, posY);
|
||||||
|
|
||||||
|
m_posX = posX;
|
||||||
|
m_posY = posY;
|
||||||
|
QApplication::processEvents();
|
||||||
|
}
|
||||||
|
|
||||||
m_mouseX = mouseEvent->scenePos().x();
|
m_mouseX = mouseEvent->scenePos().x();
|
||||||
m_mouseY = mouseEvent->scenePos().y();
|
m_mouseY = mouseEvent->scenePos().y();
|
||||||
QGraphicsScene::mouseMoveEvent(mouseEvent);
|
QGraphicsScene::mouseMoveEvent(mouseEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LandscapeScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||||
|
{
|
||||||
|
m_mouseButton = Qt::NoButton;
|
||||||
|
}
|
||||||
|
|
||||||
bool LandscapeScene::checkUnderZone(const int posX, const int posY)
|
bool LandscapeScene::checkUnderZone(const int posX, const int posY)
|
||||||
{
|
{
|
||||||
QGraphicsItem *item = itemAt((posX * m_cellSize), abs(posY) * m_cellSize);
|
QGraphicsItem *item = itemAt((posX * m_cellSize), abs(posY) * m_cellSize);
|
||||||
if (item != 0)
|
if (item != 0)
|
||||||
{
|
{
|
||||||
return true;
|
if (item->data(ZONE_NAME) == QString(LAYER_BLACKOUT_NAME))
|
||||||
|
return false;
|
||||||
|
else
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,6 +62,7 @@ public:
|
||||||
protected:
|
protected:
|
||||||
virtual void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent);
|
virtual void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent);
|
||||||
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent);
|
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent);
|
||||||
|
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent);
|
||||||
virtual void drawForeground(QPainter *painter, const QRectF &rect);
|
virtual void drawForeground(QPainter *painter, const QRectF &rect);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -69,6 +70,8 @@ private:
|
||||||
|
|
||||||
int m_cellSize;
|
int m_cellSize;
|
||||||
qreal m_mouseX, m_mouseY;
|
qreal m_mouseX, m_mouseY;
|
||||||
|
sint32 m_posX, m_posY;
|
||||||
|
Qt::MouseButton m_mouseButton;
|
||||||
ZoneBuilder *m_zoneBuilder;
|
ZoneBuilder *m_zoneBuilder;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue