diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index 9e93bd314..abf2264af 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -928,4 +928,32 @@ void NpcAnimation::applyAlpha(float alpha, Ogre::Entity *ent, NifOgre::ObjectSce } } +void NpcAnimation::equipmentChanged (const MWWorld::Ptr& actor, const MWWorld::Ptr& item, InventoryStoreListener::State state) +{ + if (actor.getRefData().getHandle() == "player" && !item.isEmpty()) + { + std::string soundId; + + if (item.getTypeName() == typeid(ESM::Light).name()) + { + soundId = item.get()->mBase->mSound; + } + + if (!soundId.empty()) + { + MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager(); + + if (state == InventoryStoreListener::EQUIPPED) + { + sndMgr->playSound3D(mPtr, soundId, 1.0f, 1.0f, MWBase::SoundManager::Play_TypeSfx, + MWBase::SoundManager::Play_Loop); + } + else if (state == InventoryStoreListener::UNEQUIPPED) + { + sndMgr->stopSound3D(mPtr, soundId); + } + } + } +} + } diff --git a/apps/openmw/mwrender/npcanimation.hpp b/apps/openmw/mwrender/npcanimation.hpp index 979210591..a6e927fce 100644 --- a/apps/openmw/mwrender/npcanimation.hpp +++ b/apps/openmw/mwrender/npcanimation.hpp @@ -114,6 +114,10 @@ private: void applyAlpha(float alpha, Ogre::Entity* ent, NifOgre::ObjectScenePtr scene); + /** + * Implementation of MWWorld::InventoryStoreListener equipmentChanged method + */ + void equipmentChanged (const MWWorld::Ptr& actor, const MWWorld::Ptr& item, InventoryStoreListener::State state); public: /** * @param ptr diff --git a/apps/openmw/mwworld/inventorystore.cpp b/apps/openmw/mwworld/inventorystore.cpp index f515f1efb..49db0025a 100644 --- a/apps/openmw/mwworld/inventorystore.cpp +++ b/apps/openmw/mwworld/inventorystore.cpp @@ -146,7 +146,8 @@ void MWWorld::InventoryStore::equip (int slot, const ContainerStoreIterator& ite flagAsModified(); - fireEquipmentChangedEvent(); + fireEquipmentChangedEvent(actor, *iterator, InventoryStoreListener::EQUIPPED); + updateMagicEffects(actor); } @@ -157,7 +158,7 @@ void MWWorld::InventoryStore::unequipAll(const MWWorld::Ptr& actor) for (int slot=0; slot < MWWorld::InventoryStore::Slots; ++slot) unequipSlot(slot, actor); mUpdatesEnabled = true; - fireEquipmentChangedEvent(); + fireEquipmentChangedEvent(actor, MWWorld::Ptr(), InventoryStoreListener::ALL_UNEQUIPPED); updateMagicEffects(actor); } @@ -286,7 +287,7 @@ void MWWorld::InventoryStore::autoEquip (const MWWorld::Ptr& actor) if (changed) { mSlots.swap (slots_); - fireEquipmentChangedEvent(); + fireEquipmentChangedEvent(actor, MWWorld::Ptr(), InventoryStoreListener::AUTOEQUIPPED); updateMagicEffects(actor); flagAsModified(); } @@ -519,7 +520,7 @@ MWWorld::ContainerStoreIterator MWWorld::InventoryStore::unequipSlot(int slot, c } } - fireEquipmentChangedEvent(); + fireEquipmentChangedEvent(actor, *it, InventoryStoreListener::UNEQUIPPED); updateMagicEffects(actor); return retval; @@ -546,12 +547,12 @@ void MWWorld::InventoryStore::setListener(InventoryStoreListener *listener, cons updateMagicEffects(actor); } -void MWWorld::InventoryStore::fireEquipmentChangedEvent() +void MWWorld::InventoryStore::fireEquipmentChangedEvent(const MWWorld::Ptr& actor, const MWWorld::Ptr& item, InventoryStoreListener::State state) { if (!mUpdatesEnabled) return; if (mListener) - mListener->equipmentChanged(); + mListener->equipmentChanged(actor, item, state); } void MWWorld::InventoryStore::visitEffectSources(MWMechanics::EffectSourceVisitor &visitor) diff --git a/apps/openmw/mwworld/inventorystore.hpp b/apps/openmw/mwworld/inventorystore.hpp index 41caae4e5..475f810af 100644 --- a/apps/openmw/mwworld/inventorystore.hpp +++ b/apps/openmw/mwworld/inventorystore.hpp @@ -20,10 +20,18 @@ namespace MWWorld class InventoryStoreListener { public: + enum State + { + EQUIPPED, + AUTOEQUIPPED, + UNEQUIPPED, + ALL_UNEQUIPPED + }; + /** * Fired when items are equipped or unequipped */ - virtual void equipmentChanged () {} + virtual void equipmentChanged (const MWWorld::Ptr& /*actor*/, const MWWorld::Ptr& /*item*/, State /*state*/) {} /** * @param effect @@ -109,7 +117,7 @@ namespace MWWorld void updateMagicEffects(const Ptr& actor); void updateRechargingItems(); - void fireEquipmentChangedEvent(); + void fireEquipmentChangedEvent(const MWWorld::Ptr& actor, const MWWorld::Ptr& item, InventoryStoreListener::State state); virtual int getSlot (const MWWorld::LiveCellRefBase& ref) const; ///< Return inventory slot that \a ref is in or -1 (if \a ref is not in a slot).