diff options
author | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-11-13 00:33:01 +0100 |
---|---|---|
committer | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-11-13 19:50:00 +0100 |
commit | a0973bc302f2972c4c70d973090c4d29ea2f7c6d (patch) | |
tree | e840f5807aa8b3cfc69b17a17ac3bf9cba317485 | |
parent | 253c660d8e3341ad2d78658a23e599d5aaa84c00 (diff) | |
download | mana-a0973bc302f2972c4c70d973090c4d29ea2f7c6d.tar.gz mana-a0973bc302f2972c4c70d973090c4d29ea2f7c6d.tar.bz2 mana-a0973bc302f2972c4c70d973090c4d29ea2f7c6d.tar.xz mana-a0973bc302f2972c4c70d973090c4d29ea2f7c6d.zip |
Added background support to the equipment boxes.
The background images are auto-centered.
Also, for Manaserv, a new background parameter has been
added in the box node of the equip.xml file
to specify the background image.
Note that the filename is relative to the gui theme
folder.
Reviewed-by: Thorbjorn Lindeijer
Resolves: TMW-Mantis #769.
-rw-r--r-- | data/graphics/gui/equip-box-ammo.png | bin | 0 -> 2083 bytes | |||
-rw-r--r-- | data/graphics/gui/equip-box-chest.png | bin | 0 -> 1758 bytes | |||
-rw-r--r-- | data/graphics/gui/equip-box-feet.png | bin | 0 -> 1496 bytes | |||
-rw-r--r-- | data/graphics/gui/equip-box-hands.png | bin | 0 -> 1912 bytes | |||
-rw-r--r-- | data/graphics/gui/equip-box-head.png | bin | 0 -> 1647 bytes | |||
-rw-r--r-- | data/graphics/gui/equip-box-legs.png | bin | 0 -> 1765 bytes | |||
-rw-r--r-- | data/graphics/gui/equip-box-neck.png | bin | 0 -> 1738 bytes | |||
-rw-r--r-- | data/graphics/gui/equip-box-ring.png | bin | 0 -> 1581 bytes | |||
-rw-r--r-- | data/graphics/gui/equip-box-shield.png | bin | 0 -> 1762 bytes | |||
-rw-r--r-- | data/graphics/gui/equip-box-weapon.png | bin | 0 -> 2094 bytes | |||
-rw-r--r-- | src/gui/equipmentwindow.cpp | 19 | ||||
-rw-r--r-- | src/gui/equipmentwindow.h | 8 | ||||
-rw-r--r-- | src/net/inventoryhandler.h | 23 | ||||
-rw-r--r-- | src/net/manaserv/inventoryhandler.cpp | 11 | ||||
-rw-r--r-- | src/net/manaserv/inventoryhandler.h | 6 |
15 files changed, 67 insertions, 0 deletions
diff --git a/data/graphics/gui/equip-box-ammo.png b/data/graphics/gui/equip-box-ammo.png Binary files differnew file mode 100644 index 00000000..d9977b0b --- /dev/null +++ b/data/graphics/gui/equip-box-ammo.png diff --git a/data/graphics/gui/equip-box-chest.png b/data/graphics/gui/equip-box-chest.png Binary files differnew file mode 100644 index 00000000..03641b85 --- /dev/null +++ b/data/graphics/gui/equip-box-chest.png diff --git a/data/graphics/gui/equip-box-feet.png b/data/graphics/gui/equip-box-feet.png Binary files differnew file mode 100644 index 00000000..31e35fad --- /dev/null +++ b/data/graphics/gui/equip-box-feet.png diff --git a/data/graphics/gui/equip-box-hands.png b/data/graphics/gui/equip-box-hands.png Binary files differnew file mode 100644 index 00000000..ac299f8d --- /dev/null +++ b/data/graphics/gui/equip-box-hands.png diff --git a/data/graphics/gui/equip-box-head.png b/data/graphics/gui/equip-box-head.png Binary files differnew file mode 100644 index 00000000..8bed0940 --- /dev/null +++ b/data/graphics/gui/equip-box-head.png diff --git a/data/graphics/gui/equip-box-legs.png b/data/graphics/gui/equip-box-legs.png Binary files differnew file mode 100644 index 00000000..19b1ebff --- /dev/null +++ b/data/graphics/gui/equip-box-legs.png diff --git a/data/graphics/gui/equip-box-neck.png b/data/graphics/gui/equip-box-neck.png Binary files differnew file mode 100644 index 00000000..809861bf --- /dev/null +++ b/data/graphics/gui/equip-box-neck.png diff --git a/data/graphics/gui/equip-box-ring.png b/data/graphics/gui/equip-box-ring.png Binary files differnew file mode 100644 index 00000000..f5e79346 --- /dev/null +++ b/data/graphics/gui/equip-box-ring.png diff --git a/data/graphics/gui/equip-box-shield.png b/data/graphics/gui/equip-box-shield.png Binary files differnew file mode 100644 index 00000000..bedb28f3 --- /dev/null +++ b/data/graphics/gui/equip-box-shield.png diff --git a/data/graphics/gui/equip-box-weapon.png b/data/graphics/gui/equip-box-weapon.png Binary files differnew file mode 100644 index 00000000..c01e077c --- /dev/null +++ b/data/graphics/gui/equip-box-weapon.png diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index 209ecdb0..4e8eae4d 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -95,6 +95,15 @@ void EquipmentWindow::loadEquipBoxes() Position boxPosition = Net::getInventoryHandler()->getBoxPosition(i); mEquipBox[i].posX = boxPosition.x + getPadding(); mEquipBox[i].posY = boxPosition.y + getTitleBarHeight(); + + const std::string &backgroundFile = + Net::getInventoryHandler()->getBoxBackground(i); + + if (!backgroundFile.empty()) + { + mEquipBox[i].backgroundImage = + Theme::instance()->getImageFromTheme(backgroundFile); + } } } @@ -117,6 +126,16 @@ void EquipmentWindow::draw(gcn::Graphics *graphics) for (int i = 0; i < mBoxesNumber; i++) { + // When there is a background image, draw it centered in the box: + if (mEquipBox[i].backgroundImage) + { + int posX = mEquipBox[i].posX + + (BOX_WIDTH - mEquipBox[i].backgroundImage->getWidth()) / 2; + int posY = mEquipBox[i].posY + + (BOX_HEIGHT - mEquipBox[i].backgroundImage->getHeight()) / 2; + g->drawImage(mEquipBox[i].backgroundImage, posX, posY); + } + if (i == mSelected) { const gcn::Color color = Theme::getThemeColor(Theme::HIGHLIGHT); diff --git a/src/gui/equipmentwindow.h b/src/gui/equipmentwindow.h index 57a13d40..408dd8e7 100644 --- a/src/gui/equipmentwindow.h +++ b/src/gui/equipmentwindow.h @@ -23,6 +23,7 @@ #define EQUIPMENTWINDOW_H #include "equipment.h" +#include "resources/image.h" #include "gui/widgets/window.h" @@ -70,8 +71,15 @@ class EquipmentWindow : public Window, public gcn::ActionListener */ struct EquipBox { + EquipBox() : + posX(0), + posY(0), + backgroundImage(0) + {} + int posX; int posY; + Image* backgroundImage; }; EquipBox *mEquipBox; /**< Equipment Boxes. */ diff --git a/src/net/inventoryhandler.h b/src/net/inventoryhandler.h index 83ef91a7..24e6dd43 100644 --- a/src/net/inventoryhandler.h +++ b/src/net/inventoryhandler.h @@ -45,6 +45,22 @@ const int fallBackBoxesPosition[][2] = { { 129, 78 } // EQUIP_PROJECTILE_SLOT }; +const std::string fallBackBoxesBackground[] = { + "equip-box-chest.png", + "equip-box-hands.png", + "equip-box-head.png", + "equip-box-legs.png", + "equip-box-feet.png", + "equip-box-ring.png", + "equip-box-ring.png", + "equip-box-neck.png", + "equip-box-weapon.png", + "equip-box-shield.png", + "equip-box-ammo.png" +}; + +static const std::string empty = std::string(); + class InventoryHandler { public: @@ -70,6 +86,13 @@ class InventoryHandler fallBackBoxesPosition[slotIndex][1]); return Position(0,0); } + + virtual const std::string& getBoxBackground(unsigned int slotIndex) const + { + if (slotIndex < sizeof(fallBackBoxesBackground)) + return fallBackBoxesBackground[slotIndex]; + return empty; // The empty string + } }; } // namespace Net diff --git a/src/net/manaserv/inventoryhandler.cpp b/src/net/manaserv/inventoryhandler.cpp index 67c79a17..7dd971ab 100644 --- a/src/net/manaserv/inventoryhandler.cpp +++ b/src/net/manaserv/inventoryhandler.cpp @@ -271,6 +271,10 @@ void EquipBackend::readBoxNode(xmlNodePtr slotNode) int y = XML::getProperty(boxNode, "y" , 0); mBoxesPositions.push_back(Position(x, y)); + + std::string backgroundFile = + XML::getProperty(boxNode, "background" , std::string()); + mBoxesBackgroundFile.push_back(backgroundFile); } } @@ -303,6 +307,13 @@ Position EquipBackend::getBoxPosition(unsigned int slotIndex) const return Position(0, 0); } +const std::string& EquipBackend::getBoxBackground(unsigned int slotIndex) const +{ + if (slotIndex < mBoxesBackgroundFile.size()) + return mBoxesBackgroundFile.at(slotIndex); + return Net::empty; +} + InventoryHandler::InventoryHandler() { static const Uint16 _messages[] = { diff --git a/src/net/manaserv/inventoryhandler.h b/src/net/manaserv/inventoryhandler.h index 446105ee..c9192525 100644 --- a/src/net/manaserv/inventoryhandler.h +++ b/src/net/manaserv/inventoryhandler.h @@ -63,6 +63,8 @@ class EquipBackend : public Equipment::Backend, public EventListener Position getBoxPosition(unsigned int slotIndex) const; + const std::string& getBoxBackground(unsigned int slotIndex) const; + private: void readEquipFile(); @@ -114,6 +116,7 @@ class EquipBackend : public Equipment::Backend, public EventListener typedef std::map<unsigned int, Slot> Slots; Slots mSlots; std::vector<Position> mBoxesPositions; + std::vector<std::string> mBoxesBackgroundFile; }; class InventoryHandler : public MessageHandler, Net::InventoryHandler, @@ -142,6 +145,9 @@ class InventoryHandler : public MessageHandler, Net::InventoryHandler, Position getBoxPosition(unsigned int slotIndex) const { return mEquipBackend.getBoxPosition(slotIndex); } + const std::string& getBoxBackground(unsigned int slotIndex) const + { return mEquipBackend.getBoxBackground(slotIndex); } + private: EquipBackend mEquipBackend; }; |