summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-08-19 02:41:30 +0200
committerYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-08-19 02:41:30 +0200
commit011135415f7f9c5cfeb220540621dfd1c46e6db9 (patch)
tree55dd2943dca362045e7ed96ef72924728343351e /src/gui
parentc392eab58774154177a0e790a414c2c52c8ce83b (diff)
parent27114fa2694318f2a1c56cb828a3b79731efcb74 (diff)
downloadmana-011135415f7f9c5cfeb220540621dfd1c46e6db9.tar.gz
mana-011135415f7f9c5cfeb220540621dfd1c46e6db9.tar.bz2
mana-011135415f7f9c5cfeb220540621dfd1c46e6db9.tar.xz
mana-011135415f7f9c5cfeb220540621dfd1c46e6db9.zip
Merge git://gitorious.org/~bertram/mana/mana-equipment-fix into equipment-fix
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/equipmentwindow.cpp229
-rw-r--r--src/gui/equipmentwindow.h23
-rw-r--r--src/gui/itempopup.cpp35
-rw-r--r--src/gui/itempopup.h11
4 files changed, 170 insertions, 128 deletions
diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp
index c17b5e04..212dcd2b 100644
--- a/src/gui/equipmentwindow.cpp
+++ b/src/gui/equipmentwindow.cpp
@@ -50,11 +50,27 @@
static const int BOX_WIDTH = 36;
static const int BOX_HEIGHT = 36;
+// Positions of the boxes, 2nd dimension is X and Y respectively.
+const int boxPosition[][2] = {
+ { 90, 40 }, // EQUIP_TORSO_SLOT
+ { 8, 78 }, // EQUIP_GLOVES_SLOT
+ { 70, 0 }, // EQUIP_HEAD_SLOT
+ { 50, 208 }, // EQUIP_LEGS_SLOT
+ { 90, 208 }, // EQUIP_FEET_SLOT
+ { 8, 168 }, // EQUIP_RING1_SLOT
+ { 129, 168 }, // EQUIP_RING2_SLOT
+ { 50, 40 }, // EQUIP_NECK_SLOT
+ { 8, 123 }, // EQUIP_FIGHT1_SLOT
+ { 129, 123 }, // EQUIP_FIGHT2_SLOT
+ { 129, 78 } // EQUIP_PROJECTILE_SLOT
+};
+
EquipmentWindow::EquipmentWindow(Equipment *equipment):
Window(_("Equipment")),
mEquipBox(0),
mSelected(-1),
- mEquipment(equipment)
+ mEquipment(equipment),
+ mBoxesNumber(0)
{
mItemPopup = new ItemPopup;
setupWindow->registerWindowForReset(this);
@@ -80,9 +96,27 @@ EquipmentWindow::EquipmentWindow(Equipment *equipment):
add(mUnequip);
}
+void EquipmentWindow::loadEquipBoxes()
+{
+ if (mEquipBox)
+ delete[] mEquipBox;
+
+ // Load equipment boxes.
+ mBoxesNumber = mEquipment->getSlotNumber();
+ mEquipBox = new EquipBox[mBoxesNumber];
+
+ for (int i = 0; i < mBoxesNumber; i++)
+ {
+ mEquipBox[i].posX = boxPosition[i][0] + getPadding();
+ mEquipBox[i].posY = boxPosition[i][1] + getTitleBarHeight();
+ }
+}
+
EquipmentWindow::~EquipmentWindow()
{
delete mItemPopup;
+ if (mEquipBox)
+ delete[] mEquipBox;
}
void EquipmentWindow::draw(gcn::Graphics *graphics)
@@ -91,32 +125,84 @@ void EquipmentWindow::draw(gcn::Graphics *graphics)
Window::draw(graphics);
Window::drawChildren(graphics);
+
+ // Draw equipment boxes
+ Graphics *g = static_cast<Graphics*>(graphics);
+
+ for (int i = 0; i < mBoxesNumber; i++)
+ {
+ 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 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();
+ // Ensure the image is drawn with maximum opacity
+ image->setAlpha(1.0f);
+ 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);
+ }
+ }
+ }
}
void EquipmentWindow::action(const gcn::ActionEvent &event)
{
if (event.getId() == "unequip" && mSelected > -1)
{
- Item *item = mEquipment->getEquipment(mSelected);
- item->doEvent(Event::DoUnequip);
+ mEquipment->triggerUnequip(mSelected);
setSelected(-1);
}
}
Item *EquipmentWindow::getItem(int x, int y) const
{
- if (Net::getNetworkType() == ServerInfo::TMWATHENA)
+ for (int i = 0; i < mBoxesNumber; ++i)
{
- for (int i = 0; i < TmwAthena::EQUIP_VECTOR_END; i++)
- {
- gcn::Rectangle tRect(mEquipBox[i].posX, mEquipBox[i].posY,
- BOX_WIDTH, BOX_HEIGHT);
+ gcn::Rectangle tRect(mEquipBox[i].posX, mEquipBox[i].posY,
+ BOX_WIDTH, BOX_HEIGHT);
- if (tRect.isPointInRect(x, y))
- return mEquipment->getEquipment(i);
- }
+ if (tRect.isPointInRect(x, y))
+ return mEquipment->getEquipment(i);
}
- return NULL;
+ return 0;
+}
+
+const std::string EquipmentWindow::getSlotName(int x, int y) const
+{
+ for (int i = 0; i < mBoxesNumber; ++i)
+ {
+ gcn::Rectangle tRect(mEquipBox[i].posX, mEquipBox[i].posY,
+ BOX_WIDTH, BOX_HEIGHT);
+
+ if (tRect.isPointInRect(x, y))
+ return mEquipment->getSlotName(i);
+ }
+ return std::string();
}
void EquipmentWindow::mousePressed(gcn::MouseEvent& mouseEvent)
@@ -129,17 +215,14 @@ void EquipmentWindow::mousePressed(gcn::MouseEvent& mouseEvent)
if (mouseEvent.getButton() == gcn::MouseEvent::LEFT)
{
// Checks if any of the presses were in the equip boxes.
- if (Net::getNetworkType() == ServerInfo::TMWATHENA)
+ for (int i = 0; i < mBoxesNumber; ++i)
{
- 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);
+ 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)
@@ -156,20 +239,28 @@ void EquipmentWindow::mousePressed(gcn::MouseEvent& mouseEvent)
}
}
-// Show ItemTooltip
void EquipmentWindow::mouseMoved(gcn::MouseEvent &event)
{
const int x = event.getX();
const int y = event.getY();
- Item *item = getItem(x, y);
+ int mouseX, mouseY;
+ SDL_GetMouseState(&mouseX, &mouseY);
- if (item)
+ // Show ItemTooltip
+ std::string slotName = getSlotName(x, y);
+ if (!slotName.empty())
{
- int mouseX, mouseY;
- SDL_GetMouseState(&mouseX, &mouseY);
+ mItemPopup->setEquipmentText(slotName);
+
+ Item *item = getItem(x, y);
+ if (item)
+ {
+ mItemPopup->setItem(item->getInfo());
+ }
+ else
+ mItemPopup->setNoItem();
- mItemPopup->setItem(item->getInfo());
mItemPopup->position(x + getX(), y + getY());
}
else
@@ -178,7 +269,6 @@ void EquipmentWindow::mouseMoved(gcn::MouseEvent &event)
}
}
-// Hide ItemTooltip
void EquipmentWindow::mouseExited(gcn::MouseEvent &event)
{
mItemPopup->setVisible(false);
@@ -189,86 +279,3 @@ void EquipmentWindow::setSelected(int index)
mSelected = index;
mUnequip->setEnabled(mSelected != -1);
}
-
-namespace TmwAthena {
-
-TaEquipmentWindow::TaEquipmentWindow(Equipment *equipment):
- EquipmentWindow(equipment)
-{
- // Positions of the boxes, 2nd dimension is X and Y respectively.
- const int boxPosition[][2] = {
- { 90, 40 }, // EQUIP_TORSO_SLOT
- { 8, 78 }, // EQUIP_GLOVES_SLOT
- { 70, 0 }, // EQUIP_HEAD_SLOT
- { 50, 208 }, // EQUIP_LEGS_SLOT
- { 90, 208 }, // EQUIP_FEET_SLOT
- { 8, 168 }, // EQUIP_RING1_SLOT
- { 129, 168 }, // EQUIP_RING2_SLOT
- { 50, 40 }, // EQUIP_NECK_SLOT
- { 8, 123 }, // EQUIP_FIGHT1_SLOT
- { 129, 123 }, // EQUIP_FIGHT2_SLOT
- { 129, 78 } // EQUIP_PROJECTILE_SLOT
- };
-
- // Load equipment boxes.
- 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();
- }
-}
-
-TaEquipmentWindow::~TaEquipmentWindow()
-{
- delete[] mEquipBox;
-}
-
-void TaEquipmentWindow::draw(gcn::Graphics *graphics)
-{
- EquipmentWindow::draw(graphics);
-
- // Draw equipment boxes
- Graphics *g = static_cast<Graphics*>(graphics);
-
- for (int i = 0; i < TmwAthena::EQUIP_VECTOR_END; i++)
- {
- 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 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 == 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);
- }
- }
- }
-}
-
-} // namespace TmwAthena
diff --git a/src/gui/equipmentwindow.h b/src/gui/equipmentwindow.h
index 5ba15ae3..b8e63efc 100644
--- a/src/gui/equipmentwindow.h
+++ b/src/gui/equipmentwindow.h
@@ -53,6 +53,11 @@ class EquipmentWindow : public Window, public gcn::ActionListener
void mousePressed(gcn::MouseEvent& mouseEvent);
+ /**
+ * Loads the correct amount of displayed equip boxes.
+ */
+ void loadEquipBoxes();
+
protected:
/**
* Equipment box.
@@ -67,12 +72,14 @@ class EquipmentWindow : public Window, public gcn::ActionListener
int mSelected; /**< Index of selected item. */
Equipment *mEquipment;
+ int mBoxesNumber; /**< Number of equipment boxes to display */
private:
void mouseExited(gcn::MouseEvent &event);
void mouseMoved(gcn::MouseEvent &event);
Item *getItem(int x, int y) const;
+ const std::string getSlotName(int x, int y) const;
void setSelected(int index);
@@ -80,22 +87,6 @@ class EquipmentWindow : public Window, public gcn::ActionListener
gcn::Button *mUnequip;
};
-namespace TmwAthena {
-
-class TaEquipmentWindow : public EquipmentWindow
-{
- public:
- TaEquipmentWindow(Equipment *equipment);
- ~TaEquipmentWindow();
-
- /**
- * Draws the equipment window using TmwAthena routine.
- */
- void draw(gcn::Graphics *graphics);
-};
-
-} // namespace TmwAthena
-
extern EquipmentWindow *equipmentWindow;
#endif // EQUIPMENTWINDOW_H
diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp
index 60943756..d65764a5 100644
--- a/src/gui/itempopup.cpp
+++ b/src/gui/itempopup.cpp
@@ -123,6 +123,34 @@ ItemPopup::~ItemPopup()
}
}
+void ItemPopup::setEquipmentText(const std::string& text)
+{
+ mItemEquipSlot = text;
+}
+
+void ItemPopup::setNoItem()
+{
+ mIcon->setImage(0);
+
+ std::string caption = _("No item");
+ if (!mItemEquipSlot.empty())
+ {
+ caption += " (";
+ caption += mItemEquipSlot;
+ caption += ")";
+ }
+ mItemName->setCaption(caption);
+ mItemName->adjustSize();
+
+ mItemName->setForegroundColor(Theme::getThemeColor(Theme::GENERIC));
+ mItemName->setPosition(getPadding(), getPadding());
+
+ mItemDesc->setText(std::string());
+ mItemEffect->setText(std::string());
+
+ setContentSize(mItemName->getWidth() + 2 * getPadding(), 0);
+}
+
void ItemPopup::setItem(const ItemInfo &item, bool showImage)
{
if (item.getName() == mItemName->getCaption())
@@ -157,7 +185,11 @@ void ItemPopup::setItem(const ItemInfo &item, bool showImage)
mItemType = item.getItemType();
- mItemName->setCaption(item.getName());
+ std::string caption = item.getName();
+ if (!mItemEquipSlot.empty())
+ caption += " (" + mItemEquipSlot + ")";
+
+ mItemName->setCaption(caption);
mItemName->adjustSize();
mItemName->setForegroundColor(getColorFromItemType(mItemType));
mItemName->setPosition(getPadding() + space, getPadding());
@@ -226,5 +258,6 @@ void ItemPopup::mouseMoved(gcn::MouseEvent &event)
// When the mouse moved on top of the popup, hide it
setVisible(false);
+ mItemEquipSlot.clear();
}
diff --git a/src/gui/itempopup.h b/src/gui/itempopup.h
index f054ddf5..95adcf45 100644
--- a/src/gui/itempopup.h
+++ b/src/gui/itempopup.h
@@ -49,6 +49,16 @@ class ItemPopup : public Popup
~ItemPopup();
/**
+ * Tells the item popup to say: No Item.
+ */
+ void setNoItem();
+
+ /**
+ * Tells in which equipment slot the item is equipped.
+ */
+ void setEquipmentText(const std::string& text = std::string());
+
+ /**
* Sets the info to be displayed given a particular item.
*/
void setItem(const ItemInfo &item, bool showImage = false);
@@ -60,6 +70,7 @@ class ItemPopup : public Popup
TextBox *mItemDesc;
TextBox *mItemEffect;
TextBox *mItemWeight;
+ std::string mItemEquipSlot;
ItemType mItemType;
Icon *mIcon;
};