From 3dd4d34239a00a71df3638d148bfe92047ac7921 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 4 Jun 2011 21:25:33 +0300 Subject: Add support for colors to shortcuts panel. --- src/itemshortcut.cpp | 58 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 3 deletions(-) (limited to 'src/itemshortcut.cpp') diff --git a/src/itemshortcut.cpp b/src/itemshortcut.cpp index 0d2aee6de..464eeda14 100644 --- a/src/itemshortcut.cpp +++ b/src/itemshortcut.cpp @@ -39,6 +39,7 @@ ItemShortcut *itemShortcut[SHORTCUT_TABS]; ItemShortcut::ItemShortcut(int number): mItemSelected(-1), + mItemColorSelected(1), mNumber(number) { load(); @@ -52,6 +53,7 @@ ItemShortcut::~ItemShortcut() void ItemShortcut::load(bool oldConfig) { std::string name; + std::string color; Configuration *cfg; if (oldConfig) cfg = &config; @@ -59,34 +61,57 @@ void ItemShortcut::load(bool oldConfig) cfg = &serverConfig; if (mNumber) + { name = "shortcut" + toString(mNumber) + "_"; + color = "shortcutColor" + toString(mNumber) + "_"; + } else + { name = "shortcut"; + color = "shortcutColor"; + } for (int i = 0; i < SHORTCUT_ITEMS; i++) { int itemId = static_cast(cfg->getValue(name + toString(i), -1)); + int itemColor = static_cast( + cfg->getValue(color + toString(i), 1)); mItems[i] = itemId; + mItemColors[i] = itemColor; } } void ItemShortcut::save() { std::string name; + std::string color; if (mNumber) + { name = "shortcut" + toString(mNumber) + "_"; + color = "shortcutColor" + toString(mNumber) + "_"; + } else + { name = "shortcut"; + color = "shortcutColor"; + } logger->log("save %s", name.c_str()); for (int i = 0; i < SHORTCUT_ITEMS; i++) { const int itemId = mItems[i] ? mItems[i] : -1; + const int itemColor = mItemColors[i] ? mItemColors[i] : 1; if (itemId != -1) + { serverConfig.setValue(name + toString(i), itemId); + serverConfig.setValue(color + toString(i), itemColor); + } else + { serverConfig.deleteKey(name + toString(i)); + serverConfig.deleteKey(color + toString(i)); + } } } @@ -96,11 +121,13 @@ void ItemShortcut::useItem(int index) return; int itemId = mItems[index]; + int itemColor = mItemColors[index]; if (itemId >= 0) { if (itemId < SPELL_MIN_ID) { - Item *item = PlayerInfo::getInventory()->findItem(itemId); + Item *item = PlayerInfo::getInventory()->findItem( + itemId, itemColor); if (item && item->getQuantity()) { if (item->isEquipment()) @@ -130,7 +157,8 @@ void ItemShortcut::equipItem(int index) if (mItems[index]) { - Item *item = PlayerInfo::getInventory()->findItem(mItems[index]); + Item *item = PlayerInfo::getInventory()->findItem( + mItems[index], mItemColors[index]); if (item && item->getQuantity()) { if (item->isEquipment()) @@ -148,7 +176,8 @@ void ItemShortcut::unequipItem(int index) if (mItems[index]) { - Item *item = PlayerInfo::getInventory()->findItem(mItems[index]); + Item *item = PlayerInfo::getInventory()->findItem( + mItems[index], mItemColors[index]); if (item && item->getQuantity()) { if (item->isEquipment()) @@ -159,3 +188,26 @@ void ItemShortcut::unequipItem(int index) } } } + +void ItemShortcut::setItemSelected(Item *item) +{ + if (item) + { + logger->log("set selected id: %d", item->getId()); + logger->log("set selected color: %d", item->getColor()); + mItemSelected = item->getId(); + mItemColorSelected = item->getColor(); + } + else + { + mItemSelected = -1; + mItemColorSelected = 1; + } +} + +void ItemShortcut::setItem(int index) +{ + mItems[index] = mItemSelected; + mItemColors[index] = mItemColorSelected; + save(); +} -- cgit v1.2.3-60-g2f50