summaryrefslogtreecommitdiff
path: root/src/gui/itempopup.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/itempopup.cpp')
-rw-r--r--src/gui/itempopup.cpp101
1 files changed, 57 insertions, 44 deletions
diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp
index b71ca529..60943756 100644
--- a/src/gui/itempopup.cpp
+++ b/src/gui/itempopup.cpp
@@ -26,27 +26,67 @@
#include "units.h"
#include "gui/gui.h"
-#include "gui/theme.h"
#include "gui/widgets/icon.h"
+#include "gui/widgets/label.h"
#include "gui/widgets/textbox.h"
#include "utils/gettext.h"
#include "utils/stringutils.h"
+#include "net/net.h"
+
#include "resources/image.h"
#include "resources/resourcemanager.h"
+#include "resources/theme.h"
#include <guichan/font.hpp>
#include <guichan/widgets/label.hpp>
+#define ITEMPOPUP_WRAP_WIDTH 196
+
+static gcn::Color getColorFromItemType(ItemType type)
+{
+ switch (type)
+ {
+ case ITEM_UNUSABLE:
+ return Theme::getThemeColor(Theme::GENERIC);
+ case ITEM_USABLE:
+ return Theme::getThemeColor(Theme::USABLE);
+ case ITEM_EQUIPMENT_ONE_HAND_WEAPON:
+ return Theme::getThemeColor(Theme::ONEHAND);
+ case ITEM_EQUIPMENT_TWO_HANDS_WEAPON:
+ return Theme::getThemeColor(Theme::TWOHAND);
+ case ITEM_EQUIPMENT_TORSO:
+ return Theme::getThemeColor(Theme::TORSO);
+ case ITEM_EQUIPMENT_ARMS:
+ return Theme::getThemeColor(Theme::ARMS);
+ case ITEM_EQUIPMENT_HEAD:
+ return Theme::getThemeColor(Theme::HEAD);
+ case ITEM_EQUIPMENT_LEGS:
+ return Theme::getThemeColor(Theme::LEGS);
+ case ITEM_EQUIPMENT_SHIELD:
+ return Theme::getThemeColor(Theme::SHIELD);
+ case ITEM_EQUIPMENT_RING:
+ return Theme::getThemeColor(Theme::RING);
+ case ITEM_EQUIPMENT_NECKLACE:
+ return Theme::getThemeColor(Theme::NECKLACE);
+ case ITEM_EQUIPMENT_FEET:
+ return Theme::getThemeColor(Theme::FEET);
+ case ITEM_EQUIPMENT_AMMO:
+ return Theme::getThemeColor(Theme::AMMO);
+ default:
+ return Theme::getThemeColor(Theme::UNKNOWN_ITEM);
+ }
+}
+
ItemPopup::ItemPopup():
Popup("ItemPopup"),
mIcon(0)
{
// Item Name
- mItemName = new gcn::Label;
+ mItemName = new Label;
mItemName->setFont(boldFont);
mItemName->setPosition(getPadding(), getPadding());
@@ -98,8 +138,9 @@ void ItemPopup::setItem(const ItemInfo &item, bool showImage)
{
ResourceManager *resman = ResourceManager::getInstance();
Image *image = resman->getImage(
- paths.getValue("itemIcons", "graphics/items/")
- + item.getImageName());
+ paths.getStringValue("itemIcons")
+ + item.getDisplay().image);
+
mIcon->setImage(image);
if (image)
{
@@ -114,18 +155,25 @@ void ItemPopup::setItem(const ItemInfo &item, bool showImage)
mIcon->setImage(0);
}
- mItemType = item.getType();
+ mItemType = item.getItemType();
mItemName->setCaption(item.getName());
mItemName->adjustSize();
- mItemName->setForegroundColor(getColor(mItemType));
+ mItemName->setForegroundColor(getColorFromItemType(mItemType));
mItemName->setPosition(getPadding() + space, getPadding());
- mItemDesc->setTextWrapped(item.getDescription(), 196);
- mItemEffect->setTextWrapped(item.getEffect(), 196);
+ mItemDesc->setTextWrapped(item.getDescription(), ITEMPOPUP_WRAP_WIDTH);
+ {
+ const std::vector<std::string> &effect = item.getEffect();
+ std::string temp = "";
+ for (std::vector<std::string>::const_iterator it = effect.begin(),
+ it_end = effect.end(); it != it_end; ++it)
+ temp += temp.empty() ? *it : "\n" + *it;
+ mItemEffect->setTextWrapped(temp, ITEMPOPUP_WRAP_WIDTH);
+ }
mItemWeight->setTextWrapped(strprintf(_("Weight: %s"),
Units::formatWeight(item.getWeight()).c_str()),
- 196);
+ ITEMPOPUP_WRAP_WIDTH);
int minWidth = mItemName->getWidth() + space;
@@ -172,41 +220,6 @@ void ItemPopup::setItem(const ItemInfo &item, bool showImage)
(numRowsDesc + 1) * fontHeight);
}
-gcn::Color ItemPopup::getColor(ItemType type)
-{
- switch (type)
- {
- case ITEM_UNUSABLE:
- return Theme::getThemeColor(Theme::GENERIC);
- case ITEM_USABLE:
- return Theme::getThemeColor(Theme::USABLE);
- case ITEM_EQUIPMENT_ONE_HAND_WEAPON:
- return Theme::getThemeColor(Theme::ONEHAND);
- case ITEM_EQUIPMENT_TWO_HANDS_WEAPON:
- return Theme::getThemeColor(Theme::TWOHAND);
- case ITEM_EQUIPMENT_TORSO:
- return Theme::getThemeColor(Theme::TORSO);
- case ITEM_EQUIPMENT_ARMS:
- return Theme::getThemeColor(Theme::ARMS);
- case ITEM_EQUIPMENT_HEAD:
- return Theme::getThemeColor(Theme::HEAD);
- case ITEM_EQUIPMENT_LEGS:
- return Theme::getThemeColor(Theme::LEGS);
- case ITEM_EQUIPMENT_SHIELD:
- return Theme::getThemeColor(Theme::SHIELD);
- case ITEM_EQUIPMENT_RING:
- return Theme::getThemeColor(Theme::RING);
- case ITEM_EQUIPMENT_NECKLACE:
- return Theme::getThemeColor(Theme::NECKLACE);
- case ITEM_EQUIPMENT_FEET:
- return Theme::getThemeColor(Theme::FEET);
- case ITEM_EQUIPMENT_AMMO:
- return Theme::getThemeColor(Theme::AMMO);
- default:
- return Theme::getThemeColor(Theme::UNKNOWN_ITEM);
- }
-}
-
void ItemPopup::mouseMoved(gcn::MouseEvent &event)
{
Popup::mouseMoved(event);