summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/emoteshortcut.cpp20
-rw-r--r--src/emoteshortcut.h12
-rw-r--r--src/game.cpp2
-rw-r--r--src/gui/emotepopup.cpp96
-rw-r--r--src/gui/emotepopup.h14
-rw-r--r--src/gui/widgets/emoteshortcutcontainer.cpp55
-rw-r--r--src/gui/widgets/emoteshortcutcontainer.h8
-rw-r--r--src/gui/windowmenu.cpp6
-rw-r--r--src/keyboardconfig.cpp4
-rw-r--r--src/localplayer.cpp4
-rw-r--r--src/localplayer.h2
-rw-r--r--src/net/tmwa/beinghandler.cpp2
-rw-r--r--src/net/tmwa/playerhandler.cpp2
-rw-r--r--src/resources/emotedb.cpp71
-rw-r--r--src/resources/emotedb.h13
15 files changed, 141 insertions, 170 deletions
diff --git a/src/emoteshortcut.cpp b/src/emoteshortcut.cpp
index 37d05647..69692437 100644
--- a/src/emoteshortcut.cpp
+++ b/src/emoteshortcut.cpp
@@ -28,8 +28,7 @@
EmoteShortcut *emoteShortcut;
-EmoteShortcut::EmoteShortcut():
- mEmoteSelected(0)
+EmoteShortcut::EmoteShortcut()
{
load();
}
@@ -43,9 +42,7 @@ void EmoteShortcut::load()
{
for (int i = 0; i < SHORTCUT_EMOTES; i++)
{
- int emoteId = (int) config.getValue("emoteshortcut" + toString(i), i + 1);
-
- mEmotes[i] = emoteId;
+ mEmotes[i] = (int) config.getValue("emoteshortcut" + toString(i), i + 1);
}
}
@@ -53,18 +50,17 @@ void EmoteShortcut::save()
{
for (int i = 0; i < SHORTCUT_EMOTES; i++)
{
- const int emoteId = mEmotes[i] ? mEmotes[i] : 0;
- config.setValue("emoteshortcut" + toString(i), emoteId);
+ config.setValue("emoteshortcut" + toString(i), mEmotes[i]);
}
}
void EmoteShortcut::useEmote(int index)
{
- if ((index > 0) && (index <= SHORTCUT_EMOTES))
+ if (index >= 0 && index < SHORTCUT_EMOTES)
{
- if (mEmotes[index - 1] > 0)
- {
- local_player->emote(mEmotes[index - 1]);
- }
+ if (mEmotes[index] > 0)
+ {
+ local_player->emote(mEmotes[index] - 1);
+ }
}
}
diff --git a/src/emoteshortcut.h b/src/emoteshortcut.h
index 0d64e6da..598cc124 100644
--- a/src/emoteshortcut.h
+++ b/src/emoteshortcut.h
@@ -45,7 +45,7 @@ class EmoteShortcut
* @param index Index of the shortcut Emote.
*/
int getEmote(int index) const
- { return mEmotes[index]; }
+ { return mEmotes[index] - 1; }
/**
* Returns the amount of shortcut Emotes.
@@ -65,7 +65,7 @@ class EmoteShortcut
* @param index Index of the emotes.
*/
void setEmote(int index)
- { mEmotes[index] = mEmoteSelected; }
+ { setEmotes(index, mEmoteSelected); }
/**
* Adds a emoticon to the emotes store specified by the index.
@@ -74,7 +74,7 @@ class EmoteShortcut
* @param emoteId ID of the emote.
*/
void setEmotes(int index, int emoteId)
- { mEmotes[index] = emoteId; }
+ { mEmotes[index] = emoteId + 1; }
/**
* Set the Emote that is selected.
@@ -87,8 +87,8 @@ class EmoteShortcut
/**
* A flag to check if the Emote is selected.
*/
- bool isEmoteSelected()
- { return mEmoteSelected; }
+ bool isEmoteSelected() const
+ { return mEmoteSelected != -1; }
/**
* Remove a Emote from the shortcut.
@@ -110,7 +110,7 @@ class EmoteShortcut
void save();
int mEmotes[SHORTCUT_EMOTES]; /**< The emote stored. */
- int mEmoteSelected; /**< The emote held by cursor. */
+ int mEmoteSelected = -1; /**< The emote held by cursor. */
};
diff --git a/src/game.cpp b/src/game.cpp
index 49f33db0..90721224 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -436,7 +436,7 @@ void Game::handleInput()
{
// Emotions
int emotion = keyboard.getKeyEmoteOffset(event.key.keysym.sym);
- if (emotion)
+ if (emotion != -1)
{
emoteShortcut->useEmote(emotion);
used = true;
diff --git a/src/gui/emotepopup.cpp b/src/gui/emotepopup.cpp
index 104f1283..b732705e 100644
--- a/src/gui/emotepopup.cpp
+++ b/src/gui/emotepopup.cpp
@@ -26,16 +26,12 @@
#include "configuration.h"
#include "emoteshortcut.h"
#include "graphics.h"
-#include "localplayer.h"
#include "log.h"
#include "resources/emotedb.h"
#include "resources/image.h"
-#include "resources/iteminfo.h"
#include "resources/theme.h"
-#include "utils/dtor.h"
-
#include <guichan/mouseinput.hpp>
#include <guichan/selectionlistener.hpp>
@@ -46,12 +42,6 @@ static const int MAX_COLUMNS = 6;
EmotePopup::EmotePopup()
{
- // Setup emote sprites
- for (int i = 0; i <= EmoteDB::getLast(); ++i)
- {
- mEmotes.push_back(EmoteDB::get(i)->sprite);
- }
-
mSelectionImage = Theme::getImageFromTheme("selection.png");
if (!mSelectionImage)
logger->error("Unable to load selection.png");
@@ -72,8 +62,7 @@ void EmotePopup::draw(gcn::Graphics *graphics)
{
Popup::draw(graphics);
- const int emoteCount = mEmotes.size();
- const int emotesLeft = mEmotes.size() % mColumnCount;
+ const int emoteCount = EmoteDB::getEmoteCount();
for (int i = 0; i < emoteCount ; i++)
{
@@ -84,8 +73,11 @@ void EmotePopup::draw(gcn::Graphics *graphics)
int emoteY = 4 + row * gridHeight;
// Center the last row when there are less emotes than columns
- if (emotesLeft > 0 && row == mRowCount - 1)
+ if (row == mRowCount - 1)
+ {
+ const int emotesLeft = emoteCount % mColumnCount;
emoteX += (mColumnCount - emotesLeft) * gridWidth / 2;
+ }
// Draw selection image below hovered item
if (i == mHoveredEmoteIndex)
@@ -95,10 +87,17 @@ void EmotePopup::draw(gcn::Graphics *graphics)
}
// Draw emote icon
- mEmotes[i]->draw(static_cast<Graphics*>(graphics), emoteX, emoteY);
+ EmoteDB::getByIndex(i).sprite->draw(static_cast<Graphics*>(graphics), emoteX, emoteY);
}
}
+void EmotePopup::mouseExited(gcn::MouseEvent &event)
+{
+ Popup::mouseExited(event);
+
+ mHoveredEmoteIndex = -1;
+}
+
void EmotePopup::mousePressed(gcn::MouseEvent &event)
{
if (event.getButton() != gcn::MouseEvent::LEFT)
@@ -107,8 +106,10 @@ void EmotePopup::mousePressed(gcn::MouseEvent &event)
const int index = getIndexAt(event.getX(), event.getY());
if (index != -1)
{
- setSelectedEmoteIndex(index);
- emoteShortcut->setEmoteSelected(index + 1);
+ const int emoteId = EmoteDB::getByIndex(index).id;
+
+ setSelectedEmoteId(emoteId);
+ emoteShortcut->setEmoteSelected(emoteId);
}
}
@@ -119,41 +120,45 @@ void EmotePopup::mouseMoved(gcn::MouseEvent &event)
mHoveredEmoteIndex = getIndexAt(event.getX(), event.getY());
}
-int EmotePopup::getSelectedEmote() const
+int EmotePopup::getSelectedEmoteId() const
{
- return 1 + mSelectedEmoteIndex;
+ return mSelectedEmoteId;
}
-void EmotePopup::setSelectedEmoteIndex(int index)
+void EmotePopup::setSelectedEmoteId(int emoteId)
{
- if (index == mSelectedEmoteIndex)
+ if (emoteId == mSelectedEmoteId)
return;
- mSelectedEmoteIndex = index;
+ mSelectedEmoteId = emoteId;
distributeValueChangedEvent();
}
int EmotePopup::getIndexAt(int x, int y) const
{
- const int emotesLeft = mEmotes.size() % mColumnCount;
+ if (mColumnCount <= 0)
+ return -1;
+
+ // Take into account the border
+ x -= 2;
+ y -= 4;
+
const int row = y / gridHeight;
- int column;
// Take into account that the last row is centered
- if (emotesLeft > 0 && row == mRowCount - 1)
- {
- int emotesMissing = mColumnCount - emotesLeft;
- column = std::min((x - emotesMissing * gridWidth / 2) / gridWidth,
- emotesLeft - 1);
- }
- else
+ if (row == mRowCount - 1)
{
- column = std::min(x / gridWidth, mColumnCount - 1);
+ const int emotesLeft = EmoteDB::getEmoteCount() % mColumnCount;
+ const int emotesMissing = mColumnCount - emotesLeft;
+ x -= emotesMissing * gridWidth / 2;
+ if (x < 0)
+ return -1;
}
- int index = column + (row * mColumnCount);
+ const int column = std::min(x / gridWidth, mColumnCount - 1);
+ const int index = column + (row * mColumnCount);
- if ((unsigned) index < mEmotes.size())
+ if (index >= 0 && index < EmoteDB::getEmoteCount())
return index;
return -1;
@@ -161,27 +166,28 @@ int EmotePopup::getIndexAt(int x, int y) const
void EmotePopup::recalculateSize()
{
- const unsigned emoteCount = mEmotes.size();
+ const int emoteCount = EmoteDB::getEmoteCount();
- mRowCount = emoteCount / MAX_COLUMNS;
- if (emoteCount % MAX_COLUMNS > 0)
- ++mRowCount;
+ if (emoteCount > 0) {
+ mRowCount = emoteCount / MAX_COLUMNS;
+ if (emoteCount % MAX_COLUMNS > 0)
+ ++mRowCount;
- mColumnCount = emoteCount / mRowCount;
- if (emoteCount % mRowCount > 0)
- ++mColumnCount;
+ mColumnCount = std::min(MAX_COLUMNS, emoteCount);
+ } else {
+ mRowCount = 0;
+ mColumnCount = 0;
+ }
setContentSize(mColumnCount * gridWidth, mRowCount * gridHeight);
}
void EmotePopup::distributeValueChangedEvent()
{
- gcn::SelectionEvent event(this);
- Listeners::const_iterator i_end = mListeners.end();
- Listeners::const_iterator i;
+ const gcn::SelectionEvent event(this);
- for (i = mListeners.begin(); i != i_end; ++i)
+ for (auto &listener : mListeners)
{
- (*i)->valueChanged(event);
+ listener->valueChanged(event);
}
}
diff --git a/src/gui/emotepopup.h b/src/gui/emotepopup.h
index ee905cd6..ef3fffed 100644
--- a/src/gui/emotepopup.h
+++ b/src/gui/emotepopup.h
@@ -28,9 +28,7 @@
#include <guichan/mouselistener.hpp>
#include <list>
-#include <vector>
-class ImageSprite;
class Image;
namespace gcn {
@@ -57,13 +55,14 @@ class EmotePopup : public Popup
*/
void draw(gcn::Graphics *graphics) override;
+ void mouseExited(gcn::MouseEvent &event) override;
void mousePressed(gcn::MouseEvent &event) override;
void mouseMoved(gcn::MouseEvent &event) override;
/**
* Returns the selected emote.
*/
- int getSelectedEmote() const;
+ int getSelectedEmoteId() const;
/**
* Adds a listener to the list that's notified each time a change to
@@ -87,7 +86,7 @@ class EmotePopup : public Popup
/**
* Sets the index of the currently selected emote.
*/
- void setSelectedEmoteIndex(int index);
+ void setSelectedEmoteId(int emoteId);
/**
* Returns the index at the specified coordinates. Returns -1 when
@@ -105,17 +104,14 @@ class EmotePopup : public Popup
*/
void distributeValueChangedEvent();
- std::vector<const ImageSprite*> mEmotes;
Image *mSelectionImage;
- int mSelectedEmoteIndex = -1;
+ int mSelectedEmoteId = -1;
int mHoveredEmoteIndex = -1;
int mRowCount = 1;
int mColumnCount = 1;
- using Listeners = std::list<gcn::SelectionListener *>;
-
- Listeners mListeners;
+ std::list<gcn::SelectionListener *> mListeners;
static const int gridWidth;
static const int gridHeight;
diff --git a/src/gui/widgets/emoteshortcutcontainer.cpp b/src/gui/widgets/emoteshortcutcontainer.cpp
index b719bc5f..f4a5449f 100644
--- a/src/gui/widgets/emoteshortcutcontainer.cpp
+++ b/src/gui/widgets/emoteshortcutcontainer.cpp
@@ -43,13 +43,7 @@ EmoteShortcutContainer::EmoteShortcutContainer()
mBackgroundImg->setAlpha(config.getFloatValue("guialpha"));
- // Setup emote sprites
- for (int i = 0; i <= EmoteDB::getLast(); i++)
- {
- mEmoteImg.push_back(EmoteDB::get(i)->sprite);
- }
-
- mMaxItems = std::min(EmoteDB::getLast(), MAX_ITEMS);
+ mMaxItems = std::min(EmoteDB::getEmoteCount(), MAX_ITEMS);
mBoxHeight = mBackgroundImg->getHeight();
mBoxWidth = mBackgroundImg->getWidth();
@@ -81,28 +75,26 @@ void EmoteShortcutContainer::draw(gcn::Graphics *graphics)
// Draw emote keyboard shortcut.
const char *key = SDL_GetKeyName(
- (SDL_Scancode) keyboard.getKeyValue(keyboard.KEY_EMOTE_1 + i));
+ (SDL_Scancode) keyboard.getKeyValue(KeyboardConfig::KEY_EMOTE_1 + i));
graphics->setColor(Theme::getThemeColor(Theme::TEXT));
g->drawText(key, emoteX + 2, emoteY + 2, gcn::Graphics::LEFT);
int emoteId = emoteShortcut->getEmote(i);
- if (emoteId > 0 && emoteId <= EmoteDB::getLast() + 1)
+ if (emoteId != -1)
{
- mEmoteImg[emoteId - 1]->draw(g, emoteX + 2, emoteY + 10);
+ EmoteDB::get(emoteId).sprite->draw(g, emoteX + 2, emoteY + 10);
}
}
- if (mEmoteMoved)
+ if (mEmoteMoved != -1)
{
// Draw the emote image being dragged by the cursor.
- const ImageSprite* sprite = mEmoteImg[mEmoteMoved - 1];
- if (sprite)
- {
- const int tPosX = mCursorPosX - (sprite->getWidth() / 2);
- const int tPosY = mCursorPosY - (sprite->getHeight() / 2);
+ const ImageSprite *sprite = EmoteDB::get(mEmoteMoved).sprite;
- sprite->draw(g, tPosX, tPosY);
- }
+ const int tPosX = mCursorPosX - (sprite->getWidth() / 2);
+ const int tPosY = mCursorPosY - (sprite->getHeight() / 2);
+
+ sprite->draw(g, tPosX, tPosY);
}
}
@@ -110,22 +102,20 @@ void EmoteShortcutContainer::mouseDragged(gcn::MouseEvent &event)
{
if (event.getButton() == gcn::MouseEvent::LEFT)
{
- if (!mEmoteMoved && mEmoteClicked)
+ if (mEmoteMoved == -1 && mEmoteClicked)
{
const int index = getIndexFromGrid(event.getX(), event.getY());
-
if (index == -1)
return;
const int emoteId = emoteShortcut->getEmote(index);
-
- if (emoteId)
+ if (emoteId != -1)
{
mEmoteMoved = emoteId;
emoteShortcut->removeEmote(index);
}
}
- if (mEmoteMoved)
+ if (mEmoteMoved != -1)
{
mCursorPosX = event.getX();
mCursorPosY = event.getY();
@@ -144,9 +134,9 @@ void EmoteShortcutContainer::mousePressed(gcn::MouseEvent &event)
if (emoteShortcut->isEmoteSelected())
{
emoteShortcut->setEmote(index);
- emoteShortcut->setEmoteSelected(0);
+ emoteShortcut->setEmoteSelected(-1);
}
- else if (emoteShortcut->getEmote(index))
+ else if (emoteShortcut->getEmote(index) != -1)
{
mEmoteClicked = true;
}
@@ -159,26 +149,25 @@ void EmoteShortcutContainer::mouseReleased(gcn::MouseEvent &event)
const int index = getIndexFromGrid(event.getX(), event.getY());
if (emoteShortcut->isEmoteSelected())
- emoteShortcut->setEmoteSelected(0);
+ emoteShortcut->setEmoteSelected(-1);
if (index == -1)
{
- mEmoteMoved = 0;
+ mEmoteMoved = -1;
return;
}
- if (mEmoteMoved)
+ if (mEmoteMoved != -1)
{
emoteShortcut->setEmotes(index, mEmoteMoved);
- mEmoteMoved = 0;
+ mEmoteMoved = -1;
}
- else if (emoteShortcut->getEmote(index) && mEmoteClicked)
+ else if (mEmoteClicked)
{
- emoteShortcut->useEmote(index + 1);
+ emoteShortcut->useEmote(index);
}
- if (mEmoteClicked)
- mEmoteClicked = false;
+ mEmoteClicked = false;
}
}
diff --git a/src/gui/widgets/emoteshortcutcontainer.h b/src/gui/widgets/emoteshortcutcontainer.h
index 209a3725..ecd41736 100644
--- a/src/gui/widgets/emoteshortcutcontainer.h
+++ b/src/gui/widgets/emoteshortcutcontainer.h
@@ -24,10 +24,6 @@
#include "gui/widgets/shortcutcontainer.h"
-#include <vector>
-
-class ImageSprite;
-
/**
* An emote shortcut container. Used to quickly use emoticons.
*
@@ -61,10 +57,8 @@ class EmoteShortcutContainer : public ShortcutContainer
void mouseReleased(gcn::MouseEvent &event) override;
private:
- std::vector<const ImageSprite*> mEmoteImg;
-
bool mEmoteClicked = false;
- int mEmoteMoved = 0;
+ int mEmoteMoved = -1;
};
#endif
diff --git a/src/gui/windowmenu.cpp b/src/gui/windowmenu.cpp
index aff7c5c5..01194c0b 100644
--- a/src/gui/windowmenu.cpp
+++ b/src/gui/windowmenu.cpp
@@ -153,9 +153,9 @@ void WindowMenu::valueChanged(const gcn::SelectionEvent &event)
{
if (event.getSource() == mEmotePopup)
{
- int emote = mEmotePopup->getSelectedEmote();
- if (emote)
- Net::getPlayerHandler()->emote(emote);
+ int emoteId = mEmotePopup->getSelectedEmoteId();
+ if (emoteId != -1)
+ Net::getPlayerHandler()->emote(emoteId);
windowContainer->scheduleDelete(mEmotePopup);
mEmotePopup = nullptr;
diff --git a/src/keyboardconfig.cpp b/src/keyboardconfig.cpp
index 42ef9440..442ec046 100644
--- a/src/keyboardconfig.cpp
+++ b/src/keyboardconfig.cpp
@@ -218,10 +218,10 @@ int KeyboardConfig::getKeyEmoteOffset(int keyValue) const
{
if (keyValue == mKey[i].value)
{
- return 1 + i - KEY_EMOTE_1;
+ return i - KEY_EMOTE_1;
}
}
- return 0;
+ return -1;
}
bool KeyboardConfig::isKeyActive(int index) const
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index 95fbd6f4..934155dd 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -810,13 +810,13 @@ void LocalPlayer::toggleSit()
Net::getPlayerHandler()->changeAction(newAction);
}
-void LocalPlayer::emote(Uint8 emotion)
+void LocalPlayer::emote(int emoteId)
{
if (mLastActionTime != -1)
return;
mLastActionTime = tick_time;
- Net::getPlayerHandler()->emote(emotion);
+ Net::getPlayerHandler()->emote(emoteId);
}
void LocalPlayer::attack(Being *target, bool keep)
diff --git a/src/localplayer.h b/src/localplayer.h
index 82e38b5b..de588402 100644
--- a/src/localplayer.h
+++ b/src/localplayer.h
@@ -160,7 +160,7 @@ class LocalPlayer : public Being
bool withinRange(Actor *target, int range) const;
void toggleSit();
- void emote(uint8_t emotion);
+ void emote(int emoteId);
/**
* Shows item pickup notifications.
diff --git a/src/net/tmwa/beinghandler.cpp b/src/net/tmwa/beinghandler.cpp
index 33908fc9..4c7e18bb 100644
--- a/src/net/tmwa/beinghandler.cpp
+++ b/src/net/tmwa/beinghandler.cpp
@@ -402,7 +402,7 @@ void BeingHandler::handleMessage(MessageIn &msg)
if (player_relations.hasPermission(dstBeing, PlayerRelation::EMOTE))
{
- const int fx = EmoteDB::get(msg.readInt8() - 1)->effect;
+ const int fx = EmoteDB::get(msg.readInt8() - 1).effectId;
effectManager->trigger(fx, dstBeing);
}
diff --git a/src/net/tmwa/playerhandler.cpp b/src/net/tmwa/playerhandler.cpp
index 9c1a7135..431137fd 100644
--- a/src/net/tmwa/playerhandler.cpp
+++ b/src/net/tmwa/playerhandler.cpp
@@ -534,7 +534,7 @@ void PlayerHandler::attack(int id)
void PlayerHandler::emote(int emoteId)
{
MessageOut outMsg(CMSG_PLAYER_EMOTE);
- outMsg.writeInt8(emoteId);
+ outMsg.writeInt8(emoteId + 1);
}
void PlayerHandler::increaseAttribute(int attr)
diff --git a/src/resources/emotedb.cpp b/src/resources/emotedb.cpp
index 752f7b4f..e1dd8f4a 100644
--- a/src/resources/emotedb.cpp
+++ b/src/resources/emotedb.cpp
@@ -27,12 +27,14 @@
#include "resources/resourcemanager.h"
#include "resources/imageset.h"
+#include <algorithm>
+#include <vector>
+
namespace
{
- Emotes mEmotes;
+ std::vector<Emote> mEmotes;
Emote mUnknown;
bool mLoaded = false;
- int mLastEmote = 0;
}
void EmoteDB::init()
@@ -41,33 +43,30 @@ void EmoteDB::init()
unload();
mUnknown.name = "unknown";
- mUnknown.effect = -1;
+ mUnknown.effectId = -1;
mUnknown.sprite = new ImageSprite(
ResourceManager::getInstance()->getImage("graphics/sprites/error.png"));
-
- mLastEmote = 0;
-
}
void EmoteDB::readEmoteNode(xmlNodePtr node, const std::string &filename)
{
- int id = XML::getProperty(node, "id", -1);
+ const int id = XML::getProperty(node, "id", -1);
if (id == -1)
{
logger->log("Emote Database: Emote with missing ID in %s!", filename.c_str());
return;
}
- auto *currentEmote = new Emote;
+ Emote currentEmote;
- currentEmote->name = XML::getProperty(node, "name", "unknown");
- currentEmote->effect = XML::getProperty(node, "effectid", -1);
+ currentEmote.id = id;
+ currentEmote.name = XML::getProperty(node, "name", "unknown");
+ currentEmote.effectId = XML::getProperty(node, "effectid", -1);
- if (currentEmote->effect == -1)
+ if (currentEmote.effectId == -1)
{
logger->log("Emote Database: Warning: Emote %s has no attached effect in %s!",
- currentEmote->name.c_str(), filename.c_str());
- delete currentEmote;
+ currentEmote.name.c_str(), filename.c_str());
return;
}
@@ -78,31 +77,25 @@ void EmoteDB::readEmoteNode(xmlNodePtr node, const std::string &filename)
if (imageName.empty() || width <= 0 || height <= 0)
{
logger->log("Emote Database: Warning: Emote %s has bad imageset values in %s",
- currentEmote->name.c_str(), filename.c_str());
- delete currentEmote;
+ currentEmote.name.c_str(), filename.c_str());
return;
}
ImageSet *is = ResourceManager::getInstance()->getImageSet(imageName,
width,
height);
- if (!is || !(is->size() > 0))
+ if (!is || is->size() == 0)
{
logger->log("Emote Database: Error loading imageset for emote %s in %s",
- currentEmote->name.c_str(), filename.c_str());
+ currentEmote.name.c_str(), filename.c_str());
delete is;
- delete currentEmote;
return;
}
- else
- {
- // For now we just use the first image in the animation
- currentEmote->sprite = new ImageSprite(is->get(0));
- }
- mEmotes[id] = currentEmote;
- if (id > mLastEmote)
- mLastEmote = id;
+ // For now we just use the first image in the animation
+ currentEmote.sprite = new ImageSprite(is->get(0));
+
+ mEmotes.push_back(std::move(currentEmote));
}
void EmoteDB::checkStatus()
@@ -112,31 +105,31 @@ void EmoteDB::checkStatus()
void EmoteDB::unload()
{
- Emotes::iterator i;
- for (i = mEmotes.begin(); i != mEmotes.end(); i++)
- {
- delete i->second;
- }
-
+ // todo: don't we need to delete the sprites?
mEmotes.clear();
-
mLoaded = false;
}
-const Emote *EmoteDB::get(int id)
+const Emote &EmoteDB::get(int id)
{
- Emotes::const_iterator i = mEmotes.find(id);
+ auto i = std::find_if(mEmotes.begin(), mEmotes.end(),
+ [id](const Emote &e) { return e.id == id; });
if (i == mEmotes.end())
{
logger->log("EmoteDB: Warning, unknown emote ID %d requested", id);
- return &mUnknown;
+ return mUnknown;
}
- return i->second;
+ return *i;
+}
+
+const Emote &EmoteDB::getByIndex(int index)
+{
+ return mEmotes.at(index);
}
-int EmoteDB::getLast()
+int EmoteDB::getEmoteCount()
{
- return mLastEmote;
+ return mEmotes.size();
}
diff --git a/src/resources/emotedb.h b/src/resources/emotedb.h
index cc3b30f7..1ed86a05 100644
--- a/src/resources/emotedb.h
+++ b/src/resources/emotedb.h
@@ -22,7 +22,6 @@
#ifndef EMOTE_DB_H
#define EMOTE_DB_H
-#include <map>
#include <string>
#include "utils/xml.h"
@@ -31,13 +30,12 @@ class ImageSprite;
struct Emote
{
+ int id;
+ int effectId;
std::string name;
ImageSprite *sprite;
- int effect;
};
-using Emotes = std::map<int, Emote *>;
-
/**
* Emote information database.
*/
@@ -51,11 +49,10 @@ namespace EmoteDB
void unload();
- const Emote *get(int id);
-
- int getLast();
+ const Emote &get(int id);
+ const Emote &getByIndex(int index);
- using EmotesIterator = Emotes::iterator;
+ int getEmoteCount();
}
#endif // EMOTE_DB_H