1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-24 19:23:52 +00:00

Merge branch 'master' into pathgrid-edit

Conflicts:
	apps/opencs/view/render/cell.cpp
	apps/opencs/view/render/mousestate.cpp
	apps/opencs/view/render/object.cpp
	apps/opencs/view/render/object.hpp
	apps/opencs/view/render/pagedworldspacewidget.cpp
	apps/opencs/view/render/unpagedworldspacewidget.cpp
	apps/opencs/view/render/worldspacewidget.cpp
This commit is contained in:
cc9cii 2014-12-09 14:02:26 +11:00
commit 84f0ddd51c
226 changed files with 4043 additions and 960 deletions

View file

@ -600,11 +600,6 @@ if (BUILD_OPENCS)
endif()
if (BUILD_WIZARD)
find_package(LIBUNSHIELD REQUIRED)
if(NOT LIBUNSHIELD_FOUND)
message(FATAL_ERROR "Failed to find Unshield library")
endif(NOT LIBUNSHIELD_FOUND)
add_subdirectory(apps/wizard)
endif()

View file

@ -137,6 +137,7 @@ void Launcher::DataFilesPage::saveSettings(const QString &profile)
void Launcher::DataFilesPage::removeProfile(const QString &profile)
{
mLauncherSettings.remove(QString("Profiles/") + profile);
mLauncherSettings.remove(QString("Profiles/") + profile + QString("/content"));
}
QAbstractItemModel *Launcher::DataFilesPage::profilesModel() const

View file

@ -11,7 +11,7 @@ opencs_units (model/doc
)
opencs_units_noqt (model/doc
stage savingstate savingstages blacklist
stage savingstate savingstages blacklist messages
)
opencs_hdrs_noqt (model/doc
@ -68,11 +68,12 @@ opencs_units (view/world
opencs_units_noqt (view/world
subviews enumdelegate vartypedelegate recordstatusdelegate idtypedelegate datadisplaydelegate
scripthighlighter idvalidator dialoguecreator physicssystem physicsmanager
scripthighlighter idvalidator dialoguecreator physicssystem
)
opencs_units (view/widget
scenetoolbar scenetool scenetoolmode pushbutton scenetooltoggle scenetoolrun modebutton
scenetooltoggle2
)
opencs_units (view/render
@ -92,7 +93,7 @@ opencs_hdrs_noqt (view/render
opencs_units (view/tools
reportsubview
reportsubview reporttable
)
opencs_units_noqt (view/tools

View file

@ -1,6 +1,8 @@
#include "editor.hpp"
#include <openengine/bullet/BulletShapeLoader.h>
#include <QApplication>
#include <QLocalServer>
#include <QLocalSocket>
@ -21,8 +23,8 @@
CS::Editor::Editor (OgreInit::OgreInit& ogreInit)
: mUserSettings (mCfgMgr), mOverlaySystem (0), mDocumentManager (mCfgMgr),
mViewManager (mDocumentManager), mPhysicsManager (0),
mIpcServerName ("org.openmw.OpenCS"), mServer(NULL), mClientSocket(NULL)
mViewManager (mDocumentManager),
mIpcServerName ("org.openmw.OpenCS"), mServer(NULL), mClientSocket(NULL), mPid(""), mLock()
{
std::pair<Files::PathContainer, std::vector<std::string> > config = readConfig();
@ -34,7 +36,6 @@ CS::Editor::Editor (OgreInit::OgreInit& ogreInit)
ogreInit.init ((mCfgMgr.getUserConfigPath() / "opencsOgre.log").string());
mOverlaySystem.reset (new CSVRender::OverlaySystem);
mPhysicsManager.reset (new CSVWorld::PhysicsManager);
Bsa::registerResources (Files::Collections (config.first, !mFsStrict), config.second, true,
mFsStrict);
@ -70,7 +71,15 @@ CS::Editor::Editor (OgreInit::OgreInit& ogreInit)
}
CS::Editor::~Editor ()
{}
{
mPidFile.close();
if(mServer && boost::filesystem::exists(mPid))
remove(mPid.string().c_str()); // ignore any error
// cleanup global resources used by OEngine
delete OEngine::Physic::BulletShapeManager::getSingletonPtr();
}
void CS::Editor::setupDataFiles (const Files::PathContainer& dataDirs)
{
@ -233,7 +242,53 @@ void CS::Editor::showSettings()
bool CS::Editor::makeIPCServer()
{
mServer = new QLocalServer(this);
try
{
mPid = boost::filesystem::temp_directory_path();
mPid /= "opencs.pid";
bool pidExists = boost::filesystem::exists(mPid);
mPidFile.open(mPid);
mLock = boost::interprocess::file_lock(mPid.string().c_str());
if(!mLock.try_lock())
{
std::cerr << "OpenCS already running." << std::endl;
return false;
}
#ifdef _WIN32
mPidFile << GetCurrentProcessId() << std::endl;
#else
mPidFile << getpid() << std::endl;
#endif
mServer = new QLocalServer(this);
if(pidExists)
{
// hack to get the temp directory path
mServer->listen("dummy");
QString fullPath = mServer->fullServerName();
mServer->close();
fullPath.remove(QRegExp("dummy$"));
fullPath += mIpcServerName;
if(boost::filesystem::exists(fullPath.toStdString().c_str()))
{
// TODO: compare pid of the current process with that in the file
std::cout << "Detected unclean shutdown." << std::endl;
// delete the stale file
if(remove(fullPath.toStdString().c_str()))
std::cerr << "ERROR removing stale connection file" << std::endl;
}
}
}
catch(const std::exception& e)
{
std::cerr << "ERROR " << e.what() << std::endl;
return false;
}
if(mServer->listen(mIpcServerName))
{
@ -242,6 +297,7 @@ bool CS::Editor::makeIPCServer()
}
mServer->close();
mServer = NULL;
return false;
}

View file

@ -3,6 +3,9 @@
#include <memory>
#include <boost/interprocess/sync/file_lock.hpp>
#include <boost/filesystem/fstream.hpp>
#include <QObject>
#include <QString>
#include <QLocalServer>
@ -28,7 +31,6 @@
#include "view/settings/dialog.hpp"
#include "view/render/overlaysystem.hpp"
#include "view/world/physicsmanager.hpp"
namespace OgreInit
{
@ -45,7 +47,6 @@ namespace CS
Files::ConfigurationManager mCfgMgr;
CSMSettings::UserSettings mUserSettings;
std::auto_ptr<CSVRender::OverlaySystem> mOverlaySystem;
std::auto_ptr<CSVWorld::PhysicsManager> mPhysicsManager;
CSMDoc::DocumentManager mDocumentManager;
CSVDoc::ViewManager mViewManager;
CSVDoc::StartupDialogue mStartup;
@ -54,6 +55,9 @@ namespace CS
CSVDoc::FileDialog mFileDialog;
boost::filesystem::path mLocal;
boost::filesystem::path mResources;
boost::filesystem::path mPid;
boost::interprocess::file_lock mLock;
boost::filesystem::ofstream mPidFile;
bool mFsStrict;
void setupDataFiles (const Files::PathContainer& dataDirs);

View file

@ -83,7 +83,7 @@ int main(int argc, char *argv[])
if(!editor.makeIPCServer())
{
editor.connectToIPCServer();
// return 0;
return 0;
}
shinyFactory = editor.setupGraphics();

View file

@ -9,6 +9,8 @@
#include <components/files/configurationmanager.hpp>
#endif
#include "../../view/world/physicssystem.hpp"
void CSMDoc::Document::addGmsts()
{
static const char *gmstFloats[] =
@ -2253,7 +2255,7 @@ CSMDoc::Document::Document (const Files::ConfigurationManager& configuration,
mProjectPath ((configuration.getUserDataPath() / "projects") /
(savePath.filename().string() + ".project")),
mSaving (*this, mProjectPath, encoding),
mRunner (mProjectPath)
mRunner (mProjectPath), mPhysics(boost::shared_ptr<CSVWorld::PhysicsSystem>())
{
if (mContentFiles.empty())
throw std::runtime_error ("Empty content file sequence");
@ -2299,8 +2301,8 @@ CSMDoc::Document::Document (const Files::ConfigurationManager& configuration,
connect (&mSaving, SIGNAL (done (int, bool)), this, SLOT (operationDone (int, bool)));
connect (
&mSaving, SIGNAL (reportMessage (const CSMWorld::UniversalId&, const std::string&, int)),
this, SLOT (reportMessage (const CSMWorld::UniversalId&, const std::string&, int)));
&mSaving, SIGNAL (reportMessage (const CSMWorld::UniversalId&, const std::string&, const std::string&, int)),
this, SLOT (reportMessage (const CSMWorld::UniversalId&, const std::string&, const std::string&, int)));
connect (&mRunner, SIGNAL (runStateChanged()), this, SLOT (runStateChanged()));
}
@ -2385,7 +2387,7 @@ void CSMDoc::Document::modificationStateChanged (bool clean)
}
void CSMDoc::Document::reportMessage (const CSMWorld::UniversalId& id, const std::string& message,
int type)
const std::string& hint, int type)
{
/// \todo find a better way to get these messages to the user.
std::cout << message << std::endl;
@ -2464,3 +2466,11 @@ void CSMDoc::Document::progress (int current, int max, int type)
{
emit progress (current, max, type, 1, this);
}
boost::shared_ptr<CSVWorld::PhysicsSystem> CSMDoc::Document::getPhysics ()
{
if(!mPhysics)
mPhysics = boost::shared_ptr<CSVWorld::PhysicsSystem> (new CSVWorld::PhysicsSystem());
return mPhysics;
}

View file

@ -3,6 +3,7 @@
#include <string>
#include <boost/shared_ptr.hpp>
#include <boost/filesystem/path.hpp>
#include <QUndoStack>
@ -39,6 +40,11 @@ namespace CSMWorld
class ResourcesManager;
}
namespace CSVWorld
{
class PhysicsSystem;
}
namespace CSMDoc
{
class Document : public QObject
@ -57,6 +63,7 @@ namespace CSMDoc
boost::filesystem::path mResDir;
Blacklist mBlacklist;
Runner mRunner;
boost::shared_ptr<CSVWorld::PhysicsSystem> mPhysics;
// It is important that the undo stack is declared last, because on desctruction it fires a signal, that is connected to a slot, that is
// using other member variables. Unfortunately this connection is cut only in the QObject destructor, which is way too late.
@ -129,6 +136,8 @@ namespace CSMDoc
QTextDocument *getRunLog();
boost::shared_ptr<CSVWorld::PhysicsSystem> getPhysics();
signals:
void stateChanged (int state, CSMDoc::Document *document);
@ -140,7 +149,7 @@ namespace CSMDoc
void modificationStateChanged (bool clean);
void reportMessage (const CSMWorld::UniversalId& id, const std::string& message,
int type);
const std::string& hint, int type);
void operationDone (int type, bool failed);

View file

@ -52,7 +52,7 @@ void CSMDoc::Loader::load()
{
if (iter->second.mRecordsLeft)
{
CSMDoc::Stage::Messages messages;
CSMDoc::Messages messages;
for (int i=0; i<batchingSize; ++i) // do not flood the system with update signals
if (document->getData().continueLoading (messages))
{
@ -65,11 +65,11 @@ void CSMDoc::Loader::load()
CSMWorld::UniversalId log (CSMWorld::UniversalId::Type_LoadErrorLog, 0);
{ // silence a g++ warning
for (CSMDoc::Stage::Messages::const_iterator iter (messages.begin());
for (CSMDoc::Messages::Iterator iter (messages.begin());
iter!=messages.end(); ++iter)
{
document->getReport (log)->add (iter->first, iter->second);
emit loadMessage (document, iter->second);
document->getReport (log)->add (iter->mId, iter->mMessage);
emit loadMessage (document, iter->mMessage);
}
}

View file

@ -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();
}

View file

@ -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

View file

@ -84,7 +84,7 @@ void CSMDoc::Operation::abort()
void CSMDoc::Operation::executeStage()
{
Stage::Messages messages;
Messages messages;
while (mCurrentStage!=mStages.end())
{
@ -101,7 +101,7 @@ void CSMDoc::Operation::executeStage()
}
catch (const std::exception& e)
{
emit reportMessage (CSMWorld::UniversalId(), e.what(), mType);
emit reportMessage (CSMWorld::UniversalId(), e.what(), "", mType);
abort();
}
@ -112,8 +112,8 @@ void CSMDoc::Operation::executeStage()
emit progress (mCurrentStepTotal, mTotalSteps ? mTotalSteps : 1, mType);
for (Stage::Messages::const_iterator iter (messages.begin()); iter!=messages.end(); ++iter)
emit reportMessage (iter->first, iter->second, mType);
for (Messages::Iterator iter (messages.begin()); iter!=messages.end(); ++iter)
emit reportMessage (iter->mId, iter->mMessage, iter->mHint, mType);
if (mCurrentStage==mStages.end())
exit();

View file

@ -52,7 +52,7 @@ namespace CSMDoc
void progress (int current, int max, int type);
void reportMessage (const CSMWorld::UniversalId& id, const std::string& message,
int type);
const std::string& hint, int type);
void done (int type, bool failed);

View file

@ -6,14 +6,14 @@
#include "../world/universalid.hpp"
#include "messages.hpp"
namespace CSMDoc
{
class Stage
{
public:
typedef std::vector<std::pair<CSMWorld::UniversalId, std::string> > Messages;
virtual ~Stage();
virtual int setup() = 0;

View file

@ -17,7 +17,7 @@ int CSMTools::BirthsignCheckStage::setup()
return mBirthsigns.getSize();
}
void CSMTools::BirthsignCheckStage::perform (int stage, Messages& messages)
void CSMTools::BirthsignCheckStage::perform (int stage, CSMDoc::Messages& messages)
{
const CSMWorld::Record<ESM::BirthSign>& record = mBirthsigns.getRecord (stage);

View file

@ -21,7 +21,7 @@ namespace CSMTools
virtual int setup();
///< \return number of steps
virtual void perform (int stage, Messages& messages);
virtual void perform (int stage, CSMDoc::Messages& messages);
///< Messages resulting from this tage will be appended to \a messages.
};
}

View file

@ -14,7 +14,7 @@ int CSMTools::BodyPartCheckStage::setup()
return mBodyParts.getSize();
}
void CSMTools::BodyPartCheckStage::perform ( int stage, Messages &messages )
void CSMTools::BodyPartCheckStage::perform (int stage, CSMDoc::Messages &messages)
{
const CSMWorld::Record<ESM::BodyPart> &record = mBodyParts.getRecord(stage);

View file

@ -27,7 +27,7 @@ namespace CSMTools
virtual int setup();
///< \return number of steps
virtual void perform( int stage, Messages &messages );
virtual void perform( int stage, CSMDoc::Messages &messages );
///< Messages resulting from this tage will be appended to \a messages.
};
}

View file

@ -18,7 +18,7 @@ int CSMTools::ClassCheckStage::setup()
return mClasses.getSize();
}
void CSMTools::ClassCheckStage::perform (int stage, Messages& messages)
void CSMTools::ClassCheckStage::perform (int stage, CSMDoc::Messages& messages)
{
const CSMWorld::Record<ESM::Class>& record = mClasses.getRecord (stage);

View file

@ -21,7 +21,7 @@ namespace CSMTools
virtual int setup();
///< \return number of steps
virtual void perform (int stage, Messages& messages);
virtual void perform (int stage, CSMDoc::Messages& messages);
///< Messages resulting from this tage will be appended to \a messages.
};
}

View file

@ -18,7 +18,7 @@ int CSMTools::FactionCheckStage::setup()
return mFactions.getSize();
}
void CSMTools::FactionCheckStage::perform (int stage, Messages& messages)
void CSMTools::FactionCheckStage::perform (int stage, CSMDoc::Messages& messages)
{
const CSMWorld::Record<ESM::Faction>& record = mFactions.getRecord (stage);

View file

@ -21,7 +21,7 @@ namespace CSMTools
virtual int setup();
///< \return number of steps
virtual void perform (int stage, Messages& messages);
virtual void perform (int stage, CSMDoc::Messages& messages);
///< Messages resulting from this tage will be appended to \a messages.
};
}

View file

@ -15,10 +15,9 @@ int CSMTools::MandatoryIdStage::setup()
return mIds.size();
}
void CSMTools::MandatoryIdStage::perform (int stage, Messages& messages)
void CSMTools::MandatoryIdStage::perform (int stage, CSMDoc::Messages& messages)
{
if (mIdCollection.searchId (mIds.at (stage))==-1 ||
mIdCollection.getRecord (mIds.at (stage)).isDeleted())
messages.push_back (std::make_pair (mCollectionId,
"Missing mandatory record: " + mIds.at (stage)));
messages.add (mCollectionId, "Missing mandatory record: " + mIds.at (stage));
}

View file

@ -30,7 +30,7 @@ namespace CSMTools
virtual int setup();
///< \return number of steps
virtual void perform (int stage, Messages& messages);
virtual void perform (int stage, CSMDoc::Messages& messages);
///< Messages resulting from this tage will be appended to \a messages.
};
}

View file

@ -7,7 +7,7 @@
#include "../world/universalid.hpp"
void CSMTools::RaceCheckStage::performPerRecord (int stage, Messages& messages)
void CSMTools::RaceCheckStage::performPerRecord (int stage, CSMDoc::Messages& messages)
{
const CSMWorld::Record<ESM::Race>& record = mRaces.getRecord (stage);
@ -46,7 +46,7 @@ void CSMTools::RaceCheckStage::performPerRecord (int stage, Messages& messages)
/// \todo check data members that can't be edited in the table view
}
void CSMTools::RaceCheckStage::performFinal (Messages& messages)
void CSMTools::RaceCheckStage::performFinal (CSMDoc::Messages& messages)
{
CSMWorld::UniversalId id (CSMWorld::UniversalId::Type_Races);
@ -64,7 +64,7 @@ int CSMTools::RaceCheckStage::setup()
return mRaces.getSize()+1;
}
void CSMTools::RaceCheckStage::perform (int stage, Messages& messages)
void CSMTools::RaceCheckStage::perform (int stage, CSMDoc::Messages& messages)
{
if (stage==mRaces.getSize())
performFinal (messages);

View file

@ -15,9 +15,9 @@ namespace CSMTools
const CSMWorld::IdCollection<ESM::Race>& mRaces;
bool mPlayable;
void performPerRecord (int stage, Messages& messages);
void performPerRecord (int stage, CSMDoc::Messages& messages);
void performFinal (Messages& messages);
void performFinal (CSMDoc::Messages& messages);
public:
@ -26,7 +26,7 @@ namespace CSMTools
virtual int setup();
///< \return number of steps
virtual void perform (int stage, Messages& messages);
virtual void perform (int stage, CSMDoc::Messages& messages);
///< Messages resulting from this tage will be appended to \a messages.
};
}

