00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "emoteshortcutcontainer.h"
00023 #include "palette.h"
00024
00025 #include "../animatedsprite.h"
00026 #include "../configuration.h"
00027 #include "../emoteshortcut.h"
00028 #include "../graphics.h"
00029 #include "../inventory.h"
00030 #include "../item.h"
00031 #include "../itemshortcut.h"
00032 #include "../keyboardconfig.h"
00033 #include "../localplayer.h"
00034 #include "../log.h"
00035
00036 #include "../resources/emotedb.h"
00037 #include "../resources/image.h"
00038 #include "../resources/resourcemanager.h"
00039
00040 #include "../utils/dtor.h"
00041 #include "../utils/gettext.h"
00042 #include "../utils/stringutils.h"
00043
00044 static const int MAX_ITEMS = 12;
00045
00046 EmoteShortcutContainer::EmoteShortcutContainer():
00047 ShortcutContainer(),
00048 mEmoteClicked(false),
00049 mEmoteMoved(0)
00050 {
00051 addMouseListener(this);
00052 addWidgetListener(this);
00053
00054 ResourceManager *resman = ResourceManager::getInstance();
00055
00056 mBackgroundImg = resman->getImage("graphics/gui/item_shortcut_bgr.png");
00057
00058 mBackgroundImg->setAlpha(config.getValue("guialpha", 0.8));
00059
00060
00061 for (int i = 0; i <= EmoteDB::getLast(); i++)
00062 {
00063 mEmoteImg.push_back(EmoteDB::getAnimation(i));
00064 }
00065
00066 mMaxItems = EmoteDB::getLast() < MAX_ITEMS ? EmoteDB::getLast() : MAX_ITEMS;
00067
00068 mBoxHeight = mBackgroundImg->getHeight();
00069 mBoxWidth = mBackgroundImg->getWidth();
00070 }
00071
00072 EmoteShortcutContainer::~EmoteShortcutContainer()
00073 {
00074 mBackgroundImg->decRef();
00075 }
00076
00077 void EmoteShortcutContainer::draw(gcn::Graphics *graphics)
00078 {
00079 if (config.getValue("guialpha", 0.8) != mAlpha)
00080 {
00081 mAlpha = config.getValue("guialpha", 0.8);
00082 mBackgroundImg->setAlpha(mAlpha);
00083 }
00084
00085 Graphics *g = static_cast<Graphics*>(graphics);
00086
00087 graphics->setFont(getFont());
00088
00089 for (int i = 0; i < mMaxItems; i++)
00090 {
00091 const int emoteX = (i % mGridWidth) * mBoxWidth;
00092 const int emoteY = (i / mGridWidth) * mBoxHeight;
00093
00094 g->drawImage(mBackgroundImg, emoteX, emoteY);
00095
00096
00097 const char *key = SDL_GetKeyName(
00098 (SDLKey) keyboard.getKeyValue(keyboard.KEY_EMOTE_1 + i));
00099 graphics->setColor(guiPalette->getColor(Palette::TEXT));
00100 g->drawText(key, emoteX + 2, emoteY + 2, gcn::Graphics::LEFT);
00101
00102 if (emoteShortcut->getEmote(i))
00103 {
00104 mEmoteImg[emoteShortcut->getEmote(i) - 1]->draw(g, emoteX + 2,
00105 emoteY + 10);
00106 }
00107
00108 }
00109
00110 if (mEmoteMoved)
00111 {
00112
00113 const AnimatedSprite* sprite = mEmoteImg[mEmoteMoved - 1];
00114 if (sprite)
00115 {
00116 const int tPosX = mCursorPosX - (sprite->getWidth() / 2);
00117 const int tPosY = mCursorPosY - (sprite->getHeight() / 2);
00118
00119 sprite->draw(g, tPosX, tPosY);
00120 }
00121 }
00122 }
00123
00124 void EmoteShortcutContainer::mouseDragged(gcn::MouseEvent &event)
00125 {
00126 if (event.getButton() == gcn::MouseEvent::LEFT)
00127 {
00128 if (!mEmoteMoved && mEmoteClicked)
00129 {
00130 const int index = getIndexFromGrid(event.getX(), event.getY());
00131 const int emoteId = emoteShortcut->getEmote(index);
00132
00133 if (index == -1)
00134 return;
00135
00136 if (emoteId)
00137 {
00138 mEmoteMoved = emoteId;
00139 emoteShortcut->removeEmote(index);
00140 }
00141 }
00142 if (mEmoteMoved)
00143 {
00144 mCursorPosX = event.getX();
00145 mCursorPosY = event.getY();
00146 }
00147 }
00148 }
00149
00150 void EmoteShortcutContainer::mousePressed(gcn::MouseEvent &event)
00151 {
00152 const int index = getIndexFromGrid(event.getX(), event.getY());
00153
00154 if (index == -1)
00155 return;
00156
00157
00158 if (emoteShortcut->isEmoteSelected())
00159 {
00160 emoteShortcut->setEmote(index);
00161 emoteShortcut->setEmoteSelected(0);
00162 }
00163 else if (emoteShortcut->getEmote(index))
00164 {
00165 mEmoteClicked = true;
00166 }
00167 }
00168
00169 void EmoteShortcutContainer::mouseReleased(gcn::MouseEvent &event)
00170 {
00171 if (event.getButton() == gcn::MouseEvent::LEFT)
00172 {
00173 const int index = getIndexFromGrid(event.getX(), event.getY());
00174
00175 if (emoteShortcut->isEmoteSelected())
00176 emoteShortcut->setEmoteSelected(0);
00177
00178 if (index == -1)
00179 {
00180 mEmoteMoved = 0;
00181 return;
00182 }
00183
00184 if (mEmoteMoved)
00185 {
00186 emoteShortcut->setEmotes(index, mEmoteMoved);
00187 mEmoteMoved = 0;
00188 }
00189 else if (emoteShortcut->getEmote(index) && mEmoteClicked)
00190 {
00191 emoteShortcut->useEmote(index + 1);
00192 }
00193
00194 if (mEmoteClicked)
00195 mEmoteClicked = false;
00196 }
00197 }
00198