summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-10-04 19:19:53 +0300
committerAndrei Karas <akaras@inbox.ru>2013-10-04 19:19:53 +0300
commitdb43ad3b72fe207e6cc03a1fd341ea598d123319 (patch)
tree6d338e9e0bff66e7751d6d0866f32388bdcfe59c
parent65a88f27b994f7ade178368c569d466f6344ded6 (diff)
downloadmv-db43ad3b72fe207e6cc03a1fd341ea598d123319.tar.gz
mv-db43ad3b72fe207e6cc03a1fd341ea598d123319.tar.bz2
mv-db43ad3b72fe207e6cc03a1fd341ea598d123319.tar.xz
mv-db43ad3b72fe207e6cc03a1fd341ea598d123319.zip
add pickup and drop sound effects.
Works like equip/unequip effects.
-rw-r--r--src/being/localplayer.cpp2
-rw-r--r--src/being/playerinfo.cpp20
-rw-r--r--src/being/playerinfo.h5
-rw-r--r--src/dropshortcut.cpp8
-rw-r--r--src/gui/popups/popupmenu.cpp3
-rw-r--r--src/gui/windows/inventorywindow.cpp3
-rw-r--r--src/gui/windows/itemamountwindow.cpp4
-rw-r--r--src/itemsoundmanager.cpp18
-rw-r--r--src/itemsoundmanager.h4
-rw-r--r--src/resources/db/itemdb.cpp2
10 files changed, 58 insertions, 11 deletions
diff --git a/src/being/localplayer.cpp b/src/being/localplayer.cpp
index 657436f49..787d59038 100644
--- a/src/being/localplayer.cpp
+++ b/src/being/localplayer.cpp
@@ -898,7 +898,7 @@ bool LocalPlayer::pickUp(FloorItem *const item)
{
if (actorSpriteManager && actorSpriteManager->checkForPickup(item))
{
- Net::getPlayerHandler()->pickUp(item);
+ PlayerInfo::pickUpItem(item, true);
mPickUpTarget = nullptr;
}
}
diff --git a/src/being/playerinfo.cpp b/src/being/playerinfo.cpp
index 3d311dd91..169ee5be3 100644
--- a/src/being/playerinfo.cpp
+++ b/src/being/playerinfo.cpp
@@ -24,6 +24,7 @@
#include "client.h"
#include "configuration.h"
#include "depricatedevent.h"
+#include "flooritem.h"
#include "inventory.h"
#include "itemsoundmanager.h"
@@ -321,14 +322,31 @@ void useEquipItem2(const Item *const item, bool sfx)
{
if (mProtectedItems.find(item->getId()) == mProtectedItems.end())
{
- Net::getInventoryHandler()->useItem(item);
if (sfx)
ItemSoundManager::playSfx(item, SOUND_EVENT_USE);
+ Net::getInventoryHandler()->useItem(item);
}
}
}
}
+void dropItem(const Item *const item, const int amount, bool sfx)
+{
+ if (item && mProtectedItems.find(item->getId()) == mProtectedItems.end())
+ {
+ if (sfx)
+ ItemSoundManager::playSfx(item, SOUND_EVENT_DROP);
+ Net::getInventoryHandler()->dropItem(item, amount);
+ }
+}
+
+void pickUpItem(const FloorItem *const item, bool sfx)
+{
+ if (sfx)
+ ItemSoundManager::playSfx(item, SOUND_EVENT_PICKUP);
+ Net::getPlayerHandler()->pickUp(item);
+}
+
// --- Misc -------------------------------------------------------------------
void setBackend(const PlayerInfoBackend &backend)
diff --git a/src/being/playerinfo.h b/src/being/playerinfo.h
index cd454692f..eef07c584 100644
--- a/src/being/playerinfo.h
+++ b/src/being/playerinfo.h
@@ -61,6 +61,7 @@ struct PlayerInfoBackend final
IntMap mSkills;
};
+class FloorItem;
class Inventory;
class Item;
@@ -267,6 +268,10 @@ namespace PlayerInfo
void useEquipItem2(const Item *const item, bool sfx);
+ void dropItem(const Item *const item, const int amount, bool sfx);
+
+ void pickUpItem(const FloorItem *const item, bool sfx);
+
void protectItem(const int id);
void unprotectItem(const int id);
diff --git a/src/dropshortcut.cpp b/src/dropshortcut.cpp
index 6f0bb5ec4..af9f6b0f3 100644
--- a/src/dropshortcut.cpp
+++ b/src/dropshortcut.cpp
@@ -114,12 +114,12 @@ void DropShortcut::dropFirst() const
const int cnt = player_node->getQuickDropCounter();
if (player_node->isServerBuggy())
{
- Net::getInventoryHandler()->dropItem(item, cnt);
+ PlayerInfo::dropItem(item, cnt, true);
}
else
{
for (int i = 0; i < cnt; i++)
- Net::getInventoryHandler()->dropItem(item, 1);
+ PlayerInfo::dropItem(item, 1, false);
}
}
}
@@ -175,7 +175,7 @@ bool DropShortcut::dropItem(const int cnt)
const Item *const item = inv->findItem(itemId, itemColor);
if (item && item->getQuantity() > 0)
{
- Net::getInventoryHandler()->dropItem(item, cnt);
+ PlayerInfo::dropItem(item, cnt, true);
return true;
}
}
@@ -198,7 +198,7 @@ bool DropShortcut::dropItem(const int cnt)
const Item *const item = inv->findItem(itemId, itemColor);
if (item && item->getQuantity() > 0)
{
- Net::getInventoryHandler()->dropItem(item, cnt);
+ PlayerInfo::dropItem(item, cnt, true);
return true;
}
}
diff --git a/src/gui/popups/popupmenu.cpp b/src/gui/popups/popupmenu.cpp
index 63da24ccf..2539ab1b8 100644
--- a/src/gui/popups/popupmenu.cpp
+++ b/src/gui/popups/popupmenu.cpp
@@ -1122,8 +1122,7 @@ void PopupMenu::handleLink(const std::string &link,
}
else if (link == "drop all" && mItem)
{
- if (!PlayerInfo::isItemProtected(mItem->getId()))
- Net::getInventoryHandler()->dropItem(mItem, mItem->getQuantity());
+ PlayerInfo::dropItem(mItem, mItem->getQuantity(), true);
}
else if (link == "store" && mItem)
{
diff --git a/src/gui/windows/inventorywindow.cpp b/src/gui/windows/inventorywindow.cpp
index 0cc9b4e0e..64d9347af 100644
--- a/src/gui/windows/inventorywindow.cpp
+++ b/src/gui/windows/inventorywindow.cpp
@@ -379,8 +379,7 @@ void InventoryWindow::action(const gcn::ActionEvent &event)
{
if (inputManager.isActionActive(static_cast<int>(Input::KEY_MOD)))
{
- Net::getInventoryHandler()->dropItem(
- item, item->getQuantity());
+ PlayerInfo::dropItem(item, item->getQuantity(), true);
}
else
{
diff --git a/src/gui/windows/itemamountwindow.cpp b/src/gui/windows/itemamountwindow.cpp
index 1eba131c1..8816be8dc 100644
--- a/src/gui/windows/itemamountwindow.cpp
+++ b/src/gui/windows/itemamountwindow.cpp
@@ -25,6 +25,8 @@
#include "inventory.h"
#include "item.h"
+#include "being/playerinfo.h"
+
#include "input/keyboardconfig.h"
#include "net/inventoryhandler.h"
@@ -109,7 +111,7 @@ void ItemAmountWindow::finish(Item *const item, const int amount,
tradeWindow->tradeItem(item, amount);
break;
case ItemDrop:
- Net::getInventoryHandler()->dropItem(item, amount);
+ PlayerInfo::dropItem(item, amount, true);
break;
case ItemSplit:
Net::getInventoryHandler()->splitItem(item, amount);
diff --git a/src/itemsoundmanager.cpp b/src/itemsoundmanager.cpp
index 0e8b33d11..c77f0a08f 100644
--- a/src/itemsoundmanager.cpp
+++ b/src/itemsoundmanager.cpp
@@ -20,6 +20,7 @@
#include "itemsoundmanager.h"
+#include "flooritem.h"
#include "item.h"
#include "logger.h"
#include "soundmanager.h"
@@ -48,3 +49,20 @@ void ItemSoundManager::playSfx(const Item *const item,
}
soundManager.playGuiSfx(sfx);
}
+
+void ItemSoundManager::playSfx(const FloorItem *const item,
+ const ItemSoundEvent sound)
+{
+ if (!item)
+ return;
+ const ItemInfo &info = ItemDB::get(item->getItemId());
+ 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
index a22daf94b..77ef221c7 100644
--- a/src/itemsoundmanager.h
+++ b/src/itemsoundmanager.h
@@ -25,6 +25,7 @@
#include "localconsts.h"
+class FloorItem;
class Item;
class ItemSoundManager final
@@ -34,6 +35,9 @@ class ItemSoundManager final
static void playSfx(const Item *const item,
const ItemSoundEvent sound);
+
+ static void playSfx(const FloorItem *const item,
+ const ItemSoundEvent sound);
};
#endif // ITEMSOUNDMANAGER_H
diff --git a/src/resources/db/itemdb.cpp b/src/resources/db/itemdb.cpp
index da896fe9d..8066eb40d 100644
--- a/src/resources/db/itemdb.cpp
+++ b/src/resources/db/itemdb.cpp
@@ -170,6 +170,8 @@ static void initStatic()
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;
}
void ItemDB::load()