summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gui/itemcontainer.cpp9
-rw-r--r--src/gui/itemlinkhandler.cpp9
-rw-r--r--src/gui/itempopup.cpp17
-rw-r--r--src/gui/itempopup.h29
-rw-r--r--src/gui/itemshortcutcontainer.cpp6
-rw-r--r--src/gui/speechbubble.cpp1
-rw-r--r--src/gui/speechbubble.h18
7 files changed, 80 insertions, 9 deletions
diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp
index 54f1f647..8139e85e 100644
--- a/src/gui/itemcontainer.cpp
+++ b/src/gui/itemcontainer.cpp
@@ -25,6 +25,7 @@
#include "itemcontainer.h"
#include "itempopup.h"
+#include "palette.h"
#include "viewport.h"
#include "../graphics.h"
@@ -51,6 +52,7 @@ ItemContainer::ItemContainer(Inventory *inventory, int offset):
mOffset(offset)
{
mItemPopup = new ItemPopup();
+ mItemPopup->setOpaque(false);
ResourceManager *resman = ResourceManager::getInstance();
@@ -123,7 +125,7 @@ void ItemContainer::draw(gcn::Graphics *graphics)
// Draw item caption
graphics->setFont(getFont());
- graphics->setColor(0x000000);
+ graphics->setColor(guiPalette->getColor(Palette::TEXT));
graphics->drawText(
(item->isEquipped() ? "Eq." : toString(item->getQuantity())),
itemX + gridWidth / 2, itemY + gridHeight - 11,
@@ -255,8 +257,9 @@ void ItemContainer::mouseMoved(gcn::MouseEvent &event)
if (item)
{
- mItemPopup->setItem(item->getInfo());
- mItemPopup->setOpaque(false);
+ if (item->getInfo().getName() != mItemPopup->getItemName())
+ mItemPopup->setItem(item->getInfo());
+ mItemPopup->updateColors();
mItemPopup->view(viewport->getMouseX(), viewport->getMouseY());
}
else
diff --git a/src/gui/itemlinkhandler.cpp b/src/gui/itemlinkhandler.cpp
index 06263ce2..e9993c2d 100644
--- a/src/gui/itemlinkhandler.cpp
+++ b/src/gui/itemlinkhandler.cpp
@@ -33,6 +33,7 @@
ItemLinkHandler::ItemLinkHandler()
{
mItemPopup = new ItemPopup;
+ mItemPopup->setOpaque(false);
}
ItemLinkHandler::~ItemLinkHandler()
@@ -50,11 +51,17 @@ void ItemLinkHandler::handleLink(const std::string &link)
{
const ItemInfo &iteminfo = ItemDB::get(id);
- mItemPopup->setItem(iteminfo);
+ if (iteminfo.getName() != mItemPopup->getItemName())
+ mItemPopup->setItem(iteminfo);
if (mItemPopup->isVisible())
+ {
mItemPopup->setVisible(false);
+ }
else
+ {
+ mItemPopup->updateColors();
mItemPopup->view(viewport->getMouseX(), viewport->getMouseY());
+ }
}
}
diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp
index b3002290..c76c3750 100644
--- a/src/gui/itempopup.cpp
+++ b/src/gui/itempopup.cpp
@@ -41,8 +41,10 @@
ItemPopup::ItemPopup():
Popup()
{
+ mItemType = "";
+
// Item Name
- mItemName = new gcn::Label("Label");
+ mItemName = new gcn::Label("");
mItemName->setFont(boldFont);
mItemName->setPosition(2, 2);
@@ -104,12 +106,12 @@ void ItemPopup::setItem(const ItemInfo &item)
return;
mItemName->setCaption(item.getName());
- mItemName->setForegroundColor(getColor(item.getType()));
mItemName->setWidth(boldFont->getWidth(item.getName()));
mItemDesc->setTextWrapped(item.getDescription(), 196);
mItemEffect->setTextWrapped(item.getEffect(), 196);
mItemWeight->setTextWrapped(_("Weight: ") + toString(item.getWeight()) +
_(" grams"), 196);
+ mItemType = item.getType();
int minWidth = mItemName->getWidth();
@@ -162,6 +164,12 @@ void ItemPopup::setItem(const ItemInfo &item)
(2 * getFont()->getHeight()));
}
+void ItemPopup::updateColors()
+{
+ mItemName->setForegroundColor(getColor(mItemType));
+ graphics->setColor(guiPalette->getColor(Palette::TEXT));
+}
+
gcn::Color ItemPopup::getColor(const std::string& type)
{
gcn::Color color;
@@ -196,6 +204,11 @@ gcn::Color ItemPopup::getColor(const std::string& type)
return color;
}
+std::string ItemPopup::getItemName()
+{
+ return mItemName->getCaption();
+}
+
unsigned int ItemPopup::getNumRows()
{
return mItemDesc->getNumberOfRows() + mItemEffect->getNumberOfRows() +
diff --git a/src/gui/itempopup.h b/src/gui/itempopup.h
index 97da4cbb..29fd127a 100644
--- a/src/gui/itempopup.h
+++ b/src/gui/itempopup.h
@@ -33,11 +33,39 @@ class TextBox;
class ItemPopup : public Popup
{
public:
+ /**
+ * Constructor. Initializes the item popup.
+ */
ItemPopup();
+
+ /**
+ * Destructor. Cleans up the item popup on deletion.
+ */
~ItemPopup();
+ /**
+ * Sets the info to be displayed given a particular item.
+ */
void setItem(const ItemInfo &item);
+
+ /**
+ * Gets the number of rows that the item popup currently has.
+ */
unsigned int getNumRows();
+
+ /**
+ * Gets the name of the currently stored item in this popup.
+ */
+ std::string getItemName();
+
+ /**
+ * Updates the colors used within the item popup.
+ */
+ void updateColors();
+
+ /**
+ * Sets the location to display the item popup.
+ */
void view(int x, int y);
private:
@@ -45,6 +73,7 @@ class ItemPopup : public Popup
TextBox *mItemDesc;
TextBox *mItemEffect;
TextBox *mItemWeight;
+ std::string mItemType;
ScrollArea *mItemDescScroll;
ScrollArea *mItemEffectScroll;
ScrollArea *mItemWeightScroll;
diff --git a/src/gui/itemshortcutcontainer.cpp b/src/gui/itemshortcutcontainer.cpp
index c1baca76..cbbbaf60 100644
--- a/src/gui/itemshortcutcontainer.cpp
+++ b/src/gui/itemshortcutcontainer.cpp
@@ -47,6 +47,7 @@ ItemShortcutContainer::ItemShortcutContainer():
addWidgetListener(this);
mItemPopup = new ItemPopup();
+ mItemPopup->setOpaque(false);
ResourceManager *resman = ResourceManager::getInstance();
@@ -233,8 +234,9 @@ void ItemShortcutContainer::mouseMoved(gcn::MouseEvent &event)
if (item)
{
- mItemPopup->setItem(item->getInfo());
- mItemPopup->setOpaque(false);
+ if (item->getInfo().getName() != mItemPopup->getItemName())
+ mItemPopup->setItem(item->getInfo());
+ mItemPopup->updateColors();
mItemPopup->view(viewport->getMouseX(), viewport->getMouseY());
}
else
diff --git a/src/gui/speechbubble.cpp b/src/gui/speechbubble.cpp
index 944bae42..811fddfa 100644
--- a/src/gui/speechbubble.cpp
+++ b/src/gui/speechbubble.cpp
@@ -25,7 +25,6 @@
#include <guichan/widgets/label.hpp>
#include "gui.h"
-#include "palette.h"
#include "scrollarea.h"
#include "speechbubble.h"
#include "textbox.h"
diff --git a/src/gui/speechbubble.h b/src/gui/speechbubble.h
index d356dac1..9eb400fb 100644
--- a/src/gui/speechbubble.h
+++ b/src/gui/speechbubble.h
@@ -32,13 +32,31 @@ class TextBox;
class SpeechBubble : public Popup
{
public:
+ /**
+ * Constructor. Initializes the speech bubble.
+ */
SpeechBubble();
+ /**
+ * Sets the name displayed for the speech bubble, and in what color.
+ */
void setCaption(const std::string &name,
const gcn::Color *color =
&guiPalette->getColor(Palette::TEXT));
+
+ /**
+ * Sets the text to be displayed.
+ */
void setText(std::string text, bool showName = true);
+
+ /**
+ * Sets the location in which the speech bubble will be displayed.
+ */
void setLocation(int x, int y);
+
+ /**
+ * Gets the number of rows the speech bubble has.
+ */
unsigned int getNumRows();
private: