Changed: #1301 Improved 2d render. Fixed adding empty undo/redo operations in command list, improved performance when adding new zones.

This commit is contained in:
dnk-88 2011-06-30 00:25:43 +03:00
parent 8eefc06d30
commit da3875cd35
12 changed files with 310 additions and 73 deletions

View file

@ -167,18 +167,22 @@ bool ZoneBuilder::init(const QString &pathName, bool makeAZone)
void ZoneBuilder::actionLigoTile(const LigoData &data, const ZonePosition &zonePos) void ZoneBuilder::actionLigoTile(const LigoData &data, const ZonePosition &zonePos)
{ {
checkBeginMacro();
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()); 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_zonePositionList.push_back(zonePos);
m_undoStack->push(new LigoTileCommand(data, zonePos, this, m_landscapeScene)); m_undoStack->push(new LigoTileCommand(data, zonePos, this, m_landscapeScene));
} }
void ZoneBuilder::actionLigoMove(uint index, sint32 deltaX, sint32 deltaY) void ZoneBuilder::actionLigoMove(uint index, sint32 deltaX, sint32 deltaY)
{ {
checkBeginMacro();
nlinfo("ligoMove"); nlinfo("ligoMove");
//m_undoStack->push(new LigoMoveCommand(index, deltaX, deltaY, this)); //m_undoStack->push(new LigoMoveCommand(index, deltaX, deltaY, this));
} }
void ZoneBuilder::actionLigoResize(uint index, sint32 newMinX, sint32 newMaxX, sint32 newMinY, sint32 newMaxY) void ZoneBuilder::actionLigoResize(uint index, sint32 newMinX, sint32 newMaxX, sint32 newMinY, sint32 newMaxY)
{ {
checkBeginMacro();
nlinfo(QString("minX=%1 maxX=%2 minY=%3 maxY=%4").arg(newMinX).arg(newMaxX).arg(newMinY).arg(newMaxY).toStdString().c_str()); 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)); m_undoStack->push(new LigoResizeCommand(index, newMinX, newMaxX, newMinY, newMaxY, this));
} }
@ -201,7 +205,11 @@ void ZoneBuilder::addZone(sint32 posX, sint32 posY)
NLLIGO::CZoneBankElement *zoneBankElement = getZoneBank().getElementByZoneName(zoneName); NLLIGO::CZoneBankElement *zoneBankElement = getZoneBank().getElementByZoneName(zoneName);
m_undoStack->beginMacro(QString("Add zone %1,%2").arg(posX).arg(posY)); m_titleAction = QString("Add zone %1,%2").arg(posX).arg(posY);
m_createdAction = false;
m_zonePositionList.clear();
nlinfo("---------");
if (m_listZonesWidget->isForce()) if (m_listZonesWidget->isForce())
{ {
builderZoneRegion->addForce(posX, posY, rot, flip, zoneBankElement); builderZoneRegion->addForce(posX, posY, rot, flip, zoneBankElement);
@ -213,7 +221,7 @@ void ZoneBuilder::addZone(sint32 posX, sint32 posY)
else else
builderZoneRegion->add(posX, posY, rot, flip, zoneBankElement); builderZoneRegion->add(posX, posY, rot, flip, zoneBankElement);
} }
m_undoStack->endMacro(); checkEndMacro();
} }
void ZoneBuilder::addTransition(const sint32 posX, const sint32 posY) void ZoneBuilder::addTransition(const sint32 posX, const sint32 posY)
@ -225,17 +233,20 @@ void ZoneBuilder::delZone(const sint32 posX, const sint32 posY)
if (m_builderZoneRegions.empty()) if (m_builderZoneRegions.empty())
return; return;
m_undoStack->beginMacro(QString("Del zone %1,%2").arg(posX).arg(posY)); m_titleAction = QString("Del zone %1,%2").arg(posX).arg(posY);
m_createdAction = false;
BuilderZoneRegion *builderZoneRegion = m_builderZoneRegions.at(m_currentZoneRegion); BuilderZoneRegion *builderZoneRegion = m_builderZoneRegions.at(m_currentZoneRegion);
std::string error; std::string error;
nlinfo("---------");
builderZoneRegion->init(this, error); builderZoneRegion->init(this, error);
builderZoneRegion->del(posX, posY); builderZoneRegion->del(posX, posY);
m_undoStack->endMacro(); checkEndMacro();
} }
int ZoneBuilder::createZoneRegion() int ZoneBuilder::createZoneRegion()
{ {
ZoneRegionEditor *newZoneRegion = new ZoneRegionEditor(); ZoneRegionObject *newZoneRegion = new ZoneRegionObject();
m_zoneRegions.push_back(newZoneRegion); m_zoneRegions.push_back(newZoneRegion);
if (m_currentZoneRegion == -1) if (m_currentZoneRegion == -1)
m_currentZoneRegion = m_zoneRegions.indexOf(newZoneRegion); m_currentZoneRegion = m_zoneRegions.indexOf(newZoneRegion);
@ -261,7 +272,7 @@ int ZoneBuilder::currentIdZoneRegion() const
return m_currentZoneRegion; return m_currentZoneRegion;
} }
ZoneRegionEditor *ZoneBuilder::currentZoneRegion() const ZoneRegionObject *ZoneBuilder::currentZoneRegion() const
{ {
return m_zoneRegions.at(m_currentZoneRegion); return m_zoneRegions.at(m_currentZoneRegion);
} }
@ -271,7 +282,7 @@ int ZoneBuilder::countZoneRegion() const
return m_zoneRegions.size(); return m_zoneRegions.size();
} }
ZoneRegionEditor *ZoneBuilder::zoneRegion(int id) const ZoneRegionObject *ZoneBuilder::zoneRegion(int id) const
{ {
return m_zoneRegions.at(id); return m_zoneRegions.at(id);
} }
@ -399,7 +410,7 @@ void ZoneBuilder::calcMask()
bool ZoneBuilder::getZoneAmongRegions (ZonePosition &zonePos, BuilderZoneRegion *builderZoneRegionFrom, sint32 x, sint32 y) bool ZoneBuilder::getZoneAmongRegions (ZonePosition &zonePos, BuilderZoneRegion *builderZoneRegionFrom, sint32 x, sint32 y)
{ {
Q_FOREACH(ZoneRegionEditor *zoneRegion, m_zoneRegions) Q_FOREACH(ZoneRegionObject *zoneRegion, m_zoneRegions)
{ {
const NLLIGO::CZoneRegion &region = zoneRegion->zoneRegion(); const NLLIGO::CZoneRegion &region = zoneRegion->zoneRegion();
if ((x < region.getMinX()) || (x > region.getMaxX()) || if ((x < region.getMinX()) || (x > region.getMaxX()) ||
@ -424,4 +435,27 @@ bool ZoneBuilder::getZoneAmongRegions (ZonePosition &zonePos, BuilderZoneRegion
return true; return true;
} }
void ZoneBuilder::checkBeginMacro()
{
if (!m_createdAction)
{
m_createdAction = true;
m_undoStack->beginMacro(m_titleAction);
m_undoScanRegionCommand = new UndoScanRegionCommand(this, m_landscapeScene);
m_undoStack->push(m_undoScanRegionCommand);
}
}
void ZoneBuilder::checkEndMacro()
{
if (m_createdAction)
{
RedoScanRegionCommand *redoScanRegionCommand = new RedoScanRegionCommand(this, m_landscapeScene);
m_undoScanRegionCommand->setScanList(m_zonePositionList);
redoScanRegionCommand->setScanList(m_zonePositionList);
m_undoStack->push(redoScanRegionCommand);
m_undoStack->endMacro();
}
}
} /* namespace LandscapeEditor */ } /* namespace LandscapeEditor */

View file

@ -42,6 +42,7 @@ namespace LandscapeEditor
{ {
class ListZonesWidget; class ListZonesWidget;
class LandscapeScene; class LandscapeScene;
class UndoScanRegionCommand;
// Data // Data
struct ZonePosition struct ZonePosition
@ -134,9 +135,9 @@ public:
void deleteZoneRegion(int id); void deleteZoneRegion(int id);
void setCurrentZoneRegion(int id); void setCurrentZoneRegion(int id);
int currentIdZoneRegion() const; int currentIdZoneRegion() const;
ZoneRegionEditor *currentZoneRegion() const; ZoneRegionObject *currentZoneRegion() const;
int countZoneRegion() const; int countZoneRegion() const;
ZoneRegionEditor *zoneRegion(int id) const; ZoneRegionObject *zoneRegion(int id) const;
void ligoData(LigoData &data, const ZonePosition &zonePos); void ligoData(LigoData &data, const ZonePosition &zonePos);
void setLigoData(LigoData &data, const ZonePosition &zonePos); void setLigoData(LigoData &data, const ZonePosition &zonePos);
@ -155,16 +156,24 @@ 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); bool initZoneBank (const QString &path);
void checkBeginMacro();
void checkEndMacro();
sint32 m_minX, m_maxX, m_minY, m_maxY; sint32 m_minX, m_maxX, m_minY, m_maxY;
std::vector<bool> m_zoneMask; std::vector<bool> m_zoneMask;
QString m_lastPathName; QString m_lastPathName;
QList<ZoneRegionEditor *> m_zoneRegions; QList<ZoneRegionObject *> m_zoneRegions;
int m_currentZoneRegion; int m_currentZoneRegion;
std::vector<BuilderZoneRegion *> m_builderZoneRegions; std::vector<BuilderZoneRegion *> m_builderZoneRegions;
bool m_createdAction;
QString m_titleAction;
QList<ZonePosition> m_zonePositionList;
UndoScanRegionCommand *m_undoScanRegionCommand;
PixmapDatabase *m_pixmapDatabase; PixmapDatabase *m_pixmapDatabase;
NLLIGO::CZoneBank m_zoneBank; NLLIGO::CZoneBank m_zoneBank;
ListZonesWidget *m_listZonesWidget; ListZonesWidget *m_listZonesWidget;

View file

@ -86,13 +86,79 @@ LigoTileCommand::~LigoTileCommand()
void LigoTileCommand::undo () void LigoTileCommand::undo ()
{ {
m_zoneBuilder->setLigoData(m_oldLigoData, m_zonePos); m_zoneBuilder->setLigoData(m_oldLigoData, m_zonePos);
m_scene->createZoneItem(m_oldLigoData, m_zonePos);
} }
void LigoTileCommand::redo () void LigoTileCommand::redo ()
{ {
m_zoneBuilder->setLigoData(m_newLigoData, m_zonePos); m_zoneBuilder->setLigoData(m_newLigoData, m_zonePos);
m_scene->createZoneItem(m_newLigoData, m_zonePos); }
UndoScanRegionCommand::UndoScanRegionCommand(ZoneBuilder *zoneBuilder, LandscapeScene *scene, QUndoCommand *parent)
: QUndoCommand(parent),
m_zoneBuilder(zoneBuilder),
m_scene(scene)
{
}
UndoScanRegionCommand::~UndoScanRegionCommand()
{
m_zonePositionList.clear();
}
void UndoScanRegionCommand::setScanList(const QList<ZonePosition> &zonePositionList)
{
m_zonePositionList = zonePositionList;
}
void UndoScanRegionCommand::undo()
{
for (int i = 0; i < m_zonePositionList.size(); ++i)
m_scene->deleteItemZone(m_zonePositionList.at(i));
nlinfo("------");
for (int i = 0; i < m_zonePositionList.size(); ++i)
{
LigoData data;
m_zoneBuilder->ligoData(data, m_zonePositionList.at(i));
m_scene->createItemZone(data, m_zonePositionList.at(i));
}
}
void UndoScanRegionCommand::redo()
{
}
RedoScanRegionCommand::RedoScanRegionCommand(ZoneBuilder *zoneBuilder, LandscapeScene *scene, QUndoCommand *parent)
: QUndoCommand(parent),
m_zoneBuilder(zoneBuilder),
m_scene(scene)
{
}
RedoScanRegionCommand::~RedoScanRegionCommand()
{
m_zonePositionList.clear();
}
void RedoScanRegionCommand::setScanList(const QList<ZonePosition> &zonePositionList)
{
m_zonePositionList = zonePositionList;
}
void RedoScanRegionCommand::undo()
{
}
void RedoScanRegionCommand::redo()
{
for (int i = 0; i < m_zonePositionList.size(); ++i)
m_scene->deleteItemZone(m_zonePositionList.at(i));
nlinfo("------");
for (int i = 0; i < m_zonePositionList.size(); ++i)
{
LigoData data;
m_zoneBuilder->ligoData(data, m_zonePositionList.at(i));
m_scene->createItemZone(data, m_zonePositionList.at(i));
}
} }
LigoResizeCommand::LigoResizeCommand(int index, sint32 newMinX, sint32 newMaxX, LigoResizeCommand::LigoResizeCommand(int index, sint32 newMinX, sint32 newMaxX,

View file

@ -75,6 +75,41 @@ private:
ZoneBuilder *m_zoneBuilder; ZoneBuilder *m_zoneBuilder;
LandscapeScene *m_scene; LandscapeScene *m_scene;
}; };
class UndoScanRegionCommand: public QUndoCommand
{
public:
UndoScanRegionCommand(ZoneBuilder *zoneBuilder, LandscapeScene *scene, QUndoCommand *parent = 0);
virtual ~UndoScanRegionCommand();
void setScanList(const QList<ZonePosition> &zonePositionList);
virtual void undo();
virtual void redo();
private:
QList<ZonePosition> m_zonePositionList;
ZoneBuilder *m_zoneBuilder;
LandscapeScene *m_scene;
};
class RedoScanRegionCommand: public QUndoCommand
{
public:
RedoScanRegionCommand(ZoneBuilder *zoneBuilder, LandscapeScene *scene, QUndoCommand *parent = 0);
virtual ~RedoScanRegionCommand();
void setScanList(const QList<ZonePosition> &zonePositionList);
virtual void undo();
virtual void redo();
private:
QList<ZonePosition> m_zonePositionList;
ZoneBuilder *m_zoneBuilder;
LandscapeScene *m_scene;
};
/* /*
// Move the landscape // Move the landscape
class LigoMoveCommand: public QUndoCommand class LigoMoveCommand: public QUndoCommand

View file

@ -62,6 +62,7 @@ LandscapeEditorWindow::LandscapeEditorWindow(QWidget *parent)
createToolBars(); createToolBars();
readSettings(); readSettings();
connect(m_ui.saveAction, SIGNAL(triggered()), this, SLOT(save()));
connect(m_ui.projectSettingsAction, SIGNAL(triggered()), this, SLOT(openProjectSettings())); connect(m_ui.projectSettingsAction, SIGNAL(triggered()), this, SLOT(openProjectSettings()));
connect(m_ui.snapshotAction, SIGNAL(triggered()), this, SLOT(openSnapshotDialog())); 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.enableGridAction, SIGNAL(toggled(bool)), m_ui.graphicsView, SLOT(setVisibleGrid(bool)));
@ -92,7 +93,7 @@ void LandscapeEditorWindow::open()
Q_FOREACH(QString fileName, fileNames) Q_FOREACH(QString fileName, fileNames)
{ {
int id = m_zoneBuilder->createZoneRegion(); int id = m_zoneBuilder->createZoneRegion();
ZoneRegionEditor *zoneRegion = m_zoneBuilder->zoneRegion(id); ZoneRegionObject *zoneRegion = m_zoneBuilder->zoneRegion(id);
zoneRegion->load(fileName.toStdString()); zoneRegion->load(fileName.toStdString());
m_landscapeScene->processZoneRegion(zoneRegion->zoneRegion()); m_landscapeScene->processZoneRegion(zoneRegion->zoneRegion());
m_ui.graphicsView->centerOn(zoneRegion->zoneRegion().getMinX() * m_landscapeScene->cellSize(), m_ui.graphicsView->centerOn(zoneRegion->zoneRegion().getMinX() * m_landscapeScene->cellSize(),
@ -104,6 +105,20 @@ void LandscapeEditorWindow::open()
setCursor(Qt::ArrowCursor); setCursor(Qt::ArrowCursor);
} }
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();
}
void LandscapeEditorWindow::openProjectSettings() void LandscapeEditorWindow::openProjectSettings()
{ {
ProjectSettingsDialog *dialog = new ProjectSettingsDialog(m_zoneBuilder->dataPath(), this); ProjectSettingsDialog *dialog = new ProjectSettingsDialog(m_zoneBuilder->dataPath(), this);

View file

@ -43,6 +43,7 @@ public:
Q_SIGNALS: Q_SIGNALS:
public Q_SLOTS: public Q_SLOTS:
void open(); void open();
void save();
private Q_SLOTS: private Q_SLOTS:
void openProjectSettings(); void openProjectSettings();

View file

@ -72,6 +72,7 @@
<attribute name="toolBarBreak"> <attribute name="toolBarBreak">
<bool>false</bool> <bool>false</bool>
</attribute> </attribute>
<addaction name="saveAction"/>
<addaction name="snapshotAction"/> <addaction name="snapshotAction"/>
<addaction name="projectSettingsAction"/> <addaction name="projectSettingsAction"/>
<addaction name="enableGridAction"/> <addaction name="enableGridAction"/>
@ -107,6 +108,11 @@
<string>snapshot</string> <string>snapshot</string>
</property> </property>
</action> </action>
<action name="saveAction">
<property name="text">
<string>Save</string>
</property>
</action>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>

View file

@ -29,8 +29,12 @@
namespace LandscapeEditor namespace LandscapeEditor
{ {
static const int ZoneName = 0;
LandscapeScene::LandscapeScene(QObject *parent) LandscapeScene::LandscapeScene(QObject *parent)
: QGraphicsScene(parent), : QGraphicsScene(parent),
m_mouseX(0.0),
m_mouseY(0.0),
m_zoneBuilder(0) m_zoneBuilder(0)
{ {
m_cellSize = 160; m_cellSize = 160;
@ -50,16 +54,21 @@ void LandscapeScene::setZoneBuilder(ZoneBuilder *zoneBuilder)
m_zoneBuilder = zoneBuilder; m_zoneBuilder = zoneBuilder;
} }
QGraphicsItem *LandscapeScene::createZoneItem(const LigoData &data, const ZonePosition &zonePos) QGraphicsItem *LandscapeScene::createItemZone(const LigoData &data, const ZonePosition &zonePos)
{ {
nlinfo(QString("%1,%2 (%3,%4)-%7 (%5,%6)").arg(zonePos.x).arg(zonePos.y).arg(data.posX).arg(data.posY).arg(data.rot).arg(data.flip).arg(data.zoneName.c_str()).toStdString().c_str());
if ((data.zoneName == STRING_OUT_OF_BOUND) || (checkUnderZone(zonePos.x, zonePos.y)))
return 0;
if (data.zoneName == STRING_UNUSED) if (data.zoneName == STRING_UNUSED)
return createEmptyZoneItem(zonePos); return createItemEmptyZone(zonePos);
if ((m_zoneBuilder == 0) || (data.zoneName.empty()) || if ((m_zoneBuilder == 0) || (data.zoneName.empty()) ||
(data.posX != 0) || (data.posY != 0)) (data.posX != 0) || (data.posY != 0))
return 0; return 0;
checkUnderZone(data, zonePos); // if ((m_zoneBuilder == 0) || (data.zoneName.empty()))
// return 0;
// Get image from pixmap database // 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()));
@ -88,21 +97,27 @@ QGraphicsItem *LandscapeScene::createZoneItem(const LigoData &data, const ZonePo
// Set position graphics item with offset for large piece // Set position graphics item with offset for large piece
NLLIGO::CZoneBankElement *zoneBankItem = m_zoneBuilder->getZoneBank().getElementByZoneName(data.zoneName); NLLIGO::CZoneBankElement *zoneBankItem = m_zoneBuilder->getZoneBank().getElementByZoneName(data.zoneName);
item->setPos(zonePos.x * m_cellSize, (abs(zonePos.y) - zoneBankItem->getSizeY() + 1) * m_cellSize);
int delta = zoneBankItem->getSizeY() - 1;
if ((data.rot == 1) || (data.rot == 3))
delta = zoneBankItem->getSizeX() - 1;
//item->setPos((zonePos.x - data.posX) * m_cellSize, (abs(int(zonePos.y)) + data.posY - delta) * m_cellSize);
item->setPos((zonePos.x) * m_cellSize, (abs(int(zonePos.y)) - delta) * m_cellSize);
// 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(ZoneName, QString(data.zoneName.c_str()));
nlinfo("render");
return item; return item;
} }
QGraphicsItem *LandscapeScene::createEmptyZoneItem(const ZonePosition &zonePos) QGraphicsItem *LandscapeScene::createItemEmptyZone(const ZonePosition &zonePos)
{ {
if (m_zoneBuilder == 0) if (m_zoneBuilder == 0)
return 0; return 0;
deleteZoneItem(zonePos);
// Get image from pixmap database // Get image from pixmap database
QPixmap *pixmap = m_zoneBuilder->pixmapDatabase()->pixmap(QString(STRING_UNUSED)); QPixmap *pixmap = m_zoneBuilder->pixmapDatabase()->pixmap(QString(STRING_UNUSED));
if (pixmap == 0) if (pixmap == 0)
@ -118,11 +133,11 @@ QGraphicsItem *LandscapeScene::createEmptyZoneItem(const ZonePosition &zonePos)
// 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());
nlinfo("render");
return item; return item;
} }
void LandscapeScene::deleteZoneItem(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)
@ -143,7 +158,7 @@ void LandscapeScene::processZoneRegion(const NLLIGO::CZoneRegion &zoneRegion)
if (zoneName == STRING_UNUSED) if (zoneName == STRING_UNUSED)
{ {
ZonePosition zonePos(i, j, -1); ZonePosition zonePos(i, j, -1);
QGraphicsItem *item = createEmptyZoneItem(zonePos); QGraphicsItem *item = createItemEmptyZone(zonePos);
} }
else if (!zoneName.empty()) else if (!zoneName.empty())
{ {
@ -154,7 +169,7 @@ void LandscapeScene::processZoneRegion(const NLLIGO::CZoneRegion &zoneRegion)
data.flip = zoneRegion.getFlip(i, j); data.flip = zoneRegion.getFlip(i, j);
data.posX = zoneRegion.getPosX(i, j); data.posX = zoneRegion.getPosX(i, j);
data.posY = zoneRegion.getPosY(i, j); data.posY = zoneRegion.getPosY(i, j);
QGraphicsItem *item = createZoneItem(data, zonePos); QGraphicsItem *item = createItemZone(data, zonePos);
} }
} }
} }
@ -230,13 +245,43 @@ void LandscapeScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
QGraphicsScene::mousePressEvent(mouseEvent); QGraphicsScene::mousePressEvent(mouseEvent);
} }
void LandscapeScene::checkUnderZone(const LigoData &data, const ZonePosition &zonePos) void LandscapeScene::mouseMoveEvent(QGraphicsSceneMouseEvent * mouseEvent)
{ {
// NLLIGO::CZoneBankElement *zoneBankItem = m_zoneBuilder->getZoneBank().getElementByZoneName(data.zoneName); m_mouseX = mouseEvent->scenePos().x();
// uint8 sizeX = zoneBankItem->getSizeX(); m_mouseY = mouseEvent->scenePos().y();
// uint8 sizeY = zoneBankItem->getSizeY(); QGraphicsScene::mouseMoveEvent(mouseEvent);
// std::vector<bool> &mask = zoneBankItem->getMask(); }
deleteZoneItem(zonePos);
bool LandscapeScene::checkUnderZone(const int posX, const int posY)
{
/* QGraphicsItem *item = itemAt((posX * m_cellSize), abs(posY) * m_cellSize);
if (item != 0)
{
QString zoneName = item->data(ZoneName).toString();
return true;
}
*/ return false;
}
void LandscapeScene::drawForeground(QPainter *painter, const QRectF &rect)
{
QGraphicsScene::drawForeground(painter, rect);
painter->setPen(QPen(Qt::white, 0.5, Qt::SolidLine));
int left = int(floor(rect.left() / m_cellSize));
int right = int(floor(rect.right() / m_cellSize));
int top = int(floor(rect.top() / m_cellSize));
int bottom = int(floor(rect.bottom() / m_cellSize));
for (int i = left; i < right; ++i)
{
for (int j = top; j < bottom; ++j)
{
LigoData data;
m_zoneBuilder->currentZoneRegion()->ligoData(data, i, -j);
painter->drawText(i * m_cellSize + 10, j * m_cellSize + 10, QString("%1 %2 %3 %4").arg(i).arg(j).arg(data.posX).arg(data.posY));
}
}
} }
} /* namespace LandscapeEditor */ } /* namespace LandscapeEditor */

