From 19ce91290d85620ee464e85c617575986cd34aec Mon Sep 17 00:00:00 2001 From: Philipp Sehmisch Date: Thu, 17 Aug 2006 19:11:28 +0000 Subject: the item icons are now stored in different files with more descriptive names --- ChangeLog | 16 ++++++++++++++-- src/engine.cpp | 4 ---- src/floor_item.cpp | 5 ++--- src/floor_item.h | 1 + src/gui/equipmentwindow.cpp | 9 ++------- src/gui/equipmentwindow.h | 3 --- src/gui/itemcontainer.cpp | 21 +++++++++------------ src/gui/itemcontainer.h | 2 -- src/resources/iteminfo.cpp | 44 +++++++++++++++++++++++++++++++++++++++++++ src/resources/iteminfo.h | 16 ++++++++++------ src/resources/itemmanager.cpp | 12 +++++++----- 11 files changed, 89 insertions(+), 44 deletions(-) create mode 100644 src/resources/iteminfo.cpp diff --git a/ChangeLog b/ChangeLog index a76229e3..2516f980 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2006-08-17 Philipp Sehmisch + * data/graphics/items/*: Splitted the items.png into separate images + with more distinctive names. (no, i won't list all 114) + * src/itemmanager.cpp, data/items.xml: Replaced indices on the item + spriteset with filenames. added names and descriptions for all missing + items. Changed names and dascriptions of some items. + * src/engine.cpp: removed global item spriteset. + * src/floor_item.cpp, src/floor_item.h, src/iteminfo.cpp, src/iteminfo.h + src/equipmentwindow.cpp, src/equipmentwindow.h, src/itemcontainer.cpp, + src/itemcontainer.h: the iteminfo class now provides a pointer to the item + icon image instead of providing the index on the item spriteset. + 2006-08-13 Eugenio Favalli * data/graphics/sprites/Makefile.am, @@ -463,7 +475,7 @@ * data/items.xml, src/being.cpp, src/being.h src/net/beinghandler.cpp, src/player.cpp: Clients get notified of equipping visible items. * src/net/beinghandler.cpp: GCC 4 fix. - + 2006-06-28 Philipp Sehmisch * src/animation.cpp, src/animation.h: Parser now works like described @@ -2700,4 +2712,4 @@ restore some doxygen comments, improved size adaption and made the window a shorter. * data/graphics/images/login_wallpaper.png: New login wallpaper by - Momotaro. + Momotaro. \ No newline at end of file diff --git a/src/engine.cpp b/src/engine.cpp index 01bbbaa2..eb36a9fc 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -58,7 +58,6 @@ int camera_x, camera_y; ItemManager *itemDb; /**< Item database object */ -Spriteset *itemset; Spriteset *emotionset; Spriteset *npcset; std::vector weaponset; @@ -84,11 +83,9 @@ Engine::Engine(Network *network): weaponset.push_back(tmp); } } - itemset = resman->getSpriteset("graphics/sprites/items.png", 32, 32); if (!npcset) logger->error("Unable to load NPC spriteset!"); if (!emotionset) logger->error("Unable to load emotions spriteset!"); - if (!itemset) logger->error("Unable to load item spriteset!"); // Initialize item manager itemDb = new ItemManager(); @@ -99,7 +96,6 @@ Engine::~Engine() // Delete sprite sets npcset->decRef(); emotionset->decRef(); - itemset->decRef(); std::for_each(weaponset.begin(), weaponset.end(), std::mem_fun(&Spriteset::decRef)); diff --git a/src/floor_item.cpp b/src/floor_item.cpp index 1581b201..edd5d4a7 100644 --- a/src/floor_item.cpp +++ b/src/floor_item.cpp @@ -29,7 +29,6 @@ #include "resources/iteminfo.h" #include "resources/spriteset.h" -extern Spriteset *itemset; FloorItem::FloorItem(unsigned int id, unsigned int itemId, @@ -42,8 +41,8 @@ FloorItem::FloorItem(unsigned int id, mY(y), mMap(map) { - // Retrieve item image using a global itemset and itemDb (alternative?) - mImage = itemset->get(itemDb->getItemInfo(itemId)->getImage() - 1); + // Retrieve item image from item info + mImage = itemDb->getItemInfo(itemId)->getImage(); // Add ourselves to the map mSpriteIterator = mMap->addSprite(this); diff --git a/src/floor_item.h b/src/floor_item.h index 24eb495d..386d0759 100644 --- a/src/floor_item.h +++ b/src/floor_item.h @@ -27,6 +27,7 @@ #include "graphics.h" #include "map.h" #include "sprite.h" +#include "resources/image.h" /** * An item lying on the floor. diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index bef39dff..2cbffde4 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -40,15 +40,10 @@ EquipmentWindow::EquipmentWindow(Equipment *equipment): setWindowName("Equipment"); setDefaultSize(5, 230, 200, 120); loadWindowState(); - - mItemset = ResourceManager::getInstance()->getSpriteset( - "graphics/sprites/items.png", 32, 32); - if (!mItemset) logger->error("Unable to load items.png"); } EquipmentWindow::~EquipmentWindow() { - mItemset->decRef(); } void EquipmentWindow::draw(gcn::Graphics *graphics) @@ -70,7 +65,7 @@ void EquipmentWindow::draw(gcn::Graphics *graphics) continue; } - image = mItemset->get(item->getInfo()->getImage() - 1); + image = item->getInfo()->getImage(); dynamic_cast(graphics)->drawImage( image, 36 * (i % 4) + 10, 36 * (i / 4) + 25); } @@ -81,7 +76,7 @@ void EquipmentWindow::draw(gcn::Graphics *graphics) return; } - image = mItemset->get(item->getInfo()->getImage() - 1); + image = item->getInfo()->getImage(); dynamic_cast(graphics)->drawImage(image, 160, 25); graphics->drawText(toString(item->getQuantity()), 170, 62, diff --git a/src/gui/equipmentwindow.h b/src/gui/equipmentwindow.h index aeaae58c..99a3cc60 100644 --- a/src/gui/equipmentwindow.h +++ b/src/gui/equipmentwindow.h @@ -27,7 +27,6 @@ #include "window.h" class Equipment; -class Spriteset; /** * Equipment dialog. @@ -53,8 +52,6 @@ class EquipmentWindow : public Window void draw(gcn::Graphics *graphics); private: - Spriteset *mItemset; - Equipment *mEquipment; }; diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp index edcf9764..c7c55fd9 100644 --- a/src/gui/itemcontainer.cpp +++ b/src/gui/itemcontainer.cpp @@ -41,8 +41,6 @@ ItemContainer::ItemContainer(Inventory *inventory): mInventory(inventory) { ResourceManager *resman = ResourceManager::getInstance(); - mItemset = resman->getSpriteset("graphics/sprites/items.png", 32, 32); - if (!mItemset) logger->error("Unable to load items.png"); mSelImg = resman->getImage("graphics/gui/selection.png"); if (!mSelImg) logger->error("Unable to load selection.png"); @@ -55,7 +53,6 @@ ItemContainer::ItemContainer(Inventory *inventory): ItemContainer::~ItemContainer() { - mItemset->decRef(); mSelImg->decRef(); } @@ -73,8 +70,8 @@ void ItemContainer::logic() void ItemContainer::draw(gcn::Graphics* graphics) { - int gridWidth = mItemset->get(0)->getWidth() + 4; - int gridHeight = mItemset->get(0)->getHeight() + 10; + int gridWidth = 36; //(item icon width + 4) + int gridHeight = 42; //(item icon height + 10) int columns = getWidth() / gridWidth; // Have at least 1 column @@ -113,11 +110,11 @@ void ItemContainer::draw(gcn::Graphics* graphics) } // Draw item icon - int idx; - if ((idx = item->getInfo()->getImage()) > 0) + Image* image; + if ((image = item->getInfo()->getImage()) != NULL) { dynamic_cast(graphics)->drawImage( - mItemset->get(idx - 1), itemX, itemY); + image, itemX, itemY); } // Draw item caption @@ -133,8 +130,8 @@ void ItemContainer::setWidth(int width) { gcn::Widget::setWidth(width); - int gridWidth = mItemset->get(0)->getWidth() + 4; - int gridHeight = mItemset->get(0)->getHeight() + 14; + int gridWidth = 36; //item icon width + 4 + int gridHeight = 46; //item icon height + 14 int columns = getWidth() / gridWidth; if (columns < 1) @@ -158,8 +155,8 @@ void ItemContainer::selectNone() void ItemContainer::mousePress(int mx, int my, int button) { - int gridWidth = mItemset->get(0)->getWidth() + 4; - int gridHeight = mItemset->get(0)->getHeight() + 10; + int gridWidth = 36; //(item icon width + 4) + int gridHeight = 42; //(item icon height + 10) int columns = getWidth() / gridWidth; if (button == gcn::MouseInput::LEFT || gcn::MouseInput::RIGHT) diff --git a/src/gui/itemcontainer.h b/src/gui/itemcontainer.h index 63e8bf47..f52f37ec 100644 --- a/src/gui/itemcontainer.h +++ b/src/gui/itemcontainer.h @@ -30,7 +30,6 @@ class Image; class Inventory; class Item; -class Spriteset; /** * An item container. Used to show items in inventory and trade dialog. @@ -83,7 +82,6 @@ class ItemContainer : public gcn::Widget, public gcn::MouseListener private: Inventory *mInventory; - Spriteset *mItemset; Image *mSelImg; Item *mSelectedItem; diff --git a/src/resources/iteminfo.cpp b/src/resources/iteminfo.cpp new file mode 100644 index 00000000..5d39d832 --- /dev/null +++ b/src/resources/iteminfo.cpp @@ -0,0 +1,44 @@ +/* + * The Mana World + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include "iteminfo.h" + +#include "resourcemanager.h" + +Image* +ItemInfo::getImage() { + if (mImage == NULL && mImageName != "") { + mImage = ResourceManager::getInstance()->getImage(mImageName); + } + return mImage; +} + +void +ItemInfo::setImage(const std::string &image) { + mImageName = "graphics/items/" + image; +} + +ItemInfo::~ItemInfo() { + if (mImage != NULL){ + mImage->decRef(); + } +} diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h index 54e7907b..afa2e857 100644 --- a/src/resources/iteminfo.h +++ b/src/resources/iteminfo.h @@ -26,6 +26,8 @@ #include +#include "image.h" + /** * Defines a class for storing item infos. */ @@ -38,7 +40,8 @@ class ItemInfo * Constructor. */ ItemInfo(): - mImage(0), + mImage(NULL), + mImageName(""), mArt(0), mType(0), mWeight(0), @@ -59,10 +62,10 @@ class ItemInfo getName() { return mName; } void - setImage(short image) { mImage = image; } + setImage(const std::string &image); - short - getImage() { return mImage; } + Image* + getImage(); void setDescription(const std::string &description) @@ -101,9 +104,10 @@ class ItemInfo /** * Destructor. */ - ~ItemInfo() {} + ~ItemInfo(); - short mImage; + Image* mImage; + std::string mImageName; short mArt; std::string mName; std::string mDescription; diff --git a/src/resources/itemmanager.cpp b/src/resources/itemmanager.cpp index 63c0b036..a497b3c8 100644 --- a/src/resources/itemmanager.cpp +++ b/src/resources/itemmanager.cpp @@ -68,8 +68,8 @@ ItemManager::ItemManager() for (node = node->xmlChildrenNode; node != NULL; node = node->next) { - int id = 0, image = 0, art = 0, type = 0, weight = 0, slot = 0; - std::string name = "", description = "", effect = ""; + int id = 0, art = 0, type = 0, weight = 0, slot = 0; + std::string name = "", description = "", effect = "", image = ""; if (!xmlStrEqual(node->name, BAD_CAST "item")) { continue; @@ -77,7 +77,7 @@ ItemManager::ItemManager() xmlChar *prop = NULL; READ_PROP(node, prop, "id", id, atoi); - READ_PROP(node, prop, "image", image, atoi); + READ_PROP(node, prop, "image", image, ); READ_PROP(node, prop, "art", art, atoi); READ_PROP(node, prop, "name", name, ); READ_PROP(node, prop, "description", description, ); @@ -86,6 +86,7 @@ ItemManager::ItemManager() READ_PROP(node, prop, "weight", weight, atoi); READ_PROP(node, prop, "slot", slot, atoi); + if (id && name != "") { ItemInfo *itemInfo = new ItemInfo(); @@ -100,6 +101,7 @@ ItemManager::ItemManager() mItemInfos[id] = itemInfo; } + if (id == 0) { logger->log("Item Manager: An item has no ID in items.xml!"); @@ -109,7 +111,7 @@ ItemManager::ItemManager() logger->log("Item Manager: An item has no name in items.xml!"); } - if (image == 0) + if (image == "") { logger->log("Item Manager: Missing image parameter for item: %i. %s", id, name.c_str()); @@ -141,7 +143,7 @@ ItemManager::ItemManager() } if (slot == 0) { - logger->log("Item Manager: Missing image parameter for item: %i. %s", + logger->log("Item Manager: Missing slot parameter for item: %i. %s", id, name.c_str()); } -- cgit v1.2.3-70-g09d2