summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2005-05-21 22:39:53 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2005-05-21 22:39:53 +0000
commite4e3f73db10d345453f2c6d06ae1dc499a4c7404 (patch)
tree7117443cf1267f9354206c21d70ac4ae0ddefcec
parent241e2461446a830194f202b840abcd3598f804a5 (diff)
downloadmana-e4e3f73db10d345453f2c6d06ae1dc499a4c7404.tar.gz
mana-e4e3f73db10d345453f2c6d06ae1dc499a4c7404.tar.bz2
mana-e4e3f73db10d345453f2c6d06ae1dc499a4c7404.tar.xz
mana-e4e3f73db10d345453f2c6d06ae1dc499a4c7404.zip
Numerous things:
* Fixed two non-virtual destructor warnings showing up with GCC 4. * Fixed OpenGL inventory text drawing that broke in last commit * Removed glClear cause screen is redrawn completely anyway * Fixed updating of buttons in inventory window * Made items.xml be loaded through resource manager.
-rw-r--r--src/configuration.cpp6
-rw-r--r--src/configuration.h12
-rw-r--r--src/game.cpp21
-rw-r--r--src/graphics.cpp1
-rw-r--r--src/gui/inventory.cpp20
-rw-r--r--src/gui/inventory.h17
-rw-r--r--src/gui/itemcontainer.cpp3
-rw-r--r--src/gui/itemcontainer.h4
-rw-r--r--src/gui/scrollarea.cpp12
-rw-r--r--src/resources/image.h1
-rw-r--r--src/resources/itemmanager.cpp20
-rw-r--r--src/resources/resource.cpp5
-rw-r--r--src/resources/resource.h5
13 files changed, 79 insertions, 48 deletions
diff --git a/src/configuration.cpp b/src/configuration.cpp
index 54fe3a1d..e3552a5a 100644
--- a/src/configuration.cpp
+++ b/src/configuration.cpp
@@ -41,6 +41,10 @@
#define xmlFree(x) ;
#endif
+ConfigListener::~ConfigListener()
+{
+}
+
void Configuration::init(const std::string &filename)
{
configPath = filename;
@@ -185,7 +189,7 @@ void Configuration::removeListener(
const std::string &key, ConfigListener *listener)
{
std::list<ConfigListener*>::iterator i = listeners[key].begin();
-
+
while (i != listeners[key].end())
{
if ((*i) == listener) {
diff --git a/src/configuration.h b/src/configuration.h
index 719ee711..75699f30 100644
--- a/src/configuration.h
+++ b/src/configuration.h
@@ -38,6 +38,15 @@
class ConfigListener
{
public:
+ /**
+ * Destructor.
+ */
+ virtual ~ConfigListener();
+
+ /**
+ * Called when an option changed. The config listener will have to be
+ * registered to the option name first.
+ */
virtual void optionChanged(const std::string &name) = 0;
};
@@ -46,7 +55,8 @@ class ConfigListener
*
* \ingroup CORE
*/
-class Configuration {
+class Configuration
+{
public:
/**
* \brief Reads INI file and parse all options into memory.
diff --git a/src/game.cpp b/src/game.cpp
index c02bcccb..bc56578a 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -859,12 +859,11 @@ void do_parse()
switch (RFIFOB(6)) {
case 0:
// Successfully added item
- if (inventoryWindow->items->isEquipment(RFIFOW(2)))
+ if (inventoryWindow->items->isEquipment(RFIFOW(2))
+ && inventoryWindow->items->isEquipped(
+ RFIFOW(2)))
{
- if (inventoryWindow->items->isEquipped(RFIFOW(2)))
- {
- inventoryWindow->unequipItem(RFIFOW(2));
- }
+ inventoryWindow->unequipItem(RFIFOW(2));
}
tradeWindow->addItem(
tradeWindow->myItems->getFreeSlot(),
@@ -922,14 +921,16 @@ void do_parse()
for (int loop = 0; loop < (RFIFOW(2) - 4) / 18; loop++)
{
- inventoryWindow->addItem(RFIFOW(4 + loop * 18),
+ inventoryWindow->addItem(RFIFOW(4 + loop * 18),
RFIFOW(4 + loop * 18 + 2),
RFIFOW(4 + loop * 18 + 6), false);
// Trick because arrows are not considered equipment
if (RFIFOW(4 + loop * 18 + 2) == 1199 ||
RFIFOW(4 + loop * 18 + 2) == 529)
+ {
inventoryWindow->items->setEquipment(
RFIFOW(4 + loop * 18), true);
+ }
/*char info[40];
sprintf(info, "1ee %i", RFIFOW(4+loop*18+2));
chatWindow->chat_log(info, BY_SERVER);*/
@@ -948,7 +949,7 @@ void do_parse()
RFIFOB(4+loop*20+4), RFIFOB(4+loop*20+5),
RFIFOW(4+loop*20+6), RFIFOW(4+loop*20+8),
RFIFOB(4+loop*20+10), RFIFOB(4+loop*20+11));
- chatWindow->chat_log(info, BY_SERVER);*/
+ chatWindow->chat_log(info, BY_SERVER);*/
if (RFIFOW(4 + loop * 20 + 8))
{
int mask = 1;
@@ -958,13 +959,13 @@ void do_parse()
position++;
}
/*sprintf(info, "%i %i", mask, position);
- chatWindow->chat_log(info, BY_SERVER);*/
+ chatWindow->chat_log(info, BY_SERVER);*/
equipmentWindow->addEquipment(position - 1,
- RFIFOW(4+loop*20+2));
+ RFIFOW(4+loop*20+2));
equipmentWindow->equipments[position - 1].inventoryIndex =
RFIFOW(4+loop*20);
inventoryWindow->items->setEquipped(
- RFIFOW(4+loop*20), true);
+ RFIFOW(4+loop*20), true);
}
}
break;
diff --git a/src/graphics.cpp b/src/graphics.cpp
index 4e43b4b5..8829e4e9 100644
--- a/src/graphics.cpp
+++ b/src/graphics.cpp
@@ -146,7 +146,6 @@ void Graphics::updateScreen()
glFlush();
glFinish();
SDL_GL_SwapBuffers();
- glClear(GL_COLOR_BUFFER_BIT);
}
else {
SDL_Flip(screen);
diff --git a/src/gui/inventory.cpp b/src/gui/inventory.cpp
index 4a1c0ca3..f73c240e 100644
--- a/src/gui/inventory.cpp
+++ b/src/gui/inventory.cpp
@@ -76,6 +76,13 @@ InventoryWindow::~InventoryWindow()
delete itemDescriptionLabel;
}
+void InventoryWindow::logic()
+{
+ // It would be nicer if this update could be event based, needs some
+ // redesign of InventoryWindow and ItemContainer probably.
+ updateButtons();
+}
+
int InventoryWindow::addItem(int index, int id, int quantity, bool equipment)
{
items->addItem(index, id, quantity, equipment);
@@ -90,14 +97,12 @@ int InventoryWindow::removeItem(int id)
int InventoryWindow::changeQuantity(int index, int quantity)
{
- //items[index].quantity = quantity;
items->changeQuantity(index, quantity);
return 0;
}
int InventoryWindow::increaseQuantity(int index, int quantity)
{
- //items[index].quantity += quantity;
items->increaseQuantity(index, quantity);
return 0;
}
@@ -147,8 +152,8 @@ void InventoryWindow::action(const std::string &eventId)
if (selectedItem != -1) {
if (eventId == "use") {
- if(items->isEquipment(selectedItem)) {
- if(items->isEquipped(selectedItem)) {
+ if (items->isEquipment(selectedItem)) {
+ if (items->isEquipped(selectedItem)) {
unequipItem(selectedItem);
}
else {
@@ -164,8 +169,6 @@ void InventoryWindow::action(const std::string &eventId)
// Choose amount of items to drop
new ItemAmountWindow(AMOUNT_ITEM_DROP, this);
}
-
- updateUseButton();
}
}
@@ -173,8 +176,6 @@ void InventoryWindow::mouseClick(int x, int y, int button, int count)
{
Window::mouseClick(x, y, button, count);
- updateUseButton();
-
if (items->getIndex() != -1)
{
// Show Name and Description
@@ -213,7 +214,7 @@ void InventoryWindow::updateWidgets()
setContentSize(getWidth(), getHeight());
}
-void InventoryWindow::updateUseButton()
+void InventoryWindow::updateButtons()
{
if (items->getIndex() != -1 && items->isEquipment(items->getIndex()))
{
@@ -229,4 +230,5 @@ void InventoryWindow::updateUseButton()
}
useButton->setEnabled(items->getIndex() != -1);
+ dropButton->setEnabled(items->getIndex() != -1);
}
diff --git a/src/gui/inventory.h b/src/gui/inventory.h
index 43a23ede..37edff7f 100644
--- a/src/gui/inventory.h
+++ b/src/gui/inventory.h
@@ -37,7 +37,8 @@
*
* \ingroup Interface
*/
-class InventoryWindow : public Window, gcn::ActionListener {
+class InventoryWindow : public Window, gcn::ActionListener
+{
public:
/**
* Constructor.
@@ -50,6 +51,11 @@ class InventoryWindow : public Window, gcn::ActionListener {
~InventoryWindow();
/**
+ * Logic (updates buttons)
+ */
+ void logic();
+
+ /**
* Add an item the inventory.
*/
int addItem(int index, int id, int quantity, bool equipment);
@@ -58,14 +64,17 @@ class InventoryWindow : public Window, gcn::ActionListener {
* Remove a item from the inventory.
*/
int removeItem(int id);
-
+
+ /**
+ * Equips an item.
+ */
void equipItem(int index);
/**
* Unequips an item.
*/
void unequipItem(int index);
-
+
/**
* Change quantity of an item.
*/
@@ -94,7 +103,7 @@ class InventoryWindow : public Window, gcn::ActionListener {
int useItem(int index, int id);
void updateWidgets(); /** Updates widgets size/position */
- void updateUseButton(); /** Updates use button to selected item */
+ void updateButtons(); /** Updates button states */
gcn::Label *itemNameLabel;
gcn::Label *itemDescriptionLabel;
diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp
index a5c70632..d571f739 100644
--- a/src/gui/itemcontainer.cpp
+++ b/src/gui/itemcontainer.cpp
@@ -32,6 +32,7 @@ ItemContainer::ItemContainer()
Image *itemImg = resman->getImage("graphics/sprites/items.png", IMG_ALPHA);
if (!itemImg) logger->error("Unable to load items.png");
itemset = new Spriteset(itemImg, 20, 20);
+ itemImg->decRef();
selImg = resman->getImage("graphics/gui/selection.png", IMG_ALPHA);
if (!selImg) logger->error("Unable to load selection.png");
@@ -50,6 +51,8 @@ ItemContainer::ItemContainer()
ItemContainer::~ItemContainer()
{
+ delete itemset;
+ selImg->decRef();
}
void ItemContainer::draw(gcn::Graphics* graphics)
diff --git a/src/gui/itemcontainer.h b/src/gui/itemcontainer.h
index 97c17924..9ee6892a 100644
--- a/src/gui/itemcontainer.h
+++ b/src/gui/itemcontainer.h
@@ -117,12 +117,12 @@ class ItemContainer : public gcn::Widget, public gcn::MouseListener
* Adds a new item.
*/
void addItem(int index, int id, int quantity, bool equipment);
-
+
/**
* Set selected item to -1.
*/
void selectNone();
-
+
/**
* Reset all item slots.
*/
diff --git a/src/gui/scrollarea.cpp b/src/gui/scrollarea.cpp
index a5c5542f..ad31ada8 100644
--- a/src/gui/scrollarea.cpp
+++ b/src/gui/scrollarea.cpp
@@ -277,26 +277,18 @@ void ScrollArea::drawRightButton(gcn::Graphics *graphics)
void ScrollArea::drawVBar(gcn::Graphics *graphics)
{
- //int x, y;
gcn::Rectangle dim = getVerticalBarDimension();
- //getAbsolutePosition(x, y);
-
graphics->setColor(gcn::Color(0, 0, 0, 32));
graphics->fillRectangle(dim);
- //((Graphics*)graphics)->drawImageRect(
- // x + dim.x, y + dim.y, dim.width, dim.height, background);
+ graphics->setColor(gcn::Color(255, 255, 255));
}
void ScrollArea::drawHBar(gcn::Graphics *graphics)
{
- //int x, y;
gcn::Rectangle dim = getHorizontalBarDimension();
- //getAbsolutePosition(x, y);
-
graphics->setColor(gcn::Color(0, 0, 0, 32));
graphics->fillRectangle(dim);
- //((Graphics*)graphics)->drawImageRect(
- // x + dim.x, y + dim.y, dim.width, dim.height, background);
+ graphics->setColor(gcn::Color(255, 255, 255));
}
void ScrollArea::drawVMarker(gcn::Graphics *graphics)
diff --git a/src/resources/image.h b/src/resources/image.h
index 807f0fb0..ebc2c971 100644
--- a/src/resources/image.h
+++ b/src/resources/image.h
@@ -155,7 +155,6 @@ class SubImage : public Image
/**
* Constructor.
*/
- //SubImage(SDL_Surface *timage, int x, int y, int width, int height);
#ifndef USE_OPENGL
SubImage(Image *parent, SDL_Surface *image,
int x, int y, int width, int height);
diff --git a/src/resources/itemmanager.cpp b/src/resources/itemmanager.cpp
index 05b0ff44..8ac05e08 100644
--- a/src/resources/itemmanager.cpp
+++ b/src/resources/itemmanager.cpp
@@ -26,6 +26,7 @@
#include <iostream>
#include "itemmanager.h"
+#include "resourcemanager.h"
#include "../main.h"
#include "../log.h"
@@ -38,16 +39,16 @@
ItemManager::ItemManager()
{
- // Check that file exists before trying to parse it
- std::fstream dbFile;
- dbFile.open(TMW_DATADIR "data/items.xml", std::ios::in);
- if (!dbFile.is_open()) {
- logger->error("Cannot find item database (items.xml)!");
- return;
+ ResourceManager *resman = ResourceManager::getInstance();
+ int size;
+ char *data = (char*)resman->loadFile("items.xml", size);
+
+ if (!data) {
+ logger->error("Could not find items.xml!");
}
- dbFile.close();
- xmlDocPtr doc = xmlParseFile(TMW_DATADIR "data/items.xml");
+ xmlDocPtr doc = xmlParseMemory(data, size);
+ free(data);
if (doc) {
xmlNodePtr node = xmlDocGetRootElement(doc);
@@ -104,7 +105,8 @@ ItemManager::ItemManager()
}
xmlFreeDoc(doc);
- } else {
+ }
+ else {
logger->error("Error while parsing item database (items.xml)!");
}
diff --git a/src/resources/resource.cpp b/src/resources/resource.cpp
index ad76f266..b3aa80f6 100644
--- a/src/resources/resource.cpp
+++ b/src/resources/resource.cpp
@@ -28,6 +28,11 @@ Resource::Resource():
{
}
+Resource::~Resource()
+{
+ // TODO: Notify resource manager about this resource being deleted
+}
+
bool Resource::isLoaded() const
{
return loaded;
diff --git a/src/resources/resource.h b/src/resources/resource.h
index bd6bfcc5..266b4198 100644
--- a/src/resources/resource.h
+++ b/src/resources/resource.h
@@ -36,6 +36,11 @@ class Resource
Resource();
/**
+ * Destructor.
+ */
+ virtual ~Resource();
+
+ /**
* Frees this objects internal resources.
*/
virtual void unload() = 0;