Changed: #1301 Polished code.

--HG--
branch : gsoc2011-worldeditorqt
This commit is contained in:
dnk-88 2011-10-03 00:40:25 +03:00
parent 4a13d9d848
commit cae892cda2
33 changed files with 109 additions and 348 deletions

View file

@ -75,7 +75,7 @@ PixmapDatabase contains the graphics for the zones
class LANDSCAPE_EDITOR_EXPORT ZoneBuilderBase class LANDSCAPE_EDITOR_EXPORT ZoneBuilderBase
{ {
public: public:
ZoneBuilderBase(LandscapeSceneBase *landscapeScene); explicit ZoneBuilderBase(LandscapeSceneBase *landscapeScene);
virtual ~ZoneBuilderBase(); virtual ~ZoneBuilderBase();
/// Init zoneBank and init zone pixmap database /// Init zoneBank and init zone pixmap database

View file

@ -230,34 +230,18 @@ void BuilderZoneRegion::add(sint32 x, sint32 y, uint8 rot, uint8 flip, NLLIGO::C
} }
// Delete all around all material that are not from the same as us // Delete all around all material that are not from the same as us
const std::string &curMat = zoneBankElement->getCategory ("material"); const std::string &curMat = zoneBankElement->getCategory("material");
if (curMat != STRING_NO_CAT_TYPE) if (curMat != STRING_NO_CAT_TYPE)
{ {
// This element is a valid material // This element is a valid material
// Place the piece // Place the piece
const std::string &eltName = zoneBankElement->getName (); const std::string &eltName = zoneBankElement->getName();
for (j = 0; j < sMask.h; ++j) placePiece(x, y, rot, flip, sMask, sPosX, sPosY, eltName);
for (i = 0; i < sMask.w; ++i)
if (sMask.Tab[i + j * sMask.w])
{
set(x + i, y + j, sPosX.Tab[i + j * sPosX.w], sPosY.Tab[i + j * sPosY.w], eltName);
setRot(x + i, y + j, rot);
setFlip(x + i, y + j, flip);
}
// Put all transitions between different materials // Put all transitions between different materials
putTransitions (x, y, sMask, curMat, &tUpdate); putTransitions (x, y, sMask, curMat, &tUpdate);
placePiece(x, y, rot, flip, sMask, sPosX, sPosY, eltName);
// Place the piece
for (j = 0; j < sMask.h; ++j)
for (i = 0; i < sMask.w; ++i)
if (sMask.Tab[i + j * sMask.w])
{
set(x + i, y + j, sPosX.Tab[i + j * sPosX.w], sPosY.Tab[i + j * sPosY.w], eltName);
setRot(x + i, y + j, rot);
setFlip(x + i, y + j, flip);
}
} }
} }
@ -449,21 +433,14 @@ bool BuilderZoneRegion::addNotPropagate (sint32 x, sint32 y, uint8 rot, uint8 fl
del(x + i, y + j, true, &tUpdate); del(x + i, y + j, true, &tUpdate);
} }
const std::string &curMat = zoneBankElement->getCategory ("material"); const std::string &curMat = zoneBankElement->getCategory("material");
if (curMat != STRING_NO_CAT_TYPE) if (curMat != STRING_NO_CAT_TYPE)
{ {
// This element is a valid material // This element is a valid material
// Place the piece // Place the piece
const std::string &EltName = zoneBankElement->getName (); const std::string &eltName = zoneBankElement->getName();
for (j = 0; j < sMask.h; ++j) placePiece(x, y, rot, flip, sMask, sPosX, sPosY, eltName);
for (i = 0; i < sMask.w; ++i)
if (sMask.Tab[i + j * sMask.w])
{
set (x + i, y + j, sPosX.Tab[i + j * sPosX.w], sPosY.Tab[i + j * sPosY.w], EltName);
setRot (x + i, y + j, rot);
setFlip (x + i, y + j, flip);
}
} }
return true; return true;
@ -803,11 +780,10 @@ void BuilderZoneRegion::addTransition (sint32 x, sint32 y, uint8 rot, uint8 flip
} }
} }
void BuilderZoneRegion::addToUpdateAndCreate(BuilderZoneRegion *builderZoneRegion, sint32 sharePos, sint32 x, sint32 y, const std::string &newMat, void *pInt1, void *pInt2) void BuilderZoneRegion::addToUpdateAndCreate(BuilderZoneRegion *builderZoneRegion, sint32 sharePos, sint32 x, sint32 y,
const std::string &newMat, ToUpdate *ptCreate, ToUpdate *ptUpdate)
{ {
const NLLIGO::CZoneRegion &zoneRegion = m_zoneBuilder->zoneRegion(m_regionId)->ligoZoneRegion(); const NLLIGO::CZoneRegion &zoneRegion = m_zoneBuilder->zoneRegion(m_regionId)->ligoZoneRegion();
ToUpdate *ptCreate = reinterpret_cast<ToUpdate *>(pInt1);
ToUpdate *ptUpdate = reinterpret_cast<ToUpdate *>(pInt2);
sint32 stride = (1 + zoneRegion.getMaxX() - zoneRegion.getMinX()); sint32 stride = (1 + zoneRegion.getMaxX() - zoneRegion.getMinX());
ZonePosition zonePos; ZonePosition zonePos;
@ -828,11 +804,10 @@ void BuilderZoneRegion::addToUpdateAndCreate(BuilderZoneRegion *builderZoneRegio
} }
void BuilderZoneRegion::putTransitions (sint32 inX, sint32 inY, const NLLIGO::SPiece &mask, const std::string &matName, void BuilderZoneRegion::putTransitions (sint32 inX, sint32 inY, const NLLIGO::SPiece &mask, const std::string &matName,
void *pInternal) ToUpdate *ptUpdate)
{ {
const NLLIGO::CZoneRegion &zoneRegion = m_zoneBuilder->zoneRegion(m_regionId)->ligoZoneRegion(); const NLLIGO::CZoneRegion &zoneRegion = m_zoneBuilder->zoneRegion(m_regionId)->ligoZoneRegion();
ToUpdate tCreate; // Transition to create ToUpdate tCreate; // Transition to create
ToUpdate *ptUpdate = reinterpret_cast<ToUpdate *>(pInternal); // Transition to update
sint32 i, j, k, l, m; sint32 i, j, k, l, m;
sint32 x = inX, y = inY; sint32 x = inX, y = inY;
@ -883,10 +858,8 @@ void BuilderZoneRegion::putTransitions (sint32 inX, sint32 inY, const NLLIGO::SP
if ( (corner < 4) && (m != 0) ) if ( (corner < 4) && (m != 0) )
{ {
// The material can't be paused // The material can't be paused
dataZoneTemp.sharingMatNames[0] = STRING_UNUSED; for (int t = 0; i < 4; ++t)
dataZoneTemp.sharingMatNames[1] = STRING_UNUSED; dataZoneTemp.sharingMatNames[t] = STRING_UNUSED;
dataZoneTemp.sharingMatNames[2] = STRING_UNUSED;
dataZoneTemp.sharingMatNames[3] = STRING_UNUSED;
// Don't propagate any more // Don't propagate any more
} }
@ -1659,16 +1632,13 @@ void BuilderZoneRegion::tryPath(uint32 posA, uint32 posB, std::vector<uint32> &p
} }
} }
void BuilderZoneRegion::del(sint32 x, sint32 y, bool transition, void *pInternal) void BuilderZoneRegion::del(sint32 x, sint32 y, bool transition, ToUpdate *pUpdate)
{ {
const NLLIGO::CZoneRegion &zoneRegion = m_zoneBuilder->zoneRegion(m_regionId)->ligoZoneRegion(); const NLLIGO::CZoneRegion &zoneRegion = m_zoneBuilder->zoneRegion(m_regionId)->ligoZoneRegion();
if (!m_zoneBuilder->getZoneMask(x, y)) if (!m_zoneBuilder->getZoneMask(x, y))
return; return;
const std::string &nameZone = zoneRegion.getName(x, y); const std::string &nameZone = zoneRegion.getName(x, y);
ToUpdate *pUpdate = reinterpret_cast<ToUpdate *>(pInternal);
NLLIGO::CZoneBankElement *zoneBankElement = m_zoneBuilder->getZoneBank().getElementByZoneName(nameZone); NLLIGO::CZoneBankElement *zoneBankElement = m_zoneBuilder->getZoneBank().getElementByZoneName(nameZone);
if (zoneBankElement != NULL) if (zoneBankElement != NULL)
{ {
@ -2108,4 +2078,18 @@ void BuilderZoneRegion::resize (sint32 newMinX, sint32 newMaxX, sint32 newMinY,
} }
} }
void BuilderZoneRegion::placePiece(sint32 x, sint32 y, uint8 rot, uint8 flip,
NLLIGO::SPiece &sMask, NLLIGO::SPiece &sPosX, NLLIGO::SPiece &sPosY,
const std::string &eltName)
{
for (int j = 0; j < sMask.h; ++j)
for (int i = 0; i < sMask.w; ++i)
if (sMask.Tab[i + j * sMask.w])
{
set(x + i, y + j, sPosX.Tab[i + j * sPosX.w], sPosY.Tab[i + j * sPosY.w], eltName);
setRot(x + i, y + j, rot);
setFlip(x + i, y + j, flip);
}
}
} /* namespace LandscapeEditor */ } /* namespace LandscapeEditor */

