summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/game.cpp25
-rw-r--r--src/gui/inventory.cpp107
-rw-r--r--src/gui/inventory.h22
-rw-r--r--src/net/network.cpp7
4 files changed, 88 insertions, 73 deletions
diff --git a/src/game.cpp b/src/game.cpp
index 8f86d63f..1292397d 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -148,7 +148,7 @@ void do_init() {
player_node->weapon = char_info->weapon;
add_node(player_node);
- //remove("./docs/packet.list");
+ remove("./docs/packet.list");
}
void do_exit() {
@@ -408,11 +408,11 @@ void do_parse() {
}
fclose(file);
*/
-/*#ifdef DEBUG
- FILE *file = fopen("./docs/packet.list", "ab");
+//#ifdef DEBUG
+ FILE *file = fopen("./docs/packet.list", "a");
fprintf(file, "%x\n", RFIFOW(0));
fclose(file);
-#endif */
+//#endif
// Parse packet based on their id
switch(id) {
// Received speech
@@ -594,10 +594,11 @@ void do_parse() {
break;
// Can I use the item?
case 0x00a8:
- // index RFIFOW(2)
- // succes or not RFIFOB(6);
- //if (RFIFOB(6))
- // inventoryWindow->addItem(RFIFOW(2), RFIFOW(4));
+ if (RFIFOB(6) == 0) {
+ chatBox->chat_log("Failed to use item", BY_OTHER);
+ } else {
+ inventoryWindow->changeQuantity(RFIFOW(2), RFIFOW(4));
+ }
break;
// Warp
case 0x0091:
@@ -875,7 +876,7 @@ void do_parse() {
else
inventoryWindow->addItem(RFIFOW(2), RFIFOW(6), RFIFOW(4));
break;
- // Remove item to inventory after you sold it
+ // Decrease quantity of an item in inventory
case 0x00af:
printf("sell %i\n", -RFIFOW(4));
inventoryWindow->increaseQuantity(RFIFOW(2), -RFIFOW(4));
@@ -886,8 +887,6 @@ void do_parse() {
break;
// ??
case 0x0119:
- sprintf(pkt_nfo, "%i %i %i %i",
- RFIFOL(2), RFIFOW(6), RFIFOW(8), RFIFOW(10));
break;
// Skill list TAG
case 0x010f:
@@ -925,6 +924,7 @@ void do_parse() {
WFIFOW(0) = net_w_value(0x009f);
WFIFOL(2) = net_l_value(RFIFOL(2));
WFIFOSET(6);
+ // To be fixed or you will pick up again what you drop
break;
// Next button in NPC dialog
case 0x00b5:
@@ -951,9 +951,6 @@ void do_parse() {
if (RFIFOB(6) == 6) {
being = find_node(RFIFOL(2));
being->hair_color = RFIFOB(7);
- //char prova[100];
- //sprintf(prova, "%i %i %i", RFIFOL(2), RFIFOB(6), RFIFOB(7));
- //alert(prova,"","","","",0,0);
} else if (RFIFOB(6) == 1) {
being = find_node(RFIFOL(2));
being->hair_style = RFIFOB(7);
diff --git a/src/gui/inventory.cpp b/src/gui/inventory.cpp
index c7f7aec8..08a308df 100644
--- a/src/gui/inventory.cpp
+++ b/src/gui/inventory.cpp
@@ -25,12 +25,26 @@
#include "inventory.h"
#include "../resources/resourcemanager.h"
#include "../resources/image.h"
+#include "button.h"
+#include "../being.h"
#include <sstream>
InventoryWindow::InventoryWindow():
Window("Inventory")
{
- setSize(322, 60);
+ setSize(322, 80);
+ useButton = new Button("Use");
+ useButton->setPosition(20, 50);
+ dropButton = new Button("Drop");
+ dropButton->setPosition(60, 50);
+
+ useButton->setEventId("use");
+ dropButton->setEventId("drop");
+ useButton->addActionListener(this);
+ dropButton->addActionListener(this);
+
+ add(useButton);
+ add(dropButton);
ResourceManager *resman = ResourceManager::getInstance();
Image *itemImg = resman->getImage("graphic/items.bmp");
@@ -41,16 +55,23 @@ InventoryWindow::InventoryWindow():
items[i].id = -1;
items[i].quantity = 0;
}
+
+ selectedItem = 4; /**< No item selected */
}
InventoryWindow::~InventoryWindow()
{
+ delete useButton;
+ delete dropButton;
}
void InventoryWindow::draw(gcn::Graphics *graphics)
{
int x, y;
getAbsolutePosition(x, y);
+
+ if(items[selectedItem].quantity <= 0)
+ selectedItem = -1;
// Draw window graphics
Window::draw(graphics);
@@ -65,57 +86,16 @@ void InventoryWindow::draw(gcn::Graphics *graphics)
std::stringstream ss;
ss << items[i].quantity;
- graphics->drawText(ss.str(), 24 * i + 10, 44,
+ graphics->drawText(ss.str(), 24 * i + 10, 54,
gcn::Graphics::CENTER);
}
}
-
- /*
- if (mouse_b & 2) {
- for (int i = 0; i < INVENTORY_SIZE; i++) {
- if (items[i].quantity > 0 &&
- x + 24 * i + 24 > mouse_x &&
- x + 24 * i < mouse_x &&
- y + 44 + 24 > mouse_y &&
- y + 44 < mouse_y)
- {
- itemMeny = 1;
- itemMeny_x = 24 * i;
- itemMeny_y = 44 + 24;
- itemMeny_i = i;
- }
- }
+
+ if (selectedItem >= 0) {
+ graphics->drawRectangle(gcn::Rectangle(24 * selectedItem + 1, 26,
+ 22, 22));
}
-
- if (itemMeny) {
- if (y + itemMeny_y < mouse_y && y + itemMeny_y + 10 > mouse_y)
- {
- if (mouse_b & 1) {
- useItem(itemMeny_i,items[itemMeny_i].id);
- itemMeny = 0;
- }
- textprintf_ex(buffer, font, x + itemMeny_x,
- y + itemMeny_y, makecol(255, 237, 33), -1, "Use item");
- }
- else {
- textprintf_ex(buffer, font, x + itemMeny_x,
- y + itemMeny_y, makecol(0,0,0), -1, "Use item");
- }
- if (y + itemMeny_y + 10 < mouse_y && y + itemMeny_y + 20 > mouse_y) {
- if (mouse_b & 1) {
- dropItem(itemMeny_i, 1);
- itemMeny = 0;
- }
- textprintf_ex(buffer, font, x + itemMeny_x,
- y + itemMeny_y + 10,
- makecol(255, 237, 33), -1, "Del item");
- }
- else {
- textprintf_ex(buffer, font, x + itemMeny_x,
- y + itemMeny_y + 10, makecol(0,0,0), -1, "Del item");
- }
- }
- */
+
}
@@ -149,18 +129,39 @@ int InventoryWindow::useItem(int index, int id) {
WFIFOW(0) = net_w_value(0x00a7);
WFIFOW(2) = net_w_value(index);
WFIFOL(4) = net_l_value(id);
- // Note: id is dest of item, usually player_node->account_ID
+ // Note: id is dest of item, usually player_node->account_ID ??
WFIFOSET(8);
while ((out_size > 0)) flush();
return 0;
}
-int InventoryWindow::dropItem(int index, int amunt) {
- WFIFOW(0) = net_w_value(0x00a7);
+int InventoryWindow::dropItem(int index, int quantity) {
+ WFIFOW(0) = net_w_value(0x00a2);
WFIFOW(2) = net_w_value(index);
- WFIFOL(4) = net_l_value(amunt);
- WFIFOSET(8);
+ WFIFOW(4) = net_w_value(quantity);
+ WFIFOSET(6);
while ((out_size > 0)) flush();
return 0;
}
+void InventoryWindow::action(const std::string &eventId)
+{
+ if(selectedItem >= 0 && selectedItem <= INVENTORY_SIZE) {
+ if (eventId == "use") {
+ useItem(selectedItem, items[selectedItem].id);
+ } else if (eventId == "drop") {
+ dropItem(selectedItem, items[selectedItem].quantity);
+ // Temp: drop all the items, you should choose quantity instead
+ }
+ }
+}
+
+void InventoryWindow::mousePress(int mx, int my, int button) {
+ if (button == gcn::MouseInput::LEFT)
+ selectedItem = mx / 24;
+ if (selectedItem > INVENTORY_SIZE)
+ selectedItem = INVENTORY_SIZE;
+
+ Window::mousePress(mx, my, button);
+}
+
diff --git a/src/gui/inventory.h b/src/gui/inventory.h
index 784918cb..4248bfdb 100644
--- a/src/gui/inventory.h
+++ b/src/gui/inventory.h
@@ -21,15 +21,16 @@
* $Id$
*/
-#ifndef _INVENTORY_H
-#define _INVENTORY_H
+#ifndef _TMW_INVENTORY_H
+#define _TMW_INVENTORY_H
#include "../log.h"
#include "../net/network.h"
#include "../graphic/spriteset.h"
+#include "gui.h"
#include "window.h"
-#define INVENTORY_SIZE 100
+#define INVENTORY_SIZE 12
struct ITEM_HOLDER { // the holder of a item
int id; // the id of the item
@@ -42,7 +43,7 @@ struct ITEM_HOLDER { // the holder of a item
*
* \ingroup GUI
*/
-class InventoryWindow : public Window {
+class InventoryWindow : public Window, gcn::ActionListener {
public:
/**
* Constructor.
@@ -78,15 +79,26 @@ class InventoryWindow : public Window {
* Increase quantity of an item.
*/
int increaseQuantity(int index, int quantity);
+
+ /**
+ * Called when receiving actions from the widgets.
+ */
+ void action(const std::string& eventId);
+
+ /**
+ * Handles mouse events
+ */
+ void mousePress(int mx, int my, int button);
ITEM_HOLDER items[INVENTORY_SIZE]; /**< this is the holder of items */
private:
+ gcn::Button *useButton, *dropButton;
int useItem(int index, int id);
int dropItem(int index, int amunt);
Spriteset *itemset;
- int itemMeny, itemMeny_x, itemMeny_y, itemMeny_i;
+ int selectedItem;
};
#endif
diff --git a/src/net/network.cpp b/src/net/network.cpp
index 0162d246..7124073c 100644
--- a/src/net/network.cpp
+++ b/src/net/network.cpp
@@ -149,10 +149,15 @@ void flush() {
out_size -= ret;
}
}
- if(ret==SOCKET_ERROR) {
+ if (ret == SOCKET_ERROR) {
error("Socket Error");
#ifdef WIN32
log("Error", "Socket error: %i ", WSAGetLastError());
+ if (WSAGetLastError() == 10053)
+ log("Error", "Packet size error");
+ /** Probably the last packet you sent, was defined with
+ * wrong size: WFIFOSET(size);
+ */
#else
log("Error", "socket_error", "Undefined socket error");
#endif