mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-26 09:35:28 +00:00
added cell rendering in paged worldspaces
This commit is contained in:
parent
a6626b94c8
commit
2fe2def64c
@ -3,14 +3,137 @@
|
|||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
#include <OgreCamera.h>
|
||||||
|
|
||||||
#include <QtGui/qevent.h>
|
#include <QtGui/qevent.h>
|
||||||
|
|
||||||
#include <apps/opencs/model/world/tablemimedata.hpp>
|
#include "../../model/world/tablemimedata.hpp"
|
||||||
|
#include "../../model/world/idtable.hpp"
|
||||||
|
|
||||||
|
bool CSVRender::PagedWorldspaceWidget::adjustCells()
|
||||||
|
{
|
||||||
|
bool modified = false;
|
||||||
|
bool setCamera = false;
|
||||||
|
|
||||||
|
{
|
||||||
|
// remove
|
||||||
|
std::map<CSMWorld::CellCoordinates, Cell *>::iterator iter (mCells.begin());
|
||||||
|
|
||||||
|
while (iter!=mCells.end())
|
||||||
|
{
|
||||||
|
if (!mSelection.has (iter->first))
|
||||||
|
{
|
||||||
|
delete iter->second;
|
||||||
|
mCells.erase (iter++);
|
||||||
|
modified = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
++iter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mCells.begin()==mCells.end())
|
||||||
|
setCamera = true;
|
||||||
|
|
||||||
|
// add
|
||||||
|
for (CSMWorld::CellSelection::Iterator iter (mSelection.begin()); iter!=mSelection.end();
|
||||||
|
++iter)
|
||||||
|
{
|
||||||
|
if (mCells.find (*iter)==mCells.end())
|
||||||
|
{
|
||||||
|
if (setCamera)
|
||||||
|
{
|
||||||
|
setCamera = false;
|
||||||
|
getCamera()->setPosition (8192*iter->getX()+4096, 8192*iter->getY()+4096, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
mCells.insert (std::make_pair (*iter,
|
||||||
|
new Cell (mDocument.getData(), getSceneManager(),
|
||||||
|
iter->getId ("std::default"))));
|
||||||
|
|
||||||
|
modified = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return modified;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVRender::PagedWorldspaceWidget::referenceableDataChanged (const QModelIndex& topLeft,
|
||||||
|
const QModelIndex& bottomRight)
|
||||||
|
{
|
||||||
|
for (std::map<CSMWorld::CellCoordinates, Cell *>::iterator iter (mCells.begin());
|
||||||
|
iter!=mCells.end(); ++iter)
|
||||||
|
if (iter->second->referenceableDataChanged (topLeft, bottomRight))
|
||||||
|
flagAsModified();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVRender::PagedWorldspaceWidget::referenceableAboutToBeRemoved (
|
||||||
|
const QModelIndex& parent, int start, int end)
|
||||||
|
{
|
||||||
|
for (std::map<CSMWorld::CellCoordinates, Cell *>::iterator iter (mCells.begin());
|
||||||
|
iter!=mCells.end(); ++iter)
|
||||||
|
if (iter->second->referenceableAboutToBeRemoved (parent, start, end))
|
||||||
|
flagAsModified();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVRender::PagedWorldspaceWidget::referenceableAdded (const QModelIndex& parent,
|
||||||
|
int start, int end)
|
||||||
|
{
|
||||||
|
CSMWorld::IdTable& referenceables = dynamic_cast<CSMWorld::IdTable&> (
|
||||||
|
*mDocument.getData().getTableModel (CSMWorld::UniversalId::Type_Referenceables));
|
||||||
|
|
||||||
|
for (std::map<CSMWorld::CellCoordinates, Cell *>::iterator iter (mCells.begin());
|
||||||
|
iter!=mCells.end(); ++iter)
|
||||||
|
{
|
||||||
|
QModelIndex topLeft = referenceables.index (start, 0);
|
||||||
|
QModelIndex bottomRight =
|
||||||
|
referenceables.index (end, referenceables.columnCount());
|
||||||
|
|
||||||
|
if (iter->second->referenceableDataChanged (topLeft, bottomRight))
|
||||||
|
flagAsModified();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVRender::PagedWorldspaceWidget::referenceDataChanged (const QModelIndex& topLeft,
|
||||||
|
const QModelIndex& bottomRight)
|
||||||
|
{
|
||||||
|
for (std::map<CSMWorld::CellCoordinates, Cell *>::iterator iter (mCells.begin());
|
||||||
|
iter!=mCells.end(); ++iter)
|
||||||
|
if (iter->second->referenceDataChanged (topLeft, bottomRight))
|
||||||
|
flagAsModified();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVRender::PagedWorldspaceWidget::referenceAboutToBeRemoved (const QModelIndex& parent,
|
||||||
|
int start, int end)
|
||||||
|
{
|
||||||
|
for (std::map<CSMWorld::CellCoordinates, Cell *>::iterator iter (mCells.begin());
|
||||||
|
iter!=mCells.end(); ++iter)
|
||||||
|
if (iter->second->referenceAboutToBeRemoved (parent, start, end))
|
||||||
|
flagAsModified();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVRender::PagedWorldspaceWidget::referenceAdded (const QModelIndex& parent, int start,
|
||||||
|
int end)
|
||||||
|
{
|
||||||
|
for (std::map<CSMWorld::CellCoordinates, Cell *>::iterator iter (mCells.begin());
|
||||||
|
iter!=mCells.end(); ++iter)
|
||||||
|
if (iter->second->referenceAdded (parent, start, end))
|
||||||
|
flagAsModified();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CSVRender::PagedWorldspaceWidget::PagedWorldspaceWidget (QWidget* parent, CSMDoc::Document& document)
|
CSVRender::PagedWorldspaceWidget::PagedWorldspaceWidget (QWidget* parent, CSMDoc::Document& document)
|
||||||
: WorldspaceWidget (document, parent)
|
: WorldspaceWidget (document, parent), mDocument (document)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
CSVRender::PagedWorldspaceWidget::~PagedWorldspaceWidget()
|
||||||
|
{
|
||||||
|
for (std::map<CSMWorld::CellCoordinates, Cell *>::iterator iter (mCells.begin());
|
||||||
|
iter!=mCells.end(); ++iter)
|
||||||
|
delete iter->second;
|
||||||
|
}
|
||||||
|
|
||||||
void CSVRender::PagedWorldspaceWidget::useViewHint (const std::string& hint)
|
void CSVRender::PagedWorldspaceWidget::useViewHint (const std::string& hint)
|
||||||
{
|
{
|
||||||
if (!hint.empty())
|
if (!hint.empty())
|
||||||
@ -47,6 +170,10 @@ void CSVRender::PagedWorldspaceWidget::useViewHint (const std::string& hint)
|
|||||||
void CSVRender::PagedWorldspaceWidget::setCellSelection (const CSMWorld::CellSelection& selection)
|
void CSVRender::PagedWorldspaceWidget::setCellSelection (const CSMWorld::CellSelection& selection)
|
||||||
{
|
{
|
||||||
mSelection = selection;
|
mSelection = selection;
|
||||||
|
|
||||||
|
if (adjustCells())
|
||||||
|
flagAsModified();
|
||||||
|
|
||||||
emit cellSelectionChanged (mSelection);
|
emit cellSelectionChanged (mSelection);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,6 +199,9 @@ void CSVRender::PagedWorldspaceWidget::handleDrop (const std::vector< CSMWorld::
|
|||||||
}
|
}
|
||||||
if (selectionChanged)
|
if (selectionChanged)
|
||||||
{
|
{
|
||||||
|
if (adjustCells())
|
||||||
|
flagAsModified();
|
||||||
|
|
||||||
emit cellSelectionChanged(mSelection);
|
emit cellSelectionChanged(mSelection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
#ifndef OPENCS_VIEW_PAGEDWORLDSPACEWIDGET_H
|
#ifndef OPENCS_VIEW_PAGEDWORLDSPACEWIDGET_H
|
||||||
#define OPENCS_VIEW_PAGEDWORLDSPACEWIDGET_H
|
#define OPENCS_VIEW_PAGEDWORLDSPACEWIDGET_H
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
|
||||||
#include "../../model/world/cellselection.hpp"
|
#include "../../model/world/cellselection.hpp"
|
||||||
|
|
||||||
#include "worldspacewidget.hpp"
|
#include "worldspacewidget.hpp"
|
||||||
|
#include "cell.hpp"
|
||||||
|
|
||||||
namespace CSVRender
|
namespace CSVRender
|
||||||
{
|
{
|
||||||
@ -11,12 +14,32 @@ namespace CSVRender
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
CSMDoc::Document& mDocument;
|
||||||
CSMWorld::CellSelection mSelection;
|
CSMWorld::CellSelection mSelection;
|
||||||
|
std::map<CSMWorld::CellCoordinates, Cell *> mCells;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::pair<int, int> getCoordinatesFromId(const std::string& record) const;
|
std::pair<int, int> getCoordinatesFromId(const std::string& record) const;
|
||||||
|
|
||||||
|
/// Bring mCells into sync with mSelection again.
|
||||||
|
///
|
||||||
|
/// \return Any cells added or removed?
|
||||||
|
bool adjustCells();
|
||||||
|
|
||||||
|
virtual void referenceableDataChanged (const QModelIndex& topLeft,
|
||||||
|
const QModelIndex& bottomRight);
|
||||||
|
|
||||||
|
virtual void referenceableAboutToBeRemoved (const QModelIndex& parent, int start, int end);
|
||||||
|
|
||||||
|
virtual void referenceableAdded (const QModelIndex& index, int start, int end);
|
||||||
|
|
||||||
|
virtual void referenceDataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight);
|
||||||
|
|
||||||
|
virtual void referenceAboutToBeRemoved (const QModelIndex& parent, int start, int end);
|
||||||
|
|
||||||
|
virtual void referenceAdded (const QModelIndex& index, int start, int end);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
PagedWorldspaceWidget (QWidget *parent, CSMDoc::Document& document);
|
PagedWorldspaceWidget (QWidget *parent, CSMDoc::Document& document);
|
||||||
@ -24,6 +47,8 @@ namespace CSVRender
|
|||||||
/// no cells are displayed. The cells to be displayed will be specified later through
|
/// no cells are displayed. The cells to be displayed will be specified later through
|
||||||
/// hint system.
|
/// hint system.
|
||||||
|
|
||||||
|
virtual ~PagedWorldspaceWidget();
|
||||||
|
|
||||||
void useViewHint (const std::string& hint);
|
void useViewHint (const std::string& hint);
|
||||||
|
|
||||||
void setCellSelection (const CSMWorld::CellSelection& selection);
|
void setCellSelection (const CSMWorld::CellSelection& selection);
|
||||||
|
@ -43,7 +43,7 @@ namespace CSVRender
|
|||||||
mCamera->setPosition (300, 0, 0);
|
mCamera->setPosition (300, 0, 0);
|
||||||
mCamera->lookAt (0, 0, 0);
|
mCamera->lookAt (0, 0, 0);
|
||||||
mCamera->setNearClipDistance (0.1);
|
mCamera->setNearClipDistance (0.1);
|
||||||
mCamera->setFarClipDistance (30000);
|
mCamera->setFarClipDistance (300000); ///< \todo make this configurable
|
||||||
mCamera->roll (Ogre::Degree (90));
|
mCamera->roll (Ogre::Degree (90));
|
||||||
|
|
||||||
setLighting (&mLightingDay);
|
setLighting (&mLightingDay);
|
||||||
@ -137,6 +137,11 @@ namespace CSVRender
|
|||||||
return mSceneMgr;
|
return mSceneMgr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ogre::Camera *SceneWidget::getCamera()
|
||||||
|
{
|
||||||
|
return mCamera;
|
||||||
|
}
|
||||||
|
|
||||||
void SceneWidget::flagAsModified()
|
void SceneWidget::flagAsModified()
|
||||||
{
|
{
|
||||||
mUpdate = true;
|
mUpdate = true;
|
||||||
|
@ -49,6 +49,8 @@ namespace CSVRender
|
|||||||
|
|
||||||
Ogre::SceneManager *getSceneManager();
|
Ogre::SceneManager *getSceneManager();
|
||||||
|
|
||||||
|
Ogre::Camera *getCamera();
|
||||||
|
|
||||||
void flagAsModified();
|
void flagAsModified();
|
||||||
|
|
||||||
void setDefaultAmbient (const Ogre::ColourValue& colour);
|
void setDefaultAmbient (const Ogre::ColourValue& colour);
|
||||||
|
@ -80,17 +80,17 @@ namespace CSVRender
|
|||||||
void selectNavigationMode (const std::string& mode);
|
void selectNavigationMode (const std::string& mode);
|
||||||
|
|
||||||
virtual void referenceableDataChanged (const QModelIndex& topLeft,
|
virtual void referenceableDataChanged (const QModelIndex& topLeft,
|
||||||
const QModelIndex& bottomRight) {}
|
const QModelIndex& bottomRight) = 0;
|
||||||
|
|
||||||
virtual void referenceableAboutToBeRemoved (const QModelIndex& parent, int start, int end) {}
|
virtual void referenceableAboutToBeRemoved (const QModelIndex& parent, int start, int end) = 0;
|
||||||
|
|
||||||
virtual void referenceableAdded (const QModelIndex& index, int start, int end) {}
|
virtual void referenceableAdded (const QModelIndex& index, int start, int end) = 0;
|
||||||
|
|
||||||
virtual void referenceDataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight) {}
|
virtual void referenceDataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight) = 0;
|
||||||
|
|
||||||
virtual void referenceAboutToBeRemoved (const QModelIndex& parent, int start, int end) {}
|
virtual void referenceAboutToBeRemoved (const QModelIndex& parent, int start, int end) = 0;
|
||||||
|
|
||||||
virtual void referenceAdded (const QModelIndex& index, int start, int end) {}
|
virtual void referenceAdded (const QModelIndex& index, int start, int end) = 0;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user