View file

@ -33,13 +33,15 @@
namespace LandscapeEditor namespace LandscapeEditor
{ {
class ZoneBuilder; class ZoneBuilder;
class ToUpdate;
// CZoneRegion contains informations about the zones painted // CZoneRegion contains informations about the zones painted.
// (Legacy class from old world editor. It needs to refactoring!)
class BuilderZoneRegion class BuilderZoneRegion
{ {
public: public:
BuilderZoneRegion(uint regionId); explicit BuilderZoneRegion(uint regionId);
// New interface // New interface
bool init(ZoneBuilder *zoneBuilder); bool init(ZoneBuilder *zoneBuilder);
@ -51,7 +53,7 @@ public:
/// Brutal adding a zone over empty space do not propagate in any way -> can result /// Brutal adding a zone over empty space do not propagate in any way -> can result
/// in inconsistency when trying the propagation mode /// in inconsistency when trying the propagation mode
void addForce (sint32 x, sint32 y, uint8 rot, uint8 flip, NLLIGO::CZoneBankElement *zoneBankElement); 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 del(sint32 x, sint32 y, bool transition = false, ToUpdate *pUpdate = 0);
void move(sint32 x, sint32 y); void move(sint32 x, sint32 y);
uint32 countZones(); uint32 countZones();
void reduceMin(); void reduceMin();
@ -62,28 +64,33 @@ private:
// An element of the graph // An element of the graph
struct SMatNode struct SMatNode
{ {
std::string Name; std::string Name;
// Position in the tree (vector of nodes) // Position in the tree (vector of nodes)
std::vector<uint32> Arcs; std::vector<uint32> Arcs;
}; };
void addTransition(sint32 x, sint32 y, uint8 rot, uint8 flip, NLLIGO::CZoneBankElement *zoneBankElement); 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 addToUpdateAndCreate(BuilderZoneRegion *builderZoneRegion, sint32 sharePos, sint32 x, sint32 y,
const std::string &newMat, ToUpdate *ptCreate, ToUpdate *ptUpdate);
void putTransitions(sint32 x, sint32 y, const NLLIGO::SPiece &mask, const std::string &matName, void *pInternal); void putTransitions(sint32 x, sint32 y, const NLLIGO::SPiece &mask, const std::string &matName, ToUpdate *ptUpdate);
void updateTrans(sint32 x, sint32 y, NLLIGO::CZoneBankElement *zoneBankElement = NULL); void updateTrans(sint32 x, sint32 y, NLLIGO::CZoneBankElement *zoneBankElement = 0);
std::string getNextMatInTree(const std::string &matA, const std::string &matB); std::string getNextMatInTree(const std::string &matA, const std::string &matB);
/// Find the fastest way between posA and posB in the MatTree (Dijkstra) /// Find the fastest way between posA and posB in the MatTree (Dijkstra)
void tryPath(uint32 posA, uint32 posB, std::vector<uint32> &path); 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 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 setRot(sint32 x, sint32 y, uint8 rot);
void setFlip(sint32 x, sint32 y, uint8 flip); void setFlip(sint32 x, sint32 y, uint8 flip);
void resize(sint32 newMinX, sint32 newMaxX, sint32 newMinY, sint32 newMaxY); void resize(sint32 newMinX, sint32 newMaxX, sint32 newMinY, sint32 newMaxY);
void placePiece(sint32 x, sint32 y, uint8 rot, uint8 flip,
NLLIGO::SPiece &sMask, NLLIGO::SPiece &sPosX, NLLIGO::SPiece &sPosY,
const std::string &eltName);
uint m_regionId; uint m_regionId;
// To use the global mask // To use the global mask

View file

@ -27,41 +27,6 @@
namespace LandscapeEditor namespace LandscapeEditor
{ {
OpenLandscapeCommand::OpenLandscapeCommand(const QString &fileName, QUndoCommand *parent)
: QUndoCommand(parent),
m_fileName(fileName)
{
}
OpenLandscapeCommand::~OpenLandscapeCommand()
{
}
void OpenLandscapeCommand::undo()
{
}
void OpenLandscapeCommand::redo()
{
}
NewLandscapeCommand::NewLandscapeCommand(QUndoCommand *parent)
: QUndoCommand(parent)
{
}
NewLandscapeCommand::~NewLandscapeCommand()
{
}
void NewLandscapeCommand::undo()
{
}
void NewLandscapeCommand::redo()
{
}
LigoTileCommand::LigoTileCommand(const LigoData &data, const ZonePosition &zonePos, LigoTileCommand::LigoTileCommand(const LigoData &data, const ZonePosition &zonePos,
ZoneBuilder *zoneBuilder, LandscapeScene *scene, ZoneBuilder *zoneBuilder, LandscapeScene *scene,
QUndoCommand *parent) QUndoCommand *parent)

View file

@ -32,40 +32,6 @@
namespace LandscapeEditor namespace LandscapeEditor
{ {
/**
@class OpenLandscapeCommand
@brief
@details
*/
class OpenLandscapeCommand: public QUndoCommand
{
public:
OpenLandscapeCommand(const QString &fileName, QUndoCommand *parent = 0);
virtual ~OpenLandscapeCommand();
virtual void undo();
virtual void redo();
private:
QString m_fileName;
};
/**
@class NewLandscapeCommand
@brief
@details
*/
class NewLandscapeCommand: public QUndoCommand
{
public:
NewLandscapeCommand(QUndoCommand *parent = 0);
virtual ~NewLandscapeCommand();
virtual void undo();
virtual void redo();
private:
};
/** /**
@class LigoTileCommand @class LigoTileCommand
@brief @brief

View file

@ -34,11 +34,6 @@ namespace NLMISC
class CLibraryContext; class CLibraryContext;
} }
namespace ExtensionSystem
{
class IPluginSpec;
}
namespace LandscapeEditor namespace LandscapeEditor
{ {
class LandscapeEditorWindow; class LandscapeEditorWindow;
@ -70,7 +65,7 @@ class LandscapeEditorContext: public Core::IContext
{ {
Q_OBJECT Q_OBJECT
public: public:
LandscapeEditorContext(QObject *parent = 0); explicit LandscapeEditorContext(QObject *parent = 0);
virtual ~LandscapeEditorContext() {} virtual ~LandscapeEditorContext() {}
virtual QString id() const virtual QString id() const

View file

@ -262,7 +262,7 @@ int LandscapeEditorWindow::createLandscape(const QString &fileName)
if (id == -1) if (id == -1)
{ {
QMessageBox::critical(this, "Landscape Editor", "Cannot add this zone because it overlaps existing ones"); QMessageBox::critical(this, "Landscape Editor", tr("Cannot add this zone because it overlaps existing ones"));
return -1; return -1;
} }
ZoneRegionObject *zoneRegion = m_zoneBuilder->zoneRegion(id); ZoneRegionObject *zoneRegion = m_zoneBuilder->zoneRegion(id);

View file

@ -37,7 +37,7 @@ class LandscapeEditorWindow: public QMainWindow
Q_OBJECT Q_OBJECT
public: public:
LandscapeEditorWindow(QWidget *parent = 0); explicit LandscapeEditorWindow(QWidget *parent = 0);
~LandscapeEditorWindow(); ~LandscapeEditorWindow();
QUndoStack *undoStack() const; QUndoStack *undoStack() const;

View file

@ -397,26 +397,6 @@ void LandscapeScene::drawForeground(QPainter *painter, const QRectF &rect)
QGraphicsScene::drawForeground(painter, rect); QGraphicsScene::drawForeground(painter, rect);
if ((m_zoneBuilder->currentIdZoneRegion() != -1) && (m_transitionMode)) if ((m_zoneBuilder->currentIdZoneRegion() != -1) && (m_transitionMode))
drawTransition(painter, rect); drawTransition(painter, rect);
/*
// Render debug text (slow!)
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));
}
}
*/
} }
void LandscapeScene::drawTransition(QPainter *painter, const QRectF &rect) void LandscapeScene::drawTransition(QPainter *painter, const QRectF &rect)

View file

@ -185,23 +185,14 @@ void LandscapeView::setCenter(const QPointF &centerPoint)
//We need to clamp the center. The centerPoint is too large //We need to clamp the center. The centerPoint is too large
if (centerPoint.x() > bounds.x() + bounds.width()) if (centerPoint.x() > bounds.x() + bounds.width())
{
m_currentCenterPoint.setX(bounds.x() + bounds.width()); m_currentCenterPoint.setX(bounds.x() + bounds.width());
}
else if(centerPoint.x() < bounds.x()) else if(centerPoint.x() < bounds.x())
{
m_currentCenterPoint.setX(bounds.x()); m_currentCenterPoint.setX(bounds.x());
}
if(centerPoint.y() > bounds.y() + bounds.height()) if(centerPoint.y() > bounds.y() + bounds.height())
{
m_currentCenterPoint.setY(bounds.y() + bounds.height()); m_currentCenterPoint.setY(bounds.y() + bounds.height());
}
else if(centerPoint.y() < bounds.y()) else if(centerPoint.y() < bounds.y())
{
m_currentCenterPoint.setY(bounds.y()); m_currentCenterPoint.setY(bounds.y());
}
} }
} }
@ -230,7 +221,6 @@ void LandscapeView::drawForeground(QPainter *painter, const QRectF &rect)
if (transform().m11() > m_maxViewText) if (transform().m11() > m_maxViewText)
{ {
painter->setPen(QPen(Qt::white, 0.5, Qt::SolidLine)); painter->setPen(QPen(Qt::white, 0.5, Qt::SolidLine));
//painter->setFont(QFont("Helvetica [Cronyx]", 12));
drawZoneNames(painter, rect); drawZoneNames(painter, rect);
} }
} }

