summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-06-04 22:08:04 +0300
committerAndrei Karas <akaras@inbox.ru>2011-06-04 22:08:04 +0300
commita865b10749df829ef46a14e244bc88ac52bc10b4 (patch)
tree244f283ab8ba6cfcc9683eafe51be7a9d7bbabbe /src
parent9b3e13d4246930f0aa4dfb86e735466032d283dd (diff)
downloadmanaplus-a865b10749df829ef46a14e244bc88ac52bc10b4.tar.gz
manaplus-a865b10749df829ef46a14e244bc88ac52bc10b4.tar.bz2
manaplus-a865b10749df829ef46a14e244bc88ac52bc10b4.tar.xz
manaplus-a865b10749df829ef46a14e244bc88ac52bc10b4.zip
Add colors support for drops panel.
Delete search item function without colors support.
Diffstat (limited to 'src')
-rw-r--r--src/dropshortcut.cpp51
-rw-r--r--src/dropshortcut.h18
-rw-r--r--src/gui/popupmenu.cpp12
-rw-r--r--src/gui/popupmenu.h1
-rw-r--r--src/gui/shopwindow.cpp12
-rw-r--r--src/gui/tradewindow.cpp3
-rw-r--r--src/gui/widgets/dropshortcutcontainer.cpp15
-rw-r--r--src/gui/widgets/itemcontainer.cpp2
-rw-r--r--src/inventory.cpp11
-rw-r--r--src/inventory.h3
-rw-r--r--src/localplayer.cpp16
11 files changed, 98 insertions, 46 deletions
diff --git a/src/dropshortcut.cpp b/src/dropshortcut.cpp
index 189d76b96..c31241409 100644
--- a/src/dropshortcut.cpp
+++ b/src/dropshortcut.cpp
@@ -41,7 +41,8 @@
DropShortcut *dropShortcut;
DropShortcut::DropShortcut():
- mItemSelected(-1)
+ mItemSelected(-1),
+ mItemColorSelected(1)
{
for (int i = 0; i < DROP_SHORTCUT_ITEMS; i++)
mItems[i] = -1;
@@ -66,9 +67,14 @@ void DropShortcut::load(bool oldConfig)
for (int i = 0; i < DROP_SHORTCUT_ITEMS; i++)
{
int itemId = static_cast<int>(cfg->getValue("drop" + toString(i), -1));
+ int itemColor = static_cast<int>(
+ cfg->getValue("dropColor" + toString(i), -1));
if (itemId != -1)
+ {
mItems[i] = itemId;
+ mItemColors[i] = itemColor;
+ }
}
}
@@ -77,10 +83,17 @@ void DropShortcut::save()
for (int i = 0; i < DROP_SHORTCUT_ITEMS; i++)
{
const int itemId = mItems[i] ? mItems[i] : -1;
+ const int itemColor = mItemColors[i] ? mItemColors[i] : 1;
if (itemId != -1)
+ {
serverConfig.setValue("drop" + toString(i), itemId);
+ serverConfig.setValue("dropColor" + toString(i), itemColor);
+ }
else
+ {
serverConfig.deleteKey("drop" + toString(i));
+ serverConfig.deleteKey("dropColor" + toString(i));
+ }
}
}
@@ -92,12 +105,12 @@ void DropShortcut::dropFirst()
if (!Client::limitPackets(PACKET_DROP))
return;
- int itemId;
- itemId = getItem(0);
+ const int itemId = getItem(0);
+ const int itemColor = getItemColor(0);
if (itemId > 0)
{
- Item *item = PlayerInfo::getInventory()->findItem(itemId);
+ Item *item = PlayerInfo::getInventory()->findItem(itemId, itemColor);
if (item && item->getQuantity())
{
if (player_node->isServerBuggy())
@@ -137,14 +150,16 @@ void DropShortcut::dropItems(int cnt)
bool DropShortcut::dropItem(int cnt)
{
int itemId = 0;
+ unsigned char itemColor = 1;
while (mLastDropIndex < DROP_SHORTCUT_ITEMS && itemId < 1)
{
itemId = getItem(mLastDropIndex);
- mLastDropIndex++;
+ itemColor = getItemColor(mLastDropIndex);
+ mLastDropIndex ++;
}
if (itemId > 0)
{
- Item *item = PlayerInfo::getInventory()->findItem(itemId);
+ Item *item = PlayerInfo::getInventory()->findItem(itemId, itemColor);
if (item && item->getQuantity() > 0)
{
Net::getInventoryHandler()->dropItem(item, cnt);
@@ -159,11 +174,12 @@ bool DropShortcut::dropItem(int cnt)
while (mLastDropIndex < DROP_SHORTCUT_ITEMS && itemId < 1)
{
itemId = getItem(mLastDropIndex);
+ itemColor = getItemColor(mLastDropIndex);
mLastDropIndex++;
}
if (itemId > 0)
{
- Item *item = PlayerInfo::getInventory()->findItem(itemId);
+ Item *item = PlayerInfo::getInventory()->findItem(itemId, itemColor);
if (item && item->getQuantity() > 0)
{
Net::getInventoryHandler()->dropItem(item, cnt);
@@ -175,3 +191,24 @@ bool DropShortcut::dropItem(int cnt)
}
return false;
}
+
+void DropShortcut::setItemSelected(Item *item)
+{
+ if (item)
+ {
+ mItemSelected = item->getId();
+ mItemColorSelected = item->getColor();
+ }
+ else
+ {
+ mItemSelected = -1;
+ mItemColorSelected = 1;
+ }
+}
+
+void DropShortcut::setItem(int index)
+{
+ mItems[index] = mItemSelected;
+ mItemColors[index] = mItemColorSelected;
+ save();
+}
diff --git a/src/dropshortcut.h b/src/dropshortcut.h
index 5a020879e..ffaf40ccf 100644
--- a/src/dropshortcut.h
+++ b/src/dropshortcut.h
@@ -61,6 +61,9 @@ class DropShortcut
int getItem(int index) const
{ return mItems[index]; }
+ int getItemColor(int index) const
+ { return mItemColors[index]; }
+
/**
* Returns the amount of shortcut items.
*/
@@ -78,8 +81,7 @@ class DropShortcut
*
* @param index Index of the items.
*/
- void setItem(int index)
- { mItems[index] = mItemSelected; save(); }
+ void setItem(int index);
/**
* Adds an item to the items store specified by the index.
@@ -87,8 +89,8 @@ class DropShortcut
* @param index Index of the item.
* @param itemId ID of the item.
*/
- void setItems(int index, int itemId)
- { mItems[index] = itemId; save(); }
+ void setItems(int index, int itemId, unsigned char color)
+ { mItems[index] = itemId; mItemColors[index] = color; save(); }
/**
* Set the item that is selected.
@@ -98,6 +100,8 @@ class DropShortcut
void setItemSelected(int itemId)
{ mItemSelected = itemId; }
+ void setItemSelected(Item *item);
+
/**
* A flag to check if the item is selected.
*/
@@ -144,8 +148,10 @@ class DropShortcut
*/
bool dropItem(int cnt = 1);
- int mItems[DROP_SHORTCUT_ITEMS]; /**< The items stored. */
- int mItemSelected; /**< The item held by cursor. */
+ int mItems[DROP_SHORTCUT_ITEMS];
+ int mItemColors[DROP_SHORTCUT_ITEMS];
+ int mItemSelected;
+ int mItemColorSelected;
int mLastDropIndex;
};
diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp
index d6004bb27..c3f28744c 100644
--- a/src/gui/popupmenu.cpp
+++ b/src/gui/popupmenu.cpp
@@ -88,6 +88,7 @@ PopupMenu::PopupMenu():
mFloorItem(0),
mItem(0),
mItemId(0),
+ mItemColor(1),
mMapItem(0),
mTab(0),
mSpell(0),
@@ -889,7 +890,7 @@ void PopupMenu::handleLink(const std::string &link,
Inventory *inv = PlayerInfo::getInventory();
if (inv)
{
- Item *item = inv->findItem(mItemId);
+ Item *item = inv->findItem(mItemId, mItemColor);
if (item)
{
if (item->isEquipment())
@@ -1473,6 +1474,7 @@ void PopupMenu::handleLink(const std::string &link,
mFloorItem = 0;
mItem = 0;
mItemId = 0;
+ mItemColor = 1;
mMapItem = 0;
mNick = "";
}
@@ -1586,6 +1588,7 @@ void PopupMenu::showItemPopup(int x, int y, int itemId, unsigned char color)
{
mItem = 0;
mItemId = itemId;
+ mItemColor = color;
mBrowserBox->clearRows();
mBrowserBox->addRow(strprintf("@@use|%s@@", _("Use")));
@@ -1603,9 +1606,15 @@ void PopupMenu::showItemPopup(int x, int y, Item *item)
{
mItem = item;
if (item)
+ {
mItemId = item->getId();
+ mItemColor = item->getColor();
+ }
else
+ {
mItemId = 0;
+ mItemColor = 1;
+ }
mBrowserBox->clearRows();
if (item)
@@ -1827,6 +1836,7 @@ void PopupMenu::showUndressPopup(int x, int y, Being *being, Item *item)
mBeingId = being->getId();
mItem = item;
mItemId = item->getId();
+ mItemColor = item->getColor();
mBrowserBox->clearRows();
diff --git a/src/gui/popupmenu.h b/src/gui/popupmenu.h
index f23dc0f87..976e3e5d2 100644
--- a/src/gui/popupmenu.h
+++ b/src/gui/popupmenu.h
@@ -143,6 +143,7 @@ class PopupMenu : public Popup, public LinkHandler
FloorItem* mFloorItem;
Item *mItem;
int mItemId;
+ unsigned char mItemColor;
MapItem *mMapItem;
ChatTab *mTab;
TextCommand *mSpell;
diff --git a/src/gui/shopwindow.cpp b/src/gui/shopwindow.cpp
index 549979905..46a3351c5 100644
--- a/src/gui/shopwindow.cpp
+++ b/src/gui/shopwindow.cpp
@@ -215,7 +215,8 @@ void ShopWindow::action(const gcn::ActionEvent &event)
if (!inv)
return;
- Item *item = inv->findItem(mSelectedItem);
+ //+++ need support for colors
+ Item *item = inv->findItem(mSelectedItem, 1);
if (item)
{
if (event.getId() == "add buy")
@@ -513,7 +514,8 @@ void ShopWindow::giveList(const std::string &nick, int mode)
if (mode == SELL)
{
- Item *item2 = inv->findItem(item->getId());
+ //+++ need support for colors
+ Item *item2 = inv->findItem(item->getId(), 1);
if (item2)
{
int amount = item->getQuantity();
@@ -609,7 +611,8 @@ void ShopWindow::showList(const std::string &nick, std::string data)
buyDialog->addItem(id, 1, amount, price);
if (sellDialog)
{
- Item *item = inv->findItem(id);
+ //+++ need support for colors
+ Item *item = inv->findItem(id, 1);
if (item)
{
if (item->getQuantity() < amount)
@@ -681,7 +684,8 @@ void ShopWindow::processRequest(std::string nick, std::string data, int mode)
if (mode == BUY)
{
- Item *item2 = inv->findItem(mTradeItem->getId());
+ //+++ need support for colors
+ Item *item2 = inv->findItem(mTradeItem->getId(), 1);
if (!item2 || item2->getQuantity() < amount
|| !findShopItem(mTradeItem, SELL))
{
diff --git a/src/gui/tradewindow.cpp b/src/gui/tradewindow.cpp
index e7e74fdbb..e3fb323e6 100644
--- a/src/gui/tradewindow.cpp
+++ b/src/gui/tradewindow.cpp
@@ -430,7 +430,8 @@ void TradeWindow::initTrade(std::string nick)
Inventory *inv = PlayerInfo::getInventory();
if (inv)
{
- Item *item = inv->findItem(mAutoAddItem->getId());
+ Item *item = inv->findItem(mAutoAddItem->getId(),
+ mAutoAddItem->getColor());
if (item)
tradeItem(item, mAutoAddItem->getQuantity());
}
diff --git a/src/gui/widgets/dropshortcutcontainer.cpp b/src/gui/widgets/dropshortcutcontainer.cpp
index 0125558dc..224830d8f 100644
--- a/src/gui/widgets/dropshortcutcontainer.cpp
+++ b/src/gui/widgets/dropshortcutcontainer.cpp
@@ -119,7 +119,8 @@ void DropShortcutContainer::draw(gcn::Graphics *graphics)
if (!inv)
return;
- Item *item = inv->findItem(dropShortcut->getItem(i));
+ Item *item = inv->findItem(dropShortcut->getItem(i),
+ dropShortcut->getItemColor(i));
if (item)
{
@@ -178,6 +179,7 @@ void DropShortcutContainer::mouseDragged(gcn::MouseEvent &event)
return;
const int itemId = dropShortcut->getItem(index);
+ const int itemColor = dropShortcut->getItemColor(index);
if (itemId < 0)
return;
@@ -186,7 +188,7 @@ void DropShortcutContainer::mouseDragged(gcn::MouseEvent &event)
if (!inv)
return;
- Item *item = inv->findItem(itemId);
+ Item *item = inv->findItem(itemId, itemColor);
if (item)
{
@@ -231,7 +233,8 @@ void DropShortcutContainer::mousePressed(gcn::MouseEvent &event)
if (!inv)
return;
- Item *item = inv->findItem(dropShortcut->getItem(index));
+ Item *item = inv->findItem(dropShortcut->getItem(index),
+ dropShortcut->getItemColor(index));
if (viewport)
viewport->showDropPopup(item);
@@ -256,7 +259,8 @@ void DropShortcutContainer::mouseReleased(gcn::MouseEvent &event)
}
if (mItemMoved)
{
- dropShortcut->setItems(index, mItemMoved->getId());
+ dropShortcut->setItems(index, mItemMoved->getId(),
+ mItemMoved->getColor());
mItemMoved = NULL;
}
@@ -277,6 +281,7 @@ void DropShortcutContainer::mouseMoved(gcn::MouseEvent &event)
return;
const int itemId = dropShortcut->getItem(index);
+ const int itemColor = dropShortcut->getItemColor(index);
if (itemId < 0)
return;
@@ -285,7 +290,7 @@ void DropShortcutContainer::mouseMoved(gcn::MouseEvent &event)
if (!inv)
return;
- Item *item = inv->findItem(itemId);
+ Item *item = inv->findItem(itemId, itemColor);
if (item && viewport)
{
diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp
index 1650c386e..a9d1f5279 100644
--- a/src/gui/widgets/itemcontainer.cpp
+++ b/src/gui/widgets/itemcontainer.cpp
@@ -342,7 +342,7 @@ void ItemContainer::mousePressed(gcn::MouseEvent &event)
itemShortcut[num]->setItemSelected(item);
}
if (dropShortcut)
- dropShortcut->setItemSelected(item->getId());
+ dropShortcut->setItemSelected(item);
if (item->isEquipment() && outfitWindow)
outfitWindow->setItemSelected(item);
if (shopWindow)
diff --git a/src/inventory.cpp b/src/inventory.cpp
index 6eb7dbf16..5e600192b 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -74,17 +74,6 @@ Item *Inventory::getItem(int index) const
return mItems[index];
}
-Item *Inventory::findItem(int itemId) const
-{
- for (unsigned i = 0; i < mSize; i++)
- {
- if (mItems[i] && mItems[i]->getId() == itemId)
- return mItems[i];
- }
-
- return 0;
-}
-
Item *Inventory::findItem(int itemId, unsigned char color) const
{
for (unsigned i = 0; i < mSize; i++)
diff --git a/src/inventory.h b/src/inventory.h
index cee9765eb..ffc2897ca 100644
--- a/src/inventory.h
+++ b/src/inventory.h
@@ -84,10 +84,9 @@ class Inventory
* Searches for the specified item by it's id.
*
* @param itemId The id of the item to be searched.
+ * @param color The color of the item to be searched.
* @return Item found on success, NULL on failure.
*/
- Item *findItem(int itemId) const;
-
Item *findItem(int itemId, unsigned char color) const;
/**
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index fc0e17a6f..93c27c0e7 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -1896,16 +1896,16 @@ void LocalPlayer::changeEquipmentBeforeAttack(Being* target)
if (allowSword)
{
//finding sword
- item = PlayerInfo::getInventory()->findItem(571);
+ item = PlayerInfo::getInventory()->findItem(571, 1);
if (!item)
- item = PlayerInfo::getInventory()->findItem(570);
+ item = PlayerInfo::getInventory()->findItem(570, 1);
if (!item)
- item = PlayerInfo::getInventory()->findItem(579);
+ item = PlayerInfo::getInventory()->findItem(579, 1);
if (!item)
- item = PlayerInfo::getInventory()->findItem(536);
+ item = PlayerInfo::getInventory()->findItem(536, 1);
//no swords
if (!item)
@@ -1921,9 +1921,9 @@ void LocalPlayer::changeEquipmentBeforeAttack(Being* target)
if (mAttackWeaponType == 3)
{
//finding shield
- item = PlayerInfo::getInventory()->findItem(601);
+ item = PlayerInfo::getInventory()->findItem(601, 1);
if (!item)
- item = PlayerInfo::getInventory()->findItem(602);
+ item = PlayerInfo::getInventory()->findItem(602, 1);
if (item && !item->isEquipped())
{
Net::getInventoryHandler()->equipItem(item);
@@ -1935,10 +1935,10 @@ void LocalPlayer::changeEquipmentBeforeAttack(Being* target)
else
{
//finding bow
- item = PlayerInfo::getInventory()->findItem(545);
+ item = PlayerInfo::getInventory()->findItem(545, 1);
if (!item)
- item = PlayerInfo::getInventory()->findItem(530);
+ item = PlayerInfo::getInventory()->findItem(530, 1);
//no bow
if (!item)