summaryrefslogtreecommitdiff
path: root/src/gui
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
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')
-rw-r--r--src/gui/equipmentwindow.cpp127
-rw-r--r--src/gui/equipmentwindow.h40
2 files changed, 139 insertions, 28 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;
+ }
+ }
+ }
}
diff --git a/src/gui/equipmentwindow.h b/src/gui/equipmentwindow.h
index 99a3cc60..e42e7b59 100644
--- a/src/gui/equipmentwindow.h
+++ b/src/gui/equipmentwindow.h
@@ -26,14 +26,28 @@
#include "window.h"
+#include <guichan/actionlistener.hpp>
+
+#include "../equipment.h"
+
class Equipment;
+class Image;
+
+/**
+ * Equipment box.
+ */
+struct EquipBox
+{
+ int posX;
+ int posY;
+};
/**
* Equipment dialog.
*
* \ingroup Interface
*/
-class EquipmentWindow : public Window
+class EquipmentWindow : public Window, public gcn::ActionListener
{
public:
/**
@@ -51,10 +65,32 @@ class EquipmentWindow : public Window
*/
void draw(gcn::Graphics *graphics);
+ void action(const gcn::ActionEvent &event);
+
+ void mousePressed(gcn::MouseEvent& mouseEvent);
+
+ enum{
+ // Equipment rules:
+ EQUIP_TORSO_SLOT = 0,
+ EQUIP_ARMS_SLOT = 1,
+ EQUIP_HEAD_SLOT = 2,
+ EQUIP_LEGS_SLOT = 3,
+ EQUIP_FEET_SLOT = 4,
+ EQUIP_RING1_SLOT = 5,
+ EQUIP_RING2_SLOT = 6,
+ EQUIP_NECKLACE_SLOT = 7,
+ EQUIP_FIGHT1_SLOT = 8,
+ EQUIP_FIGHT2_SLOT = 9,
+ EQUIP_PROJECTILE_SLOT = 10
+ };
private:
Equipment *mEquipment;
-};
+ gcn::Button *mUnequip; /**< Button for unequipping. */
+ Image *mBackground; /**< Background Image. */
+ EquipBox mEquipBox[EQUIPMENT_SIZE]; /**< Equipment Boxes. */
+ int mSelected; /**< Index of selected item. */
+};
extern EquipmentWindow *equipmentWindow;
#endif