From 0b2e6c53a158b820a3e3610372c98185a4dce30a Mon Sep 17 00:00:00 2001 From: Forge Date: Thu, 8 Jan 2009 23:57:34 +0100 Subject: Smiley shortcut 2.0: Final stage The copyright issue is left opened, all other items on the TODO list have been done. Signed-off-by: Forge --- src/smileyshortcut.cpp | 76 +++++++++++++++++++++++++++++ src/smileyshortcut.h | 127 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 203 insertions(+) create mode 100644 src/smileyshortcut.cpp create mode 100644 src/smileyshortcut.h (limited to 'src') diff --git a/src/smileyshortcut.cpp b/src/smileyshortcut.cpp new file mode 100644 index 00000000..adc7d9c3 --- /dev/null +++ b/src/smileyshortcut.cpp @@ -0,0 +1,76 @@ +/* + * The Mana World + * Copyright 2007 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "configuration.h" +#include "smileyshortcut.h" +#include "localplayer.h" + +#include "utils/tostring.h" + +SmileyShortcut::SmileyShortcut *smileyShortcut; + +SmileyShortcut::SmileyShortcut(): + mSmileySelected(0) +{ + for (int i = 0; i < SHORTCUT_SMILEYS; i++) + { + mSmileys[i] = i+1; + } + load(); +} + +SmileyShortcut::~SmileyShortcut() +{ + save(); +} + +void SmileyShortcut::load() +{ + for (int i = 0; i < SHORTCUT_SMILEYS; i++) + { + int smileyId = (int) config.getValue("Smileyshortcut" + toString(i), i+1); + + if (smileyId) + { + mSmileys[i] = smileyId; + } + } +} + +void SmileyShortcut::save() +{ + for (int i = 0; i < SHORTCUT_SMILEYS; i++) + { + const int smileyId = mSmileys[i] ? mSmileys[i] : 0; + config.setValue("Smileyshortcut" + toString(i), smileyId); + } +} + +void SmileyShortcut::useSmiley(int index) +{ + if ((index>0)&&(index<=SHORTCUT_SMILEYS)) + { + if (mSmileys[index-1]>0) + { + player_node->emote(mSmileys[index-1]); + } + } +} diff --git a/src/smileyshortcut.h b/src/smileyshortcut.h new file mode 100644 index 00000000..9960d8cf --- /dev/null +++ b/src/smileyshortcut.h @@ -0,0 +1,127 @@ +/* + * The Mana World + * Copyright 2007 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _TMW_SMILEYSHORTCUT_H__ +#define _TMW_ITEMSHORTCUT_H__ + +#define SHORTCUT_SMILEYS 12 + +class Item; + +/** + * The class which keeps track of the item shortcuts. + */ +class SmileyShortcut +{ + public: + /** + * Constructor. + */ + SmileyShortcut(); + + /** + * Destructor. + */ + ~SmileyShortcut(); + + /** + * Load the configuration information. + */ + void load(); + + /** + * Returns the shortcut smiley ID specified by the index. + * + * @param index Index of the shortcut smiley. + */ + int getSmiley(int index) const + { return mSmileys[index]; } + + /** + * Returns the amount of shortcut smileys. + */ + int getSmileyCount() const + { return SHORTCUT_SMILEYS; } + + /** + * Returns the item ID that is currently selected. + */ + int getSmileySelected() const + { return mSmileySelected; } + + /** + * Adds the selected item ID to the items specified by the index. + * + * @param index Index of the items. + */ + void setSmiley(int index) + { mSmileys[index] = mSmileySelected; } + + /** + * Adds a smiley to the smileys store specified by the index. + * + * @param index Index of the smiley. + * @param smileyId ID of the smiley. + */ + void setSmileys(int index, int smileyId) + { mSmileys[index] = smileyId; } + + /** + * Set the smiley that is selected. + * + * @param smileyId The ID of the smiley that is to be assigned. + */ + void setSmileySelected(int smileyId) + { mSmileySelected = smileyId; } + + /** + * A flag to check if the smiley is selected. + */ + bool isSmileySelected() + { return mSmileySelected; } + + /** + * Remove a smiley from the shortcut. + */ + void removeSmiley(int index) + { mSmileys[index] = 0; } + + /** + * Try to use the smiley specified by the index. + * + * @param index Index of the smiley shortcut. + */ + void useSmiley(int index); + + private: + /** + * Save the configuration information. + */ + void save(); + + int mSmileys[SHORTCUT_SMILEYS]; /**< The smiley stored. */ + int mSmileySelected; /**< The smiley held by cursor. */ + +}; + +extern SmileyShortcut *smileyShortcut; + +#endif -- cgit v1.2.3-70-g09d2 From 611210b1e0fd9cbaed38b229462e109d8f4be385 Mon Sep 17 00:00:00 2001 From: Forge Date: Fri, 9 Jan 2009 00:03:53 +0100 Subject: 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 --- src/Makefile.am | 2 + src/game.cpp | 10 +- src/gui/itemshortcutcontainer.cpp | 36 +------ src/gui/itemshortcutcontainer.h | 31 ------ src/gui/shortcutcontainer.cpp | 165 +----------------------------- src/gui/shortcutcontainer.h | 17 +--- src/gui/smileycontainer.cpp | 9 +- src/gui/smileyshortcutcontainer.cpp | 195 ++++++++++++------------------------ src/gui/smileyshortcutcontainer.h | 34 +------ src/main.cpp | 6 ++ src/smileyshortcut.h | 2 +- 11 files changed, 94 insertions(+), 413 deletions(-) (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 1d325a84..d3a9571b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -278,6 +278,8 @@ aethyra_SOURCES = gui/widgets/dropdown.cpp \ inventory.h \ item.cpp \ item.h \ + smileyshortcut.cpp \ + smileyshortcut.h \ itemshortcut.cpp \ itemshortcut.h \ joystick.cpp \ diff --git a/src/game.cpp b/src/game.cpp index 76eb6b82..da733fe3 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -36,6 +36,7 @@ #include "flooritemmanager.h" #include "graphics.h" #include "itemshortcut.h" +#include "smileyshortcut.h" #include "joystick.h" #include "keyboardconfig.h" #include "localplayer.h" @@ -556,15 +557,10 @@ void Game::handleInput() if (keyboard.isKeyActive(keyboard.KEY_SMILIE)) { // Emotions - Uint8 emotion=keyboard.getKeySmilieOffset(event.key.keysym.sym); - /** - * Later here: increase the size of emotion, - * and get the entry from the smiley - * shortcut object - */ + int emotion=keyboard.getKeySmilieOffset(event.key.keysym.sym); if (emotion) { - player_node->emote(emotion); + smileyShortcut->useSmiley(emotion); used = true; return; } diff --git a/src/gui/itemshortcutcontainer.cpp b/src/gui/itemshortcutcontainer.cpp index 77657169..f0ab8274 100644 --- a/src/gui/itemshortcutcontainer.cpp +++ b/src/gui/itemshortcutcontainer.cpp @@ -34,11 +34,11 @@ #include "../utils/tostring.h" ItemShortcutContainer::ItemShortcutContainer(): - mGridWidth(1), - mGridHeight(1), mItemClicked(false), mItemMoved(NULL) { + mGridWidth=1; + mGridHeight=1; addMouseListener(this); addWidgetListener(this); @@ -131,22 +131,6 @@ ItemShortcutContainer::draw(gcn::Graphics *graphics) } } -void ItemShortcutContainer::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 ItemShortcutContainer::mouseDragged(gcn::MouseEvent &event) { @@ -219,19 +203,3 @@ ItemShortcutContainer::mouseReleased(gcn::MouseEvent &event) } } -int -ItemShortcutContainer::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; -} diff --git a/src/gui/itemshortcutcontainer.h b/src/gui/itemshortcutcontainer.h index 92b9b968..37c61e07 100644 --- a/src/gui/itemshortcutcontainer.h +++ b/src/gui/itemshortcutcontainer.h @@ -60,12 +60,6 @@ class ItemShortcutContainer : public ShortcutContainer */ void draw(gcn::Graphics *graphics); - /** - * Invoked when a widget changes its size. This is used to determine - * the new height of the container. - */ - void widgetResized(const gcn::Event &event); - /** * Handles mouse when dragged. */ @@ -81,32 +75,7 @@ class ItemShortcutContainer : public ShortcutContainer */ void mouseReleased(gcn::MouseEvent &event); - int getMaxItems() - { return mMaxItems; } - - int getBoxWidth() - { return mBoxWidth; } - - int getBoxHeight() - { return mBoxHeight; } - private: - /** - * Gets the index from the grid provided the point is in an item box. - * - * @param pointX X coordinate of the point. - * @param pointY Y coordinate of the point. - * @return index on success, -1 on failure. - */ - int getIndexFromGrid(int pointX, int pointY) const; - - Image *mBackgroundImg; - - int mMaxItems; - int mBoxWidth; - int mBoxHeight; - int mCursorPosX, mCursorPosY; - int mGridWidth, mGridHeight; bool mItemClicked; Item *mItemMoved; }; diff --git a/src/gui/shortcutcontainer.cpp b/src/gui/shortcutcontainer.cpp index f1a60189..32d7c6af 100644 --- a/src/gui/shortcutcontainer.cpp +++ b/src/gui/shortcutcontainer.cpp @@ -35,101 +35,10 @@ ShortcutContainer::ShortcutContainer(): mGridWidth(1), - mGridHeight(1), - mItemClicked(false), - mItemMoved(NULL) + mGridHeight(1) { - addMouseListener(this); - addWidgetListener(this); - - ResourceManager *resman = ResourceManager::getInstance(); - - mBackgroundImg = resman->getImage("graphics/gui/item_shortcut_bgr.png"); - mMaxItems = itemShortcut->getItemCount(); - - mBoxHeight = 42; - mBoxWidth = 36; -} - -ShortcutContainer::~ShortcutContainer() -{ - mBackgroundImg->decRef(); } -void -ShortcutContainer::logic() -{ - gcn::Widget::logic(); - - int i = itemShortcut->getItemCount(); - - if (i != mMaxItems) - { - mMaxItems = i; - setWidth(getWidth()); - } -} - -void -ShortcutContainer::draw(gcn::Graphics *graphics) -{ - Graphics *g = static_cast(graphics); - - graphics->setFont(getFont()); - - for (int i = 0; i < mMaxItems; i++) - { - const int itemX = (i % mGridWidth) * mBoxWidth; - const int itemY = (i / mGridWidth) * mBoxHeight; - - g->drawImage(mBackgroundImg, itemX, itemY); - - // Draw item keyboard shortcut. - const char *key = SDL_GetKeyName( - (SDLKey) keyboard.getKeyValue(keyboard.KEY_SHORTCUT_0 + i)); - graphics->setColor(0x000000); - g->drawText(key, itemX + 2, itemY + 2, gcn::Graphics::LEFT); - - 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); - } - } - } - if (mItemMoved) - { - // Draw the item image being dragged by the cursor. - Image* image = mItemMoved->getImage(); - 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 ShortcutContainer::widgetResized(const gcn::Event &event) { @@ -147,78 +56,6 @@ void ShortcutContainer::widgetResized(const gcn::Event &event) } } -void -ShortcutContainer::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; - } - const int itemId = itemShortcut->getItem(index); - if (itemId < 0) - return; - Item *item = player_node->getInventory()->findItem(itemId); - if (item) - { - mItemMoved = item; - itemShortcut->removeItem(index); - } - } - if (mItemMoved) { - mCursorPosX = event.getX(); - mCursorPosY = event.getY(); - } - } -} - -void -ShortcutContainer::mousePressed(gcn::MouseEvent &event) -{ - const int index = getIndexFromGrid(event.getX(), event.getY()); - if (index == -1) { - return; - } - - // Stores the selected item if theirs one. - if (itemShortcut->isItemSelected()) { - itemShortcut->setItem(index); - itemShortcut->setItemSelected(-1); - } - else if (itemShortcut->getItem(index)) { - mItemClicked = true; - } -} - -void -ShortcutContainer::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) { - 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; - } - } -} - int ShortcutContainer::getIndexFromGrid(int pointX, int pointY) const { diff --git a/src/gui/shortcutcontainer.h b/src/gui/shortcutcontainer.h index 5ca56899..ebc0a9fc 100644 --- a/src/gui/shortcutcontainer.h +++ b/src/gui/shortcutcontainer.h @@ -49,17 +49,12 @@ class ShortcutContainer : public gcn::Widget, /** * Destructor. */ - virtual ~ShortcutContainer(); - - /** - * Handles the logic of the ItemContainer - */ - virtual void logic(); + ~ShortcutContainer(){} /** * Draws the items. */ - virtual void draw(gcn::Graphics *graphics); + virtual void draw(gcn::Graphics *graphics)=0; /** * Invoked when a widget changes its size. This is used to determine @@ -70,17 +65,17 @@ class ShortcutContainer : public gcn::Widget, /** * Handles mouse when dragged. */ - virtual void mouseDragged(gcn::MouseEvent &event); + virtual void mouseDragged(gcn::MouseEvent &event)=0; /** * Handles mouse when pressed. */ - virtual void mousePressed(gcn::MouseEvent &event); + virtual void mousePressed(gcn::MouseEvent &event)=0; /** * Handles mouse release. */ - virtual void mouseReleased(gcn::MouseEvent &event); + virtual void mouseReleased(gcn::MouseEvent &event)=0; virtual int getMaxItems() { return mMaxItems; } @@ -108,8 +103,6 @@ class ShortcutContainer : public gcn::Widget, int mBoxHeight; int mCursorPosX, mCursorPosY; int mGridWidth, mGridHeight; - bool mItemClicked; - Item *mItemMoved; }; #endif diff --git a/src/gui/smileycontainer.cpp b/src/gui/smileycontainer.cpp index 5eb99723..55f8f11b 100644 --- a/src/gui/smileycontainer.cpp +++ b/src/gui/smileycontainer.cpp @@ -31,6 +31,8 @@ #include "../resources/iteminfo.h" #include "../resources/resourcemanager.h" +#include "../smileyshortcut.h" + #include "../utils/tostring.h" const int SmileyContainer::gridWidth = 34; // item icon width + 4 @@ -158,7 +160,10 @@ void SmileyContainer::mousePressed(gcn::MouseEvent &event) int mx = event.getX(); int my = event.getY(); int index = mx / gridWidth + ((my / gridHeight) * columns); - - setSelectedItemIndex(index); + if (index setSmileySelected(index+1); + } } } 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)->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; -} diff --git a/src/gui/smileyshortcutcontainer.h b/src/gui/smileyshortcutcontainer.h index d6bbbc4f..55df6124 100644 --- a/src/gui/smileyshortcutcontainer.h +++ b/src/gui/smileyshortcutcontainer.h @@ -57,12 +57,6 @@ class SmileyShortcutContainer : public ShortcutContainer */ void draw(gcn::Graphics *graphics); - /** - * Invoked when a widget changes its size. This is used to determine - * the new height of the container. - */ - void widgetResized(const gcn::Event &event); - /** * Handles mouse when dragged. */ @@ -78,35 +72,11 @@ class SmileyShortcutContainer : public ShortcutContainer */ void mouseReleased(gcn::MouseEvent &event); - int getMaxItems() - { return mMaxItems; } - - int getBoxWidth() - { return mBoxWidth; } - - int getBoxHeight() - { return mBoxHeight; } - private: - /** - * Gets the index from the grid provided the point is in an item box. - * - * @param pointX X coordinate of the point. - * @param pointY Y coordinate of the point. - * @return index on success, -1 on failure. - */ - int getIndexFromGrid(int pointX, int pointY) const; - - Image *mBackgroundImg; ImageSet *mSmileyImg; - int mMaxItems; - int mBoxWidth; - int mBoxHeight; - int mCursorPosX, mCursorPosY; - int mGridWidth, mGridHeight; - bool mItemClicked; - Item *mItemMoved; + bool mSmileyClicked; + int mSmileyMoved; }; #endif diff --git a/src/main.cpp b/src/main.cpp index 4a3acce8..09004a50 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -40,6 +40,7 @@ #include "game.h" #include "graphics.h" #include "itemshortcut.h" +#include "smileyshortcut.h" #include "keyboardconfig.h" #include "localplayer.h" #include "lockedarray.h" @@ -401,6 +402,9 @@ void init_engine(const Options &options) // Initialize the item shortcuts. itemShortcut = new ItemShortcut(); + + // Initialize the smiley shortcuts. + smileyShortcut = new SmileyShortcut(); gui = new Gui(graphics); state = LOGIN_STATE; /**< Initial game state */ @@ -433,6 +437,8 @@ void exit_engine() { // Before config.write() since it writes the shortcuts to the config delete itemShortcut; + + delete smileyShortcut; config.write(); diff --git a/src/smileyshortcut.h b/src/smileyshortcut.h index 9960d8cf..c4fb9280 100644 --- a/src/smileyshortcut.h +++ b/src/smileyshortcut.h @@ -20,7 +20,7 @@ */ #ifndef _TMW_SMILEYSHORTCUT_H__ -#define _TMW_ITEMSHORTCUT_H__ +#define _TMW_SMILEYSHORTCUT_H__ #define SHORTCUT_SMILEYS 12 -- cgit v1.2.3-70-g09d2