summaryrefslogtreecommitdiff
path: root/indra/newview/llappearancemgr.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/llappearancemgr.cpp')
-rw-r--r--indra/newview/llappearancemgr.cpp106
1 files changed, 75 insertions, 31 deletions
diff --git a/indra/newview/llappearancemgr.cpp b/indra/newview/llappearancemgr.cpp
index 6fa23727b1..0d57b33a51 100644
--- a/indra/newview/llappearancemgr.cpp
+++ b/indra/newview/llappearancemgr.cpp
@@ -1500,6 +1500,27 @@ void wear_on_avatar_cb(const LLUUID& inv_item, bool do_replace = false)
}
}
+bool needs_to_replace(LLViewerInventoryItem* item_to_wear, bool & first_for_object, std::vector<bool>& first_for_type, bool replace)
+{
+ bool res = false;
+ LLAssetType::EType type = item_to_wear->getType();
+ if (type == LLAssetType::AT_OBJECT)
+ {
+ res = first_for_object && replace;
+ first_for_object = false;
+ }
+ else if (type == LLAssetType::AT_CLOTHING)
+ {
+ LLWearableType::EType wtype = item_to_wear->getWearableType();
+ if (wtype >= 0 && wtype < LLWearableType::WT_COUNT)
+ {
+ res = first_for_type[wtype] && replace;
+ first_for_type[wtype] = false;
+ }
+ }
+ return res;
+}
+
void LLAppearanceMgr::wearItemsOnAvatar(const uuid_vec_t& item_ids_to_wear,
bool do_update,
bool replace,
@@ -1508,7 +1529,8 @@ void LLAppearanceMgr::wearItemsOnAvatar(const uuid_vec_t& item_ids_to_wear,
LL_DEBUGS("UIUsage") << "wearItemsOnAvatar" << LL_ENDL;
LLUIUsage::instance().logCommand("Avatar.WearItem");
- bool first = true;
+ bool first_for_object = true;
+ std::vector<bool> first_for_type(LLWearableType::WT_COUNT, true);
LLInventoryObject::const_object_list_t items_to_link;
@@ -1516,9 +1538,6 @@ void LLAppearanceMgr::wearItemsOnAvatar(const uuid_vec_t& item_ids_to_wear,
it != item_ids_to_wear.end();
++it)
{
- replace = first && replace;
- first = false;
-
const LLUUID& item_id_to_wear = *it;
if (item_id_to_wear.isNull())
@@ -1537,8 +1556,9 @@ void LLAppearanceMgr::wearItemsOnAvatar(const uuid_vec_t& item_ids_to_wear,
if (gInventory.isObjectDescendentOf(item_to_wear->getUUID(), gInventory.getLibraryRootFolderID()))
{
LL_DEBUGS("Avatar") << "inventory item in library, will copy and wear "
- << item_to_wear->getName() << " id " << item_id_to_wear << LL_ENDL;
- LLPointer<LLInventoryCallback> cb = new LLBoostFuncInventoryCallback(boost::bind(wear_on_avatar_cb,_1,replace));
+ << item_to_wear->getName() << " id " << item_id_to_wear << LL_ENDL;
+ bool replace_item = needs_to_replace(item_to_wear, first_for_object, first_for_type, replace);
+ LLPointer<LLInventoryCallback> cb = new LLBoostFuncInventoryCallback(boost::bind(wear_on_avatar_cb, _1, replace_item));
copy_inventory_item(gAgent.getID(), item_to_wear->getPermissions().getOwner(),
item_to_wear->getUUID(), LLUUID::null, std::string(), cb);
continue;
@@ -1576,7 +1596,8 @@ void LLAppearanceMgr::wearItemsOnAvatar(const uuid_vec_t& item_ids_to_wear,
}
LLWearableType::EType type = item_to_wear->getWearableType();
S32 wearable_count = gAgentWearables.getWearableCount(type);
- if ((replace && wearable_count != 0) || !gAgentWearables.canAddWearable(type))
+ bool replace_item = needs_to_replace(item_to_wear, first_for_object, first_for_type, replace);
+ if ((replace_item && wearable_count != 0) || !gAgentWearables.canAddWearable(type))
{
LLUUID item_id = gAgentWearables.getWearableItemID(item_to_wear->getWearableType(),
wearable_count-1);
@@ -1605,7 +1626,13 @@ void LLAppearanceMgr::wearItemsOnAvatar(const uuid_vec_t& item_ids_to_wear,
case LLAssetType::AT_OBJECT:
{
- rez_attachment(item_to_wear, NULL, replace);
+ // Note that this will replace only first attachment regardless of attachment point,
+ // so if user is wearing two items over other two on different attachment points,
+ // only one will be replaced.
+ // Unfortunately we have no way to determine attachment point from inventory item.
+ // We might want to forbid wearing multiple objects with replace option in future.
+ bool replace_item = needs_to_replace(item_to_wear, first_for_object, first_for_type, replace);
+ rez_attachment(item_to_wear, NULL, replace_item);
}
break;
@@ -4218,37 +4245,54 @@ bool LLAppearanceMgr::moveWearable(LLViewerInventoryItem* item, bool closer_to_b
if (item->getType() != LLAssetType::AT_CLOTHING) return false;
if (!gInventory.isObjectDescendentOf(item->getUUID(), getCOF())) return false;
+ S32 pos = gAgentWearables.getWearableIdxFromItem(item);
+ if (pos < 0) return false; // Not found
+
+ U32 count = gAgentWearables.getWearableCount(item->getWearableType());
+ if (count < 2) return false; // Nothing to swap with
+ if (closer_to_body)
+ {
+ if (pos == 0) return false; // already first
+ }
+ else
+ {
+ if (pos == count - 1) return false; // already last
+ }
+
+ U32 old_pos = (U32)pos;
+ U32 swap_with = closer_to_body ? old_pos - 1 : old_pos + 1;
+ LLUUID swap_item_id = gAgentWearables.getWearableItemID(item->getWearableType(), swap_with);
+
+ // Find link item from item id.
LLInventoryModel::cat_array_t cats;
LLInventoryModel::item_array_t items;
LLFindWearablesOfType filter_wearables_of_type(item->getWearableType());
gInventory.collectDescendentsIf(getCOF(), cats, items, true, filter_wearables_of_type);
if (items.empty()) return false;
- // We assume that the items have valid descriptions.
- std::sort(items.begin(), items.end(), WearablesOrderComparator(item->getWearableType()));
-
- if (closer_to_body && items.front() == item) return false;
- if (!closer_to_body && items.back() == item) return false;
-
- LLInventoryModel::item_array_t::iterator it = std::find(items.begin(), items.end(), item);
- if (items.end() == it) return false;
-
-
- //swapping descriptions
- closer_to_body ? --it : ++it;
- LLViewerInventoryItem* swap_item = *it;
- if (!swap_item) return false;
- std::string tmp = swap_item->getActualDescription();
- swap_item->setDescription(item->getActualDescription());
- item->setDescription(tmp);
+ LLViewerInventoryItem* swap_item = nullptr;
+ for (auto iter : items)
+ {
+ if (iter->getLinkedUUID() == swap_item_id)
+ {
+ swap_item = iter.get();
+ break;
+ }
+ }
+ if (!swap_item)
+ {
+ return false;
+ }
- // LL_DEBUGS("Inventory") << "swap, item "
- // << ll_pretty_print_sd(item->asLLSD())
- // << " swap_item "
- // << ll_pretty_print_sd(swap_item->asLLSD()) << LL_ENDL;
+ // Description is supposed to hold sort index, but user could have changed
+ // order rapidly and there might be a state mismatch between description
+ // and gAgentWearables, trust gAgentWearables over description.
+ // Generate new description.
+ std::string new_desc = build_order_string(item->getWearableType(), old_pos);
+ swap_item->setDescription(new_desc);
+ new_desc = build_order_string(item->getWearableType(), swap_with);
+ item->setDescription(new_desc);
- // FIXME switch to use AISv3 where supported.
- //items need to be updated on a dataserver
item->setComplete(true);
item->updateServer(false);
gInventory.updateItem(item);