1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-02-06 18:40:23 +00:00

Reorganize ESM4 MWClasses; Add tooltips that are needed for activation.

This commit is contained in:
Petr Mikheev 2023-04-10 02:42:27 +02:00
parent 4738f0ff4d
commit 16845aa38e
8 changed files with 181 additions and 139 deletions

View File

@ -90,7 +90,7 @@ add_openmw_dir (mwphysics
add_openmw_dir (mwclass add_openmw_dir (mwclass
classes activator creature npc weapon armor potion apparatus book clothing container door classes activator creature npc weapon armor potion apparatus book clothing container door
ingredient creaturelevlist itemlevlist light lockpick misc probe repair static actor bodypart ingredient creaturelevlist itemlevlist light lockpick misc probe repair static actor bodypart
light4 esm4base light4
) )
add_openmw_dir (mwmechanics add_openmw_dir (mwmechanics

View File

@ -25,6 +25,8 @@
#include "static.hpp" #include "static.hpp"
#include "weapon.hpp" #include "weapon.hpp"
#include "esm4base.hpp"
namespace MWClass namespace MWClass
{ {
void registerClasses() void registerClasses()
@ -51,18 +53,18 @@ namespace MWClass
Static::registerSelf(); Static::registerSelf();
BodyPart::registerSelf(); BodyPart::registerSelf();
ESM4Static<ESM4::Activator>::registerSelf(); ESM4Named<ESM4::Activator>::registerSelf();
ESM4Static<ESM4::Potion>::registerSelf(); ESM4Named<ESM4::Potion>::registerSelf();
ESM4Static<ESM4::Ammunition>::registerSelf(); ESM4Named<ESM4::Ammunition>::registerSelf();
ESM4Static<ESM4::Armor>::registerSelf(); ESM4Named<ESM4::Armor>::registerSelf();
ESM4Static<ESM4::Book>::registerSelf(); ESM4Named<ESM4::Book>::registerSelf();
ESM4Static<ESM4::Clothing>::registerSelf(); ESM4Named<ESM4::Clothing>::registerSelf();
ESM4Static<ESM4::Container>::registerSelf(); ESM4Named<ESM4::Container>::registerSelf();
ESM4Static<ESM4::Door>::registerSelf(); ESM4Named<ESM4::Door>::registerSelf();
ESM4Static<ESM4::Ingredient>::registerSelf(); ESM4Named<ESM4::Ingredient>::registerSelf();
ESM4Static<ESM4::MiscItem>::registerSelf(); ESM4Named<ESM4::MiscItem>::registerSelf();
ESM4Static<ESM4::Static>::registerSelf(); ESM4Static::registerSelf();
ESM4Static<ESM4::Weapon>::registerSelf(); ESM4Named<ESM4::Weapon>::registerSelf();
ESM4Light::registerSelf(); ESM4Light::registerSelf();
} }
} }

View File

@ -0,0 +1,44 @@
#include "esm4base.hpp"
#include <MyGUI_TextIterator.h>
#include <components/sceneutil/positionattitudetransform.hpp>
#include "../mwgui/tooltips.hpp"
#include "../mwgui/ustring.hpp"
#include "../mwrender/objects.hpp"
#include "../mwrender/renderinginterface.hpp"
#include "../mwrender/vismask.hpp"
#include "../mwphysics/physicssystem.hpp"
#include "../mwworld/ptr.hpp"
#include "classmodel.hpp"
namespace MWClass
{
void ESM4Impl::insertObjectRendering(
const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface)
{
if (!model.empty())
{
renderingInterface.getObjects().insertModel(ptr, model);
ptr.getRefData().getBaseNode()->setNodeMask(MWRender::Mask_Static);
}
}
void ESM4Impl::insertObjectPhysics(
const MWWorld::Ptr& ptr, const std::string& model, const osg::Quat& rotation, MWPhysics::PhysicsSystem& physics)
{
physics.addObject(ptr, model, rotation, MWPhysics::CollisionType_World);
}
MWGui::ToolTipInfo ESM4Impl::getToolTipInfo(std::string_view name, int count)
{
MWGui::ToolTipInfo info;
info.caption
= MyGUI::TextIterator::toTagsString(MWGui::toUString(name)) + MWGui::ToolTips::getCountString(count);
return info;
}
}

View File

@ -0,0 +1,112 @@
#ifndef GAME_MWCLASS_ESM4BASE_H
#define GAME_MWCLASS_ESM4BASE_H
#include <components/esm4/loadstat.hpp>
#include "../mwgui/tooltips.hpp"
#include "../mwworld/cellstore.hpp"
#include "../mwworld/class.hpp"
#include "../mwworld/registeredclass.hpp"
#include "classmodel.hpp"
namespace MWClass
{
namespace ESM4Impl
{
void insertObjectRendering(
const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface);
void insertObjectPhysics(const MWWorld::Ptr& ptr, const std::string& model, const osg::Quat& rotation,
MWPhysics::PhysicsSystem& physics);
MWGui::ToolTipInfo getToolTipInfo(std::string_view name, int count);
}
// Base for all ESM4 Classes
template <typename Record>
class ESM4Base : public MWWorld::Class
{
MWWorld::Ptr copyToCellImpl(const MWWorld::ConstPtr& ptr, MWWorld::CellStore& cell) const override
{
const MWWorld::LiveCellRef<Record>* ref = ptr.get<Record>();
return MWWorld::Ptr(cell.insert(ref), &cell);
}
protected:
explicit ESM4Base(unsigned type)
: MWWorld::Class(type)
{
}
public:
void insertObjectRendering(const MWWorld::Ptr& ptr, const std::string& model,
MWRender::RenderingInterface& renderingInterface) const override
{
const MWWorld::LiveCellRef<Record>* ref = ptr.get<Record>();
if (ref->mBase->mFlags & ESM4::Rec_Marker)
return;
ESM4Impl::insertObjectRendering(ptr, model, renderingInterface);
}
void insertObject(const MWWorld::Ptr& ptr, const std::string& model, const osg::Quat& rotation,
MWPhysics::PhysicsSystem& physics) const override
{
insertObjectPhysics(ptr, model, rotation, physics);
}
void insertObjectPhysics(const MWWorld::Ptr& ptr, const std::string& model, const osg::Quat& rotation,
MWPhysics::PhysicsSystem& physics) const override
{
const MWWorld::LiveCellRef<Record>* ref = ptr.get<Record>();
if (ref->mBase->mFlags & ESM4::Rec_Marker)
return;
ESM4Impl::insertObjectPhysics(ptr, model, rotation, physics);
}
bool hasToolTip(const MWWorld::ConstPtr& ptr) const override { return false; }
std::string_view getName(const MWWorld::ConstPtr& ptr) const override { return ""; }
std::string getModel(const MWWorld::ConstPtr& ptr) const override { return getClassModel<Record>(ptr); }
};
class ESM4Static final : public MWWorld::RegisteredClass<ESM4Static, ESM4Base<ESM4::Static>>
{
friend MWWorld::RegisteredClass<ESM4Static, ESM4Base<ESM4::Static>>;
ESM4Static()
: MWWorld::RegisteredClass<ESM4Static, ESM4Base<ESM4::Static>>(ESM4::Static::sRecordId)
{
}
};
// For records with `mFullName` that should be shown as a tooltip.
// All objects with a tooltip can be activated (activation can be handled in Lua).
template <typename Record>
class ESM4Named : public MWWorld::RegisteredClass<ESM4Named<Record>, ESM4Base<Record>>
{
public:
friend MWWorld::RegisteredClass<ESM4Named, ESM4Base<Record>>;
ESM4Named()
: MWWorld::RegisteredClass<ESM4Named, ESM4Base<Record>>(Record::sRecordId)
{
}
public:
bool hasToolTip(const MWWorld::ConstPtr& ptr) const override { return true; }
MWGui::ToolTipInfo getToolTipInfo(const MWWorld::ConstPtr& ptr, int count) const override
{
return ESM4Impl::getToolTipInfo(ptr.get<Record>()->mBase->mFullName, count);
}
std::string_view getName(const MWWorld::ConstPtr& ptr) const override
{
return ptr.get<Record>()->mBase->mFullName;
}
};
}
#endif // GAME_MWCLASS_ESM4BASE_H

View File

@ -12,7 +12,7 @@
namespace MWClass namespace MWClass
{ {
ESM4Light::ESM4Light() ESM4Light::ESM4Light()
: MWWorld::RegisteredClass<ESM4Light>(ESM4::Light::sRecordId) : MWWorld::RegisteredClass<ESM4Light, ESM4Base<ESM4::Light>>(ESM4::Light::sRecordId)
{ {
} }
@ -24,38 +24,4 @@ namespace MWClass
// Insert even if model is empty, so that the light is added // Insert even if model is empty, so that the light is added
renderingInterface.getObjects().insertModel(ptr, model, !(ref->mBase->mData.flags & ESM4::Light::OffDefault)); renderingInterface.getObjects().insertModel(ptr, model, !(ref->mBase->mData.flags & ESM4::Light::OffDefault));
} }
void ESM4Light::insertObject(const MWWorld::Ptr& ptr, const std::string& model, const osg::Quat& rotation,
MWPhysics::PhysicsSystem& physics) const
{
insertObjectPhysics(ptr, model, rotation, physics);
}
void ESM4Light::insertObjectPhysics(const MWWorld::Ptr& ptr, const std::string& model, const osg::Quat& rotation,
MWPhysics::PhysicsSystem& physics) const
{
physics.addObject(ptr, model, rotation, MWPhysics::CollisionType_World);
}
std::string ESM4Light::getModel(const MWWorld::ConstPtr& ptr) const
{
return getClassModel<ESM4::Light>(ptr);
}
std::string_view ESM4Light ::getName(const MWWorld::ConstPtr& ptr) const
{
return {};
}
bool ESM4Light::hasToolTip(const MWWorld::ConstPtr& ptr) const
{
return false;
}
MWWorld::Ptr ESM4Light::copyToCellImpl(const MWWorld::ConstPtr& ptr, MWWorld::CellStore& cell) const
{
const MWWorld::LiveCellRef<ESM4::Light>* ref = ptr.get<ESM4::Light>();
return MWWorld::Ptr(cell.insert(ref), &cell);
}
} }

