From 368a7d109248fe286aad278e744192746381df9c Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Mon, 26 Jan 2009 16:25:55 -0700 Subject: Created a new equipment screen, which is loosely related to the equipment screen on TMW's mainline client. Also fixed up the player box so that it can be used in game as well, which could potentially be useful in the future for making future equipment dialog changes. Signed-off-by: Ira Rice --- src/being.h | 3 + src/gui/equipmentwindow.cpp | 141 +++++++++++++++++++++++++++++++++++--------- src/gui/equipmentwindow.h | 59 ++++++++++++++---- src/gui/playerbox.cpp | 9 ++- 4 files changed, 173 insertions(+), 39 deletions(-) (limited to 'src') diff --git a/src/being.h b/src/being.h index 80295db8..b4508661 100644 --- a/src/being.h +++ b/src/being.h @@ -370,6 +370,9 @@ class Being : public Sprite static std::string getHairColor(int index); + virtual AnimatedSprite* getSprite(int index) const + { return mSprites[index]; } + protected: /** * Sets the new path for this being. diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index ff976b24..b532d621 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -19,16 +19,19 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#define BOX_WIDTH 36 +#define BOX_HEIGHT 36 + +#include + +#include "button.h" #include "equipmentwindow.h" +#include "playerbox.h" -#include "../equipment.h" -#include "../inventory.h" -#include "../localplayer.h" #include "../graphics.h" #include "../inventory.h" #include "../item.h" #include "../localplayer.h" -#include "../log.h" #include "../resources/iteminfo.h" #include "../resources/resourcemanager.h" @@ -36,19 +39,57 @@ #include "../utils/gettext.h" #include "../utils/tostring.h" +// Positions of the boxes, 2nd dimension is X and Y respectively. +static const int boxPosition[][2] = { + {50, 208}, // EQUIP_LEGS_SLOT + {8, 123}, // EQUIP_FIGHT1_SLOT + {8, 78}, // EQUIP_GLOVES_SLOT + {129, 168}, // EQUIP_RING2_SLOT + {8, 168}, // EQUIP_RING1_SLOT + {129, 123}, // EQUIP_FIGHT2_SLOT + {90, 208}, // EQUIP_FEET_SLOT + {50, 40}, // EQUIP_CAPE_SLOT + {70, 0}, // EQUIP_HEAD_SLOT + {90, 40}, // EQUIP_TORSO_SLOT + {129, 78} // EQUIP_AMMO_SLOT +}; + EquipmentWindow::EquipmentWindow(Equipment *equipment): Window(_("Equipment")), - mEquipment(equipment) + mEquipment(equipment), + mSelected(-1) + { + // Control that shows the Player + mPlayerBox = new PlayerBox; + mPlayerBox->setDimension(gcn::Rectangle(50, 80, 74, 123)); + mPlayerBox->setPlayer(player_node); + setWindowName("Equipment"); setCloseButton(true); - setDefaultSize(5, 230, 200, 140); + setDefaultSize(5, 195, 180, 300); loadWindowState(); + + mUnequip = new Button(_("Unequip"), "unequip", this); + gcn::Rectangle const &area = getChildrenArea(); + mUnequip->setPosition(area.width - mUnequip->getWidth() - 5, + area.height - mUnequip->getHeight() - 5); + + add(mPlayerBox); + add(mUnequip); + + for (int i = EQUIP_LEGS_SLOT; i < EQUIP_VECTOREND; i++) + { + mEquipBox[i].posX = boxPosition[i][0] + getPadding(); + mEquipBox[i].posY = boxPosition[i][1] + getTitleBarHeight(); + } + mInventory = player_node->getInventory(); } EquipmentWindow::~EquipmentWindow() { + delete mUnequip; } void EquipmentWindow::draw(gcn::Graphics *graphics) @@ -56,38 +97,84 @@ void EquipmentWindow::draw(gcn::Graphics *graphics) // Draw window graphics Window::draw(graphics); - Item *item; - Image *image; + Item* item; - // Rectangles around items are black - graphics->setColor(gcn::Color(0, 0, 0)); + Graphics *g = static_cast(graphics); - for (int i = 0; i < EQUIPMENT_SIZE; i++) { - graphics->drawRectangle(gcn::Rectangle(10 + 36 * (i % 4), - 36 * (i / 4) + 25, 32, 32)); + Window::drawChildren(graphics); - if (!(item = mInventory->getItem(mEquipment->getEquipment(i)))) - continue; + for (int i = EQUIP_LEGS_SLOT; i < EQUIP_VECTOREND; i++) + { + item = (i != EQUIP_AMMO_SLOT) ? + mInventory->getItem(mEquipment->getEquipment(i)) : + mInventory->getItem(mEquipment->getArrows()); + if (item) + { + // Draw Item. + Image* image = item->getImage(); + g->drawImage(image, mEquipBox[i].posX, mEquipBox[i].posY); + if (i == EQUIP_AMMO_SLOT) + { + graphics->drawText(toString(item->getQuantity()), + mEquipBox[i].posX + (BOX_WIDTH / 2), + mEquipBox[i].posY - getFont()->getHeight(), + gcn::Graphics::CENTER); + } + } - image = item->getImage(); - if (image) + if (i == mSelected) + { + // Set color red. + g->setColor(gcn::Color(255, 0, 0)); + } + else { - static_cast(graphics)->drawImage( - image, 36 * (i % 4) + 10, 36 * (i / 4) + 25); + // 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)); + } +} + +void EquipmentWindow::action(const gcn::ActionEvent &event) +{ + if (event.getId() == "unequip" && mSelected > -1) + { + Item* item = (mSelected != EQUIP_AMMO_SLOT) ? + mInventory->getItem(mEquipment->getEquipment(mSelected)) : + mInventory->getItem(mEquipment->getArrows()); + player_node->unequipItem(item); + mSelected = -1; } +} - graphics->drawRectangle(gcn::Rectangle(160, 25, 32, 32)); +void EquipmentWindow::mousePressed(gcn::MouseEvent& mouseEvent) +{ + Window::mousePressed(mouseEvent); - if (!(item = mInventory->getItem(mEquipment->getArrows()))) - return; + const int x = mouseEvent.getX(); + const int y = mouseEvent.getY(); - image = item->getImage(); + Item* item; - if (image) + // Checks if any of the presses were in the equip boxes. + for (int i = EQUIP_LEGS_SLOT; i < EQUIP_VECTOREND; i++) { - static_cast(graphics)->drawImage(image, 160, 25); + item = (i != EQUIP_AMMO_SLOT) ? + mInventory->getItem(mEquipment->getEquipment(i)) : + mInventory->getItem(mEquipment->getArrows()); + gcn::Rectangle tRect(mEquipBox[i].posX, mEquipBox[i].posY, + BOX_WIDTH, BOX_HEIGHT); + if (tRect.isPointInRect(x, y)) + { + if (item) + { + mSelected = i; + } + } } - graphics->drawText(toString(item->getQuantity()), 170, 62, - gcn::Graphics::CENTER); } + diff --git a/src/gui/equipmentwindow.h b/src/gui/equipmentwindow.h index 3a3f37f4..d8018644 100644 --- a/src/gui/equipmentwindow.h +++ b/src/gui/equipmentwindow.h @@ -1,41 +1,51 @@ /* * The Mana World - * Copyright (C) 2004 The Mana World Development Team + * Copyright 2004 The Mana World Development Team * * This file is part of The Mana World. * - * This program is free software; you can redistribute it and/or modify + * The Mana World is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * any later version. * - * This program is distributed in the hope that it will be useful, + * The Mana World is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * along with The Mana World; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef EQUIPMENTWINDOW_H -#define EQUIPMENTWINDOW_H +#ifndef EQUIPMENT_WINDOW_H +#define EQUIPMENT_WINDOW_H + +#include #include "window.h" -#include "../inventory.h" -#include "../guichanfwd.h" -#include "../inventory.h" +#include "../equipment.h" + +class Inventory; +class PlayerBox; -class Equipment; +/** + * Equipment box. + */ +struct EquipBox +{ + int posX; + int posY; +}; /** * Equipment dialog. * * \ingroup Interface */ -class EquipmentWindow : public Window +class EquipmentWindow : public Window, public gcn::ActionListener { public: /** @@ -53,9 +63,36 @@ class EquipmentWindow : public Window */ void draw(gcn::Graphics *graphics); + void action(const gcn::ActionEvent &event); + + void mousePressed(gcn::MouseEvent& mouseEvent); + + enum { + // Equipment rules: + EQUIP_LEGS_SLOT = 0, + EQUIP_FIGHT1_SLOT, + EQUIP_GLOVES_SLOT, + EQUIP_RING2_SLOT, + EQUIP_RING1_SLOT, + EQUIP_FIGHT2_SLOT, + EQUIP_FEET_SLOT, + EQUIP_CAPE_SLOT, + EQUIP_HEAD_SLOT, + EQUIP_TORSO_SLOT, + EQUIP_AMMO_SLOT, + EQUIP_VECTOREND + }; + + private: Equipment *mEquipment; Inventory *mInventory; + gcn::Button *mUnequip; /**< Button for unequipping. */ + EquipBox mEquipBox[EQUIP_VECTOREND]; /**< Equipment Boxes. */ + + PlayerBox *mPlayerBox; + + int mSelected; /**< Index of selected item. */ }; extern EquipmentWindow *equipmentWindow; diff --git a/src/gui/playerbox.cpp b/src/gui/playerbox.cpp index e8c19ad4..c22d407c 100644 --- a/src/gui/playerbox.cpp +++ b/src/gui/playerbox.cpp @@ -23,6 +23,7 @@ #include "playerbox.h" +#include "../animatedsprite.h" #include "../configuration.h" #include "../graphics.h" #include "../player.h" @@ -85,7 +86,13 @@ void PlayerBox::draw(gcn::Graphics *graphics) bs = getFrameSize(); x = getWidth() / 2 - 16 + bs; y = getHeight() / 2 + bs; - mPlayer->draw(static_cast(graphics), x, y); + for (int i = 0; i < Being::VECTOREND_SPRITE; i++) + { + if (mPlayer->getSprite(i) != NULL) + { + mPlayer->getSprite(i)->draw(static_cast(graphics), x, y); + } + } } } -- cgit v1.2.3-70-g09d2