Changed: #1301 Binding 2d renderer to NELLIGO.

This commit is contained in:
dnk-88 2011-06-28 02:55:38 +03:00
parent 7351dcd33c
commit 8eefc06d30
14 changed files with 2904 additions and 232 deletions

View file

@ -17,6 +17,8 @@
// Project includes
#include "builder_zone.h"
#include "list_zones_widget.h"
#include "landscape_actions.h"
// NeL includes
#include <nel/misc/debug.h>
@ -29,9 +31,9 @@
namespace LandscapeEditor
{
const int PixmapScale = 256;
PixmapDatabase::PixmapDatabase()
: m_textureSize(256)
{
}
@ -66,15 +68,21 @@ bool PixmapDatabase::loadPixmaps(const QString &zonePath, NLLIGO::CZoneBank &zon
// Generate filled pixmap
}
// All pixmaps must be have same size
if (pixmap->width() != sizeX * PixmapScale)
if (pixmap->width() != sizeX * m_textureSize)
{
QPixmap *scaledPixmap = new QPixmap(pixmap->scaled(sizeX * PixmapScale, sizeY * PixmapScale));
QPixmap *scaledPixmap = new QPixmap(pixmap->scaled(sizeX * m_textureSize, sizeY * m_textureSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
delete pixmap;
m_pixmapMap.insert(zonePixmapName, scaledPixmap);
}
else
m_pixmapMap.insert(zonePixmapName, pixmap);
}
QPixmap *pixmap = new QPixmap(zonePath + "_UNUSED_.png");
QPixmap *scaledPixmap = new QPixmap(pixmap->scaled(m_textureSize, m_textureSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
delete pixmap;
m_pixmapMap.insert(QString(STRING_UNUSED), scaledPixmap);
delete progressDialog;
return true;
}
@ -105,8 +113,17 @@ QPixmap *PixmapDatabase::pixmap(const QString &zoneName) const
return result;
}
ZoneBuilder::ZoneBuilder()
: m_pixmapDatabase(0)
int PixmapDatabase::textureSize() const
{
return m_textureSize;
}
ZoneBuilder::ZoneBuilder(ListZonesWidget *listZonesWidget, LandscapeScene *landscapeScene, QUndoStack *undoStack)
: m_currentZoneRegion(-1),
m_pixmapDatabase(0),
m_listZonesWidget(listZonesWidget),
m_landscapeScene(landscapeScene),
m_undoStack(undoStack)
{
m_pixmapDatabase = new PixmapDatabase();
m_lastPathName = "";
@ -144,10 +161,131 @@ bool ZoneBuilder::init(const QString &pathName, bool makeAZone)
}
}
if ((makeAZone) && (bRet))
newZone();
createZoneRegion();
return bRet;
}
void ZoneBuilder::actionLigoTile(const LigoData &data, const ZonePosition &zonePos)
{
nlinfo(QString("%1 %2 %3 (%4 %5)").arg(data.zoneName.c_str()).arg(zonePos.x).arg(zonePos.y).arg(data.posX).arg(data.posY).toStdString().c_str());
m_undoStack->push(new LigoTileCommand(data, zonePos, this, m_landscapeScene));
}
void ZoneBuilder::actionLigoMove(uint index, sint32 deltaX, sint32 deltaY)
{
nlinfo("ligoMove");
//m_undoStack->push(new LigoMoveCommand(index, deltaX, deltaY, this));
}
void ZoneBuilder::actionLigoResize(uint index, sint32 newMinX, sint32 newMaxX, sint32 newMinY, sint32 newMaxY)
{
nlinfo(QString("minX=%1 maxX=%2 minY=%3 maxY=%4").arg(newMinX).arg(newMaxX).arg(newMinY).arg(newMaxY).toStdString().c_str());
m_undoStack->push(new LigoResizeCommand(index, newMinX, newMaxX, newMinY, newMaxY, this));
}
void ZoneBuilder::addZone(sint32 posX, sint32 posY)
{
if (m_builderZoneRegions.empty())
return;
std::string zoneName = m_listZonesWidget->currentZoneName().toStdString();
if (zoneName.empty())
return;
std::string error;
BuilderZoneRegion *builderZoneRegion = m_builderZoneRegions.at(m_currentZoneRegion);
builderZoneRegion->init(this, error);
uint8 rot = uint8(m_listZonesWidget->currentRot());
uint8 flip = uint8(m_listZonesWidget->currentFlip());
NLLIGO::CZoneBankElement *zoneBankElement = getZoneBank().getElementByZoneName(zoneName);
m_undoStack->beginMacro(QString("Add zone %1,%2").arg(posX).arg(posY));
if (m_listZonesWidget->isForce())
{
builderZoneRegion->addForce(posX, posY, rot, flip, zoneBankElement);
}
else
{
if (m_listZonesWidget->isNotPropogate())
builderZoneRegion->addNotPropagate(posX, posY, rot, flip, zoneBankElement);
else
builderZoneRegion->add(posX, posY, rot, flip, zoneBankElement);
}
m_undoStack->endMacro();
}
void ZoneBuilder::addTransition(const sint32 posX, const sint32 posY)
{
}
void ZoneBuilder::delZone(const sint32 posX, const sint32 posY)
{
if (m_builderZoneRegions.empty())
return;
m_undoStack->beginMacro(QString("Del zone %1,%2").arg(posX).arg(posY));
BuilderZoneRegion *builderZoneRegion = m_builderZoneRegions.at(m_currentZoneRegion);
std::string error;
builderZoneRegion->init(this, error);
builderZoneRegion->del(posX, posY);
m_undoStack->endMacro();
}
int ZoneBuilder::createZoneRegion()
{
ZoneRegionEditor *newZoneRegion = new ZoneRegionEditor();
m_zoneRegions.push_back(newZoneRegion);
if (m_currentZoneRegion == -1)
m_currentZoneRegion = m_zoneRegions.indexOf(newZoneRegion);
newZone();
return m_zoneRegions.indexOf(newZoneRegion);
}
void ZoneBuilder::deleteZoneRegion(int id)
{
if ((0 <= id) && (id < m_zoneRegions.size()))
delete m_zoneRegions.takeAt(id);
}
void ZoneBuilder::setCurrentZoneRegion(int id)
{
if ((0 <= id) && (id < m_zoneRegions.size()))
m_currentZoneRegion = id;
}
int ZoneBuilder::currentIdZoneRegion() const
{
return m_currentZoneRegion;
}
ZoneRegionEditor *ZoneBuilder::currentZoneRegion() const
{
return m_zoneRegions.at(m_currentZoneRegion);
}
int ZoneBuilder::countZoneRegion() const
{
return m_zoneRegions.size();
}
ZoneRegionEditor *ZoneBuilder::zoneRegion(int id) const
{
return m_zoneRegions.at(id);
}
void ZoneBuilder::ligoData(LigoData &data, const ZonePosition &zonePos)
{
m_zoneRegions.at(zonePos.region)->ligoData(data, zonePos.x, zonePos.y);
}
void ZoneBuilder::setLigoData(LigoData &data, const ZonePosition &zonePos)
{
m_zoneRegions.at(zonePos.region)->setLigoData(data, zonePos.x, zonePos.y);
}
bool ZoneBuilder::initZoneBank (const QString &pathName)
{
QDir *dir = new QDir(pathName);
@ -178,8 +316,112 @@ QString ZoneBuilder::dataPath() const
return m_lastPathName;
}
void ZoneBuilder::newZone (bool bDisplay)
void ZoneBuilder::newZone()
{
BuilderZoneRegion *builderZoneRegion = new BuilderZoneRegion(m_builderZoneRegions.size());
m_builderZoneRegions.push_back(builderZoneRegion);
// 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 (int i = 0; i < m_zoneRegions.size(); ++i)
{
const NLLIGO::CZoneRegion &zoneRegion = m_zoneRegions.at(i)->zoneRegion();
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)
{
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 ZoneBuilder::calcMask()
{
sint32 i;
sint32 x, y;
m_minY = m_minX = 1000000;
m_maxY = m_maxX = -1000000;
if (m_builderZoneRegions.size() == 0)
return;
for (i = 0; i < (sint32)m_builderZoneRegions.size(); ++i)
{
const NLLIGO::CZoneRegion &region = zoneRegion(i)->zoneRegion();
if (m_minX > region.getMinX())
m_minX = region.getMinX();
if (m_minY > region.getMinY())
m_minY = region.getMinY();
if (m_maxX < region.getMaxX())
m_maxX = region.getMaxX();
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;
for (i = 0; i < (sint32)m_builderZoneRegions.size(); ++i)
if (i != m_currentZoneRegion)
{
const NLLIGO::CZoneRegion &region = zoneRegion(i)->zoneRegion();
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 ZoneBuilder::getZoneAmongRegions (ZonePosition &zonePos, BuilderZoneRegion *builderZoneRegionFrom, sint32 x, sint32 y)
{
Q_FOREACH(ZoneRegionEditor *zoneRegion, m_zoneRegions)
{
const NLLIGO::CZoneRegion &region = zoneRegion->zoneRegion();
if ((x < region.getMinX()) || (x > region.getMaxX()) ||
(y < region.getMinY()) || (y > region.getMaxY()))
continue;
if (region.getName(x, y) != STRING_UNUSED)
{
int index = m_zoneRegions.indexOf(zoneRegion);
builderZoneRegionFrom = m_builderZoneRegions.at(index);
zonePos = ZonePosition(x, y, index);
return true;
}
}
// The zone is not present in other region so it is an empty or oob zone of the current region
const NLLIGO::CZoneRegion &region = zoneRegion(builderZoneRegionFrom->getRegionId())->zoneRegion();
if ((x < region.getMinX()) || (x > region.getMaxX()) ||
(y < region.getMinY()) || (y > region.getMaxY()))
return false; // Out Of Bound
zonePos = ZonePosition(x, y, builderZoneRegionFrom->getRegionId());
return true;
}
} /* namespace LandscapeEditor */

View file

@ -19,9 +19,12 @@
#define BUILDER_ZONE_H
// Project includes
#include "builder_zone_region.h"
#include "zone_region_editor.h"
// NeL includes
#include <nel/ligo/zone_bank.h>
#include <nel/ligo/zone_region.h>
// STL includes
#include <string>
@ -30,11 +33,38 @@
// Qt includes
#include <QtCore/QString>
#include <QtCore/QMap>
#include <QtCore/QList>
#include <QtCore/QString>
#include <QtGui/QPixmap>
#include <QtGui/QUndoStack>
namespace LandscapeEditor
{
class ListZonesWidget;
class LandscapeScene;
// Data
struct ZonePosition
{
// Absolute position
sint32 x;
sint32 y;
int region;
ZonePosition()
{
x = 0xffffffff;
y = 0xffffffff;
region = -1;
}
ZonePosition(const sint32 posX, const sint32 posY, const int id)
{
x = posX;
y = posY;
region = id;
}
};
/**
@class PixmapDatabase
@ -59,8 +89,12 @@ public:
/// Get original pixmap
/// @return QPixmap* if the image is in the database ; otherwise returns 0.
QPixmap *pixmap(const QString &zoneName) const;
int textureSize() const;
private:
int m_textureSize;
QMap<QString, QPixmap*> m_pixmapMap;
};
@ -74,13 +108,37 @@ PixmapDatabase contains the graphics for the zones
class ZoneBuilder
{
public:
ZoneBuilder();
ZoneBuilder(ListZonesWidget *listZonesWidget, LandscapeScene *landscapeScene, QUndoStack *undoStack);
~ZoneBuilder();
// Init zoneBank and init zone pixmap database
/// Init zoneBank and init zone pixmap database
bool init(const QString &pathName, bool bMakeAZone);
void newZone(bool bDisplay=true);
void calcMask();
void newZone();
bool getZoneMask (sint32 x, sint32 y);
bool getZoneAmongRegions(ZonePosition &zonePos, BuilderZoneRegion *builderZoneRegionFrom, sint32 x, sint32 y);
// Ligo Actions
void actionLigoTile(const LigoData &data, const ZonePosition &zonePos);
void actionLigoMove(uint index, sint32 deltaX, sint32 deltaY);
void actionLigoResize(uint index, sint32 newMinX, sint32 newMaxX, sint32 newMinY, sint32 newMaxY);
// Zone Bricks
void addZone(sint32 posX, sint32 posY);
void addTransition(const sint32 posX, const sint32 posY);
void delZone(const sint32 posX, const sint32 posY);
// Zone Region
int createZoneRegion();
void deleteZoneRegion(int id);
void setCurrentZoneRegion(int id);
int currentIdZoneRegion() const;
ZoneRegionEditor *currentZoneRegion() const;
int countZoneRegion() const;
ZoneRegionEditor *zoneRegion(int id) const;
void ligoData(LigoData &data, const ZonePosition &zonePos);
void setLigoData(LigoData &data, const ZonePosition &zonePos);
// Accessors
NLLIGO::CZoneBank &getZoneBank()
@ -94,15 +152,24 @@ public:
private:
// Scan ./zoneligos dir and add all *.ligozone files to zoneBank
/// Scan ./zoneligos dir and add all *.ligozone files to zoneBank
bool initZoneBank (const QString &path);
sint32 m_minX, m_maxX, m_minY, m_maxY;
std::vector<bool> m_zoneMask;
QString m_lastPathName;
QList<ZoneRegionEditor *> m_zoneRegions;
int m_currentZoneRegion;
std::vector<BuilderZoneRegion *> m_builderZoneRegions;
PixmapDatabase *m_pixmapDatabase;
NLLIGO::CZoneBank m_zoneBank;
std::vector<NLLIGO::CZoneBankElement*> m_currentSelection;
ListZonesWidget *m_listZonesWidget;
LandscapeScene *m_landscapeScene;
QUndoStack *m_undoStack;
};
} /* namespace LandscapeEditor */

View file

@ -1,33 +1,101 @@
// Object Viewer Qt - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2011 Dzmitry Kamiahin <dnk-88@tut.by>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef BUILDER_ZONE_REGION_H
#define BUILDER_ZONE_REGION_H
// Project includes
// NeL includes
#include <nel/ligo/zone_bank.h>
// Qt includes
namespace LandscapeEditor
{
} /* namespace LandscapeEditor */
#endif // BUILDER_ZONE_REGION_H
// Object Viewer Qt - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2011 Dzmitry Kamiahin <dnk-88@tut.by>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef BUILDER_ZONE_REGION_H
#define BUILDER_ZONE_REGION_H
// Project includes
// NeL includes
#include <nel/ligo/zone_bank.h>
#include <nel/ligo/zone_region.h>
// STL includes
#include <string>
#include <vector>
#include <queue>
// Qt includes
namespace LandscapeEditor
{
class ZoneBuilder;
// CZoneRegion contains informations about the zones painted
class BuilderZoneRegion
{
public:
BuilderZoneRegion(uint regionId);
// New interface
bool init(ZoneBuilder *zoneBuilder, std::string &error);
void add(sint32 x, sint32 y, uint8 rot, uint8 flip, NLLIGO::CZoneBankElement *zoneBankElement);
void invertCutEdge(sint32 x, sint32 y, uint8 cePos);
void cycleTransition(sint32 x, sint32 y);
bool addNotPropagate(sint32 x, sint32 y, uint8 rot, uint8 flip, NLLIGO::CZoneBankElement *zoneBankElement);
/// Brutal adding a zone over empty space do not propagate in any way -> can result
/// in inconsistency when trying the propagation mode
void addForce (sint32 x, sint32 y, uint8 rot, uint8 flip, NLLIGO::CZoneBankElement *zoneBankElement);
void del(sint32 x, sint32 y, bool transition = false, void *pInternal = NULL);
void move(sint32 x, sint32 y);
uint32 countZones();
void reduceMin();
uint getRegionId() const;
private:
// An element of the graph
struct SMatNode
{
std::string Name;
// Position in the tree (vector of nodes)
std::vector<uint32> Arcs;
};
void addTransition(sint32 x, sint32 y, uint8 rot, uint8 flip, NLLIGO::CZoneBankElement *zoneBankElement);
void addToUpdateAndCreate(BuilderZoneRegion* builderZoneRegion, sint32 sharePos, sint32 x, sint32 y, const std::string &newMat, void *pInt1, void *pInt2);
void putTransitions(sint32 x, sint32 y, const NLLIGO::SPiece &mask, const std::string &matName, void *pInternal);
void updateTrans(sint32 x, sint32 y, NLLIGO::CZoneBankElement *zoneBankElement = NULL);
std::string getNextMatInTree(const std::string &matA, const std::string &matB);
/// Find the fastest way between posA and posB in the MatTree (Dijkstra)
void tryPath(uint32 posA, uint32 posB, std::vector<uint32> &path);
void set(sint32 x, sint32 y, sint32 posX, sint32 posY, const std::string &zoneName, bool transition=false);
void setRot(sint32 x, sint32 y, uint8 rot);
void setFlip(sint32 x, sint32 y, uint8 flip);
void resize(sint32 newMinX, sint32 newMaxX, sint32 newMinY, sint32 newMaxY);
uint m_regionId;
// To use the global mask
ZoneBuilder *m_zoneBuilder;
// The tree of transition between materials
std::vector<SMatNode> m_matTree;
bool m_firstInit;
};
} /* namespace LandscapeEditor */
#endif // BUILDER_ZONE_REGION_H

View file

@ -62,54 +62,111 @@ void NewLandscapeCommand::redo()
{
}
AddLigoTileCommand::AddLigoTileCommand(const LigoData &data, LandscapeScene *scene, QUndoCommand *parent)
LigoTileCommand::LigoTileCommand(const LigoData &data, const ZonePosition &zonePos,
ZoneBuilder *zoneBuilder, LandscapeScene *scene,
QUndoCommand *parent)
: QUndoCommand(parent),
m_item(0),
m_zoneBuilder(zoneBuilder),
m_scene(scene)
{
m_ligoData = data;
// Backup position
m_zonePos = zonePos;
// Backup new data
m_newLigoData = data;
// Backup old data
m_zoneBuilder->ligoData(m_oldLigoData, m_zonePos);
}
AddLigoTileCommand::~AddLigoTileCommand()
LigoTileCommand::~LigoTileCommand()
{
}
void AddLigoTileCommand::undo()
void LigoTileCommand::undo ()
{
m_scene->removeItem(m_item);
delete m_item;
m_item = 0;
m_zoneBuilder->setLigoData(m_oldLigoData, m_zonePos);
m_scene->createZoneItem(m_oldLigoData, m_zonePos);
}
void AddLigoTileCommand::redo()
void LigoTileCommand::redo ()
{
m_item = m_scene->createZoneItem(m_ligoData);
setText(QObject::tr("Add tile(%1, %2)").arg(m_ligoData.PosX).arg(m_ligoData.PosY));
m_zoneBuilder->setLigoData(m_newLigoData, m_zonePos);
m_scene->createZoneItem(m_newLigoData, m_zonePos);
}
DelLigoTileCommand::DelLigoTileCommand(const LigoData &data, LandscapeScene *scene, QUndoCommand *parent)
LigoResizeCommand::LigoResizeCommand(int index, sint32 newMinX, sint32 newMaxX,
sint32 newMinY, sint32 newMaxY, ZoneBuilder *zoneBuilder,
QUndoCommand *parent)
: QUndoCommand(parent),
m_item(0),
m_scene(scene)
m_zoneBuilder(zoneBuilder)
{
m_ligoData = data;
m_index = index;
m_newMinX = newMinX;
m_newMaxX = newMaxX;
m_newMinY = newMinY;
m_newMaxY = newMaxY;
// Backup old region zone
m_oldZoneRegion = m_zoneBuilder->zoneRegion(m_index)->zoneRegion();
}
DelLigoTileCommand::~DelLigoTileCommand()
LigoResizeCommand::~LigoResizeCommand()
{
}
void DelLigoTileCommand::undo()
void LigoResizeCommand::undo ()
{
m_item = m_scene->createZoneItem(m_ligoData);
// Restore old region zone
m_zoneBuilder->zoneRegion(m_index)->setZoneRegion(m_oldZoneRegion);
}
void DelLigoTileCommand::redo()
void LigoResizeCommand::redo ()
{
m_item = m_scene->itemAt(m_ligoData.PosX * m_scene->cellSize(), m_ligoData.PosY * m_scene->cellSize());
delete m_item;
m_item = 0;
setText(QObject::tr("Del tile(%1, %2)").arg(m_ligoData.PosX).arg(m_ligoData.PosY));
// Get the zone region
NLLIGO::CZoneRegion &region = m_zoneBuilder->zoneRegion(m_index)->zoneRegion();
sint32 i, j;
std::vector<LigoData> newZones;
newZones.resize((1 + m_newMaxX - m_newMinX) * (1 + m_newMaxY - m_newMinY));
sint32 newStride = 1 + m_newMaxX - m_newMinX;
sint32 Stride = 1 + region.getMaxX() - region.getMinX();
for (j = m_newMinY; j <= m_newMaxY; ++j)
for (i = m_newMinX; i <= m_newMaxX; ++i)
{
// Ref on the new value
LigoData &data = newZones[(i - m_newMinX) + (j - m_newMinY) * newStride];
// In the old array ?
if ((i >= region.getMinX()) && (i <= region.getMaxX()) &&
(j >= region.getMinY()) && (j <= region.getMaxY()))
{
// Backup values
m_zoneBuilder->ligoData(data, ZonePosition(i, j, m_index));
}
}
region.resize(m_newMinX, m_newMaxX, m_newMinY, m_newMaxY);
for (j = m_newMinY; j <= m_newMaxY; ++j)
for (i = m_newMinX; i <= m_newMaxX; ++i)
{
// Ref on the new value
const LigoData &data = newZones[(i - m_newMinX) + (j - m_newMinY) * newStride];
region.setName(i, j, data.zoneName);
region.setPosX(i, j, data.posX);
region.setPosY(i, j, data.posY);
region.setRot(i, j, data.rot);
region.setFlip(i, j, data.flip);
uint k;
for (k = 0; k < 4; k++)
{
region.setSharingMatNames(i, j, k, data.sharingMatNames[k]);
region.setSharingCutEdges(i, j, k, data.sharingCutEdges[k]);
}
}
}
} /* namespace LandscapeEditor */

View file

@ -56,36 +56,64 @@ public:
private:
};
class AddLigoTileCommand: public QUndoCommand
// Modify the landscape
class LigoTileCommand: public QUndoCommand
{
public:
AddLigoTileCommand(const LigoData &data, LandscapeScene *scene, QUndoCommand *parent = 0);
virtual ~AddLigoTileCommand();
LigoTileCommand(const LigoData &data, const ZonePosition &zonePos,
ZoneBuilder *zoneBuilder, LandscapeScene *scene,
QUndoCommand *parent = 0);
virtual ~LigoTileCommand();
virtual void undo();
virtual void redo();
private:
LigoData m_ligoData;
QGraphicsItem *m_item;
ZonePosition m_zonePos;
LigoData m_newLigoData;
LigoData m_oldLigoData;
ZoneBuilder *m_zoneBuilder;
LandscapeScene *m_scene;
};
class DelLigoTileCommand: public QUndoCommand
/*
// Move the landscape
class LigoMoveCommand: public QUndoCommand
{
public:
DelLigoTileCommand(const LigoData &data, LandscapeScene *scene, QUndoCommand *parent = 0);
virtual ~DelLigoTileCommand();
LigoMoveCommand(int index, sint32 deltaX, sint32 deltaY, ZoneBuilder *zoneBuilder, QUndoCommand *parent = 0);
virtual ~LigoMoveCommand();
virtual void undo();
virtual void redo();
private:
int m_index;
sint32 m_deltaX;
sint32 m_deltaY;
ZoneBuilder *m_zoneBuilder;
};
*/
// Modify the landscape
class LigoResizeCommand: public QUndoCommand
{
public:
LigoResizeCommand(int index, sint32 newMinX, sint32 newMaxX,
sint32 newMinY, sint32 newMaxY, ZoneBuilder *zoneBuilder,
QUndoCommand *parent = 0);
virtual ~LigoResizeCommand();
virtual void undo();
virtual void redo();
private:
LigoData m_ligoData;
QGraphicsItem *m_item;
LandscapeScene *m_scene;
int m_index;
sint32 m_newMinX;
sint32 m_newMaxX;
sint32 m_newMinY;
sint32 m_newMaxY;
NLLIGO::CZoneRegion m_oldZoneRegion;
ZoneBuilder *m_zoneBuilder;
};
} /* namespace LandscapeEditor */

View file

@ -19,6 +19,7 @@
#include "landscape_editor_window.h"
#include "landscape_editor_constants.h"
#include "builder_zone.h"
#include "zone_region_editor.h"
#include "landscape_scene.h"
#include "project_settings_dialog.h"
#include "snapshot_dialog.h"
@ -45,12 +46,14 @@ LandscapeEditorWindow::LandscapeEditorWindow(QWidget *parent)
m_ui.setupUi(this);
m_undoStack = new QUndoStack(this);
m_zoneBuilder = new ZoneBuilder();
m_zoneBuilder->init("e:/-nel-/install/continents/newbieland", false);
m_landscapeScene = new LandscapeScene(this);
m_zoneBuilder = new ZoneBuilder(m_ui.zoneListWidget, m_landscapeScene, m_undoStack);
m_zoneBuilder->init("e:/-nel-/install/continents/newbieland", true);
m_ui.zoneListWidget->setZoneBuilder(m_zoneBuilder);
m_ui.zoneListWidget->updateUi();
m_landscapeScene = new LandscapeScene(m_undoStack, m_ui.zoneListWidget, m_zoneBuilder, this);
m_landscapeScene->setZoneBuilder(m_zoneBuilder);
m_ui.graphicsView->setScene(m_landscapeScene);
//m_ui.graphicsView->setViewport(new QGLWidget(QGLFormat(QGL::DoubleBuffer)));
m_ui.graphicsView->setViewport(new QGLWidget(QGLFormat(QGL::DoubleBuffer | QGL::SampleBuffers)));
@ -88,11 +91,14 @@ void LandscapeEditorWindow::open()
_lastDir = QFileInfo(list.front()).absolutePath();
Q_FOREACH(QString fileName, fileNames)
{
m_zoneRegionEditor.load(fileName.toStdString());
m_landscapeScene->processZoneRegion(m_zoneRegionEditor.zoneRegion());
m_landscapeScene->setCurrentZoneRegion(&m_zoneRegionEditor.zoneRegion());
m_ui.graphicsView->centerOn(m_zoneRegionEditor.zoneRegion().getMinX() * m_landscapeScene->cellSize(),
abs(m_zoneRegionEditor.zoneRegion().getMinY()) * m_landscapeScene->cellSize());
int id = m_zoneBuilder->createZoneRegion();
ZoneRegionEditor *zoneRegion = m_zoneBuilder->zoneRegion(id);
zoneRegion->load(fileName.toStdString());
m_landscapeScene->processZoneRegion(zoneRegion->zoneRegion());
m_ui.graphicsView->centerOn(zoneRegion->zoneRegion().getMinX() * m_landscapeScene->cellSize(),
abs(zoneRegion->zoneRegion().getMinY()) * m_landscapeScene->cellSize());
m_zoneBuilder->setCurrentZoneRegion(id);
}
}
setCursor(Qt::ArrowCursor);

View file

@ -20,7 +20,6 @@
// Project includes
#include "ui_landscape_editor_window.h"
#include "zone_region_editor.h"
// Qt includes
#include <QtGui/QUndoStack>
@ -55,8 +54,6 @@ private:
void readSettings();
void writeSettings();
ZoneRegionEditor m_zoneRegionEditor;
LandscapeScene *m_landscapeScene;
ZoneBuilder *m_zoneBuilder;
QUndoStack *m_undoStack;

View file

@ -17,9 +17,6 @@
// Project includes
#include "landscape_scene.h"
#include "builder_zone.h"
#include "landscape_actions.h"
#include "list_zones_widget.h"
// NeL includes
#include <nel/misc/debug.h>
@ -32,12 +29,9 @@
namespace LandscapeEditor
{
LandscapeScene::LandscapeScene(QUndoStack *undoStack, ListZonesWidget *listZonesWidget, ZoneBuilder *zoneBuilder, QObject *parent)
LandscapeScene::LandscapeScene(QObject *parent)
: QGraphicsScene(parent),
m_undoStack(undoStack),
m_listZonesWidget(listZonesWidget),
m_zoneBuilder(zoneBuilder),
m_zoneRegion(0)
m_zoneBuilder(0)
{
m_cellSize = 160;
}
@ -51,20 +45,34 @@ int LandscapeScene::cellSize() const
return m_cellSize;
}
QGraphicsItem *LandscapeScene::createZoneItem(const LigoData &data)
void LandscapeScene::setZoneBuilder(ZoneBuilder *zoneBuilder)
{
m_zoneBuilder = zoneBuilder;
}
QGraphicsItem *LandscapeScene::createZoneItem(const LigoData &data, const ZonePosition &zonePos)
{
if (data.zoneName == STRING_UNUSED)
return createEmptyZoneItem(zonePos);
if ((m_zoneBuilder == 0) || (data.zoneName.empty()) ||
(data.posX != 0) || (data.posY != 0))
return 0;
checkUnderZone(data, zonePos);
// Get image from pixmap database
QPixmap *pixmap = m_zoneBuilder->pixmapDatabase()->pixmap(QString(data.ZoneName.c_str()));
QPixmap *pixmap = m_zoneBuilder->pixmapDatabase()->pixmap(QString(data.zoneName.c_str()));
if (pixmap == 0)
return 0;
// Rotate the image counterclockwise
QMatrix matrix;
matrix.rotate(-data.Rot * 90.0);
matrix.rotate(-data.rot * 90.0);
QGraphicsPixmapItem *item;
if (data.Flip == 0)
if (data.flip == 0)
{
item = new QGraphicsPixmapItem(pixmap->transformed(matrix, Qt::SmoothTransformation), 0, this);
}
@ -79,135 +87,156 @@ QGraphicsItem *LandscapeScene::createZoneItem(const LigoData &data)
item->setTransformationMode(Qt::SmoothTransformation);
// Set position graphics item with offset for large piece
NLLIGO::CZoneBankElement *zoneBankItem = m_zoneBuilder->getZoneBank().getElementByZoneName(data.ZoneName);
item->setPos(data.PosX * m_cellSize, (abs(data.PosY) - zoneBankItem->getSizeY() + 1) * m_cellSize);
NLLIGO::CZoneBankElement *zoneBankItem = m_zoneBuilder->getZoneBank().getElementByZoneName(data.zoneName);
item->setPos(zonePos.x * m_cellSize, (abs(zonePos.y) - zoneBankItem->getSizeY() + 1) * m_cellSize);
// The size graphics item should be equal or proportional m_cellSize
item->setScale(m_cellSize / 256.0);
// add debug info
QGraphicsSimpleTextItem *itemText = addSimpleText(QString("%1,%2 R-%3 F-%4").
arg(data.PosX).arg(data.PosY).
arg(data.Rot * 90.0).
arg(data.Flip),
QFont("Helvetica [Cronyx]", 14));
itemText->setZValue(2);
itemText->setPos(data.PosX * m_cellSize + 10, (abs(data.PosY) - zoneBankItem->getSizeY() + 1) * m_cellSize + 10);
itemText->setBrush(QBrush(Qt::white));
item->setScale(float(m_cellSize) / m_zoneBuilder->pixmapDatabase()->textureSize());
return item;
}
QGraphicsItem *LandscapeScene::createEmptyZoneItem(const ZonePosition &zonePos)
{
if (m_zoneBuilder == 0)
return 0;
deleteZoneItem(zonePos);
// Get image from pixmap database
QPixmap *pixmap = m_zoneBuilder->pixmapDatabase()->pixmap(QString(STRING_UNUSED));
if (pixmap == 0)
return 0;
QGraphicsPixmapItem *item = new QGraphicsPixmapItem(*pixmap, 0, this);
// Enable bilinear filtering
item->setTransformationMode(Qt::SmoothTransformation);
// Set position graphics item
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());
return item;
}
void LandscapeScene::deleteZoneItem(const ZonePosition &zonePos)
{
QGraphicsItem *item = itemAt(zonePos.x * m_cellSize, abs(zonePos.y) * m_cellSize);
if (item != 0)
{
removeItem(item);
delete item;
}
}
void LandscapeScene::processZoneRegion(const NLLIGO::CZoneRegion &zoneRegion)
{
for (sint32 i = zoneRegion.getMinX(); i <= zoneRegion.getMaxX(); ++i)
{
for (sint32 j = zoneRegion.getMinY(); j <= zoneRegion.getMaxY(); ++j)
{
nlinfo(QString("%1 %2 %3").arg(i).arg(j).arg(zoneRegion.getName(i, j).c_str()).toStdString().c_str());
std::string zoneName = zoneRegion.getName(i, j);
if ((!zoneName.empty()) &&
(zoneName != STRING_UNUSED) &&
(zoneRegion.getPosX(i, j) == 0) &&
(zoneRegion.getPosY(i, j) == 0))
if (zoneName == STRING_UNUSED)
{
ZonePosition zonePos(i, j, -1);
QGraphicsItem *item = createEmptyZoneItem(zonePos);
}
else if (!zoneName.empty())
{
LigoData data;
data.PosX = i;
data.PosY = j;
data.ZoneName = zoneName;
data.Rot = zoneRegion.getRot(i, j);
data.Flip = zoneRegion.getFlip(i, j);
QGraphicsItem *item = createZoneItem(data);
ZonePosition zonePos(i, j, -1);
data.zoneName = zoneName;
data.rot = zoneRegion.getRot(i, j);
data.flip = zoneRegion.getFlip(i, j);
data.posX = zoneRegion.getPosX(i, j);
data.posY = zoneRegion.getPosY(i, j);
QGraphicsItem *item = createZoneItem(data, zonePos);
}
}
}
}
void LandscapeScene::setCurrentZoneRegion(NLLIGO::CZoneRegion *zoneRegion)
{
m_zoneRegion = zoneRegion;
}
void LandscapeScene::snapshot(const QString &fileName, int sizeSource)
{
if (m_zoneRegion == 0)
return;
/* if (m_zoneRegion == 0)
return;
sint32 regionMinX = m_zoneRegion->getMinX();
sint32 regionMaxX = m_zoneRegion->getMaxX();
sint32 regionMinY = m_zoneRegion->getMinY();
sint32 regionMaxY = m_zoneRegion->getMaxY();
sint32 regionMinX = m_zoneRegion->getMinX();
sint32 regionMaxX = m_zoneRegion->getMaxX();
sint32 regionMinY = m_zoneRegion->getMinY();
sint32 regionMaxY = m_zoneRegion->getMaxY();
int regionWidth = (regionMaxX - regionMinX + 1);
int regionHeight = (regionMaxY - regionMinY + 1);
int regionWidth = (regionMaxX - regionMinX + 1);
int regionHeight = (regionMaxY - regionMinY + 1);
snapshot(fileName, regionWidth * sizeSource, regionHeight * sizeSource);
snapshot(fileName, regionWidth * sizeSource, regionHeight * sizeSource);
*/
}
void LandscapeScene::snapshot(const QString &fileName, int width, int height)
{
if (m_zoneRegion == 0)
if (m_zoneBuilder == 0)
return;
sint32 regionMinX = m_zoneRegion->getMinX();
sint32 regionMaxX = m_zoneRegion->getMaxX();
sint32 regionMinY = m_zoneRegion->getMinY();
sint32 regionMaxY = m_zoneRegion->getMaxY();
/* if (m_zoneRegion == 0)
return;
int regionWidth = (regionMaxX - regionMinX + 1);
int regionHeight = (regionMaxY - regionMinY + 1);
sint32 regionMinX = m_zoneRegion->getMinX();
sint32 regionMaxX = m_zoneRegion->getMaxX();
sint32 regionMinY = m_zoneRegion->getMinY();
sint32 regionMaxY = m_zoneRegion->getMaxY();
QImage image(width, height, QImage::Format_RGB888);
QPainter painter(&image);
painter.setRenderHint(QPainter::Antialiasing, true);
int regionWidth = (regionMaxX - regionMinX + 1);
int regionHeight = (regionMaxY - regionMinY + 1);
// add white background
painter.setBrush(QBrush(Qt::white));
painter.setPen(Qt::NoPen);
painter.drawRect(0, 0, width, height);
QImage image(width, height, QImage::Format_RGB888);
QPainter painter(&image);
painter.setRenderHint(QPainter::Antialiasing, true);
render(&painter, QRectF(0, 0, width, height),
QRectF(regionMinX * m_cellSize, abs(regionMaxY) * m_cellSize, regionWidth * m_cellSize, regionHeight * m_cellSize));
// add white background
painter.setBrush(QBrush(Qt::white));
painter.setPen(Qt::NoPen);
painter.drawRect(0, 0, width, height);
image.save(fileName);
render(&painter, QRectF(0, 0, width, height),
QRectF(regionMinX * m_cellSize, abs(regionMaxY) * m_cellSize, regionWidth * m_cellSize, regionHeight * m_cellSize));
image.save(fileName);
*/
}
void LandscapeScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
if (m_zoneBuilder == 0)
return;
qreal x = mouseEvent->scenePos().rx();
qreal y = mouseEvent->scenePos().ry();
if ((x < 0) || (y < 0))
return;
sint32 posX = sint32(floor(x / m_cellSize));
sint32 posY = sint32(-floor(y / m_cellSize));
if (mouseEvent->button() == Qt::LeftButton)
{
// Add new zone brick
LigoData ligoData = m_listZonesWidget->currentLigoData();
if (ligoData.ZoneName == "")
return;
m_zoneBuilder->addZone(posX, posY);
else if (mouseEvent->button() == Qt::RightButton)
m_zoneBuilder->delZone(posX, posY);
ligoData.PosX = int(floor(x / m_cellSize));
ligoData.PosY = int(-floor(y / m_cellSize));
AddLigoTileCommand *action = new AddLigoTileCommand(ligoData, this);
m_undoStack->push(action);
}
/*if (mouseEvent->button() == Qt::RightButton)
{
// Delete zone brick
LigoData ligoData;
ligoData.PosX = int(floor(x / m_cellSize));
ligoData.PosY = int(floor(y / m_cellSize));
ligoData.ZoneName = m_zoneRegion->getName(ligoData.PosX, -ligoData.PosY);
ligoData.Flip = m_zoneRegion->getFlip(ligoData.PosX, -ligoData.PosY);
ligoData.Rot = m_zoneRegion->getRot(ligoData.PosX, -ligoData.PosY);
DelLigoTileCommand *action = new DelLigoTileCommand(ligoData, this);
m_undoStack->push(action);
}*/
QGraphicsScene::mousePressEvent(mouseEvent);
}
void LandscapeScene::checkUnderZone(const LigoData &data, const ZonePosition &zonePos)
{
// NLLIGO::CZoneBankElement *zoneBankItem = m_zoneBuilder->getZoneBank().getElementByZoneName(data.zoneName);
// uint8 sizeX = zoneBankItem->getSizeX();
// uint8 sizeY = zoneBankItem->getSizeY();
// std::vector<bool> &mask = zoneBankItem->getMask();
deleteZoneItem(zonePos);
}
} /* namespace LandscapeEditor */