View File

@ -1,34 +1,22 @@
#ifndef OPENW_MWCLASS_LIGHT4 #ifndef OPENW_MWCLASS_LIGHT4
#define OPENW_MWCLASS_LIGHT4 #define OPENW_MWCLASS_LIGHT4
#include "../mwworld/registeredclass.hpp" #include "../mwworld/registeredclass.hpp"
#include "esm4base.hpp"
namespace MWClass namespace MWClass
{ {
class ESM4Light : public MWWorld::RegisteredClass<ESM4Light> class ESM4Light : public MWWorld::RegisteredClass<ESM4Light, ESM4Base<ESM4::Light>>
{ {
friend MWWorld::RegisteredClass<ESM4Light>; friend MWWorld::RegisteredClass<ESM4Light, ESM4Base<ESM4::Light>>;
ESM4Light(); ESM4Light();
MWWorld::Ptr copyToCellImpl(const MWWorld::ConstPtr& ptr, MWWorld::CellStore& cell) const override;
public: public:
void insertObjectRendering(const MWWorld::Ptr& ptr, const std::string& model, void insertObjectRendering(const MWWorld::Ptr& ptr, const std::string& model,
MWRender::RenderingInterface& renderingInterface) const override; MWRender::RenderingInterface& renderingInterface) const override;
///< Add reference into a cell for rendering ///< Add reference into a cell for rendering
void insertObject(const MWWorld::Ptr& ptr, const std::string& model, const osg::Quat& rotation,
MWPhysics::PhysicsSystem& physics) const override;
void insertObjectPhysics(const MWWorld::Ptr& ptr, const std::string& model, const osg::Quat& rotation,
MWPhysics::PhysicsSystem& physics) const override;
std::string_view getName(const MWWorld::ConstPtr& ptr) const override;
///< \return name or ID; can return an empty string.
bool hasToolTip(const MWWorld::ConstPtr& ptr) const override;
///< @return true if this object has a tooltip when focused (default implementation: true)
std::string getModel(const MWWorld::ConstPtr& ptr) const override;
}; };
} }
#endif #endif

