summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2008-11-01 14:55:54 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2008-11-01 14:55:54 +0000
commit55e0ddd7e1d60a56ece679a4c2563bef854e892b (patch)
tree322df9b8661f379990b3b526e5aa41f0e23ec9e2 /src
parent3d85803d9a43c779f522a936df068a24ca6f7f2d (diff)
downloadmana-55e0ddd7e1d60a56ece679a4c2563bef854e892b.tar.gz
mana-55e0ddd7e1d60a56ece679a4c2563bef854e892b.tar.bz2
mana-55e0ddd7e1d60a56ece679a4c2563bef854e892b.tar.xz
mana-55e0ddd7e1d60a56ece679a4c2563bef854e892b.zip
Merged revisions 4180-4181 via svnmerge from
https://themanaworld.svn.sourceforge.net/svnroot/themanaworld/tmw/branches/0.0 ........ r4180 | peaveydk | 2008-04-24 22:49:30 +0200 (Thu, 24 Apr 2008) | 1 line Make shortcut container ID based instead of slot based. Fixes items shifting around often causing equipment to be lost. ........ r4181 | peaveydk | 2008-04-25 02:25:59 +0200 (Fri, 25 Apr 2008) | 1 line Document anti-trade function. ........
Diffstat (limited to 'src')
-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
4 files changed, 34 insertions, 33 deletions
diff --git a/src/gui/itemshortcutcontainer.cpp b/src/gui/itemshortcutcontainer.cpp
index e8cc5711..a54e3678 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->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 12ae95f2..59c1ee3b 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,9 +78,10 @@ void ItemShortcut::useItem(int index)
{
if (mItems[index])
{
- if (mItems[index]->getQuantity()) {
+ Item *item = player_node->searchForItem(mItems[index]);
+ if (item && item->getQuantity()) {
// TODO: Fix this (index vs. pointer mismatch)
- //player_node->useItem(mItems[index]);
+ //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 d48a77a5..dde6a954 100644
--- a/src/net/inventoryhandler.cpp
+++ b/src/net/inventoryhandler.cpp
@@ -76,7 +76,6 @@ void InventoryHandler::handleMessage(MessageIn &msg)
player_node->setInvItem(slot - 32, id, amount);
}
};
- itemShortcut->load();
break;
}
}