diff options
author | Forge <jgrimbert@free.fr> | 2009-01-09 00:03:53 +0100 |
---|---|---|
committer | Forge <jgrimbert@free.fr> | 2009-01-09 00:03:53 +0100 |
commit | 611210b1e0fd9cbaed38b229462e109d8f4be385 (patch) | |
tree | d2fc4f7465ccd611e918a8905d7478aacd458acb /src/gui/smileyshortcutcontainer.cpp | |
parent | 0b2e6c53a158b820a3e3610372c98185a4dce30a (diff) | |
download | mana-611210b1e0fd9cbaed38b229462e109d8f4be385.tar.gz mana-611210b1e0fd9cbaed38b229462e109d8f4be385.tar.bz2 mana-611210b1e0fd9cbaed38b229462e109d8f4be385.tar.xz mana-611210b1e0fd9cbaed38b229462e109d8f4be385.zip |
Now, the real stage 2.0 of smiley window.
All is done, and all files are now in the tree.
(ok, copyright of new files is still opened... do as you want, if you
care)
Signed-off-by: Forge <jgrimbert@free.fr>
Diffstat (limited to 'src/gui/smileyshortcutcontainer.cpp')
-rw-r--r-- | src/gui/smileyshortcutcontainer.cpp | 195 |
1 files changed, 65 insertions, 130 deletions
diff --git a/src/gui/smileyshortcutcontainer.cpp b/src/gui/smileyshortcutcontainer.cpp index 5a9c3036..03b343e4 100644 --- a/src/gui/smileyshortcutcontainer.cpp +++ b/src/gui/smileyshortcutcontainer.cpp @@ -25,6 +25,7 @@ #include "../inventory.h" #include "../item.h" #include "../itemshortcut.h" +#include "../smileyshortcut.h" #include "../keyboardconfig.h" #include "../localplayer.h" #include "../log.h" @@ -36,11 +37,11 @@ #include "../utils/tostring.h" SmileyShortcutContainer::SmileyShortcutContainer(): - mGridWidth(1), - mGridHeight(1), - mItemClicked(false), - mItemMoved(NULL) + mSmileyClicked(false), + mSmileyMoved(0) { + mGridWidth=1, + mGridHeight=1, addMouseListener(this); addWidgetListener(this); @@ -50,7 +51,7 @@ SmileyShortcutContainer::SmileyShortcutContainer(): mSmileyImg = resman->getImageSet("graphics/gui/emotions.png",30,32); if (!mSmileyImg) logger->error("Unable to load emotions"); - mMaxItems = 12; + mMaxItems = smileyShortcut->getSmileyCount(); mBoxHeight = 42; mBoxWidth = 36; @@ -86,158 +87,92 @@ SmileyShortcutContainer::draw(gcn::Graphics *graphics) (SDLKey) keyboard.getKeyValue(keyboard.KEY_SMILEY_1 + i)); graphics->setColor(0x000000); g->drawText(key, itemX + 2, itemY + 2, gcn::Graphics::LEFT); + if (smileyShortcut->getSmiley(i)) + { static_cast<Graphics*>(graphics)->drawImage( - mSmileyImg->get(i), itemX+2, itemY+10); - -#if 0 - if (itemShortcut->getItem(i) < 0) - continue; - - Item *item = - player_node->getInventory()->findItem(itemShortcut->getItem(i)); - if (item) { - // Draw item icon. - const std::string label = - item->isEquipped() ? "Eq." : toString(item->getQuantity()); - Image* image = item->getImage(); - if (image) { - const std::string label = - item->isEquipped() ? "Eq." : toString(item->getQuantity()); - g->drawImage(image, itemX, itemY); - g->drawText( - label, - itemX + mBoxWidth / 2, - itemY + mBoxHeight - 14, - gcn::Graphics::CENTER); - } + mSmileyImg->get(smileyShortcut->getSmiley(i)-1), itemX+2, itemY+10); } -#endif + } - if (mItemMoved) + if (mSmileyMoved) { // Draw the item image being dragged by the cursor. - Image* image = mItemMoved->getImage(); + Image* image = mSmileyImg->get(mSmileyMoved-1); if (image) { const int tPosX = mCursorPosX - (image->getWidth() / 2); const int tPosY = mCursorPosY - (image->getHeight() / 2); g->drawImage(image, tPosX, tPosY); - g->drawText( - toString(mItemMoved->getQuantity()), - tPosX + mBoxWidth / 2, - tPosY + mBoxHeight - 14, - gcn::Graphics::CENTER); } } } -void SmileyShortcutContainer::widgetResized(const gcn::Event &event) -{ - mGridWidth = getWidth() / mBoxWidth; - if (mGridWidth < 1) { - mGridWidth = 1; - } - - setHeight((mMaxItems / mGridWidth + - (mMaxItems % mGridWidth > 0 ? 1 : 0)) * mBoxHeight); - - mGridHeight = getHeight() / mBoxHeight; - if (mGridHeight < 1) { - mGridHeight = 1; - } -} - void SmileyShortcutContainer::mouseDragged(gcn::MouseEvent &event) { - if (event.getButton() == gcn::MouseEvent::LEFT) { - if (!mItemMoved && mItemClicked) { - const int index = getIndexFromGrid(event.getX(), event.getY()); - if (index == -1) { - return; - } -#if 0 - const int itemId = itemShortcut->getItem(index); - if (itemId < 0) - return; - Item *item = player_node->getInventory()->findItem(itemId); - if (item) - { - mItemMoved = item; - itemShortcut->removeItem(index); - } -#endif - } - if (mItemMoved) { - mCursorPosX = event.getX(); - mCursorPosY = event.getY(); - } - } + if (event.getButton() == gcn::MouseEvent::LEFT) { + if (!mSmileyMoved && mSmileyClicked) { + const int index = getIndexFromGrid(event.getX(), event.getY()); + if (index == -1) { + return; + } + const int smileyId = smileyShortcut->getSmiley(index); + if (smileyId) + { + mSmileyMoved = smileyId; + smileyShortcut->removeSmiley(index); + } + } + if (mSmileyMoved) { + mCursorPosX = event.getX(); + mCursorPosY = event.getY(); + } + } } void SmileyShortcutContainer::mousePressed(gcn::MouseEvent &event) { - const int index = getIndexFromGrid(event.getX(), event.getY()); - if (index == -1) { - return; - } -#if 0 - // Stores the selected item if theirs one. - if (itemShortcut->isItemSelected()) { - itemShortcut->setItem(index); - itemShortcut->setItemSelected(-1); - } - else if (itemShortcut->getItem(index)) { - mItemClicked = true; - } -#endif + const int index = getIndexFromGrid(event.getX(), event.getY()); + if (index == -1) { + return; + } + // Stores the selected item if theirs one. + if (smileyShortcut->isSmileySelected()) { + smileyShortcut->setSmiley(index); + smileyShortcut->setSmileySelected(0); + } + else if (smileyShortcut->getSmiley(index)) { + mSmileyClicked = true; + } } void SmileyShortcutContainer::mouseReleased(gcn::MouseEvent &event) { - if (event.getButton() == gcn::MouseEvent::LEFT) - { -#if 0 - if (itemShortcut->isItemSelected()) - { - itemShortcut->setItemSelected(-1); - } - const int index = getIndexFromGrid(event.getX(), event.getY()); - if (index == -1) { - mItemMoved = NULL; - return; - } - if (mItemMoved) { - itemShortcut->setItems(index, mItemMoved->getId()); - mItemMoved = NULL; - } - else if (itemShortcut->getItem(index) && mItemClicked) - { - itemShortcut->useItem(index); - } - if (mItemClicked) { - mItemClicked = false; - } -#endif - } + if (event.getButton() == gcn::MouseEvent::LEFT) + { + if (smileyShortcut->isSmileySelected()) + { + smileyShortcut->setSmileySelected(0); + } + const int index = getIndexFromGrid(event.getX(), event.getY()); + if (index == -1) { + mSmileyMoved = 0; + return; + } + if (mSmileyMoved) { + smileyShortcut->setSmileys(index, mSmileyMoved); + mSmileyMoved = 0; + } + else if (smileyShortcut->getSmiley(index) && mSmileyClicked) + { + smileyShortcut->useSmiley(index+1); + } + if (mSmileyClicked) { + mSmileyClicked = false; + } + } } -int -SmileyShortcutContainer::getIndexFromGrid(int pointX, int pointY) const -{ - const gcn::Rectangle tRect = gcn::Rectangle( - 0, 0, mGridWidth * mBoxWidth, mGridHeight * mBoxHeight); - if (!tRect.isPointInRect(pointX, pointY)) { - return -1; - } - const int index = ((pointY / mBoxHeight) * mGridWidth) + - pointX / mBoxWidth; - if (index >= mMaxItems) - { - return -1; - } - return index; -} |