summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-01-24 22:10:02 +0100
committerYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-01-24 22:10:02 +0100
commitd055bee5e6b45737ab89b3f8c70c6d0db7a22eb3 (patch)
tree081556c8fa27ce16372b1657e469ccd8587dd4e5 /src/gui
parentf663f5bbb75b850ae22f451a22d112b6c62b2ad6 (diff)
downloadmana-client-d055bee5e6b45737ab89b3f8c70c6d0db7a22eb3.tar.gz
mana-client-d055bee5e6b45737ab89b3f8c70c6d0db7a22eb3.tar.bz2
mana-client-d055bee5e6b45737ab89b3f8c70c6d0db7a22eb3.tar.xz
mana-client-d055bee5e6b45737ab89b3f8c70c6d0db7a22eb3.zip
Refactored the item loading in a more extensible and per protocol way.
This will greatly help into upgrading the need of each protocol separately. This is the first step to a new item and equipment system for manaserv. A subclassing of the EquipmentWindow will be done in the next commit, as requested by Thorbjorn. Reviewed-by: Thorbjorn.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/equipmentwindow.cpp103
-rw-r--r--src/gui/equipmentwindow.h2
-rw-r--r--src/gui/itempopup.cpp80
-rw-r--r--src/gui/itempopup.h2
4 files changed, 102 insertions, 85 deletions
diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp
index aeeaf223..d6c029c3 100644
--- a/src/gui/equipmentwindow.cpp
+++ b/src/gui/equipmentwindow.cpp
@@ -68,6 +68,7 @@ static const int boxPosition[][2] = {
EquipmentWindow::EquipmentWindow(Equipment *equipment):
Window(_("Equipment")),
mEquipment(equipment),
+ mEquipBox(0),
mSelected(-1)
{
mItemPopup = new ItemPopup;
@@ -93,15 +94,24 @@ EquipmentWindow::EquipmentWindow(Equipment *equipment):
add(playerBox);
add(mUnequip);
- for (int i = 0; i < Equipment::EQUIP_VECTOREND; i++)
+ // Load equipment boxes.
+ if (Net::getNetworkType() == ServerInfo::TMWATHENA)
{
- mEquipBox[i].posX = boxPosition[i][0] + getPadding();
- mEquipBox[i].posY = boxPosition[i][1] + getTitleBarHeight();
+ mEquipBox = new EquipBox[TmwAthena::EQUIP_VECTOR_END];
+
+ for (int i = 0; i < TmwAthena::EQUIP_VECTOR_END; i++)
+ {
+ mEquipBox[i].posX = boxPosition[i][0] + getPadding();
+ mEquipBox[i].posY = boxPosition[i][1] + getTitleBarHeight();
+ }
}
}
EquipmentWindow::~EquipmentWindow()
{
+ if (Net::getNetworkType() == ServerInfo::TMWATHENA)
+ delete[] mEquipBox;
+
delete mItemPopup;
}
@@ -114,40 +124,43 @@ void EquipmentWindow::draw(gcn::Graphics *graphics)
Window::drawChildren(graphics);
- for (int i = 0; i < Equipment::EQUIP_VECTOREND; i++)
+ if (Net::getNetworkType() == ServerInfo::TMWATHENA)
{
- if (i == mSelected)
+ for (int i = 0; i < TmwAthena::EQUIP_VECTOR_END; i++)
{
- const gcn::Color color = Theme::getThemeColor(Theme::HIGHLIGHT);
+ if (i == mSelected)
+ {
+ const gcn::Color color = Theme::getThemeColor(Theme::HIGHLIGHT);
- // Set color to the highlight color
- g->setColor(gcn::Color(color.r, color.g, color.b, getGuiAlpha()));
- g->fillRectangle(gcn::Rectangle(mEquipBox[i].posX, mEquipBox[i].posY,
- BOX_WIDTH, BOX_HEIGHT));
- }
+ // Set color to the highlight color
+ g->setColor(gcn::Color(color.r, color.g, color.b, getGuiAlpha()));
+ g->fillRectangle(gcn::Rectangle(mEquipBox[i].posX, mEquipBox[i].posY,
+ BOX_WIDTH, BOX_HEIGHT));
+ }
- // Set color black
- g->setColor(gcn::Color(0, 0, 0));
- // Draw box border
- g->drawRectangle(gcn::Rectangle(mEquipBox[i].posX, mEquipBox[i].posY,
- BOX_WIDTH, BOX_HEIGHT));
+ // Set color black
+ g->setColor(gcn::Color(0, 0, 0));
+ // Draw box border
+ g->drawRectangle(gcn::Rectangle(mEquipBox[i].posX, mEquipBox[i].posY,
+ BOX_WIDTH, BOX_HEIGHT));
- Item *item = mEquipment->getEquipment(i);
- if (item)
- {
- // Draw Item.
- Image *image = item->getImage();
- image->setAlpha(1.0f); // Ensure the image is drawn with maximum opacity
- g->drawImage(image,
- mEquipBox[i].posX + 2,
- mEquipBox[i].posY + 2);
- if (i == EQUIP_PROJECTILE_SLOT)
+ Item *item = mEquipment->getEquipment(i);
+ if (item)
{
- g->setColor(Theme::getThemeColor(Theme::TEXT));
- graphics->drawText(toString(item->getQuantity()),
- mEquipBox[i].posX + (BOX_WIDTH / 2),
- mEquipBox[i].posY - getFont()->getHeight(),
- gcn::Graphics::CENTER);
+ // Draw Item.
+ Image *image = item->getImage();
+ image->setAlpha(1.0f); // Ensure the image is drawn with maximum opacity
+ g->drawImage(image,
+ mEquipBox[i].posX + 2,
+ mEquipBox[i].posY + 2);
+ if (i == TmwAthena::EQUIP_PROJECTILE_SLOT)
+ {
+ g->setColor(Theme::getThemeColor(Theme::TEXT));
+ graphics->drawText(toString(item->getQuantity()),
+ mEquipBox[i].posX + (BOX_WIDTH / 2),
+ mEquipBox[i].posY - getFont()->getHeight(),
+ gcn::Graphics::CENTER);
+ }
}
}
}
@@ -165,14 +178,15 @@ void EquipmentWindow::action(const gcn::ActionEvent &event)
Item *EquipmentWindow::getItem(int x, int y) const
{
- for (int i = 0; i < Equipment::EQUIP_VECTOREND; i++)
+ if (Net::getNetworkType() == ServerInfo::TMWATHENA)
{
- gcn::Rectangle tRect(mEquipBox[i].posX, mEquipBox[i].posY,
- BOX_WIDTH, BOX_HEIGHT);
-
- if (tRect.isPointInRect(x, y))
+ for (int i = 0; i < TmwAthena::EQUIP_VECTOR_END; i++)
{
- return mEquipment->getEquipment(i);
+ gcn::Rectangle tRect(mEquipBox[i].posX, mEquipBox[i].posY,
+ BOX_WIDTH, BOX_HEIGHT);
+
+ if (tRect.isPointInRect(x, y))
+ return mEquipment->getEquipment(i);
}
}
return NULL;
@@ -188,14 +202,17 @@ void EquipmentWindow::mousePressed(gcn::MouseEvent& mouseEvent)
if (mouseEvent.getButton() == gcn::MouseEvent::LEFT)
{
// Checks if any of the presses were in the equip boxes.
- for (int i = 0; i < Equipment::EQUIP_VECTOREND; i++)
+ if (Net::getNetworkType() == ServerInfo::TMWATHENA)
{
- Item *item = mEquipment->getEquipment(i);
- gcn::Rectangle tRect(mEquipBox[i].posX, mEquipBox[i].posY,
- BOX_WIDTH, BOX_HEIGHT);
+ for (int i = 0; i < TmwAthena::EQUIP_VECTOR_END; i++)
+ {
+ Item *item = mEquipment->getEquipment(i);
+ gcn::Rectangle tRect(mEquipBox[i].posX, mEquipBox[i].posY,
+ BOX_WIDTH, BOX_HEIGHT);
- if (tRect.isPointInRect(x, y) && item)
- setSelected(i);
+ if (tRect.isPointInRect(x, y) && item)
+ setSelected(i);
+ }
}
}
else if (mouseEvent.getButton() == gcn::MouseEvent::RIGHT)
diff --git a/src/gui/equipmentwindow.h b/src/gui/equipmentwindow.h
index dcb3523d..a76fa689 100644
--- a/src/gui/equipmentwindow.h
+++ b/src/gui/equipmentwindow.h
@@ -78,7 +78,7 @@ class EquipmentWindow : public Window, public gcn::ActionListener
int posY;
};
- EquipBox mEquipBox[Equipment::EQUIP_VECTOREND]; /**< Equipment Boxes. */
+ EquipBox *mEquipBox; /**< Equipment Boxes. */
ItemPopup *mItemPopup;
gcn::Button *mUnequip;
diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp
index 9b2df34d..60943756 100644
--- a/src/gui/itempopup.cpp
+++ b/src/gui/itempopup.cpp
@@ -34,6 +34,8 @@
#include "utils/gettext.h"
#include "utils/stringutils.h"
+#include "net/net.h"
+
#include "resources/image.h"
#include "resources/resourcemanager.h"
#include "resources/theme.h"
@@ -42,6 +44,43 @@
#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)
@@ -116,15 +155,13 @@ 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(Theme::UNKNOWN_ITEM); // TODO
+ mItemName->setForegroundColor(getColorFromItemType(mItemType));
mItemName->setPosition(getPadding() + space, getPadding());
-#define ITEMPOPUP_WRAP_WIDTH 196
-
mItemDesc->setTextWrapped(item.getDescription(), ITEMPOPUP_WRAP_WIDTH);
{
const std::vector<std::string> &effect = item.getEffect();
@@ -183,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);
diff --git a/src/gui/itempopup.h b/src/gui/itempopup.h
index a3976a11..f054ddf5 100644
--- a/src/gui/itempopup.h
+++ b/src/gui/itempopup.h
@@ -62,8 +62,6 @@ class ItemPopup : public Popup
TextBox *mItemWeight;
ItemType mItemType;
Icon *mIcon;
-
- static gcn::Color getColor(ItemType type);
};
#endif // ITEMPOPUP_H