diff options
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | data/help/commands.txt | 1 | ||||
-rw-r--r-- | src/gui/itemshortcutcontainer.cpp | 14 | ||||
-rw-r--r-- | src/itemshortcut.cpp | 20 | ||||
-rw-r--r-- | src/itemshortcut.h | 32 | ||||
-rw-r--r-- | src/net/inventoryhandler.cpp | 1 |
6 files changed, 43 insertions, 33 deletions
@@ -493,6 +493,14 @@ * src/game.cpp, src/gui/partywindow.h, src/gui/partywindow.cpp, tmw.cbp: Added party window, updated codeblocks project file. +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. + * data/help/commands.txt: Document anti-trade function. + 2008-04-23 David Athay <ko2fan@gmail.com> * src/gui/guildwindow.h, src/net/partyhandler.h, diff --git a/data/help/commands.txt b/data/help/commands.txt index ab93b54e..f663068f 100644 --- a/data/help/commands.txt +++ b/data/help/commands.txt @@ -23,6 +23,7 @@ ##2Alt + S##P sit down / stand up ##2Alt + F##P toggle debug pathfinding feature ##2Alt + P##P take screenshot + ##2Alt + T##P toggle ignore of incoming trades ##2A##P target nearest monster ##2H##P hide all non-sticky windows ##2G or Z##P pick up item 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; } } |