summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/inventory.cpp22
-rw-r--r--src/gui/inventory.h6
-rw-r--r--src/gui/itemcontainer.cpp8
-rw-r--r--src/gui/itemcontainer.h5
4 files changed, 33 insertions, 8 deletions
diff --git a/src/gui/inventory.cpp b/src/gui/inventory.cpp
index 259f728d..db5dfb54 100644
--- a/src/gui/inventory.cpp
+++ b/src/gui/inventory.cpp
@@ -67,10 +67,10 @@ void InventoryWindow::draw(gcn::Graphics *graphics)
}
-int InventoryWindow::addItem(int index, int id, int quantity) {
+int InventoryWindow::addItem(int index, int id, int quantity, bool equipment) {
/*items[index].id = id;
items[index].quantity += quantity;*/
- items->addItem(index, id, quantity);
+ items->addItem(index, id, quantity, equipment);
return 0;
}
@@ -116,13 +116,27 @@ int InventoryWindow::dropItem(int index, int quantity) {
return 0;
}
+void InventoryWindow::equipItem(int index) {
+ WFIFOW(0) = net_w_value(0x00a9);
+ WFIFOW(2) = net_w_value(index);
+ WFIFOW(4) = net_w_value(0);
+ WFIFOSET(6);
+ while ((out_size > 0)) flush();
+}
+
void InventoryWindow::action(const std::string &eventId)
{
//if(selectedItem >= 0 && selectedItem <= INVENTORY_SIZE) {
if (items->getIndex() != -1) {
if (eventId == "use") {
- useItem(items->getIndex(), items->getId());
- } else if (eventId == "drop") {
+ if(items->isEquipment(items->getIndex())) {
+ equipItem(items->getIndex());
+ }
+ else {
+ useItem(items->getIndex(), items->getId());
+ }
+ }
+ else if (eventId == "drop") {
dropItem(items->getIndex(), items->getQuantity());
// Temp: drop all the items, you should choose quantity instead
}
diff --git a/src/gui/inventory.h b/src/gui/inventory.h
index e48d5477..178c8019 100644
--- a/src/gui/inventory.h
+++ b/src/gui/inventory.h
@@ -56,12 +56,14 @@ class InventoryWindow : public Window, gcn::ActionListener {
/**
* Add an item the inventory.
*/
- int addItem(int index, int id, int quantity);
+ int addItem(int index, int id, int quantity, bool equipment);
/**
* Remove a item from the inventory.
*/
int removeItem(int id);
+
+ void equipItem(int index);
/**
* Change quantity of an item.
@@ -83,7 +85,7 @@ class InventoryWindow : public Window, gcn::ActionListener {
private:
gcn::Button *useButton, *dropButton;
int useItem(int index, int id);
- int dropItem(int index, int amunt);
+ int dropItem(int index, int quantity);
};
diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp
index 123270c2..0bd236e2 100644
--- a/src/gui/itemcontainer.cpp
+++ b/src/gui/itemcontainer.cpp
@@ -37,6 +37,7 @@ ItemContainer::ItemContainer()
for (int i = 0; i < INVENTORY_SIZE; i++) {
items[i].id = -1;
items[i].quantity = 0;
+ items[i].equipment = false;
}
}
@@ -113,10 +114,11 @@ int ItemContainer::getQuantity(int index)
return items[index].quantity;
}
-void ItemContainer::addItem(int index, int id, int quantity)
+void ItemContainer::addItem(int index, int id, int quantity, bool equipment)
{
items[index].id = id;
items[index].quantity += quantity;
+ items[index].equipment = equipment;
}
void ItemContainer::removeItem(int id)
@@ -155,3 +157,7 @@ void ItemContainer::_mouseInputMessage(const gcn::MouseInput &mouseInput)
}
}
+bool ItemContainer::isEquipment(int index)
+{
+ return items[index].equipment;
+}
diff --git a/src/gui/itemcontainer.h b/src/gui/itemcontainer.h
index 5774feb6..69e59149 100644
--- a/src/gui/itemcontainer.h
+++ b/src/gui/itemcontainer.h
@@ -34,6 +34,7 @@
struct ITEM_HOLDER { // the holder of a item
int id; // the id of the item
int quantity; // number of items
+ bool equipment;
};
/**
@@ -101,7 +102,7 @@ class ItemContainer : public gcn::Widget
/**
* Adds a new item.
*/
- void addItem(int index, int id, int quantity);
+ void addItem(int index, int id, int quantity, bool equipment);
/**
* Remove a item from the inventory.
@@ -119,6 +120,8 @@ class ItemContainer : public gcn::Widget
void increaseQuantity(int index, int quantity);
void _mouseInputMessage(const gcn::MouseInput &mouseInput);
+
+ bool isEquipment(int index);
};
#endif