diff options
author | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-08-18 02:43:38 +0200 |
---|---|---|
committer | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-08-18 02:43:38 +0200 |
commit | e86f83ed987461adabcbc02508107366b8c65558 (patch) | |
tree | d78016f0512788a21cc321d6d1f6d7947105fbae /src | |
parent | f8551d9ef4a745327bccb9e4cb54a22f6a28cf80 (diff) | |
download | mana-e86f83ed987461adabcbc02508107366b8c65558.tar.gz mana-e86f83ed987461adabcbc02508107366b8c65558.tar.bz2 mana-e86f83ed987461adabcbc02508107366b8c65558.tar.xz mana-e86f83ed987461adabcbc02508107366b8c65558.zip |
Made the equipment window not use server specific code again.
I also made the number of slots displayed
taken from the equip.xml file for manaserv.
Diffstat (limited to 'src')
-rw-r--r-- | src/game.cpp | 10 | ||||
-rw-r--r-- | src/gui/equipmentwindow.cpp | 169 | ||||
-rw-r--r-- | src/gui/equipmentwindow.h | 22 | ||||
-rw-r--r-- | src/net/manaserv/inventoryhandler.cpp | 3 | ||||
-rw-r--r-- | src/net/tmwa/inventoryhandler.cpp | 5 |
5 files changed, 96 insertions, 113 deletions
diff --git a/src/game.cpp b/src/game.cpp index af9c2c39..5fb98e6c 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -154,15 +154,7 @@ static void createGuiWindows() minimap = new Minimap; chatWindow = new ChatWindow; tradeWindow = new TradeWindow; - switch (Net::getNetworkType()) - { - case ServerInfo::TMWATHENA: - case ServerInfo::MANASERV: - default: - equipmentWindow = - new TmwAthena::TaEquipmentWindow(PlayerInfo::getEquipment()); - break; - } + equipmentWindow = new EquipmentWindow(PlayerInfo::getEquipment()); statusWindow = new StatusWindow; inventoryWindow = new InventoryWindow(PlayerInfo::getInventory()); skillDialog = new SkillDialog; diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index d3ac82f3..91ab38e8 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,6 +125,49 @@ 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) @@ -104,7 +181,7 @@ void EquipmentWindow::action(const gcn::ActionEvent &event) Item *EquipmentWindow::getItem(int x, int y) const { - for (int i = 0; i < TmwAthena::EQUIP_VECTOR_END; i++) + for (int i = 0; i < mBoxesNumber; ++i) { gcn::Rectangle tRect(mEquipBox[i].posX, mEquipBox[i].posY, BOX_WIDTH, BOX_HEIGHT); @@ -125,7 +202,7 @@ 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 < TmwAthena::EQUIP_VECTOR_END; i++) + for (int i = 0; i < mBoxesNumber; ++i) { Item *item = mEquipment->getEquipment(i); gcn::Rectangle tRect(mEquipBox[i].posX, mEquipBox[i].posY, @@ -149,7 +226,6 @@ void EquipmentWindow::mousePressed(gcn::MouseEvent& mouseEvent) } } -// Show ItemTooltip void EquipmentWindow::mouseMoved(gcn::MouseEvent &event) { const int x = event.getX(); @@ -157,6 +233,7 @@ void EquipmentWindow::mouseMoved(gcn::MouseEvent &event) Item *item = getItem(x, y); + // Show ItemTooltip if (item) { int mouseX, mouseY; @@ -171,7 +248,6 @@ void EquipmentWindow::mouseMoved(gcn::MouseEvent &event) } } -// Hide ItemTooltip void EquipmentWindow::mouseExited(gcn::MouseEvent &event) { mItemPopup->setVisible(false); @@ -182,86 +258,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..0001dd4e 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,6 +72,7 @@ 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); @@ -80,22 +86,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/net/manaserv/inventoryhandler.cpp b/src/net/manaserv/inventoryhandler.cpp index 021d7696..a5875e08 100644 --- a/src/net/manaserv/inventoryhandler.cpp +++ b/src/net/manaserv/inventoryhandler.cpp @@ -308,6 +308,9 @@ void InventoryHandler::handleMessage(Net::MessageIn &msg) it->second.mAmountUsed, it->first); } + // The backend is ready, we can setup the equipment window. + if (equipmentWindow) + equipmentWindow->loadEquipBoxes(); } break; diff --git a/src/net/tmwa/inventoryhandler.cpp b/src/net/tmwa/inventoryhandler.cpp index ff875e69..76eb85f5 100644 --- a/src/net/tmwa/inventoryhandler.cpp +++ b/src/net/tmwa/inventoryhandler.cpp @@ -31,6 +31,7 @@ #include "localplayer.h" #include "log.h" +#include "gui/equipmentwindow.h" #include "gui/widgets/chattab.h" #include "net/messagein.h" @@ -388,6 +389,10 @@ void InventoryHandler::handleMessage(Net::MessageIn &msg) { mEquips.setEquipment(getSlot(equipType), index); } + + // Load the equipment boxes + if (equipmentWindow) + equipmentWindow->loadEquipBoxes(); } break; |