summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2009-05-06 08:22:19 -0600
committerJared Adams <jaxad0127@gmail.com>2009-05-06 08:22:19 -0600
commit429e82f91487d48ecb5a1742ec6fb6987a2bc9bd (patch)
treed3789c7ef91680ba6a6a0eee56664ba3de690d94
parent678c2316e34021bb16ac08eb48186f5570dc691b (diff)
downloadmana-client-429e82f91487d48ecb5a1742ec6fb6987a2bc9bd.tar.gz
mana-client-429e82f91487d48ecb5a1742ec6fb6987a2bc9bd.tar.bz2
mana-client-429e82f91487d48ecb5a1742ec6fb6987a2bc9bd.tar.xz
mana-client-429e82f91487d48ecb5a1742ec6fb6987a2bc9bd.zip
Remove more inventory handling support #ifdefs
This also fixes some minor bugs and centralizes some logic.
-rw-r--r--src/gui/inventorywindow.cpp14
-rw-r--r--src/gui/inventorywindow.h8
-rw-r--r--src/gui/itemamount.cpp4
-rw-r--r--src/gui/popupmenu.cpp9
-rw-r--r--src/inventory.h2
-rw-r--r--src/localplayer.cpp19
-rw-r--r--src/localplayer.h2
-rw-r--r--src/net/ea/inventoryhandler.cpp20
-rw-r--r--src/net/ea/inventoryhandler.h14
-rw-r--r--src/net/inventoryhandler.h14
-rw-r--r--src/net/tmwserv/inventoryhandler.cpp32
-rw-r--r--src/net/tmwserv/inventoryhandler.h14
12 files changed, 77 insertions, 75 deletions
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp
index fa28bc34..8a18cd0d 100644
--- a/src/gui/inventorywindow.cpp
+++ b/src/gui/inventorywindow.cpp
@@ -37,6 +37,9 @@
#include "localplayer.h"
#include "units.h"
+#include "net/inventoryhandler.h"
+#include "net/net.h"
+
#include "resources/iteminfo.h"
#include "utils/gettext.h"
@@ -75,9 +78,7 @@ InventoryWindow::InventoryWindow(int invSize):
mUseButton = new Button(longestUseString, "use", this);
mDropButton = new Button(_("Drop"), "drop", this);
-#ifdef TMWSERV_SUPPORT
mSplitButton = new Button(_("Split"), "split", this);
-#endif
mItems = new ItemContainer(player_node->getInventory());
mItems->addSelectionListener(this);
@@ -101,9 +102,7 @@ InventoryWindow::InventoryWindow(int invSize):
place(0, 1, invenScroll, 7).setPadding(3);
place(0, 2, mUseButton);
place(1, 2, mDropButton);
-#ifdef TMWSERV_SUPPORT
place(2, 2, mSplitButton);
-#endif
Layout &layout = getLayout();
layout.setRowHeight(1, Layout::AUTO_SET);
@@ -217,7 +216,6 @@ void InventoryWindow::mouseClicked(gcn::MouseEvent &event)
}
}
-#ifdef TMWSERV_SUPPORT
void InventoryWindow::keyPressed(gcn::KeyEvent &event)
{
switch (event.getKey().getValue())
@@ -239,7 +237,6 @@ void InventoryWindow::keyReleased(gcn::KeyEvent &event)
break;
}
}
-#endif
void InventoryWindow::valueChanged(const gcn::SelectionEvent &event)
{
@@ -273,14 +270,11 @@ void InventoryWindow::updateButtons()
mUseButton->setEnabled(selectedItem != 0);
mDropButton->setEnabled(selectedItem != 0);
-#ifdef TMWSERV_SUPPORT
- if (selectedItem && !selectedItem->isEquipment() &&
- selectedItem->getQuantity() > 1)
+ if (Net::getInventoryHandler()->canSplit(selectedItem))
{
mSplitButton->setEnabled(true);
}
else {
mSplitButton->setEnabled(false);
}
-#endif
}
diff --git a/src/gui/inventorywindow.h b/src/gui/inventorywindow.h
index a39ea34b..1c8db89c 100644
--- a/src/gui/inventorywindow.h
+++ b/src/gui/inventorywindow.h
@@ -49,11 +49,7 @@ class InventoryWindow : public Window,
/**
* Constructor.
*/
-#ifdef TMWSERV_SUPPORT
InventoryWindow(int invSize = (INVENTORY_SIZE));
-#else
- InventoryWindow(int invSize = (INVENTORY_SIZE - 2));
-#endif
/**
* Destructor.
@@ -80,7 +76,6 @@ class InventoryWindow : public Window,
*/
void mouseClicked(gcn::MouseEvent &event);
-#ifdef TMWSERV_SUPPORT
/**
* Handles the key presses.
*/
@@ -90,7 +85,6 @@ class InventoryWindow : public Window,
* Handles the key releases.
*/
void keyReleased(gcn::KeyEvent &event);
-#endif
/**
* Updates labels to currently selected item.
@@ -109,9 +103,7 @@ class InventoryWindow : public Window,
int mMaxWeight;
gcn::Button *mUseButton;
gcn::Button *mDropButton;
-#ifdef TMWSERV_SUPPORT
gcn::Button *mSplitButton;
-#endif
gcn::Label *mWeightLabel;
gcn::Label *mSlotsLabel;
diff --git a/src/gui/itemamount.cpp b/src/gui/itemamount.cpp
index 46d12ee5..1bbd6fdd 100644
--- a/src/gui/itemamount.cpp
+++ b/src/gui/itemamount.cpp
@@ -21,9 +21,7 @@
#include "gui/itemamount.h"
-#ifdef EATHENA_SUPPORT
#include "gui/storagewindow.h"
-#endif
#include "gui/trade.h"
#include "gui/widgets/button.h"
@@ -155,11 +153,9 @@ void ItemAmountWindow::action(const gcn::ActionEvent &event)
case ItemDrop:
player_node->dropItem(mItem, amount);
break;
-#ifdef TMWSERV_SUPPORT
case ItemSplit:
player_node->splitItem(mItem, amount);
break;
-#endif
case StoreAdd:
storageWindow->addStore(mItem, amount);
break;
diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp
index c46f673c..6f2f9be4 100644
--- a/src/gui/popupmenu.cpp
+++ b/src/gui/popupmenu.cpp
@@ -38,6 +38,7 @@
#include "playerrelations.h"
#include "net/adminhandler.h"
+#include "net/inventoryhandler.h"
#include "net/net.h"
#include "resources/itemdb.h"
@@ -259,14 +260,10 @@ void PopupMenu::handleLink(const std::string &link)
assert(mItem);
if (mItem->isEquipment())
{
-#ifdef TMWSERV_SUPPORT
- player_node->equipItem(mItem);
-#else
if (mItem->isEquipped())
player_node->unequipItem(mItem);
else
player_node->equipItem(mItem);
-#endif
}
else
{
@@ -357,12 +354,10 @@ void PopupMenu::showPopup(int x, int y, Item *item, bool isInventory)
mBrowserBox->addRow(_("@@drop|Drop@@"));
-#ifdef TMWSERV_SUPPORT
- if (!item->isEquipment())
+ if (Net::getInventoryHandler()->canSplit(item))
{
mBrowserBox->addRow(_("@@split|Split@@"));
}
-#endif
if (player_node->getInStorage())
{
diff --git a/src/inventory.h b/src/inventory.h
index cfd72089..cd57d10e 100644
--- a/src/inventory.h
+++ b/src/inventory.h
@@ -25,7 +25,7 @@
class Item;
#ifdef EATHENA_SUPPORT
-const int INVENTORY_SIZE = 102;
+const int INVENTORY_SIZE = 100;
#else
const int INVENTORY_SIZE = 50;
#endif
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index 11c142cc..afd7f0eb 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -348,15 +348,7 @@ void LocalPlayer::inviteToParty(Player *player)
void LocalPlayer::moveInvItem(Item *item, int newIndex)
{
- // special case, the old and new cannot copy over each other.
- if (item->getInvIndex() == newIndex)
- return;
-
-#ifdef TMWSERV_SUPPORT
- Net::GameServer::Player::moveItem(
- item->getInvIndex(), newIndex, item->getQuantity());
-#endif
- // TODO: eAthena support
+ Net::getInventoryHandler()->moveItem(item->getInvIndex(), newIndex);
}
void LocalPlayer::equipItem(Item *item)
@@ -386,17 +378,10 @@ void LocalPlayer::dropItem(Item *item, int quantity)
Net::getInventoryHandler()->dropItem(item, quantity);
}
-#ifdef TMWSERV_SUPPORT
void LocalPlayer::splitItem(Item *item, int quantity)
{
- int newIndex = mInventory->getFreeSlot();
- if (newIndex > Inventory::NO_SLOT_INDEX)
- {
- Net::GameServer::Player::moveItem(
- item->getInvIndex(), newIndex, quantity);
- }
+ Net::getInventoryHandler()->splitItem(item, quantity);
}
-#endif
void LocalPlayer::pickUp(FloorItem *item)
{
diff --git a/src/localplayer.h b/src/localplayer.h
index 38995896..930020db 100644
--- a/src/localplayer.h
+++ b/src/localplayer.h
@@ -216,9 +216,7 @@ class LocalPlayer : public Player
void dropItem(Item *item, int quantity);
-#ifdef TMWSERV_SUPPORT
void splitItem(Item *item, int quantity);
-#endif
void pickUp(FloorItem *item);
diff --git a/src/net/ea/inventoryhandler.cpp b/src/net/ea/inventoryhandler.cpp
index 17b64548..1c48aa6c 100644
--- a/src/net/ea/inventoryhandler.cpp
+++ b/src/net/ea/inventoryhandler.cpp
@@ -301,7 +301,7 @@ void InventoryHandler::handleMessage(MessageIn &msg)
}
}
-void InventoryHandler::equipItem(Item *item)
+void InventoryHandler::equipItem(const Item *item)
{
if (!item)
return;
@@ -311,7 +311,7 @@ void InventoryHandler::equipItem(Item *item)
outMsg.writeInt16(0);
}
-void InventoryHandler::unequipItem(Item *item)
+void InventoryHandler::unequipItem(const Item *item)
{
if (!item)
return;
@@ -320,7 +320,7 @@ void InventoryHandler::unequipItem(Item *item)
outMsg.writeInt16(item->getInvIndex() + INVENTORY_OFFSET);
}
-void InventoryHandler::useItem(Item *item)
+void InventoryHandler::useItem(const Item *item)
{
if (!item)
return;
@@ -330,7 +330,7 @@ void InventoryHandler::useItem(Item *item)
outMsg.writeInt32(item->getId()); // unused
}
-void InventoryHandler::dropItem(Item *item, int amount)
+void InventoryHandler::dropItem(const Item *item, int amount)
{
// TODO: Fix wrong coordinates of drops, serverside? (what's wrong here?)
MessageOut outMsg(CMSG_PLAYER_INVENTORY_DROP);
@@ -338,7 +338,17 @@ void InventoryHandler::dropItem(Item *item, int amount)
outMsg.writeInt16(amount);
}
-void InventoryHandler::splitItem(Item *item, int amount)
+bool InventoryHandler::canSplit(const Item *item)
+{
+ return false;
+}
+
+void InventoryHandler::splitItem(const Item *item, int amount)
+{
+ // Not implemented for eAthena (possible?)
+}
+
+void InventoryHandler::moveItem(int oldIndex, int newIndex)
{
// Not implemented for eAthena (possible?)
}
diff --git a/src/net/ea/inventoryhandler.h b/src/net/ea/inventoryhandler.h
index 391c13f4..30408dad 100644
--- a/src/net/ea/inventoryhandler.h
+++ b/src/net/ea/inventoryhandler.h
@@ -35,15 +35,19 @@ class InventoryHandler : public MessageHandler, public Net::InventoryHandler
void handleMessage(MessageIn &msg);
- void equipItem(Item *item);
+ void equipItem(const Item *item);
- void unequipItem(Item *item);
+ void unequipItem(const Item *item);
- void useItem(Item *item);
+ void useItem(const Item *item);
- void dropItem(Item *item, int amount);
+ void dropItem(const Item *item, int amount);
- void splitItem(Item *item, int amount);
+ bool canSplit(const Item *item);
+
+ void splitItem(const Item *item, int amount);
+
+ void moveItem(int oldIndex, int newIndex);
void openStorage();
diff --git a/src/net/inventoryhandler.h b/src/net/inventoryhandler.h
index 73a07710..19060797 100644
--- a/src/net/inventoryhandler.h
+++ b/src/net/inventoryhandler.h
@@ -31,15 +31,19 @@ namespace Net {
class InventoryHandler
{
public:
- virtual void equipItem(Item *item) = 0;
+ virtual void equipItem(const Item *item) = 0;
- virtual void unequipItem(Item *item) = 0;
+ virtual void unequipItem(const Item *item) = 0;
- virtual void useItem(Item *item) = 0;
+ virtual void useItem(const Item *item) = 0;
- virtual void dropItem(Item *item, int amount) = 0;
+ virtual void dropItem(const Item *item, int amount) = 0;
- virtual void splitItem(Item *item, int amount) = 0;
+ virtual bool canSplit(const Item *item) = 0;
+
+ virtual void splitItem(const Item *item, int amount) = 0;
+
+ virtual void moveItem(int oldIndex, int newIndex) = 0;
virtual void openStorage() = 0;
diff --git a/src/net/tmwserv/inventoryhandler.cpp b/src/net/tmwserv/inventoryhandler.cpp
index 103c1c51..75886948 100644
--- a/src/net/tmwserv/inventoryhandler.cpp
+++ b/src/net/tmwserv/inventoryhandler.cpp
@@ -25,6 +25,7 @@
#include "net/tmwserv/protocol.h"
#include "net/tmwserv/gameserver/internal.h"
+#include "net/tmwserv/gameserver/player.h"
#include "net/messagein.h"
#include "net/messageout.h"
@@ -87,28 +88,28 @@ void InventoryHandler::handleMessage(MessageIn &msg)
}
}
-void InventoryHandler::equipItem(Item *item)
+void InventoryHandler::equipItem(const Item *item)
{
MessageOut msg(PGMSG_EQUIP);
msg.writeInt8(item->getInvIndex());
Net::GameServer::connection->send(msg);
}
-void InventoryHandler::unequipItem(Item *item)
+void InventoryHandler::unequipItem(const Item *item)
{
MessageOut msg(PGMSG_UNEQUIP);
msg.writeInt8(item->getInvIndex());
Net::GameServer::connection->send(msg);
}
-void InventoryHandler::useItem(Item *item)
+void InventoryHandler::useItem(const Item *item)
{
MessageOut msg(PGMSG_USE_ITEM);
msg.writeInt8(item->getInvIndex());
Net::GameServer::connection->send(msg);
}
-void InventoryHandler::dropItem(Item *item, int amount)
+void InventoryHandler::dropItem(const Item *item, int amount)
{
MessageOut msg(PGMSG_DROP);
msg.writeInt8(item->getInvIndex());
@@ -116,9 +117,28 @@ void InventoryHandler::dropItem(Item *item, int amount)
Net::GameServer::connection->send(msg);
}
-void InventoryHandler::splitItem(Item *item, int amount)
+bool InventoryHandler::canSplit(const Item *item)
{
- // TODO
+ return item && !item->isEquipment() && item->getQuantity() > 1;
+}
+
+void InventoryHandler::splitItem(const Item *item, int amount)
+{
+ int newIndex = player_node->getInventory()->getFreeSlot();
+ if (newIndex > Inventory::NO_SLOT_INDEX)
+ {
+ Net::GameServer::Player::moveItem(
+ item->getInvIndex(), newIndex, amount);
+ }
+}
+
+void InventoryHandler::moveItem(int oldIndex, int newIndex)
+{
+ if (oldIndex == newIndex)
+ return;
+
+ // TODO fix me!
+ Net::GameServer::Player::moveItem(oldIndex, newIndex, -1);
}
void InventoryHandler::openStorage()
diff --git a/src/net/tmwserv/inventoryhandler.h b/src/net/tmwserv/inventoryhandler.h
index c70b10c0..9ae37c10 100644
--- a/src/net/tmwserv/inventoryhandler.h
+++ b/src/net/tmwserv/inventoryhandler.h
@@ -34,15 +34,19 @@ class InventoryHandler : public MessageHandler, Net::InventoryHandler
void handleMessage(MessageIn &msg);
- void equipItem(Item *item);
+ void equipItem(const Item *item);
- void unequipItem(Item *item);
+ void unequipItem(const Item *item);
- void useItem(Item *item);
+ void useItem(const Item *item);
- void dropItem(Item *item, int amount);
+ void dropItem(const Item *item, int amount);
- void splitItem(Item *item, int amount);
+ bool canSplit(const Item *item);
+
+ void splitItem(const Item *item, int amount);
+
+ void moveItem(int oldIndex, int newIndex);
void openStorage();