mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-24 08:06:13 +00:00
Changed: #1301 Improved 2d render. Fixed adding empty undo/redo operations in command list, improved performance when adding new zones.
--HG-- branch : gsoc2011-worldeditorqt
This commit is contained in:
parent
7c98cba1f5
commit
b390026b76
12 changed files with 310 additions and 73 deletions
|
@ -167,18 +167,22 @@ bool ZoneBuilder::init(const QString &pathName, bool makeAZone)
|
|||
|
||||
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());
|
||||
m_zonePositionList.push_back(zonePos);
|
||||
m_undoStack->push(new LigoTileCommand(data, zonePos, this, m_landscapeScene));
|
||||
}
|
||||
|
||||
void ZoneBuilder::actionLigoMove(uint index, sint32 deltaX, sint32 deltaY)
|
||||
{
|
||||
checkBeginMacro();
|
||||
nlinfo("ligoMove");
|
||||
//m_undoStack->push(new LigoMoveCommand(index, deltaX, deltaY, this));
|
||||
}
|
||||
|
||||
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());
|
||||
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);
|
||||
|
||||
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())
|
||||
{
|
||||
builderZoneRegion->addForce(posX, posY, rot, flip, zoneBankElement);
|
||||
|
@ -213,7 +221,7 @@ void ZoneBuilder::addZone(sint32 posX, sint32 posY)
|
|||
else
|
||||
builderZoneRegion->add(posX, posY, rot, flip, zoneBankElement);
|
||||
}
|
||||
m_undoStack->endMacro();
|
||||
checkEndMacro();
|
||||
}
|
||||
|
||||
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())
|
||||
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);
|
||||
std::string error;
|
||||
nlinfo("---------");
|
||||
builderZoneRegion->init(this, error);
|
||||
builderZoneRegion->del(posX, posY);
|
||||
m_undoStack->endMacro();
|
||||
checkEndMacro();
|
||||
}
|
||||
|
||||
int ZoneBuilder::createZoneRegion()
|
||||
{
|
||||
ZoneRegionEditor *newZoneRegion = new ZoneRegionEditor();
|
||||
ZoneRegionObject *newZoneRegion = new ZoneRegionObject();
|
||||
m_zoneRegions.push_back(newZoneRegion);
|
||||
if (m_currentZoneRegion == -1)
|
||||
m_currentZoneRegion = m_zoneRegions.indexOf(newZoneRegion);
|
||||
|
@ -261,7 +272,7 @@ int ZoneBuilder::currentIdZoneRegion() const
|
|||
return m_currentZoneRegion;
|
||||
}
|
||||
|
||||
ZoneRegionEditor *ZoneBuilder::currentZoneRegion() const
|
||||
ZoneRegionObject *ZoneBuilder::currentZoneRegion() const
|
||||
{
|
||||
return m_zoneRegions.at(m_currentZoneRegion);
|
||||
}
|
||||
|
@ -271,7 +282,7 @@ int ZoneBuilder::countZoneRegion() const
|
|||
return m_zoneRegions.size();
|
||||
}
|
||||
|
||||
ZoneRegionEditor *ZoneBuilder::zoneRegion(int id) const
|
||||
ZoneRegionObject *ZoneBuilder::zoneRegion(int id) const
|
||||
{
|
||||
return m_zoneRegions.at(id);
|
||||
}
|
||||
|
@ -399,7 +410,7 @@ void ZoneBuilder::calcMask()
|
|||
|
||||
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 ®ion = zoneRegion->zoneRegion();
|
||||
if ((x < region.getMinX()) || (x > region.getMaxX()) ||
|
||||
|
@ -424,4 +435,27 @@ bool ZoneBuilder::getZoneAmongRegions (ZonePosition &zonePos, BuilderZoneRegion
|
|||
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 */
|
||||
|
|
|
@ -42,6 +42,7 @@ namespace LandscapeEditor
|
|||
{
|
||||
class ListZonesWidget;
|
||||
class LandscapeScene;
|
||||
class UndoScanRegionCommand;
|
||||
|
||||
// Data
|
||||
struct ZonePosition
|
||||
|
@ -134,9 +135,9 @@ public:
|
|||
void deleteZoneRegion(int id);
|
||||
void setCurrentZoneRegion(int id);
|
||||
int currentIdZoneRegion() const;
|
||||
ZoneRegionEditor *currentZoneRegion() const;
|
||||
ZoneRegionObject *currentZoneRegion() const;
|
||||
int countZoneRegion() const;
|
||||
ZoneRegionEditor *zoneRegion(int id) const;
|
||||
ZoneRegionObject *zoneRegion(int id) const;
|
||||
void ligoData(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
|
||||
bool initZoneBank (const QString &path);
|
||||
|
||||
void checkBeginMacro();
|
||||
void checkEndMacro();
|
||||
|
||||
sint32 m_minX, m_maxX, m_minY, m_maxY;
|
||||
std::vector<bool> m_zoneMask;
|
||||
|
||||
QString m_lastPathName;
|
||||
|
||||
QList<ZoneRegionEditor *> m_zoneRegions;
|
||||
QList<ZoneRegionObject *> m_zoneRegions;
|
||||
int m_currentZoneRegion;
|
||||
|
||||
std::vector<BuilderZoneRegion *> m_builderZoneRegions;
|
||||
|
||||
bool m_createdAction;
|
||||
QString m_titleAction;
|
||||
QList<ZonePosition> m_zonePositionList;
|
||||
UndoScanRegionCommand *m_undoScanRegionCommand;
|
||||
|
||||
PixmapDatabase *m_pixmapDatabase;
|
||||
NLLIGO::CZoneBank m_zoneBank;
|
||||
ListZonesWidget *m_listZonesWidget;
|
||||
|
|
|
@ -86,13 +86,79 @@ LigoTileCommand::~LigoTileCommand()
|
|||
void LigoTileCommand::undo ()
|
||||
{
|
||||
m_zoneBuilder->setLigoData(m_oldLigoData, m_zonePos);
|
||||
m_scene->createZoneItem(m_oldLigoData, m_zonePos);
|
||||
}
|
||||
|
||||
void LigoTileCommand::redo ()
|
||||
{
|
||||
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,
|
||||
|
|
|
@ -75,6 +75,41 @@ private:
|
|||
ZoneBuilder *m_zoneBuilder;
|
||||
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
|
||||
class LigoMoveCommand: public QUndoCommand
|
||||
|
|
|
@ -62,6 +62,7 @@ LandscapeEditorWindow::LandscapeEditorWindow(QWidget *parent)
|
|||
createToolBars();
|
||||
readSettings();
|
||||
|
||||
connect(m_ui.saveAction, SIGNAL(triggered()), this, SLOT(save()));
|
||||
connect(m_ui.projectSettingsAction, SIGNAL(triggered()), this, SLOT(openProjectSettings()));
|
||||
connect(m_ui.snapshotAction, SIGNAL(triggered()), this, SLOT(openSnapshotDialog()));
|
||||
connect(m_ui.enableGridAction, SIGNAL(toggled(bool)), m_ui.graphicsView, SLOT(setVisibleGrid(bool)));
|
||||
|
@ -92,7 +93,7 @@ void LandscapeEditorWindow::open()
|
|||
Q_FOREACH(QString fileName, fileNames)
|
||||
{
|
||||
int id = m_zoneBuilder->createZoneRegion();
|
||||
ZoneRegionEditor *zoneRegion = m_zoneBuilder->zoneRegion(id);
|
||||
ZoneRegionObject *zoneRegion = m_zoneBuilder->zoneRegion(id);
|
||||
zoneRegion->load(fileName.toStdString());
|
||||
m_landscapeScene->processZoneRegion(zoneRegion->zoneRegion());
|
||||
m_ui.graphicsView->centerOn(zoneRegion->zoneRegion().getMinX() * m_landscapeScene->cellSize(),
|
||||
|
@ -104,6 +105,20 @@ void LandscapeEditorWindow::open()
|
|||
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()
|
||||
{
|
||||
ProjectSettingsDialog *dialog = new ProjectSettingsDialog(m_zoneBuilder->dataPath(), this);
|
||||
|
|
|
@ -43,6 +43,7 @@ public:
|
|||
Q_SIGNALS:
|
||||
public Q_SLOTS:
|
||||
void open();
|
||||
void save();
|
||||
|
||||
private Q_SLOTS:
|
||||
void openProjectSettings();
|
||||
|
|
|
@ -72,6 +72,7 @@
|
|||
<attribute name="toolBarBreak">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<addaction name="saveAction"/>
|
||||
<addaction name="snapshotAction"/>
|
||||
<addaction name="projectSettingsAction"/>
|
||||
<addaction name="enableGridAction"/>
|
||||
|
@ -107,6 +108,11 @@
|
|||
<string>snapshot</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="saveAction">
|
||||
<property name="text">
|
||||
<string>Save</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
|
|
|
@ -29,8 +29,12 @@
|
|||
namespace LandscapeEditor
|
||||
{
|
||||
|
||||
static const int ZoneName = 0;
|
||||
|
||||
LandscapeScene::LandscapeScene(QObject *parent)
|
||||
: QGraphicsScene(parent),
|
||||
m_mouseX(0.0),
|
||||
m_mouseY(0.0),
|
||||
m_zoneBuilder(0)
|
||||
{
|
||||
m_cellSize = 160;
|
||||
|
@ -50,16 +54,21 @@ void LandscapeScene::setZoneBuilder(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)
|
||||
return createEmptyZoneItem(zonePos);
|
||||
return createItemEmptyZone(zonePos);
|
||||
|
||||
if ((m_zoneBuilder == 0) || (data.zoneName.empty()) ||
|
||||
(data.posX != 0) || (data.posY != 0))
|
||||
return 0;
|
||||
|
||||
checkUnderZone(data, zonePos);
|
||||
// if ((m_zoneBuilder == 0) || (data.zoneName.empty()))
|
||||
// return 0;
|
||||
|
||||
// Get image from pixmap database
|
||||
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
|
||||
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
|
||||
item->setScale(float(m_cellSize) / m_zoneBuilder->pixmapDatabase()->textureSize());
|
||||
|
||||
item->setData(ZoneName, QString(data.zoneName.c_str()));
|
||||
nlinfo("render");
|
||||
return item;
|
||||
}
|
||||
|
||||
QGraphicsItem *LandscapeScene::createEmptyZoneItem(const ZonePosition &zonePos)
|
||||
QGraphicsItem *LandscapeScene::createItemEmptyZone(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)
|
||||
|
@ -118,11 +133,11 @@ QGraphicsItem *LandscapeScene::createEmptyZoneItem(const ZonePosition &zonePos)
|
|||
|
||||
// The size graphics item should be equal or proportional m_cellSize
|
||||
item->setScale(float(m_cellSize) / m_zoneBuilder->pixmapDatabase()->textureSize());
|
||||
|
||||
nlinfo("render");
|
||||
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);
|
||||
if (item != 0)
|
||||
|
@ -143,7 +158,7 @@ void LandscapeScene::processZoneRegion(const NLLIGO::CZoneRegion &zoneRegion)
|
|||
if (zoneName == STRING_UNUSED)
|
||||
{
|
||||
ZonePosition zonePos(i, j, -1);
|
||||
QGraphicsItem *item = createEmptyZoneItem(zonePos);
|
||||
QGraphicsItem *item = createItemEmptyZone(zonePos);
|
||||
}
|
||||
else if (!zoneName.empty())
|
||||
{
|
||||
|
@ -154,7 +169,7 @@ void LandscapeScene::processZoneRegion(const NLLIGO::CZoneRegion &zoneRegion)
|
|||
data.flip = zoneRegion.getFlip(i, j);
|
||||
data.posX = zoneRegion.getPosX(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);
|
||||
}
|
||||
|
||||
void LandscapeScene::checkUnderZone(const LigoData &data, const ZonePosition &zonePos)
|
||||
void LandscapeScene::mouseMoveEvent(QGraphicsSceneMouseEvent * mouseEvent)
|
||||
{
|
||||
// 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);
|
||||
m_mouseX = mouseEvent->scenePos().x();
|
||||
m_mouseY = mouseEvent->scenePos().y();
|
||||
QGraphicsScene::mouseMoveEvent(mouseEvent);
|
||||
}
|
||||
|
||||
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 */
|
||||
|
|
|
@ -43,9 +43,9 @@ public:
|
|||
int cellSize() const;
|
||||
void setZoneBuilder(ZoneBuilder *zoneBuilder);
|
||||
|
||||
QGraphicsItem *createZoneItem(const LigoData &data, const ZonePosition &zonePos);
|
||||
QGraphicsItem *createEmptyZoneItem(const ZonePosition &zonePos);
|
||||
void deleteZoneItem(const ZonePosition &zonePos);
|
||||
QGraphicsItem *createItemZone(const LigoData &data, const ZonePosition &zonePos);
|
||||
QGraphicsItem *createItemEmptyZone(const ZonePosition &zonePos);
|
||||
void deleteItemZone(const ZonePosition &zonePos);
|
||||
void processZoneRegion(const NLLIGO::CZoneRegion &zoneRegion);
|
||||
|
||||
void snapshot(const QString &fileName, int sizeSource);
|
||||
|
@ -53,11 +53,14 @@ public:
|
|||
|
||||
protected:
|
||||
virtual void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent);
|
||||
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * mouseEvent);
|
||||
virtual void drawForeground(QPainter *painter, const QRectF &rect);
|
||||
|
||||
private:
|
||||
void checkUnderZone(const LigoData &data, const ZonePosition &zonePos);
|
||||
bool checkUnderZone(const int posX, const int posY);
|
||||
|
||||
int m_cellSize;
|
||||
qreal m_mouseX, m_mouseY;
|
||||
ZoneBuilder *m_zoneBuilder;
|
||||
};
|
||||
|
||||
|
|
|
@ -110,6 +110,8 @@ void LandscapeView::mouseReleaseEvent(QMouseEvent *event)
|
|||
|
||||
void LandscapeView::drawForeground(QPainter *painter, const QRectF &rect)
|
||||
{
|
||||
QGraphicsView::drawForeground(painter, rect);
|
||||
|
||||
if (!m_visibleGrid)
|
||||
return;
|
||||
|
||||
|
|
|
@ -47,16 +47,33 @@ LigoData::LigoData()
|
|||
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 = "";
|
||||
}
|
||||
|
||||
ZoneRegionEditor::~ZoneRegionEditor()
|
||||
ZoneRegionObject::~ZoneRegionObject()
|
||||
{
|
||||
}
|
||||
|
||||
bool ZoneRegionEditor::load(const std::string &fileName)
|
||||
bool ZoneRegionObject::load(const std::string &fileName)
|
||||
{
|
||||
bool result = true;
|
||||
try
|
||||
|
@ -85,7 +102,7 @@ bool ZoneRegionEditor::load(const std::string &fileName)
|
|||
return result;
|
||||
}
|
||||
|
||||
bool ZoneRegionEditor::save()
|
||||
bool ZoneRegionObject::save()
|
||||
{
|
||||
if (m_fileName.empty())
|
||||
return false;
|
||||
|
@ -123,18 +140,24 @@ bool ZoneRegionEditor::save()
|
|||
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;
|
||||
}
|
||||
|
||||
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()) &&
|
||||
(x <= m_zoneRegion.getMaxX()) &&
|
||||
(y >= m_zoneRegion.getMinY()) &&
|
||||
(y <= m_zoneRegion.getMaxY()));
|
||||
|
||||
/*
|
||||
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);
|
||||
|
@ -150,13 +173,14 @@ void ZoneRegionEditor::ligoData(LigoData &data, const sint32 x, const sint32 y)
|
|||
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()) &&
|
||||
(x <= m_zoneRegion.getMaxX()) &&
|
||||
(y >= m_zoneRegion.getMinY()) &&
|
||||
(y <= m_zoneRegion.getMaxY()));
|
||||
|
||||
/*
|
||||
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);
|
||||
|
@ -172,14 +196,22 @@ void ZoneRegionEditor::setLigoData(const LigoData &data, const sint32 x, const s
|
|||
m_zoneRegion.setSharingCutEdges(x, y, 3, data.sharingCutEdges[3]);
|
||||
}
|
||||
|
||||
NLLIGO::CZoneRegion &ZoneRegionEditor::zoneRegion()
|
||||
NLLIGO::CZoneRegion &ZoneRegionObject::zoneRegion()
|
||||
{
|
||||
return m_zoneRegion;
|
||||
}
|
||||
|
||||
void ZoneRegionEditor::setZoneRegion(const NLLIGO::CZoneRegion &zoneRegion)
|
||||
void ZoneRegionObject::setZoneRegion(const NLLIGO::CZoneRegion &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 */
|
||||
|
|
|
@ -44,29 +44,14 @@ struct LigoData
|
|||
|
||||
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]);
|
||||
}
|
||||
bool operator!= (const LigoData& other) const;
|
||||
};
|
||||
|
||||
class ZoneRegionEditor
|
||||
class ZoneRegionObject
|
||||
{
|
||||
public:
|
||||
ZoneRegionEditor();
|
||||
~ZoneRegionEditor();
|
||||
ZoneRegionObject();
|
||||
~ZoneRegionObject();
|
||||
|
||||
// Load landscape data from file
|
||||
bool load(const std::string &fileName);
|
||||
|
@ -78,6 +63,8 @@ public:
|
|||
|
||||
void setLigoData(const LigoData &data, const sint32 x, const sint32 y);
|
||||
|
||||
std::string fileName() const;
|
||||
|
||||
// Set file name
|
||||
void setFileName(const std::string &fileName);
|
||||
|
||||
|
@ -85,6 +72,8 @@ public:
|
|||
|
||||
void setZoneRegion(const NLLIGO::CZoneRegion &zoneRegion);
|
||||
|
||||
bool checkPos(const sint32 x, const sint32 y);
|
||||
|
||||
private:
|
||||
|
||||
bool m_modified;
|
||||
|
|
Loading…
Reference in a new issue