View file

@ -18,7 +18,7 @@ CSMTools::ReferenceableCheckStage::ReferenceableCheckStage(
{
}
void CSMTools::ReferenceableCheckStage::perform (int stage, Messages& messages)
void CSMTools::ReferenceableCheckStage::perform (int stage, CSMDoc::Messages& messages)
{
//Checks for books, than, when stage is above mBooksSize goes to other checks, with (stage - PrevSum) as stage.
const int bookSize(mReferencables.getBooks().getSize());
@ -232,7 +232,7 @@ int CSMTools::ReferenceableCheckStage::setup()
void CSMTools::ReferenceableCheckStage::bookCheck(
int stage,
const CSMWorld::RefIdDataContainer< ESM::Book >& records,
Messages& messages)
CSMDoc::Messages& messages)
{
const CSMWorld::RecordBase& baseRecord = records.getRecord(stage);
@ -250,7 +250,7 @@ void CSMTools::ReferenceableCheckStage::bookCheck(
void CSMTools::ReferenceableCheckStage::activatorCheck(
int stage,
const CSMWorld::RefIdDataContainer< ESM::Activator >& records,
Messages& messages)
CSMDoc::Messages& messages)
{
const CSMWorld::RecordBase& baseRecord = records.getRecord(stage);
@ -270,7 +270,7 @@ void CSMTools::ReferenceableCheckStage::activatorCheck(
void CSMTools::ReferenceableCheckStage::potionCheck(
int stage,
const CSMWorld::RefIdDataContainer< ESM::Potion >& records,
Messages& messages)
CSMDoc::Messages& messages)
{
const CSMWorld::RecordBase& baseRecord = records.getRecord(stage);
@ -290,7 +290,7 @@ void CSMTools::ReferenceableCheckStage::potionCheck(
void CSMTools::ReferenceableCheckStage::apparatusCheck(
int stage,
const CSMWorld::RefIdDataContainer< ESM::Apparatus >& records,
Messages& messages)
CSMDoc::Messages& messages)
{
const CSMWorld::RecordBase& baseRecord = records.getRecord(stage);
@ -310,7 +310,7 @@ void CSMTools::ReferenceableCheckStage::apparatusCheck(
void CSMTools::ReferenceableCheckStage::armorCheck(
int stage,
const CSMWorld::RefIdDataContainer< ESM::Armor >& records,
Messages& messages)
CSMDoc::Messages& messages)
{
const CSMWorld::RecordBase& baseRecord = records.getRecord(stage);
@ -336,7 +336,7 @@ void CSMTools::ReferenceableCheckStage::armorCheck(
void CSMTools::ReferenceableCheckStage::clothingCheck(
int stage,
const CSMWorld::RefIdDataContainer< ESM::Clothing >& records,
Messages& messages)
CSMDoc::Messages& messages)
{
const CSMWorld::RecordBase& baseRecord = records.getRecord(stage);
@ -353,7 +353,7 @@ void CSMTools::ReferenceableCheckStage::clothingCheck(
void CSMTools::ReferenceableCheckStage::containerCheck(
int stage,
const CSMWorld::RefIdDataContainer< ESM::Container >& records,
Messages& messages)
CSMDoc::Messages& messages)
{
const CSMWorld::RecordBase& baseRecord = records.getRecord(stage);
@ -381,7 +381,7 @@ void CSMTools::ReferenceableCheckStage::containerCheck(
void CSMTools::ReferenceableCheckStage::creatureCheck (
int stage, const CSMWorld::RefIdDataContainer< ESM::Creature >& records,
Messages& messages)
CSMDoc::Messages& messages)
{
const CSMWorld::RecordBase& baseRecord = records.getRecord(stage);
@ -448,7 +448,7 @@ void CSMTools::ReferenceableCheckStage::creatureCheck (
void CSMTools::ReferenceableCheckStage::doorCheck(
int stage, const CSMWorld::RefIdDataContainer< ESM::Door >& records,
Messages& messages)
CSMDoc::Messages& messages)
{
const CSMWorld::RecordBase& baseRecord = records.getRecord(stage);
@ -469,7 +469,7 @@ void CSMTools::ReferenceableCheckStage::doorCheck(
void CSMTools::ReferenceableCheckStage::ingredientCheck(
int stage,
const CSMWorld::RefIdDataContainer< ESM::Ingredient >& records,
Messages& messages)
CSMDoc::Messages& messages)
{
const CSMWorld::RecordBase& baseRecord = records.getRecord(stage);
@ -487,7 +487,7 @@ void CSMTools::ReferenceableCheckStage::ingredientCheck(
void CSMTools::ReferenceableCheckStage::creaturesLevListCheck(
int stage,
const CSMWorld::RefIdDataContainer< ESM::CreatureLevList >& records,
Messages& messages)
CSMDoc::Messages& messages)
{
const CSMWorld::RecordBase& baseRecord = records.getRecord(stage);
@ -505,7 +505,7 @@ void CSMTools::ReferenceableCheckStage::creaturesLevListCheck(
void CSMTools::ReferenceableCheckStage::itemLevelledListCheck(
int stage,
const CSMWorld::RefIdDataContainer< ESM::ItemLevList >& records,
Messages& messages)
CSMDoc::Messages& messages)
{
const CSMWorld::RecordBase& baseRecord = records.getRecord(stage);
@ -522,7 +522,7 @@ void CSMTools::ReferenceableCheckStage::itemLevelledListCheck(
void CSMTools::ReferenceableCheckStage::lightCheck(
int stage, const CSMWorld::RefIdDataContainer< ESM::Light >& records,
Messages& messages)
CSMDoc::Messages& messages)
{
const CSMWorld::RecordBase& baseRecord = records.getRecord(stage);
@ -547,7 +547,7 @@ void CSMTools::ReferenceableCheckStage::lightCheck(
void CSMTools::ReferenceableCheckStage::lockpickCheck(
int stage,
const CSMWorld::RefIdDataContainer< ESM::Lockpick >& records,
Messages& messages)
CSMDoc::Messages& messages)
{
const CSMWorld::RecordBase& baseRecord = records.getRecord(stage);
@ -567,7 +567,7 @@ void CSMTools::ReferenceableCheckStage::lockpickCheck(
void CSMTools::ReferenceableCheckStage::miscCheck(
int stage,
const CSMWorld::RefIdDataContainer< ESM::Miscellaneous >& records,
Messages& messages)
CSMDoc::Messages& messages)
{
const CSMWorld::RecordBase& baseRecord = records.getRecord(stage);
@ -584,7 +584,7 @@ void CSMTools::ReferenceableCheckStage::miscCheck(
void CSMTools::ReferenceableCheckStage::npcCheck (
int stage, const CSMWorld::RefIdDataContainer< ESM::NPC >& records,
Messages& messages)
CSMDoc::Messages& messages)
{
const CSMWorld::RecordBase& baseRecord = records.getRecord(stage);
@ -701,7 +701,7 @@ void CSMTools::ReferenceableCheckStage::npcCheck (
void CSMTools::ReferenceableCheckStage::weaponCheck(
int stage, const CSMWorld::RefIdDataContainer< ESM::Weapon >& records,
Messages& messages)
CSMDoc::Messages& messages)
{
const CSMWorld::RecordBase& baseRecord = records.getRecord (stage);
@ -778,7 +778,7 @@ void CSMTools::ReferenceableCheckStage::weaponCheck(
void CSMTools::ReferenceableCheckStage::probeCheck(
int stage,
const CSMWorld::RefIdDataContainer< ESM::Probe >& records,
Messages& messages)
CSMDoc::Messages& messages)
{
const CSMWorld::RecordBase& baseRecord = records.getRecord(stage);
@ -796,7 +796,7 @@ void CSMTools::ReferenceableCheckStage::probeCheck(
void CSMTools::ReferenceableCheckStage::repairCheck (
int stage, const CSMWorld::RefIdDataContainer< ESM::Repair >& records,
Messages& messages)
CSMDoc::Messages& messages)
{
const CSMWorld::RecordBase& baseRecord = records.getRecord (stage);
@ -812,7 +812,7 @@ void CSMTools::ReferenceableCheckStage::repairCheck (
void CSMTools::ReferenceableCheckStage::staticCheck (
int stage, const CSMWorld::RefIdDataContainer< ESM::Static >& records,
Messages& messages)
CSMDoc::Messages& messages)
{
const CSMWorld::RecordBase& baseRecord = records.getRecord (stage);
@ -828,7 +828,7 @@ void CSMTools::ReferenceableCheckStage::staticCheck (
//final check
void CSMTools::ReferenceableCheckStage::finalCheck (Messages& messages)
void CSMTools::ReferenceableCheckStage::finalCheck (CSMDoc::Messages& messages)
{
if (!mPlayerPresent)
messages.push_back (std::make_pair (CSMWorld::UniversalId::Type_Referenceables,
@ -839,7 +839,7 @@ void CSMTools::ReferenceableCheckStage::finalCheck (Messages& messages)
//Templates begins here
template<typename Item> void CSMTools::ReferenceableCheckStage::inventoryItemCheck (
const Item& someItem, Messages& messages, const std::string& someID, bool enchantable)
const Item& someItem, CSMDoc::Messages& messages, const std::string& someID, bool enchantable)
{
if (someItem.mName.empty())
messages.push_back (std::make_pair (someID, someItem.mId + " has an empty name"));
@ -865,7 +865,7 @@ template<typename Item> void CSMTools::ReferenceableCheckStage::inventoryItemChe
}
template<typename Item> void CSMTools::ReferenceableCheckStage::inventoryItemCheck (
const Item& someItem, Messages& messages, const std::string& someID)
const Item& someItem, CSMDoc::Messages& messages, const std::string& someID)
{
if (someItem.mName.empty())
messages.push_back (std::make_pair (someID, someItem.mId + " has an empty name"));
@ -888,7 +888,7 @@ template<typename Item> void CSMTools::ReferenceableCheckStage::inventoryItemChe
}
template<typename Tool> void CSMTools::ReferenceableCheckStage::toolCheck (
const Tool& someTool, Messages& messages, const std::string& someID, bool canBeBroken)
const Tool& someTool, CSMDoc::Messages& messages, const std::string& someID, bool canBeBroken)
{
if (someTool.mData.mQuality <= 0)
messages.push_back (std::make_pair (someID, someTool.mId + " has non-positive quality"));
@ -899,14 +899,14 @@ template<typename Tool> void CSMTools::ReferenceableCheckStage::toolCheck (
}
template<typename Tool> void CSMTools::ReferenceableCheckStage::toolCheck (
const Tool& someTool, Messages& messages, const std::string& someID)
const Tool& someTool, CSMDoc::Messages& messages, const std::string& someID)
{
if (someTool.mData.mQuality <= 0)
messages.push_back (std::make_pair (someID, someTool.mId + " has non-positive quality"));
}
template<typename List> void CSMTools::ReferenceableCheckStage::listCheck (
const List& someList, Messages& messages, const std::string& someID)
const List& someList, CSMDoc::Messages& messages, const std::string& someID)
{
for (unsigned i = 0; i < someList.mList.size(); ++i)
{

View file

@ -17,56 +17,56 @@ namespace CSMTools
const CSMWorld::IdCollection<ESM::Class>& classes,
const CSMWorld::IdCollection<ESM::Faction>& factions);
virtual void perform(int stage, Messages& messages);
virtual void perform(int stage, CSMDoc::Messages& messages);
virtual int setup();
private:
//CONCRETE CHECKS
void bookCheck(int stage, const CSMWorld::RefIdDataContainer< ESM::Book >& records, Messages& messages);
void activatorCheck(int stage, const CSMWorld::RefIdDataContainer< ESM::Activator >& records, Messages& messages);
void potionCheck(int stage, const CSMWorld::RefIdDataContainer<ESM::Potion>& records, Messages& messages);
void apparatusCheck(int stage, const CSMWorld::RefIdDataContainer<ESM::Apparatus>& records, Messages& messages);
void armorCheck(int stage, const CSMWorld::RefIdDataContainer<ESM::Armor>& records, Messages& messages);
void clothingCheck(int stage, const CSMWorld::RefIdDataContainer<ESM::Clothing>& records, Messages& messages);
void containerCheck(int stage, const CSMWorld::RefIdDataContainer<ESM::Container>& records, Messages& messages);
void creatureCheck(int stage, const CSMWorld::RefIdDataContainer<ESM::Creature>& records, Messages& messages);
void doorCheck(int stage, const CSMWorld::RefIdDataContainer<ESM::Door>& records, Messages& messages);
void ingredientCheck(int stage, const CSMWorld::RefIdDataContainer<ESM::Ingredient>& records, Messages& messages);
void creaturesLevListCheck(int stage, const CSMWorld::RefIdDataContainer<ESM::CreatureLevList>& records, Messages& messages);
void itemLevelledListCheck(int stage, const CSMWorld::RefIdDataContainer<ESM::ItemLevList>& records, Messages& messages);
void lightCheck(int stage, const CSMWorld::RefIdDataContainer<ESM::Light>& records, Messages& messages);
void lockpickCheck(int stage, const CSMWorld::RefIdDataContainer<ESM::Lockpick>& records, Messages& messages);
void miscCheck(int stage, const CSMWorld::RefIdDataContainer<ESM::Miscellaneous>& records, Messages& messages);
void npcCheck(int stage, const CSMWorld::RefIdDataContainer<ESM::NPC>& records, Messages& messages);
void weaponCheck(int stage, const CSMWorld::RefIdDataContainer<ESM::Weapon>& records, Messages& messages);
void probeCheck(int stage, const CSMWorld::RefIdDataContainer<ESM::Probe>& records, Messages& messages);
void repairCheck(int stage, const CSMWorld::RefIdDataContainer<ESM::Repair>& records, Messages& messages);
void staticCheck(int stage, const CSMWorld::RefIdDataContainer<ESM::Static>& records, Messages& messages);
void bookCheck(int stage, const CSMWorld::RefIdDataContainer< ESM::Book >& records, CSMDoc::Messages& messages);
void activatorCheck(int stage, const CSMWorld::RefIdDataContainer< ESM::Activator >& records, CSMDoc::Messages& messages);
void potionCheck(int stage, const CSMWorld::RefIdDataContainer<ESM::Potion>& records, CSMDoc::Messages& messages);
void apparatusCheck(int stage, const CSMWorld::RefIdDataContainer<ESM::Apparatus>& records, CSMDoc::Messages& messages);
void armorCheck(int stage, const CSMWorld::RefIdDataContainer<ESM::Armor>& records, CSMDoc::Messages& messages);
void clothingCheck(int stage, const CSMWorld::RefIdDataContainer<ESM::Clothing>& records, CSMDoc::Messages& messages);
void containerCheck(int stage, const CSMWorld::RefIdDataContainer<ESM::Container>& records, CSMDoc::Messages& messages);
void creatureCheck(int stage, const CSMWorld::RefIdDataContainer<ESM::Creature>& records, CSMDoc::Messages& messages);
void doorCheck(int stage, const CSMWorld::RefIdDataContainer<ESM::Door>& records, CSMDoc::Messages& messages);
void ingredientCheck(int stage, const CSMWorld::RefIdDataContainer<ESM::Ingredient>& records, CSMDoc::Messages& messages);
void creaturesLevListCheck(int stage, const CSMWorld::RefIdDataContainer<ESM::CreatureLevList>& records, CSMDoc::Messages& messages);
void itemLevelledListCheck(int stage, const CSMWorld::RefIdDataContainer<ESM::ItemLevList>& records, CSMDoc::Messages& messages);
void lightCheck(int stage, const CSMWorld::RefIdDataContainer<ESM::Light>& records, CSMDoc::Messages& messages);
void lockpickCheck(int stage, const CSMWorld::RefIdDataContainer<ESM::Lockpick>& records, CSMDoc::Messages& messages);
void miscCheck(int stage, const CSMWorld::RefIdDataContainer<ESM::Miscellaneous>& records, CSMDoc::Messages& messages);
void npcCheck(int stage, const CSMWorld::RefIdDataContainer<ESM::NPC>& records, CSMDoc::Messages& messages);
void weaponCheck(int stage, const CSMWorld::RefIdDataContainer<ESM::Weapon>& records, CSMDoc::Messages& messages);
void probeCheck(int stage, const CSMWorld::RefIdDataContainer<ESM::Probe>& records, CSMDoc::Messages& messages);
void repairCheck(int stage, const CSMWorld::RefIdDataContainer<ESM::Repair>& records, CSMDoc::Messages& messages);
void staticCheck(int stage, const CSMWorld::RefIdDataContainer<ESM::Static>& records, CSMDoc::Messages& messages);
//FINAL CHECK
void finalCheck (Messages& messages);
void finalCheck (CSMDoc::Messages& messages);
//TEMPLATE CHECKS
template<typename ITEM> void inventoryItemCheck(const ITEM& someItem,
Messages& messages,
CSMDoc::Messages& messages,
const std::string& someID,
bool enchantable); //for all enchantable items.
template<typename ITEM> void inventoryItemCheck(const ITEM& someItem,
Messages& messages,
CSMDoc::Messages& messages,
const std::string& someID); //for non-enchantable items.
template<typename TOOL> void toolCheck(const TOOL& someTool,
Messages& messages,
CSMDoc::Messages& messages,
const std::string& someID,
bool canbebroken); //for tools with uses.
template<typename TOOL> void toolCheck(const TOOL& someTool,
Messages& messages,
CSMDoc::Messages& messages,
const std::string& someID); //for tools without uses.
template<typename LIST> void listCheck(const LIST& someList,
Messages& messages,
CSMDoc::Messages& messages,
const std::string& someID);
const CSMWorld::RefIdData& mReferencables;

View file

@ -17,7 +17,7 @@ int CSMTools::RegionCheckStage::setup()
return mRegions.getSize();
}
void CSMTools::RegionCheckStage::perform (int stage, Messages& messages)
void CSMTools::RegionCheckStage::perform (int stage, CSMDoc::Messages& messages)
{
const CSMWorld::Record<ESM::Region>& record = mRegions.getRecord (stage);

View file

@ -21,7 +21,7 @@ namespace CSMTools
virtual int setup();
///< \return number of steps
virtual void perform (int stage, Messages& messages);
virtual void perform (int stage, CSMDoc::Messages& messages);
///< Messages resulting from this tage will be appended to \a messages.
};
}

View file

@ -16,7 +16,7 @@ int CSMTools::ReportModel::columnCount (const QModelIndex & parent) const
if (parent.isValid())
return 0;
return 2;
return 3;
}
QVariant CSMTools::ReportModel::data (const QModelIndex & index, int role) const
@ -26,8 +26,11 @@ QVariant CSMTools::ReportModel::data (const QModelIndex & index, int role) const
if (index.column()==0)
return static_cast<int> (mRows.at (index.row()).first.getType());
else
return mRows.at (index.row()).second.c_str();
if (index.column()==1)
return QString::fromUtf8 (mRows.at (index.row()).second.first.c_str());
return QString::fromUtf8 (mRows.at (index.row()).second.second.c_str());
}
QVariant CSMTools::ReportModel::headerData (int section, Qt::Orientation orientation, int role) const
@ -38,7 +41,13 @@ QVariant CSMTools::ReportModel::headerData (int section, Qt::Orientation orienta
if (orientation==Qt::Vertical)
return QVariant();
return tr (section==0 ? "Type" : "Description");
if (section==0)
return "Type";
if (section==1)
return "Description";
return "Hint";
}
bool CSMTools::ReportModel::removeRows (int row, int count, const QModelIndex& parent)
@ -51,11 +60,12 @@ bool CSMTools::ReportModel::removeRows (int row, int count, const QModelIndex& p
return true;
}
void CSMTools::ReportModel::add (const CSMWorld::UniversalId& id, const std::string& message)
void CSMTools::ReportModel::add (const CSMWorld::UniversalId& id, const std::string& message,
const std::string& hint)
{
beginInsertRows (QModelIndex(), mRows.size(), mRows.size());
mRows.push_back (std::make_pair (id, message));
mRows.push_back (std::make_pair (id, std::make_pair (message, hint)));
endInsertRows();
}
@ -64,3 +74,8 @@ const CSMWorld::UniversalId& CSMTools::ReportModel::getUniversalId (int row) con
{
return mRows.at (row).first;
}
std::string CSMTools::ReportModel::getHint (int row) const
{
return mRows.at (row).second.second;
}

View file

@ -14,7 +14,7 @@ namespace CSMTools
{
Q_OBJECT
std::vector<std::pair<CSMWorld::UniversalId, std::string> > mRows;
std::vector<std::pair<CSMWorld::UniversalId, std::pair<std::string, std::string> > > mRows;
public:
@ -28,9 +28,12 @@ namespace CSMTools
virtual bool removeRows (int row, int count, const QModelIndex& parent = QModelIndex());
void add (const CSMWorld::UniversalId& id, const std::string& message);
void add (const CSMWorld::UniversalId& id, const std::string& message,
const std::string& hint = "");
const CSMWorld::UniversalId& getUniversalId (int row) const;
std::string getHint (int row) const;
};
}

View file

@ -28,7 +28,11 @@ void CSMTools::ScriptCheckStage::report (const std::string& message, const Compi
<< ", line " << loc.mLine << ", column " << loc.mColumn
<< " (" << loc.mLiteral << "): " << message;
mMessages->push_back (std::make_pair (id, stream.str()));
std::ostringstream hintStream;
hintStream << "l:" << loc.mLine << " " << loc.mColumn;
mMessages->add (id, stream.str(), hintStream.str());
}
void CSMTools::ScriptCheckStage::report (const std::string& message, Type type)
@ -58,7 +62,7 @@ int CSMTools::ScriptCheckStage::setup()
return mDocument.getData().getScripts().getSize();
}
void CSMTools::ScriptCheckStage::perform (int stage, Messages& messages)
void CSMTools::ScriptCheckStage::perform (int stage, CSMDoc::Messages& messages)
{
mId = mDocument.getData().getScripts().getId (stage);

View file

@ -23,7 +23,7 @@ namespace CSMTools
CSMWorld::ScriptContext mContext;
std::string mId;
std::string mFile;
Messages *mMessages;
CSMDoc::Messages *mMessages;
virtual void report (const std::string& message, const Compiler::TokenLoc& loc, Type type);
///< Report error to the user.
@ -38,7 +38,7 @@ namespace CSMTools
virtual int setup();
///< \return number of steps
virtual void perform (int stage, Messages& messages);
virtual void perform (int stage, CSMDoc::Messages& messages);
///< Messages resulting from this tage will be appended to \a messages.
};
}

View file

@ -16,7 +16,7 @@ int CSMTools::SkillCheckStage::setup()
return mSkills.getSize();
}
void CSMTools::SkillCheckStage::perform (int stage, Messages& messages)
void CSMTools::SkillCheckStage::perform (int stage, CSMDoc::Messages& messages)
{
const CSMWorld::Record<ESM::Skill>& record = mSkills.getRecord (stage);

View file

@ -21,7 +21,7 @@ namespace CSMTools
virtual int setup();
///< \return number of steps
virtual void perform (int stage, Messages& messages);
virtual void perform (int stage, CSMDoc::Messages& messages);
///< Messages resulting from this tage will be appended to \a messages.
};
}

View file

@ -16,7 +16,7 @@ int CSMTools::SoundCheckStage::setup()
return mSounds.getSize();
}
void CSMTools::SoundCheckStage::perform (int stage, Messages& messages)
void CSMTools::SoundCheckStage::perform (int stage, CSMDoc::Messages& messages)
{
const CSMWorld::Record<ESM::Sound>& record = mSounds.getRecord (stage);

View file

@ -21,7 +21,7 @@ namespace CSMTools
virtual int setup();
///< \return number of steps
virtual void perform (int stage, Messages& messages);
virtual void perform (int stage, CSMDoc::Messages& messages);
///< Messages resulting from this tage will be appended to \a messages.
};
}

View file

@ -17,7 +17,7 @@ int CSMTools::SpellCheckStage::setup()
return mSpells.getSize();
}
void CSMTools::SpellCheckStage::perform (int stage, Messages& messages)
void CSMTools::SpellCheckStage::perform (int stage, CSMDoc::Messages& messages)
{
const CSMWorld::Record<ESM::Spell>& record = mSpells.getRecord (stage);

View file

@ -21,7 +21,7 @@ namespace CSMTools
virtual int setup();
///< \return number of steps
virtual void perform (int stage, Messages& messages);
virtual void perform (int stage, CSMDoc::Messages& messages);
///< Messages resulting from this tage will be appended to \a messages.
};
}

View file

@ -48,8 +48,8 @@ CSMDoc::Operation *CSMTools::Tools::getVerifier()
connect (mVerifier, SIGNAL (progress (int, int, int)), this, SIGNAL (progress (int, int, int)));
connect (mVerifier, SIGNAL (done (int, bool)), this, SIGNAL (done (int, bool)));
connect (mVerifier,
SIGNAL (reportMessage (const CSMWorld::UniversalId&, const std::string&, int)),
this, SLOT (verifierMessage (const CSMWorld::UniversalId&, const std::string&, int)));
SIGNAL (reportMessage (const CSMWorld::UniversalId&, const std::string&, const std::string&, int)),
this, SLOT (verifierMessage (const CSMWorld::UniversalId&, const std::string&, const std::string&, int)));
std::vector<std::string> mandatoryIds; // I want C++11, damn it!
mandatoryIds.push_back ("Day");
@ -155,11 +155,11 @@ CSMTools::ReportModel *CSMTools::Tools::getReport (const CSMWorld::UniversalId&
}
void CSMTools::Tools::verifierMessage (const CSMWorld::UniversalId& id, const std::string& message,
int type)
const std::string& hint, int type)
{
std::map<int, int>::iterator iter = mActiveReports.find (type);
if (iter!=mActiveReports.end())
mReports[iter->second]->add (id, message);
mReports[iter->second]->add (id, message, hint);
}

View file

@ -64,7 +64,7 @@ namespace CSMTools
private slots:
void verifierMessage (const CSMWorld::UniversalId& id, const std::string& message,
int type);
const std::string& hint, int type);
signals:

View file

@ -272,7 +272,7 @@ namespace CSMWorld
{
ESXRecordT record2 = record.get();
record2.mData.mUseValue[mIndex] = data.toInt();
record2.mData.mUseValue[mIndex] = data.toFloat();
record.setModified (record2);
}

View file

@ -671,16 +671,24 @@ int CSMWorld::Data::startLoading (const boost::filesystem::path& path, bool base
return mReader->getRecordCount();
}
bool CSMWorld::Data::continueLoading (CSMDoc::Stage::Messages& messages)
bool CSMWorld::Data::continueLoading (CSMDoc::Messages& messages)
{
if (!mReader)
throw std::logic_error ("can't continue loading, because no load has been started");
if (!mReader->hasMoreRecs())
{
// Don't delete the Reader yet. Some record types store a reference to the Reader to handle on-demand loading
boost::shared_ptr<ESM::ESMReader> ptr(mReader);
mReaders.push_back(ptr);
if (mBase)
{
// Don't delete the Reader yet. Some record types store a reference to the Reader to handle on-demand loading.
// We don't store non-base reader, because everything going into modified will be
// fully loaded during the initial loading process.
boost::shared_ptr<ESM::ESMReader> ptr(mReader);
mReaders.push_back(ptr);
}
else
delete mReader;
mReader = 0;
mDialogue = 0;
@ -713,7 +721,18 @@ bool CSMWorld::Data::continueLoading (CSMDoc::Stage::Messages& messages)
case ESM::REC_PGRD: mPathgrids.load (*mReader, mBase); break;
case ESM::REC_LTEX: mLandTextures.load (*mReader, mBase); break;
case ESM::REC_LAND: mLand.load(*mReader, mBase); break;
case ESM::REC_LAND:
{
int index = mLand.load(*mReader, mBase);
if (index!=-1 && !mBase)
mLand.getRecord (index).mModified.mLand->loadData (
ESM::Land::DATA_VHGT | ESM::Land::DATA_VNML | ESM::Land::DATA_VCLR |
ESM::Land::DATA_VTEX);
break;
}
case ESM::REC_CELL:
{
@ -775,8 +794,8 @@ bool CSMWorld::Data::continueLoading (CSMDoc::Stage::Messages& messages)
}
else
{
messages.push_back (std::make_pair (UniversalId::Type_None,
"Trying to delete dialogue record " + id + " which does not exist"));
messages.add (UniversalId::Type_None,
"Trying to delete dialogue record " + id + " which does not exist");
}
}
else
@ -792,8 +811,8 @@ bool CSMWorld::Data::continueLoading (CSMDoc::Stage::Messages& messages)
{
if (!mDialogue)
{
messages.push_back (std::make_pair (UniversalId::Type_None,
"Found info record not following a dialogue record"));
messages.add (UniversalId::Type_None,
"Found info record not following a dialogue record");
mReader->skipRecord();
break;
@ -836,8 +855,7 @@ bool CSMWorld::Data::continueLoading (CSMDoc::Stage::Messages& messages)
if (unhandledRecord)
{
messages.push_back (std::make_pair (UniversalId::Type_None,
"Unsupported record type: " + n.toString()));
messages.add (UniversalId::Type_None, "Unsupported record type: " + n.toString());
mReader->skipRecord();
}

View file

@ -244,7 +244,7 @@ namespace CSMWorld
///
///< \return estimated number of records
bool continueLoading (CSMDoc::Stage::Messages& messages);
bool continueLoading (CSMDoc::Messages& messages);
///< \return Finished?
bool hasId (const std::string& id) const;

View file

@ -15,12 +15,15 @@ namespace CSMWorld
public:
void load (ESM::ESMReader& reader, bool base);
/// \return Index of loaded record (-1 if no record was loaded)
int load (ESM::ESMReader& reader, bool base);
/// \param index Index at which the record can be found.
/// Special values: -2 index unknown, -1 record does not exist yet and therefore
/// does not have an index
void load (const ESXRecordT& record, bool base, int index = -2);
///
/// \return index
int load (const ESXRecordT& record, bool base, int index = -2);
bool tryDelete (const std::string& id);
///< Try deleting \a id. If the id does not exist or can't be deleted the call is ignored.
@ -36,7 +39,7 @@ namespace CSMWorld
}
template<typename ESXRecordT, typename IdAccessorT>
void IdCollection<ESXRecordT, IdAccessorT>::load (ESM::ESMReader& reader, bool base)
int IdCollection<ESXRecordT, IdAccessorT>::load (ESM::ESMReader& reader, bool base)
{
std::string id = reader.getHNOString ("NAME");
@ -64,6 +67,8 @@ namespace CSMWorld
record.mState = RecordBase::State_Deleted;
this->setRecord (index, record);
}
return -1;
}
else
{
@ -88,12 +93,12 @@ namespace CSMWorld
index = newIndex;
}
load (record, base, index);
return load (record, base, index);
}
}
template<typename ESXRecordT, typename IdAccessorT>
void IdCollection<ESXRecordT, IdAccessorT>::load (const ESXRecordT& record, bool base,
int IdCollection<ESXRecordT, IdAccessorT>::load (const ESXRecordT& record, bool base,
int index)
{
if (index==-2)
@ -106,6 +111,7 @@ namespace CSMWorld
record2.mState = base ? RecordBase::State_BaseOnly : RecordBase::State_ModifiedOnly;
(base ? record2.mBase : record2.mModified) = record;
index = this->getSize();
this->appendRecord (record2);
}
else
@ -120,6 +126,8 @@ namespace CSMWorld
this->setRecord (index, record2);
}
return index;
}
template<typename ESXRecordT, typename IdAccessorT>

View file

@ -11,7 +11,7 @@
#include "record.hpp"
void CSMWorld::RefCollection::load (ESM::ESMReader& reader, int cellIndex, bool base,
std::map<ESM::RefNum, std::string>& cache, CSMDoc::Stage::Messages& messages)
std::map<ESM::RefNum, std::string>& cache, CSMDoc::Messages& messages)
{
Record<Cell> cell = mCells.getRecord (cellIndex);
@ -36,8 +36,7 @@ void CSMWorld::RefCollection::load (ESM::ESMReader& reader, int cellIndex, bool
CSMWorld::UniversalId id (CSMWorld::UniversalId::Type_Cell,
mCells.getId (cellIndex));
messages.push_back (std::make_pair (id,
"Attempt to delete a non-existing reference"));
messages.add (id, "Attempt to delete a non-existing reference");
continue;
}

View file

@ -28,7 +28,7 @@ namespace CSMWorld
void load (ESM::ESMReader& reader, int cellIndex, bool base,
std::map<ESM::RefNum, std::string>& cache,
CSMDoc::Stage::Messages& messages);
CSMDoc::Messages& messages);
///< Load a sequence of references.
std::string getNewId();

View file

@ -3,6 +3,7 @@
#include <sstream>
#include <stdexcept>
#include <algorithm>
#include <OgreResourceGroupManager.h>
@ -55,7 +56,9 @@ CSMWorld::Resources::Resources (const std::string& baseDirectory, UniversalId::T
std::string file = iter->substr (baseSize+1);
mFiles.push_back (file);
mIndex.insert (std::make_pair (file, static_cast<int> (mFiles.size())-1));
std::replace (file.begin(), file.end(), '\\', '/');
mIndex.insert (std::make_pair (
Misc::StringUtils::lowerCase (file), static_cast<int> (mFiles.size())-1));
}
}
}
@ -89,6 +92,8 @@ int CSMWorld::Resources::searchId (const std::string& id) const
{
std::string id2 = Misc::StringUtils::lowerCase (id);
std::replace (id2.begin(), id2.end(), '\\', '/');
std::map<std::string, int>::const_iterator iter = mIndex.find (id2);
if (iter==mIndex.end())

View file

@ -16,7 +16,6 @@
#include "../../model/world/idtable.hpp"
#include "../world/subviews.hpp"
#include "../world/physicsmanager.hpp"
#include "../tools/subviews.hpp"
@ -407,8 +406,6 @@ CSVDoc::View::View (ViewManager& viewManager, CSMDoc::Document *document, int to
mSubViewFactory.add (CSMWorld::UniversalId::Type_RunLog, new SubViewFactory<RunLogSubView>);
connect (mOperations, SIGNAL (abortOperation (int)), this, SLOT (abortOperation (int)));
CSVWorld::PhysicsManager::instance()->setupPhysics(document);
}
CSVDoc::View::~View()

View file

@ -16,7 +16,6 @@
#include "../world/vartypedelegate.hpp"
#include "../world/recordstatusdelegate.hpp"
#include "../world/idtypedelegate.hpp"
#include "../world/physicsmanager.hpp"
#include "../../model/settings/usersettings.hpp"
@ -219,7 +218,6 @@ void CSVDoc::ViewManager::removeDocAndView (CSMDoc::Document *document)
mDocumentManager.removeDocument(document);
(*iter)->deleteLater();
mViews.erase (iter);
CSVWorld::PhysicsManager::instance()->removeDocument(document);
updateIndices();
return;

View file

@ -119,7 +119,7 @@ bool CSVRender::Cell::addObjects (int start, int end)
}
CSVRender::Cell::Cell (CSMWorld::Data& data, Ogre::SceneManager *sceneManager,
const std::string& id, CSVWorld::PhysicsSystem *physics, const Ogre::Vector3& origin)
const std::string& id, boost::shared_ptr<CSVWorld::PhysicsSystem> physics, const Ogre::Vector3& origin)
: mData (data), mId (Misc::StringUtils::lowerCase (id)), mSceneMgr(sceneManager), mPhysics(physics),
mPathgridId("")
{

View file

@ -5,6 +5,8 @@
#include <map>
#include <memory>
#include <boost/shared_ptr.hpp>
#include <OgreVector3.h>
#include <components/terrain/terraingrid.hpp>
@ -50,7 +52,7 @@ namespace CSVRender
std::string mPathgridId; // FIXME: temporary storage until saving to document
std::auto_ptr<Terrain::TerrainGrid> mTerrain;
CSVWorld::PhysicsSystem *mPhysics;
boost::shared_ptr<CSVWorld::PhysicsSystem> mPhysics;
Ogre::SceneManager *mSceneMgr;
int mX;
int mY;
@ -68,7 +70,7 @@ namespace CSVRender
public:
Cell (CSMWorld::Data& data, Ogre::SceneManager *sceneManager, const std::string& id,
CSVWorld::PhysicsSystem *physics, const Ogre::Vector3& origin = Ogre::Vector3 (0, 0, 0));
boost::shared_ptr<CSVWorld::PhysicsSystem> physics, const Ogre::Vector3& origin = Ogre::Vector3 (0, 0, 0));
~Cell();