View file

@ -43,9 +43,9 @@ public:
int cellSize() const; int cellSize() const;
void setZoneBuilder(ZoneBuilder *zoneBuilder); void setZoneBuilder(ZoneBuilder *zoneBuilder);
QGraphicsItem *createZoneItem(const LigoData &data, const ZonePosition &zonePos); QGraphicsItem *createItemZone(const LigoData &data, const ZonePosition &zonePos);
QGraphicsItem *createEmptyZoneItem(const ZonePosition &zonePos); QGraphicsItem *createItemEmptyZone(const ZonePosition &zonePos);
void deleteZoneItem(const ZonePosition &zonePos); void deleteItemZone(const ZonePosition &zonePos);
void processZoneRegion(const NLLIGO::CZoneRegion &zoneRegion); void processZoneRegion(const NLLIGO::CZoneRegion &zoneRegion);
void snapshot(const QString &fileName, int sizeSource); void snapshot(const QString &fileName, int sizeSource);
@ -53,11 +53,14 @@ public:
protected: protected:
virtual void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent); virtual void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent);
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * mouseEvent);
virtual void drawForeground(QPainter *painter, const QRectF &rect);
private: private:
void checkUnderZone(const LigoData &data, const ZonePosition &zonePos); bool checkUnderZone(const int posX, const int posY);
int m_cellSize; int m_cellSize;
qreal m_mouseX, m_mouseY;
ZoneBuilder *m_zoneBuilder; ZoneBuilder *m_zoneBuilder;
}; };

