diff options
author | Andrey Kleshchev <andreykproductengine@lindenlab.com> | 2023-11-14 00:48:30 +0200 |
---|---|---|
committer | Andrey Kleshchev <andreykproductengine@lindenlab.com> | 2023-11-14 00:48:30 +0200 |
commit | 742f5ebec64b7633763b651abb6e1f1eea82f140 (patch) | |
tree | 72b20d1f331c8ec86f4cf2f138f1df3e5b1e1ac6 /indra | |
parent | 7e66f6ca18e667093ac6b505badf25d467e5acff (diff) |
SL-20233 Add command to remove selected avatar attachment(s)
Diffstat (limited to 'indra')
-rw-r--r-- | indra/newview/llviewermenu.cpp | 77 |
1 files changed, 55 insertions, 22 deletions
diff --git a/indra/newview/llviewermenu.cpp b/indra/newview/llviewermenu.cpp index 8686fad3e6..5d9d10cf30 100644 --- a/indra/newview/llviewermenu.cpp +++ b/indra/newview/llviewermenu.cpp @@ -7263,37 +7263,70 @@ class LLAttachmentDetach : public view_listener_t { // Called when the user clicked on an object attached to them // and selected "Detach". - LLViewerObject *object = LLSelectMgr::getInstance()->getSelection()->getPrimaryObject(); + LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection(); + LLViewerObject *object = selection->getPrimaryObject(); if (!object) { LL_WARNS() << "handle_detach() - no object to detach" << LL_ENDL; return true; } - LLViewerObject *parent = (LLViewerObject*)object->getParent(); - while (parent) - { - if(parent->isAvatar()) - { - break; - } - object = parent; - parent = (LLViewerObject*)parent->getParent(); - } + struct f: public LLSelectedObjectFunctor + { + f() : mAvatarsInSelection(false) {} + virtual bool apply(LLViewerObject* objectp) + { + if (!objectp) + { + return false; + } - if (!object) - { - LL_WARNS() << "handle_detach() - no object to detach" << LL_ENDL; - return true; - } + if (objectp->isAvatar()) + { + mAvatarsInSelection = true; + return false; + } - if (object->isAvatar()) - { - LL_WARNS() << "Trying to detach avatar from avatar." << LL_ENDL; - return true; - } + LLViewerObject* parent = (LLViewerObject*)objectp->getParent(); + while (parent) + { + if (parent->isAvatar()) + { + break; + } + objectp = parent; + parent = (LLViewerObject*)parent->getParent(); + } + + // std::set to avoid dupplicate 'roots' from linksets + mRemoveSet.insert(objectp->getAttachmentItemID()); + + return true; + } + bool mAvatarsInSelection; + uuid_set_t mRemoveSet; + } func; + // Probbly can run applyToRootObjects instead, + // but previous version of this code worked for any selected object + selection->applyToObjects(&func); + + if (func.mAvatarsInSelection) + { + // Not possible under normal circumstances + // Either avatar selection is ON or has to do with animeshes + // Better stop this than mess something + LL_WARNS() << "Trying to detach avatar from avatar." << LL_ENDL; + return true; + } + + if (func.mRemoveSet.empty()) + { + LL_WARNS() << "handle_detach() - no valid attachments in selection to detach" << LL_ENDL; + return true; + } - LLAppearanceMgr::instance().removeItemFromAvatar(object->getAttachmentItemID()); + uuid_vec_t detach_list(func.mRemoveSet.begin(), func.mRemoveSet.end()); + LLAppearanceMgr::instance().removeItemsFromAvatar(detach_list); return true; } |