mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-20 15:53:54 +00:00
Issue #1887: Equipped items do not emit sounds
Added playing of sounds for equipped items (at this moment only for lights). Signed-off-by: Lukasz Gromanowski <lgromanowski@gmail.com>
This commit is contained in:
parent
6a89b67cb1
commit
e566e4abf2
4 changed files with 49 additions and 8 deletions
|
@ -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<ESM::Light>()->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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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).
|
||||
|
|
Loading…
Reference in a new issue