View file

@ -8,10 +8,10 @@ namespace CSVRender
{
// elements that are part of the actual scene
Element_Reference = 0x1,
Element_Terrain = 0x2,
Element_Pathgrid = 0x2,
Element_Water = 0x4,
Element_Pathgrid = 0x8,
Element_Fog = 0x10,
Element_Fog = 0x8,
Element_Terrain = 0x10,
// control elements
Element_CellMarker = 0x10000,

View file

@ -56,7 +56,7 @@ namespace CSVRender
//
MouseState::MouseState(WorldspaceWidget *parent)
: mParent(parent), mPhysics(parent->getPhysics()), mSceneManager(parent->getSceneManager())
: mParent(parent), mPhysics(parent->mDocument.getPhysics()), mSceneManager(parent->getSceneManager())
, mCurrentObj(""), mMouseState(Mouse_Default), mOldCursorPos(0,0), mMouseEventTimer(0)
, mGrabbedSceneNode(""), mGrabbedRefId(""), mOrigObjPos(Ogre::Vector3())
, mOrigMousePos(Ogre::Vector3()), mOldMousePos(Ogre::Vector3()), mPlane(0)

View file

@ -2,6 +2,7 @@
#define OPENCS_VIEW_MOUSESTATE_H
#include <map>
#include <boost/shared_ptr.hpp>
#include <QPoint>
#include <OgreVector3.h>
@ -43,7 +44,7 @@ namespace CSVRender
MouseStates mMouseState;
WorldspaceWidget *mParent;
CSVWorld::PhysicsSystem *mPhysics; // local copy
boost::shared_ptr<CSVWorld::PhysicsSystem> mPhysics;
Ogre::SceneManager *mSceneManager; // local copy
QPoint mOldCursorPos;

View file

@ -93,7 +93,6 @@ void CSVRender::Object::update()
Ogre::Quaternion yr (Ogre::Radian (-reference.mPos.rot[1]), Ogre::Vector3::UNIT_Y);
Ogre::Quaternion zr (Ogre::Radian (-reference.mPos.rot[2]), Ogre::Vector3::UNIT_Z);
mPhysicsObject = mReferenceId;
mPhysics->addObject("meshes\\" + model, mBase->getName(), mReferenceId, reference.mScale, position, xr*yr*zr);
}
}
@ -133,9 +132,9 @@ const CSMWorld::CellRef& CSVRender::Object::getReference() const
}
CSVRender::Object::Object (const CSMWorld::Data& data, Ogre::SceneNode *cellNode,
const std::string& id, bool referenceable, CSVWorld::PhysicsSystem *physics,
const std::string& id, bool referenceable, boost::shared_ptr<CSVWorld::PhysicsSystem> physics,
bool forceBaseToZero)
: mData (data), mBase (0), mForceBaseToZero (forceBaseToZero), mPhysics(physics), mPhysicsObject("")
: mData (data), mBase (0), mForceBaseToZero (forceBaseToZero), mPhysics(physics)
{
mBase = cellNode->createChildSceneNode();
@ -157,7 +156,7 @@ CSVRender::Object::~Object()
{
clear();
if(mPhysicsObject != "")
if(mPhysics) // preview may not have physics enabled
mPhysics->removeObject(mBase->getName());
if (mBase)

View file

@ -1,6 +1,8 @@
#ifndef OPENCS_VIEW_OBJECT_H
#define OPENCS_VIEW_OBJECT_H
#include <boost/shared_ptr.hpp>
#include <components/nifogre/ogrenifloader.hpp>
class QModelIndex;
@ -31,7 +33,7 @@ namespace CSVRender
Ogre::SceneNode *mBase;
NifOgre::ObjectScenePtr mObject;
bool mForceBaseToZero;
CSVWorld::PhysicsSystem *mPhysics;
boost::shared_ptr<CSVWorld::PhysicsSystem> mPhysics;
std::string mPhysicsObject;
/// Not implemented
@ -59,7 +61,8 @@ namespace CSVRender
Object (const CSMWorld::Data& data, Ogre::SceneNode *cellNode,
const std::string& id, bool referenceable,
CSVWorld::PhysicsSystem *physics = NULL, bool forceBaseToZero = false);
boost::shared_ptr<CSVWorld::PhysicsSystem> physics = boost::shared_ptr<CSVWorld::PhysicsSystem> (),
bool forceBaseToZero = false);
/// \param forceBaseToZero If this is a reference ignore the coordinates and place
/// it at 0, 0, 0 instead.

View file

@ -22,6 +22,7 @@
#include "../widget/scenetooltoggle.hpp"
#include "../widget/scenetoolmode.hpp"
#include "../widget/scenetooltoggle2.hpp"
#include "../world/physicssystem.hpp"
#include "pathgridpoint.hpp"
@ -113,7 +114,7 @@ bool CSVRender::PagedWorldspaceWidget::adjustCells()
mCells.find (*iter)==mCells.end())
{
Cell *cell = new Cell (mDocument.getData(), getSceneManager(),
iter->getId (mWorldspace), getPhysics());
iter->getId (mWorldspace), mDocument.getPhysics());
mCells.insert (std::make_pair (*iter, cell));
float height = cell->getTerrainHeightAt(Ogre::Vector3(
@ -214,6 +215,14 @@ void CSVRender::PagedWorldspaceWidget::mouseDoubleClickEvent (QMouseEvent *event
WorldspaceWidget::mouseDoubleClickEvent(event);
}
void CSVRender::PagedWorldspaceWidget::addVisibilitySelectorButtons (
CSVWidget::SceneToolToggle2 *tool)
{
WorldspaceWidget::addVisibilitySelectorButtons (tool);
tool->addButton (Element_Terrain, "Terrain");
tool->addButton (Element_Fog, "Fog", "", true);
}
void CSVRender::PagedWorldspaceWidget::addEditModeSelectorButtons (
CSVWidget::SceneToolMode *tool)
{
@ -474,9 +483,12 @@ CSVRender::PagedWorldspaceWidget::~PagedWorldspaceWidget()
delete iter->second;
}
if(mOverlayMask)
{
removeRenderTargetListener(mOverlayMask);
delete mOverlayMask;
}
}
void CSVRender::PagedWorldspaceWidget::useViewHint (const std::string& hint)
{

View file

@ -8,9 +8,13 @@
#include "worldspacewidget.hpp"
#include "cell.hpp"
namespace CSVWidget
{
class SceneToolToggle;
}
namespace CSVRender
{
class TextOverlay;
class OverlayMask;
@ -87,6 +91,8 @@ namespace CSVRender
protected:
virtual void addVisibilitySelectorButtons (CSVWidget::SceneToolToggle2 *tool);
virtual void addEditModeSelectorButtons (CSVWidget::SceneToolMode *tool);
virtual void updateOverlay();

View file

@ -10,7 +10,7 @@
CSVRender::PreviewWidget::PreviewWidget (CSMWorld::Data& data,
const std::string& id, bool referenceable, QWidget *parent)
: SceneWidget (parent), mData (data),
mObject (data, getSceneManager()->getRootSceneNode(), id, referenceable, NULL, true)
mObject (data, getSceneManager()->getRootSceneNode(), id, referenceable, boost::shared_ptr<CSVWorld::PhysicsSystem>(), true)
{
setNavigation (&mOrbit);

View file

@ -15,6 +15,7 @@
#include "../../model/world/tablemimedata.hpp"
#include "../widget/scenetooltoggle.hpp"
#include "../widget/scenetooltoggle2.hpp"
#include "elements.hpp"
@ -32,14 +33,6 @@ void CSVRender::UnpagedWorldspaceWidget::update()
flagAsModified();
}
void CSVRender::UnpagedWorldspaceWidget::addVisibilitySelectorButtons (
CSVWidget::SceneToolToggle *tool)
{
WorldspaceWidget::addVisibilitySelectorButtons (tool);
tool->addButton (":armor.png", Element_Fog, ":armor.png", "Fog");
}
CSVRender::UnpagedWorldspaceWidget::UnpagedWorldspaceWidget (const std::string& cellId, CSMDoc::Document& document, QWidget* parent)
: WorldspaceWidget (document, parent), mCellId (cellId)
{
@ -56,7 +49,7 @@ CSVRender::UnpagedWorldspaceWidget::UnpagedWorldspaceWidget (const std::string&
update();
mCell.reset (new Cell (document.getData(), getSceneManager(), mCellId, getPhysics()));
mCell.reset (new Cell (document.getData(), getSceneManager(), mCellId, document.getPhysics()));
}
void CSVRender::UnpagedWorldspaceWidget::cellDataChanged (const QModelIndex& topLeft,
@ -98,7 +91,7 @@ bool CSVRender::UnpagedWorldspaceWidget::handleDrop (const std::vector<CSMWorld:
return false;
mCellId = data.begin()->getId();
mCell.reset (new Cell (getDocument().getData(), getSceneManager(), mCellId, getPhysics()));
mCell.reset (new Cell (getDocument().getData(), getSceneManager(), mCellId, getDocument().getPhysics()));
update();
emit cellChanged(*data.begin());
@ -160,6 +153,14 @@ void CSVRender::UnpagedWorldspaceWidget::referenceAdded (const QModelIndex& pare
flagAsModified();
}
void CSVRender::UnpagedWorldspaceWidget::addVisibilitySelectorButtons (
CSVWidget::SceneToolToggle2 *tool)
{
WorldspaceWidget::addVisibilitySelectorButtons (tool);
tool->addButton (Element_Terrain, "Terrain", "", true);
tool->addButton (Element_Fog, "Fog");
}
//void CSVRender::UnpagedWorldspaceWidget::pathgridAdded (const QModelIndex& parent,
// int start, int end)
//{

View file

@ -32,10 +32,6 @@ namespace CSVRender
void update();
protected:
virtual void addVisibilitySelectorButtons (CSVWidget::SceneToolToggle *tool);
public:
UnpagedWorldspaceWidget (const std::string& cellId, CSMDoc::Document& document,
@ -70,6 +66,10 @@ namespace CSVRender
virtual std::string getStartupInstruction();
protected:
virtual void addVisibilitySelectorButtons (CSVWidget::SceneToolToggle2 *tool);
private slots:
void cellDataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight);

View file

@ -14,17 +14,16 @@
#include "../../model/world/idtable.hpp"
#include "../widget/scenetoolmode.hpp"
#include "../widget/scenetooltoggle.hpp"
#include "../widget/scenetooltoggle2.hpp"
#include "../widget/scenetoolrun.hpp"
#include "../world/physicsmanager.hpp"
#include "../world/physicssystem.hpp"
#include "elements.hpp"
#include "editmode.hpp"
CSVRender::WorldspaceWidget::WorldspaceWidget (CSMDoc::Document& document, QWidget* parent)
: SceneWidget (parent), mDocument(document), mSceneElements(0), mRun(0), mPhysics(0), mMouse(0),
: SceneWidget (parent), mDocument(document), mSceneElements(0), mRun(0), mPhysics(boost::shared_ptr<CSVWorld::PhysicsSystem>()), mMouse(0),
mInteractionMask (0)
{
setAcceptDrops(true);
@ -67,9 +66,7 @@ CSVRender::WorldspaceWidget::WorldspaceWidget (CSMDoc::Document& document, QWidg
//connect (pathgrids, SIGNAL (rowsAboutToBeRemoved (const QModelIndex&, int, int)),
//this, SLOT (pathgridAboutToBeRemoved (const QModelIndex&, int, int)));
// associate WorldSpaceWidgets (and their SceneManagers) with Documents
// then create physics if there is a new document
mPhysics = CSVWorld::PhysicsManager::instance()->addSceneWidget(document, this);
mPhysics = document.getPhysics(); // create physics if one doesn't exist
mPhysics->addSceneManager(getSceneManager(), this);
mMouse = new MouseState(this);
}
@ -78,7 +75,6 @@ CSVRender::WorldspaceWidget::~WorldspaceWidget ()
{
delete mMouse;
mPhysics->removeSceneManager(getSceneManager());
CSVWorld::PhysicsManager::instance()->removeSceneWidget(this);
}
void CSVRender::WorldspaceWidget::selectNavigationMode (const std::string& mode)
@ -138,10 +134,10 @@ CSVWidget::SceneToolMode *CSVRender::WorldspaceWidget::makeNavigationSelector (
return tool;
}
CSVWidget::SceneToolToggle *CSVRender::WorldspaceWidget::makeSceneVisibilitySelector (CSVWidget::SceneToolbar *parent)
CSVWidget::SceneToolToggle2 *CSVRender::WorldspaceWidget::makeSceneVisibilitySelector (CSVWidget::SceneToolbar *parent)
{
mSceneElements= new CSVWidget::SceneToolToggle (parent,
"Scene Element Visibility", ":placeholder");
mSceneElements = new CSVWidget::SceneToolToggle2 (parent,
"Scene Element Visibility", ":scenetoolbar/scene-view-c", ":scenetoolbar/scene-view-");
addVisibilitySelectorButtons (mSceneElements);
@ -183,7 +179,7 @@ CSVWidget::SceneToolRun *CSVRender::WorldspaceWidget::makeRunTool (
std::sort (profiles.begin(), profiles.end());
mRun = new CSVWidget::SceneToolRun (parent, "Run OpenMW from the current camera position",
":placeholder", ":placeholder", profiles);
":scenetoolbar/play", profiles);
connect (mRun, SIGNAL (runRequest (const std::string&)),
this, SLOT (runRequest (const std::string&)));
@ -271,12 +267,11 @@ unsigned int CSVRender::WorldspaceWidget::getInteractionMask() const
}
void CSVRender::WorldspaceWidget::addVisibilitySelectorButtons (
CSVWidget::SceneToolToggle *tool)
CSVWidget::SceneToolToggle2 *tool)
{
tool->addButton (":placeholder", Element_Reference, ":placeholder", "References");
tool->addButton (":placeholder", Element_Terrain, ":placeholder", "Terrain");
tool->addButton (":placeholder", Element_Water, ":placeholder", "Water");
tool->addButton (":placeholder", Element_Pathgrid, ":placeholder", "Pathgrid");
tool->addButton (Element_Reference, "References");
tool->addButton (Element_Water, "Water");
tool->addButton (Element_Pathgrid, "Pathgrid");
}
void CSVRender::WorldspaceWidget::addEditModeSelectorButtons (CSVWidget::SceneToolMode *tool)
@ -380,12 +375,6 @@ void CSVRender::WorldspaceWidget::updateOverlay()
{
}
CSVWorld::PhysicsSystem *CSVRender::WorldspaceWidget::getPhysics()
{
assert(mPhysics);
return mPhysics;
}
void CSVRender::WorldspaceWidget::mouseMoveEvent (QMouseEvent *event)
{
if(event->buttons() & Qt::RightButton)

View file

@ -1,6 +1,8 @@
#ifndef OPENCS_VIEW_WORLDSPACEWIDGET_H
#define OPENCS_VIEW_WORLDSPACEWIDGET_H
#include <boost/shared_ptr.hpp>
#include "scenewidget.hpp"
#include "mousestate.hpp"
@ -18,7 +20,7 @@ namespace CSMWorld
namespace CSVWidget
{
class SceneToolMode;
class SceneToolToggle;
class SceneToolToggle2;
class SceneToolbar;
class SceneToolRun;
}
@ -37,10 +39,10 @@ namespace CSVRender
CSVRender::Navigation1st m1st;
CSVRender::NavigationFree mFree;
CSVRender::NavigationOrbit mOrbit;
CSVWidget::SceneToolToggle *mSceneElements;
CSVWidget::SceneToolToggle2 *mSceneElements;
CSVWidget::SceneToolRun *mRun;
CSMDoc::Document& mDocument;
CSVWorld::PhysicsSystem *mPhysics;
boost::shared_ptr<CSVWorld::PhysicsSystem> mPhysics;
MouseState *mMouse;
unsigned int mInteractionMask;
@ -71,7 +73,7 @@ namespace CSVRender
/// \attention The created tool is not added to the toolbar (via addTool). Doing
/// that is the responsibility of the calling function.
CSVWidget::SceneToolToggle *makeSceneVisibilitySelector (
CSVWidget::SceneToolToggle2 *makeSceneVisibilitySelector (
CSVWidget::SceneToolbar *parent);
/// \attention The created tool is not added to the toolbar (via addTool). Doing
@ -107,7 +109,7 @@ namespace CSVRender
protected:
virtual void addVisibilitySelectorButtons (CSVWidget::SceneToolToggle *tool);
virtual void addVisibilitySelectorButtons (CSVWidget::SceneToolToggle2 *tool);
virtual void addEditModeSelectorButtons (CSVWidget::SceneToolMode *tool);
@ -115,8 +117,6 @@ namespace CSVRender
virtual void updateOverlay();
CSVWorld::PhysicsSystem *getPhysics();
virtual void mouseMoveEvent (QMouseEvent *event);
virtual void mousePressEvent (QMouseEvent *event);
virtual void mouseReleaseEvent (QMouseEvent *event);

View file

@ -1,31 +1,15 @@
#include "reportsubview.hpp"
#include <QTableView>
#include <QHeaderView>
#include "../../model/tools/reportmodel.hpp"
#include "../../view/world/idtypedelegate.hpp"
#include "reporttable.hpp"
CSVTools::ReportSubView::ReportSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document)
: CSVDoc::SubView (id), mModel (document.getReport (id))
: CSVDoc::SubView (id)
{
setWidget (mTable = new QTableView (this));
mTable->setModel (mModel);
setWidget (mTable = new ReportTable (document, id, this));
mTable->horizontalHeader()->setResizeMode (QHeaderView::Interactive);
mTable->verticalHeader()->hide();
mTable->setSortingEnabled (true);
mTable->setSelectionBehavior (QAbstractItemView::SelectRows);
mTable->setSelectionMode (QAbstractItemView::ExtendedSelection);
mIdTypeDelegate = CSVWorld::IdTypeDelegateFactory().makeDelegate (
document, this);
mTable->setItemDelegateForColumn (0, mIdTypeDelegate);
connect (mTable, SIGNAL (doubleClicked (const QModelIndex&)), this, SLOT (show (const QModelIndex&)));
connect (mTable, SIGNAL (editRequest (const CSMWorld::UniversalId&, const std::string&)),
SIGNAL (focusId (const CSMWorld::UniversalId&, const std::string&)));
}
void CSVTools::ReportSubView::setEditLock (bool locked)
@ -33,13 +17,7 @@ void CSVTools::ReportSubView::setEditLock (bool locked)
// ignored. We don't change document state anyway.
}
void CSVTools::ReportSubView::updateUserSetting
(const QString &name, const QStringList &list)
void CSVTools::ReportSubView::updateUserSetting (const QString &name, const QStringList &list)
{
mIdTypeDelegate->updateUserSetting (name, list);
}
void CSVTools::ReportSubView::show (const QModelIndex& index)
{
focusId (mModel->getUniversalId (index.row()), "");
mTable->updateUserSetting (name, list);
}

View file

@ -11,27 +11,15 @@ namespace CSMDoc
class Document;
}
namespace CSMTools
{
class ReportModel;
}
namespace CSVWorld
{
class CommandDelegate;
}
namespace CSVTools
{
class Table;
class ReportTable;
class ReportSubView : public CSVDoc::SubView
{
Q_OBJECT
CSMTools::ReportModel *mModel;
QTableView *mTable;
CSVWorld::CommandDelegate *mIdTypeDelegate;
ReportTable *mTable;
public:
@ -39,12 +27,7 @@ namespace CSVTools
virtual void setEditLock (bool locked);
virtual void updateUserSetting
(const QString &, const QStringList &);
private slots:
void show (const QModelIndex& index);
virtual void updateUserSetting (const QString &, const QStringList &);
};
}

View file

@ -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();
}

View file

@ -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

View file

@ -72,6 +72,11 @@ CSVWidget::PushButton::PushButton (const QIcon& icon, Type type, const QString&
QWidget *parent)
: QPushButton (icon, "", parent), mKeepOpen (false), mType (type), mToolTip (tooltip)
{
if (type==Type_Mode || type==Type_Toggle)
{
setCheckable (true);
connect (this, SIGNAL (toggled (bool)), this, SLOT (checkedStateChanged (bool)));
}
setCheckable (type==Type_Mode || type==Type_Toggle);
setExtendedToolTip();
}
@ -96,4 +101,9 @@ QString CSVWidget::PushButton::getBaseToolTip() const
CSVWidget::PushButton::Type CSVWidget::PushButton::getType() const
{
return mType;
}
void CSVWidget::PushButton::checkedStateChanged (bool checked)
{
setExtendedToolTip();
}

View file

@ -53,6 +53,10 @@ namespace CSVWidget
QString getBaseToolTip() const;
Type getType() const;
private slots:
void checkedStateChanged (bool checked);
};
}

View file

@ -26,7 +26,7 @@ void CSVWidget::SceneToolRun::adjustToolTips()
void CSVWidget::SceneToolRun::updateIcon()
{
setIcon (QIcon (mSelected==mProfiles.end() ? mIconDisabled : mIcon));
setDisabled (mSelected==mProfiles.end());
}
void CSVWidget::SceneToolRun::updatePanel()
@ -46,11 +46,11 @@ void CSVWidget::SceneToolRun::updatePanel()
}
CSVWidget::SceneToolRun::SceneToolRun (SceneToolbar *parent, const QString& toolTip,
const QString& icon, const QString& iconDisabled, const std::vector<std::string>& profiles)
const QString& icon, const std::vector<std::string>& profiles)
: SceneTool (parent, Type_TopAction), mProfiles (profiles.begin(), profiles.end()),
mSelected (mProfiles.begin()), mToolTip (toolTip), mIcon (icon),
mIconDisabled (iconDisabled)
mSelected (mProfiles.begin()), mToolTip (toolTip)
{
setIcon (QIcon (icon));
updateIcon();
adjustToolTips();

View file

@ -19,8 +19,6 @@ namespace CSVWidget
std::set<std::string> mProfiles;
std::set<std::string>::iterator mSelected;
QString mToolTip;
QString mIcon;
QString mIconDisabled;
QFrame *mPanel;
QTableWidget *mTable;
@ -35,7 +33,7 @@ namespace CSVWidget
public:
SceneToolRun (SceneToolbar *parent, const QString& toolTip, const QString& icon,
const QString& iconDisabled, const std::vector<std::string>& profiles);
const std::vector<std::string>& profiles);
virtual void showPanel (const QPoint& position);

