commit
66040e3a7b
@ -0,0 +1,28 @@
|
||||
|
||||
#include "messages.hpp"
|
||||
|
||||
void CSMDoc::Messages::add (const CSMWorld::UniversalId& id, const std::string& message,
|
||||
const std::string& hint)
|
||||
{
|
||||
Message data;
|
||||
data.mId = id;
|
||||
data.mMessage = message;
|
||||
data.mHint = hint;
|
||||
|
||||
mMessages.push_back (data);
|
||||
}
|
||||
|
||||
void CSMDoc::Messages::push_back (const std::pair<CSMWorld::UniversalId, std::string>& data)
|
||||
{
|
||||
add (data.first, data.second);
|
||||
}
|
||||
|
||||
CSMDoc::Messages::Iterator CSMDoc::Messages::begin() const
|
||||
{
|
||||
return mMessages.begin();
|
||||
}
|
||||
|
||||
CSMDoc::Messages::Iterator CSMDoc::Messages::end() const
|
||||
{
|
||||
return mMessages.end();
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
#ifndef CSM_DOC_MESSAGES_H
|
||||
#define CSM_DOC_MESSAGES_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "../world/universalid.hpp"
|
||||
|
||||
namespace CSMDoc
|
||||
{
|
||||
class Messages
|
||||
{
|
||||
public:
|
||||
|
||||
struct Message
|
||||
{
|
||||
CSMWorld::UniversalId mId;
|
||||
std::string mMessage;
|
||||
std::string mHint;
|
||||
};
|
||||
|
||||
typedef std::vector<Message> Collection;
|
||||
|
||||
typedef Collection::const_iterator Iterator;
|
||||
|
||||
private:
|
||||
|
||||
Collection mMessages;
|
||||
|
||||
public:
|
||||
|
||||
void add (const CSMWorld::UniversalId& id, const std::string& message,
|
||||
const std::string& hint = "");
|
||||
|
||||
/// \deprecated Use add instead.
|
||||
void push_back (const std::pair<CSMWorld::UniversalId, std::string>& data);
|
||||
|
||||
Iterator begin() const;
|
||||
|
||||
Iterator end() const;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,136 @@
|
||||
|
||||
#include "reporttable.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <QHeaderView>
|
||||
#include <QAction>
|
||||
#include <QMenu>
|
||||
|
||||
#include "../../model/tools/reportmodel.hpp"
|
||||
|
||||
#include "../../view/world/idtypedelegate.hpp"
|
||||
|
||||
void CSVTools::ReportTable::contextMenuEvent (QContextMenuEvent *event)
|
||||
{
|
||||
QModelIndexList selectedRows = selectionModel()->selectedRows();
|
||||
|
||||
// create context menu
|
||||
QMenu menu (this);
|
||||
|
||||
if (!selectedRows.empty())
|
||||
{
|
||||
menu.addAction (mShowAction);
|
||||
menu.addAction (mRemoveAction);
|
||||
}
|
||||
|
||||
menu.exec (event->globalPos());
|
||||
}
|
||||
|
||||
void CSVTools::ReportTable::mouseMoveEvent (QMouseEvent *event)
|
||||
{
|
||||
if (event->buttons() & Qt::LeftButton)
|
||||
startDrag (*this);
|
||||
}
|
||||
|
||||
void CSVTools::ReportTable::mouseDoubleClickEvent (QMouseEvent *event)
|
||||
{
|
||||
Qt::KeyboardModifiers modifiers =
|
||||
event->modifiers() & (Qt::ShiftModifier | Qt::ControlModifier);
|
||||
|
||||
QModelIndex index = currentIndex();
|
||||
|
||||
selectionModel()->select (index,
|
||||
QItemSelectionModel::Clear | QItemSelectionModel::Select | QItemSelectionModel::Rows);
|
||||
|
||||
switch (modifiers)
|
||||
{
|
||||
case 0:
|
||||
|
||||
event->accept();
|
||||
showSelection();
|
||||
break;
|
||||
|
||||
case Qt::ShiftModifier:
|
||||
|
||||
event->accept();
|
||||
removeSelection();
|
||||
break;
|
||||
|
||||
case Qt::ControlModifier:
|
||||
|
||||
event->accept();
|
||||
showSelection();
|
||||
removeSelection();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
CSVTools::ReportTable::ReportTable (CSMDoc::Document& document,
|
||||
const CSMWorld::UniversalId& id, QWidget *parent)
|
||||
: CSVWorld::DragRecordTable (document, parent), mModel (document.getReport (id))
|
||||
{
|
||||
horizontalHeader()->setResizeMode (QHeaderView::Interactive);
|
||||
verticalHeader()->hide();
|
||||
setSortingEnabled (true);
|
||||
setSelectionBehavior (QAbstractItemView::SelectRows);
|
||||
setSelectionMode (QAbstractItemView::ExtendedSelection);
|
||||
|
||||
setModel (mModel);
|
||||
setColumnHidden (2, true);
|
||||
|
||||
mIdTypeDelegate = CSVWorld::IdTypeDelegateFactory().makeDelegate (
|
||||
document, this);
|
||||
|
||||
setItemDelegateForColumn (0, mIdTypeDelegate);
|
||||
|
||||
mShowAction = new QAction (tr ("Show"), this);
|
||||
connect (mShowAction, SIGNAL (triggered()), this, SLOT (showSelection()));
|
||||
addAction (mShowAction);
|
||||
|
||||
mRemoveAction = new QAction (tr ("Remove from list"), this);
|
||||
connect (mRemoveAction, SIGNAL (triggered()), this, SLOT (removeSelection()));
|
||||
addAction (mRemoveAction);
|
||||
}
|
||||
|
||||
std::vector<CSMWorld::UniversalId> CSVTools::ReportTable::getDraggedRecords() const
|
||||
{
|
||||
std::vector<CSMWorld::UniversalId> ids;
|
||||
|
||||
QModelIndexList selectedRows = selectionModel()->selectedRows();
|
||||
|
||||
for (QModelIndexList::const_iterator iter (selectedRows.begin()); iter!=selectedRows.end();
|
||||
++iter)
|
||||
{
|
||||
ids.push_back (mModel->getUniversalId (iter->row()));
|
||||
}
|
||||
|
||||
return ids;
|
||||
}
|
||||
|
||||
void CSVTools::ReportTable::updateUserSetting (const QString& name, const QStringList& list)
|
||||
{
|
||||
mIdTypeDelegate->updateUserSetting (name, list);
|
||||
}
|
||||
|
||||
void CSVTools::ReportTable::showSelection()
|
||||
{
|
||||
QModelIndexList selectedRows = selectionModel()->selectedRows();
|
||||
|
||||
for (QModelIndexList::const_iterator iter (selectedRows.begin()); iter!=selectedRows.end();
|
||||
++iter)
|
||||
emit editRequest (mModel->getUniversalId (iter->row()), mModel->getHint (iter->row()));
|
||||
}
|
||||
|
||||
void CSVTools::ReportTable::removeSelection()
|
||||
{
|
||||
QModelIndexList selectedRows = selectionModel()->selectedRows();
|
||||
|
||||
std::reverse (selectedRows.begin(), selectedRows.end());
|
||||
|
||||
for (QModelIndexList::const_iterator iter (selectedRows.begin()); iter!=selectedRows.end();
|
||||
++iter)
|
||||
mModel->removeRows (iter->row(), 1);
|
||||
|
||||
selectionModel()->clear();
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
#ifndef CSV_TOOLS_REPORTTABLE_H
|
||||
#define CSV_TOOLS_REPORTTABLE_H
|
||||
|
||||
#include "../world/dragrecordtable.hpp"
|
||||
|
||||
class QAction;
|
||||
|
||||
namespace CSMTools
|
||||
{
|
||||
class ReportModel;
|
||||
}
|
||||
|
||||
namespace CSVWorld
|
||||
{
|
||||
class CommandDelegate;
|
||||
}
|
||||
|
||||
namespace CSVTools
|
||||
{
|
||||
class ReportTable : public CSVWorld::DragRecordTable
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
CSMTools::ReportModel *mModel;
|
||||
CSVWorld::CommandDelegate *mIdTypeDelegate;
|
||||
QAction *mShowAction;
|
||||
QAction *mRemoveAction;
|
||||
|
||||
private:
|
||||
|
||||
void contextMenuEvent (QContextMenuEvent *event);
|
||||
|
||||
void mouseMoveEvent (QMouseEvent *event);
|
||||
|
||||
virtual void mouseDoubleClickEvent (QMouseEvent *event);
|
||||
|
||||
public:
|
||||
|
||||
ReportTable (CSMDoc::Document& document, const CSMWorld::UniversalId& id,
|
||||
QWidget *parent = 0);
|
||||
|
||||
virtual std::vector<CSMWorld::UniversalId> getDraggedRecords() const;
|
||||
|
||||
void updateUserSetting (const QString& name, const QStringList& list);
|
||||
|
||||
private slots:
|
||||
|
||||
void showSelection();
|
||||
|
||||
void removeSelection();
|
||||
|
||||
signals:
|
||||
|
||||
void editRequest (const CSMWorld::UniversalId& id, const std::string& hint);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -1,110 +0,0 @@
|
||||
#include "physicsmanager.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <openengine/bullet/BulletShapeLoader.h>
|
||||
|
||||
#include "../render/worldspacewidget.hpp"
|
||||
#include "physicssystem.hpp"
|
||||
|
||||
namespace CSVWorld
|
||||
{
|
||||
PhysicsManager *PhysicsManager::mPhysicsManagerInstance = 0;
|
||||
|
||||
PhysicsManager::PhysicsManager()
|
||||
{
|
||||
assert(!mPhysicsManagerInstance);
|
||||
mPhysicsManagerInstance = this;
|
||||
}
|
||||
|
||||
PhysicsManager::~PhysicsManager()
|
||||
{
|
||||
std::map<CSMDoc::Document *, CSVWorld::PhysicsSystem *>::iterator iter = mPhysics.begin();
|
||||
for(; iter != mPhysics.end(); ++iter)
|
||||
delete iter->second; // shouldn't be any left but just in case
|
||||
}
|
||||
|
||||
PhysicsManager *PhysicsManager::instance()
|
||||
{
|
||||
assert(mPhysicsManagerInstance);
|
||||
return mPhysicsManagerInstance;
|
||||
}
|
||||
|
||||
// create a physics instance per document, called from CSVDoc::View() to get Document*
|
||||
void PhysicsManager::setupPhysics(CSMDoc::Document *doc)
|
||||
{
|
||||
std::map<CSMDoc::Document *, std::list<CSVRender::SceneWidget *> >::iterator iter = mSceneWidgets.find(doc);
|
||||
if(iter == mSceneWidgets.end())
|
||||
{
|
||||
mSceneWidgets[doc] = std::list<CSVRender::SceneWidget *> (); // zero elements
|
||||
mPhysics[doc] = new PhysicsSystem();
|
||||
}
|
||||
}
|
||||
|
||||
// destroy physics, called from CSVDoc::ViewManager
|
||||
void PhysicsManager::removeDocument(CSMDoc::Document *doc)
|
||||
{
|
||||
std::map<CSMDoc::Document *, CSVWorld::PhysicsSystem *>::iterator iter = mPhysics.find(doc);
|
||||
if(iter != mPhysics.end())
|
||||
{
|
||||
delete iter->second;
|
||||
mPhysics.erase(iter);
|
||||
}
|
||||
|
||||
std::map<CSMDoc::Document *, std::list<CSVRender::SceneWidget *> >::iterator it = mSceneWidgets.find(doc);
|
||||
if(it != mSceneWidgets.end())
|
||||
{
|
||||
mSceneWidgets.erase(it);
|
||||
}
|
||||
|
||||
// cleanup global resources used by OEngine
|
||||
if(mPhysics.empty())
|
||||
{
|
||||
delete OEngine::Physic::BulletShapeManager::getSingletonPtr();
|
||||
}
|
||||
}
|
||||
|
||||
// called from CSVRender::WorldspaceWidget() to get widgets' association with Document&
|
||||
PhysicsSystem *PhysicsManager::addSceneWidget(CSMDoc::Document &doc, CSVRender::WorldspaceWidget *widget)
|
||||
{
|
||||
CSVRender::SceneWidget *sceneWidget = static_cast<CSVRender::SceneWidget *>(widget);
|
||||
|
||||
std::map<CSMDoc::Document *, std::list<CSVRender::SceneWidget *> >::iterator iter = mSceneWidgets.begin();
|
||||
for(; iter != mSceneWidgets.end(); ++iter)
|
||||
{
|
||||
if((*iter).first == &doc)
|
||||
{
|
||||
(*iter).second.push_back(sceneWidget);
|
||||
return mPhysics[(*iter).first]; // TODO: consider using shared_ptr instead
|
||||
}
|
||||
}
|
||||
|
||||
throw std::runtime_error("No physics system found for the given document.");
|
||||
}
|
||||
|
||||
// deprecated by removeDocument() and may be deleted in future code updates
|
||||
// however there may be some value in removing the deleted scene widgets from the
|
||||
// list so that the list does not grow forever
|
||||
void PhysicsManager::removeSceneWidget(CSVRender::WorldspaceWidget *widget)
|
||||
{
|
||||
CSVRender::SceneWidget *sceneWidget = static_cast<CSVRender::SceneWidget *>(widget);
|
||||
|
||||
std::map<CSMDoc::Document *, std::list<CSVRender::SceneWidget *> >::iterator iter = mSceneWidgets.begin();
|
||||
for(; iter != mSceneWidgets.end(); ++iter)
|
||||
{
|
||||
std::list<CSVRender::SceneWidget *>::iterator itWidget = (*iter).second.begin();
|
||||
for(; itWidget != (*iter).second.end(); ++itWidget)
|
||||
{
|
||||
if((*itWidget) == sceneWidget)
|
||||
{
|
||||
(*iter).second.erase(itWidget);
|
||||
|
||||
//if((*iter).second.empty()) // last one for the document
|
||||
// NOTE: do not delete physics until the document itself is closed
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
#ifndef CSV_WORLD_PHYSICSMANAGER_H
|
||||
#define CSV_WORLD_PHYSICSMANAGER_H
|
||||
|
||||
#include <map>
|
||||
#include <list>
|
||||
|
||||
namespace Ogre
|
||||
{
|
||||
class SceneManager;
|
||||
}
|
||||
|
||||
namespace CSMDoc
|
||||
{
|
||||
class Document;
|
||||
}
|
||||
|
||||
namespace CSVRender
|
||||
{
|
||||
class WorldspaceWidget;
|
||||
class SceneWidget;
|
||||
}
|
||||
|
||||
namespace CSVWorld
|
||||
{
|
||||
class PhysicsSystem;
|
||||
}
|
||||
|
||||
namespace CSVWorld
|
||||
{
|
||||
class PhysicsManager
|
||||
{
|
||||
static PhysicsManager *mPhysicsManagerInstance;
|
||||
|
||||
std::map<CSMDoc::Document *, std::list<CSVRender::SceneWidget *> > mSceneWidgets;
|
||||
std::map<CSMDoc::Document *, CSVWorld::PhysicsSystem *> mPhysics;
|
||||
|
||||
public:
|
||||
|
||||
PhysicsManager();
|
||||
~PhysicsManager();
|
||||
|
||||
static PhysicsManager *instance();
|
||||
|
||||
void setupPhysics(CSMDoc::Document *);
|
||||
|
||||
PhysicsSystem *addSceneWidget(CSMDoc::Document &doc, CSVRender::WorldspaceWidget *widget);
|
||||
|
||||
void removeSceneWidget(CSVRender::WorldspaceWidget *widget);
|
||||
|
||||
void removeDocument(CSMDoc::Document *doc);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // CSV_WORLD_PHYSICSMANAGER_H
|
@ -0,0 +1,125 @@
|
||||
#include "scripttest.hpp"
|
||||
|
||||
#include "../mwworld/manualref.hpp"
|
||||
#include "../mwworld/class.hpp"
|
||||
|
||||
#include "../mwbase/environment.hpp"
|
||||
#include "../mwbase/world.hpp"
|
||||
#include "../mwbase/scriptmanager.hpp"
|
||||
|
||||
#include "../mwscript/compilercontext.hpp"
|
||||
|
||||
#include <components/compiler/exception.hpp>
|
||||
#include <components/compiler/streamerrorhandler.hpp>
|
||||
#include <components/compiler/scanner.hpp>
|
||||
#include <components/compiler/locals.hpp>
|
||||
#include <components/compiler/output.hpp>
|
||||
#include <components/compiler/scriptparser.hpp>
|
||||
|
||||
#include "filter.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
void test(const MWWorld::Ptr& actor, int &compiled, int &total, const Compiler::Extensions* extensions, int warningsMode)
|
||||
{
|
||||
MWDialogue::Filter filter(actor, 0, false);
|
||||
|
||||
MWScript::CompilerContext compilerContext(MWScript::CompilerContext::Type_Dialogue);
|
||||
compilerContext.setExtensions(extensions);
|
||||
std::ostream errorStream(std::cout.rdbuf());
|
||||
Compiler::StreamErrorHandler errorHandler(errorStream);
|
||||
errorHandler.setWarningsMode (warningsMode);
|
||||
|
||||
const MWWorld::Store<ESM::Dialogue>& dialogues = MWBase::Environment::get().getWorld()->getStore().get<ESM::Dialogue>();
|
||||
for (MWWorld::Store<ESM::Dialogue>::iterator it = dialogues.begin(); it != dialogues.end(); ++it)
|
||||
{
|
||||
std::vector<const ESM::DialInfo*> infos = filter.listAll(*it);
|
||||
|
||||
for (std::vector<const ESM::DialInfo*>::iterator it = infos.begin(); it != infos.end(); ++it)
|
||||
{
|
||||
const ESM::DialInfo* info = *it;
|
||||
if (!info->mResultScript.empty())
|
||||
{
|
||||
bool success = true;
|
||||
++total;
|
||||
try
|
||||
{
|
||||
errorHandler.reset();
|
||||
|
||||
std::istringstream input (info->mResultScript + "\n");
|
||||
|
||||
Compiler::Scanner scanner (errorHandler, input, extensions);
|
||||
|
||||
Compiler::Locals locals;
|
||||
|
||||
std::string actorScript = actor.getClass().getScript(actor);
|
||||
|
||||
if (!actorScript.empty())
|
||||
{
|
||||
// grab local variables from actor's script, if available.
|
||||
locals = MWBase::Environment::get().getScriptManager()->getLocals (actorScript);
|
||||
}
|
||||
|
||||
Compiler::ScriptParser parser(errorHandler, compilerContext, locals, false);
|
||||
|
||||
scanner.scan (parser);
|
||||
|
||||
if (!errorHandler.isGood())
|
||||
success = false;
|
||||
|
||||
++compiled;
|
||||
}
|
||||
catch (const Compiler::SourceException& /* error */)
|
||||
{
|
||||
// error has already been reported via error handler
|
||||
success = false;
|
||||
}
|
||||
catch (const std::exception& error)
|
||||
{
|
||||
std::cerr << std::string ("Dialogue error: An exception has been thrown: ") + error.what() << std::endl;
|
||||
success = false;
|
||||
}
|
||||
|
||||
if (!success)
|
||||
{
|
||||
std::cerr
|
||||
<< "compiling failed (dialogue script)" << std::endl
|
||||
<< info->mResultScript
|
||||
<< std::endl << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace MWDialogue
|
||||
{
|
||||
|
||||
namespace ScriptTest
|
||||
{
|
||||
|
||||
std::pair<int, int> compileAll(const Compiler::Extensions *extensions, int warningsMode)
|
||||
{
|
||||
int compiled = 0, total = 0;
|
||||
const MWWorld::Store<ESM::NPC>& npcs = MWBase::Environment::get().getWorld()->getStore().get<ESM::NPC>();
|
||||
for (MWWorld::Store<ESM::NPC>::iterator it = npcs.begin(); it != npcs.end(); ++it)
|
||||
{
|
||||
MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), it->mId);
|
||||
test(ref.getPtr(), compiled, total, extensions, warningsMode);
|
||||
}
|
||||
|
||||
const MWWorld::Store<ESM::Creature>& creatures = MWBase::Environment::get().getWorld()->getStore().get<ESM::Creature>();
|
||||
for (MWWorld::Store<ESM::Creature>::iterator it = creatures.begin(); it != creatures.end(); ++it)
|
||||
{
|
||||
MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), it->mId);
|
||||
test(ref.getPtr(), compiled, total, extensions, warningsMode);
|
||||
}
|
||||
return std::make_pair(total, compiled);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
#ifndef OPENMW_MWDIALOGUE_SCRIPTTEST_H
|
||||
#define OPENMW_MWDIALOGUE_SCRIPTTEST_H
|
||||
|
||||
#include <components/compiler/extensions.hpp>
|
||||
|
||||
namespace MWDialogue
|
||||
{
|
||||
|
||||
namespace ScriptTest
|
||||
{
|
||||
|
||||
/// Attempt to compile all dialogue scripts, use for verification purposes
|
||||
/// @return A pair containing <total number of scripts, number of successfully compiled scripts>
|
||||
std::pair<int, int> compileAll(const Compiler::Extensions* extensions, int warningsMode);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue