Changed: #1301 Updated LandscapeSceneBase and ZoneBuilderBase classes for world editor plugin.

This commit is contained in:
dnk-88 2011-07-30 21:50:30 +03:00
parent 5e6bccdd11
commit 0ef659c13d
6 changed files with 72 additions and 185 deletions

View file

@ -17,8 +17,9 @@
// Project includes
#include "builder_zone_base.h"
#include "list_zones_widget.h"
#include "landscape_actions.h"
#include "landscape_scene_base.h"
#include "zone_region_editor.h"
#include "pixmap_database.h"
// NeL includes
#include <nel/misc/debug.h>
@ -32,12 +33,11 @@ namespace LandscapeEditor
{
int NewLandId = 0;
ZoneBuilderBase::ZoneBuilderBase(LandscapeScene *landscapeScene)
: m_currentZoneRegion(-1),
m_pixmapDatabase(0),
m_landscapeScene(landscapeScene)
ZoneBuilderBase::ZoneBuilderBase(LandscapeSceneBase *landscapeScene)
: m_pixmapDatabase(0),
m_landscapeSceneBase(landscapeScene)
{
nlassert(m_landscapeScene);
nlassert(m_landscapeSceneBase);
m_pixmapDatabase = new PixmapDatabase();
m_lastPathName = "";
}
@ -77,23 +77,7 @@ bool ZoneBuilderBase::init(const QString &pathName, bool displayProgress)
return true;
}
int ZoneBuilderBase::createZoneRegion()
{
LandscapeItem landItem;
landItem.zoneRegionObject = new ZoneRegionObject();
// landItem.builderZoneRegion = new BuilderZoneRegion(LandCounter);
// landItem.builderZoneRegion->init(this);
landItem.rectItem = m_landscapeScene->createLayerBlackout(landItem.zoneRegionObject->ligoZoneRegion());
m_landscapeMap.insert(NewLandId, landItem);
if (m_currentZoneRegion == -1)
setCurrentZoneRegion(NewLandId);
calcMask();
return NewLandId++;
}
int ZoneBuilderBase::createZoneRegion(const QString &fileName)
int ZoneBuilderBase::loadZoneRegion(const QString &fileName)
{
LandscapeItem landItem;
landItem.zoneRegionObject = new ZoneRegionObject();
@ -107,13 +91,10 @@ int ZoneBuilderBase::createZoneRegion(const QString &fileName)
// landItem.builderZoneRegion = new BuilderZoneRegion(LandCounter);
// landItem.builderZoneRegion->init(this);
m_landscapeScene->addZoneRegion(landItem.zoneRegionObject->ligoZoneRegion());
landItem.rectItem = m_landscapeScene->createLayerBlackout(landItem.zoneRegionObject->ligoZoneRegion());
m_landscapeSceneBase->addZoneRegion(landItem.zoneRegionObject->ligoZoneRegion());
// landItem.rectItem = m_landscapeScene->createLayerBlackout(landItem.zoneRegionObject->ligoZoneRegion());
m_landscapeMap.insert(NewLandId, landItem);
if (m_currentZoneRegion == -1)
setCurrentZoneRegion(NewLandId);
calcMask();
return NewLandId++;
}
@ -122,9 +103,7 @@ void ZoneBuilderBase::deleteZoneRegion(int id)
{
if (m_landscapeMap.contains(id))
{
if (m_landscapeMap.value(id).rectItem != 0)
delete m_landscapeMap.value(id).rectItem;
m_landscapeScene->delZoneRegion(m_landscapeMap.value(id).zoneRegionObject->ligoZoneRegion());
m_landscapeSceneBase->delZoneRegion(m_landscapeMap.value(id).zoneRegionObject->ligoZoneRegion());
delete m_landscapeMap.value(id).zoneRegionObject;
// delete m_landscapeMap.value(id).builderZoneRegion;
m_landscapeMap.remove(id);
@ -134,34 +113,6 @@ void ZoneBuilderBase::deleteZoneRegion(int id)
nlwarning("Landscape (id %i) not found", id);
}
void ZoneBuilderBase::setCurrentZoneRegion(int id)
{
if (m_landscapeMap.contains(id))
{
if (currentIdZoneRegion() != -1)
{
NLLIGO::CZoneRegion &ligoRegion = m_landscapeMap.value(m_currentZoneRegion).zoneRegionObject->ligoZoneRegion();
m_landscapeMap[m_currentZoneRegion].rectItem = m_landscapeScene->createLayerBlackout(ligoRegion);
}
delete m_landscapeMap.value(id).rectItem;
m_landscapeMap[id].rectItem = 0;
m_currentZoneRegion = id;
calcMask();
}
else
nlwarning("Landscape (id %i) not found", id);
}
int ZoneBuilderBase::currentIdZoneRegion() const
{
return m_currentZoneRegion;
}
ZoneRegionObject *ZoneBuilderBase::currentZoneRegion() const
{
return m_landscapeMap.value(m_currentZoneRegion).zoneRegionObject;
}
int ZoneBuilderBase::countZoneRegion() const
{
return m_landscapeMap.size();
@ -172,16 +123,6 @@ ZoneRegionObject *ZoneBuilderBase::zoneRegion(int id) const
return m_landscapeMap.value(id).zoneRegionObject;
}
void ZoneBuilderBase::ligoData(LigoData &data, const ZonePosition &zonePos)
{
m_landscapeMap.value(zonePos.region).zoneRegionObject->ligoData(data, zonePos.x, zonePos.y);
}
void ZoneBuilderBase::setLigoData(LigoData &data, const ZonePosition &zonePos)
{
m_landscapeMap.value(zonePos.region).zoneRegionObject->setLigoData(data, zonePos.x, zonePos.y);
}
bool ZoneBuilderBase::initZoneBank (const QString &pathName)
{
QDir *dir = new QDir(pathName);
@ -212,23 +153,8 @@ QString ZoneBuilderBase::dataPath() const
return m_lastPathName;
}
bool ZoneBuilderBase::getZoneMask(sint32 x, sint32 y)
{
if ((x < m_minX) || (x > m_maxX) ||
(y < m_minY) || (y > m_maxY))
{
return true;
}
else
{
return m_zoneMask[(x - m_minX) + (y - m_minY) * (1 + m_maxX - m_minX)];
}
}
void ZoneBuilderBase::calcMask()
{
sint32 x, y;
m_minY = m_minX = 1000000;
m_maxY = m_maxX = -1000000;
@ -250,30 +176,6 @@ void ZoneBuilderBase::calcMask()
if (m_maxY < region.getMaxY())
m_maxY = region.getMaxY();
}
m_zoneMask.resize ((1 + m_maxX - m_minX) * (1 + m_maxY - m_minY));
sint32 stride = (1 + m_maxX - m_minX);
for (y = m_minY; y <= m_maxY; ++y)
for (x = m_minX; x <= m_maxX; ++x)
{
m_zoneMask[x - m_minX + (y - m_minY) * stride] = true;
QMapIterator<int, LandscapeItem> it(m_landscapeMap);
while (it.hasNext())
{
it.next();
if (int(it.key()) != m_currentZoneRegion)
{
const NLLIGO::CZoneRegion &region = it.value().zoneRegionObject->ligoZoneRegion();
const std::string &rSZone = region.getName (x, y);
if ((rSZone != STRING_OUT_OF_BOUND) && (rSZone != STRING_UNUSED))
{
m_zoneMask[x - m_minX + (y - m_minY) * stride] = false;
}
}
}
}
}
bool ZoneBuilderBase::checkOverlaps(const NLLIGO::CZoneRegion &newZoneRegion)