View file

@ -0,0 +1,142 @@
#include "scenetooltoggle2.hpp"
#include <stdexcept>
#include <sstream>
#include <QHBoxLayout>
#include <QFrame>
#include <QIcon>
#include <QPainter>
#include "scenetoolbar.hpp"
#include "pushbutton.hpp"
void CSVWidget::SceneToolToggle2::adjustToolTip()
{
QString toolTip = mToolTip;
toolTip += "<p>Currently enabled: ";
bool first = true;
for (std::map<PushButton *, ButtonDesc>::const_iterator iter (mButtons.begin());
iter!=mButtons.end(); ++iter)
if (iter->first->isChecked())
{
if (!first)
toolTip += ", ";
else
first = false;
toolTip += iter->second.mName;
}
if (first)
toolTip += "none";
toolTip += "<p>(left click to alter selection)";
setToolTip (toolTip);
}
void CSVWidget::SceneToolToggle2::adjustIcon()
{
std::ostringstream stream;
stream << mCompositeIcon << getSelection();
setIcon (QIcon (QString::fromUtf8 (stream.str().c_str())));
}
CSVWidget::SceneToolToggle2::SceneToolToggle2 (SceneToolbar *parent, const QString& toolTip,
const std::string& compositeIcon, const std::string& singleIcon)
: SceneTool (parent), mCompositeIcon (compositeIcon), mSingleIcon (singleIcon),
mButtonSize (parent->getButtonSize()), mIconSize (parent->getIconSize()), mToolTip (toolTip),
mFirst (0)
{
mPanel = new QFrame (this, Qt::Popup);
mLayout = new QHBoxLayout (mPanel);
mLayout->setContentsMargins (QMargins (0, 0, 0, 0));
mPanel->setLayout (mLayout);
}
void CSVWidget::SceneToolToggle2::showPanel (const QPoint& position)
{
mPanel->move (position);
mPanel->show();
if (mFirst)
mFirst->setFocus (Qt::OtherFocusReason);
}
void CSVWidget::SceneToolToggle2::addButton (unsigned int id,
const QString& name, const QString& tooltip, bool disabled)
{
std::ostringstream stream;
stream << mSingleIcon << id;
PushButton *button = new PushButton (QIcon (QPixmap (stream.str().c_str())),
PushButton::Type_Toggle, tooltip.isEmpty() ? name: tooltip, mPanel);
button->setSizePolicy (QSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed));
button->setIconSize (QSize (mIconSize, mIconSize));
button->setFixedSize (mButtonSize, mButtonSize);
if (disabled)
button->setDisabled (true);
mLayout->addWidget (button);
ButtonDesc desc;
desc.mId = id;
desc.mName = name;
desc.mIndex = mButtons.size();
mButtons.insert (std::make_pair (button, desc));
connect (button, SIGNAL (clicked()), this, SLOT (selected()));
if (mButtons.size()==1 && !disabled)
mFirst = button;
}
unsigned int CSVWidget::SceneToolToggle2::getSelection() const
{
unsigned int selection = 0;
for (std::map<PushButton *, ButtonDesc>::const_iterator iter (mButtons.begin());
iter!=mButtons.end(); ++iter)
if (iter->first->isChecked())
selection |= iter->second.mId;
return selection;
}
void CSVWidget::SceneToolToggle2::setSelection (unsigned int selection)
{
for (std::map<PushButton *, ButtonDesc>::iterator iter (mButtons.begin());
iter!=mButtons.end(); ++iter)
iter->first->setChecked (selection & iter->second.mId);
adjustToolTip();
adjustIcon();
}
void CSVWidget::SceneToolToggle2::selected()
{
std::map<PushButton *, ButtonDesc>::const_iterator iter =
mButtons.find (dynamic_cast<PushButton *> (sender()));
if (iter!=mButtons.end())
{
if (!iter->first->hasKeepOpen())
mPanel->hide();
adjustToolTip();
adjustIcon();
emit selectionChanged();
}
}

View file

@ -0,0 +1,76 @@
#ifndef CSV_WIDGET_SCENETOOL_TOGGLE2_H
#define CSV_WIDGET_SCENETOOL_TOGGLE2_H
#include "scenetool.hpp"
#include <map>
class QHBoxLayout;
class QRect;
namespace CSVWidget
{
class SceneToolbar;
class PushButton;
///< \brief Multi-Toggle tool
///
/// Top level button is using predefined icons instead building a composite icon.
class SceneToolToggle2 : public SceneTool
{
Q_OBJECT
struct ButtonDesc
{
unsigned int mId;
QString mName;
int mIndex;
};
std::string mCompositeIcon;
std::string mSingleIcon;
QWidget *mPanel;
QHBoxLayout *mLayout;
std::map<PushButton *, ButtonDesc> mButtons; // widget, id
int mButtonSize;
int mIconSize;
QString mToolTip;
PushButton *mFirst;
void adjustToolTip();
void adjustIcon();
public:
/// The top level icon is compositeIcon + sum of bitpatterns for active buttons (in
/// decimal)
///
/// The icon for individual toggle buttons is signleIcon + bitmask for button (in
/// decimal)
SceneToolToggle2 (SceneToolbar *parent, const QString& toolTip,
const std::string& compositeIcon, const std::string& singleIcon);
virtual void showPanel (const QPoint& position);
/// \attention After the last button has been added, setSelection must be called at
/// least once to finalise the layout.
void addButton (unsigned int id,
const QString& name, const QString& tooltip = "", bool disabled = false);
unsigned int getSelection() const;
/// \param or'ed button IDs. IDs that do not exist will be ignored.
void setSelection (unsigned int selection);
signals:
void selectionChanged();
private slots:
void selected();
};
}
#endif

