diff options
author | Eugenio Favalli <elvenprogrammer@gmail.com> | 2005-02-20 11:32:50 +0000 |
---|---|---|
committer | Eugenio Favalli <elvenprogrammer@gmail.com> | 2005-02-20 11:32:50 +0000 |
commit | 3135c725cc37251943271cd8f939e646c9164259 (patch) | |
tree | 159ae31b1c0518d37f5bb21344fe3c72bf5cc382 | |
parent | 54a359f67da79d97df667299ea4d91cef79c08f2 (diff) | |
download | mana-3135c725cc37251943271cd8f939e646c9164259.tar.gz mana-3135c725cc37251943271cd8f939e646c9164259.tar.bz2 mana-3135c725cc37251943271cd8f939e646c9164259.tar.xz mana-3135c725cc37251943271cd8f939e646c9164259.zip |
Finally equipment! Sometimes it works :P
-rw-r--r-- | The Mana World.dev | 12 | ||||
-rw-r--r-- | src/game.cpp | 32 | ||||
-rw-r--r-- | src/gui/equipment.cpp | 28 | ||||
-rw-r--r-- | src/gui/equipment.h | 8 | ||||
-rw-r--r-- | src/gui/inventory.cpp | 19 | ||||
-rw-r--r-- | src/gui/inventory.h | 1 | ||||
-rw-r--r-- | src/gui/itemcontainer.cpp | 24 | ||||
-rw-r--r-- | src/gui/itemcontainer.h | 10 | ||||
-rw-r--r-- | src/resources/mapreader.cpp | 8 |
9 files changed, 125 insertions, 17 deletions
diff --git a/The Mana World.dev b/The Mana World.dev index acdd6a88..445b1086 100644 --- a/The Mana World.dev +++ b/The Mana World.dev @@ -1,7 +1,7 @@ [Project] FileName=The Mana World.dev Name=tmw -UnitCount=97 +UnitCount=99 Type=0 Ver=1 ObjFiles= @@ -10,7 +10,7 @@ Libs= PrivateResource=The_Mana_World_private.rc ResourceIncludes= MakeIncludes= -Compiler=-Dmain=SDL_main_@@__@@_ +Compiler=-Dmain=SDL_main_@@_ CppCompiler=-funroll-loops_@@_-ffast-math_@@_-fomit-frame-pointer_@@_-pipe_@@_-D__DEBUG_@@__@@_ Linker=-lguichan_@@_-lguichan_sdl_@@_-lguichan_opengl_@@_-lwsock32_@@_-lSDL_image_@@_-lSDL_mixer_@@_-lmingw32_@@_-lSDLmain_@@_-lSDL_@@_-llibxml2_@@_-lopengl32_@@_-lphysfs_static_@@_ IsCpp=1 @@ -1023,9 +1023,9 @@ OverrideBuildCmd=0 BuildCmd= [Unit98] -FileName=src\gui\equipment.cpp +FileName=src\resources\mapreader.cpp CompileCpp=1 -Folder=gui +Folder=resources Compile=1 Link=1 Priority=1000 @@ -1033,9 +1033,9 @@ OverrideBuildCmd=0 BuildCmd= [Unit99] -FileName=src\gui\equipment.h +FileName=src\resources\mapreader.h CompileCpp=1 -Folder=gui +Folder=resources Compile=1 Link=1 Priority=1000 diff --git a/src/game.cpp b/src/game.cpp index 82842504..b372518a 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -415,7 +415,7 @@ void do_parse() { } fclose(file); */ -#ifdef DEBUG +#ifdef __DEBUG FILE *file = fopen("./docs/packet.list", "a"); fprintf(file, "%x\n", RFIFOW(0)); fclose(file); @@ -598,7 +598,8 @@ void do_parse() { case 0x01ee: for (int loop = 0; loop < (RFIFOW(2) - 4) / 18; loop++) { inventoryWindow->addItem(RFIFOW(4 + loop * 18), - RFIFOW(4 + loop * 18 + 2), RFIFOW(4 + loop * 18 + 6), false); + RFIFOW(4 + loop * 18 + 2), + RFIFOW(4 + loop * 18 + 6), false); } break; // Get the equipments @@ -971,16 +972,33 @@ void do_parse() { being->hair_style = RFIFOB(7); } break; - // Answer to equip items + // Answer to equip item case 0x00aa: if (RFIFOB(6) == 0) - chatBox->chat_log("Unable to equip.", BY_SERVER); + chatBox->chat_log("Unable to equip.", BY_SERVER); + else + inventoryWindow->items->setEquipped( + inventoryWindow->items->getIndex(), true); break; // Equipment related case 0x01d7: - char content[40]; - sprintf(content, "%i %i", RFIFOW(7), RFIFOW(9)); - chatBox->chat_log(content, BY_SERVER); + /*char content[40]; + sprintf(content, "%i %i %i", RFIFOB(6), RFIFOW(7), RFIFOW(9)); + chatBox->chat_log(content, BY_SERVER);*/ + equipmentWindow->addEquipment(RFIFOB(6), RFIFOW(7)); + if(inventoryWindow->items->getIndex(RFIFOW(7))); + inventoryWindow->items->setEquipped( + inventoryWindow->items->getIndex(RFIFOW(7)), true); + break; + // Answer to unequip item + case 0x00ac: + if (RFIFOB(6) == 0) + chatBox->chat_log("Unable to unequip.", BY_SERVER); + else { + equipmentWindow->removeEquipment(RFIFOW(2)); + inventoryWindow->items->setEquipped( + inventoryWindow->items->getIndex(), false); + } break; // Manage non implemented packets default: diff --git a/src/gui/equipment.cpp b/src/gui/equipment.cpp index c34a9b30..ccc4d403 100644 --- a/src/gui/equipment.cpp +++ b/src/gui/equipment.cpp @@ -29,10 +29,17 @@ EquipmentWindow::EquipmentWindow(): Window("Equipment") { - setSize(300, 300); + setSize(70, 200); setPosition(40, 40); + ResourceManager *resman = ResourceManager::getInstance(); + Image *itemImg = resman->getImage("core/graphics/sprites/items.png"); + if (!itemImg) error("Unable to load items.png"); + itemset = new Spriteset(itemImg, 20, 20); + for (int i = 0; i < 10; i++ ) { + equipments[i] = 0; + } } EquipmentWindow::~EquipmentWindow() @@ -41,10 +48,29 @@ EquipmentWindow::~EquipmentWindow() void EquipmentWindow::draw(gcn::Graphics *graphics) { + int x, y; + getAbsolutePosition(x, y); + // Draw window graphics Window::draw(graphics); + + for (int i = 0; i < 10; i++) { + if (equipments[i] > 0) { + itemset->spriteset[equipments[i] - 501]->draw(screen, + x + 20, y + 24 * i); + } + } } void EquipmentWindow::action(const std::string &eventId) { } + +void EquipmentWindow::addEquipment(int index, int id) { + equipments[index] = id; +} + +void EquipmentWindow::removeEquipment(int index) { + equipments[index] = 0; +} + diff --git a/src/gui/equipment.h b/src/gui/equipment.h index b1b4269b..79f229d4 100644 --- a/src/gui/equipment.h +++ b/src/gui/equipment.h @@ -55,7 +55,15 @@ class EquipmentWindow : public Window, gcn::ActionListener { */ void action(const std::string& eventId); + void addEquipment(int index, int id); + + void removeEquipment(int index); + + int equipments[10]; + private: + + Spriteset *itemset; }; diff --git a/src/gui/inventory.cpp b/src/gui/inventory.cpp index db5dfb54..67d6fecb 100644 --- a/src/gui/inventory.cpp +++ b/src/gui/inventory.cpp @@ -124,13 +124,28 @@ void InventoryWindow::equipItem(int index) { while ((out_size > 0)) flush(); } +void InventoryWindow::unequipItem(int index) { + WFIFOW(0) = net_w_value(0x00ab); + WFIFOW(2) = net_w_value(index); + WFIFOSET(4); + 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") { if(items->isEquipment(items->getIndex())) { - equipItem(items->getIndex()); + if(items->isEquipped(items->getIndex())) { + unequipItem(items->getIndex()); + std::cout << "Blah\n"; + + } + else { + equipItem(items->getIndex()); + } } else { useItem(items->getIndex(), items->getId()); @@ -138,7 +153,7 @@ void InventoryWindow::action(const std::string &eventId) } else if (eventId == "drop") { dropItem(items->getIndex(), items->getQuantity()); - // Temp: drop all the items, you should choose quantity instead + // TODO: now drop all the items, you should choose quantity instead } } } diff --git a/src/gui/inventory.h b/src/gui/inventory.h index 178c8019..f97a9b83 100644 --- a/src/gui/inventory.h +++ b/src/gui/inventory.h @@ -86,6 +86,7 @@ class InventoryWindow : public Window, gcn::ActionListener { gcn::Button *useButton, *dropButton; int useItem(int index, int id); int dropItem(int index, int quantity); + void unequipItem(int index); }; diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp index 0bd236e2..195f9188 100644 --- a/src/gui/itemcontainer.cpp +++ b/src/gui/itemcontainer.cpp @@ -38,6 +38,7 @@ ItemContainer::ItemContainer() items[i].id = -1; items[i].quantity = 0; items[i].equipment = false; + items[i].equipped = false; } } @@ -66,7 +67,8 @@ void ItemContainer::draw(gcn::Graphics* graphics) } std::stringstream ss; - ss << items[i].quantity; + if(!items[i].equipped) + ss << items[i].quantity; graphics->drawText(ss.str(), 24 * i + 10, 24 + 2, gcn::Graphics::CENTER); } @@ -83,6 +85,16 @@ int ItemContainer::getIndex() return selectedItem; } +int ItemContainer::getIndex(int id) +{ + for (int i = 0; i < INVENTORY_SIZE; i++) { + if (items[i].id == id) { + return i; + } + } + return -1; +} + int ItemContainer::getId() { if (selectedItem != -1) { @@ -161,3 +173,13 @@ bool ItemContainer::isEquipment(int index) { return items[index].equipment; } + +bool ItemContainer::isEquipped(int index) +{ + return items[index].equipped; +} + +void ItemContainer::setEquipped(int index, bool equipped) +{ + items[index].equipped = equipped; +} diff --git a/src/gui/itemcontainer.h b/src/gui/itemcontainer.h index 69e59149..5f7b6cbe 100644 --- a/src/gui/itemcontainer.h +++ b/src/gui/itemcontainer.h @@ -35,6 +35,7 @@ struct ITEM_HOLDER { // the holder of a item int id; // the id of the item int quantity; // number of items bool equipment; + bool equipped; }; /** @@ -80,6 +81,11 @@ class ItemContainer : public gcn::Widget int getIndex(); /** + * Finds the index of an item. + */ + int getIndex(int id); + + /** * Returns the id of the selected item. */ int getId(); @@ -122,6 +128,10 @@ class ItemContainer : public gcn::Widget void _mouseInputMessage(const gcn::MouseInput &mouseInput); bool isEquipment(int index); + + bool isEquipped(int index); + + void setEquipped(int index, bool equipped); }; #endif diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index 31c2cb75..031188c1 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -82,7 +82,9 @@ Map* MapReader::readMap(xmlNodePtr node, const std::string &path) xmlChar *prop; prop = xmlGetProp(node, BAD_CAST "version"); +#ifndef WIN32 xmlFree(prop); +#endif int w = getProperty(node, "width", 0); int h = getProperty(node, "height", 0); @@ -142,7 +144,9 @@ void MapReader::readTileset(xmlNodePtr node, const std::string &path, Map *map) xmlChar* prop = xmlGetProp(node, BAD_CAST "source"); if (prop) { log("Warning: External tilesets not supported yet."); +#ifndef WIN32 xmlFree(prop); +#endif return; } @@ -169,7 +173,9 @@ void MapReader::readTileset(xmlNodePtr node, const std::string &path, Map *map) Spriteset *set = new Spriteset(tilebmp, tw, th); //set->setFirstGid(firstgid); // TODO: Like uhm, do something with this set! +#ifndef WIN32 xmlFree(source); +#endif } else { log("Warning: Failed to load tileset (%s)\n", source); @@ -188,7 +194,9 @@ int MapReader::getProperty(xmlNodePtr node, const char* name, int def) xmlChar *prop = xmlGetProp(node, BAD_CAST name); if (prop) { int val = atoi((char*)prop); +#ifndef WIN32 xmlFree(prop); +#endif return val; } else { |