View file

@ -37,7 +37,7 @@ class LANDSCAPE_EDITOR_EXPORT LandscapeView: public QGraphicsView
Q_OBJECT Q_OBJECT
public: public:
LandscapeView(QWidget *parent = 0); explicit LandscapeView(QWidget *parent = 0);
virtual ~LandscapeView(); virtual ~LandscapeView();
//Set the current centerpoint in the //Set the current centerpoint in the

View file

@ -39,7 +39,7 @@ class ListZonesWidget: public QWidget
Q_OBJECT Q_OBJECT
public: public:
ListZonesWidget(QWidget *parent = 0); explicit ListZonesWidget(QWidget *parent = 0);
~ListZonesWidget(); ~ListZonesWidget();
void updateUi(); void updateUi();

View file

@ -64,7 +64,7 @@ bool PixmapDatabase::loadPixmaps(const QString &zonePath, NLLIGO::CZoneBank &zon
zoneBank.getCategoryValues ("zone", listNames); zoneBank.getCategoryValues ("zone", listNames);
if (displayProgress) if (displayProgress)
{ {
progressDialog = new QProgressDialog("Loading ligo zones.", "Cancel", 0, listNames.size()); progressDialog = new QProgressDialog(QObject::tr("Loading ligo zones."), QObject::tr("Cancel"), 0, listNames.size());
progressDialog->show(); progressDialog->show();
} }

View file

@ -39,7 +39,7 @@ namespace LandscapeEditor
class LANDSCAPE_EDITOR_EXPORT PixmapDatabase class LANDSCAPE_EDITOR_EXPORT PixmapDatabase
{ {
public: public:
PixmapDatabase(int textureSize = 256); explicit PixmapDatabase(int textureSize = 256);
~PixmapDatabase(); ~PixmapDatabase();
/// Load all images(png) from zonePath, list images gets from zoneBank /// Load all images(png) from zonePath, list images gets from zoneBank

View file

@ -30,7 +30,7 @@ class SnapshotDialog: public QDialog
Q_OBJECT Q_OBJECT
public: public:
SnapshotDialog(QWidget *parent = 0); explicit SnapshotDialog(QWidget *parent = 0);
~SnapshotDialog(); ~SnapshotDialog();
bool isCustomSize() const; bool isCustomSize() const;

View file

@ -118,12 +118,6 @@ void ZoneRegionObject::setFileName(const std::string &fileName)
void ZoneRegionObject::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()));
*/
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);
@ -141,12 +135,6 @@ void ZoneRegionObject::ligoData(LigoData &data, const sint32 x, const sint32 y)
void ZoneRegionObject::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()));
*/
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);

View file

@ -215,20 +215,18 @@ PrimitiveNode::PrimitiveNode(NLLIGO::IPrimitive *primitive)
m_primitive->getPropertyByName("class", className); m_primitive->getPropertyByName("class", className);
// Set Icon // Set Icon
QString nameIcon = QString("./old_ico/%1.ico").arg(className.c_str()); QString nameIcon = QString("%1/%2.ico").arg(Constants::PATH_TO_OLD_ICONS).arg(className.c_str());
QIcon icon(nameIcon); QIcon icon(nameIcon);
if (!QFile::exists(nameIcon)) if (!QFile::exists(nameIcon))
{ {
if (primitive->getParent() == NULL) if (primitive->getParent() == NULL)
icon = QIcon("./old_ico/root.ico"); icon = QIcon(Constants::ICON_ROOT_PRIMITIVE);
else if (primitive->getNumChildren() == 0) else if (primitive->getNumChildren() == 0)
icon = QIcon("./old_ico/property.ico"); icon = QIcon(Constants::ICON_PROPERTY);
else else
icon = QIcon("./old_ico/folder_h.ico"); icon = QIcon(Constants::ICON_FOLDER);
} }
setData(Qt::DecorationRole, icon); setData(Qt::DecorationRole, icon);
//setData(3, QString(className.c_str()));
} }
PrimitiveNode::~PrimitiveNode() PrimitiveNode::~PrimitiveNode()
@ -242,7 +240,7 @@ NLLIGO::IPrimitive *PrimitiveNode::primitive() const
const NLLIGO::CPrimitiveClass *PrimitiveNode::primitiveClass() const const NLLIGO::CPrimitiveClass *PrimitiveNode::primitiveClass() const
{ {
return NLLIGO::CPrimitiveContext::instance().CurrentLigoConfig->getPrimitiveClass(*m_primitive); return Utils::ligoConfig()->getPrimitiveClass(*m_primitive);
} }
RootPrimitiveNode *PrimitiveNode::rootPrimitiveNode() RootPrimitiveNode *PrimitiveNode::rootPrimitiveNode()
@ -250,7 +248,7 @@ RootPrimitiveNode *PrimitiveNode::rootPrimitiveNode()
Node *node = this; Node *node = this;
while (node && (node->type() != Node::RootPrimitiveNodeType)) while (node && (node->type() != Node::RootPrimitiveNodeType))
node = node->parent(); node = node->parent();
return (RootPrimitiveNode *)node; return static_cast<RootPrimitiveNode *>(node);
} }
Node::NodeType PrimitiveNode::type() const Node::NodeType PrimitiveNode::type() const

View file

