diff options
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/emotecontainer.cpp (renamed from src/gui/smileycontainer.cpp) | 81 | ||||
-rw-r--r-- | src/gui/emotecontainer.h (renamed from src/gui/smileycontainer.h) | 37 | ||||
-rw-r--r-- | src/gui/emoteshortcutcontainer.cpp | 192 | ||||
-rw-r--r-- | src/gui/emoteshortcutcontainer.h (renamed from src/gui/smileyshortcutcontainer.h) | 38 | ||||
-rw-r--r-- | src/gui/emotewindow.cpp (renamed from src/gui/smileywindow.cpp) | 34 | ||||
-rw-r--r-- | src/gui/emotewindow.h (renamed from src/gui/smileywindow.h) | 33 | ||||
-rw-r--r-- | src/gui/itemshortcutcontainer.cpp | 6 | ||||
-rw-r--r-- | src/gui/menuwindow.cpp | 4 | ||||
-rw-r--r-- | src/gui/setup.cpp | 8 | ||||
-rw-r--r-- | src/gui/setup.h | 3 | ||||
-rw-r--r-- | src/gui/shortcutcontainer.cpp | 9 | ||||
-rw-r--r-- | src/gui/shortcutcontainer.h | 9 | ||||
-rw-r--r-- | src/gui/shortcutwindow.h | 2 | ||||
-rw-r--r-- | src/gui/smileyshortcutcontainer.cpp | 179 |
14 files changed, 324 insertions, 311 deletions
diff --git a/src/gui/smileycontainer.cpp b/src/gui/emotecontainer.cpp index f8f57c45..c3e20c41 100644 --- a/src/gui/smileycontainer.cpp +++ b/src/gui/emotecontainer.cpp @@ -1,33 +1,33 @@ /* - * The Mana World - * Copyright 2004 The Mana World Development Team + * Aethyra + * Copyright 2009 Aethyra Development Team * - * This file is part of The Mana World. + * This file is part of Aethyra. * - * The Mana World is free software; you can redistribute it and/or modify + * Aethyra 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, + * Aethyra 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 + * along with Aethyra; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "smileycontainer.h" - #include <guichan/mouseinput.hpp> #include <guichan/selectionlistener.hpp> +#include "emotecontainer.h" +#include "emoteshortcut.h" + #include "../configuration.h" #include "../graphics.h" #include "../log.h" -#include "../smileyshortcut.h" #include "../resources/image.h" #include "../resources/iteminfo.h" @@ -36,45 +36,45 @@ #include "../utils/gettext.h" #include "../utils/tostring.h" -const int SmileyContainer::gridWidth = 34; // emote icon width + 4 -const int SmileyContainer::gridHeight = 36; // emote icon height + 4 +const int EmoteContainer::gridWidth = 34; // emote icon width + 4 +const int EmoteContainer::gridHeight = 36; // emote icon height + 4 static const int NO_EMOTE = -1; -SmileyContainer::SmileyContainer(): +EmoteContainer::EmoteContainer(): mSelectedEmoteIndex(NO_EMOTE) { ResourceManager *resman = ResourceManager::getInstance(); - mSmileyImg = resman->getImageSet("graphics/sprites/emotions.png", 30, 32); - if (!mSmileyImg) logger->error(_("Unable to load emotions")); + mEmoteImg = resman->getImageSet("graphics/sprites/emotions.png", 30, 32); + if (!mEmoteImg) logger->error(_("Unable to load emotions")); mSelImg = resman->getImage("graphics/gui/selection.png"); if (!mSelImg) logger->error(_("Unable to load selection.png")); mSelImg->setAlpha(config.getValue("guialpha", 0.8)); - mMaxSmiley = mSmileyImg->size(); + mMaxEmote = mEmoteImg->size(); addMouseListener(this); addWidgetListener(this); } -SmileyContainer::~SmileyContainer() +EmoteContainer::~EmoteContainer() { - if (mSmileyImg) + if (mEmoteImg) { - mSmileyImg->decRef(); - mSmileyImg=NULL; + mEmoteImg->decRef(); + mEmoteImg = NULL; } if (!mSelImg) { mSelImg->decRef(); - mSelImg=NULL; + mSelImg = NULL; } } -void SmileyContainer::draw(gcn::Graphics *graphics) +void EmoteContainer::draw(gcn::Graphics *graphics) { int columns = getWidth() / gridWidth; @@ -84,65 +84,64 @@ void SmileyContainer::draw(gcn::Graphics *graphics) columns = 1; } - for (int i = 0; i < mMaxSmiley ; i++) + for (int i = 0; i < mMaxEmote ; i++) { - int itemX = ((i) % columns) * gridWidth; - int itemY = ((i) / columns) * gridHeight; + int emoteX = ((i) % columns) * gridWidth; + int emoteY = ((i) / columns) * gridHeight; - - // Draw item icon + // Draw emote icon static_cast<Graphics*>(graphics)->drawImage( - mSmileyImg->get(i), itemX, itemY); + mEmoteImg->get(i), emoteX, emoteY); // Draw selection image below selected item if (mSelectedEmoteIndex == i) { static_cast<Graphics*>(graphics)->drawImage( - mSelImg, itemX, itemY); + mSelImg, emoteX, emoteY); } } } -void SmileyContainer::widgetResized(const gcn::Event &event) +void EmoteContainer::widgetResized(const gcn::Event &event) { recalculateHeight(); } -void SmileyContainer::recalculateHeight() +void EmoteContainer::recalculateHeight() { int cols = getWidth() / gridWidth; if (cols < 1) cols = 1; - const int rows = (mMaxSmiley / cols) + (mMaxSmiley % cols > 0 ? 1 : 0); + const int rows = (mMaxEmote / cols) + (mMaxEmote % cols > 0 ? 1 : 0); const int height = rows * gridHeight + 8; if (height != getHeight()) setHeight(height); } -int SmileyContainer::getSelectedSmiley() +int EmoteContainer::getSelectedEmote() { if (mSelectedEmoteIndex == NO_EMOTE) return 0; - return 1+mSelectedEmoteIndex; + return 1 + mSelectedEmoteIndex; } -void SmileyContainer::selectNone() +void EmoteContainer::selectNone() { setSelectedEmoteIndex(NO_EMOTE); } -void SmileyContainer::setSelectedEmoteIndex(int index) +void EmoteContainer::setSelectedEmoteIndex(int index) { - if (index < 0 || index >= mMaxSmiley ) + if (index < 0 || index >= mMaxEmote ) mSelectedEmoteIndex = NO_EMOTE; else mSelectedEmoteIndex = index; } -void SmileyContainer::distributeValueChangedEvent() +void EmoteContainer::distributeValueChangedEvent() { gcn::SelectionEvent event(this); std::list<gcn::SelectionListener*>::iterator i_end = mListeners.end(); @@ -154,7 +153,7 @@ void SmileyContainer::distributeValueChangedEvent() } } -void SmileyContainer::mousePressed(gcn::MouseEvent &event) +void EmoteContainer::mousePressed(gcn::MouseEvent &event) { int button = event.getButton(); if (button == gcn::MouseEvent::LEFT || button == gcn::MouseEvent::RIGHT) @@ -163,10 +162,10 @@ void SmileyContainer::mousePressed(gcn::MouseEvent &event) int mx = event.getX(); int my = event.getY(); int index = mx / gridWidth + ((my / gridHeight) * columns); - if (index <mMaxSmiley) + if (index < mMaxEmote) { setSelectedEmoteIndex(index); - smileyShortcut->setSmileySelected(index+1); + emoteShortcut->setEmoteSelected(index + 1); } } } diff --git a/src/gui/smileycontainer.h b/src/gui/emotecontainer.h index 88ca0b48..f5922a9c 100644 --- a/src/gui/smileycontainer.h +++ b/src/gui/emotecontainer.h @@ -1,26 +1,26 @@ /* - * The Mana World - * Copyright 2004 The Mana World Development Team + * Aethyra + * Copyright 2009 Aethyra Development Team * - * This file is part of The Mana World. + * This file is part of Aethyra. * - * The Mana World is free software; you can redistribute it and/or modify + * Aethyra 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, + * Aethyra 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 + * along with Aethyra; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef _TMW_SMILEYCONTAINER_H__ -#define _TMW_SMILEYCONTAINER_H__ +#ifndef _AETHYRA_EMOTECONTAINER_H__ +#define _AETHYRA_EMOTECONTAINER_H__ #include <list> @@ -28,9 +28,10 @@ #include <guichan/widget.hpp> #include <guichan/widgetlistener.hpp> -#include "../resources/imageset.h" #include "../guichanfwd.h" +#include "../resources/imageset.h" + class Image; class Inventory; class Emote; @@ -44,20 +45,20 @@ namespace gcn { * * \ingroup GUI */ -class SmileyContainer : public gcn::Widget, - public gcn::MouseListener, - public gcn::WidgetListener +class EmoteContainer : public gcn::Widget, + public gcn::MouseListener, + public gcn::WidgetListener { public: /** * Constructor. Initializes the graphic. */ - SmileyContainer(); + EmoteContainer(); /** * Destructor. */ - virtual ~SmileyContainer(); + virtual ~EmoteContainer(); /** * Draws the items. @@ -77,7 +78,7 @@ class SmileyContainer : public gcn::Widget, /** * Returns the selected item. */ - int getSelectedSmiley(); + int getSelectedEmote(); /** * Sets selected item to NULL. @@ -124,11 +125,11 @@ class SmileyContainer : public gcn::Widget, */ void distributeValueChangedEvent(void); - ImageSet *mSmileyImg; + ImageSet *mEmoteImg; Image *mSelImg; int mSelectedEmoteIndex; - int mMaxSmiley; + int mMaxEmote; std::list<gcn::SelectionListener*> mListeners; diff --git a/src/gui/emoteshortcutcontainer.cpp b/src/gui/emoteshortcutcontainer.cpp new file mode 100644 index 00000000..5e984dd5 --- /dev/null +++ b/src/gui/emoteshortcutcontainer.cpp @@ -0,0 +1,192 @@ +/* + * Aethyra + * Copyright 2009 Aethyra Development Team + * + * This file is part of Aethyra. + * + * Aethyra 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. + * + * Aethyra 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 Aethyra; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "emoteshortcutcontainer.h" + +#include "../emoteshortcut.h" +#include "../graphics.h" +#include "../inventory.h" +#include "../item.h" +#include "../itemshortcut.h" +#include "../keyboardconfig.h" +#include "../localplayer.h" +#include "../log.h" + +#include "../resources/image.h" +#include "../resources/resourcemanager.h" + +#include "../utils/gettext.h" +#include "../utils/tostring.h" + +EmoteShortcutContainer::EmoteShortcutContainer(): + mEmoteClicked(false), + mEmoteMoved(0) +{ + mGridWidth = 1, + mGridHeight = 1, + addMouseListener(this); + addWidgetListener(this); + + ResourceManager *resman = ResourceManager::getInstance(); + + mBackgroundImg = resman->getImage("graphics/gui/item_shortcut_bgr.png"); + mEmoteImg = resman->getImageSet("graphics/sprites/emotions.png", 30, 32); + if (!mEmoteImg) logger->error(_("Unable to load emotions")); + + mMaxItems = emoteShortcut->getEmoteCount(); + + mBoxHeight = mBackgroundImg->getHeight(); + mBoxWidth = mBackgroundImg->getWidth(); +} + +EmoteShortcutContainer::~EmoteShortcutContainer() +{ + mBackgroundImg->decRef(); + if (mEmoteImg) + { + mEmoteImg->decRef(); + mEmoteImg=NULL; + } +} + +void EmoteShortcutContainer::draw(gcn::Graphics *graphics) +{ + Graphics *g = static_cast<Graphics*>(graphics); + + //graphics->setFont(getFont()); + + for (int i = 0; i < mMaxItems; i++) + { + const int emoteX = (i % mGridWidth) * mBoxWidth; + const int emoteY = (i / mGridWidth) * mBoxHeight; + + g->drawImage(mBackgroundImg, emoteX, emoteY); + + // Draw emote keyboard shortcut. + const char *key = SDL_GetKeyName( + (SDLKey) keyboard.getKeyValue(keyboard.KEY_EMOTE_1 + i)); + graphics->setColor(0x000000); + g->drawText(key, emoteX + 2, emoteY + 2, gcn::Graphics::LEFT); + + if (emoteShortcut->getEmote(i)) + { + static_cast<Graphics*>(graphics)->drawImage( + mEmoteImg->get(emoteShortcut->getEmote(i) - 1), emoteX + 2, emoteY + 10); + } + + } + if (mEmoteMoved) + { + // Draw the emote image being dragged by the cursor. + Image* image = mEmoteImg->get(mEmoteMoved-1); + if (image) + { + const int tPosX = mCursorPosX - (image->getWidth() / 2); + const int tPosY = mCursorPosY - (image->getHeight() / 2); + + g->drawImage(image, tPosX, tPosY); + } + } +} + +void EmoteShortcutContainer::mouseDragged(gcn::MouseEvent &event) +{ + if (event.getButton() == gcn::MouseEvent::LEFT) + { + if (!mEmoteMoved && mEmoteClicked) + { + const int index = getIndexFromGrid(event.getX(), event.getY()); + const int emoteId = emoteShortcut->getEmote(index); + + if (index == -1) + { + return; + } + + if (emoteId) + { + mEmoteMoved = emoteId; + emoteShortcut->removeEmote(index); + } + } + if (mEmoteMoved) + { + mCursorPosX = event.getX(); + mCursorPosY = event.getY(); + } + } +} + +void EmoteShortcutContainer::mousePressed(gcn::MouseEvent &event) +{ + const int index = getIndexFromGrid(event.getX(), event.getY()); + + if (index == -1) + { + return; + } + + // Stores the selected emote if there is one. + if (emoteShortcut->isEmoteSelected()) + { + emoteShortcut->setEmote(index); + emoteShortcut->setEmoteSelected(0); + } + else if (emoteShortcut->getEmote(index)) + { + mEmoteClicked = true; + } +} + +void EmoteShortcutContainer::mouseReleased(gcn::MouseEvent &event) +{ + if (event.getButton() == gcn::MouseEvent::LEFT) + { + const int index = getIndexFromGrid(event.getX(), event.getY()); + + if (emoteShortcut->isEmoteSelected()) + { + emoteShortcut->setEmoteSelected(0); + } + + if (index == -1) + { + mEmoteMoved = 0; + return; + } + + if (mEmoteMoved) + { + emoteShortcut->setEmotes(index, mEmoteMoved); + mEmoteMoved = 0; + } + else if (emoteShortcut->getEmote(index) && mEmoteClicked) + { + emoteShortcut->useEmote(index + 1); + } + + if (mEmoteClicked) + { + mEmoteClicked = false; + } + } +} + diff --git a/src/gui/smileyshortcutcontainer.h b/src/gui/emoteshortcutcontainer.h index 55df6124..5b3f61cd 100644 --- a/src/gui/smileyshortcutcontainer.h +++ b/src/gui/emoteshortcutcontainer.h @@ -1,56 +1,56 @@ /* - * The Mana World - * Copyright 2007 The Mana World Development Team + * Aethyra + * Copyright 2009 Aethyra Development Team * - * This file is part of The Mana World. + * This file is part of Aethyra. * - * The Mana World is free software; you can redistribute it and/or modify + * Aethyra 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, + * Aethyra 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 + * along with Aethyra; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef _TMW_SMILEYSHORTCUTCONTAINER_H__ -#define _TMW_SMILEYSHORTCUTCONTAINER_H__ +#ifndef _AETHYRA_EMOTESHORTCUTCONTAINER_H__ +#define _AETHYRA_EMOTESHORTCUTCONTAINER_H__ #include <guichan/mouselistener.hpp> #include <guichan/widget.hpp> #include <guichan/widgetlistener.hpp> -#include "../resources/imageset.h" +#include "shortcutcontainer.h" + #include "../guichanfwd.h" -#include "shortcutcontainer.h" +#include "../resources/imageset.h" class Image; -class Item; /** - * A smiley shortcut container. Used to quickly use items. + * An emote shortcut container. Used to quickly use emoticons. * * \ingroup GUI */ -class SmileyShortcutContainer : public ShortcutContainer +class EmoteShortcutContainer : public ShortcutContainer { public: /** * Constructor. Initializes the graphic. */ - SmileyShortcutContainer(); + EmoteShortcutContainer(); /** * Destructor. */ - virtual ~SmileyShortcutContainer(); + virtual ~EmoteShortcutContainer(); /** * Draws the items. @@ -73,10 +73,10 @@ class SmileyShortcutContainer : public ShortcutContainer void mouseReleased(gcn::MouseEvent &event); private: - ImageSet *mSmileyImg; + ImageSet *mEmoteImg; - bool mSmileyClicked; - int mSmileyMoved; + bool mEmoteClicked; + int mEmoteMoved; }; #endif diff --git a/src/gui/smileywindow.cpp b/src/gui/emotewindow.cpp index e3e821ff..af9648ef 100644 --- a/src/gui/smileywindow.cpp +++ b/src/gui/emotewindow.cpp @@ -1,22 +1,22 @@ /* - * The Mana World - * Copyright 2004 The Mana World Development Team + * Aethyra + * Copyright 2009 Aethyra Development Team * - * This file is part of The Mana World. + * This file is part of Aethyra. * - * The Mana World is free software; you can redistribute it and/or modify + * Aethyra 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, + * Aethyra 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 + * along with Aethyra; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include <string> @@ -25,8 +25,8 @@ #include "button.h" #include "gui.h" -#include "smileywindow.h" -#include "smileycontainer.h" +#include "emotewindow.h" +#include "emotecontainer.h" #include "scrollarea.h" #include "../localplayer.h" @@ -34,7 +34,7 @@ #include "../utils/gettext.h" #include "../utils/tostring.h" -SmileyWindow::SmileyWindow(): +EmoteWindow::EmoteWindow(): Window(_("Emote")) { setWindowName(_("Emote")); @@ -45,7 +45,7 @@ SmileyWindow::SmileyWindow(): mUseButton = new Button(_("Use"), "use", this); - mEmotes = new SmileyContainer(); + mEmotes = new EmoteContainer(); mEmotes->addSelectionListener(this); mInvenScroll = new ScrollArea(mEmotes); @@ -61,9 +61,9 @@ SmileyWindow::SmileyWindow(): loadWindowState(); } -void SmileyWindow::action(const gcn::ActionEvent &event) +void EmoteWindow::action(const gcn::ActionEvent &event) { - int emote = mEmotes->getSelectedSmiley(); + int emote = mEmotes->getSelectedEmote(); if (!emote) return; @@ -72,7 +72,7 @@ void SmileyWindow::action(const gcn::ActionEvent &event) } -void SmileyWindow::draw() +void EmoteWindow::draw() { const gcn::Rectangle &area = getChildrenArea(); const int width = area.width; @@ -86,14 +86,14 @@ void SmileyWindow::draw() setMinHeight(130); } -void SmileyWindow::widgetResized(const gcn::Event &event) +void EmoteWindow::widgetResized(const gcn::Event &event) { Window::widgetResized(event); draw(); } -int SmileyWindow::getSelectedSmiley() const +int EmoteWindow::getSelectedEmote() const { - return mEmotes->getSelectedSmiley(); + return mEmotes->getSelectedEmote(); } diff --git a/src/gui/smileywindow.h b/src/gui/emotewindow.h index db27fcbd..a382e37d 100644 --- a/src/gui/smileywindow.h +++ b/src/gui/emotewindow.h @@ -1,26 +1,26 @@ /* - * The Mana World - * Copyright 2004 The Mana World Development Team + * Aethyra + * Copyright 2009 Aethyra Development Team * - * This file is part of The Mana World. + * This file is part of Aethyra. * - * The Mana World is free software; you can redistribute it and/or modify + * Aethyra 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, + * Aethyra 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 + * along with Aethyra; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef _TMW_SMILEYWINDOW_H -#define _TMW_SMILEYWINDOW_H +#ifndef _AETHYRA_EMOTEWINDOW_H +#define _AETHYRA_EMOTEWINDOW_H #include <guichan/actionlistener.hpp> #include <guichan/selectionlistener.hpp> @@ -30,22 +30,21 @@ #include "../guichanfwd.h" -class Item; -class SmileyContainer; +class EmoteContainer; /** - * smiley dialog. + * Emote dialog. * * \ingroup Interface */ -class SmileyWindow : public Window, gcn::ActionListener, +class EmoteWindow : public Window, gcn::ActionListener, gcn::SelectionListener { public: /** * Constructor. */ - SmileyWindow(); + EmoteWindow(); /** * Called when receiving actions from the widgets. @@ -55,7 +54,7 @@ class SmileyWindow : public Window, gcn::ActionListener, /** * Returns the selected item. */ - int getSelectedSmiley() const; + int getSelectedEmote() const; /** * Updates window drawing. @@ -69,12 +68,12 @@ class SmileyWindow : public Window, gcn::ActionListener, private: - SmileyContainer *mEmotes; + EmoteContainer *mEmotes; gcn::Button *mUseButton; gcn::ScrollArea *mInvenScroll; }; -extern SmileyWindow *smileyWindow; +extern EmoteWindow *emoteWindow; #endif diff --git a/src/gui/itemshortcutcontainer.cpp b/src/gui/itemshortcutcontainer.cpp index b576e843..7e2eeac0 100644 --- a/src/gui/itemshortcutcontainer.cpp +++ b/src/gui/itemshortcutcontainer.cpp @@ -50,8 +50,8 @@ ItemShortcutContainer::ItemShortcutContainer(): mBackgroundImg->setAlpha(config.getValue("guialpha", 0.8)); - mBoxHeight = 42; - mBoxWidth = 36; + mBoxHeight = mBackgroundImg->getHeight(); + mBoxWidth = mBackgroundImg->getWidth(); } ItemShortcutContainer::~ItemShortcutContainer() @@ -89,7 +89,7 @@ ItemShortcutContainer::draw(gcn::Graphics *graphics) // Draw item keyboard shortcut. const char *key = SDL_GetKeyName( - (SDLKey) keyboard.getKeyValue(keyboard.KEY_SHORTCUT_0 + i)); + (SDLKey) keyboard.getKeyValue(keyboard.KEY_SHORTCUT_1 + i)); graphics->setColor(0x000000); g->drawText(key, itemX + 2, itemY + 2, gcn::Graphics::LEFT); diff --git a/src/gui/menuwindow.cpp b/src/gui/menuwindow.cpp index 99eaca34..2a175a61 100644 --- a/src/gui/menuwindow.cpp +++ b/src/gui/menuwindow.cpp @@ -33,7 +33,7 @@ extern Window *chatWindow; extern Window *equipmentWindow; extern Window *inventoryWindow; extern Window *itemShortcutWindow; -extern Window *smileyWindow; +extern Window *emoteWindow; extern Window *setupWindow; extern Window *skillDialog; extern Window *statusWindow; @@ -120,7 +120,7 @@ void MenuWindowListener::action(const gcn::ActionEvent &event) } else if (event.getId() == _("Emote")) { - window = smileyWindow; + window = emoteWindow; } else if (event.getId() == _("Setup")) { diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index bcffbae0..66f15f03 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -43,8 +43,8 @@ extern Window *minimap; extern Window *skillDialog; extern Window *statusWindow; extern Window *itemShortcutWindow; -extern Window *smileyShortcutWindow; -extern Window *smileyWindow; +extern Window *emoteShortcutWindow; +extern Window *emoteWindow; extern Window *tradeWindow; Setup::Setup(): @@ -138,8 +138,8 @@ void Setup::action(const gcn::ActionEvent &event) helpWindow->resetToDefaultSize(); skillDialog->resetToDefaultSize(); itemShortcutWindow->resetToDefaultSize(); - smileyShortcutWindow->resetToDefaultSize(); - smileyWindow->resetToDefaultSize(); + emoteShortcutWindow->resetToDefaultSize(); + emoteWindow->resetToDefaultSize(); tradeWindow->resetToDefaultSize(); } } diff --git a/src/gui/setup.h b/src/gui/setup.h index fd200f4c..1ad93cac 100644 --- a/src/gui/setup.h +++ b/src/gui/setup.h @@ -53,8 +53,7 @@ class Setup : public Window, public gcn::ActionListener /** * Event handling method. */ - void - action(const gcn::ActionEvent &event); + void action(const gcn::ActionEvent &event); private: std::list<SetupTab*> mTabs; diff --git a/src/gui/shortcutcontainer.cpp b/src/gui/shortcutcontainer.cpp index 32d7c6af..88d9bb22 100644 --- a/src/gui/shortcutcontainer.cpp +++ b/src/gui/shortcutcontainer.cpp @@ -43,7 +43,8 @@ ShortcutContainer::ShortcutContainer(): void ShortcutContainer::widgetResized(const gcn::Event &event) { mGridWidth = getWidth() / mBoxWidth; - if (mGridWidth < 1) { + if (mGridWidth < 1) + { mGridWidth = 1; } @@ -51,7 +52,8 @@ void ShortcutContainer::widgetResized(const gcn::Event &event) (mMaxItems % mGridWidth > 0 ? 1 : 0)) * mBoxHeight); mGridHeight = getHeight() / mBoxHeight; - if (mGridHeight < 1) { + if (mGridHeight < 1) + { mGridHeight = 1; } } @@ -61,7 +63,8 @@ ShortcutContainer::getIndexFromGrid(int pointX, int pointY) const { const gcn::Rectangle tRect = gcn::Rectangle( 0, 0, mGridWidth * mBoxWidth, mGridHeight * mBoxHeight); - if (!tRect.isPointInRect(pointX, pointY)) { + if (!tRect.isPointInRect(pointX, pointY)) + { return -1; } const int index = ((pointY / mBoxHeight) * mGridWidth) + diff --git a/src/gui/shortcutcontainer.h b/src/gui/shortcutcontainer.h index ebc0a9fc..9d0584d3 100644 --- a/src/gui/shortcutcontainer.h +++ b/src/gui/shortcutcontainer.h @@ -29,7 +29,6 @@ #include "../guichanfwd.h" class Image; -class Item; /** * An item shortcut container. Used to quickly use items. @@ -54,7 +53,7 @@ class ShortcutContainer : public gcn::Widget, /** * Draws the items. */ - virtual void draw(gcn::Graphics *graphics)=0; + virtual void draw(gcn::Graphics *graphics) = 0; /** * Invoked when a widget changes its size. This is used to determine @@ -65,17 +64,17 @@ class ShortcutContainer : public gcn::Widget, /** * Handles mouse when dragged. */ - virtual void mouseDragged(gcn::MouseEvent &event)=0; + virtual void mouseDragged(gcn::MouseEvent &event) = 0; /** * Handles mouse when pressed. */ - virtual void mousePressed(gcn::MouseEvent &event)=0; + virtual void mousePressed(gcn::MouseEvent &event) = 0; /** * Handles mouse release. */ - virtual void mouseReleased(gcn::MouseEvent &event)=0; + virtual void mouseReleased(gcn::MouseEvent &event) = 0; virtual int getMaxItems() { return mMaxItems; } diff --git a/src/gui/shortcutwindow.h b/src/gui/shortcutwindow.h index b5a23c2c..9ac1a52a 100644 --- a/src/gui/shortcutwindow.h +++ b/src/gui/shortcutwindow.h @@ -60,6 +60,6 @@ class ShortcutWindow : public Window }; extern ShortcutWindow *itemShortcutWindow; -extern ShortcutWindow *smileyShortcutWindow; +extern ShortcutWindow *emoteShortcutWindow; #endif diff --git a/src/gui/smileyshortcutcontainer.cpp b/src/gui/smileyshortcutcontainer.cpp deleted file mode 100644 index c3cd056d..00000000 --- a/src/gui/smileyshortcutcontainer.cpp +++ /dev/null @@ -1,179 +0,0 @@ -/* - * 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 "smileyshortcutcontainer.h" - -#include "../graphics.h" -#include "../inventory.h" -#include "../item.h" -#include "../itemshortcut.h" -#include "../smileyshortcut.h" -#include "../keyboardconfig.h" -#include "../localplayer.h" -#include "../log.h" - - -#include "../resources/image.h" -#include "../resources/resourcemanager.h" - -#include "../utils/gettext.h" -#include "../utils/tostring.h" - -SmileyShortcutContainer::SmileyShortcutContainer(): - mSmileyClicked(false), - mSmileyMoved(0) -{ - mGridWidth = 1, - mGridHeight = 1, - addMouseListener(this); - addWidgetListener(this); - - ResourceManager *resman = ResourceManager::getInstance(); - - mBackgroundImg = resman->getImage("graphics/gui/item_shortcut_bgr.png"); - mSmileyImg = resman->getImageSet("graphics/sprites/emotions.png", 30, 32); - if (!mSmileyImg) logger->error(_("Unable to load emotions")); - - mMaxItems = smileyShortcut->getSmileyCount(); - - mBoxHeight = 42; - mBoxWidth = 36; -} - -SmileyShortcutContainer::~SmileyShortcutContainer() -{ - mBackgroundImg->decRef(); - if (mSmileyImg) - { - mSmileyImg->decRef(); - mSmileyImg=NULL; - } - -} - -void -SmileyShortcutContainer::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_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(smileyShortcut->getSmiley(i)-1), itemX+2, itemY+10); - } - - } - if (mSmileyMoved) - { - // Draw the item image being dragged by the cursor. - 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); - } - } -} - -void -SmileyShortcutContainer::mouseDragged(gcn::MouseEvent &event) -{ - 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; - } - // 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 (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; - } - } -} - |