diff options
author | Andrei Karas <akaras@inbox.ru> | 2014-05-19 01:11:52 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2014-05-19 01:11:52 +0300 |
commit | 0d6ca48b79a596bec11fc7351fadbf3b1fc1f67b (patch) | |
tree | 4d03ab1e6b655bccafbad06e5cc3386a4f6480d7 | |
parent | 29a93440367af32463f285ae5f0bd2aa23aadc92 (diff) | |
download | manaverse-0d6ca48b79a596bec11fc7351fadbf3b1fc1f67b.tar.gz manaverse-0d6ca48b79a596bec11fc7351fadbf3b1fc1f67b.tar.bz2 manaverse-0d6ca48b79a596bec11fc7351fadbf3b1fc1f67b.tar.xz manaverse-0d6ca48b79a596bec11fc7351fadbf3b1fc1f67b.zip |
Move itemsoundevent into separate file.
-rw-r--r-- | src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/being/being.cpp | 22 | ||||
-rw-r--r-- | src/being/playerinfo.cpp | 22 | ||||
-rw-r--r-- | src/dragdrop.h | 4 | ||||
-rw-r--r-- | src/itemsoundmanager.cpp | 6 | ||||
-rw-r--r-- | src/itemsoundmanager.h | 6 | ||||
-rw-r--r-- | src/resources/beinginfo.cpp | 4 | ||||
-rw-r--r-- | src/resources/beinginfo.h | 5 | ||||
-rw-r--r-- | src/resources/db/itemdb.cpp | 24 | ||||
-rw-r--r-- | src/resources/db/monsterdb.cpp | 24 | ||||
-rw-r--r-- | src/resources/iteminfo.cpp | 6 | ||||
-rw-r--r-- | src/resources/iteminfo.h | 6 | ||||
-rw-r--r-- | src/resources/itemsoundevent.h | 46 | ||||
-rw-r--r-- | src/resources/soundinfo.h | 24 |
15 files changed, 120 insertions, 81 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f2cd7340b..9001d9a59 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -553,6 +553,7 @@ SET(SRCS resources/iteminfo.h resources/iteminfo.cpp resources/itemslot.h + resources/itemsoundevent.h resources/itemtype.h resources/db/mapdb.cpp resources/db/mapdb.h diff --git a/src/Makefile.am b/src/Makefile.am index eea12fa74..39c032946 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -660,6 +660,7 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ resources/iteminfo.h \ resources/iteminfo.cpp \ resources/itemslot.h \ + resources/itemsoundevent.h \ resources/itemtype.h \ resources/db/mapdb.cpp \ resources/db/mapdb.h \ diff --git a/src/being/being.cpp b/src/being/being.cpp index fbbbfecae..3446351c9 100644 --- a/src/being/being.cpp +++ b/src/being/being.cpp @@ -594,7 +594,7 @@ void Being::takeDamage(Being *const attacker, const int amount, mDamageTaken += amount; if (mInfo) { - playSfx(mInfo->getSound(SOUND_EVENT_HURT), this, false, mX, mY); + playSfx(mInfo->getSound(ItemSoundEvent::HURT), this, false, mX, mY); if (!mInfo->isStaticMaxHP()) { @@ -754,13 +754,13 @@ void Being::handleAttack(Being *const victim, const int damage, weaponId = -100 - mSubType; const ItemInfo &info = ItemDB::get(weaponId); playSfx(info.getSound((damage > 0) ? - SOUND_EVENT_HIT : SOUND_EVENT_MISS), victim, true, mX, mY); + ItemSoundEvent::HIT : ItemSoundEvent::MISS), victim, true, mX, mY); } } else { playSfx(mInfo->getSound((damage > 0) ? - SOUND_EVENT_HIT : SOUND_EVENT_MISS), victim, true, mX, mY); + ItemSoundEvent::HIT : ItemSoundEvent::MISS), victim, true, mX, mY); } } @@ -804,7 +804,7 @@ void Being::handleSkill(Being *const victim, const int damage, else { playSfx(mInfo->getSound((damage > 0) ? - SOUND_EVENT_HIT : SOUND_EVENT_MISS), victim, true, mX, mY); + ItemSoundEvent::HIT : ItemSoundEvent::MISS), victim, true, mX, mY); } } @@ -1135,7 +1135,7 @@ void Being::setAction(const BeingAction::Action &action, const int attackId) if (mInfo) { playSfx(mInfo->getSound( - SOUND_EVENT_MOVE), nullptr, true, mX, mY); + ItemSoundEvent::MOVE), nullptr, true, mX, mY); } currentAction = getMoveAction(); // Note: When adding a run action, @@ -1146,11 +1146,11 @@ void Being::setAction(const BeingAction::Action &action, const int attackId) currentAction = getSitAction(); if (mInfo) { - ItemSoundEvent event; + ItemSoundEvent::Type event; if (currentAction == SpriteAction::SITTOP) - event = SOUND_EVENT_SITTOP; + event = ItemSoundEvent::SITTOP; else - event = SOUND_EVENT_SIT; + event = ItemSoundEvent::SIT; playSfx(mInfo->getSound(event), nullptr, true, mX, mY); } break; @@ -1198,7 +1198,7 @@ void Being::setAction(const BeingAction::Action &action, const int attackId) case BeingAction::HURT: if (mInfo) { - playSfx(mInfo->getSound(SOUND_EVENT_HURT), + playSfx(mInfo->getSound(ItemSoundEvent::HURT), this, false, mX, mY); } break; @@ -1206,7 +1206,7 @@ void Being::setAction(const BeingAction::Action &action, const int attackId) currentAction = getDeadAction(); if (mInfo) { - playSfx(mInfo->getSound(SOUND_EVENT_DIE), this, false, mX, mY); + playSfx(mInfo->getSound(ItemSoundEvent::DIE), this, false, mX, mY); if (mType == ActorType::MONSTER || mType == ActorType::NPC) mYDiff = mInfo->getDeadSortOffsetY(); } @@ -1217,7 +1217,7 @@ void Being::setAction(const BeingAction::Action &action, const int attackId) case BeingAction::SPAWN: if (mInfo) { - playSfx(mInfo->getSound(SOUND_EVENT_SPAWN), + playSfx(mInfo->getSound(ItemSoundEvent::SPAWN), nullptr, true, mX, mY); } currentAction = getSpawnAction(); diff --git a/src/being/playerinfo.cpp b/src/being/playerinfo.cpp index 4978bd494..5632c8d38 100644 --- a/src/being/playerinfo.cpp +++ b/src/being/playerinfo.cpp @@ -232,21 +232,21 @@ void setEquipmentBackend(Equipment::Backend *const backend) void equipItem(const Item *const item, const bool sfx) { if (sfx) - ItemSoundManager::playSfx(item, SOUND_EVENT_EQUIP); + ItemSoundManager::playSfx(item, ItemSoundEvent::EQUIP); Net::getInventoryHandler()->equipItem(item); } void unequipItem(const Item *const item, const bool sfx) { if (sfx) - ItemSoundManager::playSfx(item, SOUND_EVENT_UNEQUIP); + ItemSoundManager::playSfx(item, ItemSoundEvent::UNEQUIP); Net::getInventoryHandler()->unequipItem(item); } void useItem(const Item *const item, const bool sfx) { if (sfx) - ItemSoundManager::playSfx(item, SOUND_EVENT_USE); + ItemSoundManager::playSfx(item, ItemSoundEvent::USE); Net::getInventoryHandler()->useItem(item); } @@ -259,13 +259,13 @@ void useEquipItem(const Item *const item, const bool sfx) if (item->isEquipped()) { if (sfx) - ItemSoundManager::playSfx(item, SOUND_EVENT_UNEQUIP); + ItemSoundManager::playSfx(item, ItemSoundEvent::UNEQUIP); Net::getInventoryHandler()->unequipItem(item); } else { if (sfx) - ItemSoundManager::playSfx(item, SOUND_EVENT_EQUIP); + ItemSoundManager::playSfx(item, ItemSoundEvent::EQUIP); Net::getInventoryHandler()->equipItem(item); } } @@ -275,7 +275,7 @@ void useEquipItem(const Item *const item, const bool sfx) { Net::getInventoryHandler()->useItem(item); if (sfx) - ItemSoundManager::playSfx(item, SOUND_EVENT_USE); + ItemSoundManager::playSfx(item, ItemSoundEvent::USE); } } } @@ -290,13 +290,13 @@ void useEquipItem2(const Item *const item, const bool sfx) if (item->isEquipped()) { if (sfx) - ItemSoundManager::playSfx(item, SOUND_EVENT_UNEQUIP); + ItemSoundManager::playSfx(item, ItemSoundEvent::UNEQUIP); Net::getInventoryHandler()->unequipItem(item); } else { if (sfx) - ItemSoundManager::playSfx(item, SOUND_EVENT_EQUIP); + ItemSoundManager::playSfx(item, ItemSoundEvent::EQUIP); Net::getInventoryHandler()->equipItem(item); } } @@ -305,7 +305,7 @@ void useEquipItem2(const Item *const item, const bool sfx) if (mProtectedItems.find(item->getId()) == mProtectedItems.end()) { if (sfx) - ItemSoundManager::playSfx(item, SOUND_EVENT_USE); + ItemSoundManager::playSfx(item, ItemSoundEvent::USE); Net::getInventoryHandler()->useItem(item); } } @@ -317,7 +317,7 @@ void dropItem(const Item *const item, const int amount, const bool sfx) if (item && mProtectedItems.find(item->getId()) == mProtectedItems.end()) { if (sfx) - ItemSoundManager::playSfx(item, SOUND_EVENT_DROP); + ItemSoundManager::playSfx(item, ItemSoundEvent::DROP); Net::getInventoryHandler()->dropItem(item, amount); } } @@ -325,7 +325,7 @@ void dropItem(const Item *const item, const int amount, const bool sfx) void pickUpItem(const FloorItem *const item, const bool sfx) { if (sfx) - ItemSoundManager::playSfx(item, SOUND_EVENT_PICKUP); + ItemSoundManager::playSfx(item, ItemSoundEvent::PICKUP); Net::getPlayerHandler()->pickUp(item); } diff --git a/src/dragdrop.h b/src/dragdrop.h index 6f18479a4..b277af3b9 100644 --- a/src/dragdrop.h +++ b/src/dragdrop.h @@ -104,7 +104,7 @@ class DragDrop final mItemImage->incRef(); mSource = source; mTag = tag; - ItemSoundManager::playSfx(item, SOUND_EVENT_TAKE); + ItemSoundManager::playSfx(item, ItemSoundEvent::TAKE); } else { @@ -183,7 +183,7 @@ class DragDrop final if (mItemImage) mItemImage->decRef(); if (mItem) - ItemSoundManager::playSfx(mItem, SOUND_EVENT_PUT); + ItemSoundManager::playSfx(mItem, ItemSoundEvent::PUT); mItem = 0; mItemColor = 1; mItemImage = nullptr; diff --git a/src/itemsoundmanager.cpp b/src/itemsoundmanager.cpp index 8132395aa..5206273a7 100644 --- a/src/itemsoundmanager.cpp +++ b/src/itemsoundmanager.cpp @@ -31,7 +31,7 @@ #include "debug.h" void ItemSoundManager::playSfx(const Item *const item, - const ItemSoundEvent sound) + const ItemSoundEvent::Type sound) { if (!item) return; @@ -39,7 +39,7 @@ void ItemSoundManager::playSfx(const Item *const item, } void ItemSoundManager::playSfx(const int itemId, - const ItemSoundEvent sound) + const ItemSoundEvent::Type sound) { const ItemInfo &info = ItemDB::get(itemId); std::string sfx = info.getSound(sound).sound; @@ -54,7 +54,7 @@ void ItemSoundManager::playSfx(const int itemId, } void ItemSoundManager::playSfx(const FloorItem *const item, - const ItemSoundEvent sound) + const ItemSoundEvent::Type sound) { if (!item) return; diff --git a/src/itemsoundmanager.h b/src/itemsoundmanager.h index 4654074d8..4cc738724 100644 --- a/src/itemsoundmanager.h +++ b/src/itemsoundmanager.h @@ -34,13 +34,13 @@ class ItemSoundManager final A_DELETE_COPY(ItemSoundManager) static void playSfx(const int item, - const ItemSoundEvent sound); + const ItemSoundEvent::Type sound); static void playSfx(const Item *const item, - const ItemSoundEvent sound); + const ItemSoundEvent::Type sound); static void playSfx(const FloorItem *const item, - const ItemSoundEvent sound); + const ItemSoundEvent::Type sound); }; #endif // ITEMSOUNDMANAGER_H diff --git a/src/resources/beinginfo.cpp b/src/resources/beinginfo.cpp index a12961315..a20e55d86 100644 --- a/src/resources/beinginfo.cpp +++ b/src/resources/beinginfo.cpp @@ -126,7 +126,7 @@ void BeingInfo::setTargetCursorSize(const std::string &size) } } -void BeingInfo::addSound(const ItemSoundEvent event, +void BeingInfo::addSound(const ItemSoundEvent::Type event, const std::string &filename, const int delay) { @@ -137,7 +137,7 @@ void BeingInfo::addSound(const ItemSoundEvent event, mSounds[event]->push_back(SoundInfo("sfx/" + filename, delay)); } -const SoundInfo &BeingInfo::getSound(const ItemSoundEvent event) const +const SoundInfo &BeingInfo::getSound(const ItemSoundEvent::Type event) const { static SoundInfo emptySound("", 0); diff --git a/src/resources/beinginfo.h b/src/resources/beinginfo.h index 27d36e2a3..851295e5a 100644 --- a/src/resources/beinginfo.h +++ b/src/resources/beinginfo.h @@ -88,10 +88,11 @@ class BeingInfo final TargetCursorSize::Size getTargetCursorSize() const A_WARN_UNUSED { return mTargetCursorSize; } - void addSound(const ItemSoundEvent event, const std::string &filename, + void addSound(const ItemSoundEvent::Type event, + const std::string &filename, const int delay); - const SoundInfo &getSound(const ItemSoundEvent event) + const SoundInfo &getSound(const ItemSoundEvent::Type event) const A_WARN_UNUSED; void addAttack(const int id, diff --git a/src/resources/db/itemdb.cpp b/src/resources/db/itemdb.cpp index 234225fb0..c077f58fe 100644 --- a/src/resources/db/itemdb.cpp +++ b/src/resources/db/itemdb.cpp @@ -45,7 +45,7 @@ namespace bool mConstructed = false; StringVect mTagNames; std::map<std::string, int> mTags; - std::map<std::string, ItemSoundEvent> mSoundNames; + std::map<std::string, ItemSoundEvent::Type> mSoundNames; } // namespace extern int serverVersion; @@ -184,16 +184,16 @@ static ItemType::Type itemTypeFromString(const std::string &name) static void initStatic() { mConstructed = true; - mSoundNames["hit"] = SOUND_EVENT_HIT; - mSoundNames["strike"] = SOUND_EVENT_MISS; - mSoundNames["miss"] = SOUND_EVENT_MISS; - mSoundNames["use"] = SOUND_EVENT_USE; - mSoundNames["equip"] = SOUND_EVENT_EQUIP; - mSoundNames["unequip"] = SOUND_EVENT_UNEQUIP; - mSoundNames["drop"] = SOUND_EVENT_DROP; - mSoundNames["pickup"] = SOUND_EVENT_PICKUP; - mSoundNames["take"] = SOUND_EVENT_TAKE; - mSoundNames["put"] = SOUND_EVENT_PUT; + mSoundNames["hit"] = ItemSoundEvent::HIT; + mSoundNames["strike"] = ItemSoundEvent::MISS; + mSoundNames["miss"] = ItemSoundEvent::MISS; + mSoundNames["use"] = ItemSoundEvent::USE; + mSoundNames["equip"] = ItemSoundEvent::EQUIP; + mSoundNames["unequip"] = ItemSoundEvent::UNEQUIP; + mSoundNames["drop"] = ItemSoundEvent::DROP; + mSoundNames["pickup"] = ItemSoundEvent::PICKUP; + mSoundNames["take"] = ItemSoundEvent::TAKE; + mSoundNames["put"] = ItemSoundEvent::PUT; } void ItemDB::load() @@ -763,7 +763,7 @@ void loadSoundRef(ItemInfo *const itemInfo, const XmlNodePtr node) node->xmlChildrenNode->content); const int delay = XML::getProperty(node, "delay", 0); - const std::map<std::string, ItemSoundEvent>::const_iterator + const std::map<std::string, ItemSoundEvent::Type>::const_iterator it = mSoundNames.find(event); if (it != mSoundNames.end()) { diff --git a/src/resources/db/monsterdb.cpp b/src/resources/db/monsterdb.cpp index ec68e5731..d29cac7e9 100644 --- a/src/resources/db/monsterdb.cpp +++ b/src/resources/db/monsterdb.cpp @@ -164,35 +164,43 @@ void MonsterDB::loadXmlFile(const std::string &fileName) if (event == "hit") { - currentInfo->addSound(SOUND_EVENT_HIT, filename, delay); + currentInfo->addSound(ItemSoundEvent::HIT, + filename, delay); } else if (event == "miss") { - currentInfo->addSound(SOUND_EVENT_MISS, filename, delay); + currentInfo->addSound(ItemSoundEvent::MISS, + filename, delay); } else if (event == "hurt") { - currentInfo->addSound(SOUND_EVENT_HURT, filename, delay); + currentInfo->addSound(ItemSoundEvent::HURT, + filename, delay); } else if (event == "die") { - currentInfo->addSound(SOUND_EVENT_DIE, filename, delay); + currentInfo->addSound(ItemSoundEvent::DIE, + filename, delay); } else if (event == "move") { - currentInfo->addSound(SOUND_EVENT_MOVE, filename, delay); + currentInfo->addSound(ItemSoundEvent::MOVE, + filename, delay); } else if (event == "sit") { - currentInfo->addSound(SOUND_EVENT_SIT, filename, delay); + currentInfo->addSound(ItemSoundEvent::SIT, + filename, delay); } else if (event == "sittop") { - currentInfo->addSound(SOUND_EVENT_SITTOP, filename, delay); + currentInfo->addSound(ItemSoundEvent::SITTOP, + filename, delay); } else if (event == "spawn") { - currentInfo->addSound(SOUND_EVENT_SPAWN, filename, delay); + currentInfo->addSound(ItemSoundEvent::SPAWN, + filename, delay); } else { diff --git a/src/resources/iteminfo.cpp b/src/resources/iteminfo.cpp index c4af7d30a..acf355b87 100644 --- a/src/resources/iteminfo.cpp +++ b/src/resources/iteminfo.cpp @@ -131,17 +131,17 @@ void ItemInfo::setWaterAttackAction(const std::string &attackAction) mWaterAttackAction = attackAction; } -void ItemInfo::addSound(const ItemSoundEvent event, +void ItemInfo::addSound(const ItemSoundEvent::Type event, const std::string &filename, const int delay) { mSounds[event].push_back(SoundInfo( paths.getStringValue("sfx").append(filename), delay)); } -const SoundInfo &ItemInfo::getSound(const ItemSoundEvent event) const +const SoundInfo &ItemInfo::getSound(const ItemSoundEvent::Type event) const { static const SoundInfo empty("", 0); - std::map<ItemSoundEvent, SoundInfoVect>::const_iterator i; + std::map<ItemSoundEvent::Type, SoundInfoVect>::const_iterator i; i = mSounds.find(event); diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h index 8d25ff8f2..ce318ca61 100644 --- a/src/resources/iteminfo.h +++ b/src/resources/iteminfo.h @@ -164,11 +164,11 @@ class ItemInfo final void setAttackRange(const int r) { mAttackRange = r; } - void addSound(const ItemSoundEvent event, + void addSound(const ItemSoundEvent::Type event, const std::string &filename, const int delay); - const SoundInfo &getSound(const ItemSoundEvent event) + const SoundInfo &getSound(const ItemSoundEvent::Type event) const A_WARN_UNUSED; int getDrawBefore(const int direction) const A_WARN_UNUSED; @@ -294,7 +294,7 @@ class ItemInfo final std::map <int, std::string> mAnimationFiles; /** Stores the names of sounds to be played at certain event. */ - std::map <ItemSoundEvent, SoundInfoVect> mSounds; + std::map <ItemSoundEvent::Type, SoundInfoVect> mSounds; std::map <int, int> mTags; const std::map <int, ColorDB::ItemColor> *mColors; std::string mColorList; diff --git a/src/resources/itemsoundevent.h b/src/resources/itemsoundevent.h new file mode 100644 index 000000000..a33caa076 --- /dev/null +++ b/src/resources/itemsoundevent.h @@ -0,0 +1,46 @@ +/* + * The ManaPlus Client + * Copyright (C) 2013-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef RESOURCES_ITEMSOUNDEVENT_H +#define RESOURCES_ITEMSOUNDEVENT_H + +namespace ItemSoundEvent +{ + enum Type + { + HIT = 0, + MISS, + HURT, + DIE, + MOVE, + SIT, + SITTOP, + SPAWN, + DROP, + PICKUP, + TAKE, // take from container + PUT, // put into container + EQUIP, + UNEQUIP, + USE + }; +} + +#endif // RESOURCES_ITEMSOUNDEVENT_H diff --git a/src/resources/soundinfo.h b/src/resources/soundinfo.h index bae53ae35..2e0bf46cc 100644 --- a/src/resources/soundinfo.h +++ b/src/resources/soundinfo.h @@ -21,6 +21,8 @@ #ifndef RESOURCES_SOUNDINFO_H #define RESOURCES_SOUNDINFO_H +#include "resources/itemsoundevent.h" + #include <map> #include <string> #include <vector> @@ -40,26 +42,6 @@ struct SoundInfo final }; typedef std::vector<SoundInfo> SoundInfoVect; - -enum ItemSoundEvent -{ - SOUND_EVENT_HIT = 0, - SOUND_EVENT_MISS, - SOUND_EVENT_HURT, - SOUND_EVENT_DIE, - SOUND_EVENT_MOVE, - SOUND_EVENT_SIT, - SOUND_EVENT_SITTOP, - SOUND_EVENT_SPAWN, - SOUND_EVENT_DROP, - SOUND_EVENT_PICKUP, - SOUND_EVENT_TAKE, // take from container - SOUND_EVENT_PUT, // put into container - SOUND_EVENT_EQUIP, - SOUND_EVENT_UNEQUIP, - SOUND_EVENT_USE -}; - -typedef std::map<ItemSoundEvent, SoundInfoVect*> ItemSoundEvents; +typedef std::map<ItemSoundEvent::Type, SoundInfoVect*> ItemSoundEvents; #endif // RESOURCES_SOUNDINFO_H |