@ -30,10 +30,7 @@
namespace WorldEditor namespace WorldEditor
{ {
class WorldEditNode;
class RootPrimitiveNode; class RootPrimitiveNode;
class LandscapeNode;
class PrimitiveNode;
/* /*
@class Node @class Node
@ -150,7 +147,7 @@ private:
class PrimitiveNode: public Node class PrimitiveNode: public Node
{ {
public: public:
PrimitiveNode(NLLIGO::IPrimitive *primitive); explicit PrimitiveNode(NLLIGO::IPrimitive *primitive);
virtual ~PrimitiveNode(); virtual ~PrimitiveNode();
NLLIGO::IPrimitive *primitive() const; NLLIGO::IPrimitive *primitive() const;

View file

@ -183,6 +183,10 @@ Node *PrimitivesTreeModel::pathToNode(const Path &path)
void PrimitivesTreeModel::createWorldEditNode(const QString &fileName) void PrimitivesTreeModel::createWorldEditNode(const QString &fileName)
{ {
// World edit node already is created, if yes is showing error message box
if (m_worldEditNode != 0)
nlerror("World edit node already is created.");
beginResetModel(); beginResetModel();
m_worldEditNode = new WorldEditNode(fileName); m_worldEditNode = new WorldEditNode(fileName);
m_rootNode->appendChildNode(m_worldEditNode); m_rootNode->appendChildNode(m_worldEditNode);

View file

@ -39,7 +39,8 @@ const int AtTheEnd = -1;
typedef QPair<int, int> PathItem; typedef QPair<int, int> PathItem;
/* /*
@typedef Path @typedef Path
@brief It store a list of row and column numbers which have to walk through from the root index of the model to reach the need item @brief It store a list of row and column numbers which have to walk through from the root index of the model to reach the need item.
It is used for undo/redo commands.
*/ */
typedef QList<PathItem> Path; typedef QList<PathItem> Path;
@ -53,7 +54,7 @@ class PrimitivesTreeModel : public QAbstractItemModel
Q_OBJECT Q_OBJECT
public: public:
PrimitivesTreeModel(QObject *parent = 0); explicit PrimitivesTreeModel(QObject *parent = 0);
~PrimitivesTreeModel(); ~PrimitivesTreeModel();
QVariant data(const QModelIndex &index, int role) const; QVariant data(const QModelIndex &index, int role) const;
@ -92,7 +93,6 @@ public:
private: private:
void createChildNodes(NLLIGO::IPrimitive *primitive, int pos, const QModelIndex &parent); void createChildNodes(NLLIGO::IPrimitive *primitive, int pos, const QModelIndex &parent);
void removeChildNodes(Node *node, const QModelIndex &parent); void removeChildNodes(Node *node, const QModelIndex &parent);
Node *m_rootNode; Node *m_rootNode;

View file

@ -61,7 +61,7 @@ PrimitivesView::PrimitivesView(QWidget *parent)
m_loadLandAction->setIcon(QIcon(LandscapeEditor::Constants::ICON_ZONE_ITEM)); m_loadLandAction->setIcon(QIcon(LandscapeEditor::Constants::ICON_ZONE_ITEM));
m_loadPrimitiveAction = new QAction("Load primitive file", this); m_loadPrimitiveAction = new QAction("Load primitive file", this);
m_loadPrimitiveAction->setIcon(QIcon("./old_ico/root.ico")); m_loadPrimitiveAction->setIcon(QIcon(Constants::ICON_ROOT_PRIMITIVE));
m_newPrimitiveAction = new QAction("New primitive", this); m_newPrimitiveAction = new QAction("New primitive", this);
@ -132,7 +132,7 @@ void PrimitivesView::loadRootPrimitive()
if (!fileNames.isEmpty()) if (!fileNames.isEmpty())
{ {
if (fileNames.count() > 1) if (fileNames.count() > 1)
m_undoStack->beginMacro("Load primitive files"); m_undoStack->beginMacro(tr("Load primitive files"));
Q_FOREACH(QString fileName, fileNames) Q_FOREACH(QString fileName, fileNames)
{ {
@ -160,7 +160,7 @@ void PrimitivesView::loadLandscape()
if (!fileNames.isEmpty()) if (!fileNames.isEmpty())
{ {
if (fileNames.count() > 1) if (fileNames.count() > 1)
m_undoStack->beginMacro("Load land files"); m_undoStack->beginMacro(tr("Load land files"));
Q_FOREACH(QString fileName, fileNames) Q_FOREACH(QString fileName, fileNames)
{ {
@ -206,7 +206,7 @@ void PrimitivesView::save()
if (node->data(Constants::PRIMITIVE_FILE_IS_CREATED).toBool()) if (node->data(Constants::PRIMITIVE_FILE_IS_CREATED).toBool())
{ {
if (!NLLIGO::saveXmlPrimitiveFile(*node->primitives(), node->fileName().toStdString())) if (!NLLIGO::saveXmlPrimitiveFile(*node->primitives(), node->fileName().toStdString()))
QMessageBox::warning(this, "World Editor Qt", QString("Error writing output file: %1").arg(node->fileName())); QMessageBox::warning(this, "World Editor Qt", tr("Error writing output file: %1").arg(node->fileName()));
else else
node->setData(Constants::PRIMITIVE_IS_MODIFIED, false); node->setData(Constants::PRIMITIVE_IS_MODIFIED, false);
} }
@ -231,7 +231,7 @@ void PrimitivesView::saveAs()
RootPrimitiveNode *node = static_cast<RootPrimitiveNode *>(index.internalPointer()); RootPrimitiveNode *node = static_cast<RootPrimitiveNode *>(index.internalPointer());
if (!NLLIGO::saveXmlPrimitiveFile(*node->primitives(), fileName.toStdString())) if (!NLLIGO::saveXmlPrimitiveFile(*node->primitives(), fileName.toStdString()))
QMessageBox::warning(this, "World Editor Qt", QString("Error writing output file: %1").arg(fileName)); QMessageBox::warning(this, "World Editor Qt", tr("Error writing output file: %1").arg(fileName));
else else
{ {
node->setFileName(fileName); node->setFileName(fileName);
@ -407,7 +407,7 @@ void PrimitivesView::fillMenu_Primitive(QMenu *menu, const QModelIndex &index)
QSignalMapper *addSignalMapper = new QSignalMapper(menu); QSignalMapper *addSignalMapper = new QSignalMapper(menu);
QSignalMapper *generateSignalMapper = new QSignalMapper(menu); QSignalMapper *generateSignalMapper = new QSignalMapper(menu);
QSignalMapper *openSignalMapper = new QSignalMapper(menu); //QSignalMapper *openSignalMapper = new QSignalMapper(menu);
connect(addSignalMapper, SIGNAL(mapped(int)), this, SLOT(addNewPrimitiveByClass(int))); connect(addSignalMapper, SIGNAL(mapped(int)), this, SLOT(addNewPrimitiveByClass(int)));
connect(generateSignalMapper, SIGNAL(mapped(int)), this, SLOT(generatePrimitives(int))); connect(generateSignalMapper, SIGNAL(mapped(int)), this, SLOT(generatePrimitives(int)));
//connect(openSignalMapper, SIGNAL(mapped(int)), this, SLOT(openItem(int))); //connect(openSignalMapper, SIGNAL(mapped(int)), this, SLOT(openItem(int)));
@ -427,10 +427,10 @@ void PrimitivesView::fillMenu_Primitive(QMenu *menu, const QModelIndex &index)
QString className = primClass->DynamicChildren[i].ClassName.c_str(); QString className = primClass->DynamicChildren[i].ClassName.c_str();
// Get icon // Get icon
QIcon icon(QString("./old_ico/%1.ico").arg(className)); QIcon icon(QString("%1/%2.ico").arg(Constants::PATH_TO_OLD_ICONS).arg(className));
// Create and add action in popur menu // Create and add action in popur menu
QAction *action = menu->addAction(icon, QString("Add %1").arg(className)); QAction *action = menu->addAction(icon, tr("Add %1").arg(className));
addSignalMapper->setMapping(action, i); addSignalMapper->setMapping(action, i);
connect(action, SIGNAL(triggered()), addSignalMapper, SLOT(map())); connect(action, SIGNAL(triggered()), addSignalMapper, SLOT(map()));
} }
@ -448,35 +448,11 @@ void PrimitivesView::fillMenu_Primitive(QMenu *menu, const QModelIndex &index)
QString childName = primClass->GeneratedChildren[i].ClassName.c_str(); QString childName = primClass->GeneratedChildren[i].ClassName.c_str();
// Create and add action in popur menu // Create and add action in popur menu
QAction *action = menu->addAction(QString("Generate %1").arg(childName)); QAction *action = menu->addAction(tr("Generate %1").arg(childName));
generateSignalMapper->setMapping(action, i); generateSignalMapper->setMapping(action, i);
connect(generateSignalMapper, SIGNAL(triggered()), addSignalMapper, SLOT(map())); connect(action, SIGNAL(triggered()), generateSignalMapper, SLOT(map()));
} }
} }
/*
// What class is it ?
if (primClass)
{
// Look for files
std::vector<std::string> filenames;
// Filenames
buildFilenameVector (*Selection.front (), filenames);
// File names ?
if (!filenames.empty ())
{
// Add separator
popurMenu->addSeparator();
// Found ?
for (uint i = 0; i < filenames.size(); i++)
{
// Add a menu entry
pMenu->AppendMenu (MF_STRING, ID_EDIT_OPEN_FILE_BEGIN+i, ("Open "+NLMISC::CFile::getFilename (filenames[i])).c_str ());
}
}
*/
} }
} /* namespace WorldEditor */ } /* namespace WorldEditor */

View file

@ -53,7 +53,7 @@ class PrimitivesView : public QTreeView
Q_OBJECT Q_OBJECT
public: public:
PrimitivesView(QWidget *parent = 0); explicit PrimitivesView(QWidget *parent = 0);
~PrimitivesView(); ~PrimitivesView();
void setUndoStack(QUndoStack *undoStack); void setUndoStack(QUndoStack *undoStack);

View file

@ -45,7 +45,7 @@ class PropertyEditorWidget: public QWidget
Q_OBJECT Q_OBJECT
public: public:
PropertyEditorWidget(QWidget *parent = 0); explicit PropertyEditorWidget(QWidget *parent = 0);
~PropertyEditorWidget(); ~PropertyEditorWidget();
public Q_SLOTS: public Q_SLOTS:

View file

@ -103,13 +103,11 @@ void addNewGraphicsItems(const QModelIndex &primIndex, PrimitivesTreeModel *mode
QPolygonF polygon; QPolygonF polygon;
vec = primitive->getPrimVector(); vec = primitive->getPrimVector();
int sizeVec = primitive->getNumVector(); int sizeVec = primitive->getNumVector();
for (int i = 0; i < sizeVec; ++i) for (int i = 0; i < sizeVec; ++i)
{ {
polygon << QPointF(vec->x, -vec->y + cellSize); polygon << QPointF(vec->x, -vec->y + cellSize);
++vec; ++vec;
} }
item = scene->addWorldItemPath(polygon, showArrow); item = scene->addWorldItemPath(polygon, showArrow);
break; break;
} }
@ -118,7 +116,6 @@ void addNewGraphicsItems(const QModelIndex &primIndex, PrimitivesTreeModel *mode
QPolygonF polygon; QPolygonF polygon;
vec = primitive->getPrimVector(); vec = primitive->getPrimVector();
int sizeVec = primitive->getNumVector(); int sizeVec = primitive->getNumVector();
for (int i = 0; i < sizeVec; ++i) for (int i = 0; i < sizeVec; ++i)
{ {
polygon << QPointF(vec->x, cellSize - vec->y); polygon << QPointF(vec->x, cellSize - vec->y);
@ -133,30 +130,7 @@ void addNewGraphicsItems(const QModelIndex &primIndex, PrimitivesTreeModel *mode
{ {
// Get color from world_editor_classes.xml // Get color from world_editor_classes.xml
NLMISC::CRGBA color = Utils::ligoConfig()->getPrimitiveColor(*primitive); NLMISC::CRGBA color = Utils::ligoConfig()->getPrimitiveColor(*primitive);
/*
// Configurations (from world_editor_primitive_configuration.xml)
const std::vector<NLLIGO::CPrimitiveConfigurations> &configurations = Utils::ligoConfig()->getPrimitiveConfiguration();
// Look for the configuration
sint search = 0;
bool colorFound = false;
while ((search = theApp.getActiveConfiguration (*primitive, search)) != -1)
{
// Configuration activated ?
if (theApp.Configurations[search].Activated)
{
colorFound = true;
mainColor = configurations[search].Color;
break;
}
search++;
}
// try to get the primitive color ?
//if (!colorFound)*/
primitive->getPropertyByName ("Color", color); primitive->getPropertyByName ("Color", color);
item->setColor(QColor(color.R, color.G, color.B)); item->setColor(QColor(color.R, color.G, color.B));
QVariant variantNode; QVariant variantNode;

View file

@ -44,7 +44,10 @@ const char *const PRIMITIVE_CLASS_FILENAME = "WorldEditorPrimitiveClassFilename"
//resources //resources
const char *const ICON_WORLD_EDITOR = ":/icons/ic_nel_world_editor.png"; const char *const ICON_WORLD_EDITOR = ":/icons/ic_nel_world_editor.png";
const char *const ICON_ROOT_PRIMITIVE = "./old_ico/root.ico";
const char *const ICON_PROPERTY = "./old_ico/property.ico";
const char *const ICON_FOLDER = "./old_ico/folder_h.ico";
const char *const PATH_TO_OLD_ICONS = "./old_ico";
} // namespace Constants } // namespace Constants
} // namespace WorldEditor } // namespace WorldEditor

View file

@ -1,6 +1,5 @@
// Object Viewer Qt - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/> // Object Viewer Qt - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited // 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 // This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as // it under the terms of the GNU Affero General Public License as
@ -99,7 +98,6 @@ bool loadWorldEditFile(const std::string &fileName, WorldEditList &worldEditList
// Good header ? // Good header ?
if (strcmp((const char *)(rootNode->name), "NEL_WORLD_EDITOR_PROJECT") == 0) if (strcmp((const char *)(rootNode->name), "NEL_WORLD_EDITOR_PROJECT") == 0)
{ {
// Read the version
int version = -1; int version = -1;
// Read the parameters // Read the parameters
@ -112,10 +110,7 @@ bool loadWorldEditFile(const std::string &fileName, WorldEditList &worldEditList
} }
if (version == -1) if (version == -1)
{
// Error
syntaxError(fileName.c_str(), rootNode, "No version node"); syntaxError(fileName.c_str(), rootNode, "No version node");
}
else else
{ {
// Old format, // Old format,
@ -213,9 +208,7 @@ bool loadWorldEditFile(const std::string &fileName, WorldEditList &worldEditList
} }
} }
else else
{
nlerror("Can't open the file %s for reading.", fileName.c_str()); nlerror("Can't open the file %s for reading.", fileName.c_str());
}
return result; return result;
} }
@ -255,12 +248,10 @@ void initPrimitiveParameters(const NLLIGO::CPrimitiveClass &primClass, NLLIGO::I
if (cp < primClass.Parameters.size()) if (cp < primClass.Parameters.size())
type = primClass.Parameters[cp].Type; type = primClass.Parameters[cp].Type;
// Name ?
if (initParameters[p].Name == "name") if (initParameters[p].Name == "name")
type = NLLIGO::CPrimitiveClass::CParameter::String; type = NLLIGO::CPrimitiveClass::CParameter::String;
// Continue ? if (cp < primClass.Parameters.size () || (initParameters[p].Name == "name"))
if (cp<primClass.Parameters.size () || (initParameters[p].Name == "name"))
{ {
// Default value ? // Default value ?
if (!parameter.DefaultValue.empty()) if (!parameter.DefaultValue.empty())
@ -294,16 +285,12 @@ void initPrimitiveParameters(const NLLIGO::CPrimitiveClass &primClass, NLLIGO::I
{ {
bool Visible = false; bool Visible = false;
if (cp < primClass.Parameters.size() && !primClass.Parameters[cp].Visible) if (cp < primClass.Parameters.size() && !primClass.Parameters[cp].Visible)
{
Visible = true; Visible = true;
}
for (size_t i = 0; i < parameter.DefaultValue.size(); ++i) for (size_t i = 0; i < parameter.DefaultValue.size(); ++i)
{ {
// Generate a unique id ? // Generate a unique id ?
if (parameter.DefaultValue[i].GenID) if (parameter.DefaultValue[i].GenID)
{
Visible = true; Visible = true;
}
} }
if (Visible) if (Visible)
{ {
@ -317,13 +304,9 @@ void initPrimitiveParameters(const NLLIGO::CPrimitiveClass &primClass, NLLIGO::I
{ {
// Generate a unique id ? // Generate a unique id ?
if (parameter.DefaultValue[i].GenID) if (parameter.DefaultValue[i].GenID)
{
str->StringArray[i] = NLMISC::toString(getUniqueId()); str->StringArray[i] = NLMISC::toString(getUniqueId());
}
else else
{
str->StringArray[i] = ""; str->StringArray[i] = "";
}
} }
primitive.addPropertyByName(parameter.Name.c_str(), str); primitive.addPropertyByName(parameter.Name.c_str(), str);
} }
@ -347,7 +330,7 @@ NLLIGO::IPrimitive *createPrimitive(const char *className, const char *primName,
NLLIGO::IPrimitive *parent) NLLIGO::IPrimitive *parent)
{ {
// Get the prim class // Get the prim class
const NLLIGO::CPrimitiveClass *primClass = NLLIGO::CPrimitiveContext::instance().CurrentLigoConfig->getPrimitiveClass(className); const NLLIGO::CPrimitiveClass *primClass = ligoConfig()->getPrimitiveClass(className);
if (primClass) if (primClass)
{ {
// Create the base primitive // Create the base primitive
@ -438,41 +421,18 @@ NLLIGO::IPrimitive *createPrimitive(const char *className, const char *primName,
return NULL; return NULL;
} }
// Prim file ?
if (primClass->Type == NLLIGO::CPrimitiveClass::Bitmap)
{
// Create a dialog file
//CFileDialogEx dialog (BASE_REGISTRY_KEY, "image", TRUE, primClass->FileExtension.c_str (), NULL, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
// (primClass->FileType+" (*."+primClass->FileExtension+")|*."+primClass->FileExtension+"|All Files (*.*)|*.*||").c_str (), getMainFrame ());
//if (dialog.DoModal() == IDOK)
//{
// Save filename
// static_cast<CPrimBitmap*>(primitive)->init(dialog.GetPathName ());
//}
}
// Continue ?
if (primitive) if (primitive)
{ {
// Auto init ?
if (!primClass->AutoInit) if (!primClass->AutoInit)
{ {
// Make a vector of locator // TODO
//CDatabaseLocatorPointer locatorPtr;
//getLocator (locatorPtr, locator);
std::list<NLLIGO::IPrimitive *> locators;
//locators.push_back (const_cast<IPrimitive*> (locatorPtr.Primitive));
// Yes, go
//CDialogProperties dialogProperty (locators, getMainFrame ());
//dialogProperty.DoModal ();
} }
// Eval the default name property // Eval the default name property
std::string name; std::string name;
if (!primitive->getPropertyByName ("name", name) || name.empty()) if (!primitive->getPropertyByName ("name", name) || name.empty())
{ {
const NLLIGO::CPrimitiveClass *primClass = NLLIGO::CPrimitiveContext::instance().CurrentLigoConfig->getPrimitiveClass(*primitive); const NLLIGO::CPrimitiveClass *primClass = ligoConfig()->getPrimitiveClass(*primitive);
if (primClass) if (primClass)
{ {
for (size_t i = 0; i < primClass->Parameters.size(); ++i) for (size_t i = 0; i < primClass->Parameters.size(); ++i)
@ -491,17 +451,13 @@ NLLIGO::IPrimitive *createPrimitive(const char *className, const char *primName,
} }
} }
// Init primitive default values primitive->initDefaultValues(*ligoConfig());
primitive->initDefaultValues(*NLLIGO::CPrimitiveContext::instance().CurrentLigoConfig);
} }
// Done
return primitive; return primitive;
} }
else else
{
nlerror("Unknown primitive class name : %s", className); nlerror("Unknown primitive class name : %s", className);
}
return 0; return 0;
} }
@ -521,11 +477,10 @@ void deletePrimitive(NLLIGO::IPrimitive *primitive)
bool updateDefaultValues(NLLIGO::IPrimitive *primitive) bool updateDefaultValues(NLLIGO::IPrimitive *primitive)
{ {
// Modified
bool modified = false; bool modified = false;
// Get the prim class // Get the prim class
const NLLIGO::CPrimitiveClass *primClass = NLLIGO::CPrimitiveContext::instance().CurrentLigoConfig->getPrimitiveClass(*primitive); const NLLIGO::CPrimitiveClass *primClass = ligoConfig()->getPrimitiveClass(*primitive);
nlassert(primClass); nlassert(primClass);
if (primClass) if (primClass)

View file

@ -1,6 +1,5 @@
// Object Viewer Qt - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/> // Object Viewer Qt - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited // 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 // This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as // it under the terms of the GNU Affero General Public License as

View file

@ -36,11 +36,6 @@ namespace NLMISC
class CLibraryContext; class CLibraryContext;
} }
namespace ExtensionSystem
{
class IPluginSpec;
}
namespace WorldEditor namespace WorldEditor
{ {
class WorldEditorWindow; class WorldEditorWindow;

View file

@ -45,17 +45,15 @@ WorldEditorScene::WorldEditorScene(int sizeCell, PrimitivesTreeModel *model, QUn
// TODO: get params from settings // TODO: get params from settings
setSceneRect(QRectF(-20 * 160, -20 * 160, 256 * 160, 256 * 160)); setSceneRect(QRectF(-20 * 160, -20 * 160, 256 * 160, 256 * 160));
m_pen1.setColor(QColor(50, 255, 155)); m_greenPen.setColor(QColor(50, 255, 155));
m_pen1.setWidth(0); m_greenPen.setWidth(0);
m_greenBrush.setColor(QColor(50, 255, 155, 80));
m_greenBrush.setStyle(Qt::SolidPattern);
m_brush1.setColor(QColor(50, 255, 155, 80)); m_purplePen.setColor(QColor(100, 0, 255));
m_brush1.setStyle(Qt::SolidPattern); m_purplePen.setWidth(0);
m_purpleBrush.setColor(QColor(100, 0, 255, 80));
m_pen2.setColor(QColor(100, 0, 255)); m_purpleBrush.setStyle(Qt::SolidPattern);
m_pen2.setWidth(0);
m_brush2.setColor(QColor(100, 0, 255, 80));
m_brush2.setStyle(Qt::SolidPattern);
} }
WorldEditorScene::~WorldEditorScene() WorldEditorScene::~WorldEditorScene()
@ -67,8 +65,6 @@ AbstractWorldItem *WorldEditorScene::addWorldItemPoint(const QPointF &point, con
{ {
WorldItemPoint *item = new WorldItemPoint(point, angle, radius, showArrow); WorldItemPoint *item = new WorldItemPoint(point, angle, radius, showArrow);
addItem(item); addItem(item);
m_worldItems.push_back(item);
return item; return item;
} }
@ -76,8 +72,6 @@ AbstractWorldItem *WorldEditorScene::addWorldItemPath(const QPolygonF &polyline,
{ {
WorldItemPath *item = new WorldItemPath(polyline); WorldItemPath *item = new WorldItemPath(polyline);
addItem(item); addItem(item);
m_worldItems.push_back(item);
return item; return item;
} }
@ -85,8 +79,6 @@ AbstractWorldItem *WorldEditorScene::addWorldItemZone(const QPolygonF &polygon)
{ {
WorldItemZone *item = new WorldItemZone(polygon); WorldItemZone *item = new WorldItemZone(polygon);
addItem(item); addItem(item);
m_worldItems.push_back(item);
return item; return item;
} }
@ -96,10 +88,6 @@ void WorldEditorScene::removeWorldItem(QGraphicsItem *item)
m_selectedItems.clear(); m_selectedItems.clear();
m_editedSelectedItems = false; m_editedSelectedItems = false;
m_firstSelection = false; m_firstSelection = false;
// TODO
AbstractWorldItem *worldItem = qgraphicsitem_cast<AbstractWorldItem *>(item);
m_worldItems.removeOne(worldItem);
delete item; delete item;
} }
@ -174,18 +162,18 @@ void WorldEditorScene::drawForeground(QPainter *painter, const QRectF &rect)
if ((m_selectionArea.left() != 0) && (m_selectionArea.right() != 0)) if ((m_selectionArea.left() != 0) && (m_selectionArea.right() != 0))
{ {
// Draw selection area
if (m_selectionArea.left() < m_selectionArea.right()) if (m_selectionArea.left() < m_selectionArea.right())
{ {
painter->setPen(m_pen1); painter->setPen(m_greenPen);
painter->setBrush(m_brush1); painter->setBrush(m_greenBrush);
} }
else else
{ {
painter->setPen(m_pen2); painter->setPen(m_purplePen);
painter->setBrush(m_brush2); painter->setBrush(m_purpleBrush);
} }
painter->drawRect(m_selectionArea); painter->drawRect(m_selectionArea);
} }
} }

View file

@ -110,15 +110,14 @@ private:
void checkUndo(); void checkUndo();
QPen m_pen1, m_pen2; QPen m_greenPen, m_purplePen;
QBrush m_brush1, m_brush2; QBrush m_greenBrush, m_purpleBrush;
QPointF m_firstPick, m_scaleFactor, m_pivot; QPointF m_firstPick, m_scaleFactor, m_pivot;
QRectF m_selectionArea; QRectF m_selectionArea;
qreal m_firstPickX, m_firstPickY, m_angle; qreal m_firstPickX, m_firstPickY, m_angle;
QList<QGraphicsItem *> m_selectedItems; QList<QGraphicsItem *> m_selectedItems;
QList<QGraphicsItem *> m_selectedPoints; QList<QGraphicsItem *> m_selectedPoints;
QList<AbstractWorldItem *> m_worldItems;
QList<QPolygonF> m_polygons; QList<QPolygonF> m_polygons;
bool m_editedSelectedItems, m_firstSelection; bool m_editedSelectedItems, m_firstSelection;
uint m_lastPickedPrimitive; uint m_lastPickedPrimitive;

View file

@ -36,7 +36,7 @@ class WorldEditorSettingsPage : public Core::IOptionsPage
{ {
Q_OBJECT Q_OBJECT
public: public:
WorldEditorSettingsPage(QObject *parent = 0); explicit WorldEditorSettingsPage(QObject *parent = 0);
virtual ~WorldEditorSettingsPage() {} virtual ~WorldEditorSettingsPage() {}
virtual QString id() const; virtual QString id() const;

View file

@ -63,7 +63,6 @@ WorldEditorWindow::WorldEditorWindow(QWidget *parent)
m_ui.graphicsView->setVisibleText(false); m_ui.graphicsView->setVisibleText(false);
m_ui.treePrimitivesView->setModel(m_primitivesModel); m_ui.treePrimitivesView->setModel(m_primitivesModel);
// TODO: ?
m_ui.treePrimitivesView->setUndoStack(m_undoStack); m_ui.treePrimitivesView->setUndoStack(m_undoStack);
m_ui.treePrimitivesView->setZoneBuilder(m_zoneBuilderBase); m_ui.treePrimitivesView->setZoneBuilder(m_zoneBuilderBase);
m_ui.treePrimitivesView->setWorldScene(m_worldEditorScene); m_ui.treePrimitivesView->setWorldScene(m_worldEditorScene);
@ -131,7 +130,7 @@ QUndoStack *WorldEditorWindow::undoStack() const
void WorldEditorWindow::maybeSave() void WorldEditorWindow::maybeSave()
{ {
QMessageBox *messageBox = new QMessageBox(tr("SDI"), QMessageBox *messageBox = new QMessageBox(tr("World Editor"),
tr("The data has been modified.\n" tr("The data has been modified.\n"
"Do you want to save your changes?"), "Do you want to save your changes?"),
QMessageBox::Warning, QMessageBox::Warning,
@ -143,7 +142,7 @@ void WorldEditorWindow::maybeSave()
messageBox->setButtonText(QMessageBox::Yes, messageBox->setButtonText(QMessageBox::Yes,
tr("Save")); tr("Save"));
messageBox->setButtonText(QMessageBox::No, tr("Dont Save")); messageBox->setButtonText(QMessageBox::No, tr("Don't Save"));
messageBox->show(); messageBox->show();
} }
@ -175,7 +174,7 @@ void WorldEditorWindow::loadWorldEditFile(const QString &fileName)
return; return;
} }
m_undoStack->beginMacro(QString("Load %1").arg(fileName)); m_undoStack->beginMacro(tr("Load %1").arg(fileName));
checkCurrentWorld(); checkCurrentWorld();
@ -208,7 +207,6 @@ void WorldEditorWindow::checkCurrentWorld()
void WorldEditorWindow::newWorldEditFile() void WorldEditorWindow::newWorldEditFile()
{ {
checkCurrentWorld(); checkCurrentWorld();
m_undoStack->push(new CreateWorldCommand("NewWorldEdit", m_primitivesModel)); m_undoStack->push(new CreateWorldCommand("NewWorldEdit", m_primitivesModel));
} }
@ -347,7 +345,7 @@ void WorldEditorWindow::hideEvent(QHideEvent *hideEvent)
void WorldEditorWindow::createMenus() void WorldEditorWindow::createMenus()
{ {
Core::MenuManager *menuManager = Core::ICore::instance()->menuManager(); //Core::MenuManager *menuManager = Core::ICore::instance()->menuManager();
} }
void WorldEditorWindow::createToolBars() void WorldEditorWindow::createToolBars()

View file

@ -42,7 +42,7 @@ class WorldEditorWindow: public QMainWindow
Q_OBJECT Q_OBJECT
public: public:
WorldEditorWindow(QWidget *parent = 0); explicit WorldEditorWindow(QWidget *parent = 0);
~WorldEditorWindow(); ~WorldEditorWindow();
QUndoStack *undoStack() const; QUndoStack *undoStack() const;