summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/Makefile.am2
-rw-r--r--src/gui/inventorywindow.cpp1
-rw-r--r--src/gui/itemcontainer.cpp41
-rw-r--r--src/gui/itemcontainer.h16
-rw-r--r--src/gui/itempopup.cpp119
-rw-r--r--src/gui/itempopup.h48
7 files changed, 228 insertions, 1 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index dbdd64b6..43e5cb95 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -101,6 +101,8 @@ SET(SRCS
gui/inventorywindow.h
gui/itemcontainer.cpp
gui/itemcontainer.h
+ gui/itempopup.cpp
+ gui/itempopup.h
gui/itemshortcutcontainer.cpp
gui/itemshortcutcontainer.h
gui/itemshortcutwindow.cpp
diff --git a/src/Makefile.am b/src/Makefile.am
index 5c519832..9a3fa3b9 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -59,6 +59,8 @@ aethyra_SOURCES = gui/widgets/dropdown.cpp \
gui/inventorywindow.h \
gui/itemcontainer.cpp \
gui/itemcontainer.h \
+ gui/itempopup.cpp \
+ gui/itempopup.h \
gui/itemshortcutcontainer.cpp \
gui/itemshortcutcontainer.h \
gui/item_amount.cpp \
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp
index 8c5edec4..f52745bf 100644
--- a/src/gui/inventorywindow.cpp
+++ b/src/gui/inventorywindow.cpp
@@ -28,6 +28,7 @@
#include "inventorywindow.h"
#include "item_amount.h"
#include "itemcontainer.h"
+#include "itempopup.h"
#include "scrollarea.h"
#include "viewport.h"
diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp
index 26ca3379..2cc0bef3 100644
--- a/src/gui/itemcontainer.cpp
+++ b/src/gui/itemcontainer.cpp
@@ -48,6 +48,8 @@ ItemContainer::ItemContainer(Inventory *inventory, int offset):
mLastSelectedItemId(NO_ITEM),
mOffset(offset)
{
+ mItemPopup = new ItemPopup();
+
ResourceManager *resman = ResourceManager::getInstance();
mSelImg = resman->getImage("graphics/gui/selection.png");
@@ -222,7 +224,7 @@ void ItemContainer::distributeValueChangedEvent()
void ItemContainer::mousePressed(gcn::MouseEvent &event)
{
- int button = event.getButton();
+ const int button = event.getButton();
if (button == gcn::MouseEvent::LEFT || button == gcn::MouseEvent::RIGHT)
{
@@ -240,3 +242,40 @@ void ItemContainer::mousePressed(gcn::MouseEvent &event)
itemShortcut->setItemSelected(item->getId());
}
}
+
+// Show ItemTooltip
+void ItemContainer::mouseMoved(gcn::MouseEvent &event)
+{
+ Item *item = mInventory->getItem( getSlotIndex(event.getX(), event.getY() ) );
+
+ if( item )
+ {
+ mItemPopup->setPosition(getParent()->getParent()->getX() +
+ getParent()->getParent()->getWidth(),
+ getParent()->getParent()->getY());
+
+ mItemPopup->setItem(item->getInfo());
+
+ mItemPopup->setVisible(true);
+ }
+ else
+ {
+ mItemPopup->setVisible(false);
+ }
+}
+
+// Hide ItemTooltip
+void ItemContainer::mouseExited(gcn::MouseEvent &event)
+{
+ mItemPopup->setVisible(false);
+}
+
+int ItemContainer::getSlotIndex(const int posX, const int posY) const
+{
+ int columns = getWidth() / gridWidth;
+ int index = posX / gridWidth + ((posY / gridHeight) * columns) + mOffset;
+
+ return (index);
+}
+
+
diff --git a/src/gui/itemcontainer.h b/src/gui/itemcontainer.h
index 8927b001..223a3677 100644
--- a/src/gui/itemcontainer.h
+++ b/src/gui/itemcontainer.h
@@ -28,6 +28,8 @@
#include <guichan/widget.hpp>
#include <guichan/widgetlistener.hpp>
+#include "itempopup.h"
+
#include "../guichanfwd.h"
class Image;
@@ -107,6 +109,9 @@ class ItemContainer : public gcn::Widget,
}
private:
+ void mouseExited(gcn::MouseEvent &event);
+ void mouseMoved(gcn::MouseEvent &event);
+
/**
* Sets the currently selected item. Invalid (e.g., negative) indices set `no item'.
@@ -128,6 +133,15 @@ class ItemContainer : public gcn::Widget,
*/
void distributeValueChangedEvent(void);
+ /**
+ * Gets the slot index based on the cursor position.
+ *
+ * @param posX The X Coordinate position.
+ * @param posY The Y Coordinate position.
+ * @return The slot index on success, -1 on failure.
+ */
+ int getSlotIndex(const int posX, const int posY) const;
+
Inventory *mInventory;
Image *mSelImg;
int mSelectedItemIndex;
@@ -136,6 +150,8 @@ class ItemContainer : public gcn::Widget,
int mMaxItems;
int mOffset;
+ ItemPopup *mItemPopup;
+
std::list<gcn::SelectionListener*> mListeners;
static const int gridWidth;
diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp
new file mode 100644
index 00000000..1402a148
--- /dev/null
+++ b/src/gui/itempopup.cpp
@@ -0,0 +1,119 @@
+/*
+ * The Mana World
+ * Copyright (C) 2008 The Legend of Mazzeroth Development Team
+ * Copyright (C) 2008 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 "itempopup.h"
+#include <guichan/widgets/label.hpp>
+#include "widgets/layout.h"
+
+#include "gui.h"
+
+#include "../resources/image.h"
+#include "../resources/resourcemanager.h"
+#include "../resources/iteminfo.h"
+#include "../utils/gettext.h"
+#include "../utils/strprintf.h"
+
+
+ItemPopup::ItemPopup()
+{
+ setResizable(false);
+ setCaption("");
+ setTitleBarHeight(0);
+ loadSkin("graphics/gui/gui.xml");
+
+ // Item Name
+ mItemName = new gcn::Label("Label");
+ mItemName->setFont(gui->getFont());
+ mItemName->setPosition(2, 2);
+ mItemName->setWidth(getWidth() - 4);
+
+ // Item Description
+ mItemDesc = new TextBox();
+ mItemDesc->setEditable(false);
+ mItemDesc->setMinWidth(170);
+ mItemDescScroll = new ScrollArea(mItemDesc);
+
+ mItemDescScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
+ mItemDescScroll->setVerticalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
+ mItemDescScroll->setDimension(gcn::Rectangle(0, 0, 196, 14));
+ mItemDescScroll->setOpaque(false);
+ mItemDescScroll->setPosition(2, 15);
+
+ // Item Effect
+ mItemEffect = new TextBox();
+ mItemEffect->setEditable(false);
+ mItemEffect->setMinWidth(170);
+ mItemEffectScroll = new ScrollArea(mItemEffect);
+
+ mItemEffectScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
+ mItemEffectScroll->setVerticalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
+ mItemEffectScroll->setDimension(gcn::Rectangle(0, 0, 196, 14));
+ mItemEffectScroll->setOpaque(false);
+ mItemEffectScroll->setPosition(2, 35);
+
+ add(mItemName);
+ add(mItemDescScroll);
+ add(mItemEffectScroll);
+
+ setLocationRelativeTo(getParent());
+
+ // LEEOR / TODO: This causes an exception error.
+ //moveToBottom(getParent());
+
+ mItemDesc->setTextWrapped( "" );
+ mItemEffect->setTextWrapped( "" );
+}
+
+void ItemPopup::setItem(const ItemInfo &item)
+{
+ const gcn::Rectangle &area = getChildrenArea();
+ const int width = area.width;
+
+ mItemDesc->setMinWidth(width - 30);
+ mItemEffect->setMinWidth(width - 30);
+
+ mItemName->setCaption(item.getName());
+ mItemDesc->setTextWrapped(item.getDescription());
+ mItemEffect->setTextWrapped(item.getEffect());
+
+ int numRowsDesc = mItemDesc->getNumberOfRows();
+ int numRowsEffect = mItemEffect->getNumberOfRows();
+
+ if(item.getEffect() == "")
+ {
+ setContentSize(200, (numRowsDesc * 14) + 30);
+ } else {
+ setContentSize(200, (numRowsDesc * 14) + (numRowsEffect * 14) + 30);
+ }
+
+ mItemDescScroll->setDimension(gcn::Rectangle(2, 0, 196, numRowsDesc * 14));
+
+ mItemEffectScroll->setDimension(gcn::Rectangle(2, 0, 196, numRowsEffect * 14));
+
+ mItemDescScroll->setPosition(2, 20);
+ mItemEffectScroll->setPosition(2, (numRowsDesc * 15) + 25);
+}
+
+unsigned int ItemPopup::getNumRows()
+{
+ return mItemDesc->getNumberOfRows(), mItemEffect->getNumberOfRows();
+}
diff --git a/src/gui/itempopup.h b/src/gui/itempopup.h
new file mode 100644
index 00000000..8da0b32a
--- /dev/null
+++ b/src/gui/itempopup.h
@@ -0,0 +1,48 @@
+/*
+ * The Mana World
+ * Copyright (C) 2008 The Legend of Mazzeroth Development Team
+ * Copyright (C) 2008 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
+ */
+
+#ifndef _TMW_ITEMPOPUP_H__
+#define _TMW_ITEMPOPUP_H__
+
+#include "textbox.h"
+#include "scrollarea.h"
+#include "window.h"
+
+#include "../item.h"
+
+class ItemPopup : public Window
+{
+ public:
+ ItemPopup();
+
+ void setItem(const ItemInfo &item);
+ unsigned int getNumRows();
+
+ private:
+ gcn::Label *mItemName;
+ TextBox *mItemDesc;
+ TextBox *mItemEffect;
+ ScrollArea *mItemDescScroll;
+ ScrollArea *mItemEffectScroll;
+};
+
+#endif // _TMW_ITEMPOPUP_H__