summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-08-30 21:09:04 +0200
committerYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-08-30 21:09:04 +0200
commit5d00678217e5198cb375b4a2214a3e056151bdd9 (patch)
tree1874f2e8fa941f091e34c2b703c923e89f8a01f5 /src
parent19f6ce87e69b42fb69a4739ce363e1346cd569ea (diff)
parent4ab9c3f14340910e77856a9e12779ee8c6b9be4d (diff)
downloadmana-5d00678217e5198cb375b4a2214a3e056151bdd9.tar.gz
mana-5d00678217e5198cb375b4a2214a3e056151bdd9.tar.bz2
mana-5d00678217e5198cb375b4a2214a3e056151bdd9.tar.xz
mana-5d00678217e5198cb375b4a2214a3e056151bdd9.zip
Merge branch 'equipment-fix'
Diffstat (limited to 'src')
-rw-r--r--src/gui/equipmentwindow.cpp48
-rw-r--r--src/gui/equipmentwindow.h6
-rw-r--r--src/gui/popupmenu.cpp25
-rw-r--r--src/gui/popupmenu.h2
-rw-r--r--src/gui/viewport.cpp4
-rw-r--r--src/gui/viewport.h2
-rw-r--r--src/net/inventoryhandler.h25
-rw-r--r--src/net/manaserv/inventoryhandler.cpp45
-rw-r--r--src/net/manaserv/inventoryhandler.h10
-rw-r--r--src/net/manaserv/manaserv_protocol.h5
10 files changed, 121 insertions, 51 deletions
diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp
index 212dcd2b..209ecdb0 100644
--- a/src/gui/equipmentwindow.cpp
+++ b/src/gui/equipmentwindow.cpp
@@ -50,21 +50,6 @@
static const int BOX_WIDTH = 36;
static const int BOX_HEIGHT = 36;
-// Positions of the boxes, 2nd dimension is X and Y respectively.
-const int boxPosition[][2] = {
- { 90, 40 }, // EQUIP_TORSO_SLOT
- { 8, 78 }, // EQUIP_GLOVES_SLOT
- { 70, 0 }, // EQUIP_HEAD_SLOT
- { 50, 208 }, // EQUIP_LEGS_SLOT
- { 90, 208 }, // EQUIP_FEET_SLOT
- { 8, 168 }, // EQUIP_RING1_SLOT
- { 129, 168 }, // EQUIP_RING2_SLOT
- { 50, 40 }, // EQUIP_NECK_SLOT
- { 8, 123 }, // EQUIP_FIGHT1_SLOT
- { 129, 123 }, // EQUIP_FIGHT2_SLOT
- { 129, 78 } // EQUIP_PROJECTILE_SLOT
-};
-
EquipmentWindow::EquipmentWindow(Equipment *equipment):
Window(_("Equipment")),
mEquipBox(0),
@@ -105,10 +90,11 @@ void EquipmentWindow::loadEquipBoxes()
mBoxesNumber = mEquipment->getSlotNumber();
mEquipBox = new EquipBox[mBoxesNumber];
- for (int i = 0; i < mBoxesNumber; i++)
+ for (int i = 0; i < mBoxesNumber; ++i)
{
- mEquipBox[i].posX = boxPosition[i][0] + getPadding();
- mEquipBox[i].posY = boxPosition[i][1] + getTitleBarHeight();
+ Position boxPosition = Net::getInventoryHandler()->getBoxPosition(i);
+ mEquipBox[i].posX = boxPosition.x + getPadding();
+ mEquipBox[i].posY = boxPosition.y + getTitleBarHeight();
}
}
@@ -211,30 +197,32 @@ void EquipmentWindow::mousePressed(gcn::MouseEvent& mouseEvent)
const int x = mouseEvent.getX();
const int y = mouseEvent.getY();
+ Item *item = 0;
- if (mouseEvent.getButton() == gcn::MouseEvent::LEFT)
+ // Checks if any of the presses were in the equip boxes.
+ for (int i = 0; i < mBoxesNumber; ++i)
{
- // Checks if any of the presses were in the equip boxes.
- for (int i = 0; i < mBoxesNumber; ++i)
- {
- Item *item = mEquipment->getEquipment(i);
- gcn::Rectangle tRect(mEquipBox[i].posX, mEquipBox[i].posY,
- BOX_WIDTH, BOX_HEIGHT);
+ item = mEquipment->getEquipment(i);
+ gcn::Rectangle tRect(mEquipBox[i].posX, mEquipBox[i].posY,
+ BOX_WIDTH, BOX_HEIGHT);
- if (tRect.isPointInRect(x, y) && item)
- setSelected(i);
+ if (tRect.isPointInRect(x, y) && item)
+ {
+ setSelected(i);
+ break;
}
}
- else if (mouseEvent.getButton() == gcn::MouseEvent::RIGHT)
+
+ if (mouseEvent.getButton() == gcn::MouseEvent::RIGHT)
{
- if (Item *item = getItem(x, y))
+ if (item)
{
/* Convert relative to the window coordinates to absolute screen
* coordinates.
*/
const int mx = x + getX();
const int my = y + getY();
- viewport->showPopup(this, mx, my, item, true);
+ viewport->showPopup(this, mx, my, item, true, false);
}
}
}
diff --git a/src/gui/equipmentwindow.h b/src/gui/equipmentwindow.h
index b8e63efc..57a13d40 100644
--- a/src/gui/equipmentwindow.h
+++ b/src/gui/equipmentwindow.h
@@ -58,6 +58,12 @@ class EquipmentWindow : public Window, public gcn::ActionListener
*/
void loadEquipBoxes();
+ /**
+ * Returns the current selected slot or -1 if none.
+ */
+ int getSelected()
+ { return mSelected; }
+
protected:
/**
* Equipment box.
diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp
index 1c2f3b60..fbe3c739 100644
--- a/src/gui/popupmenu.cpp
+++ b/src/gui/popupmenu.cpp
@@ -32,6 +32,7 @@
#include "playerrelations.h"
#include "gui/chat.h"
+#include "gui/equipmentwindow.h"
#include "gui/inventorywindow.h"
#include "gui/itemamount.h"
@@ -266,15 +267,20 @@ void PopupMenu::handleLink(const std::string &link)
{
}
- else if (link == "activate")
+ else if (link == "activate" || link == "equip" || link == "unequip")
{
assert(mItem);
if (mItem->isEquippable())
{
if (mItem->isEquipped())
- mItem->doEvent(Event::DoUnequip);
+ {
+ PlayerInfo::getEquipment()->triggerUnequip(
+ equipmentWindow->getSelected());
+ }
else
+ {
mItem->doEvent(Event::DoEquip);
+ }
}
else
{
@@ -347,7 +353,7 @@ void PopupMenu::handleLink(const std::string &link)
}
void PopupMenu::showPopup(Window *parent, int x, int y, Item *item,
- bool isInventory)
+ bool isInventory, bool canDrop)
{
assert(item);
mItem = item;
@@ -364,17 +370,20 @@ void PopupMenu::showPopup(Window *parent, int x, int y, Item *item,
if (item->getInfo().getEquippable())
{
if (item->isEquipped())
- mBrowserBox->addRow(strprintf("@@equip|%s@@", _("Unequip")));
+ mBrowserBox->addRow(strprintf("@@unequip|%s@@", _("Unequip")));
else
mBrowserBox->addRow(strprintf("@@equip|%s@@", _("Equip")));
}
if (item->getInfo().getActivatable())
mBrowserBox->addRow(strprintf("@@activate|%s@@", _("Activate")));
- if (item->getQuantity() > 1)
- mBrowserBox->addRow(strprintf("@@drop|%s@@", _("Drop...")));
- else
- mBrowserBox->addRow(strprintf("@@drop|%s@@", _("Drop")));
+ if (canDrop)
+ {
+ if (item->getQuantity() > 1)
+ mBrowserBox->addRow(strprintf("@@drop|%s@@", _("Drop...")));
+ else
+ mBrowserBox->addRow(strprintf("@@drop|%s@@", _("Drop")));
+ }
if (Net::getInventoryHandler()->canSplit(item))
{
diff --git a/src/gui/popupmenu.h b/src/gui/popupmenu.h
index 969c5c20..111f94ed 100644
--- a/src/gui/popupmenu.h
+++ b/src/gui/popupmenu.h
@@ -55,7 +55,7 @@ class PopupMenu : public Popup, public LinkHandler
* at the specified mouse coordinates.
*/
void showPopup(Window *parent, int x, int y, Item *item,
- bool isInventory);
+ bool isInventory, bool canDrop = true);
/**
* Handles link action.
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index 0353fd44..945be7de 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -530,9 +530,9 @@ void Viewport::mouseReleased(gcn::MouseEvent &event)
}
void Viewport::showPopup(Window *parent, int x, int y, Item *item,
- bool isInventory)
+ bool isInventory, bool canDrop)
{
- mPopupMenu->showPopup(parent, x, y, item, isInventory);
+ mPopupMenu->showPopup(parent, x, y, item, isInventory, canDrop);
}
void Viewport::closePopupMenu()
diff --git a/src/gui/viewport.h b/src/gui/viewport.h
index 5814f08e..e5fb92b0 100644
--- a/src/gui/viewport.h
+++ b/src/gui/viewport.h
@@ -106,7 +106,7 @@ class Viewport : public WindowContainer, public gcn::MouseListener,
* TODO Find some way to get rid of Item here
*/
void showPopup(Window *parent, int x, int y, Item *item,
- bool isInventory = true);
+ bool isInventory = true, bool canDrop = true);
/**
* Closes the popup menu. Needed for when the player dies or switching
diff --git a/src/net/inventoryhandler.h b/src/net/inventoryhandler.h
index f1dea956..83ef91a7 100644
--- a/src/net/inventoryhandler.h
+++ b/src/net/inventoryhandler.h
@@ -24,11 +24,27 @@
#include "inventory.h"
#include "item.h"
+#include "position.h"
#include <iosfwd>
namespace Net {
+// Default positions of the boxes, 2nd dimension is X and Y respectively.
+const int fallBackBoxesPosition[][2] = {
+ { 90, 40 }, // EQUIP_TORSO_SLOT
+ { 8, 78 }, // EQUIP_GLOVES_SLOT
+ { 70, 0 }, // EQUIP_HEAD_SLOT
+ { 50, 208 }, // EQUIP_LEGS_SLOT
+ { 90, 208 }, // EQUIP_FEET_SLOT
+ { 8, 168 }, // EQUIP_RING1_SLOT
+ { 129, 168 }, // EQUIP_RING2_SLOT
+ { 50, 40 }, // EQUIP_NECK_SLOT
+ { 8, 123 }, // EQUIP_FIGHT1_SLOT
+ { 129, 123 }, // EQUIP_FIGHT2_SLOT
+ { 129, 78 } // EQUIP_PROJECTILE_SLOT
+};
+
class InventoryHandler
{
public:
@@ -45,6 +61,15 @@ class InventoryHandler
virtual unsigned int getVisibleSlotsNumber() const
{ return 0; }
+
+ virtual Position getBoxPosition(unsigned int slotIndex) const
+ {
+ if (slotIndex < (sizeof(fallBackBoxesPosition)
+ / sizeof(fallBackBoxesPosition[0][0])))
+ return Position(fallBackBoxesPosition[slotIndex][0],
+ fallBackBoxesPosition[slotIndex][1]);
+ return Position(0,0);
+ }
};
} // namespace Net
diff --git a/src/net/manaserv/inventoryhandler.cpp b/src/net/manaserv/inventoryhandler.cpp
index 1a74f732..67c79a17 100644
--- a/src/net/manaserv/inventoryhandler.cpp
+++ b/src/net/manaserv/inventoryhandler.cpp
@@ -65,6 +65,11 @@ EquipBackend::EquipBackend()
mVisibleSlots = 0;
}
+EquipBackend::~EquipBackend()
+{
+ clear();
+}
+
Item *EquipBackend::getEquipment(int slotIndex) const
{
Slots::const_iterator it = mSlots.find(slotIndex);
@@ -211,19 +216,19 @@ void EquipBackend::readEquipFile()
unsigned int slotIndex = 0;
mVisibleSlots = 0;
- for_each_xml_child_node(childNode, rootNode)
+ for_each_xml_child_node(slotNode, rootNode)
{
- if (!xmlStrEqual(childNode->name, BAD_CAST "slot"))
+ if (!xmlStrEqual(slotNode->name, BAD_CAST "slot"))
continue;
Slot slot;
- slot.slotTypeId = XML::getProperty(childNode, "id", 0);
- std::string name = XML::getProperty(childNode, "name", std::string());
- const int capacity = XML::getProperty(childNode, "capacity", 1);
- slot.weaponSlot = XML::getBoolProperty(childNode, "weapon", false);
- slot.ammoSlot = XML::getBoolProperty(childNode, "ammo", false);
+ slot.slotTypeId = XML::getProperty(slotNode, "id", 0);
+ std::string name = XML::getProperty(slotNode, "name", std::string());
+ const int capacity = XML::getProperty(slotNode, "capacity", 1);
+ slot.weaponSlot = XML::getBoolProperty(slotNode, "weapon", false);
+ slot.ammoSlot = XML::getBoolProperty(slotNode, "ammo", false);
- if (XML::getBoolProperty(childNode, "visible", false))
+ if (XML::getBoolProperty(slotNode, "visible", false))
++mVisibleSlots;
if (slot.slotTypeId > 0 && capacity > 0)
@@ -249,6 +254,23 @@ void EquipBackend::readEquipFile()
++slotIndex;
}
}
+
+ // Read the box properties
+ readBoxNode(slotNode);
+ }
+}
+
+void EquipBackend::readBoxNode(xmlNodePtr slotNode)
+{
+ for_each_xml_child_node(boxNode, slotNode)
+ {
+ if (!xmlStrEqual(boxNode->name, BAD_CAST "box"))
+ continue;
+
+ int x = XML::getProperty(boxNode, "x" , 0);
+ int y = XML::getProperty(boxNode, "y" , 0);
+
+ mBoxesPositions.push_back(Position(x, y));
}
}
@@ -274,6 +296,13 @@ bool EquipBackend::isAmmoSlot(int slotTypeId) const
return false;
}
+Position EquipBackend::getBoxPosition(unsigned int slotIndex) const
+{
+ if (slotIndex < mBoxesPositions.size())
+ return mBoxesPositions.at(slotIndex);
+ return Position(0, 0);
+}
+
InventoryHandler::InventoryHandler()
{
static const Uint16 _messages[] = {
diff --git a/src/net/manaserv/inventoryhandler.h b/src/net/manaserv/inventoryhandler.h
index bf3022ab..446105ee 100644
--- a/src/net/manaserv/inventoryhandler.h
+++ b/src/net/manaserv/inventoryhandler.h
@@ -38,6 +38,8 @@ class EquipBackend : public Equipment::Backend, public EventListener
public:
EquipBackend();
+ ~EquipBackend();
+
Item *getEquipment(int slotIndex) const;
std::string getSlotName(int slotIndex) const;
void clear();
@@ -59,9 +61,13 @@ class EquipBackend : public Equipment::Backend, public EventListener
bool isWeaponSlot(int slotTypeId) const;
bool isAmmoSlot(int slotTypeId) const;
+ Position getBoxPosition(unsigned int slotIndex) const;
+
private:
void readEquipFile();
+ void readBoxNode(xmlNodePtr slotNode);
+
struct Slot {
Slot():
item(0),
@@ -107,6 +113,7 @@ class EquipBackend : public Equipment::Backend, public EventListener
// slot client index, slot info
typedef std::map<unsigned int, Slot> Slots;
Slots mSlots;
+ std::vector<Position> mBoxesPositions;
};
class InventoryHandler : public MessageHandler, Net::InventoryHandler,
@@ -132,6 +139,9 @@ class InventoryHandler : public MessageHandler, Net::InventoryHandler,
unsigned int getVisibleSlotsNumber() const
{ return mEquipBackend.getVisibleSlotsNumber(); }
+ Position getBoxPosition(unsigned int slotIndex) const
+ { return mEquipBackend.getBoxPosition(slotIndex); }
+
private:
EquipBackend mEquipBackend;
};
diff --git a/src/net/manaserv/manaserv_protocol.h b/src/net/manaserv/manaserv_protocol.h
index 2c790d26..49548132 100644
--- a/src/net/manaserv/manaserv_protocol.h
+++ b/src/net/manaserv/manaserv_protocol.h
@@ -24,7 +24,10 @@
namespace ManaServ {
-enum { PROTOCOL_VERSION = 1 };
+enum {
+ PROTOCOL_VERSION = 1,
+ SUPPORTED_DB_VERSION = 15
+};
/**
* Enumerated type for communicated messages: