diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-10-04 17:38:19 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-10-04 17:38:19 +0300 |
commit | 65a88f27b994f7ade178368c569d466f6344ded6 (patch) | |
tree | 1b4bae38055b1ce31201ebb72b5c10987cba9f62 | |
parent | a553b3cda91aa095d88e22abcaa81701c2894334 (diff) | |
download | manaverse-65a88f27b994f7ade178368c569d466f6344ded6.tar.gz manaverse-65a88f27b994f7ade178368c569d466f6344ded6.tar.bz2 manaverse-65a88f27b994f7ade178368c569d466f6344ded6.tar.xz manaverse-65a88f27b994f7ade178368c569d466f6344ded6.zip |
add sound effects for equip/unequip/use items for local player.
It using: "equip", "unequip", "use" effects from items.
If no item effect present, fallback to same effects from player race.
-rw-r--r-- | src/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/Makefile.am | 6 | ||||
-rw-r--r-- | src/being/localplayer.cpp | 10 | ||||
-rw-r--r-- | src/being/playerinfo.cpp | 41 | ||||
-rw-r--r-- | src/being/playerinfo.h | 12 | ||||
-rw-r--r-- | src/gui/popups/popupmenu.cpp | 2 | ||||
-rw-r--r-- | src/gui/windows/equipmentwindow.cpp | 6 | ||||
-rw-r--r-- | src/gui/windows/inventorywindow.cpp | 18 | ||||
-rw-r--r-- | src/gui/windows/outfitwindow.cpp | 4 | ||||
-rw-r--r-- | src/itemshortcut.cpp | 6 | ||||
-rw-r--r-- | src/itemsoundmanager.cpp | 50 | ||||
-rw-r--r-- | src/itemsoundmanager.h | 39 | ||||
-rw-r--r-- | src/resources/db/itemdb.cpp | 3 | ||||
-rw-r--r-- | src/resources/soundinfo.h | 3 |
14 files changed, 160 insertions, 42 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a26d123e6..0a0fec949 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -638,6 +638,8 @@ SET(SRCS item.h itemshortcut.cpp itemshortcut.h + itemsoundmanager.cpp + itemsoundmanager.h dropshortcut.cpp dropshortcut.h spellshortcut.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 7d6bc1147..b300d71a5 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -622,6 +622,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ depricatedlistener.cpp \ depricatedlistener.h \ dragdrop.h \ + dropshortcut.cpp \ + dropshortcut.h \ effectmanager.cpp \ effectmanager.h \ emoteshortcut.cpp \ @@ -651,8 +653,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ item.h \ itemshortcut.cpp \ itemshortcut.h \ - dropshortcut.cpp \ - dropshortcut.h \ + itemsoundmanager.cpp \ + itemsoundmanager.h \ spellshortcut.cpp \ spellshortcut.h \ textcommand.cpp \ diff --git a/src/being/localplayer.cpp b/src/being/localplayer.cpp index 22a214168..657436f49 100644 --- a/src/being/localplayer.cpp +++ b/src/being/localplayer.cpp @@ -2349,7 +2349,7 @@ void LocalPlayer::changeEquipmentBeforeAttack(const Being *const target) const // if sword not equiped if (!item->isEquipped()) - PlayerInfo::equipItem(item); + PlayerInfo::equipItem(item, true); // if need equip shield too if (mAttackWeaponType == 3) @@ -2359,7 +2359,7 @@ void LocalPlayer::changeEquipmentBeforeAttack(const Being *const target) const if (!item) item = inv->findItem(602, 0); if (item && !item->isEquipped()) - PlayerInfo::equipItem(item); + PlayerInfo::equipItem(item, true); } } // big distance. allowed only bow @@ -2376,7 +2376,7 @@ void LocalPlayer::changeEquipmentBeforeAttack(const Being *const target) const return; if (!item->isEquipped()) - PlayerInfo::equipItem(item); + PlayerInfo::equipItem(item, true); } } @@ -3981,7 +3981,7 @@ void LocalPlayer::imitateOutfit(Being *const player, const int sprite) const const Item *const item = inv->findItemBySprite(path, player->getGender(), player->getSubType()); if (item && !item->isEquipped()) - PlayerInfo::equipItem(item); + PlayerInfo::equipItem(item, false); } else { @@ -3996,7 +3996,7 @@ void LocalPlayer::imitateOutfit(Being *const player, const int sprite) const if (item) { // logger->log("unequiping"); - PlayerInfo::unequipItem(item); + PlayerInfo::unequipItem(item, false); } } } diff --git a/src/being/playerinfo.cpp b/src/being/playerinfo.cpp index 954cb20f4..3d311dd91 100644 --- a/src/being/playerinfo.cpp +++ b/src/being/playerinfo.cpp @@ -25,6 +25,7 @@ #include "configuration.h" #include "depricatedevent.h" #include "inventory.h" +#include "itemsoundmanager.h" #include "gui/windows/inventorywindow.h" #include "gui/windows/npcdialog.h" @@ -245,55 +246,85 @@ void setEquipmentBackend(Equipment::Backend *const backend) mEquipment->setBackend(backend); } -void equipItem(const Item *const item) +void equipItem(const Item *const item, bool sfx) { + if (sfx) + ItemSoundManager::playSfx(item, SOUND_EVENT_EQUIP); Net::getInventoryHandler()->equipItem(item); } -void unequipItem(const Item *const item) +void unequipItem(const Item *const item, bool sfx) { + if (sfx) + ItemSoundManager::playSfx(item, SOUND_EVENT_UNEQUIP); Net::getInventoryHandler()->unequipItem(item); } -void useItem(const Item *const item) +void useItem(const Item *const item, bool sfx) { + if (sfx) + ItemSoundManager::playSfx(item, SOUND_EVENT_USE); Net::getInventoryHandler()->useItem(item); } -void useEquipItem(const Item *const item) +void useEquipItem(const Item *const item, bool sfx) { if (item) { if (item->isEquipment()) { if (item->isEquipped()) + { + if (sfx) + ItemSoundManager::playSfx(item, SOUND_EVENT_UNEQUIP); Net::getInventoryHandler()->unequipItem(item); + } else + { + if (sfx) + ItemSoundManager::playSfx(item, SOUND_EVENT_EQUIP); Net::getInventoryHandler()->equipItem(item); + } } else { if (mProtectedItems.find(item->getId()) == mProtectedItems.end()) + { Net::getInventoryHandler()->useItem(item); + if (sfx) + ItemSoundManager::playSfx(item, SOUND_EVENT_USE); + } } } } -void useEquipItem2(const Item *const item) +void useEquipItem2(const Item *const item, bool sfx) { if (item) { if (!item->isEquipment()) { if (item->isEquipped()) + { + if (sfx) + ItemSoundManager::playSfx(item, SOUND_EVENT_UNEQUIP); Net::getInventoryHandler()->unequipItem(item); + } else + { + if (sfx) + ItemSoundManager::playSfx(item, SOUND_EVENT_EQUIP); Net::getInventoryHandler()->equipItem(item); + } } else { if (mProtectedItems.find(item->getId()) == mProtectedItems.end()) + { Net::getInventoryHandler()->useItem(item); + if (sfx) + ItemSoundManager::playSfx(item, SOUND_EVENT_USE); + } } } } diff --git a/src/being/playerinfo.h b/src/being/playerinfo.h index 052fbe966..cd454692f 100644 --- a/src/being/playerinfo.h +++ b/src/being/playerinfo.h @@ -24,6 +24,8 @@ #include "equipment.h" +#include "resources/soundinfo.h" + #include <map> #include <string> @@ -255,15 +257,15 @@ namespace PlayerInfo void setEquipmentBackend(Equipment::Backend *const backend); - void equipItem(const Item *const item); + void equipItem(const Item *const item, bool sfx); - void unequipItem(const Item *const item); + void unequipItem(const Item *const item, bool sfx); - void useItem(const Item *const item); + void useItem(const Item *const item, bool sfx); - void useEquipItem(const Item *const item); + void useEquipItem(const Item *const item, bool sfx); - void useEquipItem2(const Item *const item); + void useEquipItem2(const Item *const item, bool sfx); void protectItem(const int id); diff --git a/src/gui/popups/popupmenu.cpp b/src/gui/popups/popupmenu.cpp index 459925bd0..63da24ccf 100644 --- a/src/gui/popups/popupmenu.cpp +++ b/src/gui/popups/popupmenu.cpp @@ -1012,7 +1012,7 @@ void PopupMenu::handleLink(const std::string &link, if (inv) { const Item *const item = inv->findItem(mItemId, mItemColor); - PlayerInfo::useEquipItem(item); + PlayerInfo::useEquipItem(item, true); } } else if (mItemId < SKILL_MIN_ID && spellManager) diff --git a/src/gui/windows/equipmentwindow.cpp b/src/gui/windows/equipmentwindow.cpp index 5f214cebe..cf8484555 100644 --- a/src/gui/windows/equipmentwindow.cpp +++ b/src/gui/windows/equipmentwindow.cpp @@ -257,7 +257,7 @@ void EquipmentWindow::action(const gcn::ActionEvent &event) if (event.getId() == "unequip" && mSelected > -1) { const Item *const item = mEquipment->getEquipment(mSelected); - PlayerInfo::unequipItem(item); + PlayerInfo::unequipItem(item, true); setSelected(-1); } } @@ -377,7 +377,7 @@ void EquipmentWindow::mouseReleased(gcn::MouseEvent &mouseEvent) if (item->isEquipment()) { if (!item->isEquipped()) - PlayerInfo::equipItem(item); + PlayerInfo::equipItem(item, true); } } else if (dragDrop.getSource() == DRAGDROP_SOURCE_EQUIPMENT) @@ -401,7 +401,7 @@ void EquipmentWindow::mouseReleased(gcn::MouseEvent &mouseEvent) } if (item->isEquipped()) - PlayerInfo::unequipItem(item); + PlayerInfo::unequipItem(item, true); } } dragDrop.clear(); diff --git a/src/gui/windows/inventorywindow.cpp b/src/gui/windows/inventorywindow.cpp index 99d4d4954..0cc9b4e0e 100644 --- a/src/gui/windows/inventorywindow.cpp +++ b/src/gui/windows/inventorywindow.cpp @@ -358,11 +358,11 @@ void InventoryWindow::action(const gcn::ActionEvent &event) if (eventId == "use") { - PlayerInfo::useEquipItem(item); + PlayerInfo::useEquipItem(item, true); } if (eventId == "equip") { - PlayerInfo::useEquipItem2(item); + PlayerInfo::useEquipItem2(item, true); } else if (eventId == "drop") { @@ -524,19 +524,7 @@ void InventoryWindow::mouseClicked(gcn::MouseEvent &event) } else { - if (item->isEquipment()) - { - if (item->isEquipped()) - PlayerInfo::unequipItem(item); - else - PlayerInfo::equipItem(item); - } - else - { - if (PlayerInfo::isItemProtected(item->getId())) - return; - PlayerInfo::useItem(item); - } + PlayerInfo::useEquipItem(item, true); } } else diff --git a/src/gui/windows/outfitwindow.cpp b/src/gui/windows/outfitwindow.cpp index 73acf475a..ff1088071 100644 --- a/src/gui/windows/outfitwindow.cpp +++ b/src/gui/windows/outfitwindow.cpp @@ -279,7 +279,7 @@ void OutfitWindow::wearOutfit(const int outfit, const bool unwearEmpty, { if (item->isEquipment()) { - PlayerInfo::equipItem(item); + PlayerInfo::equipItem(item, false); isEmpty = false; } } @@ -522,7 +522,7 @@ void OutfitWindow::unequipNotInOutfit(const int outfit) const } } if (!found) - PlayerInfo::unequipItem(item); + PlayerInfo::unequipItem(item, false); } } } diff --git a/src/itemshortcut.cpp b/src/itemshortcut.cpp index 7356ff0e7..2a95c7d4e 100644 --- a/src/itemshortcut.cpp +++ b/src/itemshortcut.cpp @@ -133,7 +133,7 @@ void ItemShortcut::useItem(const int index) const { const Item *const item = inv->findItem(itemId, itemColor); if (item && item->getQuantity()) - PlayerInfo::useEquipItem(item); + PlayerInfo::useEquipItem(item, true); } else if (itemId < SKILL_MIN_ID && spellManager) { @@ -161,7 +161,7 @@ void ItemShortcut::equipItem(const int index) const if (item->isEquipment()) { if (!item->isEquipped()) - PlayerInfo::equipItem(item); + PlayerInfo::equipItem(item, true); } } } @@ -181,7 +181,7 @@ void ItemShortcut::unequipItem(const int index) const if (item->isEquipment()) { if (item->isEquipped()) - PlayerInfo::unequipItem(item); + PlayerInfo::unequipItem(item, true); } } } diff --git a/src/itemsoundmanager.cpp b/src/itemsoundmanager.cpp new file mode 100644 index 000000000..0e8b33d11 --- /dev/null +++ b/src/itemsoundmanager.cpp @@ -0,0 +1,50 @@ +/* + * The ManaPlus Client + * Copyright (C) 2013 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/>. + */ + +#include "itemsoundmanager.h" + +#include "item.h" +#include "logger.h" +#include "soundmanager.h" + +#include "being/localplayer.h" + +#include "resources/iteminfo.h" + +#include "resources/db/itemdb.h" + +#include "debug.h" + +void ItemSoundManager::playSfx(const Item *const item, + const ItemSoundEvent sound) +{ + if (!item) + return; + const ItemInfo &info = ItemDB::get(item->getId()); + std::string sfx = info.getSound(sound).sound; + if (sfx.empty()) + { + // fallback to player race sound if no item sound. + const int id = -100 - player_node->getSubType(); + const ItemInfo &info2 = ItemDB::get(id); + sfx = info2.getSound(sound).sound; + } + soundManager.playGuiSfx(sfx); +} diff --git a/src/itemsoundmanager.h b/src/itemsoundmanager.h new file mode 100644 index 000000000..a22daf94b --- /dev/null +++ b/src/itemsoundmanager.h @@ -0,0 +1,39 @@ +/* + * The ManaPlus Client + * Copyright (C) 2013 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 ITEMSOUNDMANAGER_H +#define ITEMSOUNDMANAGER_H + +#include "resources/soundinfo.h" + +#include "localconsts.h" + +class Item; + +class ItemSoundManager final +{ + public: + A_DELETE_COPY(ItemSoundManager) + + static void playSfx(const Item *const item, + const ItemSoundEvent sound); +}; + +#endif // ITEMSOUNDMANAGER_H diff --git a/src/resources/db/itemdb.cpp b/src/resources/db/itemdb.cpp index 867c01e2d..da896fe9d 100644 --- a/src/resources/db/itemdb.cpp +++ b/src/resources/db/itemdb.cpp @@ -167,6 +167,9 @@ static void initStatic() 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; } void ItemDB::load() diff --git a/src/resources/soundinfo.h b/src/resources/soundinfo.h index 01671d43b..5d6bd21ad 100644 --- a/src/resources/soundinfo.h +++ b/src/resources/soundinfo.h @@ -56,7 +56,8 @@ enum ItemSoundEvent SOUND_EVENT_TAKE, // take from container SOUND_EVENT_PUT, // put into container SOUND_EVENT_EQUIP, - SOUND_EVENT_UNEQUIP + SOUND_EVENT_UNEQUIP, + SOUND_EVENT_USE }; typedef std::map<ItemSoundEvent, SoundInfoVect*> ItemSoundEvents; |