summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/engine.cpp4
-rw-r--r--src/floor_item.cpp5
-rw-r--r--src/floor_item.h1
-rw-r--r--src/gui/equipmentwindow.cpp9
-rw-r--r--src/gui/equipmentwindow.h3
-rw-r--r--src/gui/itemcontainer.cpp21
-rw-r--r--src/gui/itemcontainer.h2
-rw-r--r--src/resources/iteminfo.cpp44
-rw-r--r--src/resources/iteminfo.h16
-rw-r--r--src/resources/itemmanager.cpp12
10 files changed, 75 insertions, 42 deletions
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<Spriteset *> 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*>(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*>(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*>(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 <string>
+#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());
}