summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Edwardsson <simon@crossnet.se>2004-09-26 19:01:56 +0000
committerSimon Edwardsson <simon@crossnet.se>2004-09-26 19:01:56 +0000
commitf141416397c8fd7f65fd9cd363a99257ca769d86 (patch)
tree72146533436ba487b35c8795194f729c220935f5 /src
parent9f25a358b6a10b9abeb93cd42129254a331d80cf (diff)
downloadmana-f141416397c8fd7f65fd9cd363a99257ca769d86.tar.gz
mana-f141416397c8fd7f65fd9cd363a99257ca769d86.tar.bz2
mana-f141416397c8fd7f65fd9cd363a99257ca769d86.tar.xz
mana-f141416397c8fd7f65fd9cd363a99257ca769d86.zip
The invetory now gets real items, and you can use them.
Diffstat (limited to 'src')
-rw-r--r--src/game.cpp14
-rw-r--r--src/gui/inventory.cpp60
-rw-r--r--src/gui/inventory.h11
3 files changed, 72 insertions, 13 deletions
diff --git a/src/game.cpp b/src/game.cpp
index cd494b8a..ebf1ddd6 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -462,6 +462,20 @@ void do_parse() {
show_npc_dialog = 1;
}
break;
+ case 0x01ee: //Get the items
+ for(int loop = 0; loop < RFIFOW(4); loop++)
+ {
+ inventory.addItem(loop,RFIFOW(10+18*loop));
+ }
+ break;
+ case 0x00a8: // could I use the item?
+ // index RFIFOW(2)
+ // succes or not RFIFOB(6);
+ if(RFIFOB(6))
+ {
+ inventory.addItem(RFIFOW(2),RFIFOW(4));
+ }
+ break;
// Warp
case 0x0091:
memset(map_path, '\0', 480);
diff --git a/src/gui/inventory.cpp b/src/gui/inventory.cpp
index 72c2cbaa..8300a310 100644
--- a/src/gui/inventory.cpp
+++ b/src/gui/inventory.cpp
@@ -26,9 +26,7 @@
void TmwInventory::create(int tempxpos, int tempypos) {
xpos =tempxpos;
ypos =tempypos;
-
- itemPIC[0].pic = load_bitmap("items/herb.bmp", NULL); //ID=0
- itemPIC[1].pic = load_bitmap("items/magicthing.bmp", NULL); //ID=1
+ itemset = load_datafile("./items/item.dat");
empty = load_bitmap("items/empty.bmp", NULL);
selected = load_bitmap("items/selected.bmp", NULL);
@@ -41,15 +39,16 @@ void TmwInventory::create(int tempxpos, int tempypos) {
items[i][ii].num = 0;
}
}
+ //draw_rle_sprite(buffer, (RLE_SPRITE *)itemPIC[items[itemX][itemY].itemIDNum].pic, (xpos+items[itemX][itemY].xpos), (ypos+items[itemX][itemY].ypos));
//create two fake items
- items[0][0].flag = 1;
+ /*items[0][0].flag = 1;
items[0][0].itemIDNum = 0;
items[0][0].num = 1;
items[2][0].flag = 1;
items[2][0].itemIDNum = 1;
- items[2][0].num = 3;
+ items[2][0].num = 3;*/
backgroundSmall = create_bitmap(empty->w*10+10, empty->h+10);
backgroundBig = create_bitmap(empty->w*10+10, empty->h*10+10);
@@ -62,6 +61,7 @@ void TmwInventory::create(int tempxpos, int tempypos) {
lastSelectedX = -1;
lastSelectedY = -1;
bigwindow = 0; //false
+
}
void TmwInventory::draw(BITMAP * buffer) {
@@ -79,7 +79,6 @@ void TmwInventory::draw(BITMAP * buffer) {
for(int itemX = 0; itemX< 10; itemX++) {
for(int itemY = 0;itemY<max;itemY++) {
int draw = 0;
-
blit(empty, buffer, 0, 0, (xpos+items[itemX][itemY].xpos), (ypos+items[itemX][itemY].ypos), 800, 600);
if(mouse_b&1) {
@@ -117,7 +116,17 @@ void TmwInventory::draw(BITMAP * buffer) {
}
dragingItem = 0; // stop dragging
}
-
+ if(mouse_b&2 && items[itemX][itemY].flag) {
+ if(xpos+items[itemX][itemY].xpos+empty->w > mouse_x && xpos+items[itemX][itemY].xpos < mouse_x)
+ if(ypos+items[itemX][itemY].ypos+empty->h > mouse_y && ypos+items[itemX][itemY].ypos < mouse_y) {
+ //selected
+ masked_blit(selected, buffer, 0, 0, (xpos+items[itemX][itemY].xpos), (ypos+items[itemX][itemY].ypos), 800, 600);
+ draw = 1;
+ if(itemMeny){ itemMeny=0; } else { itemMeny=1; itemIdn =items[itemX][itemY].itemIDNum ;itemMeny_x = (xpos+items[itemX][itemY].xpos)+selected->w;itemMeny_y = (ypos+items[itemX][itemY].ypos)+selected->h;}
+ }
+ }
+
+
if(xpos+items[itemX][itemY].xpos+empty->w > mouse_x && xpos+items[itemX][itemY].xpos < mouse_x && ypos+items[itemX][itemY].ypos+empty->h > mouse_y && ypos+items[itemX][itemY].ypos < mouse_y ) {
// a hoover
lastSelectedX = itemX;
@@ -125,7 +134,7 @@ void TmwInventory::draw(BITMAP * buffer) {
}
if(items[itemX][itemY].flag) //draw the item
- masked_blit(itemPIC[items[itemX][itemY].itemIDNum].pic, buffer, 0, 0, (xpos+items[itemX][itemY].xpos), (ypos+items[itemX][itemY].ypos), 800, 600);
+ masked_blit(itemset[items[itemX][itemY].itemIDNum].dat, buffer, 0, 0, (xpos+items[itemX][itemY].xpos), (ypos+items[itemX][itemY].ypos), 800, 600);
//the number of that item
if(!bigwindow)
@@ -162,10 +171,34 @@ void TmwInventory::draw(BITMAP * buffer) {
}
if(dragingItem) { //moving the item
- masked_blit(itemPIC[ghostID].pic, buffer, 0, 0, ghostX, ghostY, 800, 600);
+ masked_blit(itemset[ghostID].dat, buffer, 0, 0, ghostX, ghostY, 800, 600);
ghostX = mouse_x;
ghostY = mouse_y;
}
+
+ if(itemMeny){
+ if(itemMeny_y < mouse_y && itemMeny_y+10 > mouse_y) {
+ if(mouse_b&1)
+ {
+ useItem(itemIdn);
+ itemMeny = 0;
+ }
+ alfont_textprintf_aa(buffer, gui_font, itemMeny_x, itemMeny_y, makecol(255,237,33), "Use item");
+ } else {
+ alfont_textprintf_aa(buffer, gui_font, itemMeny_x, itemMeny_y, MAKECOL_BLACK, "Use item");
+ }
+ if(itemMeny_y+10 < mouse_y && itemMeny_y+20 > mouse_y) {
+ if(mouse_b&1)
+ {
+ rmItem(itemIdn);
+ itemMeny = 0;
+ }
+ alfont_textprintf_aa(buffer, gui_font, itemMeny_x, itemMeny_y+10, makecol(255,237,33), "Del item");
+ } else {
+ alfont_textprintf_aa(buffer, gui_font, itemMeny_x, itemMeny_y+10, MAKECOL_BLACK, "Del item");
+ }
+ }
+
}
@@ -246,4 +279,13 @@ for(int i = 0; i< 10; i++)
}
}
return -1;
+}
+
+int TmwInventory::useItem(int idnum)
+{
+ printf("Use item %i\n",idnum);
+ WFIFOW(0) = net_w_value(0x00a7);
+ WFIFOW(2) = net_w_value(idnum);
+ WFIFOSET(4);
+ while((out_size>0))flush();
} \ No newline at end of file
diff --git a/src/gui/inventory.h b/src/gui/inventory.h
index f72bdb64..1b5d2c12 100644
--- a/src/gui/inventory.h
+++ b/src/gui/inventory.h
@@ -44,9 +44,7 @@ struct itemHolder { // the holder of a item
int xpos,ypos; // where am I?
};
-struct itemID {//the holder of the pictures for each item, maybe more in the future
- BITMAP * pic;
-};
+
class TmwInventory{
public:
@@ -61,6 +59,7 @@ class TmwInventory{
int addItem(int idnum, int antal); //add a item
int rmItem(int idnum); //remove a item
int changeNum(int idnum, int antal); // change nummber of a item
+ int useItem(int idnum);
//END API
private:
BITMAP * backgroundSmall;
@@ -69,12 +68,16 @@ class TmwInventory{
BITMAP * empty;
BITMAP * selected;
itemHolder items[10][10]; // this is the test holder of items
- itemID itemPIC[2]; // I only got two items
+ DATAFILE *itemset;
int ghostX, ghostY, ghostID, ghostOldIDX,ghostOldIDY; //info needed when moving item
int dragingItem, lastSelectedX,lastSelectedY; //info needed when moving item
int areDisplaying, dragingWindow;
int bigwindow;
int xpos, ypos; // Where am I ?
+ int itemMeny;
+ int itemMeny_x, itemMeny_y;
+ int itemIdn;
+
};
#endif