summaryrefslogtreecommitdiff
path: root/src/gui/equipmentwindow.cpp
diff options
context:
space:
mode:
authorJoshua Langley <joshlangley[at]optusnet.com.au>2007-08-08 09:35:21 +0000
committerJoshua Langley <joshlangley[at]optusnet.com.au>2007-08-08 09:35:21 +0000
commitf80ff244eea2c3e6b37acf156f0d6933220d2cce (patch)
treeb18ec0bdfde0f2a780942732032f17fc4cb08dda /src/gui/equipmentwindow.cpp
parentc7ca39c9fc863fbd59f9e859cbcfc2a65188f6f2 (diff)
downloadmana-f80ff244eea2c3e6b37acf156f0d6933220d2cce.tar.gz
mana-f80ff244eea2c3e6b37acf156f0d6933220d2cce.tar.bz2
mana-f80ff244eea2c3e6b37acf156f0d6933220d2cce.tar.xz
mana-f80ff244eea2c3e6b37acf156f0d6933220d2cce.zip
Re-designed equipment window, un-equip created.
Diffstat (limited to 'src/gui/equipmentwindow.cpp')
-rw-r--r--src/gui/equipmentwindow.cpp127
1 files changed, 101 insertions, 26 deletions
diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp
index 0ffba5a2..fb8da493 100644
--- a/src/gui/equipmentwindow.cpp
+++ b/src/gui/equipmentwindow.cpp
@@ -21,27 +21,66 @@
* $Id$
*/
+#define BOX_WIDTH 36
+#define BOX_HEIGHT 36
+
#include "equipmentwindow.h"
-#include "../equipment.h"
+#include "button.h"
+
#include "../graphics.h"
#include "../item.h"
-#include "../log.h"
+#include "../localplayer.h"
-#include "../resources/iteminfo.h"
+#include "../resources/image.h"
#include "../resources/resourcemanager.h"
#include "../utils/gettext.h"
+// Positions of the boxes, 2nd dimension is X and Y respectively.
+const int boxPosition[][2] = {
+ {90, 100}, // EQUIP_TORSO_SLOT
+ {135, 60}, // EQUIP_ARMS_SLOT
+ {90, 10}, // EQUIP_HEAD_SLOT
+ {90, 145}, // EQUIP_LEGS_SLOT
+ {90, 190}, // EQUIP_FEET_SLOT
+ {35, 105}, // EQUIP_RING1_SLOT
+ {145, 105}, // EQUIP_RING2_SLOT
+ {90, 55}, // EQUIP_NECKLACE_SLOT
+ {20, 150}, // EQUIP_FIGHT1_SLOT
+ {160, 150}, // EQUIP_FIGHT2_SLOT
+ {45, 60} // EQUIP_PROJECTILE_SLOT
+};
+
EquipmentWindow::EquipmentWindow(Equipment *equipment):
- Window(_("Equipment")), mEquipment(equipment)
+
+ Window(_("Equipment")),
+ mEquipment(equipment),
+ mBackground(NULL),
+ mSelected(-1)
{
- setDefaultSize(5, 230, 200, 120);
+ setDefaultSize(5, 195, 216, 260);
loadWindowState("Equipment");
+
+ mUnequip = new Button(_("Unequip"), "unequip", this);
+ mUnequip->setPosition(150,235);
+ add(mUnequip);
+
+ for (int i = 0; i < EQUIPMENT_SIZE; i++)
+ {
+ mEquipBox[i].posX = boxPosition[i][0] + getPadding();
+ mEquipBox[i].posY = boxPosition[i][1] + getTitleBarHeight();
+ }
+
+ ResourceManager *resman = ResourceManager::getInstance();
+ mBackground = resman->getImage("graphics/images/equipBackground.png");
+ mBackground->setAlpha(0.3);
}
EquipmentWindow::~EquipmentWindow()
{
+ mBackground->decRef();
+ delete mUnequip;
}
void EquipmentWindow::draw(gcn::Graphics *graphics)
@@ -49,33 +88,69 @@ void EquipmentWindow::draw(gcn::Graphics *graphics)
// Draw window graphics
Window::draw(graphics);
- // Rectangles around items are black
- graphics->setColor(gcn::Color(0, 0, 0));
+ Graphics *g = static_cast<Graphics*>(graphics);
- for (int i = 0; i < EQUIPMENT_SIZE; i++) {
- graphics->drawRectangle(gcn::Rectangle(10 + 36 * (i % 4),
- 36 * (i / 4) + 25, 32, 32));
+ if (mBackground)
+ {
+ g->drawImage(mBackground, getPadding() + 10, 0);
+ }
- int item = mEquipment->getEquipment(i);
- if (!item) continue;
+ Window::drawChildren(graphics);
- Image *image = Item(item).getInfo().getImage();
- static_cast<Graphics*>(graphics)->
- drawImage(image, 36 * (i % 4) + 10, 36 * (i / 4) + 25);
- }
+ for (int i = 0; i < EQUIPMENT_SIZE; i++)
+ {
+ int itemId = mEquipment->getEquipment(i);
+ if (itemId)
+ {
+ // Draw Item.
+ Image *image = Item(itemId).getInfo().getImage();
+ g->drawImage(image, mEquipBox[i].posX, mEquipBox[i].posY);
+ }
- graphics->drawRectangle(gcn::Rectangle(160, 25, 32, 32));
+ if (i == mSelected)
+ {
+ // Set color red.
+ g->setColor(gcn::Color(255, 0, 0));
+ }
+ else
+ {
+ // 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));
+ }
+}
- /*
- if (!(item = mEquipment->getArrows())) {
- return;
+void EquipmentWindow::action(const gcn::ActionEvent &event)
+{
+ if (event.getId() == "unequip" && mSelected > -1)
+ {
+ player_node->unequipItem(mSelected);
+ mSelected = -1;
}
+}
+
+void EquipmentWindow::mousePressed(gcn::MouseEvent& mouseEvent)
+{
+ Window::mousePressed(mouseEvent);
- image = item->getInfo().getImage();
+ const int x = mouseEvent.getX();
+ const int y = mouseEvent.getY();
- static_cast<Graphics*>(graphics)->drawImage(image, 160, 25);
- graphics->drawText(toString(item->getQuantity()), 170, 62,
- gcn::Graphics::CENTER);
- */
- return;
+ // Checks if any of the presses were in the equip boxes.
+ for (int i = 0; i < EQUIPMENT_SIZE; i++)
+ {
+ gcn::Rectangle tRect(mEquipBox[i].posX, mEquipBox[i].posY,
+ BOX_WIDTH, BOX_HEIGHT);
+ if (tRect.isPointInRect(x, y))
+ {
+ int itemId = mEquipment->getEquipment(i);
+ if (itemId)
+ {
+ mSelected = i;
+ }
+ }
+ }
}