From 26b43e7164214e8c9e5cdb8842a79a4fcc1493da Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 14 Jul 2015 22:42:47 +0300 Subject: Add ability for insert cards into items. --- src/CMakeLists.txt | 2 ++ src/Makefile.am | 2 ++ src/being/playerinfo.cpp | 16 +++++++++ src/gui/windows/insertcarddialog.cpp | 67 ++++++++++++++++++++++++++++++++++++ src/gui/windows/insertcarddialog.h | 51 +++++++++++++++++++++++++++ src/net/eathena/inventoryhandler.cpp | 47 ++++++++++++++++++++----- src/net/eathena/inventoryhandler.h | 8 ++++- src/net/eathena/protocol.h | 2 +- src/net/inventoryhandler.h | 4 ++- src/net/tmwa/inventoryhandler.cpp | 2 +- src/net/tmwa/inventoryhandler.h | 5 ++- 11 files changed, 192 insertions(+), 14 deletions(-) create mode 100644 src/gui/windows/insertcarddialog.cpp create mode 100644 src/gui/windows/insertcarddialog.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1f806a932..b3974bf4b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -368,6 +368,8 @@ SET(SRCS gui/mailmessage.h gui/windows/helpwindow.cpp gui/windows/helpwindow.h + gui/windows/insertcarddialog.cpp + gui/windows/insertcarddialog.h gui/windows/inventorywindow.cpp gui/windows/inventorywindow.h gui/windows/itemamountwindow.cpp diff --git a/src/Makefile.am b/src/Makefile.am index fac1fce70..d1881a254 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1408,6 +1408,8 @@ manaplus_SOURCES += gui/windows/bankwindow.cpp \ gui/windows/buyingstoreselldialog.h \ gui/windows/eggselectiondialog.cpp \ gui/windows/eggselectiondialog.h \ + gui/windows/insertcarddialog.cpp \ + gui/windows/insertcarddialog.h \ gui/windows/maileditwindow.cpp \ gui/windows/maileditwindow.h \ gui/windows/mailviewwindow.cpp \ diff --git a/src/being/playerinfo.cpp b/src/being/playerinfo.cpp index c86200219..8c7b55639 100644 --- a/src/being/playerinfo.cpp +++ b/src/being/playerinfo.cpp @@ -41,6 +41,10 @@ #include "net/mercenaryhandler.h" #include "net/playerhandler.h" +#ifdef EATHENA_SUPPORT +#include "resources/itemtype.h" +#endif + #include "utils/delete2.h" #include "debug.h" @@ -267,6 +271,18 @@ void useEquipItem(const Item *const item, const Sfx sfx) { if (item) { +#ifdef EATHENA_SUPPORT + if (item->getType() == ItemType::CARD) + { + if (mProtectedItems.find(item->getId()) == mProtectedItems.end()) + { + inventoryHandler->useCard(item); + if (sfx == Sfx_true) + ItemSoundManager::playSfx(item, ItemSoundEvent::USECARD); + } + } + else +#endif if (item->isEquipment() == Equipm_true) { if (item->isEquipped() == Equipped_true) diff --git a/src/gui/windows/insertcarddialog.cpp b/src/gui/windows/insertcarddialog.cpp new file mode 100644 index 000000000..d34dcc7c6 --- /dev/null +++ b/src/gui/windows/insertcarddialog.cpp @@ -0,0 +1,67 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-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/windows/insertcarddialog.h" + +#include "shopitem.h" + +#include "gui/models/shopitems.h" + +#include "gui/widgets/button.h" +#include "gui/widgets/shoplistbox.h" + +#include "net/inventoryhandler.h" + +#include "utils/gettext.h" + +#include "debug.h" + +InsertCardDialog::InsertCardDialog(const int itemIndex) : + SellDialog(false), + mItemIndex(itemIndex) +{ + // TRANSLATORS: insert card dialog name + setWindowName(_("Insert card")); + // TRANSLATORS: insert card dialog name + setCaption(_("Insert card")); +} + +void InsertCardDialog::initButtons() +{ + // TRANSLATORS: insert card dialog button + mSellButton->setCaption(_("Insert")); + mSellButton->adjustSize(); + mShopItems->setMergeDuplicates(false); +} + +void InsertCardDialog::sellAction(const ActionEvent &event A_UNUSED) +{ + if (mAmountItems <= 0 || mAmountItems > mMaxItems) + return; + + const int selectedItem = mShopItemList->getSelected(); + const ShopItem *const item = mShopItems->at(selectedItem); + if (!item) + return; + inventoryHandler->insertCard(mItemIndex, item->getInvIndex()); + scheduleDelete(); +} diff --git a/src/gui/windows/insertcarddialog.h b/src/gui/windows/insertcarddialog.h new file mode 100644 index 000000000..938e1b57b --- /dev/null +++ b/src/gui/windows/insertcarddialog.h @@ -0,0 +1,51 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-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_WINDOWS_INSERTCARDDIALOG_H +#define GUI_WINDOWS_INSERTCARDDIALOG_H + +#ifdef EATHENA_SUPPORT + +#include "gui/widgets/selldialog.h" + +class InsertCardDialog final : public SellDialog +{ + public: + /** + * Constructor. + * + * @see Window::Window + */ + InsertCardDialog(const int itemIndex); + + A_DELETE_COPY(InsertCardDialog) + + protected: + void initButtons() override final; + void sellAction(const ActionEvent &event) override final; + + private: + int mItemIndex; +}; + +#endif // EATHENA_SUPPORT +#endif // GUI_WINDOWS_INSERTCARDDIALOG_H diff --git a/src/net/eathena/inventoryhandler.cpp b/src/net/eathena/inventoryhandler.cpp index a2e7c869e..c73425874 100644 --- a/src/net/eathena/inventoryhandler.cpp +++ b/src/net/eathena/inventoryhandler.cpp @@ -30,6 +30,10 @@ #include "enums/resources/notifytypes.h" +#include "gui/widgets/createwidget.h" + +#include "gui/windows/insertcarddialog.h" + #include "listeners/arrowslistener.h" #include "net/eathena/itemflags.h" @@ -72,7 +76,8 @@ Ea::InventoryItems InventoryHandler::mCartItems; InventoryHandler::InventoryHandler() : MessageHandler(), - Ea::InventoryHandler() + Ea::InventoryHandler(), + mItemIndex(0) { static const uint16_t _messages[] = { @@ -93,7 +98,7 @@ InventoryHandler::InventoryHandler() : SMSG_PLAYER_UNEQUIP, SMSG_PLAYER_ARROW_EQUIP, SMSG_PLAYER_ATTACK_RANGE, - SMSG_PLAYER_UNE_CARD, + SMSG_PLAYER_USE_CARD, SMSG_PLAYER_INSERT_CARD, SMSG_PLAYER_ITEM_RENTAL_TIME, SMSG_PLAYER_ITEM_RENTAL_EXPIRED, @@ -200,7 +205,7 @@ void InventoryHandler::handleMessage(Net::MessageIn &msg) processPlayerArrowEquip(msg); break; - case SMSG_PLAYER_UNE_CARD: + case SMSG_PLAYER_USE_CARD: processPlayerUseCard(msg); break; @@ -385,10 +390,15 @@ void InventoryHandler::moveItem2(const int source, } } -void InventoryHandler::useCard(const int index) const +void InventoryHandler::useCard(const Item *const item) { + if (!item) + return; + + mItemIndex = item->getInvIndex(); createOutPacket(CMSG_PLAYER_USE_CARD); - outMsg.writeInt16(static_cast(index + INVENTORY_OFFSET), "index"); + outMsg.writeInt16(static_cast( + mItemIndex + INVENTORY_OFFSET), "index"); } void InventoryHandler::insertCard(const int cardIndex, @@ -783,21 +793,40 @@ void InventoryHandler::processPlayerStorageAdd(Net::MessageIn &msg) void InventoryHandler::processPlayerUseCard(Net::MessageIn &msg) { - UNIMPLIMENTEDPACKET; - // +++ here need show dialog with item selection for card. + SellDialog *const dialog = CREATEWIDGETR(InsertCardDialog, + inventoryHandler->getItemIndex()); + Inventory *const inv = PlayerInfo::getInventory(); + const int count = (msg.readInt16("len") - 4) / 2; for (int f = 0; f < count; f ++) - msg.readInt16("item id"); + { + const int itemIndex = msg.readInt16("item index") - INVENTORY_OFFSET; + const Item *const item = inv->getItem(itemIndex); + if (!item) + continue; + dialog->addItem(item, 0); + } } void InventoryHandler::processPlayerInsertCard(Net::MessageIn &msg) { msg.readInt16("item index"); - msg.readInt16("card index"); + const int cardIndex = msg.readInt16("card index") - INVENTORY_OFFSET; if (msg.readUInt8("flag")) + { NotifyManager::notify(NotifyTypes::CARD_INSERT_FAILED); + } else + { NotifyManager::notify(NotifyTypes::CARD_INSERT_SUCCESS); + Inventory *const inv = PlayerInfo::getInventory(); + Item *const item = inv->getItem(cardIndex); + if (!item) + return; + item->increaseQuantity(-1); + if (item->getQuantity() == 0) + inv->removeItemAt(cardIndex); + } } void InventoryHandler::selectEgg(const Item *const item) const diff --git a/src/net/eathena/inventoryhandler.h b/src/net/eathena/inventoryhandler.h index 6497c2e9b..c593a2c67 100644 --- a/src/net/eathena/inventoryhandler.h +++ b/src/net/eathena/inventoryhandler.h @@ -58,7 +58,7 @@ class InventoryHandler final : public MessageHandler, const int amount, const int destination) const override final; - void useCard(const int index) const override final; + void useCard(const Item *const item) override final; void insertCard(const int cardIndex, const int itemIndex) const override final; @@ -74,6 +74,9 @@ class InventoryHandler final : public MessageHandler, int getProjectileSlot() const override final { return 23; } + int getItemIndex() const override final A_WARN_UNUSED + { return mItemIndex; } + protected: static void processPlayerEquipment(Net::MessageIn &msg); @@ -142,6 +145,9 @@ class InventoryHandler final : public MessageHandler, static void processBindItem(Net::MessageIn &msg); static Ea::InventoryItems mCartItems; + + private: + int mItemIndex; }; } // namespace EAthena diff --git a/src/net/eathena/protocol.h b/src/net/eathena/protocol.h index faef51ac2..a8cea65a4 100644 --- a/src/net/eathena/protocol.h +++ b/src/net/eathena/protocol.h @@ -97,7 +97,7 @@ packet(SMSG_PLAYER_REFINE, 0x0188); packet(SMSG_PLAYER_EQUIPMENT, 0x0992); packet(SMSG_PLAYER_EQUIP, 0x0999); packet(SMSG_PLAYER_UNEQUIP, 0x099a); -packet(SMSG_PLAYER_UNE_CARD, 0x017b); +packet(SMSG_PLAYER_USE_CARD, 0x017b); packet(SMSG_PLAYER_INSERT_CARD, 0x017d); packet(SMSG_PLAYER_ATTACK_RANGE, 0x013a); packet(SMSG_PLAYER_ARROW_EQUIP, 0x013c); diff --git a/src/net/inventoryhandler.h b/src/net/inventoryhandler.h index fc1365898..a151e39da 100644 --- a/src/net/inventoryhandler.h +++ b/src/net/inventoryhandler.h @@ -71,7 +71,7 @@ class InventoryHandler notfinal virtual int convertFromServerSlot(const int eAthenaSlot) const = 0; - virtual void useCard(const int index) const = 0; + virtual void useCard(const Item *const item) = 0; virtual void insertCard(const int cardIndex, const int itemIndex) const = 0; @@ -82,6 +82,8 @@ class InventoryHandler notfinal virtual void selectEgg(const Item *const item) const = 0; virtual int getProjectileSlot() const = 0; + + virtual int getItemIndex() const A_WARN_UNUSED = 0; }; } // namespace Net diff --git a/src/net/tmwa/inventoryhandler.cpp b/src/net/tmwa/inventoryhandler.cpp index 6097f515d..5ff9325ae 100644 --- a/src/net/tmwa/inventoryhandler.cpp +++ b/src/net/tmwa/inventoryhandler.cpp @@ -240,7 +240,7 @@ void InventoryHandler::moveItem2(const int source, const int slot, } } -void InventoryHandler::useCard(const int index A_UNUSED) const +void InventoryHandler::useCard(const Item *const item A_UNUSED) { } diff --git a/src/net/tmwa/inventoryhandler.h b/src/net/tmwa/inventoryhandler.h index 5a8056538..bf6badc48 100644 --- a/src/net/tmwa/inventoryhandler.h +++ b/src/net/tmwa/inventoryhandler.h @@ -58,7 +58,7 @@ class InventoryHandler final : public MessageHandler, const int amount, const int destination) const override final; - void useCard(const int index) const override final; + void useCard(const Item *const item) override final; void insertCard(const int cardIndex, const int itemIndex) const override final; @@ -74,6 +74,9 @@ class InventoryHandler final : public MessageHandler, int getProjectileSlot() const override final { return 10; } + int getItemIndex() const override final A_WARN_UNUSED + { return 0; } + protected: static void processPlayerEquipment(Net::MessageIn &msg); -- cgit v1.2.3-60-g2f50