View file

@ -19,8 +19,6 @@
#define BUILDER_ZONE_BASE_H
// Project includes
#include "zone_region_editor.h"
#include "pixmap_database.h"
#include "landscape_editor_global.h"
// NeL includes
@ -41,7 +39,9 @@
namespace LandscapeEditor
{
class LandscapeScene;
class LandscapeSceneBase;
class PixmapDatabase;
class ZoneRegionObject;
// Data
struct ZonePosition
@ -75,27 +75,18 @@ PixmapDatabase contains the graphics for the zones
class LANDSCAPE_EDITOR_EXPORT ZoneBuilderBase
{
public:
ZoneBuilderBase(LandscapeScene *landscapeScene);
ZoneBuilderBase(LandscapeSceneBase *landscapeScene);
virtual ~ZoneBuilderBase();
/// Init zoneBank and init zone pixmap database
bool init(const QString &pathName, bool displayProgress = false);
void calcMask();
bool getZoneMask (sint32 x, sint32 y);
/// Zone Region
/// @{
int createZoneRegion();
int createZoneRegion(const QString &fileName);
int loadZoneRegion(const QString &fileName);
void deleteZoneRegion(int id);
void setCurrentZoneRegion(int id);
int currentIdZoneRegion() const;
ZoneRegionObject *currentZoneRegion() const;
int countZoneRegion() const;
ZoneRegionObject *zoneRegion(int id) const;
void ligoData(LigoData &data, const ZonePosition &zonePos);
void setLigoData(LigoData &data, const ZonePosition &zonePos);
/// @}
// Accessors
@ -113,25 +104,24 @@ private:
/// Scan ./zoneligos dir and add all *.ligozone files to zoneBank
bool initZoneBank (const QString &path);
void calcMask();
bool checkOverlaps(const NLLIGO::CZoneRegion &newZoneRegion);
struct LandscapeItem
{
ZoneRegionObject *zoneRegionObject;
QGraphicsRectItem *rectItem;
};
sint32 m_minX, m_maxX, m_minY, m_maxY;
std::vector<bool> m_zoneMask;
QString m_lastPathName;
int m_currentZoneRegion;
QMap<int, LandscapeItem> m_landscapeMap;
PixmapDatabase *m_pixmapDatabase;
NLLIGO::CZoneBank m_zoneBank;
LandscapeScene *m_landscapeScene;
LandscapeSceneBase *m_landscapeSceneBase;
};
} /* namespace LandscapeEditor */

View file

@ -29,13 +29,12 @@
namespace LandscapeEditor
{
static const int ZONE_NAME = 0;
static const int LAYER_ZONES = 2;
static const int LAYER_EMPTY_ZONES = 3;
// TODO: delete
const char * const LAYER_BLACKOUT_NAME = "blackout";
const char *const LAYER_BLACKOUT_NAME = "blackout";
const int MAX_SCENE_WIDTH = 256;
const int MAX_SCENE_HEIGHT = 256;
@ -43,7 +42,7 @@ const int MAX_SCENE_HEIGHT = 256;
LandscapeSceneBase::LandscapeSceneBase(int sizeCell, QObject *parent)
: QGraphicsScene(parent),
m_cellSize(sizeCell),
m_zoneBuilder(0)
m_zoneBuilderBase(0)
{
setSceneRect(QRectF(0, m_cellSize, MAX_SCENE_WIDTH * m_cellSize, MAX_SCENE_HEIGHT * m_cellSize));
}
@ -57,9 +56,9 @@ int LandscapeSceneBase::cellSize() const
return m_cellSize;
}
void LandscapeSceneBase::setZoneBuilder(ZoneBuilder *zoneBuilder)
void LandscapeSceneBase::setZoneBuilder(ZoneBuilderBase *zoneBuilder)
{
m_zoneBuilder = zoneBuilder;
m_zoneBuilderBase = zoneBuilder;
}
QGraphicsItem *LandscapeSceneBase::createItemZone(const LigoData &data, const ZonePosition &zonePos)
@ -70,11 +69,11 @@ QGraphicsItem *LandscapeSceneBase::createItemZone(const LigoData &data, const Zo
if (data.zoneName == STRING_UNUSED)
return createItemEmptyZone(zonePos);
if ((m_zoneBuilder == 0) || (data.zoneName.empty()))
if ((m_zoneBuilderBase == 0) || (data.zoneName.empty()))
return 0;
// Get image from pixmap database
QPixmap *pixmap = m_zoneBuilder->pixmapDatabase()->pixmap(QString(data.zoneName.c_str()));
QPixmap *pixmap = m_zoneBuilderBase->pixmapDatabase()->pixmap(QString(data.zoneName.c_str()));
if (pixmap == 0)
return 0;
@ -98,7 +97,7 @@ QGraphicsItem *LandscapeSceneBase::createItemZone(const LigoData &data, const Zo
// Enable bilinear filtering
item->setTransformationMode(Qt::SmoothTransformation);
NLLIGO::CZoneBankElement *zoneBankItem = m_zoneBuilder->getZoneBank().getElementByZoneName(data.zoneName);
NLLIGO::CZoneBankElement *zoneBankItem = m_zoneBuilderBase->getZoneBank().getElementByZoneName(data.zoneName);
sint32 deltaX = 0, deltaY = 0;
@ -156,7 +155,7 @@ QGraphicsItem *LandscapeSceneBase::createItemZone(const LigoData &data, const Zo
item->setPos((zonePos.x + deltaX) * m_cellSize, (abs(int(zonePos.y + deltaY))) * 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_zoneBuilderBase->pixmapDatabase()->textureSize());
item->setData(ZONE_NAME, QString(data.zoneName.c_str()));
@ -168,14 +167,14 @@ QGraphicsItem *LandscapeSceneBase::createItemZone(const LigoData &data, const Zo
QGraphicsItem *LandscapeSceneBase::createItemEmptyZone(const ZonePosition &zonePos)
{
if (m_zoneBuilder == 0)
if (m_zoneBuilderBase == 0)
return 0;
if (checkUnderZone(zonePos.x, zonePos.y))
return 0;
// Get image from pixmap database
QPixmap *pixmap = m_zoneBuilder->pixmapDatabase()->pixmap(QString(STRING_UNUSED));
QPixmap *pixmap = m_zoneBuilderBase->pixmapDatabase()->pixmap(QString(STRING_UNUSED));
if (pixmap == 0)
return 0;
@ -188,7 +187,7 @@ QGraphicsItem *LandscapeSceneBase::createItemEmptyZone(const ZonePosition &zoneP
item->setPos(zonePos.x * m_cellSize, abs(int(zonePos.y)) * 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_zoneBuilderBase->pixmapDatabase()->textureSize());
// for not full item zone
item->setZValue(LAYER_EMPTY_ZONES);
@ -249,7 +248,7 @@ void LandscapeSceneBase::delZoneRegion(const NLLIGO::CZoneRegion &zoneRegion)
void LandscapeSceneBase::snapshot(const QString &fileName, int width, int height, const QRectF &landRect)
{
if (m_zoneBuilder == 0)
if (m_zoneBuilderBase == 0)
return;
// Create image
@ -291,7 +290,7 @@ void LandscapeSceneBase::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
m_mouseButton = mouseEvent->button();
}
void LandscapeSceneBase::mouseMoveEvent(QGraphicsSceneMouseEvent * mouseEvent)
void LandscapeSceneBase::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
m_mouseX = mouseEvent->scenePos().x();
m_mouseY = mouseEvent->scenePos().y() - m_cellSize;

View file

@ -18,9 +18,9 @@
#define LANDSCAPE_SCENE_BASE_H
// Project includes
#include "zone_region_editor.h"
#include "builder_zone.h"
#include "landscape_editor_global.h"
#include "builder_zone_base.h"
#include "zone_region_editor.h"
// NeL includes
#include <nel/ligo/zone_region.h>
@ -46,7 +46,7 @@ public:
virtual ~LandscapeSceneBase();
int cellSize() const;
virtual void setZoneBuilder(ZoneBuilder *zoneBuilder);
void setZoneBuilder(ZoneBuilderBase *zoneBuilder);
QGraphicsItem *createItemZone(const LigoData &data, const ZonePosition &zonePos);
QGraphicsItem *createItemEmptyZone(const ZonePosition &zonePos);
@ -73,7 +73,7 @@ private:
qreal m_mouseX, m_mouseY;
sint32 m_posX, m_posY;
Qt::MouseButton m_mouseButton;
ZoneBuilder *m_zoneBuilder;
ZoneBuilderBase *m_zoneBuilderBase;
};
} /* namespace LandscapeEditor */

View file

@ -30,40 +30,6 @@
namespace LandscapeEditor
{
LigoData::LigoData()
{
posX = 0;
posY = 0;
zoneName = "";
rot = 0;
flip = 0;
sharingMatNames[0] = "";
sharingMatNames[1] = "";
sharingMatNames[2] = "";
sharingMatNames[3] = "";
sharingCutEdges[0] = 0;
sharingCutEdges[1] = 0;
sharingCutEdges[2] = 0;
sharingCutEdges[3] = 0;
}
bool LigoData::operator!= (const LigoData& other) const
{
return (posX != other.posX) ||
(posY != other.posY) ||
(rot != other.rot) ||
(flip != other.flip) ||
(zoneName != other.zoneName) ||
(sharingMatNames[0] != other.sharingMatNames[0]) ||
(sharingMatNames[1] != other.sharingMatNames[1]) ||
(sharingMatNames[2] != other.sharingMatNames[2]) ||
(sharingMatNames[3] != other.sharingMatNames[3]) ||
(sharingCutEdges[0] != other.sharingCutEdges[0]) ||
(sharingCutEdges[1] != other.sharingCutEdges[1]) ||
(sharingCutEdges[2] != other.sharingCutEdges[2]) ||
(sharingCutEdges[3] != other.sharingCutEdges[3]);
}
ZoneRegionObject::ZoneRegionObject()
{
m_fileName = "";
@ -92,7 +58,7 @@ bool ZoneRegionObject::load(const std::string &fileName)
result = false;
}
}
catch (NLMISC::Exception& e)
catch (NLMISC::Exception &e)
{
nlwarning("Error reading file %s : %s", fileName.c_str(), e.what ());
result = false;
@ -132,7 +98,7 @@ bool ZoneRegionObject::save()
result = false;
}
}
catch (NLMISC::Exception& e)
catch (NLMISC::Exception &e)
{
nlwarning("Error writing file %s : %s", m_fileName.c_str(), e.what());
result = false;

View file

@ -19,6 +19,7 @@
#define LANDSCAPE_EDITOR_H
// Project includes
#include "landscape_editor_global.h"
// NeL includes
#include <nel/ligo/zone_bank.h>
@ -43,9 +44,38 @@ struct LigoData
std::string sharingMatNames[4];
uint8 sharingCutEdges[4];
LigoData();
bool operator!= (const LigoData& other) const;
LigoData()
{
posX = 0;
posY = 0;
zoneName = "";
rot = 0;
flip = 0;
sharingMatNames[0] = "";
sharingMatNames[1] = "";
sharingMatNames[2] = "";
sharingMatNames[3] = "";
sharingCutEdges[0] = 0;
sharingCutEdges[1] = 0;
sharingCutEdges[2] = 0;
sharingCutEdges[3] = 0;
}
bool operator!= (const LigoData &other) const
{
return (posX != other.posX) ||
(posY != other.posY) ||
(rot != other.rot) ||
(flip != other.flip) ||
(zoneName != other.zoneName) ||
(sharingMatNames[0] != other.sharingMatNames[0]) ||
(sharingMatNames[1] != other.sharingMatNames[1]) ||
(sharingMatNames[2] != other.sharingMatNames[2]) ||
(sharingMatNames[3] != other.sharingMatNames[3]) ||
(sharingCutEdges[0] != other.sharingCutEdges[0]) ||
(sharingCutEdges[1] != other.sharingCutEdges[1]) ||
(sharingCutEdges[2] != other.sharingCutEdges[2]) ||
(sharingCutEdges[3] != other.sharingCutEdges[3]);
}
};
/**
@ -53,7 +83,7 @@ struct LigoData
@brief
@details
*/
class ZoneRegionObject
class LANDSCAPE_EDITOR_EXPORT ZoneRegionObject
{
public:
ZoneRegionObject();