View file

@ -19,6 +19,8 @@
#define LANDSCAPE_SCENE_H
// Project includes
#include "zone_region_editor.h"
#include "builder_zone.h"
// NeL includes
#include <nel/ligo/zone_region.h>
@ -26,54 +28,25 @@
// Qt includes
#include <QtGui/QGraphicsScene>
#include <QtGui/QGraphicsSceneMouseEvent>
#include <QtGui/QUndoStack>
namespace LandscapeEditor
{
class ZoneBuilder;
class ListZonesWidget;
// Data
struct LigoData
{
sint32 PosX;
sint32 PosY;
uint8 Rot;
uint8 Flip;
std::string ZoneName;
std::string SharingMatNames[4];
uint8 SharingCutEdges[4];
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]);
}
};
class LandscapeScene : public QGraphicsScene
{
Q_OBJECT
public:
LandscapeScene(QUndoStack *undoStack, ListZonesWidget *listZonesWidget, ZoneBuilder *zoneBuilder, QObject *parent = 0);
LandscapeScene(QObject *parent = 0);
virtual ~LandscapeScene();
int cellSize() const;
void setZoneBuilder(ZoneBuilder *zoneBuilder);
QGraphicsItem *createZoneItem(const LigoData &data);
QGraphicsItem *createZoneItem(const LigoData &data, const ZonePosition &zonePos);
QGraphicsItem *createEmptyZoneItem(const ZonePosition &zonePos);
void deleteZoneItem(const ZonePosition &zonePos);
void processZoneRegion(const NLLIGO::CZoneRegion &zoneRegion);
void setCurrentZoneRegion(NLLIGO::CZoneRegion *zoneRegion);
void snapshot(const QString &fileName, int sizeSource);
void snapshot(const QString &fileName, int width, int height);
@ -82,12 +55,10 @@ protected:
virtual void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent);
private:
void checkUnderZone(const LigoData &data, const ZonePosition &zonePos);
int m_cellSize;
ListZonesWidget *m_listZonesWidget;
QUndoStack *m_undoStack;
ZoneBuilder *m_zoneBuilder;
NLLIGO::CZoneRegion *m_zoneRegion;
};
} /* namespace LandscapeEditor */

View file

@ -18,6 +18,7 @@
// Project includes
#include "list_zones_widget.h"
#include "list_zones_model.h"
#include "builder_zone.h"
// NeL includes
#include <nel/misc/debug.h>
@ -100,17 +101,34 @@ void ListZonesWidget::updateUi()
m_listZonesModel->rebuildModel(m_zoneBuilder->pixmapDatabase());
}
LigoData ListZonesWidget::currentLigoData() const
QString ListZonesWidget::currentZoneName() const
{
LigoData ligoData;
ligoData.ZoneName = "";
QString zoneName = "";
QModelIndex index = m_ui.listView->currentIndex();
if (index.isValid())
ligoData.ZoneName = index.data().toString().toStdString();
zoneName = index.data().toString();
ligoData.Rot = m_ui.rotComboBox->currentIndex();
ligoData.Flip = m_ui.flipComboBox->currentIndex();
return ligoData;
return zoneName;
}
int ListZonesWidget::currentRot() const
{
return m_ui.rotComboBox->currentIndex();
}
int ListZonesWidget::currentFlip() const
{
return m_ui.flipComboBox->currentIndex();
}
bool ListZonesWidget::isNotPropogate() const
{
return m_ui.propogateCheckBox->isChecked();
}
bool ListZonesWidget::isForce() const
{
return m_ui.forceCheckBox->isChecked();
}
void ListZonesWidget::setZoneBuilder(ZoneBuilder *zoneBuilder)

View file

@ -20,8 +20,6 @@
// Project includes
#include "ui_list_zones_widget.h"
#include "builder_zone.h"
#include "landscape_scene.h"
// NeL includes
@ -30,6 +28,7 @@
namespace LandscapeEditor
{
class ListZonesModel;
class ZoneBuilder;
/**
@class ZoneListWidget
@ -46,7 +45,11 @@ public:
void updateUi();
void setZoneBuilder(ZoneBuilder *zoneBuilder);
LigoData currentLigoData() const;
QString currentZoneName() const;
int currentRot() const;
int currentFlip() const;
bool isNotPropogate() const;
bool isForce() const;
Q_SIGNALS:
private Q_SLOTS:

View file

@ -30,6 +30,23 @@
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;
}
ZoneRegionEditor::ZoneRegionEditor()
{
m_fileName = "";
@ -111,9 +128,58 @@ void ZoneRegionEditor::setFileName(const std::string &fileName)
m_fileName = fileName;
}
void ZoneRegionEditor::ligoData(LigoData &data, const sint32 x, const sint32 y)
{
nlassert((x >= m_zoneRegion.getMinX()) &&
(x <= m_zoneRegion.getMaxX()) &&
(y >= m_zoneRegion.getMinY()) &&
(y <= m_zoneRegion.getMaxY()));
data.posX = m_zoneRegion.getPosX(x, y);
data.posY = m_zoneRegion.getPosY(x, y);
data.zoneName = m_zoneRegion.getName(x, y);
data.rot = m_zoneRegion.getRot(x, y);
data.flip = m_zoneRegion.getFlip(x, y);
data.sharingMatNames[0] = m_zoneRegion.getSharingMatNames(x, y, 0);
data.sharingMatNames[1] = m_zoneRegion.getSharingMatNames(x, y, 1);
data.sharingMatNames[2] = m_zoneRegion.getSharingMatNames(x, y, 2);
data.sharingMatNames[3] = m_zoneRegion.getSharingMatNames(x, y, 3);
data.sharingCutEdges[0] = m_zoneRegion.getSharingCutEdges(x, y, 0);
data.sharingCutEdges[1] = m_zoneRegion.getSharingCutEdges(x, y, 1);
data.sharingCutEdges[2] = m_zoneRegion.getSharingCutEdges(x, y, 2);
data.sharingCutEdges[3] = m_zoneRegion.getSharingCutEdges(x, y, 3);
}
void ZoneRegionEditor::setLigoData(const LigoData &data, const sint32 x, const sint32 y)
{
nlassert((x >= m_zoneRegion.getMinX()) &&
(x <= m_zoneRegion.getMaxX()) &&
(y >= m_zoneRegion.getMinY()) &&
(y <= m_zoneRegion.getMaxY()));
m_zoneRegion.setPosX(x, y, data.posX);
m_zoneRegion.setPosY(x, y, data.posY);
m_zoneRegion.setName(x, y, data.zoneName);
m_zoneRegion.setRot(x, y, data.rot);
m_zoneRegion.setFlip(x, y, data.flip);
m_zoneRegion.setSharingMatNames(x, y, 0, data.sharingMatNames[0]);
m_zoneRegion.setSharingMatNames(x, y, 1, data.sharingMatNames[1]);
m_zoneRegion.setSharingMatNames(x, y, 2, data.sharingMatNames[2]);
m_zoneRegion.setSharingMatNames(x, y, 3, data.sharingMatNames[3]);
m_zoneRegion.setSharingCutEdges(x, y, 0, data.sharingCutEdges[0]);
m_zoneRegion.setSharingCutEdges(x, y, 1, data.sharingCutEdges[1]);
m_zoneRegion.setSharingCutEdges(x, y, 2, data.sharingCutEdges[2]);
m_zoneRegion.setSharingCutEdges(x, y, 3, data.sharingCutEdges[3]);
}
NLLIGO::CZoneRegion &ZoneRegionEditor::zoneRegion()
{
return m_zoneRegion;
}
void ZoneRegionEditor::setZoneRegion(const NLLIGO::CZoneRegion &zoneRegion)
{
m_zoneRegion = zoneRegion;
}
} /* namespace LandscapeEditor */

View file

@ -32,6 +32,36 @@
namespace LandscapeEditor
{
struct LigoData
{
uint8 posX;
uint8 posY;
uint8 rot;
uint8 flip;
std::string zoneName;
std::string sharingMatNames[4];
uint8 sharingCutEdges[4];
LigoData();
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]);
}
};
class ZoneRegionEditor
{
public:
@ -44,11 +74,17 @@ public:
// Save landscape data to file
bool save();
void ligoData(LigoData &data, const sint32 x, const sint32 y);
void setLigoData(const LigoData &data, const sint32 x, const sint32 y);
// Set file name
void setFileName(const std::string &fileName);
NLLIGO::CZoneRegion &zoneRegion();
void setZoneRegion(const NLLIGO::CZoneRegion &zoneRegion);
private:
bool m_modified;