summaryrefslogtreecommitdiff
path: root/src/gui/outfitwindow.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2009-09-29 21:09:13 +0300
committerChuck Miller <shadowmil@gmail.com>2009-09-29 15:09:24 -0400
commit805edb864a489b8af91db18c7b53bd80b60b0fe0 (patch)
tree6ccf7ece48022e39e3d79fdf04a1215180b34b6f /src/gui/outfitwindow.cpp
parent50c23cbae082f4aba50620e97ab1f08a16f9703d (diff)
downloadmana-805edb864a489b8af91db18c7b53bd80b60b0fe0.tar.gz
mana-805edb864a489b8af91db18c7b53bd80b60b0fe0.tar.bz2
mana-805edb864a489b8af91db18c7b53bd80b60b0fe0.tar.xz
mana-805edb864a489b8af91db18c7b53bd80b60b0fe0.zip
Outfits update
Increased outfits count to 15 Changed unequip outfits feature Added copy outfits feature
Diffstat (limited to 'src/gui/outfitwindow.cpp')
-rw-r--r--src/gui/outfitwindow.cpp100
1 files changed, 75 insertions, 25 deletions
diff --git a/src/gui/outfitwindow.cpp b/src/gui/outfitwindow.cpp
index 67fec9b0..a88003bb 100644
--- a/src/gui/outfitwindow.cpp
+++ b/src/gui/outfitwindow.cpp
@@ -27,13 +27,16 @@
#include "inventory.h"
#include "equipment.h"
#include "item.h"
+#include "log.h"
#include "gui/widgets/button.h"
#include "gui/widgets/checkbox.h"
+#include "gui/widgets/chattab.h"
#include "gui/widgets/label.h"
#include "gui/widgets/layout.h"
#include "net/inventoryhandler.h"
+#include "gui/chat.h"
#include "net/net.h"
#include "resources/image.h"
@@ -55,15 +58,19 @@ OutfitWindow::OutfitWindow():
mCurrentOutfit(0)
{
setWindowName("Outfits");
+ setResizable(true);
setCloseButton(true);
- setDefaultSize(250, 250, 118, 180); //160
+ setDefaultSize(250, 250, 118, 180);
mPreviousButton = new Button(_("<"), "previous", this);
mNextButton = new Button(_(">"), "next", this);
mCurrentLabel = new Label(strprintf(_("Outfit: %d"), 1));
mCurrentLabel->setAlignment(gcn::Graphics::CENTER);
mUnequipCheck = new CheckBox(_("Unequip first"),
- config.getValue("OutfitUnequip", true));
+ config.getValue("OutfitUnequip0", true));
+
+ mUnequipCheck->setActionEventId("unequip");
+ mUnequipCheck->addActionListener(this);
place(0, 3, mPreviousButton, 1);
place(1, 3, mCurrentLabel, 2);
@@ -87,7 +94,7 @@ OutfitWindow::~OutfitWindow()
void OutfitWindow::load()
{
memset(mItems, -1, sizeof(mItems));
- for (int o = 0; o < 10; o++)
+ for (int o = 0; o < OUTFITS_COUNT; o++)
{
std::string outfit = config.getValue("Outfit" + toString(o), "-1");
std::string buf;
@@ -103,69 +110,81 @@ void OutfitWindow::load()
{
mItems[o][i] = tokens[i];
}
+ mItemsUnequip[o] = config.getValue("OutfitUnequip" + toString(o), true);
}
}
void OutfitWindow::save()
{
std::string outfitStr;
- for (int o = 0; o < 10; o++)
+ for (int o = 0; o < OUTFITS_COUNT; o++)
{
- for (int i = 0; i < 9; i++)
+ for (int i = 0; i < OUTFIT_ITEM_COUNT; i++)
{
outfitStr += mItems[o][i] ? toString(mItems[o][i]) : toString(-1);
if (i <8) outfitStr += " ";
}
config.setValue("Outfit" + toString(o), outfitStr);
+ config.setValue("OutfitUnequip" + toString(o), mItemsUnequip[o]);
outfitStr = "";
}
- config.setValue("OutfitUnequip", mUnequipCheck->isSelected());
}
void OutfitWindow::action(const gcn::ActionEvent &event)
{
if (event.getId() == "next")
{
- if (mCurrentOutfit < 9) {
+ if (mCurrentOutfit < (OUTFITS_COUNT - 1)) {
mCurrentOutfit++;
} else {
mCurrentOutfit = 0;
}
+ mCurrentLabel->setCaption(strprintf(_("Outfit: %d"), mCurrentOutfit + 1));
+ mUnequipCheck->setSelected(mItemsUnequip[mCurrentOutfit]);
}
else if (event.getId() == "previous")
{
if (mCurrentOutfit > 0) {
mCurrentOutfit--;
} else {
- mCurrentOutfit = 9;
+ mCurrentOutfit = OUTFITS_COUNT - 1;
}
+ mCurrentLabel->setCaption(strprintf(_("Outfit: %d"), mCurrentOutfit + 1));
+ mUnequipCheck->setSelected(mItemsUnequip[mCurrentOutfit]);
+ }
+ else if (event.getId() == "unequip")
+ {
+ mItemsUnequip[mCurrentOutfit] = mUnequipCheck->isSelected();
}
- mCurrentLabel->setCaption(strprintf(_("Outfit: %d"), mCurrentOutfit + 1));
}
void OutfitWindow::wearOutfit(int outfit)
{
Item *item;
- if (mUnequipCheck->isSelected())
- {
- for (int i = 0; i < 11; i++)
- {
- if (!(item = player_node->mEquipment.get()->getEquipment(i)))
- continue;
- Net::getInventoryHandler()->unequipItem(item);
- }
- }
-
- for (int i = 0; i < 9; i++)
+ for (int i = 0; i < OUTFIT_ITEM_COUNT; i++)
{
item = player_node->getInventory()->findItem(mItems[outfit][i]);
- if (item && item->getQuantity())
+ if (item && !item->isEquipped() && item->getQuantity())
{
if (item->isEquipment()) {
Net::getInventoryHandler()->equipItem(item);
}
}
}
+
+ if (mItemsUnequip[outfit])
+ {
+ unequipNotInOutfit(outfit);
+ }
+}
+
+void OutfitWindow::copyOutfit(int outfit)
+{
+ Item *item;
+ for (int i = 0; i < OUTFIT_ITEM_COUNT; i++)
+ {
+ mItems[mCurrentOutfit][i] = mItems[outfit][i];
+ }
}
void OutfitWindow::draw(gcn::Graphics *graphics)
@@ -173,7 +192,7 @@ void OutfitWindow::draw(gcn::Graphics *graphics)
Window::draw(graphics);
Graphics *g = static_cast<Graphics*>(graphics);
- for (int i = 0; i < 9; i++)
+ for (int i = 0; i < OUTFIT_ITEM_COUNT; i++)
{
const int itemX = 10 + (i % mGridWidth) * mBoxWidth;
const int itemY = 25 + (i / mGridWidth) * mBoxHeight;
@@ -184,14 +203,18 @@ void OutfitWindow::draw(gcn::Graphics *graphics)
graphics->fillRectangle(gcn::Rectangle(itemX, itemY, 32, 32));
if (mItems[mCurrentOutfit][i] < 0)
+ {
continue;
+ }
Item *item =
player_node->getInventory()->findItem(mItems[mCurrentOutfit][i]);
- if (item) {
+ if (item)
+ {
// Draw item icon.
Image* image = item->getImage();
- if (image) {
+ if (image)
+ {
g->drawImage(image, itemX, itemY);
}
}
@@ -288,9 +311,36 @@ int OutfitWindow::getIndexFromGrid(int pointX, int pointY) const
}
const int index = (((pointY - 25) / mBoxHeight) * mGridWidth) +
(pointX - 10) / mBoxWidth;
- if (index >= 9)
+ if (index >= OUTFIT_ITEM_COUNT)
{
return -1;
}
return index;
}
+
+void OutfitWindow::unequipNotInOutfit(int outfit)
+{
+ Inventory *inventory = player_node->getInventory();
+ if (!inventory)
+ return;
+
+ for (int i = 0; i < inventory->getSize(); i++)
+ {
+ if (inventory->getItem(i) && inventory->getItem(i)->isEquipped())
+ {
+ bool found = false;
+ for (int f = 0; f < OUTFIT_ITEM_COUNT; f++)
+ {
+ if (inventory->getItem(i)->getId() == mItems[outfit][f])
+ {
+ found = true;
+ break;
+ }
+ }
+ if (!found)
+ {
+ Net::getInventoryHandler()->unequipItem(inventory->getItem(i));
+ }
+ }
+ }
+}