View file

@ -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;
}
}
}
}
}

View file

@ -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

View file

@ -20,6 +20,7 @@
#include "../widget/scenetoolbar.hpp"
#include "../widget/scenetoolmode.hpp"
#include "../widget/scenetooltoggle.hpp"
#include "../widget/scenetooltoggle2.hpp"
#include "../widget/scenetoolrun.hpp"
#include "tablebottombox.hpp"
@ -109,7 +110,7 @@ CSVWidget::SceneToolbar* CSVWorld::SceneSubView::makeToolbar (CSVRender::Worldsp
CSVWidget::SceneToolMode *lightingTool = widget->makeLightingSelector (toolbar);
toolbar->addTool (lightingTool);
CSVWidget::SceneToolToggle *sceneVisibilityTool =
CSVWidget::SceneToolToggle2 *sceneVisibilityTool =
widget->makeSceneVisibilitySelector (toolbar);
toolbar->addTool (sceneVisibilityTool);

View file

@ -47,6 +47,32 @@ void CSVWorld::ScriptSubView::setEditLock (bool locked)
mEditor->setReadOnly (locked);
}
void CSVWorld::ScriptSubView::useHint (const std::string& hint)
{
if (hint.empty())
return;
if (hint[0]=='l')
{
std::istringstream stream (hint.c_str()+1);
char ignore;
int line;
int column;
if (stream >> ignore >> line >> column)
{
QTextCursor cursor = mEditor->textCursor();
cursor.movePosition (QTextCursor::Start);
if (cursor.movePosition (QTextCursor::Down, QTextCursor::MoveAnchor, line))
cursor.movePosition (QTextCursor::Right, QTextCursor::MoveAnchor, column);
mEditor->setTextCursor (cursor);
}
}
}
void CSVWorld::ScriptSubView::textChanged()
{
if (mEditor->isChangeLocked())

View file

@ -34,6 +34,8 @@ namespace CSVWorld
virtual void setEditLock (bool locked);
virtual void useHint (const std::string& hint);
public slots:
void textChanged();

View file

@ -2,6 +2,8 @@
#include "util.hpp"
#include <stdexcept>
#include <climits>
#include <cfloat>
#include <QUndoStack>
#include <QMetaProperty>
@ -157,16 +159,24 @@ QWidget *CSVWorld::CommandDelegate::createEditor (QWidget *parent, const QStyleO
return new QLineEdit(parent);
case CSMWorld::ColumnBase::Display_Integer:
return new QSpinBox(parent);
{
QSpinBox *sb = new QSpinBox(parent);
sb->setRange(INT_MIN, INT_MAX);
return sb;
}
case CSMWorld::ColumnBase::Display_Var:
return new QLineEdit(parent);
case CSMWorld::ColumnBase::Display_Float:
return new QDoubleSpinBox(parent);
{
QDoubleSpinBox *dsb = new QDoubleSpinBox(parent);
dsb->setRange(FLT_MIN, FLT_MAX);
dsb->setSingleStep(0.01f);
dsb->setDecimals(3);
return dsb;
}
case CSMWorld::ColumnBase::Display_LongString:
{

View file

@ -79,8 +79,7 @@ bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt)
{
try
{
float frametime = std::min(evt.timeSinceLastFrame, 0.2f);
float frametime = evt.timeSinceLastFrame;
mEnvironment.setFrameDuration (frametime);
// update input
@ -478,9 +477,15 @@ void OMW::Engine::go()
}
// Start the main rendering loop
Ogre::Timer timer;
while (!MWBase::Environment::get().getStateManager()->hasQuitRequest())
Ogre::Root::getSingleton().renderOneFrame();
{
float dt = timer.getMilliseconds()/1000.f;
dt = std::min(dt, 0.2f);
timer.reset();
Ogre::Root::getSingleton().renderOneFrame(dt);
}
// Save user settings
settings.saveUser(settingspath);

View file

@ -330,11 +330,11 @@ namespace MWBase
virtual void pinWindow (MWGui::GuiWindow window) = 0;
/// Fade the screen in, over \a time seconds
virtual void fadeScreenIn(const float time) = 0;
virtual void fadeScreenIn(const float time, bool clearQueue=true) = 0;
/// Fade the screen out to black, over \a time seconds
virtual void fadeScreenOut(const float time) = 0;
virtual void fadeScreenOut(const float time, bool clearQueue=true) = 0;
/// Fade the screen to a specified percentage of black, over \a time seconds
virtual void fadeScreenTo(const int percent, const float time) = 0;
virtual void fadeScreenTo(const int percent, const float time, bool clearQueue=true) = 0;
/// Darken the screen to a specified percentage
virtual void setBlindness(const int percent) = 0;

View file

@ -279,6 +279,7 @@ namespace MWBase
///< Attempt to fix position so that the Ptr is no longer inside collision geometry.
virtual void deleteObject (const MWWorld::Ptr& ptr) = 0;
virtual void undeleteObject (const MWWorld::Ptr& ptr) = 0;
virtual void moveObject (const MWWorld::Ptr& ptr, float x, float y, float z) = 0;

View file

@ -7,6 +7,7 @@
#include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp"
#include "../mwbase/windowmanager.hpp"
#include "../mwbase/mechanicsmanager.hpp"
#include "../mwworld/ptr.hpp"
#include "../mwworld/failedaction.hpp"
@ -21,7 +22,7 @@
#include "../mwgui/tooltips.hpp"
#include "../mwrender/objects.hpp"
#include "../mwrender/actors.hpp"
#include "../mwrender/renderinginterface.hpp"
#include "../mwmechanics/npcstats.hpp"
@ -87,7 +88,8 @@ namespace MWClass
{
const std::string model = getModel(ptr);
if (!model.empty()) {
renderingInterface.getObjects().insertModel(ptr, model);
MWRender::Actors& actors = renderingInterface.getActors();
actors.insertActivator(ptr);
}
}
@ -96,6 +98,7 @@ namespace MWClass
const std::string model = getModel(ptr);
if(!model.empty())
physics.addObject(ptr);
MWBase::Environment::get().getMechanicsManager()->add(ptr);
}
std::string Container::getModel(const MWWorld::Ptr &ptr) const

View file

@ -969,6 +969,9 @@ namespace MWClass
float Npc::getJump(const MWWorld::Ptr &ptr) const
{
if(getEncumbrance(ptr) > getCapacity(ptr))
return 0.f;
const NpcCustomData *npcdata = static_cast<const NpcCustomData*>(ptr.getRefData().getCustomData());
const GMST& gmst = getGmst();
const MWMechanics::MagicEffects &mageffects = npcdata->mNpcStats.getMagicEffects();

View file

@ -533,9 +533,11 @@ namespace MWGui
if (mGoodbye)
{
Goodbye* link = new Goodbye();
mLinks.push_back(link);
std::string goodbye = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("sGoodbye")->getString();
BookTypesetter::Style* questionStyle = typesetter->createHotStyle(body, linkNormal, linkHot, linkActive,
TypesetBook::InteractiveId(mLinks.back()));
TypesetBook::InteractiveId(link));
typesetter->lineBreak();
typesetter->write(questionStyle, to_utf8_span(goodbye.c_str()));
}
@ -654,7 +656,6 @@ namespace MWGui
void DialogueWindow::goodbye()
{
mLinks.push_back(new Goodbye());
mGoodbye = true;
mEnabled = false;
updateHistory();

View file

@ -128,11 +128,17 @@ namespace MWGui
setRaceId(proto.mRace);
recountParts();
std::string index = proto.mHead.substr(proto.mHead.size() - 2, 2);
mFaceIndex = boost::lexical_cast<int>(index) - 1;
for (unsigned int i=0; i<mAvailableHeads.size(); ++i)
{
if (mAvailableHeads[i] == proto.mHead)
mFaceIndex = i;
}
index = proto.mHair.substr(proto.mHair.size() - 2, 2);
mHairIndex = boost::lexical_cast<int>(index) - 1;
for (unsigned int i=0; i<mAvailableHairs.size(); ++i)
{
if (mAvailableHairs[i] == proto.mHair)
mHairIndex = i;
}
mPreviewImage->setImageTexture (textureName);
@ -162,6 +168,9 @@ namespace MWGui
void RaceDialog::close()
{
mPreviewImage->setImageTexture("");
const std::string textureName = "CharacterHeadPreview";
MyGUI::RenderManager::getInstance().destroyTexture(MyGUI::RenderManager::getInstance().getTexture(textureName));
mPreview.reset(NULL);
}
@ -304,7 +313,15 @@ namespace MWGui
record.mHead = mAvailableHeads[mFaceIndex];
record.mHair = mAvailableHairs[mHairIndex];
mPreview->setPrototype(record);
try
{
mPreview->setPrototype(record);
}
catch (std::exception& e)
{
std::cerr << "Error creating preview: " << e.what() << std::endl;
}
mPreviewDirty = true;
}

View file

@ -9,6 +9,8 @@
#include <SDL_video.h>
#include <components/widgets/sharedstatebutton.hpp>
#include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp"
#include "../mwbase/soundmanager.hpp"
@ -454,16 +456,21 @@ namespace MWGui
std::string binding = MWBase::Environment::get().getInputManager()->getActionBindingName (*it);
MyGUI::TextBox* leftText = mControlsBox->createWidget<MyGUI::TextBox>("SandText", MyGUI::IntCoord(0,curH,w,h), MyGUI::Align::Default);
Gui::SharedStateButton* leftText = mControlsBox->createWidget<Gui::SharedStateButton>("SandTextButton", MyGUI::IntCoord(0,curH,w,h), MyGUI::Align::Default);
leftText->setCaptionWithReplacing(desc);
MyGUI::Button* rightText = mControlsBox->createWidget<MyGUI::Button>("SandTextButton", MyGUI::IntCoord(0,curH,w,h), MyGUI::Align::Default);
Gui::SharedStateButton* rightText = mControlsBox->createWidget<Gui::SharedStateButton>("SandTextButton", MyGUI::IntCoord(0,curH,w,h), MyGUI::Align::Default);
rightText->setCaptionWithReplacing(binding);
rightText->setTextAlign (MyGUI::Align::Right);
rightText->setUserData(*it); // save the action id for callbacks
rightText->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsWindow::onRebindAction);
rightText->eventMouseWheel += MyGUI::newDelegate(this, &SettingsWindow::onInputTabMouseWheel);
curH += h;
Gui::ButtonGroup group;
group.push_back(leftText);
group.push_back(rightText);
Gui::SharedStateButton::createButtonGroup(group);
}
// Canvas size must be expressed with VScroll disabled, otherwise MyGUI would expand the scroll area when the scrollbar is hidden

View file

@ -3,6 +3,8 @@
#include <boost/lexical_cast.hpp>
#include <boost/format.hpp>
#include <components/widgets/sharedstatebutton.hpp>
#include "../mwbase/windowmanager.hpp"
#include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp"
@ -177,7 +179,7 @@ namespace MWGui
for (std::vector<std::string>::const_iterator it = spellList.begin(); it != spellList.end(); ++it)
{
const ESM::Spell* spell = esmStore.get<ESM::Spell>().find(*it);
MyGUI::Button* t = mSpellView->createWidget<MyGUI::Button>("SandTextButton",
Gui::SharedStateButton* t = mSpellView->createWidget<Gui::SharedStateButton>("SandTextButton",
MyGUI::IntCoord(4, mHeight, mWidth-8, spellHeight), MyGUI::Align::Left | MyGUI::Align::Top);
t->setCaption(spell->mName);
t->setTextAlign(MyGUI::Align::Left);
@ -185,20 +187,28 @@ namespace MWGui
t->setUserString("Spell", *it);
t->eventMouseWheel += MyGUI::newDelegate(this, &SpellWindow::onMouseWheel);
t->eventMouseButtonClick += MyGUI::newDelegate(this, &SpellWindow::onSpellSelected);
t->setStateSelected(*it == MWBase::Environment::get().getWindowManager()->getSelectedSpell());
// cost / success chance
MyGUI::Button* costChance = mSpellView->createWidget<MyGUI::Button>("SandTextButton",
Gui::SharedStateButton* costChance = mSpellView->createWidget<Gui::SharedStateButton>("SandTextButton",
MyGUI::IntCoord(4, mHeight, mWidth-8, spellHeight), MyGUI::Align::Left | MyGUI::Align::Top);
std::string cost = boost::lexical_cast<std::string>(spell->mData.mCost);
std::string chance = boost::lexical_cast<std::string>(int(MWMechanics::getSpellSuccessChance(*it, player)));
costChance->setCaption(cost + "/" + chance);
costChance->setTextAlign(MyGUI::Align::Right);
costChance->setNeedMouseFocus(false);
costChance->setStateSelected(*it == MWBase::Environment::get().getWindowManager()->getSelectedSpell());
costChance->setUserString("ToolTipType", "Spell");
costChance->setUserString("Spell", *it);
costChance->eventMouseWheel += MyGUI::newDelegate(this, &SpellWindow::onMouseWheel);
costChance->eventMouseButtonClick += MyGUI::newDelegate(this, &SpellWindow::onSpellSelected);
t->setSize(mWidth-12-costChance->getTextSize().width, t->getHeight());
Gui::ButtonGroup group;
group.push_back(t);
group.push_back(costChance);
Gui::SharedStateButton::createButtonGroup(group);
t->setStateSelected(*it == MWBase::Environment::get().getWindowManager()->getSelectedSpell());
mHeight += spellHeight;
}
@ -224,7 +234,7 @@ namespace MWGui
}
}
MyGUI::Button* t = mSpellView->createWidget<MyGUI::Button>(equipped ? "SandTextButton" : "SpellTextUnequipped",
Gui::SharedStateButton* t = mSpellView->createWidget<Gui::SharedStateButton>(equipped ? "SandTextButton" : "SpellTextUnequipped",
MyGUI::IntCoord(4, mHeight, mWidth-8, spellHeight), MyGUI::Align::Left | MyGUI::Align::Top);
t->setCaption(item.getClass().getName(item));
t->setTextAlign(MyGUI::Align::Left);
@ -233,12 +243,9 @@ namespace MWGui
t->setUserString("Equipped", equipped ? "true" : "false");
t->eventMouseButtonClick += MyGUI::newDelegate(this, &SpellWindow::onEnchantedItemSelected);
t->eventMouseWheel += MyGUI::newDelegate(this, &SpellWindow::onMouseWheel);
if (store.getSelectedEnchantItem() != store.end())
t->setStateSelected(item == *store.getSelectedEnchantItem());
// cost / charge
MyGUI::Button* costCharge = mSpellView->createWidget<MyGUI::Button>(equipped ? "SandTextButton" : "SpellTextUnequipped",
Gui::SharedStateButton* costCharge = mSpellView->createWidget<Gui::SharedStateButton>(equipped ? "SandTextButton" : "SpellTextUnequipped",
MyGUI::IntCoord(4, mHeight, mWidth-8, spellHeight), MyGUI::Align::Left | MyGUI::Align::Top);
float enchantCost = enchant->mData.mCost;
@ -257,11 +264,22 @@ namespace MWGui
charge = "100";
}
costCharge->setUserData(item);
costCharge->setUserString("ToolTipType", "ItemPtr");
costCharge->setUserString("Equipped", equipped ? "true" : "false");
costCharge->eventMouseButtonClick += MyGUI::newDelegate(this, &SpellWindow::onEnchantedItemSelected);
costCharge->eventMouseWheel += MyGUI::newDelegate(this, &SpellWindow::onMouseWheel);
costCharge->setCaption(cost + "/" + charge);
costCharge->setTextAlign(MyGUI::Align::Right);
costCharge->setNeedMouseFocus(false);
Gui::ButtonGroup group;
group.push_back(t);
group.push_back(costCharge);
Gui::SharedStateButton::createButtonGroup(group);
if (store.getSelectedEnchantItem() != store.end())
costCharge->setStateSelected(item == *store.getSelectedEnchantItem());
t->setStateSelected(item == *store.getSelectedEnchantItem());
t->setSize(mWidth-12-costCharge->getTextSize().width, t->getHeight());

View file

@ -633,8 +633,8 @@ namespace MWGui
MWWorld::Store<ESM::Skill>::iterator it = skills.begin();
for (; it != skills.end(); ++it)
{
if (it->mData.mSpecialization == specId)
specText += std::string("\n#{") + ESM::Skill::sSkillNameIds[it->mIndex] + "}";
if (it->second.mData.mSpecialization == specId)
specText += std::string("\n#{") + ESM::Skill::sSkillNameIds[it->first] + "}";
}
widget->setUserString("Caption_CenteredCaptionText", specText);
widget->setUserString("ToolTipLayout", "TextWithCenteredCaptionToolTip");

View file

@ -1748,21 +1748,24 @@ namespace MWGui
updateVisible();
}
void WindowManager::fadeScreenIn(const float time)
void WindowManager::fadeScreenIn(const float time, bool clearQueue)
{
mScreenFader->clearQueue();
if (clearQueue)
mScreenFader->clearQueue();
mScreenFader->fadeOut(time);
}
void WindowManager::fadeScreenOut(const float time)
void WindowManager::fadeScreenOut(const float time, bool clearQueue)
{
mScreenFader->clearQueue();
if (clearQueue)
mScreenFader->clearQueue();
mScreenFader->fadeIn(time);
}
void WindowManager::fadeScreenTo(const int percent, const float time)
void WindowManager::fadeScreenTo(const int percent, const float time, bool clearQueue)
{
mScreenFader->clearQueue();
if (clearQueue)
mScreenFader->clearQueue();
mScreenFader->fadeTo(percent, time);
}

View file

@ -325,11 +325,11 @@ namespace MWGui
virtual void pinWindow (MWGui::GuiWindow window);
/// Fade the screen in, over \a time seconds
virtual void fadeScreenIn(const float time);
virtual void fadeScreenIn(const float time, bool clearQueue);
/// Fade the screen out to black, over \a time seconds
virtual void fadeScreenOut(const float time);
virtual void fadeScreenOut(const float time, bool clearQueue);
/// Fade the screen to a specified percentage of black, over \a time seconds
virtual void fadeScreenTo(const int percent, const float time);
virtual void fadeScreenTo(const int percent, const float time, bool clearQueue);
/// Darken the screen to a specified percentage
virtual void setBlindness(const int percent);

View file