View file

@ -110,6 +110,8 @@ void LandscapeView::mouseReleaseEvent(QMouseEvent *event)
void LandscapeView::drawForeground(QPainter *painter, const QRectF &rect) void LandscapeView::drawForeground(QPainter *painter, const QRectF &rect)
{ {
QGraphicsView::drawForeground(painter, rect);
if (!m_visibleGrid) if (!m_visibleGrid)
return; return;

View file

@ -47,16 +47,33 @@ LigoData::LigoData()
sharingCutEdges[3] = 0; sharingCutEdges[3] = 0;
} }
ZoneRegionEditor::ZoneRegionEditor() 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 = ""; m_fileName = "";
} }
ZoneRegionEditor::~ZoneRegionEditor() ZoneRegionObject::~ZoneRegionObject()
{ {
} }
bool ZoneRegionEditor::load(const std::string &fileName) bool ZoneRegionObject::load(const std::string &fileName)
{ {
bool result = true; bool result = true;
try try
@ -85,7 +102,7 @@ bool ZoneRegionEditor::load(const std::string &fileName)
return result; return result;
} }
bool ZoneRegionEditor::save() bool ZoneRegionObject::save()
{ {
if (m_fileName.empty()) if (m_fileName.empty())
return false; return false;
@ -123,18 +140,24 @@ bool ZoneRegionEditor::save()
return result; return result;
} }
void ZoneRegionEditor::setFileName(const std::string &fileName) std::string ZoneRegionObject::fileName() const
{
return m_fileName;
}
void ZoneRegionObject::setFileName(const std::string &fileName)
{ {
m_fileName = fileName; m_fileName = fileName;
} }
void ZoneRegionEditor::ligoData(LigoData &data, const sint32 x, const sint32 y) void ZoneRegionObject::ligoData(LigoData &data, const sint32 x, const sint32 y)
{ {
/*
nlassert((x >= m_zoneRegion.getMinX()) && nlassert((x >= m_zoneRegion.getMinX()) &&
(x <= m_zoneRegion.getMaxX()) && (x <= m_zoneRegion.getMaxX()) &&
(y >= m_zoneRegion.getMinY()) && (y >= m_zoneRegion.getMinY()) &&
(y <= m_zoneRegion.getMaxY())); (y <= m_zoneRegion.getMaxY()));
*/
data.posX = m_zoneRegion.getPosX(x, y); data.posX = m_zoneRegion.getPosX(x, y);
data.posY = m_zoneRegion.getPosY(x, y); data.posY = m_zoneRegion.getPosY(x, y);
data.zoneName = m_zoneRegion.getName(x, y); data.zoneName = m_zoneRegion.getName(x, y);
@ -150,13 +173,14 @@ void ZoneRegionEditor::ligoData(LigoData &data, const sint32 x, const sint32 y)
data.sharingCutEdges[3] = m_zoneRegion.getSharingCutEdges(x, y, 3); data.sharingCutEdges[3] = m_zoneRegion.getSharingCutEdges(x, y, 3);
} }
void ZoneRegionEditor::setLigoData(const LigoData &data, const sint32 x, const sint32 y) void ZoneRegionObject::setLigoData(const LigoData &data, const sint32 x, const sint32 y)
{ {
/*
nlassert((x >= m_zoneRegion.getMinX()) && nlassert((x >= m_zoneRegion.getMinX()) &&
(x <= m_zoneRegion.getMaxX()) && (x <= m_zoneRegion.getMaxX()) &&
(y >= m_zoneRegion.getMinY()) && (y >= m_zoneRegion.getMinY()) &&
(y <= m_zoneRegion.getMaxY())); (y <= m_zoneRegion.getMaxY()));
*/
m_zoneRegion.setPosX(x, y, data.posX); m_zoneRegion.setPosX(x, y, data.posX);
m_zoneRegion.setPosY(x, y, data.posY); m_zoneRegion.setPosY(x, y, data.posY);
m_zoneRegion.setName(x, y, data.zoneName); m_zoneRegion.setName(x, y, data.zoneName);
@ -172,14 +196,22 @@ void ZoneRegionEditor::setLigoData(const LigoData &data, const sint32 x, const s
m_zoneRegion.setSharingCutEdges(x, y, 3, data.sharingCutEdges[3]); m_zoneRegion.setSharingCutEdges(x, y, 3, data.sharingCutEdges[3]);
} }
NLLIGO::CZoneRegion &ZoneRegionEditor::zoneRegion() NLLIGO::CZoneRegion &ZoneRegionObject::zoneRegion()
{ {
return m_zoneRegion; return m_zoneRegion;
} }
void ZoneRegionEditor::setZoneRegion(const NLLIGO::CZoneRegion &zoneRegion) void ZoneRegionObject::setZoneRegion(const NLLIGO::CZoneRegion &zoneRegion)
{ {
m_zoneRegion = zoneRegion; m_zoneRegion = zoneRegion;
} }
bool ZoneRegionObject::checkPos(const sint32 x, const sint32 y)
{
return ((x >= m_zoneRegion.getMinX()) &&
(x <= m_zoneRegion.getMaxX()) &&
(y >= m_zoneRegion.getMinY()) &&
(y <= m_zoneRegion.getMaxY()));
}
} /* namespace LandscapeEditor */ } /* namespace LandscapeEditor */

View file

@ -44,29 +44,14 @@ struct LigoData
LigoData(); LigoData();
bool operator!= (const LigoData& other) const 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 class ZoneRegionObject
{ {
public: public:
ZoneRegionEditor(); ZoneRegionObject();
~ZoneRegionEditor(); ~ZoneRegionObject();
// Load landscape data from file // Load landscape data from file
bool load(const std::string &fileName); bool load(const std::string &fileName);
@ -78,6 +63,8 @@ public:
void setLigoData(const LigoData &data, const sint32 x, const sint32 y); void setLigoData(const LigoData &data, const sint32 x, const sint32 y);
std::string fileName() const;
// Set file name // Set file name
void setFileName(const std::string &fileName); void setFileName(const std::string &fileName);
@ -85,6 +72,8 @@ public:
void setZoneRegion(const NLLIGO::CZoneRegion &zoneRegion); void setZoneRegion(const NLLIGO::CZoneRegion &zoneRegion);
bool checkPos(const sint32 x, const sint32 y);
private: private:
bool m_modified; bool m_modified;