summaryrefslogtreecommitdiff
path: root/src/gui/outfitwindow.cpp
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 /src/gui/outfitwindow.cpp
parente668ab141d6b006b790d2b0a8fc515d13b78317e (diff)
downloadplus-2e752adf979e74f9a4b919bbc88929a7bf3adf25.tar.gz
plus-2e752adf979e74f9a4b919bbc88929a7bf3adf25.tar.bz2
plus-2e752adf979e74f9a4b919bbc88929a7bf3adf25.tar.xz
plus-2e752adf979e74f9a4b919bbc88929a7bf3adf25.zip
Add support for colors in outfits window.
Diffstat (limited to 'src/gui/outfitwindow.cpp')
-rw-r--r--src/gui/outfitwindow.cpp59
1 files changed, 54 insertions, 5 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;
+ }
+}