diff options
author | Ira Rice <irarice@gmail.com> | 2009-01-08 16:38:22 -0700 |
---|---|---|
committer | Ira Rice <irarice@gmail.com> | 2009-01-08 16:38:22 -0700 |
commit | a001775f8b0b992cc7c4c5863722d02e8606b175 (patch) | |
tree | 44dfa8ab01119022b7999b27c3031a39d9d3c186 | |
parent | 193ccbdba8031a351ea622f8842b6d9a0b6cfd43 (diff) | |
parent | 611210b1e0fd9cbaed38b229462e109d8f4be385 (diff) | |
download | mana-a001775f8b0b992cc7c4c5863722d02e8606b175.tar.gz mana-a001775f8b0b992cc7c4c5863722d02e8606b175.tar.bz2 mana-a001775f8b0b992cc7c4c5863722d02e8606b175.tar.xz mana-a001775f8b0b992cc7c4c5863722d02e8606b175.zip |
Fixed include order (pedantic change)
Conflicts:
src/gui/smileycontainer.cpp
Signed-off-by: Ira Rice <irarice@gmail.com>
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/game.cpp | 10 | ||||
-rw-r--r-- | src/gui/itemshortcutcontainer.cpp | 36 | ||||
-rw-r--r-- | src/gui/itemshortcutcontainer.h | 31 | ||||
-rw-r--r-- | src/gui/shortcutcontainer.cpp | 165 | ||||
-rw-r--r-- | src/gui/shortcutcontainer.h | 17 | ||||
-rw-r--r-- | src/gui/smileycontainer.cpp | 8 | ||||
-rw-r--r-- | src/gui/smileyshortcutcontainer.cpp | 195 | ||||
-rw-r--r-- | src/gui/smileyshortcutcontainer.h | 34 | ||||
-rw-r--r-- | src/main.cpp | 6 | ||||
-rw-r--r-- | src/smileyshortcut.cpp | 76 | ||||
-rw-r--r-- | src/smileyshortcut.h | 127 |
12 files changed, 295 insertions, 412 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 9d95488d..d267022b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -272,6 +272,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 @@ -61,12 +61,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. */ void mouseDragged(gcn::MouseEvent &event); @@ -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); - - 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 d5e2e815..afe4ce15 100644 --- a/src/gui/smileycontainer.cpp +++ b/src/gui/smileycontainer.cpp @@ -26,6 +26,7 @@ #include "../graphics.h" #include "../log.h" +#include "../smileyshortcut.h" #include "../resources/image.h" #include "../resources/iteminfo.h" @@ -159,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 <mMaxSmiley) + { + setSelectedItemIndex(index); + smileyShortcut->setSmileySelected(index+1); + } } } diff --git a/src/gui/smileyshortcutcontainer.cpp b/src/gui/smileyshortcutcontainer.cpp index f857ed5d..6028939f 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" @@ -37,11 +38,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); @@ -51,7 +52,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; @@ -87,158 +88,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; -} 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 @@ -58,12 +58,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. */ void mouseDragged(gcn::MouseEvent &event); @@ -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 c15011ff..efb14deb 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.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..c4fb9280 --- /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_SMILEYSHORTCUT_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 |