summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-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.cpp8
-rw-r--r--src/gui/smileyshortcutcontainer.cpp195
-rw-r--r--src/gui/smileyshortcutcontainer.h34
7 files changed, 81 insertions, 405 deletions
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