summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Makefile.am2
-rw-r--r--src/game.cpp10
-rw-r--r--src/gui/itemshortcutcontainer.cpp36
-rw-r--r--src/gui/itemshortcutcontainer.h31
-rw-r--r--src/gui/shortcutcontainer.cpp165
-rw-r--r--src/gui/shortcutcontainer.h17
-rw-r--r--src/gui/smileycontainer.cpp9
-rw-r--r--src/gui/smileyshortcutcontainer.cpp195
-rw-r--r--src/gui/smileyshortcutcontainer.h34
-rw-r--r--src/main.cpp6
-rw-r--r--src/smileyshortcut.h2
11 files changed, 94 insertions, 413 deletions
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
@@ -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 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 <mMaxSmiley)
+ {
+ setSelectedItemIndex(index);
+ smileyShortcut->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*>(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 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