mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-16 19:19:56 +00:00
handle primary and secondary edit button clicks on cell arrows
This commit is contained in:
parent
361634489e
commit
e34af4c4b5
6 changed files with 177 additions and 12 deletions
|
@ -154,3 +154,8 @@ CSMWorld::CellCoordinates CSVRender::CellArrow::getCoordinates() const
|
||||||
{
|
{
|
||||||
return mCoordinates;
|
return mCoordinates;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CSVRender::CellArrow::Direction CSVRender::CellArrow::getDirection() const
|
||||||
|
{
|
||||||
|
return mDirection;
|
||||||
|
}
|
||||||
|
|
|
@ -64,6 +64,8 @@ namespace CSVRender
|
||||||
~CellArrow();
|
~CellArrow();
|
||||||
|
|
||||||
CSMWorld::CellCoordinates getCoordinates() const;
|
CSMWorld::CellCoordinates getCoordinates() const;
|
||||||
|
|
||||||
|
Direction getDirection() const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
|
#include <QApplication>
|
||||||
|
|
||||||
#include <osgGA/TrackballManipulator>
|
#include <osgGA/TrackballManipulator>
|
||||||
|
|
||||||
|
@ -81,10 +82,7 @@ bool CSVRender::PagedWorldspaceWidget::adjustCells()
|
||||||
{
|
{
|
||||||
if (mCells.find (*iter)==mCells.end())
|
if (mCells.find (*iter)==mCells.end())
|
||||||
{
|
{
|
||||||
Cell *cell = new Cell (mDocument.getData(), mRootNode,
|
addCellToScene (*iter);
|
||||||
iter->getId (mWorldspace));
|
|
||||||
mCells.insert (std::make_pair (*iter, cell));
|
|
||||||
|
|
||||||
modified = true;
|
modified = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -152,6 +150,76 @@ void CSVRender::PagedWorldspaceWidget::addEditModeSelectorButtons (
|
||||||
"terrain-move");
|
"terrain-move");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSVRender::PagedWorldspaceWidget::handleMouseClick (osg::ref_ptr<TagBase> tag, const std::string& button)
|
||||||
|
{
|
||||||
|
if (tag && tag->getElement()==Element_CellArrow)
|
||||||
|
{
|
||||||
|
if (button=="p-edit" || button=="s-edit")
|
||||||
|
{
|
||||||
|
if (CellArrowTag *cellArrowTag =
|
||||||
|
dynamic_cast<CSVRender::CellArrowTag *> (tag.get()))
|
||||||
|
{
|
||||||
|
CellArrow *arrow = cellArrowTag->getCellArrow();
|
||||||
|
|
||||||
|
CSMWorld::CellCoordinates coordinates = arrow->getCoordinates();
|
||||||
|
|
||||||
|
CellArrow::Direction direction = arrow->getDirection();
|
||||||
|
|
||||||
|
int x = 0;
|
||||||
|
int y = 0;
|
||||||
|
|
||||||
|
switch (direction)
|
||||||
|
{
|
||||||
|
case CellArrow::Direction_North: y = 1; break;
|
||||||
|
case CellArrow::Direction_West: x = -1; break;
|
||||||
|
case CellArrow::Direction_South: y = -1; break;
|
||||||
|
case CellArrow::Direction_East: x = 1; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool modified = false;
|
||||||
|
|
||||||
|
if (QApplication::keyboardModifiers() & Qt::ShiftModifier)
|
||||||
|
{
|
||||||
|
if (button=="p-edit")
|
||||||
|
addCellSelection (x, y);
|
||||||
|
else
|
||||||
|
moveCellSelection (x, y);
|
||||||
|
|
||||||
|
modified = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CSMWorld::CellCoordinates newCoordinates = coordinates.move (x, y);
|
||||||
|
|
||||||
|
if (mCells.find (newCoordinates)==mCells.end())
|
||||||
|
{
|
||||||
|
addCellToScene (newCoordinates);
|
||||||
|
mSelection.add (newCoordinates);
|
||||||
|
modified = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (button=="s-edit")
|
||||||
|
{
|
||||||
|
if (mCells.find (coordinates)!=mCells.end())
|
||||||
|
{
|
||||||
|
removeCellFromScene (coordinates);
|
||||||
|
mSelection.remove (coordinates);
|
||||||
|
modified = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (modified)
|
||||||
|
adjustCells();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
WorldspaceWidget::handleMouseClick (tag, button);
|
||||||
|
}
|
||||||
|
|
||||||
void CSVRender::PagedWorldspaceWidget::referenceableDataChanged (const QModelIndex& topLeft,
|
void CSVRender::PagedWorldspaceWidget::referenceableDataChanged (const QModelIndex& topLeft,
|
||||||
const QModelIndex& bottomRight)
|
const QModelIndex& bottomRight)
|
||||||
{
|
{
|
||||||
|
@ -231,6 +299,72 @@ std::string CSVRender::PagedWorldspaceWidget::getStartupInstruction()
|
||||||
return stream.str();
|
return stream.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSVRender::PagedWorldspaceWidget::addCellToScene (
|
||||||
|
const CSMWorld::CellCoordinates& coordinates)
|
||||||
|
{
|
||||||
|
const CSMWorld::IdCollection<CSMWorld::Cell>& cells = mDocument.getData().getCells();
|
||||||
|
|
||||||
|
int index = cells.searchId (coordinates.getId (mWorldspace));
|
||||||
|
|
||||||
|
bool deleted = index==-1 ||
|
||||||
|
cells.getRecord (index).mState==CSMWorld::RecordBase::State_Deleted;
|
||||||
|
|
||||||
|
Cell *cell = new Cell (mDocument.getData(), mRootNode, coordinates.getId (mWorldspace),
|
||||||
|
deleted);
|
||||||
|
|
||||||
|
mCells.insert (std::make_pair (coordinates, cell));
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVRender::PagedWorldspaceWidget::removeCellFromScene (
|
||||||
|
const CSMWorld::CellCoordinates& coordinates)
|
||||||
|
{
|
||||||
|
std::map<CSMWorld::CellCoordinates, Cell *>::iterator iter = mCells.find (coordinates);
|
||||||
|
|
||||||
|
if (iter!=mCells.end())
|
||||||
|
{
|
||||||
|
delete iter->second;
|
||||||
|
mCells.erase (iter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVRender::PagedWorldspaceWidget::addCellSelection (int x, int y)
|
||||||
|
{
|
||||||
|
CSMWorld::CellSelection newSelection = mSelection;
|
||||||
|
newSelection.move (x, y);
|
||||||
|
|
||||||
|
for (CSMWorld::CellSelection::Iterator iter (newSelection.begin()); iter!=newSelection.end();
|
||||||
|
++iter)
|
||||||
|
{
|
||||||
|
if (mCells.find (*iter)==mCells.end())
|
||||||
|
{
|
||||||
|
addCellToScene (*iter);
|
||||||
|
mSelection.add (*iter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVRender::PagedWorldspaceWidget::moveCellSelection (int x, int y)
|
||||||
|
{
|
||||||
|
CSMWorld::CellSelection newSelection = mSelection;
|
||||||
|
newSelection.move (x, y);
|
||||||
|
|
||||||
|
for (CSMWorld::CellSelection::Iterator iter (mSelection.begin()); iter!=mSelection.end();
|
||||||
|
++iter)
|
||||||
|
{
|
||||||
|
if (!newSelection.has (*iter))
|
||||||
|
removeCellFromScene (*iter);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (CSMWorld::CellSelection::Iterator iter (newSelection.begin()); iter!=newSelection.end();
|
||||||
|
++iter)
|
||||||
|
{
|
||||||
|
if (!mSelection.has (*iter))
|
||||||
|
addCellToScene (*iter);
|
||||||
|
}
|
||||||
|
|
||||||
|
mSelection = newSelection;
|
||||||
|
}
|
||||||
|
|
||||||
CSVRender::PagedWorldspaceWidget::PagedWorldspaceWidget (QWidget* parent, CSMDoc::Document& document)
|
CSVRender::PagedWorldspaceWidget::PagedWorldspaceWidget (QWidget* parent, CSMDoc::Document& document)
|
||||||
: WorldspaceWidget (document, parent), mDocument (document), mWorldspace ("std::default"),
|
: WorldspaceWidget (document, parent), mDocument (document), mWorldspace ("std::default"),
|
||||||
mControlElements(NULL), mDisplayCellCoord(true)
|
mControlElements(NULL), mDisplayCellCoord(true)
|
||||||
|
|
|
@ -53,6 +53,20 @@ namespace CSVRender
|
||||||
|
|
||||||
virtual std::string getStartupInstruction();
|
virtual std::string getStartupInstruction();
|
||||||
|
|
||||||
|
/// \note Does not update the view or any cell marker
|
||||||
|
void addCellToScene (const CSMWorld::CellCoordinates& coordinates);
|
||||||
|
|
||||||
|
/// \note Does not update the view or any cell marker
|
||||||
|
///
|
||||||
|
/// \note Calling this function for a cell that is not in the selection is a no-op.
|
||||||
|
void removeCellFromScene (const CSMWorld::CellCoordinates& coordinates);
|
||||||
|
|
||||||
|
/// \note Does not update the view or any cell marker
|
||||||
|
void addCellSelection (int x, int y);
|
||||||
|
|
||||||
|
/// \note Does not update the view or any cell marker
|
||||||
|
void moveCellSelection (int x, int y);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
PagedWorldspaceWidget (QWidget *parent, CSMDoc::Document& document);
|
PagedWorldspaceWidget (QWidget *parent, CSMDoc::Document& document);
|
||||||
|
@ -88,6 +102,8 @@ namespace CSVRender
|
||||||
|
|
||||||
virtual void addEditModeSelectorButtons (CSVWidget::SceneToolMode *tool);
|
virtual void addEditModeSelectorButtons (CSVWidget::SceneToolMode *tool);
|
||||||
|
|
||||||
|
virtual void handleMouseClick (osg::ref_ptr<TagBase> tag, const std::string& button);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
void cellSelectionChanged (const CSMWorld::CellSelection& selection);
|
void cellSelectionChanged (const CSMWorld::CellSelection& selection);
|
||||||
|
|
|
@ -574,14 +574,7 @@ void CSVRender::WorldspaceWidget::mousePressEvent (QMouseEvent *event)
|
||||||
{
|
{
|
||||||
osg::ref_ptr<TagBase> tag = mousePick (event);
|
osg::ref_ptr<TagBase> tag = mousePick (event);
|
||||||
|
|
||||||
EditMode& editMode = dynamic_cast<CSVRender::EditMode&> (*mEditMode->getCurrent());
|
handleMouseClick (tag, button);
|
||||||
|
|
||||||
if (button=="p-edit")
|
|
||||||
editMode.primaryEditPressed (tag);
|
|
||||||
else if (button=="s-edit")
|
|
||||||
editMode.secondaryEditPressed (tag);
|
|
||||||
else if (button=="select")
|
|
||||||
editMode.selectPressed (tag);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -650,3 +643,15 @@ void CSVRender::WorldspaceWidget::keyPressEvent (QKeyEvent *event)
|
||||||
else
|
else
|
||||||
RenderWidget::keyPressEvent(event);
|
RenderWidget::keyPressEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSVRender::WorldspaceWidget::handleMouseClick (osg::ref_ptr<TagBase> tag, const std::string& button)
|
||||||
|
{
|
||||||
|
EditMode& editMode = dynamic_cast<CSVRender::EditMode&> (*mEditMode->getCurrent());
|
||||||
|
|
||||||
|
if (button=="p-edit")
|
||||||
|
editMode.primaryEditPressed (tag);
|
||||||
|
else if (button=="s-edit")
|
||||||
|
editMode.secondaryEditPressed (tag);
|
||||||
|
else if (button=="select")
|
||||||
|
editMode.selectPressed (tag);
|
||||||
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ namespace CSVWidget
|
||||||
namespace CSVRender
|
namespace CSVRender
|
||||||
{
|
{
|
||||||
class TagBase;
|
class TagBase;
|
||||||
|
class CellArrow;
|
||||||
|
|
||||||
class WorldspaceWidget : public SceneWidget
|
class WorldspaceWidget : public SceneWidget
|
||||||
{
|
{
|
||||||
|
@ -132,6 +133,8 @@ namespace CSVRender
|
||||||
virtual void wheelEvent (QWheelEvent *event);
|
virtual void wheelEvent (QWheelEvent *event);
|
||||||
virtual void keyPressEvent (QKeyEvent *event);
|
virtual void keyPressEvent (QKeyEvent *event);
|
||||||
|
|
||||||
|
virtual void handleMouseClick (osg::ref_ptr<TagBase> tag, const std::string& button);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void dragEnterEvent(QDragEnterEvent *event);
|
void dragEnterEvent(QDragEnterEvent *event);
|
||||||
|
|
Loading…
Reference in a new issue