From e576b8a204e2c8be2733acd121d036ab14a70646 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 20 Dec 2015 23:57:32 +0300 Subject: Move shortcuts files into gui/shortcut directory. --- src/CMakeLists.txt | 20 +-- src/Makefile.am | 20 +-- src/actions/actions.cpp | 7 +- src/actions/commands.cpp | 7 +- src/actions/pets.cpp | 3 +- src/being/crazymoves.cpp | 3 +- src/client.cpp | 9 +- src/dropshortcut.cpp | 169 -------------------- src/dropshortcut.h | 69 --------- src/emoteshortcut.cpp | 84 ---------- src/emoteshortcut.h | 128 --------------- src/game.cpp | 7 +- src/gui/shortcut/dropshortcut.cpp | 169 ++++++++++++++++++++ src/gui/shortcut/dropshortcut.h | 69 +++++++++ src/gui/shortcut/emoteshortcut.cpp | 84 ++++++++++ src/gui/shortcut/emoteshortcut.h | 128 +++++++++++++++ src/gui/shortcut/itemshortcut.cpp | 240 +++++++++++++++++++++++++++++ src/gui/shortcut/itemshortcut.h | 165 ++++++++++++++++++++ src/gui/shortcut/shortcutbase.cpp | 129 ++++++++++++++++ src/gui/shortcut/shortcutbase.h | 139 +++++++++++++++++ src/gui/shortcut/spellshortcut.cpp | 62 ++++++++ src/gui/shortcut/spellshortcut.h | 88 +++++++++++ src/gui/widgets/emoteshortcutcontainer.cpp | 3 +- src/gui/widgets/itemcontainer.cpp | 3 +- src/gui/widgets/itemshortcutcontainer.cpp | 5 +- src/gui/widgets/spellshortcutcontainer.cpp | 5 +- src/gui/widgets/textfield.cpp | 2 + src/gui/widgets/virtshortcutcontainer.cpp | 3 +- src/gui/windowmanager.cpp | 3 +- src/gui/windows/skilldialog.cpp | 3 +- src/itemshortcut.cpp | 240 ----------------------------- src/itemshortcut.h | 165 -------------------- src/shortcutbase.cpp | 129 ---------------- src/shortcutbase.h | 139 ----------------- src/spellshortcut.cpp | 62 -------- src/spellshortcut.h | 88 ----------- 36 files changed, 1332 insertions(+), 1317 deletions(-) delete mode 100644 src/dropshortcut.cpp delete mode 100644 src/dropshortcut.h delete mode 100644 src/emoteshortcut.cpp delete mode 100644 src/emoteshortcut.h create mode 100644 src/gui/shortcut/dropshortcut.cpp create mode 100644 src/gui/shortcut/dropshortcut.h create mode 100644 src/gui/shortcut/emoteshortcut.cpp create mode 100644 src/gui/shortcut/emoteshortcut.h create mode 100644 src/gui/shortcut/itemshortcut.cpp create mode 100644 src/gui/shortcut/itemshortcut.h create mode 100644 src/gui/shortcut/shortcutbase.cpp create mode 100644 src/gui/shortcut/shortcutbase.h create mode 100644 src/gui/shortcut/spellshortcut.cpp create mode 100644 src/gui/shortcut/spellshortcut.h delete mode 100644 src/itemshortcut.cpp delete mode 100644 src/itemshortcut.h delete mode 100644 src/shortcutbase.cpp delete mode 100644 src/shortcutbase.h delete mode 100644 src/spellshortcut.cpp delete mode 100644 src/spellshortcut.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fb2429bec..dcc88442a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -910,8 +910,8 @@ SET(SRCS dragdrop.h effectmanager.cpp effectmanager.h - emoteshortcut.cpp - emoteshortcut.h + gui/shortcut/emoteshortcut.cpp + gui/shortcut/emoteshortcut.h const/emoteshortcut.h equipment.h eventsmanager.cpp @@ -952,14 +952,14 @@ SET(SRCS item.h itemcolormanager.cpp itemcolormanager.h - itemshortcut.cpp - itemshortcut.h + gui/shortcut/itemshortcut.cpp + gui/shortcut/itemshortcut.h itemsoundmanager.cpp itemsoundmanager.h - dropshortcut.cpp - dropshortcut.h - spellshortcut.cpp - spellshortcut.h + gui/shortcut/dropshortcut.cpp + gui/shortcut/dropshortcut.h + gui/shortcut/spellshortcut.cpp + gui/shortcut/spellshortcut.h textcommand.cpp textcommand.h enums/input/inputaction.h @@ -1119,8 +1119,8 @@ SET(SRCS settings.h shopitem.cpp shopitem.h - shortcutbase.cpp - shortcutbase.h + gui/shortcut/shortcutbase.cpp + gui/shortcut/shortcutbase.h simpleanimation.cpp simpleanimation.h const/sound.h diff --git a/src/Makefile.am b/src/Makefile.am index 0f89cf44d..f26e6332f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -716,8 +716,8 @@ manaplus_SOURCES += main.cpp \ item.h \ itemcolormanager.cpp \ itemcolormanager.h \ - itemshortcut.cpp \ - itemshortcut.h \ + gui/shortcut/itemshortcut.cpp \ + gui/shortcut/itemshortcut.h \ itemsoundmanager.cpp \ itemsoundmanager.h \ enums/commandtarget.h \ @@ -725,8 +725,8 @@ manaplus_SOURCES += main.cpp \ enums/equipslot.h \ enums/guildpositionflags.h \ enums/inventorytype.h \ - spellshortcut.cpp \ - spellshortcut.h \ + gui/shortcut/spellshortcut.cpp \ + gui/shortcut/spellshortcut.h \ statuseffect.cpp \ statuseffect.h \ units.cpp \ @@ -770,8 +770,8 @@ manaplus_SOURCES += main.cpp \ catch.hpp \ chatlogger.cpp \ chatlogger.h \ - shortcutbase.cpp \ - shortcutbase.h \ + gui/shortcut/shortcutbase.cpp \ + gui/shortcut/shortcutbase.h \ being/playerinfo.cpp \ being/playerinfo.h \ being/playerrelation.cpp \ @@ -796,12 +796,12 @@ manaplus_SOURCES += main.cpp \ enums/being/attributes.h \ enums/being/badgeindex.h \ dragdrop.h \ - dropshortcut.cpp \ - dropshortcut.h \ + gui/shortcut/dropshortcut.cpp \ + gui/shortcut/dropshortcut.h \ effectmanager.cpp \ effectmanager.h \ - emoteshortcut.cpp \ - emoteshortcut.h \ + gui/shortcut/emoteshortcut.cpp \ + gui/shortcut/emoteshortcut.h \ const/emoteshortcut.h \ equipment.h \ listeners/actorspritelistener.h \ diff --git a/src/actions/actions.cpp b/src/actions/actions.cpp index dec8539d3..1c87e1c33 100644 --- a/src/actions/actions.cpp +++ b/src/actions/actions.cpp @@ -22,13 +22,10 @@ #include "actormanager.h" #include "configuration.h" -#include "dropshortcut.h" -#include "emoteshortcut.h" #include "game.h" #ifdef USE_OPENGL #include "graphicsmanager.h" #endif -#include "itemshortcut.h" #include "spellmanager.h" #include "actions/actiondef.h" @@ -43,6 +40,10 @@ #include "gui/sdlinput.h" #include "gui/windowmanager.h" +#include "gui/shortcut/dropshortcut.h" +#include "gui/shortcut/emoteshortcut.h" +#include "gui/shortcut/itemshortcut.h" + #include "gui/popups/popupmenu.h" #include "gui/windows/buydialog.h" diff --git a/src/actions/commands.cpp b/src/actions/commands.cpp index 6f2d49b77..3511e9808 100644 --- a/src/actions/commands.cpp +++ b/src/actions/commands.cpp @@ -22,9 +22,6 @@ #include "actormanager.h" #include "configuration.h" -#ifdef EATHENA_SUPPORT -#include "emoteshortcut.h" -#endif #include "game.h" #include "inventory.h" #include "item.h" @@ -40,6 +37,10 @@ #include "gui/viewport.h" +#ifdef EATHENA_SUPPORT +#include "gui/shortcut/emoteshortcut.h" +#endif + #include "gui/windows/chatwindow.h" #include "gui/windows/skilldialog.h" #include "gui/windows/socialwindow.h" diff --git a/src/actions/pets.cpp b/src/actions/pets.cpp index 826d5ad84..3df0e64d9 100644 --- a/src/actions/pets.cpp +++ b/src/actions/pets.cpp @@ -22,7 +22,6 @@ #include "actormanager.h" #include "game.h" -#include "emoteshortcut.h" #include "actions/actiondef.h" @@ -37,6 +36,8 @@ #include "listeners/inputactionreplaylistener.h" +#include "gui/shortcut/emoteshortcut.h" + #include "net/chathandler.h" #ifdef TMWA_SUPPORT #include "net/net.h" diff --git a/src/being/crazymoves.cpp b/src/being/crazymoves.cpp index 9636e6711..65ef5f52b 100644 --- a/src/being/crazymoves.cpp +++ b/src/being/crazymoves.cpp @@ -21,13 +21,14 @@ #include "being/crazymoves.h" #include "configuration.h" -#include "dropshortcut.h" #include "settings.h" #include "being/localplayer.h" #include "enums/being/beingdirection.h" +#include "gui/shortcut/dropshortcut.h" + #include "gui/windows/outfitwindow.h" #include "net/packetlimiter.h" diff --git a/src/client.cpp b/src/client.cpp index 4f4f5279a..ec5adcfd1 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -25,17 +25,13 @@ #include "chatlogger.h" #include "configmanager.h" #include "dirs.h" -#include "dropshortcut.h" -#include "emoteshortcut.h" #include "eventsmanager.h" #include "game.h" #include "graphicsmanager.h" -#include "itemshortcut.h" #include "party.h" #include "settings.h" #include "soundmanager.h" #include "spellmanager.h" -#include "spellshortcut.h" #include "statuseffect.h" #include "units.h" #include "touchmanager.h" @@ -55,6 +51,11 @@ #include "gui/popupmanager.h" #include "gui/windowmanager.h" +#include "gui/shortcut/dropshortcut.h" +#include "gui/shortcut/emoteshortcut.h" +#include "gui/shortcut/itemshortcut.h" +#include "gui/shortcut/spellshortcut.h" + #include "gui/windows/changeemaildialog.h" #include "gui/windows/changepassworddialog.h" #include "gui/windows/charselectdialog.h" diff --git a/src/dropshortcut.cpp b/src/dropshortcut.cpp deleted file mode 100644 index d112b4796..000000000 --- a/src/dropshortcut.cpp +++ /dev/null @@ -1,169 +0,0 @@ -/* - * 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 . - */ - -#include "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/dropshortcut.h b/src/dropshortcut.h deleted file mode 100644 index 6920ff3aa..000000000 --- a/src/dropshortcut.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * 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 . - */ - -#ifndef DROPSHORTCUT_H -#define DROPSHORTCUT_H - -#include "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 // DROPSHORTCUT_H diff --git a/src/emoteshortcut.cpp b/src/emoteshortcut.cpp deleted file mode 100644 index e60c05cb0..000000000 --- a/src/emoteshortcut.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/* - * 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 . - */ - -#include "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(EmoteDB::getLast()); - i <= sz && j < SHORTCUT_EMOTES; - i++) - { - const EmoteSprite *const sprite = EmoteDB::getSprite(i, true); - if (sprite) - { - mEmotes[j] = static_cast(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(0); - serverConfig.setValue("emoteshortcut" + toString(i), - static_cast(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/emoteshortcut.h b/src/emoteshortcut.h deleted file mode 100644 index 8cd3a7ded..000000000 --- a/src/emoteshortcut.h +++ /dev/null @@ -1,128 +0,0 @@ -/* - * 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 . - */ - -#ifndef EMOTESHORTCUT_H -#define 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 // EMOTESHORTCUT_H diff --git a/src/game.cpp b/src/game.cpp index a6aa8e8cb..1cec9efbd 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -25,12 +25,9 @@ #include "actormanager.h" #include "client.h" #include "configuration.h" -#include "dropshortcut.h" #include "effectmanager.h" -#include "emoteshortcut.h" #include "eventsmanager.h" #include "gamemodifiers.h" -#include "itemshortcut.h" #include "soundmanager.h" #include "settings.h" #include "touchmanager.h" @@ -60,6 +57,10 @@ #include "gui/fonts/font.h" +#include "gui/shortcut/dropshortcut.h" +#include "gui/shortcut/emoteshortcut.h" +#include "gui/shortcut/itemshortcut.h" + #include "gui/popups/popupmenu.h" #ifdef EATHENA_SUPPORT 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 . + */ + +#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 . + */ + +#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 . + */ + +#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(EmoteDB::getLast()); + i <= sz && j < SHORTCUT_EMOTES; + i++) + { + const EmoteSprite *const sprite = EmoteDB::getSprite(i, true); + if (sprite) + { + mEmotes[j] = static_cast(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(0); + serverConfig.setValue("emoteshortcut" + toString(i), + static_cast(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 . + */ + +#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 . + */ + +#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(index1) >= SHORTCUT_ITEMS + || static_cast(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 . + */ + +#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 . + */ + +#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 . + */ + +#ifndef GUI_SHORTCUT_SHORTCUTBASE_H +#define GUI_SHORTCUT_SHORTCUTBASE_H + +#include "enums/simpletypes/itemcolor.h" + +#include + +#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 . + */ + +#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 &spells = spellManager->getAll(); + unsigned k = 0; + + for (std::vector::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 . + */ + +#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" diff --git a/src/itemshortcut.cpp b/src/itemshortcut.cpp deleted file mode 100644 index f1ef56993..000000000 --- a/src/itemshortcut.cpp +++ /dev/null @@ -1,240 +0,0 @@ -/* - * 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 . - */ - -#include "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(index1) >= SHORTCUT_ITEMS - || static_cast(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/itemshortcut.h b/src/itemshortcut.h deleted file mode 100644 index 7dd093abd..000000000 --- a/src/itemshortcut.h +++ /dev/null @@ -1,165 +0,0 @@ -/* - * 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 . - */ - -#ifndef ITEMSHORTCUT_H -#define 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 // ITEMSHORTCUT_H diff --git a/src/shortcutbase.cpp b/src/shortcutbase.cpp deleted file mode 100644 index 8bb0b3a54..000000000 --- a/src/shortcutbase.cpp +++ /dev/null @@ -1,129 +0,0 @@ -/* - * 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 . - */ - -#include "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/shortcutbase.h b/src/shortcutbase.h deleted file mode 100644 index 58520a8ad..000000000 --- a/src/shortcutbase.h +++ /dev/null @@ -1,139 +0,0 @@ -/* - * 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 . - */ - -#ifndef SHORTCUTBASE_H -#define SHORTCUTBASE_H - -#include "enums/simpletypes/itemcolor.h" - -#include - -#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 // SHORTCUTBASE_H diff --git a/src/spellshortcut.cpp b/src/spellshortcut.cpp deleted file mode 100644 index aa4e95248..000000000 --- a/src/spellshortcut.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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 . - */ - -#include "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 &spells = spellManager->getAll(); - unsigned k = 0; - - for (std::vector::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/spellshortcut.h b/src/spellshortcut.h deleted file mode 100644 index 88d2541ef..000000000 --- a/src/spellshortcut.h +++ /dev/null @@ -1,88 +0,0 @@ -/* - * 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 . - */ - -#ifndef SPELLSHORTCUT_H -#define 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 // SPELLSHORTCUT_H -- cgit v1.2.3-70-g09d2