mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-05 03:45:35 +00:00
Handle change of names or regions to dynamically update the overlay.
This commit is contained in:
parent
7836ee9ab6
commit
e1197e75bc
4 changed files with 60 additions and 19 deletions
|
@ -32,7 +32,7 @@ bool CSVRender::PagedWorldspaceWidget::adjustCells()
|
|||
const CSMWorld::IdCollection<CSMWorld::Cell>& cells = mDocument.getData().getCells();
|
||||
|
||||
{
|
||||
// remove
|
||||
// remove (or name/region modified)
|
||||
std::map<CSMWorld::CellCoordinates, Cell *>::iterator iter (mCells.begin());
|
||||
|
||||
while (iter!=mCells.end())
|
||||
|
@ -43,21 +43,61 @@ bool CSVRender::PagedWorldspaceWidget::adjustCells()
|
|||
cells.getRecord (index).mState==CSMWorld::RecordBase::State_Deleted)
|
||||
{
|
||||
delete iter->second;
|
||||
mCells.erase (iter++);
|
||||
mCells.erase (iter);
|
||||
|
||||
// delete overlays
|
||||
std::map<CSMWorld::CellCoordinates, TextOverlay *>::iterator itOverlay = mTextOverlays.find(iter->first);
|
||||
if(itOverlay != mTextOverlays.end())
|
||||
{
|
||||
delete itOverlay->second;
|
||||
mTextOverlays.erase(itOverlay);
|
||||
}
|
||||
|
||||
// destroy manual objects and entities
|
||||
std::map<std::string, Ogre::Entity *>::iterator it = mEntities.find(iter->first.getId(mWorldspace));
|
||||
if(it != mEntities.end())
|
||||
std::map<CSMWorld::CellCoordinates, Ogre::Entity *>::iterator itEntity = mEntities.find(iter->first);
|
||||
if(itEntity != mEntities.end())
|
||||
{
|
||||
getSceneManager()->destroyEntity(it->second);
|
||||
mEntities.erase(it);
|
||||
getSceneManager()->destroyEntity(itEntity->second);
|
||||
mEntities.erase(itEntity);
|
||||
}
|
||||
getSceneManager()->destroyManualObject("manual"+iter->first.getId(mWorldspace));
|
||||
|
||||
iter++;
|
||||
modified = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// check if name or region field has changed
|
||||
std::string name = cells.getRecord(index).get().mName;
|
||||
std::string region = cells.getRecord(index).get().mRegion;
|
||||
|
||||
std::map<CSMWorld::CellCoordinates, TextOverlay *>::iterator it = mTextOverlays.find(iter->first);
|
||||
if(it != mTextOverlays.end())
|
||||
{
|
||||
if(it->second->getDesc() != "") // previously had name
|
||||
{
|
||||
if(name != it->second->getDesc()) // new name
|
||||
{
|
||||
if(name != "")
|
||||
it->second->setDesc(name);
|
||||
else // name deleted, use region
|
||||
it->second->setDesc(region);
|
||||
it->second->update();
|
||||
}
|
||||
}
|
||||
else if(name != "") // name added
|
||||
{
|
||||
it->second->setDesc(name);
|
||||
it->second->update();
|
||||
}
|
||||
else if(region != it->second->getDesc()) // new region
|
||||
{
|
||||
it->second->setDesc(region);
|
||||
it->second->update();
|
||||
}
|
||||
}
|
||||
++iter;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -100,7 +140,7 @@ bool CSVRender::PagedWorldspaceWidget::adjustCells()
|
|||
entity->setVisible(false);
|
||||
|
||||
// keep pointers so that they can be deleted later
|
||||
mEntities.insert(std::make_pair(iter->getId(mWorldspace), entity));
|
||||
mEntities.insert(std::make_pair(*iter, entity));
|
||||
|
||||
CSVRender::TextOverlay *textDisp = new CSVRender::TextOverlay(entity, getCamera(), iter->getId(mWorldspace));
|
||||
textDisp->enable(true);
|
||||
|
@ -109,7 +149,7 @@ bool CSVRender::PagedWorldspaceWidget::adjustCells()
|
|||
if(desc == "") desc = cells.getRecord(index).get().mRegion;
|
||||
textDisp->setDesc(desc);
|
||||
textDisp->update();
|
||||
mTextOverlays.push_back(textDisp);
|
||||
mTextOverlays.insert(std::make_pair(*iter, textDisp));
|
||||
|
||||
modified = true;
|
||||
}
|
||||
|
@ -122,13 +162,14 @@ void CSVRender::PagedWorldspaceWidget::mouseReleaseEvent (QMouseEvent *event)
|
|||
{
|
||||
if(event->button() == Qt::RightButton)
|
||||
{
|
||||
std::list<TextOverlay *>::iterator iter = mTextOverlays.begin();
|
||||
std::map<CSMWorld::CellCoordinates, TextOverlay *>::iterator iter = mTextOverlays.begin();
|
||||
for(; iter != mTextOverlays.end(); ++iter)
|
||||
{
|
||||
if(mDisplayCellCoord &&
|
||||
(*iter)->isEnabled() && (*iter)->container().contains(event->x(), event->y()))
|
||||
iter->second->isEnabled() && iter->second->container().contains(event->x(), event->y()))
|
||||
{
|
||||
std::cout << "clicked: " << (*iter)->getCaption() << std::endl;
|
||||
std::cout << "clicked: " << iter->second->getCaption() << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -172,10 +213,10 @@ void CSVRender::PagedWorldspaceWidget::updateOverlay()
|
|||
|
||||
if(!mTextOverlays.empty())
|
||||
{
|
||||
std::list<CSVRender::TextOverlay *>::iterator it = mTextOverlays.begin();
|
||||
std::map<CSMWorld::CellCoordinates, TextOverlay *>::iterator it = mTextOverlays.begin();
|
||||
for(; it != mTextOverlays.end(); ++it)
|
||||
{
|
||||
(*it)->update();
|
||||
it->second->update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -259,7 +300,6 @@ std::string CSVRender::PagedWorldspaceWidget::getStartupInstruction()
|
|||
|
||||
CSVRender::PagedWorldspaceWidget::PagedWorldspaceWidget (QWidget* parent, CSMDoc::Document& document)
|
||||
: WorldspaceWidget(document, parent), mDocument(document), mWorldspace("std::default"), mDisplayCellCoord(true)
|
||||
, mTextOverlays(0)
|
||||
{
|
||||
QAbstractItemModel *cells =
|
||||
document.getData().getTableModel (CSMWorld::UniversalId::Type_Cells);
|
||||
|
@ -279,7 +319,7 @@ CSVRender::PagedWorldspaceWidget::~PagedWorldspaceWidget()
|
|||
{
|
||||
delete iter->second;
|
||||
|
||||
std::map<std::string, Ogre::Entity *>::iterator it = mEntities.find(iter->first.getId(mWorldspace));
|
||||
std::map<CSMWorld::CellCoordinates, Ogre::Entity *>::iterator it = mEntities.find(iter->first);
|
||||
if(it != mEntities.end())
|
||||
{
|
||||
getSceneManager()->destroyEntity(it->second);
|
||||
|
|
|
@ -23,8 +23,8 @@ namespace CSVRender
|
|||
std::string mWorldspace;
|
||||
CSVWidget::SceneToolToggle *mControlElements;
|
||||
bool mDisplayCellCoord;
|
||||
std::list<TextOverlay *> mTextOverlays;
|
||||
std::map<std::string, Ogre::Entity*> mEntities;
|
||||
std::map<CSMWorld::CellCoordinates, TextOverlay *> mTextOverlays;
|
||||
std::map<CSMWorld::CellCoordinates, Ogre::Entity*> mEntities;
|
||||
|
||||
private:
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ namespace CSVRender
|
|||
// http://www.ogre3d.org/tikiwiki/tiki-index.php?page=Creating+dynamic+textures
|
||||
// http://www.ogre3d.org/tikiwiki/ManualObject
|
||||
TextOverlay::TextOverlay(const Ogre::MovableObject* obj, const Ogre::Camera* camera, const Ogre::String& id)
|
||||
: mOverlay(0), mCaption(""), mEnabled(true), mCamera(camera), mObj(obj), mId(id), mOnScreen(false)
|
||||
: mOverlay(0), mCaption(""), mDesc(""), mEnabled(true), mCamera(camera), mObj(obj), mId(id), mOnScreen(false)
|
||||
, mFontHeight(16) // FIXME: make this configurable
|
||||
{
|
||||
if(id == "" || !camera || !obj)
|
||||
|
|
|
@ -54,7 +54,8 @@ namespace CSVRender
|
|||
void setDesc(const Ogre::String& text);
|
||||
void update();
|
||||
QRect container();
|
||||
Ogre::String getCaption() { return mCaption; } // FIXME: debug
|
||||
Ogre::String getCaption() { return mCaption; } // FIXME: debug
|
||||
Ogre::String getDesc() { return mDesc; }
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue