From eda9f224bc04c1635344e2f91a42b341e11a4e81 Mon Sep 17 00:00:00 2001 From: Nuno Date: Wed, 9 Feb 2022 23:33:04 +0100 Subject: [PATCH] Merge remote-tracking branch 'origin/10-use-item-shortcut-client' into main/yubo-dev --- .../src/interface_v3/action_handler_item.cpp | 35 ---- .../client/src/interface_v3/dbctrl_sheet.cpp | 10 - ryzom/client/src/interface_v3/dbctrl_sheet.h | 2 - .../src/interface_v3/inventory_manager.cpp | 194 +++--------------- ryzom/common/src/game_share/inventories.cpp | 4 +- ryzom/common/src/game_share/inventories.h | 24 +-- 6 files changed, 48 insertions(+), 221 deletions(-) diff --git a/ryzom/client/src/interface_v3/action_handler_item.cpp b/ryzom/client/src/interface_v3/action_handler_item.cpp index 02f8d1633..2e55531fe 100644 --- a/ryzom/client/src/interface_v3/action_handler_item.cpp +++ b/ryzom/client/src/interface_v3/action_handler_item.cpp @@ -1079,41 +1079,6 @@ class CCanDropToExchange : public IActionHandler }; REGISTER_ACTION_HANDLER (CCanDropToExchange, "can_drop_to_exchange"); -// ********************************************************************************************************** -class CCanDropToHotbar : public IActionHandler -{ - virtual void execute (CCtrlBase *pCaller, const string &Params) - { - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - nlinfo("hey"); - string src = getParam(Params, "src"); - CInterfaceElement *pElt = CWidgetManager::getInstance()->getElementFromId(src); - CDBCtrlSheet *pCSSrc = dynamic_cast(pElt); - CDBCtrlSheet *pCSDst = dynamic_cast(pCaller); - if (!pCSSrc || !pCSDst) return; - - // Exchange can only be done from bag to exchange inventories - uint32 srcInventory = pCSSrc->getSecondIndexInDB(); - if ( - (srcInventory == INVENTORIES::bag || - srcInventory == INVENTORIES::pet_animal1 || - srcInventory == INVENTORIES::pet_animal2 || - srcInventory == INVENTORIES::pet_animal3 || - srcInventory == INVENTORIES::pet_animal4 || - srcInventory == INVENTORIES::pet_animal5 || - srcInventory == INVENTORIES::pet_animal6 || - srcInventory == INVENTORIES::pet_animal7 || - srcInventory == INVENTORIES::player_room) - && getInventory().isInventoryAvailable((INVENTORIES::TInventory) pCSSrc->getSecondIndexInDB()) - && getInventory().isUsableItem(pCSSrc->getSheetId()) - ) - { - pCSDst->setCanDrop ( true ); - } - } -}; -REGISTER_ACTION_HANDLER (CCanDropToHotbar, "can_drop_to_hotbar"); - // ********************************************************************************************************** /** Clear the selected sheet diff --git a/ryzom/client/src/interface_v3/dbctrl_sheet.cpp b/ryzom/client/src/interface_v3/dbctrl_sheet.cpp index 95caeabe8..dd70c7ece 100644 --- a/ryzom/client/src/interface_v3/dbctrl_sheet.cpp +++ b/ryzom/client/src/interface_v3/dbctrl_sheet.cpp @@ -314,7 +314,6 @@ CCtrlSheetInfo::CCtrlSheetInfo() _ItemSlot= SLOTTYPE::UNDEFINED; _AutoGrayed= false; _HasTradeSlotType = false; - _IsHotbarSlot = false; _BrickOverable= false; _ReadQuantityFromSheet = false; _AHOnLeftClick = NULL; @@ -390,10 +389,6 @@ bool CCtrlSheetInfo::parseCtrlInfo(xmlNodePtr cur, CInterfaceGroup * /* parentGr prop = (char*) xmlGetProp( cur, (xmlChar*)"use_slot_type_db_entry" ); if (prop) _HasTradeSlotType= CInterfaceElement::convertBool(prop); - - prop = (char*) xmlGetProp( cur, (xmlChar*)"hotbar_slot" ); - if (prop) - _IsHotbarSlot= CInterfaceElement::convertBool(prop); // Read Action handlers CAHManager::getInstance()->parseAH(cur, "onclick_l", "params_l", _AHOnLeftClick, _AHLeftClickParams); @@ -3798,11 +3793,6 @@ bool CDBCtrlSheet::canDropItem(CDBCtrlSheet *src) const bf|= 1<getSheetId()) ) - { - return true; - } - // Look if one slot solution match. if( pIS->SlotBF & bf ) { diff --git a/ryzom/client/src/interface_v3/dbctrl_sheet.h b/ryzom/client/src/interface_v3/dbctrl_sheet.h index f4c58872c..40e943307 100644 --- a/ryzom/client/src/interface_v3/dbctrl_sheet.h +++ b/ryzom/client/src/interface_v3/dbctrl_sheet.h @@ -168,7 +168,6 @@ public: // and another in the source slot. Useful for items to buy that are in infinite quantity. bool _AutoGrayed : 1; // if true then gray the ctrlSheeet if: 1/ Items: Is the Item Locked. 2/ Bricks: is the brick Latent. bool _HasTradeSlotType : 1; // true is the SLOT_TYPE DB field should be taken in account - bool _IsHotbarSlot : 1; // true if the slot is part of the hotbar bool _BrickOverable : 1; // if Type is Brick, display like a button (because LeftClickable). @@ -273,7 +272,6 @@ public: uint32 getItemNameId() const { return (uint32)_NameId.getSInt32();} // New Stack Size sint32 getStackable() const { return (_Stackable>1) ? 999 : 1; } - bool isHotbarSlot() const { return _IsHotbarSlot; } // get non locked quantity (can be zero) sint32 getNonLockedQuantity() const; diff --git a/ryzom/client/src/interface_v3/inventory_manager.cpp b/ryzom/client/src/interface_v3/inventory_manager.cpp index ccf75c77c..56dbb176a 100644 --- a/ryzom/client/src/interface_v3/inventory_manager.cpp +++ b/ryzom/client/src/interface_v3/inventory_manager.cpp @@ -1030,6 +1030,11 @@ void CInventoryManager::equip(const std::string &bagPath, const std::string &inv inventory = INVENTORIES::equipment; fromString(invPath.substr(22,invPath.size()), invSlot); } + else if (strnicmp(invPath.c_str(),"LOCAL:INVENTORY:HOTBAR",22) == 0) + { + inventory = INVENTORIES::hotbar; + fromString(invPath.substr(23,invPath.size()), invSlot); + } // Hands management : check if we have to unequip left hand because of incompatibility with right hand item sint16 oldRightIndexInBag = NLGUI::CDBManager::getInstance()->getDbProp(invPath + ":INDEX_IN_BAG")->getValue16(); @@ -1163,6 +1168,11 @@ void CInventoryManager::unequip(const std::string &invPath) inventory = INVENTORIES::equipment; fromString(invPath.substr(22,invPath.size()), invSlot); } + else if (strnicmp(invPath.c_str(),"LOCAL:INVENTORY:HOTBAR",22) == 0) + { + inventory = INVENTORIES::hotbar; + fromString(invPath.substr(23,invPath.size()), invSlot); + } // Hands management : check if we have to unequip left hand because of incompatibility with right hand item if (inventory == INVENTORIES::handling && invSlot == 0) @@ -1365,14 +1375,11 @@ void CInventoryManager::CDBEquipObs::update(ICDBNode* node) // Remove Last reference and update database sint16 oldVal = pNL->getOldValue16(); sint16 newVal = pNL->getValue16(); - if (sIE != CTRL_HOTBAR_1 && sIE != CTRL_HOTBAR_2 && sIE != CTRL_HOTBAR_3 && sIE != CTRL_HOTBAR_4 && sIE != CTRL_HOTBAR_5) - { - if (oldVal != 0) - getInventory().unwearBagItem (oldVal-1); + if (oldVal != 0) + getInventory().unwearBagItem (oldVal-1); - if (newVal != 0) - getInventory().wearBagItem (newVal-1); - } + if (newVal != 0) + getInventory().wearBagItem (newVal-1); // Update Display if (newVal == 0) @@ -3113,7 +3120,7 @@ class CHandlerInvDropTo : public IActionHandler { CInterfaceGroup *pIG = CWidgetManager::getInstance()->getModalWindow(); if (pIG == NULL) return; - if (pIG->getId() != "ui:interface:bag_choose") return; + if (pIG->getId() != "ui:interface:bag_choose" && pIG->getId() != "ui:interface:hotbar_choose") return; getInventory().beginDrag(NULL, CInventoryManager::TextList); // Special case for choose in bag dialog @@ -3275,173 +3282,40 @@ class CHandlerInvCannotDrop : public IActionHandler if (!getInventory().isDraggingFromTextList()) { CDBCtrlSheet *pCSDst = dynamic_cast(pCaller); - if (!pCSDst->isHotbarSlot()) { - string invPath = getInventory().getDBIndexPath(pCSDst); - getInventory().unequip(invPath); - } + string invPath = getInventory().getDBIndexPath(pCSDst); + getInventory().unequip(invPath); } getInventory().endDrag(); } }; REGISTER_ACTION_HANDLER( CHandlerInvCannotDrop, "inv_cannot_drop" ); - -// *************************************************************************** -class CHandlerHotbarDropTo : public IActionHandler +// ********************************************************************************************************** +class CCanDropToHotbar : public IActionHandler { virtual void execute (CCtrlBase *pCaller, const string &Params) { CInterfaceManager *pIM = CInterfaceManager::getInstance(); - - // Check that we have drag'n'drop from inventory (list or slot) - // Or if we have launched the choose_bag modal - // To prevent other things to happens + nlinfo("hey"); string src = getParam(Params, "src"); CInterfaceElement *pElt = CWidgetManager::getInstance()->getElementFromId(src); CDBCtrlSheet *pCSSrc = dynamic_cast(pElt); - CDBCtrlSheet *pCSDst = dynamic_cast(pCaller); - CAHManager::getInstance()->runActionHandler("swap_item", pCSDst, "src="+toString(pCSSrc->getId())); - getInventory().endDrag(); - // if (!getInventory().isDragging()) - // { - // CInterfaceGroup *pIG = CWidgetManager::getInstance()->getModalWindow(); - // if (pIG == NULL) return; - // if (pIG->getId() != "ui:interface:bag_choose") return; - // getInventory().beginDrag(NULL, CInventoryManager::TextList); - - // // Special case for choose in bag dialog - // string src = getParam(Params, "src"); - // CInterfaceElement *pElt = CWidgetManager::getInstance()->getElementFromId(src); - // CDBCtrlSheet *pCSSrc = dynamic_cast(pElt); - // CDBCtrlSheet *pCSDst = dynamic_cast(pCaller); - - // string invPath = getInventory().getDBIndexPath(pCSSrc); - // string bagPath = pCSDst->getSheet(); - - // if (bagPath == "UI:EMPTY") - // CAHManager::getInstance()->runActionHandler("swap_item", pCSDst, "src="+toString(pCSSrc->getId())); - // else - // getInventory().equip (bagPath, invPath); - - // getInventory().endDrag(); - // return; - // } - - // string src = getParam(Params, "src"); - // CInterfaceElement *pElt = CWidgetManager::getInstance()->getElementFromId(src); - // CDBCtrlSheet *pCSSrc = dynamic_cast(pElt); - // CDBCtrlSheet *pCSDst = dynamic_cast(pCaller); - // if (pCSSrc == NULL) return; - - // // Is the dragged sheet comes from an inventory list - // if (getInventory().isDraggingFromTextList() || getInventory().isDraggingFromIconList()) - // { - // // If the destination is an equipment slot ? - // if (pCSDst != NULL) - // { - // string invPath = getInventory().getDBIndexPath(pCSDst); // Get the index in the equipment - // if (!invPath.empty()) - // { - // // Drop to the slot ie write the database with the index of the slot - // string bagPath = pCSSrc->getSheet(); // Get the database branch of the dragged sheet - - // if (pCSSrc && pCSSrc->getType() == CCtrlSheetInfo::SheetType_Item) - // if (pCSDst && pCSDst->getType() == CCtrlSheetInfo::SheetType_Item) - // { - // // If the destination slot match with the type of incoming item - // if (pCSDst->canDropItem(pCSSrc)) - // { - // // So directly equip - // getInventory().equip(bagPath, invPath); - // } - // else - // { - // // Else try to auto equip the player with the incoming item - // const string sTmp = bagPath.substr(bagPath.rfind(':')+1,bagPath.size()); - // sint index; - // fromString(sTmp, index); - // if (!getInventory().autoEquip(index, false)) - // getInventory().autoEquip(index, true); - // } - // } - // getInventory().endDrag(); - // return; - // } - // } - - // // If the destination is a list sheet - // IListSheetBase *pListDst = dynamic_cast(pCaller); - // if ((pListDst == NULL) && (pCSDst != NULL)) - // pListDst = IListSheetBase::getListContaining(pCSDst); - // IListSheetBase *pListSrc = IListSheetBase::getListContaining(pCSSrc); - // if ((pListDst != NULL) && (pListSrc != NULL)) - // { - // // If the source list and destination list are the same - // if (pListDst == pListSrc) - // { - // // no op - // getInventory().endDrag(); - // return; - // } - // else // Source list and destination list are not the same - // { - // // Move the item to the destination list using the procedure move_to_xxx - // CDBGroupListSheetBag *pListDstText = dynamic_cast(pListDst); - // CDBGroupIconListBag *pListDstIcon = dynamic_cast(pListDst); - - // if (((pListDstText != NULL) && (pListDstText->getInvType() == CInventoryManager::InvBag)) || - // ((pListDstIcon != NULL) && (pListDstIcon->getInvType() == CInventoryManager::InvBag))) - // { - // CAHManager::getInstance()->runActionHandler("proc", pCSSrc, "move_to_bag"); - // } - // else if (((pListDstText != NULL) && ((pListDstText->getInvType() == CInventoryManager::InvPA0) || - // (pListDstText->getInvType() == CInventoryManager::InvPA1) || - // (pListDstText->getInvType() == CInventoryManager::InvPA2) || - // (pListDstText->getInvType() == CInventoryManager::InvPA3) || - // (pListDstText->getInvType() == CInventoryManager::InvPA4) || - // (pListDstText->getInvType() == CInventoryManager::InvPA5) || - // (pListDstText->getInvType() == CInventoryManager::InvPA6) - // )) || - // ((pListDstIcon != NULL) && ((pListDstIcon->getInvType() == CInventoryManager::InvPA0) || - // (pListDstIcon->getInvType() == CInventoryManager::InvPA1) || - // (pListDstIcon->getInvType() == CInventoryManager::InvPA2) || - // (pListDstIcon->getInvType() == CInventoryManager::InvPA3) || - // (pListDstIcon->getInvType() == CInventoryManager::InvPA4) || - // (pListDstIcon->getInvType() == CInventoryManager::InvPA5) || - // (pListDstIcon->getInvType() == CInventoryManager::InvPA6) - // ))) - // { - // string sTmp; - // if (pListDstText != NULL) sTmp = toString("%d",pListDstText->getInvType()-CInventoryManager::InvPA0); - // if (pListDstIcon != NULL) sTmp = toString("%d",pListDstIcon->getInvType()-CInventoryManager::InvPA0); - // nlinfo("ici :%s", sTmp.c_str()); - // CAHManager::getInstance()->runActionHandler("proc", pCSSrc, "move_to_pa|"+sTmp); - // } - // else if (((pListDstText != NULL) && (pListDstText->getInvType() == CInventoryManager::InvGuild)) || - // ((pListDstIcon != NULL) && (pListDstIcon->getInvType() == CInventoryManager::InvGuild))) - // { - // CAHManager::getInstance()->runActionHandler("proc", pCSSrc, "move_to_guild"); - // } - // else if (((pListDstText != NULL) && (pListDstText->getInvType() == CInventoryManager::InvRoom)) || - // ((pListDstIcon != NULL) && (pListDstIcon->getInvType() == CInventoryManager::InvRoom))) - // { - // CAHManager::getInstance()->runActionHandler("proc", pCSSrc, "move_to_room"); - // } - // } - // } - // } - - // // Is the dragged sheet comes from another slot - // if (pCSDst != NULL) - // if (getInventory().isDraggingFromSlot()) - // { - // CAHManager::getInstance()->runActionHandler("swap_item", pCSDst, "src="+toString(pCSSrc->getId())); - // } - - // CAHManager::getInstance()->runActionHandler("inv_cannot_drop", pCSSrc); + CDBCtrlSheet *pCSDst = dynamic_cast(pCaller); + if (!pCSSrc || !pCSDst) return; + + // Exchange can only be done from bag to exchange inventories + uint32 srcInventory = pCSSrc->getSecondIndexInDB(); + if ( + srcInventory == INVENTORIES::bag + && getInventory().isInventoryAvailable((INVENTORIES::TInventory) pCSSrc->getSecondIndexInDB()) + && getInventory().isUsableItem(pCSSrc->getSheetId()) + ) + { + pCSDst->setCanDrop ( true ); + } } }; -REGISTER_ACTION_HANDLER( CHandlerHotbarDropTo, "hotbar_drop" ); +REGISTER_ACTION_HANDLER (CCanDropToHotbar, "can_drop_to_hotbar"); // ********************************************************************************************************** class CHotbarLeftClickOnSlotHandler : public IActionHandler diff --git a/ryzom/common/src/game_share/inventories.cpp b/ryzom/common/src/game_share/inventories.cpp index f4ee24915..bb867f992 100644 --- a/ryzom/common/src/game_share/inventories.cpp +++ b/ryzom/common/src/game_share/inventories.cpp @@ -33,6 +33,7 @@ namespace INVENTORIES NL_STRING_CONVERSION_TABLE_ENTRY(handling) NL_STRING_CONVERSION_TABLE_ENTRY(temporary) NL_STRING_CONVERSION_TABLE_ENTRY(equipment) + NL_STRING_CONVERSION_TABLE_ENTRY(hotbar) NL_STRING_CONVERSION_TABLE_ENTRY(bag) NL_STRING_CONVERSION_TABLE_ENTRY(pet_animal1) NL_STRING_CONVERSION_TABLE_ENTRY(pet_animal2) @@ -49,7 +50,6 @@ namespace INVENTORIES NL_STRING_CONVERSION_TABLE_ENTRY(reward_sharing) NL_STRING_CONVERSION_TABLE_ENTRY(guild) NL_STRING_CONVERSION_TABLE_ENTRY(player_room) - NL_STRING_CONVERSION_TABLE_ENTRY(hotbar) NL_END_STRING_CONVERSION_TABLE(TInventory, InventoryToString, UNDEFINED) @@ -95,6 +95,7 @@ namespace INVENTORIES "TEMP", // temporary // "", // pick-up "EQUIP", // equipment + "HOTBAR", // hotbar "", // bag "", // pack_animal1 "", // pack_animal2 @@ -109,7 +110,6 @@ namespace INVENTORIES // "", // exchange_proposition "", // guild "", // player_room - "HOTBAR", // hotbar "" // unknown }; diff --git a/ryzom/common/src/game_share/inventories.h b/ryzom/common/src/game_share/inventories.h index 076038950..7142140f4 100644 --- a/ryzom/common/src/game_share/inventories.h +++ b/ryzom/common/src/game_share/inventories.h @@ -158,8 +158,9 @@ namespace INVENTORIES handling = 0, temporary, // 1 equipment, // 2 - bag, // 3 - pet_animal, // 4 Character can have 7 pack animal + hotbar, // 3 + bag, // 4 + pet_animal, // 5 Character can have 7 pack animal pet_animal1 = pet_animal, // for toString => TInventory convertion pet_animal2, pet_animal3, @@ -167,18 +168,17 @@ namespace INVENTORIES pet_animal5, pet_animal6, pet_animal7, - max_pet_animal, // 11 - NUM_INVENTORY = max_pet_animal, // 11 - UNDEFINED = NUM_INVENTORY, // 11 + max_pet_animal, // 12 + NUM_INVENTORY = max_pet_animal, // 12 + UNDEFINED = NUM_INVENTORY, // 12 - exchange, // 12 This is not a bug : exchange is a fake inventory - exchange_proposition, // 13 and should not count in the number of inventory + exchange, // 13 This is not a bug : exchange is a fake inventory + exchange_proposition, // 14 and should not count in the number of inventory // same for botChat trading. - trading, // 14 - reward_sharing, // 15 fake inventory, not in database.xml. Used by the item info protocol only - guild, // 16 (warning: number stored in guild saved file) - player_room, // 17 - hotbar, // 18 + trading, // 15 + reward_sharing, // 16 fake inventory, not in database.xml. Used by the item info protocol only + guild, // 17 (warning: number stored in guild saved file) + player_room, // 18 NUM_ALL_INVENTORY // warning: distinct from NUM_INVENTORY };