summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-06-04 19:06:23 +0300
committerAndrei Karas <akaras@inbox.ru>2011-06-04 19:35:23 +0300
commit2e752adf979e74f9a4b919bbc88929a7bf3adf25 (patch)
treecd8b5f370e0c86dc08a487a9721971da8bd491d8
parente668ab141d6b006b790d2b0a8fc515d13b78317e (diff)
downloadmanaplus-2e752adf979e74f9a4b919bbc88929a7bf3adf25.tar.gz
manaplus-2e752adf979e74f9a4b919bbc88929a7bf3adf25.tar.bz2
manaplus-2e752adf979e74f9a4b919bbc88929a7bf3adf25.tar.xz
manaplus-2e752adf979e74f9a4b919bbc88929a7bf3adf25.zip
Add support for colors in outfits window.
-rw-r--r--src/gui/outfitwindow.cpp59
-rw-r--r--src/gui/outfitwindow.h4
-rw-r--r--src/gui/widgets/itemcontainer.cpp2
-rw-r--r--src/inventory.cpp14
-rw-r--r--src/inventory.h2
5 files changed, 75 insertions, 6 deletions
diff --git a/src/gui/outfitwindow.cpp b/src/gui/outfitwindow.cpp
index e322187fd..96deee71d 100644
--- a/src/gui/outfitwindow.cpp
+++ b/src/gui/outfitwindow.cpp
@@ -64,6 +64,7 @@ OutfitWindow::OutfitWindow():
mItemClicked(false),
mItemMoved(NULL),
mItemSelected(-1),
+ mItemColorSelected(1),
mCurrentOutfit(0),
mAwayOutfit(0)
{
@@ -125,6 +126,7 @@ void OutfitWindow::load(bool oldConfig)
cfg = &serverConfig;
memset(mItems, -1, sizeof(mItems));
+ memset(mItemColors, 1, sizeof(mItemColors));
for (int o = 0; o < OUTFITS_COUNT; o++)
{
@@ -143,6 +145,21 @@ void OutfitWindow::load(bool oldConfig)
mItems[o][i] = tokens[i];
}
+
+ outfit = cfg->getValue("OutfitColor" + toString(o), "1");
+ std::stringstream ss2(outfit);
+
+ tokens.clear();
+
+ while (ss2 >> buf)
+ tokens.push_back(atoi(buf.c_str()));
+
+ for (int i = 0; i < static_cast<int>(tokens.size())
+ && i < OUTFIT_ITEM_COUNT; i++)
+ {
+ mItemColors[o][i] = tokens[i];
+ }
+
mItemsUnequip[o] = cfg->getValueBool("OutfitUnequip" + toString(o),
true);
}
@@ -157,6 +174,7 @@ void OutfitWindow::load(bool oldConfig)
void OutfitWindow::save()
{
std::string outfitStr;
+ std::string outfitColorsStr;
for (int o = 0; o < OUTFITS_COUNT; o++)
{
bool good = false;
@@ -168,11 +186,21 @@ void OutfitWindow::save()
outfitStr += toString(res);
if (i < OUTFIT_ITEM_COUNT - 1)
outfitStr += " ";
+ outfitColorsStr += toString((int)mItemColors[o][i]);
+ if (i < OUTFIT_ITEM_COUNT - 1)
+ outfitColorsStr += " ";
}
if (good)
+ {
serverConfig.setValue("Outfit" + toString(o), outfitStr);
+ serverConfig.setValue("OutfitColor" + toString(o),
+ outfitColorsStr);
+ }
else
+ {
serverConfig.deleteKey("Outfit" + toString(o));
+ serverConfig.deleteKey("OutfitColor" + toString(o));
+ }
if (mItemsUnequip[o])
{
@@ -184,6 +212,7 @@ void OutfitWindow::save()
mItemsUnequip[o]);
}
outfitStr = "";
+ outfitColorsStr = "";
}
serverConfig.setValue("OutfitAwayIndex", mAwayOutfit);
}
@@ -221,7 +250,8 @@ void OutfitWindow::wearOutfit(int outfit, bool unwearEmpty, bool select)
for (int i = 0; i < OUTFIT_ITEM_COUNT; i++)
{
- item = PlayerInfo::getInventory()->findItem(mItems[outfit][i]);
+ item = PlayerInfo::getInventory()->findItem(
+ mItems[outfit][i], mItemColors[outfit][i]);
if (item && !item->isEquipped() && item->getQuantity())
{
if (item->isEquipment())
@@ -285,7 +315,8 @@ void OutfitWindow::draw(gcn::Graphics *graphics)
Inventory *inv = PlayerInfo::getInventory();
if (inv)
{
- Item *item = inv->findItem(mItems[mCurrentOutfit][i]);
+ Item *item = inv->findItem(mItems[mCurrentOutfit][i],
+ mItemColors[mCurrentOutfit][i]);
if (item)
{
// Draw item icon.
@@ -299,8 +330,8 @@ void OutfitWindow::draw(gcn::Graphics *graphics)
}
if (!foundItem)
{
- //+++ need use colors in outfits
- Image *image = Item::getImage(mItems[mCurrentOutfit][i], 1);
+ Image *image = Item::getImage(mItems[mCurrentOutfit][i],
+ mItemColors[mCurrentOutfit][i]);
if (image)
g->drawImage(image, itemX, itemY);
}
@@ -333,6 +364,7 @@ void OutfitWindow::mouseDragged(gcn::MouseEvent &event)
return;
}
const int itemId = mItems[mCurrentOutfit][index];
+ const int itemColor = mItemColors[mCurrentOutfit][index];
if (itemId < 0)
{
Window::mouseDragged(event);
@@ -343,7 +375,7 @@ void OutfitWindow::mouseDragged(gcn::MouseEvent &event)
Inventory *inv = PlayerInfo::getInventory();
if (inv)
{
- Item *item = inv->findItem(itemId);
+ Item *item = inv->findItem(itemId, itemColor);
if (item)
mItemMoved = item;
else
@@ -377,6 +409,7 @@ void OutfitWindow::mousePressed(gcn::MouseEvent &event)
if (isItemSelected())
{
mItems[mCurrentOutfit][index] = mItemSelected;
+ mItemColors[mCurrentOutfit][index] = mItemColorSelected;
// mItemSelected = -1;
}
else if (mItems[mCurrentOutfit][index])
@@ -405,6 +438,7 @@ void OutfitWindow::mouseReleased(gcn::MouseEvent &event)
if (mItemMoved)
{
mItems[mCurrentOutfit][index] = mItemMoved->getId();
+ mItemColors[mCurrentOutfit][index] = mItemMoved->getColor();
mItemMoved = NULL;
}
if (mItemClicked)
@@ -916,6 +950,7 @@ void OutfitWindow::copyFromEquiped(int dst)
if (inventory->getItem(i) && inventory->getItem(i)->isEquipped())
{
mItems[dst][outfitCell++] = inventory->getItem(i)->getId();
+ mItemColors[dst][outfitCell++] = inventory->getItem(i)->getColor();
if (outfitCell > 8)
break;
}
@@ -932,3 +967,17 @@ void OutfitWindow::unwearAwayOutfit()
{
wearOutfit(OUTFITS_COUNT);
}
+
+void OutfitWindow::setItemSelected(Item *item)
+{
+ if (item)
+ {
+ mItemSelected = item->getId();
+ mItemColorSelected = item->getColor();
+ }
+ else
+ {
+ mItemSelected = -1;
+ mItemColorSelected = 1;
+ }
+}
diff --git a/src/gui/outfitwindow.h b/src/gui/outfitwindow.h
index 8c73b13e0..7fd29608c 100644
--- a/src/gui/outfitwindow.h
+++ b/src/gui/outfitwindow.h
@@ -64,6 +64,8 @@ class OutfitWindow : public Window, gcn::ActionListener
void setItemSelected(int itemId)
{ mItemSelected = itemId; }
+ void setItemSelected(Item *item);
+
bool isItemSelected()
{ return mItemSelected > 0; }
@@ -120,8 +122,10 @@ class OutfitWindow : public Window, gcn::ActionListener
void save();
int mItems[OUTFITS_COUNT + 1][OUTFIT_ITEM_COUNT];
+ unsigned char mItemColors[OUTFITS_COUNT + 1][OUTFIT_ITEM_COUNT];
bool mItemsUnequip[OUTFITS_COUNT];
int mItemSelected;
+ int mItemColorSelected;
int mCurrentOutfit;
int mAwayOutfit;
diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp
index d4cecced2..589cb376a 100644
--- a/src/gui/widgets/itemcontainer.cpp
+++ b/src/gui/widgets/itemcontainer.cpp
@@ -344,7 +344,7 @@ void ItemContainer::mousePressed(gcn::MouseEvent &event)
if (dropShortcut)
dropShortcut->setItemSelected(item->getId());
if (item->isEquipment() && outfitWindow)
- outfitWindow->setItemSelected(item->getId());
+ outfitWindow->setItemSelected(item);
if (shopWindow)
shopWindow->setItemSelected(item->getId());
}
diff --git a/src/inventory.cpp b/src/inventory.cpp
index 9c3e16666..6eb7dbf16 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -85,6 +85,20 @@ Item *Inventory::findItem(int itemId) const
return 0;
}
+Item *Inventory::findItem(int itemId, unsigned char color) const
+{
+ for (unsigned i = 0; i < mSize; i++)
+ {
+ if (mItems[i] && mItems[i]->getId() == itemId
+ && mItems[i]->getColor() == color)
+ {
+ return mItems[i];
+ }
+ }
+
+ return 0;
+}
+
void Inventory::addItem(int id, int quantity, int refine,
unsigned char color, bool equipment)
{
diff --git a/src/inventory.h b/src/inventory.h
index 1e2d8a2bc..cee9765eb 100644
--- a/src/inventory.h
+++ b/src/inventory.h
@@ -88,6 +88,8 @@ class Inventory
*/
Item *findItem(int itemId) const;
+ Item *findItem(int itemId, unsigned char color) const;
+
/**
* Adds a new item in a free slot.
*/