summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-06-04 21:25:33 +0300
committerAndrei Karas <akaras@inbox.ru>2011-06-04 21:25:33 +0300
commit3dd4d34239a00a71df3638d148bfe92047ac7921 (patch)
tree543c71241fc55fac01c1329480863256b0c62471 /src
parent2e752adf979e74f9a4b919bbc88929a7bf3adf25 (diff)
downloadmanaplus-3dd4d34239a00a71df3638d148bfe92047ac7921.tar.gz
manaplus-3dd4d34239a00a71df3638d148bfe92047ac7921.tar.bz2
manaplus-3dd4d34239a00a71df3638d148bfe92047ac7921.tar.xz
manaplus-3dd4d34239a00a71df3638d148bfe92047ac7921.zip
Add support for colors to shortcuts panel.
Diffstat (limited to 'src')
-rw-r--r--src/gui/popupmenu.cpp4
-rw-r--r--src/gui/popupmenu.h2
-rw-r--r--src/gui/viewport.cpp4
-rw-r--r--src/gui/viewport.h2
-rw-r--r--src/gui/widgets/itemcontainer.cpp2
-rw-r--r--src/gui/widgets/itemshortcutcontainer.cpp17
-rw-r--r--src/itemshortcut.cpp58
-rw-r--r--src/itemshortcut.h18
8 files changed, 86 insertions, 21 deletions
diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp
index 66a8ce3ab..d6004bb27 100644
--- a/src/gui/popupmenu.cpp
+++ b/src/gui/popupmenu.cpp
@@ -1571,13 +1571,13 @@ void PopupMenu::showPopup(Window *parent, int x, int y, Item *item,
showPopup(x, y);
}
-void PopupMenu::showItemPopup(int x, int y, int itemId)
+void PopupMenu::showItemPopup(int x, int y, int itemId, unsigned char color)
{
Inventory *inv = PlayerInfo::getInventory();
if (!inv)
return;
- Item *item = inv->findItem(itemId);
+ Item *item = inv->findItem(itemId, color);
if (item)
{
showItemPopup(x, y, item);
diff --git a/src/gui/popupmenu.h b/src/gui/popupmenu.h
index e16a9fb4f..f23dc0f87 100644
--- a/src/gui/popupmenu.h
+++ b/src/gui/popupmenu.h
@@ -109,7 +109,7 @@ class PopupMenu : public Popup, public LinkHandler
void showItemPopup(int x, int y, Item *item);
- void showItemPopup(int x, int y, int itemId);
+ void showItemPopup(int x, int y, int itemId, unsigned char color);
void showDropPopup(int x, int y, Item *item);
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index 3c13fcb7e..15353d9f9 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -590,9 +590,9 @@ void Viewport::showItemPopup(Item *item)
mPopupMenu->showItemPopup(getMouseX(), getMouseY(), item);
}
-void Viewport::showItemPopup(int itemId)
+void Viewport::showItemPopup(int itemId, unsigned char color)
{
- mPopupMenu->showItemPopup(getMouseX(), getMouseY(), itemId);
+ mPopupMenu->showItemPopup(getMouseX(), getMouseY(), itemId, color);
}
void Viewport::showDropPopup(Item *item)
diff --git a/src/gui/viewport.h b/src/gui/viewport.h
index 7cd12365b..52a3257f5 100644
--- a/src/gui/viewport.h
+++ b/src/gui/viewport.h
@@ -143,7 +143,7 @@ class Viewport : public WindowContainer, public gcn::MouseListener,
void showItemPopup(Item *item);
- void showItemPopup(int itemId);
+ void showItemPopup(int itemId, unsigned char color = 1);
void showDropPopup(Item *item);
diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp
index 589cb376a..1650c386e 100644
--- a/src/gui/widgets/itemcontainer.cpp
+++ b/src/gui/widgets/itemcontainer.cpp
@@ -339,7 +339,7 @@ void ItemContainer::mousePressed(gcn::MouseEvent &event)
if (num >= 0 && num < SHORTCUT_TABS)
{
if (itemShortcut[num])
- itemShortcut[num]->setItemSelected(item->getId());
+ itemShortcut[num]->setItemSelected(item);
}
if (dropShortcut)
dropShortcut->setItemSelected(item->getId());
diff --git a/src/gui/widgets/itemshortcutcontainer.cpp b/src/gui/widgets/itemshortcutcontainer.cpp
index 4d0758e3d..362cfad54 100644
--- a/src/gui/widgets/itemshortcutcontainer.cpp
+++ b/src/gui/widgets/itemshortcutcontainer.cpp
@@ -123,7 +123,8 @@ void ItemShortcutContainer::draw(gcn::Graphics *graphics)
g->drawText(key, itemX + 2, itemY + 2, gcn::Graphics::LEFT);
- int itemId = itemShortcut[mNumber]->getItem(i);
+ const int itemId = itemShortcut[mNumber]->getItem(i);
+ const int itemColor = itemShortcut[mNumber]->getItemColor(i);
if (itemId < 0)
continue;
@@ -134,7 +135,8 @@ void ItemShortcutContainer::draw(gcn::Graphics *graphics)
if (!PlayerInfo::getInventory())
continue;
- Item *item = PlayerInfo::getInventory()->findItem(itemId);
+ Item *item = PlayerInfo::getInventory()->findItem(
+ itemId, itemColor);
if (item)
{
@@ -284,7 +286,10 @@ void ItemShortcutContainer::mousePressed(gcn::MouseEvent &event)
// Item *item = PlayerInfo::getInventory()->findItem(id);
if (viewport && itemShortcut[mNumber])
- viewport->showItemPopup(itemShortcut[mNumber]->getItem(index));
+ {
+ viewport->showItemPopup(itemShortcut[mNumber]->getItem(index),
+ itemShortcut[mNumber]->getItemColor(index));
+ }
}
}
@@ -306,7 +311,8 @@ void ItemShortcutContainer::mouseReleased(gcn::MouseEvent &event)
}
if (mItemMoved)
{
- itemShortcut[mNumber]->setItems(index, mItemMoved->getId());
+ itemShortcut[mNumber]->setItems(index,
+ mItemMoved->getId(), mItemMoved->getColor());
mItemMoved = NULL;
}
else if (itemShortcut[mNumber]->getItem(index) && mItemClicked)
@@ -331,6 +337,7 @@ void ItemShortcutContainer::mouseMoved(gcn::MouseEvent &event)
return;
const int itemId = itemShortcut[mNumber]->getItem(index);
+ const int itemColor = itemShortcut[mNumber]->getItemColor(index);
if (itemId < 0)
return;
@@ -342,7 +349,7 @@ void ItemShortcutContainer::mouseMoved(gcn::MouseEvent &event)
if (!PlayerInfo::getInventory())
return;
- Item *item = PlayerInfo::getInventory()->findItem(itemId);
+ Item *item = PlayerInfo::getInventory()->findItem(itemId, itemColor);
if (item && viewport)
{
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<int>(cfg->getValue(name + toString(i), -1));
+ int itemColor = static_cast<int>(
+ 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();
+}
diff --git a/src/itemshortcut.h b/src/itemshortcut.h
index ee59a27ac..b735e899c 100644
--- a/src/itemshortcut.h
+++ b/src/itemshortcut.h
@@ -63,6 +63,9 @@ class ItemShortcut
int getItem(int index) const
{ return mItems[index]; }
+ unsigned char getItemColor(int index) const
+ { return mItemColors[index]; }
+
/**
* Returns the amount of shortcut items.
*/
@@ -80,8 +83,7 @@ class ItemShortcut
*
* @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.
@@ -89,8 +91,8 @@ class ItemShortcut
* @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.
@@ -100,6 +102,8 @@ class ItemShortcut
void setItemSelected(int itemId)
{ mItemSelected = itemId; }
+ void setItemSelected(Item *item);
+
/**
* Returns selected shortcut item ID.
*/
@@ -137,8 +141,10 @@ class ItemShortcut
private:
- int mItems[SHORTCUT_ITEMS]; /**< The items stored. */
- int mItemSelected; /**< The item held by cursor. */
+ int mItems[SHORTCUT_ITEMS]; /**< The items. */
+ unsigned char mItemColors[SHORTCUT_ITEMS]; /**< The item colors. */
+ int mItemSelected;
+ int mItemColorSelected;
int mNumber;
};