summaryrefslogtreecommitdiff
path: root/src/gui/equipmentwindow.cpp
diff options
context:
space:
mode:
authorDennis Friis <peavey@placid.dk>2008-11-06 16:46:18 +0000
committerDennis Friis <peavey@placid.dk>2008-11-06 16:46:18 +0000
commit87f43f7621dda3071ba189df6975cd0a0595165a (patch)
treefa5cf0603bbcc4ecb4506dd357124975a8534503 /src/gui/equipmentwindow.cpp
parent9475a009e95a3f379a0e97bc66d1aab93ca24b34 (diff)
downloadmana-87f43f7621dda3071ba189df6975cd0a0595165a.tar.gz
mana-87f43f7621dda3071ba189df6975cd0a0595165a.tar.bz2
mana-87f43f7621dda3071ba189df6975cd0a0595165a.tar.xz
mana-87f43f7621dda3071ba189df6975cd0a0595165a.zip
Have equipment tied into player inventory instead of keeping its own list of pointers to items. This ensures the ressource is up-to-date and avoids crashes on stale item pointers.
Diffstat (limited to 'src/gui/equipmentwindow.cpp')
-rw-r--r--src/gui/equipmentwindow.cpp20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp
index 93b9ea37..3ea2fcbc 100644
--- a/src/gui/equipmentwindow.cpp
+++ b/src/gui/equipmentwindow.cpp
@@ -24,6 +24,8 @@
#include "equipmentwindow.h"
#include "../equipment.h"
+#include "../inventory.h"
+#include "../localplayer.h"
#include "../graphics.h"
#include "../item.h"
#include "../log.h"
@@ -40,6 +42,7 @@ EquipmentWindow::EquipmentWindow(Equipment *equipment):
setCloseButton(true);
setDefaultSize(5, 230, 200, 120);
loadWindowState();
+ inventory = player_node->getInventory();
}
EquipmentWindow::~EquipmentWindow()
@@ -61,22 +64,27 @@ void EquipmentWindow::draw(gcn::Graphics *graphics)
graphics->drawRectangle(gcn::Rectangle(10 + 36 * (i % 4),
36 * (i / 4) + 25, 32, 32));
- if (!(item = mEquipment->getEquipment(i)))
+ if (!(item = inventory->getItem(mEquipment->getEquipment(i))))
continue;
image = item->getImage();
- static_cast<Graphics*>(graphics)->drawImage(
- image, 36 * (i % 4) + 10, 36 * (i / 4) + 25);
+ if (image)
+ {
+ static_cast<Graphics*>(graphics)->drawImage(
+ image, 36 * (i % 4) + 10, 36 * (i / 4) + 25);
+ }
}
graphics->drawRectangle(gcn::Rectangle(160, 25, 32, 32));
- if (!(item = mEquipment->getArrows()))
+ if (!(item = inventory->getItem(mEquipment->getArrows())))
return;
image = item->getImage();
-
- static_cast<Graphics*>(graphics)->drawImage(image, 160, 25);
+ if (image)
+ {
+ static_cast<Graphics*>(graphics)->drawImage(image, 160, 25);
+ }
graphics->drawText(toString(item->getQuantity()), 170, 62,
gcn::Graphics::CENTER);
}