diff options
author | Ira Rice <irarice@gmail.com> | 2009-01-20 09:37:46 -0700 |
---|---|---|
committer | Ira Rice <irarice@gmail.com> | 2009-01-20 09:37:46 -0700 |
commit | 114559b98b7e8c94b1d84d4d450309fd16ed2a38 (patch) | |
tree | 1f03c1a8eca687bc7feeaa503ff64a7bda8eee6e /src/gui/itemshortcutcontainer.cpp | |
parent | d1b38ab0264bf922fc5e12e9328eea49cee132c3 (diff) | |
download | mana-114559b98b7e8c94b1d84d4d450309fd16ed2a38.tar.gz mana-114559b98b7e8c94b1d84d4d450309fd16ed2a38.tar.bz2 mana-114559b98b7e8c94b1d84d4d450309fd16ed2a38.tar.xz mana-114559b98b7e8c94b1d84d4d450309fd16ed2a38.zip |
Modified the item shortcut bar to show item popups based on a suggestion
made by Jarvellis.
Signed-off-by: Ira Rice <irarice@gmail.com>
Diffstat (limited to 'src/gui/itemshortcutcontainer.cpp')
-rw-r--r-- | src/gui/itemshortcutcontainer.cpp | 82 |
1 files changed, 67 insertions, 15 deletions
diff --git a/src/gui/itemshortcutcontainer.cpp b/src/gui/itemshortcutcontainer.cpp index e66dc04f..950c042a 100644 --- a/src/gui/itemshortcutcontainer.cpp +++ b/src/gui/itemshortcutcontainer.cpp @@ -43,6 +43,8 @@ ItemShortcutContainer::ItemShortcutContainer(): addMouseListener(this); addWidgetListener(this); + mItemPopup = new ItemPopup(); + ResourceManager *resman = ResourceManager::getInstance(); mBackgroundImg = resman->getImage("graphics/gui/item_shortcut_bgr.png"); @@ -134,16 +136,21 @@ void ItemShortcutContainer::draw(gcn::Graphics *graphics) void ItemShortcutContainer::mouseDragged(gcn::MouseEvent &event) { - if (event.getButton() == gcn::MouseEvent::LEFT) { - if (!mItemMoved && mItemClicked) { + if (event.getButton() == gcn::MouseEvent::LEFT) + { + if (!mItemMoved && mItemClicked) + { const int index = getIndexFromGrid(event.getX(), event.getY()); - if (index == -1) { - return; - } const int itemId = itemShortcut->getItem(index); + + if (index == -1) + return; + if (itemId < 0) return; + Item *item = player_node->getInventory()->findItem(itemId); + if (item) { mItemMoved = item; @@ -160,18 +167,17 @@ void ItemShortcutContainer::mouseDragged(gcn::MouseEvent &event) void ItemShortcutContainer::mousePressed(gcn::MouseEvent &event) { const int index = getIndexFromGrid(event.getX(), event.getY()); - if (index == -1) { + if (index == -1) return; - } // Stores the selected item if theirs one. - if (itemShortcut->isItemSelected()) { + if (itemShortcut->isItemSelected()) + { itemShortcut->setItem(index); itemShortcut->setItemSelected(-1); } - else if (itemShortcut->getItem(index)) { + else if (itemShortcut->getItem(index)) mItemClicked = true; - } } void ItemShortcutContainer::mouseReleased(gcn::MouseEvent &event) @@ -179,15 +185,16 @@ void ItemShortcutContainer::mouseReleased(gcn::MouseEvent &event) if (event.getButton() == gcn::MouseEvent::LEFT) { if (itemShortcut->isItemSelected()) - { itemShortcut->setItemSelected(-1); - } + const int index = getIndexFromGrid(event.getX(), event.getY()); - if (index == -1) { + if (index == -1) + { mItemMoved = NULL; return; } - if (mItemMoved) { + if (mItemMoved) + { itemShortcut->setItems(index, mItemMoved->getId()); mItemMoved = NULL; } @@ -195,9 +202,54 @@ void ItemShortcutContainer::mouseReleased(gcn::MouseEvent &event) { itemShortcut->useItem(index); } - if (mItemClicked) { + if (mItemClicked) mItemClicked = false; + } +} + +// Show ItemTooltip +void ItemShortcutContainer::mouseMoved(gcn::MouseEvent &event) +{ + const int index = getIndexFromGrid(event.getX(), event.getY()); + const int itemId = itemShortcut->getItem(index); + + if (index == -1) + return; + + if (itemId < 0) + return; + + Item *item = player_node->getInventory()->findItem(itemId); + + if (item) + { + if (getParent()->getParent()->getWidth() < + getParent()->getParent()->getHeight()) + { + mItemPopup->setPosition(getParent()->getParent()->getX() - + mItemPopup->getWidth(), + getParent()->getParent()->getY()); } + else + { + mItemPopup->setPosition(getParent()->getParent()->getX(), + getParent()->getParent()->getY() + + getParent()->getParent()->getHeight()); + } + + mItemPopup->setItem(item->getInfo()); + mItemPopup->setOpaque(false); + mItemPopup->setVisible(true); } + else + { + mItemPopup->setVisible(false); + } +} + +// Hide ItemTooltip +void ItemShortcutContainer::mouseExited(gcn::MouseEvent &event) +{ + mItemPopup->setVisible(false); } |