@ -190,14 +190,12 @@ namespace MWInput
int action = channel->getNumber();
if (action == A_Use)
if (mControlSwitch["playercontrols"])
{
mPlayer->getPlayer().getClass().getCreatureStats(mPlayer->getPlayer()).setAttackingOrSpell(currentValue);
}
if (action == A_Jump)
{
mAttemptJump = (currentValue == 1.0 && previousValue == 0.0);
if (action == A_Use)
mPlayer->getPlayer().getClass().getCreatureStats(mPlayer->getPlayer()).setAttackingOrSpell(currentValue);
else if (action == A_Jump)
mAttemptJump = (currentValue == 1.0 && previousValue == 0.0);
}
if (currentValue == 1)
@ -373,6 +371,7 @@ namespace MWInput
{
mPlayer->setUpDown (1);
triedToMove = true;
mOverencumberedMessageDelay = 0.f;
}
if (mAlwaysRunActive)
@ -603,7 +602,7 @@ namespace MWInput
MyGUI::InputManager::getInstance().injectMouseMove( int(mMouseX), int(mMouseY), mMouseWheel);
}
if (mMouseLookEnabled)
if (mMouseLookEnabled && !mControlsDisabled)
{
resetIdleTime();
@ -622,10 +621,12 @@ namespace MWInput
mPlayer->pitch(y);
}
if (arg.zrel && mControlSwitch["playerviewswitch"]) //Check to make sure you are allowed to zoomout and there is a change
if (arg.zrel && mControlSwitch["playerviewswitch"] && mControlSwitch["playercontrols"]) //Check to make sure you are allowed to zoomout and there is a change
{
MWBase::Environment::get().getWorld()->changeVanityModeScale(arg.zrel);
MWBase::Environment::get().getWorld()->setCameraDistance(arg.zrel, true, true);
if (Settings::Manager::getBool("allow third person zoom", "Input"))
MWBase::Environment::get().getWorld()->setCameraDistance(arg.zrel, true, true);
}
}
}
@ -680,7 +681,7 @@ namespace MWInput
if (MWBase::Environment::get().getWindowManager()->isGuiMode()) return;
// Not allowed before the magic window is accessible
if (!mControlSwitch["playermagic"])
if (!mControlSwitch["playermagic"] || !mControlSwitch["playercontrols"])
return;
// Not allowed if no spell selected
@ -701,7 +702,7 @@ namespace MWInput
if (MWBase::Environment::get().getWindowManager()->isGuiMode()) return;
// Not allowed before the inventory window is accessible
if (!mControlSwitch["playerfighting"])
if (!mControlSwitch["playerfighting"] || !mControlSwitch["playercontrols"])
return;
MWMechanics::DrawState_ state = mPlayer->getDrawState();
@ -713,6 +714,9 @@ namespace MWInput
void InputManager::rest()
{
if (!mControlSwitch["playercontrols"])
return;
if (!MWBase::Environment::get().getWindowManager()->getRestEnabled () || MWBase::Environment::get().getWindowManager()->isGuiMode ())
return;
@ -734,6 +738,9 @@ namespace MWInput
void InputManager::toggleInventory()
{
if (!mControlSwitch["playercontrols"])
return;
if (MyGUI::InputManager::getInstance ().isModalAny())
return;
@ -770,6 +777,8 @@ namespace MWInput
void InputManager::toggleJournal()
{
if (!mControlSwitch["playercontrols"])
return;
if (MyGUI::InputManager::getInstance ().isModalAny())
return;
@ -787,6 +796,8 @@ namespace MWInput
void InputManager::quickKey (int index)
{
if (!mControlSwitch["playercontrols"])
return;
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr();
if (player.getClass().getNpcStats(player).isWerewolf())
{

View file

@ -17,18 +17,35 @@ namespace MWMechanics
MWWorld::TimeStamp now = MWBase::Environment::get().getWorld()->getTimeStamp();
// Erase no longer active spells
// Erase no longer active spells and effects
if (mLastUpdate!=now)
{
TContainer::iterator iter (mSpells.begin());
while (iter!=mSpells.end())
{
if (!timeToExpire (iter))
{
mSpells.erase (iter++);
rebuild = true;
}
else
{
std::vector<ActiveEffect>& effects = iter->second.mEffects;
for (std::vector<ActiveEffect>::iterator effectIt = effects.begin(); effectIt != effects.end();)
{
MWWorld::TimeStamp start = iter->second.mTimeStamp;
MWWorld::TimeStamp end = start + static_cast<double>(effectIt->mDuration)*MWBase::Environment::get().getWorld()->getTimeScaleFactor()/(60*60);
if (end <= now)
{
effectIt = effects.erase(effectIt);
rebuild = true;
}
else
++effectIt;
}
++iter;
}
}
mLastUpdate = now;
}

View file

@ -396,11 +396,7 @@ namespace MWMechanics
{
CreatureStats& creatureStats = ptr.getClass().getCreatureStats (ptr);
int strength = creatureStats.getAttribute(ESM::Attribute::Strength).getModified();
int intelligence = creatureStats.getAttribute(ESM::Attribute::Intelligence).getModified();
int willpower = creatureStats.getAttribute(ESM::Attribute::Willpower).getModified();
int agility = creatureStats.getAttribute(ESM::Attribute::Agility).getModified();
int endurance = creatureStats.getAttribute(ESM::Attribute::Endurance).getModified();
float base = 1.f;
if (ptr.getCellRef().getRefId() == "player")
@ -415,11 +411,6 @@ namespace MWMechanics
float diff = (static_cast<int>(magickaFactor*intelligence)) - magicka.getBase();
magicka.modify(diff);
creatureStats.setMagicka(magicka);
DynamicStat<float> fatigue = creatureStats.getFatigue();
diff = (strength+willpower+agility+endurance) - fatigue.getBase();
fatigue.modify(diff);
creatureStats.setFatigue(fatigue);
}
void Actors::restoreDynamicStats (const MWWorld::Ptr& ptr, bool sleep)

View file

@ -325,6 +325,11 @@ namespace MWMechanics
currentAction = prepareNextAction(actor, target);
actionCooldown = currentAction->getActionCooldown();
}
// Stop attacking if target is not seen
if (!MWBase::Environment::get().getMechanicsManager()->awarenessCheck(target, actor))
return true;
if (currentAction.get())
currentAction->getCombatRange(rangeAttack, rangeFollow);

View file

@ -9,6 +9,7 @@
#include "../mwworld/actionequip.hpp"
#include "../mwmechanics/npcstats.hpp"
#include "../mwmechanics/spellcasting.hpp"
#include <components/esm/loadench.hpp>
#include <components/esm/loadmgef.hpp>
@ -166,6 +167,9 @@ namespace MWMechanics
{
const CreatureStats& stats = actor.getClass().getCreatureStats(actor);
if (MWMechanics::getSpellSuccessChance(spell, actor) == 0)
return 0.f;
if (spell->mData.mType != ESM::Spell::ST_Spell)
return 0.f;

View file

@ -69,6 +69,7 @@ namespace MWMechanics
/** \return If the actor has arrived at his destination **/
bool pathTo(const MWWorld::Ptr& actor, ESM::Pathgrid::Point dest, float duration);
// TODO: all this does not belong here, move into temporary storage
PathFinder mPathFinder;
ObstacleCheck mObstacleCheck;

View file

@ -57,6 +57,8 @@ namespace MWMechanics
bool mWalking;
unsigned short mPlayedIdle;
PathFinder mPathFinder;
AiWanderStorage():
mTargetAngle(0),
@ -211,9 +213,9 @@ namespace MWMechanics
// Are we there yet?
bool& chooseAction = storage.mChooseAction;
if(walking &&
mPathFinder.checkPathCompleted(pos.pos[0], pos.pos[1], pos.pos[2]))
storage.mPathFinder.checkPathCompleted(pos.pos[0], pos.pos[1], pos.pos[2]))
{
stopWalking(actor);
stopWalking(actor, storage);
moveNow = false;
walking = false;
chooseAction = true;
@ -225,7 +227,7 @@ namespace MWMechanics
if(walking) // have not yet reached the destination
{
// turn towards the next point in mPath
zTurn(actor, Ogre::Degree(mPathFinder.getZAngleToNext(pos.pos[0], pos.pos[1])));
zTurn(actor, Ogre::Degree(storage.mPathFinder.getZAngleToNext(pos.pos[0], pos.pos[1])));
actor.getClass().getMovementSettings(actor).mPosition[1] = 1;
// Returns true if evasive action needs to be taken
@ -236,9 +238,9 @@ namespace MWMechanics
{
// remove allowed points then select another random destination
mTrimCurrentNode = true;
trimAllowedNodes(mAllowedNodes, mPathFinder);
trimAllowedNodes(mAllowedNodes, storage.mPathFinder);
mObstacleCheck.clear();
mPathFinder.clearPath();
storage.mPathFinder.clearPath();
walking = false;
moveNow = true;
}
@ -249,7 +251,7 @@ namespace MWMechanics
actor.getClass().getMovementSettings(actor).mPosition[0] = 1;
actor.getClass().getMovementSettings(actor).mPosition[1] = 0.1f;
// change the angle a bit, too
zTurn(actor, Ogre::Degree(mPathFinder.getZAngleToNext(pos.pos[0] + 1, pos.pos[1])));
zTurn(actor, Ogre::Degree(storage.mPathFinder.getZAngleToNext(pos.pos[0] + 1, pos.pos[1])));
}
mStuckCount++; // TODO: maybe no longer needed
}
@ -260,7 +262,7 @@ namespace MWMechanics
//std::cout << "Reset \""<< cls.getName(actor) << "\"" << std::endl;
mObstacleCheck.clear();
stopWalking(actor);
stopWalking(actor, storage);
moveNow = false;
walking = false;
chooseAction = true;
@ -280,6 +282,58 @@ namespace MWMechanics
rotate = false;
}
// Check if idle animation finished
short unsigned& playedIdle = storage.mPlayedIdle;
GreetingState& greetingState = storage.mSaidGreeting;
if(idleNow && !checkIdle(actor, playedIdle) && (greetingState == Greet_Done || greetingState == Greet_None))
{
playedIdle = 0;
idleNow = false;
chooseAction = true;
}
MWBase::World *world = MWBase::Environment::get().getWorld();
if(chooseAction)
{
playedIdle = 0;
getRandomIdle(playedIdle); // NOTE: sets mPlayedIdle with a random selection
if(!playedIdle && mDistance)
{
chooseAction = false;
moveNow = true;
}
else
{
// Play idle animation and recreate vanilla (broken?) behavior of resetting start time of AIWander:
MWWorld::TimeStamp currentTime = world->getTimeStamp();
mStartTime = currentTime;
playIdle(actor, playedIdle);
chooseAction = false;
idleNow = true;
// Play idle voiced dialogue entries randomly
int hello = cStats.getAiSetting(CreatureStats::AI_Hello).getModified();
if (hello > 0)
{
int roll = std::rand()/ (static_cast<double> (RAND_MAX) + 1) * 100; // [0, 99]
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr();
// Don't bother if the player is out of hearing range
static float fVoiceIdleOdds = MWBase::Environment::get().getWorld()->getStore()
.get<ESM::GameSetting>().find("fVoiceIdleOdds")->getFloat();
// Only say Idle voices when player is in LOS
// A bit counterintuitive, likely vanilla did this to reduce the appearance of
// voices going through walls?
if (roll < fVoiceIdleOdds && Ogre::Vector3(player.getRefData().getPosition().pos).squaredDistance(Ogre::Vector3(pos.pos)) < 1500*1500
&& MWBase::Environment::get().getWorld()->getLOS(player, actor))
MWBase::Environment::get().getDialogueManager()->say(actor, "idle");
}
}
}
float& lastReaction = storage.mReaction;
lastReaction += duration;
if(lastReaction < REACTION_INTERVAL)
@ -291,7 +345,6 @@ namespace MWMechanics
// NOTE: everything below get updated every REACTION_INTERVAL seconds
MWBase::World *world = MWBase::Environment::get().getWorld();
if(mDuration)
{
// End package if duration is complete or mid-night hits:
@ -300,7 +353,7 @@ namespace MWMechanics
{
if(!mRepeat)
{
stopWalking(actor);
stopWalking(actor, storage);
return true;
}
else
@ -310,7 +363,7 @@ namespace MWMechanics
{
if(!mRepeat)
{
stopWalking(actor);
stopWalking(actor, storage);
return true;
}
else
@ -411,7 +464,7 @@ namespace MWMechanics
chooseAction = false;
idleNow = false;
if (!mPathFinder.isPathConstructed())
if (!storage.mPathFinder.isPathConstructed())
{
Ogre::Vector3 destNodePos = mReturnPosition;
@ -427,9 +480,9 @@ namespace MWMechanics
start.mZ = pos.pos[2];
// don't take shortcuts for wandering
mPathFinder.buildPath(start, dest, actor.getCell(), false);
storage.mPathFinder.buildPath(start, dest, actor.getCell(), false);
if(mPathFinder.isPathConstructed())
if(storage.mPathFinder.isPathConstructed())
{
moveNow = false;
walking = true;
@ -437,48 +490,6 @@ namespace MWMechanics
}
}
AiWander::GreetingState& greetingState = storage.mSaidGreeting;
short unsigned& playedIdle = storage.mPlayedIdle;
if(chooseAction)
{
playedIdle = 0;
getRandomIdle(playedIdle); // NOTE: sets mPlayedIdle with a random selection
if(!playedIdle && mDistance)
{
chooseAction = false;
moveNow = true;
}
else
{
// Play idle animation and recreate vanilla (broken?) behavior of resetting start time of AIWander:
MWWorld::TimeStamp currentTime = world->getTimeStamp();
mStartTime = currentTime;
playIdle(actor, playedIdle);
chooseAction = false;
idleNow = true;
// Play idle voiced dialogue entries randomly
int hello = cStats.getAiSetting(CreatureStats::AI_Hello).getModified();
if (hello > 0)
{
int roll = std::rand()/ (static_cast<double> (RAND_MAX) + 1) * 100; // [0, 99]
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr();
// Don't bother if the player is out of hearing range
static float fVoiceIdleOdds = MWBase::Environment::get().getWorld()->getStore()
.get<ESM::GameSetting>().find("fVoiceIdleOdds")->getFloat();
// Only say Idle voices when player is in LOS
// A bit counterintuitive, likely vanilla did this to reduce the appearance of
// voices going through walls?
if (roll < fVoiceIdleOdds && Ogre::Vector3(player.getRefData().getPosition().pos).squaredDistance(Ogre::Vector3(pos.pos)) < 1500*1500
&& MWBase::Environment::get().getWorld()->getLOS(player, actor))
MWBase::Environment::get().getDialogueManager()->say(actor, "idle");
}
}
}
// Allow interrupting a walking actor to trigger a greeting
if(idleNow || walking)
{
@ -494,7 +505,7 @@ namespace MWMechanics
Ogre::Vector3 playerPos(player.getRefData().getPosition().pos);
Ogre::Vector3 actorPos(actor.getRefData().getPosition().pos);
float playerDistSqr = playerPos.squaredDistance(actorPos);
int& greetingTimer = storage.mGreetingTimer;
if (greetingState == Greet_None)
{
@ -517,7 +528,7 @@ namespace MWMechanics
if(walking)
{
stopWalking(actor);
stopWalking(actor, storage);
moveNow = false;
walking = false;
mObstacleCheck.clear();
@ -554,20 +565,12 @@ namespace MWMechanics
if (playerDistSqr >= fGreetDistanceReset*fGreetDistanceReset)
greetingState = Greet_None;
}
// Check if idle animation finished
if(!checkIdle(actor, playedIdle) && (playerDistSqr > helloDistance*helloDistance || greetingState == MWMechanics::AiWander::Greet_Done))
{
playedIdle = 0;
idleNow = false;
chooseAction = true;
}
}
if(moveNow && mDistance)
{
// Construct a new path if there isn't one
if(!mPathFinder.isPathConstructed())
if(!storage.mPathFinder.isPathConstructed())
{
assert(mAllowedNodes.size());
unsigned int randNode = (int)(rand() / ((double)RAND_MAX + 1) * mAllowedNodes.size());
@ -589,16 +592,16 @@ namespace MWMechanics
start.mZ = pos.pos[2];
// don't take shortcuts for wandering
mPathFinder.buildPath(start, dest, actor.getCell(), false);
storage.mPathFinder.buildPath(start, dest, actor.getCell(), false);
if(mPathFinder.isPathConstructed())
if(storage.mPathFinder.isPathConstructed())
{
// buildPath inserts dest in case it is not a pathgraph point
// index which is a duplicate for AiWander. However below code
// does not work since getPath() returns a copy of path not a
// reference
//if(mPathFinder.getPathSize() > 1)
//mPathFinder.getPath().pop_back();
//if(storage.mPathFinder.getPathSize() > 1)
//storage.mPathFinder.getPath().pop_back();
// Remove this node as an option and add back the previously used node (stops NPC from picking the same node):
ESM::Pathgrid::Point temp = mAllowedNodes[randNode];
@ -616,7 +619,7 @@ namespace MWMechanics
// Choose a different node and delete this one from possible nodes because it is uncreachable:
else
mAllowedNodes.erase(mAllowedNodes.begin() + randNode);
}
}
}
return false; // AiWander package not yet completed
@ -653,9 +656,9 @@ namespace MWMechanics
return TypeIdWander;
}
void AiWander::stopWalking(const MWWorld::Ptr& actor)
void AiWander::stopWalking(const MWWorld::Ptr& actor, AiWanderStorage& storage)
{
mPathFinder.clearPath();
storage.mPathFinder.clearPath();
actor.getClass().getMovementSettings(actor).mPosition[1] = 0;
}

Some files were not shown because too many files have changed in this diff Show more