diff options
author | Jared Adams <jaxad0127@gmail.com> | 2009-07-13 19:52:12 -0600 |
---|---|---|
committer | Jared Adams <jaxad0127@gmail.com> | 2009-07-13 19:52:12 -0600 |
commit | 666211542df4fd4fb0f9a1c936b54f6405ef09ba (patch) | |
tree | 478ea55ae467406f2f90f8941a2c5bc2a74a48db | |
parent | 6c764b3c95d0c078c5ccebac607517353e64dc55 (diff) | |
download | mana-666211542df4fd4fb0f9a1c936b54f6405ef09ba.tar.gz mana-666211542df4fd4fb0f9a1c936b54f6405ef09ba.tar.bz2 mana-666211542df4fd4fb0f9a1c936b54f6405ef09ba.tar.xz mana-666211542df4fd4fb0f9a1c936b54f6405ef09ba.zip |
Some item pickup cleaning
Still need to find where to attach LocalPlayer::pickedUp for TMWServ.
-rw-r--r-- | src/localplayer.cpp | 47 | ||||
-rw-r--r-- | src/localplayer.h | 12 | ||||
-rw-r--r-- | src/net/ea/inventoryhandler.cpp | 39 | ||||
-rw-r--r-- | src/net/tmwserv/gameserver/player.cpp | 8 | ||||
-rw-r--r-- | src/net/tmwserv/gameserver/player.h | 1 | ||||
-rw-r--r-- | src/net/tmwserv/playerhandler.cpp | 5 |
6 files changed, 57 insertions, 55 deletions
diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 69049398..fd0c0264 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -42,6 +42,8 @@ #include "gui/skilldialog.h" #include "gui/storagewindow.h" +#include "gui/widgets/chattab.h" + #include "net/inventoryhandler.h" #include "net/net.h" #include "net/partyhandler.h" @@ -161,13 +163,15 @@ void LocalPlayer::logic() { //const Vector &pos = getPosition(); + MessagePair info = mMessages.front(); + particleEngine->addTextRiseFadeOutEffect( - mMessages.front(), + info.first, /*(int) pos.x, (int) pos.y - 48,*/ getPixelX(), getPixelY() - 48, - &guiPalette->getColor(Palette::EXP_INFO), + &guiPalette->getColor(info.second), gui->getInfoParticleFont(), true); mMessages.pop_front(); @@ -850,17 +854,33 @@ void LocalPlayer::setLevelProgress(int percent) mLevelProgress = percent; } -void LocalPlayer::pickedUp(const std::string &item) +void LocalPlayer::pickedUp(const ItemInfo &itemInfo, int amount) { - if (mMap) + if (!amount) + { + if (config.getValue("showpickupchat", 1)) + { + localChatTab->chatLog(_("Unable to pick up item."), BY_SERVER); + } + } + else { - // Show pickup notification - particleEngine->addTextRiseFadeOutEffect( - item, - getPixelX(), - getPixelY() - 48, - &guiPalette->getColor(Palette::PICKUP_INFO), - gui->getInfoParticleFont(), true); + // TRANSLATORS: Used as in "You picked up a ...", when picking up + // only one item. + const std::string amountStr = (amount > 1) ? toString(amount) : _("a"); + + if (config.getValue("showpickupchat", 1)) + { + localChatTab->chatLog(strprintf(_("You picked up %s [@@%d|%s@@]."), + amountStr.c_str(), itemInfo.getId(), + itemInfo.getName().c_str()), BY_SERVER); + } + + if (mMap && config.getValue("showpickupparticle", 0)) + { + // Show pickup notification + addMessageToQueue(itemInfo.getName(), Palette::PICKUP_INFO); + } } } @@ -1010,7 +1030,8 @@ void LocalPlayer::setInStorage(bool inStorage) } #endif -void LocalPlayer::addMessageToQueue(const std::string &message) +void LocalPlayer::addMessageToQueue(const std::string &message, + Palette::ColorType color) { - mMessages.push_back(message); + mMessages.push_back(MessagePair(message, color)); } diff --git a/src/localplayer.h b/src/localplayer.h index 702ae38c..7fb43d3a 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -26,6 +26,7 @@ #include <vector> #include "player.h" +#include "gui/palette.h" class Equipment; class FloorItem; @@ -269,9 +270,9 @@ class LocalPlayer : public Player void emote(Uint8 emotion); /** - * Shows item pickup effect if the player is on a map. + * Shows item pickup notifications. */ - void pickedUp(const std::string &item); + void pickedUp(const ItemInfo &itemInfo, int amount); /** * Accessors for mInStorage @@ -375,7 +376,8 @@ class LocalPlayer : public Player const std::auto_ptr<Equipment> mEquipment; - void addMessageToQueue(const std::string &message); + void addMessageToQueue(const std::string &message, + Palette::ColorType color = Palette::EXP_INFO); protected: virtual void handleStatusEffect(StatusEffect *effect, int effectId); @@ -443,7 +445,9 @@ class LocalPlayer : public Player /** Animated target cursors. */ SimpleAnimation *mTargetCursor[2][NUM_TC]; - std::list<std::string> mMessages; /**< Queued exp messages*/ + typedef std::pair<std::string, Palette::ColorType> MessagePair; + /** Queued exp messages*/ + std::list<MessagePair> mMessages; int mMessageTime; }; diff --git a/src/net/ea/inventoryhandler.cpp b/src/net/ea/inventoryhandler.cpp index c1f04661..ebea1883 100644 --- a/src/net/ea/inventoryhandler.cpp +++ b/src/net/ea/inventoryhandler.cpp @@ -178,42 +178,25 @@ void InventoryHandler::handleMessage(MessageIn &msg) equipType = msg.readInt16(); itemType = msg.readInt8(); - if (msg.readInt8() > 0) - { - if (config.getValue("showpickupchat", 1)) - { - localChatTab->chatLog(_("Unable to pick up item."), - BY_SERVER); - } - } - else { const ItemInfo &itemInfo = ItemDB::get(itemId); - const std::string amountStr = - // TRANSLATORS: Used as in "You picked up a ...", when - // picking up only one item. - (amount > 1) ? toString(amount) : _("a"); - if (config.getValue("showpickupchat", 1)) + if (msg.readInt8() > 0) { - localChatTab->chatLog(strprintf(_("You picked up %s [@@%d|%s@@]."), - amountStr.c_str(), itemInfo.getId(), itemInfo.getName().c_str()), - BY_SERVER); + player_node->pickedUp(itemInfo, 0); } - - if (config.getValue("showpickupparticle", 0)) + else { - player_node->pickedUp(itemInfo.getName()); - } + player_node->pickedUp(itemInfo, amount); - if (Item *item = inventory->getItem(index)) { - item->setId(itemId); - item->increaseQuantity(amount); - } else { - inventory->setItem(index, itemId, amount, equipType != 0); + if (Item *item = inventory->getItem(index)) { + item->setId(itemId); + item->increaseQuantity(amount); + } else { + inventory->setItem(index, itemId, amount, equipType != 0); + } } - } - break; + } break; case SMSG_PLAYER_INVENTORY_REMOVE: index = msg.readInt16() - INVENTORY_OFFSET; diff --git a/src/net/tmwserv/gameserver/player.cpp b/src/net/tmwserv/gameserver/player.cpp index 93853681..733b7cdc 100644 --- a/src/net/tmwserv/gameserver/player.cpp +++ b/src/net/tmwserv/gameserver/player.cpp @@ -41,14 +41,6 @@ void Net::GameServer::Player::walk(int x, int y) Net::GameServer::connection->send(msg); } -void Net::GameServer::Player::pickUp(int x, int y) -{ - MessageOut msg(PGMSG_PICKUP); - msg.writeInt16(x); - msg.writeInt16(y); - Net::GameServer::connection->send(msg); -} - void Net::GameServer::Player::moveItem(int oldSlot, int newSlot, int amount) { MessageOut msg(PGMSG_MOVE_ITEM); diff --git a/src/net/tmwserv/gameserver/player.h b/src/net/tmwserv/gameserver/player.h index 24b25dc7..76d7844b 100644 --- a/src/net/tmwserv/gameserver/player.h +++ b/src/net/tmwserv/gameserver/player.h @@ -41,7 +41,6 @@ namespace Net namespace Player { void walk(int x, int y); - void pickUp(int x, int y); void moveItem(int oldSlot, int newSlot, int amount); void useSpecial(int special); void requestTrade(int id); diff --git a/src/net/tmwserv/playerhandler.cpp b/src/net/tmwserv/playerhandler.cpp index 825da8a4..6cf81496 100644 --- a/src/net/tmwserv/playerhandler.cpp +++ b/src/net/tmwserv/playerhandler.cpp @@ -335,7 +335,10 @@ void PlayerHandler::decreaseStat(LocalPlayer::Attribute attr) void PlayerHandler::pickUp(FloorItem *floorItem) { int id = floorItem->getId(); - Net::GameServer::Player::pickUp(id >> 16, id & 0xFFFF); + MessageOut msg(PGMSG_PICKUP); + msg.writeInt16(id >> 16); + msg.writeInt16(id & 0xFFFF); + Net::GameServer::connection->send(msg); } void PlayerHandler::setDirection(char direction) |