summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2009-04-10 01:53:05 +0200
committerBjørn Lindeijer <bjorn@lindeijer.nl>2009-04-10 01:55:54 +0200
commit07e8a1b8408ed40cbf2031476627647057f62141 (patch)
tree688aa64341cb0dee0a5ea51acc16a28ddf3ea5c5 /src/gui
parentb4ebdcf0622ce297704887cf0d653079a1fbcf1e (diff)
downloadmana-client-07e8a1b8408ed40cbf2031476627647057f62141.tar.gz
mana-client-07e8a1b8408ed40cbf2031476627647057f62141.tar.bz2
mana-client-07e8a1b8408ed40cbf2031476627647057f62141.tar.xz
mana-client-07e8a1b8408ed40cbf2031476627647057f62141.zip
Some cleanup of the equipment window code
Also removed some unnecessary delete statements, since the Popup class already deletes its children and the ScrollArea already deletes its content.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/equipmentwindow.cpp91
-rw-r--r--src/gui/equipmentwindow.h34
-rw-r--r--src/gui/inventorywindow.cpp1
-rw-r--r--src/gui/itempopup.cpp7
-rw-r--r--src/gui/speechbubble.cpp4
-rw-r--r--src/gui/speechbubble.h2
6 files changed, 53 insertions, 86 deletions
diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp
index d9ada6f4..04b275e2 100644
--- a/src/gui/equipmentwindow.cpp
+++ b/src/gui/equipmentwindow.cpp
@@ -47,17 +47,17 @@ static const int BOX_HEIGHT = 36;
// 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
+ { 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
};
#ifdef TMWSERV_SUPPORT
@@ -74,28 +74,24 @@ EquipmentWindow::EquipmentWindow():
mItemPopup = new ItemPopup;
// Control that shows the Player
- mPlayerBox = new PlayerBox;
- mPlayerBox->setDimension(gcn::Rectangle(50, 80, 74, 123));
- mPlayerBox->setPlayer(player_node);
+ PlayerBox *playerBox = new PlayerBox;
+ playerBox->setDimension(gcn::Rectangle(50, 80, 74, 123));
+ playerBox->setPlayer(player_node);
setWindowName("Equipment");
setCloseButton(true);
setDefaultSize(180, 300, ImageRect::CENTER);
loadWindowState();
- mUnequip = new Button(_("Unequip"), "unequip", this);
+ gcn::Button *unequip = new Button(_("Unequip"), "unequip", this);
gcn::Rectangle const &area = getChildrenArea();
- mUnequip->setPosition(area.width - mUnequip->getWidth() - 5,
- area.height - mUnequip->getHeight() - 5);
+ unequip->setPosition(area.width - unequip->getWidth() - 5,
+ area.height - unequip->getHeight() - 5);
- add(mPlayerBox);
- add(mUnequip);
+ add(playerBox);
+ add(unequip);
-#ifdef TMWSERV_SUPPORT
- for (int i = 0; i < EQUIPMENT_SIZE; i++)
-#else
- for (int i = EQUIP_LEGS_SLOT; i < EQUIP_VECTOREND; i++)
-#endif
+ for (int i = 0; i < EQUIP_VECTOREND; i++)
{
mEquipBox[i].posX = boxPosition[i][0] + getPadding();
mEquipBox[i].posY = boxPosition[i][1] + getTitleBarHeight();
@@ -110,7 +106,6 @@ EquipmentWindow::EquipmentWindow():
EquipmentWindow::~EquipmentWindow()
{
delete mItemPopup;
- delete mUnequip;
}
void EquipmentWindow::draw(gcn::Graphics *graphics)
@@ -122,11 +117,7 @@ void EquipmentWindow::draw(gcn::Graphics *graphics)
Window::drawChildren(graphics);
-#ifdef TMWSERV_SUPPORT
- for (int i = 0; i < EQUIPMENT_SIZE; i++)
-#else
- for (int i = EQUIP_LEGS_SLOT; i < EQUIP_VECTOREND; i++)
-#endif
+ for (int i = 0; i < EQUIP_VECTOREND; i++)
{
if (i == mSelected)
{
@@ -188,11 +179,7 @@ void EquipmentWindow::action(const gcn::ActionEvent &event)
Item* EquipmentWindow::getItem(int x, int y) const
{
-#ifdef TMWSERV_SUPPORT
- for (int i = 0; i < EQUIPMENT_SIZE; i++)
-#else
- for (int i = EQUIP_LEGS_SLOT; i < EQUIP_VECTOREND; i++)
-#endif
+ for (int i = 0; i < EQUIP_VECTOREND; i++)
{
gcn::Rectangle tRect(mEquipBox[i].posX, mEquipBox[i].posY,
BOX_WIDTH, BOX_HEIGHT);
@@ -218,21 +205,15 @@ void EquipmentWindow::mousePressed(gcn::MouseEvent& mouseEvent)
const int x = mouseEvent.getX();
const int y = mouseEvent.getY();
- Item* item;
-
if (mouseEvent.getButton() == gcn::MouseEvent::LEFT)
{
// Checks if any of the presses were in the equip boxes.
-#ifdef TMWSERV_SUPPORT
- for (int i = 0; i < EQUIPMENT_SIZE; i++)
-#else
- for (int i = EQUIP_LEGS_SLOT; i < EQUIP_VECTOREND; i++)
-#endif
+ for (int i = 0; i < EQUIP_VECTOREND; i++)
{
#ifdef TMWSERV_SUPPORT
- item = mEquipment->getEquipment(i);
+ Item *item = mEquipment->getEquipment(i);
#else
- item = (i != EQUIP_AMMO_SLOT) ?
+ Item *item = (i != EQUIP_AMMO_SLOT) ?
mInventory->getItem(mEquipment->getEquipment(i)) :
mInventory->getItem(mEquipment->getArrows());
#endif
@@ -245,17 +226,15 @@ void EquipmentWindow::mousePressed(gcn::MouseEvent& mouseEvent)
}
else if (mouseEvent.getButton() == gcn::MouseEvent::RIGHT)
{
- item = getItem(x, y);
-
- if (!item)
- return;
-
- /* Convert relative to the window coordinates to absolute screen
- * coordinates.
- */
- const int mx = x + getX();
- const int my = y + getY();
- viewport->showPopup(mx, my, item);
+ if (Item *item = getItem(x, y))
+ {
+ /* Convert relative to the window coordinates to absolute screen
+ * coordinates.
+ */
+ const int mx = x + getX();
+ const int my = y + getY();
+ viewport->showPopup(mx, my, item);
+ }
}
}
@@ -265,7 +244,7 @@ void EquipmentWindow::mouseMoved(gcn::MouseEvent &event)
const int x = event.getX();
const int y = event.getY();
- Item* item = getItem(x, y);
+ Item *item = getItem(x, y);
if (item)
{
diff --git a/src/gui/equipmentwindow.h b/src/gui/equipmentwindow.h
index f5f9ee98..f6ba19f8 100644
--- a/src/gui/equipmentwindow.h
+++ b/src/gui/equipmentwindow.h
@@ -27,20 +27,9 @@
#include <guichan/actionlistener.hpp>
class Equipment;
-class Image;
class Inventory;
class Item;
class ItemPopup;
-class PlayerBox;
-
-/**
- * Equipment box.
- */
-struct EquipBox
-{
- int posX;
- int posY;
-};
/**
* Equipment dialog.
@@ -74,8 +63,8 @@ class EquipmentWindow : public Window, public gcn::ActionListener
void mousePressed(gcn::MouseEvent& mouseEvent);
#ifdef TMWSERV_SUPPORT
- enum{
- // Equipment rules:
+ enum EquipmentSlots
+ {
EQUIP_TORSO_SLOT = 0,
EQUIP_ARMS_SLOT = 1,
EQUIP_HEAD_SLOT = 2,
@@ -90,8 +79,8 @@ class EquipmentWindow : public Window, public gcn::ActionListener
EQUIP_VECTOREND
};
#else
- enum {
- // Equipment rules:
+ enum EquipmentSlots
+ {
EQUIP_LEGS_SLOT = 0,
EQUIP_FIGHT1_SLOT,
EQUIP_GLOVES_SLOT,
@@ -111,19 +100,26 @@ class EquipmentWindow : public Window, public gcn::ActionListener
void mouseExited(gcn::MouseEvent &event);
void mouseMoved(gcn::MouseEvent &event);
- Item* getItem(int x, int y) const;
+ Item *getItem(int x, int y) const;
Equipment *mEquipment;
#ifdef EATHENA_SUPPORT
Inventory *mInventory;
#endif
- gcn::Button *mUnequip; /**< Button for unequipping. */
+
+ /**
+ * Equipment box.
+ */
+ struct EquipBox
+ {
+ int posX;
+ int posY;
+ };
+
EquipBox mEquipBox[EQUIP_VECTOREND]; /**< Equipment Boxes. */
ItemPopup *mItemPopup;
- PlayerBox *mPlayerBox;
-
int mSelected; /**< Index of selected item. */
};
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp
index cb26f36f..a808945e 100644
--- a/src/gui/inventorywindow.cpp
+++ b/src/gui/inventorywindow.cpp
@@ -112,7 +112,6 @@ InventoryWindow::InventoryWindow(int invSize):
InventoryWindow::~InventoryWindow()
{
- delete mItems;
}
void InventoryWindow::logic()
diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp
index 278b06e2..6c994aca 100644
--- a/src/gui/itempopup.cpp
+++ b/src/gui/itempopup.cpp
@@ -91,13 +91,6 @@ ItemPopup::ItemPopup():
ItemPopup::~ItemPopup()
{
- delete mItemName;
- delete mItemDesc;
- delete mItemDescScroll;
- delete mItemEffect;
- delete mItemEffectScroll;
- delete mItemWeight;
- delete mItemWeightScroll;
}
void ItemPopup::setItem(const ItemInfo &item)
diff --git a/src/gui/speechbubble.cpp b/src/gui/speechbubble.cpp
index fb896ba2..b7977d09 100644
--- a/src/gui/speechbubble.cpp
+++ b/src/gui/speechbubble.cpp
@@ -70,7 +70,7 @@ void SpeechBubble::setCaption(const std::string &name, const gcn::Color *color)
void SpeechBubble::setText(std::string text, bool showName)
{
- if ((text == mText) && (mCaption->getWidth() <= mSpeechBox->getMinWidth()))
+ if (text == mText && (mCaption->getWidth() <= mSpeechBox->getMinWidth()))
return;
graphics->setColor(guiPalette->getColor(Palette::TEXT));
@@ -99,7 +99,7 @@ void SpeechBubble::setText(std::string text, bool showName)
mSpeechArea->setDimension(gcn::Rectangle(xPos, yPos, width, height));
}
-unsigned int SpeechBubble::getNumRows()
+unsigned int SpeechBubble::getNumRows() const
{
return mSpeechBox->getNumberOfRows();
}
diff --git a/src/gui/speechbubble.h b/src/gui/speechbubble.h
index 3b97d3fe..4601a43e 100644
--- a/src/gui/speechbubble.h
+++ b/src/gui/speechbubble.h
@@ -58,7 +58,7 @@ class SpeechBubble : public Popup
/**
* Gets the number of rows the speech bubble has.
*/
- unsigned int getNumRows();
+ unsigned int getNumRows() const;
private:
std::string mText;