diff options
author | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-01-24 22:10:02 +0100 |
---|---|---|
committer | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-01-24 22:10:02 +0100 |
commit | d055bee5e6b45737ab89b3f8c70c6d0db7a22eb3 (patch) | |
tree | 081556c8fa27ce16372b1657e469ccd8587dd4e5 /src/gui/equipmentwindow.cpp | |
parent | f663f5bbb75b850ae22f451a22d112b6c62b2ad6 (diff) | |
download | mana-d055bee5e6b45737ab89b3f8c70c6d0db7a22eb3.tar.gz mana-d055bee5e6b45737ab89b3f8c70c6d0db7a22eb3.tar.bz2 mana-d055bee5e6b45737ab89b3f8c70c6d0db7a22eb3.tar.xz mana-d055bee5e6b45737ab89b3f8c70c6d0db7a22eb3.zip |
Refactored the item loading in a more extensible and per protocol way.
This will greatly help into upgrading the need of
each protocol separately.
This is the first step to a new item and equipment system for manaserv.
A subclassing of the EquipmentWindow will be done in the next commit,
as requested by Thorbjorn.
Reviewed-by: Thorbjorn.
Diffstat (limited to 'src/gui/equipmentwindow.cpp')
-rw-r--r-- | src/gui/equipmentwindow.cpp | 103 |
1 files changed, 60 insertions, 43 deletions
diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index aeeaf223..d6c029c3 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -68,6 +68,7 @@ static const int boxPosition[][2] = { EquipmentWindow::EquipmentWindow(Equipment *equipment): Window(_("Equipment")), mEquipment(equipment), + mEquipBox(0), mSelected(-1) { mItemPopup = new ItemPopup; @@ -93,15 +94,24 @@ EquipmentWindow::EquipmentWindow(Equipment *equipment): add(playerBox); add(mUnequip); - for (int i = 0; i < Equipment::EQUIP_VECTOREND; i++) + // Load equipment boxes. + if (Net::getNetworkType() == ServerInfo::TMWATHENA) { - mEquipBox[i].posX = boxPosition[i][0] + getPadding(); - mEquipBox[i].posY = boxPosition[i][1] + getTitleBarHeight(); + 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(); + } } } EquipmentWindow::~EquipmentWindow() { + if (Net::getNetworkType() == ServerInfo::TMWATHENA) + delete[] mEquipBox; + delete mItemPopup; } @@ -114,40 +124,43 @@ void EquipmentWindow::draw(gcn::Graphics *graphics) Window::drawChildren(graphics); - for (int i = 0; i < Equipment::EQUIP_VECTOREND; i++) + if (Net::getNetworkType() == ServerInfo::TMWATHENA) { - if (i == mSelected) + for (int i = 0; i < TmwAthena::EQUIP_VECTOR_END; i++) { - const gcn::Color color = Theme::getThemeColor(Theme::HIGHLIGHT); + 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 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)); + // 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 == EQUIP_PROJECTILE_SLOT) + Item *item = mEquipment->getEquipment(i); + if (item) { - 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); + // 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); + } } } } @@ -165,14 +178,15 @@ void EquipmentWindow::action(const gcn::ActionEvent &event) Item *EquipmentWindow::getItem(int x, int y) const { - for (int i = 0; i < Equipment::EQUIP_VECTOREND; i++) + if (Net::getNetworkType() == ServerInfo::TMWATHENA) { - gcn::Rectangle tRect(mEquipBox[i].posX, mEquipBox[i].posY, - BOX_WIDTH, BOX_HEIGHT); - - if (tRect.isPointInRect(x, y)) + for (int i = 0; i < TmwAthena::EQUIP_VECTOR_END; i++) { - return mEquipment->getEquipment(i); + gcn::Rectangle tRect(mEquipBox[i].posX, mEquipBox[i].posY, + BOX_WIDTH, BOX_HEIGHT); + + if (tRect.isPointInRect(x, y)) + return mEquipment->getEquipment(i); } } return NULL; @@ -188,14 +202,17 @@ 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 < Equipment::EQUIP_VECTOREND; i++) + if (Net::getNetworkType() == ServerInfo::TMWATHENA) { - Item *item = mEquipment->getEquipment(i); - gcn::Rectangle tRect(mEquipBox[i].posX, mEquipBox[i].posY, - BOX_WIDTH, BOX_HEIGHT); + 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); - if (tRect.isPointInRect(x, y) && item) - setSelected(i); + if (tRect.isPointInRect(x, y) && item) + setSelected(i); + } } } else if (mouseEvent.getButton() == gcn::MouseEvent::RIGHT) |