summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--src/gui/itemcontainer.cpp4
-rw-r--r--src/gui/itemshortcutcontainer.cpp14
-rw-r--r--src/itemshortcut.cpp20
-rw-r--r--src/itemshortcut.h32
-rw-r--r--src/net/inventoryhandler.cpp1
6 files changed, 43 insertions, 35 deletions
diff --git a/ChangeLog b/ChangeLog
index 48388b16..76c545bb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2008-04-24 Dennis Friis <peavey@placid.dk>
+
+ * src/itemshortcut.h, src/gui/itemshortcutcontainer.cpp,
+ src/gui/itemcontainer.cpp, src/net/inventoryhandler.cpp,
+ src/itemshortcut.cpp: Make shortcut container ID based instead of slot
+ based. Fixes items shifting around often causing equipment to be lost.
+
2008-04-22 Bjørn Lindeijer <bjorn@lindeijer.nl>
* src/beingmanager.cpp: Fixed a bug, thanks GCC 4.3!
diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp
index ad0674f4..a6348d01 100644
--- a/src/gui/itemcontainer.cpp
+++ b/src/gui/itemcontainer.cpp
@@ -197,7 +197,7 @@ ItemContainer::mousePressed(gcn::MouseEvent &event)
int my = event.getY();
int index = mx / gridWidth + ((my / gridHeight) * columns) + 2;
- itemShortcut->setItemSelected(NULL);
+ itemShortcut->setItemSelected(-1);
// Fix for old server, it should be: if (index >= mMaxItems)
if (index > mMaxItems + 1)
{
@@ -208,7 +208,7 @@ ItemContainer::mousePressed(gcn::MouseEvent &event)
setSelectedItem(item);
if (!item->isEquipment())
{
- itemShortcut->setItemSelected(item);
+ itemShortcut->setItemSelected(item->getId());
}
}
}
diff --git a/src/gui/itemshortcutcontainer.cpp b/src/gui/itemshortcutcontainer.cpp
index 3c03d85a..4c376718 100644
--- a/src/gui/itemshortcutcontainer.cpp
+++ b/src/gui/itemshortcutcontainer.cpp
@@ -23,6 +23,7 @@
#include "itemshortcutcontainer.h"
+#include "../localplayer.h"
#include "../graphics.h"
#include "../item.h"
#include "../itemshortcut.h"
@@ -87,7 +88,10 @@ ItemShortcutContainer::draw(gcn::Graphics *graphics)
(SDLKey) keyboard.getKeyValue(keyboard.KEY_SHORTCUT_0+i));
g->drawText(key, itemX + 2, itemY + 2, gcn::Graphics::LEFT);
- Item *item = itemShortcut->getItem(i);
+ if (itemShortcut->getItem(i) < 0)
+ continue;
+
+ Item *item = player_node->searchForItem(itemShortcut->getItem(i));
if (item) {
// Draw item icon.
Image* image = item->getInfo().getImage();
@@ -145,7 +149,7 @@ ItemShortcutContainer::mouseDragged(gcn::MouseEvent &event)
if (index == -1) {
return;
}
- Item *item = itemShortcut->getItem(index);
+ Item *item = player_node->searchForItem(itemShortcut->getItem(index));
if (item)
{
mItemMoved = item;
@@ -170,7 +174,7 @@ ItemShortcutContainer::mousePressed(gcn::MouseEvent &event)
// Stores the selected item if theirs one.
if (itemShortcut->isItemSelected()) {
itemShortcut->setItem(index);
- itemShortcut->setItemSelected(NULL);
+ itemShortcut->setItemSelected(-1);
}
else if (itemShortcut->getItem(index)) {
mItemClicked = true;
@@ -184,7 +188,7 @@ ItemShortcutContainer::mouseReleased(gcn::MouseEvent &event)
{
if (itemShortcut->isItemSelected())
{
- itemShortcut->setItemSelected(NULL);
+ itemShortcut->setItemSelected(-1);
}
const int index = getIndexFromGrid(event.getX(), event.getY());
if (index == -1) {
@@ -192,7 +196,7 @@ ItemShortcutContainer::mouseReleased(gcn::MouseEvent &event)
return;
}
if (mItemMoved) {
- itemShortcut->setItems(index, mItemMoved);
+ itemShortcut->setItems(index, mItemMoved->getId());
mItemMoved = NULL;
}
else if (itemShortcut->getItem(index) && mItemClicked)
diff --git a/src/itemshortcut.cpp b/src/itemshortcut.cpp
index 931ce6f2..1201b23b 100644
--- a/src/itemshortcut.cpp
+++ b/src/itemshortcut.cpp
@@ -32,12 +32,13 @@
ItemShortcut::ItemShortcut *itemShortcut;
ItemShortcut::ItemShortcut():
- mItemSelected(NULL)
+ mItemSelected(-1)
{
for (int i = 0; i < SHORTCUT_ITEMS; i++)
{
- mItems[i] = NULL;
+ mItems[i] = -1;
}
+ load();
}
ItemShortcut::~ItemShortcut()
@@ -49,15 +50,11 @@ void ItemShortcut::load()
{
for (int i = 0; i < SHORTCUT_ITEMS; i++)
{
- int itemId = (int) config.getValue("itemShortcut" + toString(i), -1);
+ int itemId = (int) config.getValue("shortcut" + toString(i), -1);
if (itemId != -1)
{
- Item* item = player_node->searchForItem(itemId);
- if (item)
- {
- mItems[i] = item;
- }
+ mItems[i] = itemId;
}
}
}
@@ -68,7 +65,7 @@ void ItemShortcut::save()
{
if (mItems[i])
{
- config.setValue("shortcut" + toString(i), mItems[i]->getId());
+ config.setValue("shortcut" + toString(i), mItems[i]);
}
else
{
@@ -81,8 +78,9 @@ void ItemShortcut::useItem(int index)
{
if (mItems[index])
{
- if (mItems[index]->getQuantity()) {
- player_node->useItem(mItems[index]);
+ Item *item = player_node->searchForItem(mItems[index]);
+ if (item && item->getQuantity()) {
+ player_node->useItem(item);
}
}
}
diff --git a/src/itemshortcut.h b/src/itemshortcut.h
index fecb7d86..d75db2e8 100644
--- a/src/itemshortcut.h
+++ b/src/itemshortcut.h
@@ -50,11 +50,11 @@ class ItemShortcut
void load();
/**
- * Returns the shortcut item specified by the index.
+ * Returns the shortcut item ID specified by the index.
*
* @param index Index of the shortcut item.
*/
- Item* getItem(int index) const
+ int getItem(int index) const
{ return mItems[index]; }
/**
@@ -64,13 +64,13 @@ class ItemShortcut
{ return SHORTCUT_ITEMS; }
/**
- * Returns the item that is currently selected.
+ * Returns the item ID that is currently selected.
*/
- Item* getItemSelected() const
+ int getItemSelected() const
{ return mItemSelected; }
/**
- * Adds the selected item to the items specified by the index.
+ * Adds the selected item ID to the items specified by the index.
*
* @param index Index of the items.
*/
@@ -80,31 +80,31 @@ class ItemShortcut
/**
* Adds an item to the items store specified by the index.
*
- * @param index Index of the items.
- * @param item Item to store.
+ * @param index Index of the item.
+ * @param itemId ID of the item.
*/
- void setItems(int index, Item *item)
- { mItems[index] = item; }
+ void setItems(int index, int itemId)
+ { mItems[index] = itemId; }
/**
* Set the item that is selected.
*
- * @param item The item that is to be assigned.
+ * @param itemId The ID of the item that is to be assigned.
*/
- void setItemSelected(Item* item)
- { mItemSelected = item; }
+ void setItemSelected(int itemId)
+ { mItemSelected = itemId; }
/**
* A flag to check if the item is selected.
*/
bool isItemSelected()
- { return mItemSelected; }
+ { return mItemSelected > -1; }
/**
* Remove a item from the shortcut.
*/
void removeItem(int index)
- { mItems[index] = 0; }
+ { mItems[index] = -1; }
/**
* Try to use the item specified by the index.
@@ -119,8 +119,8 @@ class ItemShortcut
*/
void save();
- Item* mItems[SHORTCUT_ITEMS]; /**< The items stored. */
- Item* mItemSelected; /**< The item held by cursor. */
+ int mItems[SHORTCUT_ITEMS]; /**< The items stored. */
+ int mItemSelected; /**< The item held by cursor. */
};
diff --git a/src/net/inventoryhandler.cpp b/src/net/inventoryhandler.cpp
index 7ed7e38d..a2190c1e 100644
--- a/src/net/inventoryhandler.cpp
+++ b/src/net/inventoryhandler.cpp
@@ -80,7 +80,6 @@ void InventoryHandler::handleMessage(MessageIn *msg)
player_node->getInvItem(index)->setEquipment(true);
}
}
- itemShortcut->load();
break;
case SMSG_PLAYER_INVENTORY_ADD: