Skip to content

Commit

Permalink
SL-20232 Allow deletion of worn items #1
Browse files Browse the repository at this point in the history
  • Loading branch information
akleshchev committed Oct 17, 2023
1 parent 19ac7d1 commit a62f5bf
Show file tree
Hide file tree
Showing 16 changed files with 138 additions and 46 deletions.
2 changes: 1 addition & 1 deletion indra/llui/llfolderview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ void LLFolderView::removeSelectedItems()
}
else
{
LL_INFOS() << "Cannot delete " << item->getName() << LL_ENDL;
LL_DEBUGS() << "Cannot delete " << item->getName() << LL_ENDL;
return;
}
}
Expand Down
2 changes: 1 addition & 1 deletion indra/llui/llfolderviewmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class LLFolderViewModelItem : public LLRefCount
virtual BOOL isItemMovable( void ) const = 0; // Can be moved to another folder
virtual void move( LLFolderViewModelItem* parent_listener ) = 0;

virtual BOOL isItemRemovable( void ) const = 0; // Can be destroyed
virtual BOOL isItemRemovable( bool check_worn = true ) const = 0; // Can be destroyed
virtual BOOL removeItem() = 0;
virtual void removeBatch(std::vector<LLFolderViewModelItem*>& batch) = 0;

Expand Down
9 changes: 5 additions & 4 deletions indra/newview/llappearancemgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3176,6 +3176,7 @@ void LLAppearanceMgr::removeCOFItemLinks(const LLUUID& item_id, LLPointer<LLInve
{
// Immediate delete
remove_inventory_item(item->getUUID(), cb, true);
remove_inventory_item(item->getUUID(), cb, true);
gInventory.addChangedMask(LLInventoryObserver::LABEL, item_id);
}
else
Expand Down Expand Up @@ -4117,7 +4118,7 @@ void LLAppearanceMgr::wearBaseOutfit()
updateCOF(base_outfit_id);
}

void LLAppearanceMgr::removeItemsFromAvatar(const uuid_vec_t& ids_to_remove)
void LLAppearanceMgr::removeItemsFromAvatar(const uuid_vec_t& ids_to_remove, nullary_func_t post_update_func)
{
LL_DEBUGS("UIUsage") << "removeItemsFromAvatar" << LL_ENDL;
LLUIUsage::instance().logCommand("Avatar.RemoveItem");
Expand All @@ -4127,7 +4128,7 @@ void LLAppearanceMgr::removeItemsFromAvatar(const uuid_vec_t& ids_to_remove)
LL_WARNS() << "called with empty list, nothing to do" << LL_ENDL;
return;
}
LLPointer<LLInventoryCallback> cb = new LLUpdateAppearanceOnDestroy;
LLPointer<LLInventoryCallback> cb = new LLUpdateAppearanceOnDestroy(true, true, post_update_func);
for (uuid_vec_t::const_iterator it = ids_to_remove.begin(); it != ids_to_remove.end(); ++it)
{
const LLUUID& id_to_remove = *it;
Expand All @@ -4146,11 +4147,11 @@ void LLAppearanceMgr::removeItemsFromAvatar(const uuid_vec_t& ids_to_remove)
}
}

void LLAppearanceMgr::removeItemFromAvatar(const LLUUID& id_to_remove)
void LLAppearanceMgr::removeItemFromAvatar(const LLUUID& id_to_remove, nullary_func_t post_update_func)
{
uuid_vec_t ids_to_remove;
ids_to_remove.push_back(id_to_remove);
removeItemsFromAvatar(ids_to_remove);
removeItemsFromAvatar(ids_to_remove, post_update_func);
}


Expand Down
4 changes: 2 additions & 2 deletions indra/newview/llappearancemgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ class LLAppearanceMgr: public LLSingleton<LLAppearanceMgr>
bool updateBaseOutfit();

//Remove clothing or detach an object from the agent (a bodypart cannot be removed)
void removeItemsFromAvatar(const uuid_vec_t& item_ids);
void removeItemFromAvatar(const LLUUID& item_id);
void removeItemsFromAvatar(const uuid_vec_t& item_ids, nullary_func_t post_update_func = no_op);
void removeItemFromAvatar(const LLUUID& item_id, nullary_func_t post_update_func = no_op);


void onOutfitFolderCreated(const LLUUID& folder_id, bool show_panel);
Expand Down
4 changes: 2 additions & 2 deletions indra/newview/llcofwearables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class CofAttachmentContextMenu : public CofContextMenu

registrar.add("Attachment.Touch", boost::bind(handleMultiple, handle_attachment_touch, mUUIDs));
registrar.add("Attachment.Edit", boost::bind(handleMultiple, handle_item_edit, mUUIDs));
registrar.add("Attachment.Detach", boost::bind(&LLAppearanceMgr::removeItemsFromAvatar, LLAppearanceMgr::getInstance(), mUUIDs));
registrar.add("Attachment.Detach", boost::bind(&LLAppearanceMgr::removeItemsFromAvatar, LLAppearanceMgr::getInstance(), mUUIDs, no_op));

LLUICtrl::EnableCallbackRegistry::ScopedRegistrar enable_registrar;
enable_registrar.add("Attachment.OnEnable", boost::bind(&CofAttachmentContextMenu::onEnable, this, _2));
Expand Down Expand Up @@ -195,7 +195,7 @@ class CofClothingContextMenu : public CofContextMenu
LLUICtrl::EnableCallbackRegistry::ScopedRegistrar enable_registrar;
LLUUID selected_id = mUUIDs.back();

registrar.add("Clothing.TakeOff", boost::bind(&LLAppearanceMgr::removeItemsFromAvatar, LLAppearanceMgr::getInstance(), mUUIDs));
registrar.add("Clothing.TakeOff", boost::bind(&LLAppearanceMgr::removeItemsFromAvatar, LLAppearanceMgr::getInstance(), mUUIDs, no_op));
registrar.add("Clothing.Replace", boost::bind(replaceWearable, selected_id));
registrar.add("Clothing.Edit", boost::bind(LLAgentWearables::editWearable, selected_id));
registrar.add("Clothing.Create", boost::bind(&CofClothingContextMenu::createNew, this, selected_id));
Expand Down
2 changes: 1 addition & 1 deletion indra/newview/llconversationmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class LLConversationItem : public LLFolderViewModelItemCommon
virtual BOOL isItemRenameable() const { return TRUE; }
virtual BOOL renameItem(const std::string& new_name) { mName = new_name; mNeedsRefresh = true; return TRUE; }
virtual BOOL isItemMovable( void ) const { return FALSE; }
virtual BOOL isItemRemovable( void ) const { return FALSE; }
virtual BOOL isItemRemovable(bool check_worn = true) const { return FALSE; }
virtual BOOL isItemInTrash( void) const { return FALSE; }
virtual BOOL removeItem() { return FALSE; }
virtual void removeBatch(std::vector<LLFolderViewModelItem*>& batch) { }
Expand Down
15 changes: 8 additions & 7 deletions indra/newview/llinventorybridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,9 @@ void LLInvFVBridge::setCreationDate(time_t creation_date_utc)


// Can be destroyed (or moved to trash)
BOOL LLInvFVBridge::isItemRemovable() const
BOOL LLInvFVBridge::isItemRemovable(bool check_worn) const
{
return get_is_item_removable(getInventoryModel(), mUUID);
return get_is_item_removable(getInventoryModel(), mUUID, check_worn);
}

