summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-12-20 23:57:32 +0300
committerAndrei Karas <akaras@inbox.ru>2015-12-20 23:57:32 +0300
commite576b8a204e2c8be2733acd121d036ab14a70646 (patch)
treee55c1ac4ebd6cff1db87a93675c2bd65a2da2dec /src/gui
parent8cd4bfe47ea8ace9fc1f0ecf0eb68c844ab7a326 (diff)
downloadmanaverse-e576b8a204e2c8be2733acd121d036ab14a70646.tar.gz
manaverse-e576b8a204e2c8be2733acd121d036ab14a70646.tar.bz2
manaverse-e576b8a204e2c8be2733acd121d036ab14a70646.tar.xz
manaverse-e576b8a204e2c8be2733acd121d036ab14a70646.zip
Move shortcuts files into gui/shortcut directory.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/shortcut/dropshortcut.cpp169
-rw-r--r--src/gui/shortcut/dropshortcut.h69
-rw-r--r--src/gui/shortcut/emoteshortcut.cpp84
-rw-r--r--src/gui/shortcut/emoteshortcut.h128
-rw-r--r--src/gui/shortcut/itemshortcut.cpp240
-rw-r--r--src/gui/shortcut/itemshortcut.h165
-rw-r--r--src/gui/shortcut/shortcutbase.cpp129
-rw-r--r--src/gui/shortcut/shortcutbase.h139
-rw-r--r--src/gui/shortcut/spellshortcut.cpp62
-rw-r--r--src/gui/shortcut/spellshortcut.h88
-rw-r--r--src/gui/widgets/emoteshortcutcontainer.cpp3
-rw-r--r--src/gui/widgets/itemcontainer.cpp3
-rw-r--r--src/gui/widgets/itemshortcutcontainer.cpp5
-rw-r--r--src/gui/widgets/spellshortcutcontainer.cpp5
-rw-r--r--src/gui/widgets/textfield.cpp2
-rw-r--r--src/gui/widgets/virtshortcutcontainer.cpp3
-rw-r--r--src/gui/windowmanager.cpp3
-rw-r--r--src/gui/windows/skilldialog.cpp3
18 files changed, 1291 insertions, 9 deletions
diff --git a/src/gui/shortcut/dropshortcut.cpp b/src/gui/shortcut/dropshortcut.cpp
new file mode 100644
index 000000000..e9264e9c3
--- /dev/null
+++ b/src/gui/shortcut/dropshortcut.cpp
@@ -0,0 +1,169 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 Andrei Karas
+ * Copyright (C) 2011-2015 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "gui/shortcut/dropshortcut.h"
+
+#include "inventory.h"
+#include "item.h"
+#include "settings.h"
+
+#include "being/localplayer.h"
+#include "being/playerinfo.h"
+
+#include "net/packetlimiter.h"
+
+#include "debug.h"
+
+static const int DROP_SHORTCUT_ITEMS = 16;
+
+DropShortcut *dropShortcut = nullptr;
+
+DropShortcut::DropShortcut() :
+ ShortcutBase("drop", "dropColor", DROP_SHORTCUT_ITEMS),
+ mLastDropIndex(0)
+{
+ clear(false);
+ load();
+}
+
+DropShortcut::~DropShortcut()
+{
+}
+
+void DropShortcut::dropFirst() const
+{
+ if (!localPlayer)
+ return;
+
+ if (!PacketLimiter::limitPackets(PacketType::PACKET_DROP))
+ return;
+
+ const int itemId = getItem(0);
+ const ItemColor itemColor = getItemColor(0);
+ if (PlayerInfo::isItemProtected(itemId))
+ return;
+
+ if (itemId > 0)
+ {
+ const Item *const item = PlayerInfo::getInventory()
+ ->findItem(itemId, itemColor);
+ if (item && item->getQuantity())
+ {
+ const int cnt = settings.quickDropCounter;
+ if (localPlayer->isServerBuggy())
+ {
+ PlayerInfo::dropItem(item, cnt, Sfx_true);
+ }
+ else
+ {
+ for (int i = 0; i < cnt; i++)
+ PlayerInfo::dropItem(item, 1, Sfx_false);
+ }
+ }
+ }
+}
+
+void DropShortcut::dropItems(const int cnt)
+{
+ if (!localPlayer)
+ return;
+
+ if (localPlayer->isServerBuggy())
+ {
+ dropItem(settings.quickDropCounter);
+ return;
+ }
+
+ int n = 0;
+ const int sz = settings.quickDropCounter;
+ for (int f = 0; f < 9; f++)
+ {
+ for (int i = 0; i < sz; i++)
+ {
+ if (!PacketLimiter::limitPackets(PacketType::PACKET_DROP))
+ return;
+ if (dropItem())
+ n++;
+ }
+ if (n >= cnt)
+ break;
+ }
+}
+
+bool DropShortcut::dropItem(const int cnt)
+{
+ const Inventory *const inv = PlayerInfo::getInventory();
+ if (!inv)
+ return false;
+
+ int itemId = 0;
+ ItemColor itemColor = ItemColor_one;
+ while (mLastDropIndex < DROP_SHORTCUT_ITEMS &&
+ itemId < 1)
+ {
+ if (!PlayerInfo::isItemProtected(itemId))
+ {
+ itemId = getItem(mLastDropIndex);
+ itemColor = getItemColor(mLastDropIndex);
+ }
+ mLastDropIndex ++;
+ }
+
+ if (itemId > 0)
+ {
+ const Item *const item = inv->findItem(itemId, itemColor);
+ if (item &&
+ item->getQuantity() > 0)
+ {
+ PlayerInfo::dropItem(item, cnt, Sfx_true);
+ return true;
+ }
+ }
+ if (mLastDropIndex >= DROP_SHORTCUT_ITEMS)
+ mLastDropIndex = 0;
+
+ if (itemId < 1)
+ {
+ while (mLastDropIndex < DROP_SHORTCUT_ITEMS &&
+ itemId < 1)
+ {
+ if (!PlayerInfo::isItemProtected(itemId))
+ {
+ itemId = getItem(mLastDropIndex);
+ itemColor = getItemColor(mLastDropIndex);
+ }
+ mLastDropIndex++;
+ }
+ if (itemId > 0)
+ {
+ const Item *const item = inv->findItem(itemId, itemColor);
+ if (item && item->getQuantity() > 0)
+ {
+ PlayerInfo::dropItem(item, cnt, Sfx_true);
+ return true;
+ }
+ }
+ if (mLastDropIndex >= DROP_SHORTCUT_ITEMS)
+ mLastDropIndex = 0;
+ }
+ return false;
+}
diff --git a/src/gui/shortcut/dropshortcut.h b/src/gui/shortcut/dropshortcut.h
new file mode 100644
index 000000000..5fc84623c
--- /dev/null
+++ b/src/gui/shortcut/dropshortcut.h
@@ -0,0 +1,69 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 Andrei Karas
+ * Copyright (C) 2011-2015 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GUI_SHORTCUT_DROPSHORTCUT_H
+#define GUI_SHORTCUT_DROPSHORTCUT_H
+
+#include "gui/shortcut/shortcutbase.h"
+
+#include "localconsts.h"
+
+/**
+ * The class which keeps track of the item shortcuts.
+ */
+class DropShortcut final : public ShortcutBase
+{
+ public:
+ /**
+ * Constructor.
+ */
+ DropShortcut();
+
+ A_DELETE_COPY(DropShortcut)
+
+ /**
+ * Destructor.
+ */
+ ~DropShortcut();
+
+ /**
+ * Drop first item.
+ */
+ void dropFirst() const;
+
+ /**
+ * Drop all items in cicle.
+ */
+ void dropItems(const int cnt = 1);
+
+ private:
+ /**
+ * Drop item in cicle.
+ */
+ bool dropItem(const int cnt = 1);
+
+ int mLastDropIndex;
+};
+
+extern DropShortcut *dropShortcut;
+
+#endif // GUI_SHORTCUT_DROPSHORTCUT_H
diff --git a/src/gui/shortcut/emoteshortcut.cpp b/src/gui/shortcut/emoteshortcut.cpp
new file mode 100644
index 000000000..03361f3f2
--- /dev/null
+++ b/src/gui/shortcut/emoteshortcut.cpp
@@ -0,0 +1,84 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2009 Aethyra Development Team
+ * Copyright (C) 2011-2015 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "gui/shortcut/emoteshortcut.h"
+
+#include "configuration.h"
+
+#include "being/localplayer.h"
+
+#include "resources/db/emotedb.h"
+
+#include "debug.h"
+
+EmoteShortcut *emoteShortcut = nullptr;
+
+EmoteShortcut::EmoteShortcut() :
+ mEmoteSelected(0)
+{
+ for (int i = 0; i < SHORTCUT_EMOTES; i++)
+ mEmotes[i] = 0;
+}
+
+EmoteShortcut::~EmoteShortcut()
+{
+ save();
+}
+
+void EmoteShortcut::load()
+{
+ for (unsigned char i = 0, j = 0,
+ sz = static_cast<unsigned char>(EmoteDB::getLast());
+ i <= sz && j < SHORTCUT_EMOTES;
+ i++)
+ {
+ const EmoteSprite *const sprite = EmoteDB::getSprite(i, true);
+ if (sprite)
+ {
+ mEmotes[j] = static_cast<unsigned char>(i + 1);
+ j ++;
+ }
+ }
+}
+
+void EmoteShortcut::save() const
+{
+ for (int i = 0; i < SHORTCUT_EMOTES; i++)
+ {
+ const unsigned char emoteId = mEmotes[i] ? mEmotes[i]
+ : static_cast<unsigned char>(0);
+ serverConfig.setValue("emoteshortcut" + toString(i),
+ static_cast<unsigned int>(emoteId));
+ }
+}
+
+void EmoteShortcut::useEmote(const int index) const
+{
+ if (!localPlayer)
+ return;
+
+ if (index > 0 &&
+ index <= SHORTCUT_EMOTES)
+ {
+ if (mEmotes[index - 1] > 0)
+ localPlayer->emote(mEmotes[index - 1]);
+ }
+}
diff --git a/src/gui/shortcut/emoteshortcut.h b/src/gui/shortcut/emoteshortcut.h
new file mode 100644
index 000000000..bd4eed7f1
--- /dev/null
+++ b/src/gui/shortcut/emoteshortcut.h
@@ -0,0 +1,128 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2009 Aethyra Development Team
+ * Copyright (C) 2011-2015 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GUI_SHORTCUT_EMOTESHORTCUT_H
+#define GUI_SHORTCUT_EMOTESHORTCUT_H
+
+#include "const/emoteshortcut.h"
+
+#include "localconsts.h"
+
+/**
+ * The class which keeps track of the emote shortcuts.
+ */
+class EmoteShortcut final
+{
+ public:
+ /**
+ * Constructor.
+ */
+ EmoteShortcut();
+
+ A_DELETE_COPY(EmoteShortcut)
+
+ /**
+ * Destructor.
+ */
+ ~EmoteShortcut();
+
+ /**
+ * Load the configuration information.
+ */
+ void load();
+
+ /**
+ * Returns the shortcut Emote ID specified by the index.
+ *
+ * @param index Index of the shortcut Emote.
+ */
+ unsigned char getEmote(const int index) const A_WARN_UNUSED
+ { return mEmotes[index]; }
+
+ /**
+ * Returns the amount of shortcut Emotes.
+ */
+ static unsigned int getEmoteCount() A_WARN_UNUSED
+ { return SHORTCUT_EMOTES; }
+
+ /**
+ * Returns the emote ID that is currently selected.
+ */
+ unsigned char getEmoteSelected() const A_WARN_UNUSED
+ { return mEmoteSelected; }
+
+ /**
+ * Adds the selected emote ID to the emotes specified by the index.
+ *
+ * @param index Index of the emotes.
+ */
+ void setEmote(const int index)
+ { mEmotes[index] = mEmoteSelected; }
+
+ /**
+ * Adds a emoticon to the emotes store specified by the index.
+ *
+ * @param index Index of the emote.
+ * @param emoteId ID of the emote.
+ */
+ void setEmotes(const int index, const unsigned char emoteId)
+ { mEmotes[index] = emoteId; }
+
+ /**
+ * Set the Emote that is selected.
+ *
+ * @param emoteId The ID of the emote that is to be assigned.
+ */
+ void setEmoteSelected(const unsigned char emoteId)
+ { mEmoteSelected = emoteId; }
+
+ /**
+ * A flag to check if the Emote is selected.
+ */
+ bool isEmoteSelected() const A_WARN_UNUSED
+ { return mEmoteSelected; }
+
+ /**
+ * Remove a Emote from the shortcut.
+ */
+ void removeEmote(const int index)
+ { if (index >= 0 && index < SHORTCUT_EMOTES) mEmotes[index] = 0; }
+
+ /**
+ * Try to use the Emote specified by the index.
+ *
+ * @param index Index of the emote shortcut.
+ */
+ void useEmote(const int index) const;
+
+ private:
+ /**
+ * Save the configuration information.
+ */
+ void save() const;
+
+ unsigned char mEmotes[SHORTCUT_EMOTES]; // The emote stored.
+ unsigned char mEmoteSelected; // The emote held by cursor.
+};
+
+extern EmoteShortcut *emoteShortcut;
+
+#endif // GUI_SHORTCUT_EMOTESHORTCUT_H
diff --git a/src/gui/shortcut/itemshortcut.cpp b/src/gui/shortcut/itemshortcut.cpp
new file mode 100644
index 000000000..7d6aec8f1
--- /dev/null
+++ b/src/gui/shortcut/itemshortcut.cpp
@@ -0,0 +1,240 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2007-2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 The Mana Developers
+ * Copyright (C) 2011-2015 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "gui/shortcut/itemshortcut.h"
+
+#include "configuration.h"
+#include "inventory.h"
+#include "item.h"
+#include "spellmanager.h"
+
+#include "being/playerinfo.h"
+
+#include "const/spells.h"
+
+#include "gui/windows/skilldialog.h"
+
+#include "const/resources/skill.h"
+
+#include "debug.h"
+
+ItemShortcut *itemShortcut[SHORTCUT_TABS];
+
+ItemShortcut::ItemShortcut(const int number) :
+ mItemSelected(-1),
+ mItemColorSelected(ItemColor_one),
+ mNumber(number)
+{
+ load();
+}
+
+ItemShortcut::~ItemShortcut()
+{
+ logger->log1("ItemShortcut::~ItemShortcut");
+}
+
+void ItemShortcut::load(const bool oldConfig)
+{
+ std::string name;
+ std::string color;
+ const Configuration *cfg;
+ if (oldConfig)
+ cfg = &config;
+ else
+ cfg = &serverConfig;
+
+ if (mNumber)
+ {
+ name = std::string("shortcut").append(toString(mNumber)).append("_");
+ color = std::string("shortcutColor").append(
+ toString(mNumber)).append("_");
+ }
+ else
+ {
+ name = "shortcut";
+ color = "shortcutColor";
+ }
+ for (unsigned int i = 0; i < SHORTCUT_ITEMS; i++)
+ {
+ const int itemId = cfg->getValue(name + toString(i), -1);
+ const ItemColor itemColor = fromInt(
+ cfg->getValue(color + toString(i), 1),
+ ItemColor);
+
+ mItems[i] = itemId;
+ mItemColors[i] = itemColor;
+ }
+}
+
+void ItemShortcut::save() const
+{
+ std::string name;
+ std::string color;
+ if (mNumber)
+ {
+ name = std::string("shortcut").append(toString(mNumber)).append("_");
+ color = std::string("shortcutColor").append(
+ toString(mNumber)).append("_");
+ }
+ else
+ {
+ name = "shortcut";
+ color = "shortcutColor";
+ }
+
+ logger->log("save %s", name.c_str());
+
+ for (unsigned int i = 0; i < SHORTCUT_ITEMS; i++)
+ {
+ const int itemId = mItems[i] ? mItems[i] : -1;
+ const int itemColor = (mItemColors[i] != ItemColor_zero) ?
+ toInt(mItemColors[i], int) : 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));
+ }
+ }
+}
+
+void ItemShortcut::useItem(const int index) const
+{
+ const Inventory *const inv = PlayerInfo::getInventory();
+ if (!inv)
+ return;
+
+ const int itemId = mItems[index];
+ const ItemColor itemColor = mItemColors[index];
+ if (itemId >= 0)
+ {
+ if (itemId < SPELL_MIN_ID)
+ {
+ const Item *const item = inv->findItem(itemId, itemColor);
+ if (item && item->getQuantity())
+ PlayerInfo::useEquipItem(item, Sfx_true);
+ }
+ else if (itemId < SKILL_MIN_ID && spellManager)
+ {
+ spellManager->useItem(itemId);
+ }
+ else if (skillDialog)
+ {
+ skillDialog->useItem(itemId,
+ fromBool(config.getBoolValue("skillAutotarget"), AutoTarget),
+ toInt(itemColor, int));
+ }
+ }
+}
+
+void ItemShortcut::equipItem(const int index) const
+{
+ const Inventory *const inv = PlayerInfo::getInventory();
+ if (!inv)
+ return;
+
+ const int itemId = mItems[index];
+ if (itemId)
+ {
+ const Item *const item = inv->findItem(itemId, mItemColors[index]);
+ if (item && item->getQuantity())
+ {
+ if (item->isEquipment() == Equipm_true)
+ {
+ if (item->isEquipped() == Equipped_false)
+ PlayerInfo::equipItem(item, Sfx_true);
+ }
+ }
+ }
+}
+void ItemShortcut::unequipItem(const int index) const
+{
+ const Inventory *const inv = PlayerInfo::getInventory();
+ if (!inv)
+ return;
+
+ const int itemId = mItems[index];
+ if (itemId)
+ {
+ const Item *const item = inv->findItem(itemId, mItemColors[index]);
+ if (item && item->getQuantity())
+ {
+ if (item->isEquipment() == Equipm_true)
+ {
+ if (item->isEquipped() == Equipped_true)
+ PlayerInfo::unequipItem(item, Sfx_true);
+ }
+ }
+ }
+}
+
+void ItemShortcut::setItemSelected(const Item *const item)
+{
+ if (item)
+ {
+ mItemSelected = item->getId();
+ mItemColorSelected = item->getColor();
+ }
+ else
+ {
+ mItemSelected = -1;
+ mItemColorSelected = ItemColor_one;
+ }
+}
+
+void ItemShortcut::setItem(const int index)
+{
+ mItems[index] = mItemSelected;
+ mItemColors[index] = mItemColorSelected;
+ save();
+}
+
+void ItemShortcut::setItem(const int index,
+ const int item,
+ const ItemColor color)
+{
+ mItems[index] = item;
+ mItemColors[index] = color;
+ save();
+}
+
+void ItemShortcut::swap(const int index1, const int index2)
+{
+ if (index1 < 0 || index2 < 0
+ || static_cast<unsigned int>(index1) >= SHORTCUT_ITEMS
+ || static_cast<unsigned int>(index2) >= SHORTCUT_ITEMS)
+ {
+ return;
+ }
+
+ const int tmpItem = mItems[index1];
+ mItems[index1] = mItems[index2];
+ mItems[index2] = tmpItem;
+ const ItemColor tmpColor = mItemColors[index1];
+ mItemColors[index1] = mItemColors[index2];
+ mItemColors[index2] = tmpColor;
+ save();
+}
diff --git a/src/gui/shortcut/itemshortcut.h b/src/gui/shortcut/itemshortcut.h
new file mode 100644
index 000000000..bb2642c92
--- /dev/null
+++ b/src/gui/shortcut/itemshortcut.h
@@ -0,0 +1,165 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2007-2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 The Mana Developers
+ * Copyright (C) 2011-2015 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GUI_SHORTCUT_ITEMSHORTCUT_H
+#define GUI_SHORTCUT_ITEMSHORTCUT_H
+
+#include "enums/simpletypes/itemcolor.h"
+
+#include "localconsts.h"
+
+const unsigned int SHORTCUT_ITEMS = 20;
+const unsigned int SHORTCUT_TABS = 4;
+
+class Item;
+
+/**
+ * The class which keeps track of the item shortcuts.
+ */
+class ItemShortcut final
+{
+ public:
+ /**
+ * Constructor.
+ */
+ explicit ItemShortcut(const int number);
+
+ A_DELETE_COPY(ItemShortcut)
+
+ /**
+ * Destructor.
+ */
+ ~ItemShortcut();
+
+ /**
+ * Load the configuration information.
+ */
+ void load(const bool oldConfig = false);
+
+ /**
+ * Save the configuration information.
+ */
+ void save() const;
+
+ /**
+ * Returns the shortcut item ID specified by the index.
+ *
+ * @param index Index of the shortcut item.
+ */
+ int getItem(const int index) const A_WARN_UNUSED
+ { return mItems[index]; }
+
+ ItemColor getItemColor(const int index) const A_WARN_UNUSED
+ { return mItemColors[index]; }
+
+ /**
+ * Returns the amount of shortcut items.
+ */
+ static int getItemCount() A_WARN_UNUSED
+ { return SHORTCUT_ITEMS; }
+
+ /**
+ * Returns the item ID that is currently selected.
+ */
+ int getItemSelected() const A_WARN_UNUSED
+ { return mItemSelected; }
+
+ /**
+ * Adds the selected item ID to the items specified by the index.
+ *
+ * @param index Index of the items.
+ */
+ void setItem(const int index);
+
+ void setItem(const int index,
+ const int item,
+ const ItemColor color);
+
+ /**
+ * Adds an item to the items store specified by the index.
+ *
+ * @param index Index of the item.
+ * @param itemId ID of the item.
+ */
+ void setItems(const int index,
+ const int itemId,
+ const ItemColor color)
+ { mItems[index] = itemId; mItemColors[index] = color; save(); }
+
+ /**
+ * Set the item that is selected.
+ *
+ * @param itemId The ID of the item that is to be assigned.
+ */
+ void setItemSelected(const int itemId)
+ { mItemSelected = itemId; }
+
+ void setItemSelected(const Item *const item);
+
+ /**
+ * Returns selected shortcut item ID.
+ */
+ int getSelectedItem() const A_WARN_UNUSED
+ { return mItemSelected; }
+
+ /**
+ * A flag to check if the item is selected.
+ */
+ bool isItemSelected() const A_WARN_UNUSED
+ { return mItemSelected > -1; }
+
+ /**
+ * Remove a item from the shortcut.
+ */
+ void removeItem(const int index)
+ { mItems[index] = -1; save(); }
+
+ /**
+ * Try to use the item specified by the index.
+ *
+ * @param index Index of the item shortcut.
+ */
+ void useItem(const int index) const;
+
+ /**
+ * Equip a item from the shortcut.
+ */
+ void equipItem(const int index) const;
+
+ /**
+ * UnEquip a item from the shortcut.
+ */
+ void unequipItem(const int index) const;
+
+ void swap(const int index1, const int index2);
+
+ private:
+ int mItems[SHORTCUT_ITEMS]; /**< The items. */
+ ItemColor mItemColors[SHORTCUT_ITEMS]; /**< The item colors. */
+ int mItemSelected;
+ ItemColor mItemColorSelected;
+ int mNumber;
+};
+
+extern ItemShortcut *itemShortcut[SHORTCUT_TABS];
+
+#endif // GUI_SHORTCUT_ITEMSHORTCUT_H
diff --git a/src/gui/shortcut/shortcutbase.cpp b/src/gui/shortcut/shortcutbase.cpp
new file mode 100644
index 000000000..99eb492f1
--- /dev/null
+++ b/src/gui/shortcut/shortcutbase.cpp
@@ -0,0 +1,129 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 Andrei Karas
+ * Copyright (C) 2011-2015 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "gui/shortcut/shortcutbase.h"
+
+#include "configuration.h"
+#include "item.h"
+
+#include "debug.h"
+
+ShortcutBase::ShortcutBase(const std::string &itemName,
+ const std::string &colorName,
+ const int maxSize) :
+ mItems(new int[maxSize]),
+ mItemColors(new ItemColor[maxSize]),
+ mItemName(itemName),
+ mColorName(colorName),
+ mItemSelected(-1),
+ mMaxSize(maxSize),
+ mItemColorSelected(ItemColor_one)
+{
+ clear(false);
+ load();
+}
+
+ShortcutBase::~ShortcutBase()
+{
+ delete [] mItems;
+ mItems = nullptr;
+ delete [] mItemColors;
+ mItemColors = nullptr;
+}
+
+void ShortcutBase::load(const bool oldConfig)
+{
+ const Configuration *cfg;
+ if (oldConfig)
+ cfg = &config;
+ else
+ cfg = &serverConfig;
+
+ for (int i = 0; i < mMaxSize; i++)
+ {
+ const int itemId = cfg->getValue(mItemName + toString(i), -1);
+ const ItemColor itemColor = fromInt(
+ cfg->getValue(mColorName + toString(i), -1),
+ ItemColor);
+
+ if (itemId != -1)
+ {
+ mItems[i] = itemId;
+ mItemColors[i] = itemColor;
+ }
+ }
+}
+
+void ShortcutBase::save() const
+{
+ for (int i = 0; i < mMaxSize; i++)
+ {
+ const int itemId = mItems[i] ? mItems[i] : -1;
+ const int itemColor = (mItemColors[i] != ItemColor_zero)
+ ? toInt(mItemColors[i], int) : 1;
+ if (itemId != -1)
+ {
+ serverConfig.setValue(mItemName + toString(i), itemId);
+ serverConfig.setValue(mColorName + toString(i), itemColor);
+ }
+ else
+ {
+ serverConfig.deleteKey(mItemName + toString(i));
+ serverConfig.deleteKey(mColorName + toString(i));
+ }
+ }
+}
+
+void ShortcutBase::setItemSelected(const Item *const item)
+{
+ if (item)
+ {
+ mItemSelected = item->getId();
+ mItemColorSelected = item->getColor();
+ }
+ else
+ {
+ mItemSelected = -1;
+ mItemColorSelected = ItemColor_one;
+ }
+}
+
+void ShortcutBase::setItem(const int index)
+{
+ if (index < 0 || index >= mMaxSize)
+ return;
+
+ mItems[index] = mItemSelected;
+ mItemColors[index] = mItemColorSelected;
+ save();
+}
+
+void ShortcutBase::clear(const bool isSave)
+{
+ for (int i = 0; i < mMaxSize; i++)
+ {
+ mItems[i] = -1;
+ mItemColors[i] = ItemColor_one;
+ }
+ if (isSave)
+ save();
+}
diff --git a/src/gui/shortcut/shortcutbase.h b/src/gui/shortcut/shortcutbase.h
new file mode 100644
index 000000000..6b4691811
--- /dev/null
+++ b/src/gui/shortcut/shortcutbase.h
@@ -0,0 +1,139 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 Andrei Karas
+ * Copyright (C) 2011-2015 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GUI_SHORTCUT_SHORTCUTBASE_H
+#define GUI_SHORTCUT_SHORTCUTBASE_H
+
+#include "enums/simpletypes/itemcolor.h"
+
+#include <string>
+
+#include "localconsts.h"
+
+class Item;
+
+/**
+ * The class which keeps track of the item shortcuts.
+ */
+class ShortcutBase notfinal
+{
+ public:
+ /**
+ * Constructor.
+ */
+ ShortcutBase(const std::string &itemName,
+ const std::string &colorName,
+ const int maxSize);
+
+ A_DELETE_COPY(ShortcutBase)
+
+ /**
+ * Destructor.
+ */
+ virtual ~ShortcutBase();
+
+ /**
+ * Load the configuration information.
+ */
+ void load(const bool oldConfig = false);
+
+ /**
+ * Save the configuration information.
+ */
+ void save() const;
+
+ /**
+ * Returns the shortcut item ID specified by the index.
+ *
+ * @param index Index of the shortcut item.
+ */
+ int getItem(const int index) const A_WARN_UNUSED
+ { return mItems[index]; }
+
+ ItemColor getItemColor(const int index) const A_WARN_UNUSED
+ { return mItemColors[index]; }
+
+ /**
+ * Returns the amount of shortcut items.
+ */
+ int getItemCount() const A_WARN_UNUSED
+ { return mMaxSize; }
+
+ /**
+ * Returns the item ID that is currently selected.
+ */
+ int getItemSelected() const A_WARN_UNUSED
+ { return mItemSelected; }
+
+ /**
+ * Adds the selected item ID to the items specified by the index.
+ *
+ * @param index Index of the items.
+ */
+ void setItem(const int index);
+
+ /**
+ * Adds an item to the items store specified by the index.
+ *
+ * @param index Index of the item.
+ * @param itemId ID of the item.
+ */
+ void setItems(const int index,
+ const int itemId,
+ const ItemColor color)
+ { mItems[index] = itemId; mItemColors[index] = color; save(); }
+
+ /**
+ * Set the item that is selected.
+ *
+ * @param itemId The ID of the item that is to be assigned.
+ */
+ void setItemSelected(const int itemId)
+ { mItemSelected = itemId; }
+
+ void setItemSelected(const Item *const item);
+
+ /**
+ * A flag to check if the item is selected.
+ */
+ bool isItemSelected() const A_WARN_UNUSED
+ { return mItemSelected > -1; }
+
+ /**
+ * Remove a item from the shortcut.
+ */
+ void removeItem(const int index)
+ { mItems[index] = -1; save(); }
+
+ void clear(const bool isSave = true);
+
+ private:
+ int *mItems A_NONNULLPOINTER;
+ ItemColor *mItemColors A_NONNULLPOINTER;
+ std::string mItemName;
+ std::string mColorName;
+ int mItemSelected;
+ int mMaxSize;
+ ItemColor mItemColorSelected;
+};
+
+#endif // GUI_SHORTCUT_SHORTCUTBASE_H
diff --git a/src/gui/shortcut/spellshortcut.cpp b/src/gui/shortcut/spellshortcut.cpp
new file mode 100644
index 000000000..609b7e335
--- /dev/null
+++ b/src/gui/shortcut/spellshortcut.cpp
@@ -0,0 +1,62 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 Andrei Karas
+ * Copyright (C) 2011-2015 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "gui/shortcut/spellshortcut.h"
+
+#include "spellmanager.h"
+
+#include "debug.h"
+
+SpellShortcut *spellShortcut = nullptr;
+
+SpellShortcut::SpellShortcut() :
+ mItemSelected(-1)
+{
+ load();
+}
+
+SpellShortcut::~SpellShortcut()
+{
+}
+
+void SpellShortcut::load()
+{
+ for (unsigned f = 0; f < SPELLS_SIZE; f ++)
+ mItems[f] = -1;
+
+ if (!spellManager)
+ return;
+
+ const std::vector<TextCommand*> &spells = spellManager->getAll();
+ unsigned k = 0;
+
+ for (std::vector<TextCommand*>::const_iterator i = spells.begin(),
+ i_end = spells.end(); i != i_end && k < SPELLS_SIZE; ++i)
+ {
+ mItems[k++] = (*i)->getId();
+ }
+}
+
+unsigned int SpellShortcut::getSpellsCount() const
+{
+ return SPELL_SHORTCUT_ITEMS;
+}
diff --git a/src/gui/shortcut/spellshortcut.h b/src/gui/shortcut/spellshortcut.h
new file mode 100644
index 000000000..694bf5fac
--- /dev/null
+++ b/src/gui/shortcut/spellshortcut.h
@@ -0,0 +1,88 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 Andrei Karas
+ * Copyright (C) 2011-2015 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GUI_SHORTCUT_SPELLSHORTCUT_H
+#define GUI_SHORTCUT_SPELLSHORTCUT_H
+
+#include "const/spells.h"
+
+/**
+ * The class which keeps track of the item shortcuts.
+ */
+class SpellShortcut final
+{
+ public:
+ /**
+ * Constructor.
+ */
+ SpellShortcut();
+
+ A_DELETE_COPY(SpellShortcut)
+
+ /**
+ * Destructor.
+ */
+ ~SpellShortcut();
+
+ /**
+ * Load the configuration information.
+ */
+ void load();
+
+ unsigned int getSpellsCount() const A_WARN_UNUSED;
+
+ /**
+ * Set the item that is selected.
+ *
+ * @param itemId The ID of the item that is to be assigned.
+ */
+ void setItemSelected(const int itemId)
+ { mItemSelected = itemId; }
+
+ /**
+ * A flag to check if the item is selected.
+ */
+ bool isItemSelected() const A_WARN_UNUSED
+ { return mItemSelected > -1; }
+
+ /**
+ * Returns selected shortcut item ID.
+ */
+ int getSelectedItem() const A_WARN_UNUSED
+ { return mItemSelected; }
+
+ /**
+ * Returns the shortcut item ID specified by the index.
+ *
+ * @param index Index of the shortcut item.
+ */
+ int getItem(const int index) const
+ { return mItems[index]; }
+
+ private:
+ int mItems[SPELLS_SIZE];
+ int mItemSelected; /**< The item held by cursor. */
+};
+
+extern SpellShortcut *spellShortcut;
+
+#endif // GUI_SHORTCUT_SPELLSHORTCUT_H
diff --git a/src/gui/widgets/emoteshortcutcontainer.cpp b/src/gui/widgets/emoteshortcutcontainer.cpp
index e83e91bb8..455a657b5 100644
--- a/src/gui/widgets/emoteshortcutcontainer.cpp
+++ b/src/gui/widgets/emoteshortcutcontainer.cpp
@@ -21,7 +21,6 @@
#include "gui/widgets/emoteshortcutcontainer.h"
-#include "emoteshortcut.h"
#include "settings.h"
#include "input/inputmanager.h"
@@ -30,6 +29,8 @@
#include "gui/fonts/font.h"
+#include "gui/shortcut/emoteshortcut.h"
+
#include "gui/popups/textpopup.h"
#include "input/inputactionoperators.h"
diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp
index e17cb711e..8a5e6bca3 100644
--- a/src/gui/widgets/itemcontainer.cpp
+++ b/src/gui/widgets/itemcontainer.cpp
@@ -24,7 +24,6 @@
#include "dragdrop.h"
#include "graphicsvertexes.h"
-#include "itemshortcut.h"
#include "being/playerinfo.h"
@@ -34,6 +33,8 @@
#include "gui/fonts/font.h"
+#include "gui/shortcut/itemshortcut.h"
+
#include "gui/popups/itempopup.h"
#include "gui/windows/chatwindow.h"
diff --git a/src/gui/widgets/itemshortcutcontainer.cpp b/src/gui/widgets/itemshortcutcontainer.cpp
index 4659f4afd..b8fd02217 100644
--- a/src/gui/widgets/itemshortcutcontainer.cpp
+++ b/src/gui/widgets/itemshortcutcontainer.cpp
@@ -23,10 +23,8 @@
#include "gui/widgets/itemshortcutcontainer.h"
#include "dragdrop.h"
-#include "itemshortcut.h"
#include "settings.h"
#include "spellmanager.h"
-#include "spellshortcut.h"
#include "being/playerinfo.h"
@@ -36,6 +34,9 @@
#include "gui/fonts/font.h"
+#include "gui/shortcut/itemshortcut.h"
+#include "gui/shortcut/spellshortcut.h"
+
#include "gui/popups/itempopup.h"
#include "gui/popups/popupmenu.h"
#include "gui/popups/skillpopup.h"
diff --git a/src/gui/widgets/spellshortcutcontainer.cpp b/src/gui/widgets/spellshortcutcontainer.cpp
index 1d1b15836..7f1ca47fa 100644
--- a/src/gui/widgets/spellshortcutcontainer.cpp
+++ b/src/gui/widgets/spellshortcutcontainer.cpp
@@ -23,15 +23,16 @@
#include "gui/widgets/spellshortcutcontainer.h"
#include "dragdrop.h"
-#include "itemshortcut.h"
#include "settings.h"
#include "spellmanager.h"
-#include "spellshortcut.h"
#include "gui/viewport.h"
#include "gui/fonts/font.h"
+#include "gui/shortcut/itemshortcut.h"
+#include "gui/shortcut/spellshortcut.h"
+
#include "gui/popups/popupmenu.h"
#include "gui/popups/spellpopup.h"
diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp
index 497f17d2f..36315af34 100644
--- a/src/gui/widgets/textfield.cpp
+++ b/src/gui/widgets/textfield.cpp
@@ -287,6 +287,8 @@ int TextField::getValue() const
void TextField::keyPressed(KeyEvent &event)
{
const int val = event.getKey().getValue();
+ logger->log("TextField::keyPressed %d", val);
+
#ifdef USE_SDL2
if (val == Key::TEXTINPUT)
{
diff --git a/src/gui/widgets/virtshortcutcontainer.cpp b/src/gui/widgets/virtshortcutcontainer.cpp
index 5a8a0432d..43fed340a 100644
--- a/src/gui/widgets/virtshortcutcontainer.cpp
+++ b/src/gui/widgets/virtshortcutcontainer.cpp
@@ -23,7 +23,6 @@
#include "gui/widgets/virtshortcutcontainer.h"
#include "dragdrop.h"
-#include "shortcutbase.h"
#include "settings.h"
#include "being/playerinfo.h"
@@ -32,6 +31,8 @@
#include "gui/fonts/font.h"
+#include "gui/shortcut/shortcutbase.h"
+
#include "gui/popups/itempopup.h"
#include "gui/popups/popupmenu.h"
diff --git a/src/gui/windowmanager.cpp b/src/gui/windowmanager.cpp
index 1959ac4a1..49c0b859e 100644
--- a/src/gui/windowmanager.cpp
+++ b/src/gui/windowmanager.cpp
@@ -27,12 +27,13 @@
#include "game.h"
#include "settings.h"
#include "spellmanager.h"
-#include "spellshortcut.h"
#include "touchmanager.h"
#include "gui/gui.h"
#include "gui/userpalette.h"
+#include "gui/shortcut/spellshortcut.h"
+
#include "gui/popups/textpopup.h"
#ifndef DYECMD
diff --git a/src/gui/windows/skilldialog.cpp b/src/gui/windows/skilldialog.cpp
index 0446bc886..5db995e9d 100644
--- a/src/gui/windows/skilldialog.cpp
+++ b/src/gui/windows/skilldialog.cpp
@@ -24,7 +24,6 @@
#include "configuration.h"
#include "effectmanager.h"
-#include "itemshortcut.h"
#include "spellmanager.h"
#include "being/localplayer.h"
@@ -32,6 +31,8 @@
#include "const/resources/spriteaction.h"
+#include "gui/shortcut/itemshortcut.h"
+
#include "gui/windows/setupwindow.h"
#include "gui/windows/shortcutwindow.h"