View File

@ -64,20 +64,4 @@ namespace MWClass
return MWWorld::Ptr(cell.insert(ref), &cell); return MWWorld::Ptr(cell.insert(ref), &cell);
} }
void ESM4StaticImpl::insertObjectRendering(
const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface)
{
if (!model.empty())
{
renderingInterface.getObjects().insertModel(ptr, model);
ptr.getRefData().getBaseNode()->setNodeMask(MWRender::Mask_Static);
}
}
void ESM4StaticImpl::insertObjectPhysics(
const MWWorld::Ptr& ptr, const std::string& model, const osg::Quat& rotation, MWPhysics::PhysicsSystem& physics)
{
physics.addObject(ptr, model, rotation, MWPhysics::CollisionType_World);
}
} }

View File

@ -1,11 +1,15 @@
#ifndef GAME_MWCLASS_STATIC_H #ifndef GAME_MWCLASS_STATIC_H
#define GAME_MWCLASS_STATIC_H #define GAME_MWCLASS_STATIC_H
#include "../mwgui/tooltips.hpp"
#include "../mwworld/cellstore.hpp" #include "../mwworld/cellstore.hpp"
#include "../mwworld/registeredclass.hpp" #include "../mwworld/registeredclass.hpp"
#include "classmodel.hpp" #include "classmodel.hpp"
#include "../mwgui/ustring.hpp"
#include <MyGUI_TextIterator.h>
namespace MWClass namespace MWClass
{ {
class Static : public MWWorld::RegisteredClass<Static> class Static : public MWWorld::RegisteredClass<Static>
@ -34,64 +38,6 @@ namespace MWClass
std::string getModel(const MWWorld::ConstPtr& ptr) const override; std::string getModel(const MWWorld::ConstPtr& ptr) const override;
}; };
namespace ESM4StaticImpl
{
void insertObjectRendering(
const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface);
void insertObjectPhysics(const MWWorld::Ptr& ptr, const std::string& model, const osg::Quat& rotation,
MWPhysics::PhysicsSystem& physics);
}
// Templated because it is used as a dummy MWClass implementation for several ESM4 recors
template <typename Record>
class ESM4Static : public MWWorld::RegisteredClass<ESM4Static<Record>>
{
friend MWWorld::RegisteredClass<ESM4Static>;
ESM4Static()
: MWWorld::RegisteredClass<ESM4Static>(Record::sRecordId)
{
}
MWWorld::Ptr copyToCellImpl(const MWWorld::ConstPtr& ptr, MWWorld::CellStore& cell) const override
{
const MWWorld::LiveCellRef<Record>* ref = ptr.get<Record>();
return MWWorld::Ptr(cell.insert(ref), &cell);
}
public:
void insertObjectRendering(const MWWorld::Ptr& ptr, const std::string& model,
MWRender::RenderingInterface& renderingInterface) const override
{
const MWWorld::LiveCellRef<Record>* ref = ptr.get<Record>();
if (ref->mBase->mFlags & ESM4::Rec_Marker)
return;
ESM4StaticImpl::insertObjectRendering(ptr, model, renderingInterface);
}
void insertObject(const MWWorld::Ptr& ptr, const std::string& model, const osg::Quat& rotation,
MWPhysics::PhysicsSystem& physics) const override
{
insertObjectPhysics(ptr, model, rotation, physics);
}
void insertObjectPhysics(const MWWorld::Ptr& ptr, const std::string& model, const osg::Quat& rotation,
MWPhysics::PhysicsSystem& physics) const override
{
const MWWorld::LiveCellRef<Record>* ref = ptr.get<Record>();
if (ref->mBase->mFlags & ESM4::Rec_Marker)
return;
ESM4StaticImpl::insertObjectPhysics(ptr, model, rotation, physics);
}
std::string_view getName(const MWWorld::ConstPtr& ptr) const override { return ""; }
///< \return name or ID; can return an empty string.
bool hasToolTip(const MWWorld::ConstPtr& ptr) const override { return false; }
///< @return true if this object has a tooltip when focused (default implementation: true)
std::string getModel(const MWWorld::ConstPtr& ptr) const override { return getClassModel<Record>(ptr); }
};
} }
#endif #endif