diff options
author | Joshua Langley <joshlangley[at]optusnet.com.au> | 2007-08-08 09:35:21 +0000 |
---|---|---|
committer | Joshua Langley <joshlangley[at]optusnet.com.au> | 2007-08-08 09:35:21 +0000 |
commit | f80ff244eea2c3e6b37acf156f0d6933220d2cce (patch) | |
tree | b18ec0bdfde0f2a780942732032f17fc4cb08dda | |
parent | c7ca39c9fc863fbd59f9e859cbcfc2a65188f6f2 (diff) | |
download | mana-client-f80ff244eea2c3e6b37acf156f0d6933220d2cce.tar.gz mana-client-f80ff244eea2c3e6b37acf156f0d6933220d2cce.tar.bz2 mana-client-f80ff244eea2c3e6b37acf156f0d6933220d2cce.tar.xz mana-client-f80ff244eea2c3e6b37acf156f0d6933220d2cce.zip |
Re-designed equipment window, un-equip created.
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | data/graphics/images/EquipBackground.png | bin | 0 -> 18901 bytes | |||
-rw-r--r-- | src/equipment.h | 2 | ||||
-rw-r--r-- | src/gui/equipmentwindow.cpp | 127 | ||||
-rw-r--r-- | src/gui/equipmentwindow.h | 40 | ||||
-rw-r--r-- | src/localplayer.cpp | 6 | ||||
-rw-r--r-- | src/net/gameserver/player.cpp | 7 | ||||
-rw-r--r-- | src/net/gameserver/player.h | 1 |
8 files changed, 155 insertions, 34 deletions
@@ -1,3 +1,9 @@ +2007-08-08 Josh Langley <joshlangley[at]optusnet.com.au> + * src/equipment.h, src/gui/equipmentwindow.cpp, src/gui/equipmentwindow.h, + src/localplayer.cpp, src/net/gameserver/player.cpp, + src/net/gameserver/player.h, data/graphics/images/EquipBackground.png: + Re-designed equipment window, un-equip created. + 2007-08-07 Guillaume Melquiond <guillaume.melquiond@gmail.com> * po/Makevars, src/main.cpp: Replaced PACKAGE by tmw to reduce diff --git a/data/graphics/images/EquipBackground.png b/data/graphics/images/EquipBackground.png Binary files differnew file mode 100644 index 00000000..77ac63d8 --- /dev/null +++ b/data/graphics/images/EquipBackground.png diff --git a/src/equipment.h b/src/equipment.h index f178e0ca..bac5a028 100644 --- a/src/equipment.h +++ b/src/equipment.h @@ -26,7 +26,7 @@ class Item; -#define EQUIPMENT_SIZE 10 +#define EQUIPMENT_SIZE 11 class Equipment { 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 diff --git a/src/localplayer.cpp b/src/localplayer.cpp index b4fc5957..23d4c99b 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -107,11 +107,7 @@ void LocalPlayer::equipItem(Item *item) void LocalPlayer::unequipItem(int slot) { - // XXX Convert for new server - /* - MessageOut outMsg(CMSG_PLAYER_UNEQUIP); - outMsg.writeShort(item->getInvIndex()); - */ + Net::GameServer::Player::unequip(slot); // Tidy equipment directly to avoid weapon still shown bug, by instance mEquipment->setEquipment(slot, 0); diff --git a/src/net/gameserver/player.cpp b/src/net/gameserver/player.cpp index c91923d8..e93fff46 100644 --- a/src/net/gameserver/player.cpp +++ b/src/net/gameserver/player.cpp @@ -67,6 +67,13 @@ void Net::GameServer::Player::equip(int slot) Net::GameServer::connection->send(msg); } +void Net::GameServer::Player::unequip(int slot) +{ + MessageOut msg(PGMSG_UNEQUIP); + msg.writeByte(slot); + Net::GameServer::connection->send(msg); +} + void Net::GameServer::Player::attack(int direction) { MessageOut msg(PGMSG_ATTACK); diff --git a/src/net/gameserver/player.h b/src/net/gameserver/player.h index 8b4cde5b..4c27d4d0 100644 --- a/src/net/gameserver/player.h +++ b/src/net/gameserver/player.h @@ -39,6 +39,7 @@ namespace Net void pickUp(int x, int y); void drop(int slot, int amount); void equip(int slot); + void unequip(int slot); void attack(int direction); void changeAction(Being::Action action); void talkToNPC(int id, bool restart); |