// Can be moved to another folder
Expand Down Expand Up @@ -1063,7 +1063,7 @@ void LLInvFVBridge::addDeleteContextMenuOptions(menuentry_vec_t &items,

items.push_back(std::string("Delete"));

if (!isItemRemovable() || isPanelActive("Favorite Items"))
if (!isItemRemovable(false) || isPanelActive("Favorite Items"))
{
disabled_items.push_back(std::string("Delete"));
}
Expand Down Expand Up @@ -2405,20 +2405,21 @@ void LLFolderBridge::update()
class LLIsItemRemovable : public LLFolderViewFunctor
{
public:
LLIsItemRemovable() : mPassed(TRUE) {}
LLIsItemRemovable(bool check_worn = true) : mPassed(TRUE), mCheckWorn(check_worn) {}
virtual void doFolder(LLFolderViewFolder* folder)
{
mPassed &= folder->getViewModelItem()->isItemRemovable();
mPassed &= folder->getViewModelItem()->isItemRemovable(mCheckWorn);
}
virtual void doItem(LLFolderViewItem* item)
{
mPassed &= item->getViewModelItem()->isItemRemovable();
mPassed &= item->getViewModelItem()->isItemRemovable(mCheckWorn);
}
BOOL mPassed;
bool mCheckWorn;
};

// Can be destroyed (or moved to trash)
BOOL LLFolderBridge::isItemRemovable() const
BOOL LLFolderBridge::isItemRemovable(bool check_worn) const
{
if (!get_is_category_removable(getInventoryModel(), mUUID))
{
Expand Down
4 changes: 2 additions & 2 deletions indra/newview/llinventorybridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class LLInvFVBridge : public LLFolderViewModelItemInventory
virtual BOOL isItemRenameable() const { return TRUE; }
virtual BOOL isMultiPreviewAllowed() { return TRUE; }
//virtual BOOL renameItem(const std::string& new_name) {}
virtual BOOL isItemRemovable() const;
virtual BOOL isItemRemovable(bool check_worn = true) const;
virtual BOOL isItemMovable() const;
virtual BOOL isItemInTrash() const;
virtual bool isItemInOutfits() const;
Expand Down Expand Up @@ -321,7 +321,7 @@ class LLFolderBridge : public LLInvFVBridge
void* cargo_data,
std::string& tooltip_msg);

virtual BOOL isItemRemovable() const;
virtual BOOL isItemRemovable(bool check_worn = true) const;
virtual BOOL isItemMovable() const ;
virtual BOOL isUpToDate() const;
virtual bool isItemCopyable(bool can_copy_as_link = true) const;
Expand Down
87 changes: 75 additions & 12 deletions indra/newview/llinventoryfunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -682,17 +682,17 @@ BOOL get_can_item_be_worn(const LLUUID& id)
return FALSE;
}

BOOL get_is_item_removable(const LLInventoryModel* model, const LLUUID& id)
bool get_is_item_removable(const LLInventoryModel* model, const LLUUID& id, bool check_worn)
{
if (!model)
{
return FALSE;
return false;
}

// Can't delete an item that's in the library.
if (!model->isObjectDescendentOf(id, gInventory.getRootFolderID()))
{
return FALSE;
return false;
}

// Disable delete from COF folder; have users explicitly choose "detach/take off",
Expand All @@ -701,20 +701,20 @@ BOOL get_is_item_removable(const LLInventoryModel* model, const LLUUID& id)
{
if (get_is_item_worn(id))
{
return FALSE;
return false;
}
}

const LLInventoryObject *obj = model->getItem(id);
if (obj && obj->getIsLinkType())
{
return TRUE;
return true;
}
if (get_is_item_worn(id))
if (check_worn && get_is_item_worn(id))
{
return FALSE;
return false;
}
return TRUE;
return true;
}

bool get_is_item_editable(const LLUUID& inv_item_id)
Expand Down Expand Up @@ -2759,7 +2759,7 @@ bool LLFindNonRemovableObjects::operator()(LLInventoryCategory* cat, LLInventory
{
if (item)
{
return !get_is_item_removable(&gInventory, item->getUUID());
return !get_is_item_removable(&gInventory, item->getUUID(), true);
}
if (cat)
{
Expand Down Expand Up @@ -3024,6 +3024,8 @@ void LLInventoryAction::doToSelected(LLInventoryModel* model, LLFolderView* root
{
const LLUUID &marketplacelistings_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_MARKETPLACE_LISTINGS);
bool marketplacelistings_item = false;
bool worn_item = false;
bool needs_replacement = false;
LLAllDescendentsPassedFilter f;
for (std::set<LLFolderViewItem*>::iterator it = selected_items.begin(); (it != selected_items.end()) && (f.allDescendentsPassedFilter()); ++it)
{
Expand All @@ -3037,9 +3039,32 @@ void LLInventoryAction::doToSelected(LLInventoryModel* model, LLFolderView* root
marketplacelistings_item = true;
break;
}
if (get_is_item_worn(viewModel->getUUID()))
{
worn_item = true;
LLWearableType::EType type = viewModel->getWearableType();
if (type == LLWearableType::WT_SHAPE
|| type == LLWearableType::WT_SKIN
|| type == LLWearableType::WT_HAIR
|| type == LLWearableType::WT_EYES)
{
needs_replacement = true;
break;
}
}
}
// Fall through to the generic confirmation if the user choose to ignore the specialized one
if ( (!f.allDescendentsPassedFilter()) && !marketplacelistings_item && (!LLNotifications::instance().getIgnored("DeleteFilteredItems")) )
if (needs_replacement)
{
LLNotificationsUtil::add("CantDeleteRequiredClothing");
}
else if (worn_item)
{
LLSD payload;
payload["has_worn"] = true;
LLNotificationsUtil::add("DeleteWornItems", LLSD(), payload, boost::bind(&LLInventoryAction::onItemsRemovalConfirmation, _1, _2, root->getHandle()));
}
else if ( (!f.allDescendentsPassedFilter()) && !marketplacelistings_item && (!LLNotifications::instance().getIgnored("DeleteFilteredItems")) )
{
LLNotificationsUtil::add("DeleteFilteredItems", LLSD(), LLSD(), boost::bind(&LLInventoryAction::onItemsRemovalConfirmation, _1, _2, root->getHandle()));
}
Expand Down Expand Up @@ -3356,17 +3381,55 @@ void LLInventoryAction::removeItemFromDND(LLFolderView* root)
}
}
}

void LLInventoryAction::onItemsRemovalConfirmation(const LLSD& notification, const LLSD& response, LLHandle<LLFolderView> root)
{
S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
if (option == 0 && !root.isDead() && !root.get()->isDead())
{
bool has_worn = notification["payload"]["has_worn"].asBoolean();
LLFolderView* folder_root = root.get();
//Need to remove item from DND before item is removed from root folder view
//because once removed from root folder view the item is no longer a selected item
removeItemFromDND(folder_root);
folder_root->removeSelectedItems();

// removeSelectedItems will change selection, collect worn items beforehand
uuid_vec_t worn;
if (has_worn)
{
//Get selected items
LLFolderView::selected_items_t selectedItems = folder_root->getSelectedItems();

//If user is in DND and deletes item, make sure the notification is not displayed by removing the notification
//from DND history and .xml file. Once this is done, upon exit of DND mode the item deleted will not show a notification.
for (LLFolderView::selected_items_t::iterator it = selectedItems.begin(); it != selectedItems.end(); ++it)
{
LLObjectBridge* view_model = dynamic_cast<LLObjectBridge*>((*it)->getViewModelItem());

if (view_model && get_is_item_worn(view_model->getUUID()))
{
worn.push_back(view_model->getUUID());
}
}
}

// removeSelectedItems will check if items are worn before deletion,
// don't 'unwear' yet to prevent a race condition from unwearing
// and removing simultaneously
folder_root->removeSelectedItems();

// unwear then delete the rest
if (!worn.empty())
{
// should fire once after every item gets detached
LLAppearanceMgr::instance().removeItemsFromAvatar(worn,
[worn]()
{
for (const LLUUID& id : worn)
{
remove_inventory_item(id, NULL);
}
});
}

// Update the marketplace listings that have been affected by the operation
updateMarketplaceFolders();
Expand Down
2 changes: 1 addition & 1 deletion indra/newview/llinventoryfunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ BOOL get_is_item_worn(const LLUUID& id);
// Could this item be worn (correct type + not already being worn)
BOOL get_can_item_be_worn(const LLUUID& id);

BOOL get_is_item_removable(const LLInventoryModel* model, const LLUUID& id);
bool get_is_item_removable(const LLInventoryModel* model, const LLUUID& id, bool check_worn);

// Performs the appropiate edit action (if one exists) for this item
bool get_is_item_editable(const LLUUID& inv_item_id);
Expand Down
6 changes: 3 additions & 3 deletions indra/newview/llinventorygallery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1685,7 +1685,7 @@ BOOL LLInventoryGallery::canCut() const
return FALSE;
}
}
else if (!get_is_item_removable(&gInventory, id))
else if (!get_is_item_removable(&gInventory, id, true))
{
return FALSE;
}
Expand Down Expand Up @@ -1880,7 +1880,7 @@ void LLInventoryGallery::onDelete(const LLSD& notification, const LLSD& response
}
else
{
if (get_is_item_removable(&gInventory, id))
if (get_is_item_removable(&gInventory, id, true))
{
gInventory.removeItem(id);
}
Expand Down Expand Up @@ -1925,7 +1925,7 @@ bool LLInventoryGallery::canDeleteSelection()
return false;
}
}
else if (!get_is_item_removable(&gInventory, id))
else if (!get_is_item_removable(&gInventory, id, true))
{
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion indra/newview/llinventorygallerymenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ void LLInventoryGalleryContextMenu::updateMenuItemsVisibility(LLContextMenu* men
{
items.push_back(std::string("Delete"));
}
if(!get_is_item_removable(&gInventory, selected_id))
if(!get_is_item_removable(&gInventory, selected_id, true))
{
disabled_items.push_back(std::string("Delete"));
disabled_items.push_back(std::string("Cut"));
Expand Down
8 changes: 4 additions & 4 deletions indra/newview/llpanelobjectinventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class LLTaskInvFVBridge : public LLFolderViewModelItemInventory
virtual BOOL isItemRenameable() const;
virtual BOOL renameItem(const std::string& new_name);
virtual BOOL isItemMovable() const;
virtual BOOL isItemRemovable() const;
virtual BOOL isItemRemovable(bool check_worn = true) const;
virtual BOOL removeItem();
virtual void removeBatch(std::vector<LLFolderViewModelItem*>& batch);
virtual void move(LLFolderViewModelItem* parent_listener);
Expand Down Expand Up @@ -335,7 +335,7 @@ BOOL LLTaskInvFVBridge::isItemMovable() const
return TRUE;
}

BOOL LLTaskInvFVBridge::isItemRemovable() const
BOOL LLTaskInvFVBridge::isItemRemovable(bool check_worn) const
{
const LLViewerObject* object = gObjectList.findObject(mPanel->getTaskUUID());
if(object
Expand Down Expand Up @@ -587,7 +587,7 @@ class LLTaskCategoryBridge : public LLTaskInvFVBridge
virtual BOOL isItemRenameable() const;
// virtual BOOL isItemCopyable() const { return FALSE; }
virtual BOOL renameItem(const std::string& new_name);
virtual BOOL isItemRemovable() const;
virtual BOOL isItemRemovable(bool check_worn = true) const;
virtual void buildContextMenu(LLMenuGL& menu, U32 flags);
virtual bool hasChildren() const;
virtual BOOL startDrag(EDragAndDropType* type, LLUUID* id) const;
Expand Down Expand Up @@ -647,7 +647,7 @@ BOOL LLTaskCategoryBridge::renameItem(const std::string& new_name)
return FALSE;
}

BOOL LLTaskCategoryBridge::isItemRemovable() const
BOOL LLTaskCategoryBridge::isItemRemovable(bool check_worn) const
{
return FALSE;
}
Expand Down
Loading

0 comments on commit a62f5bf

Please sign in to comment.