summaryrefslogtreecommitdiff
path: root/indra/newview/llagentwearables.cpp
diff options
context:
space:
mode:
authorErik Kundiman <erik@megapahit.org>2026-09-01 18:35:23 +0800
committerErik Kundiman <erik@megapahit.org>2026-09-04 21:58:53 +0800
commit00bb3bb6f07660bd914d29a1389342bb3060d254 (patch)
tree431f574922494d2201718f13085f17bc6bd7fb42 /indra/newview/llagentwearables.cpp
parenta8636720129952c10cf49ab80da21bf8b340b96c (diff)
parent4ef9f8f14b35ed388c294d53767a0dca0e890924 (diff)
Merge remote-tracking branch 'secondlife/release/26.4' into 26.4
Diffstat (limited to 'indra/newview/llagentwearables.cpp')
-rw-r--r--indra/newview/llagentwearables.cpp46
1 files changed, 43 insertions, 3 deletions
diff --git a/indra/newview/llagentwearables.cpp b/indra/newview/llagentwearables.cpp
index 5801ba1eb8..7163f9510f 100644
--- a/indra/newview/llagentwearables.cpp
+++ b/indra/newview/llagentwearables.cpp
@@ -547,14 +547,23 @@ const S32 LLAgentWearables::getWearableIdxFromItem(const LLViewerInventoryItem*
U32 wearable_count = getWearableCount(type);
if (0 == wearable_count) return -1;
- const LLUUID& asset_id = item->getAssetUUID();
+ // Match by linked inventory item id so the correct copy is found when several
+ // worn wearables of this type share the same asset.
+ const LLUUID item_id = gInventory.getLinkedItemID(item->getUUID());
+ for (U32 i = 0; i < wearable_count; ++i)
+ {
+ const LLViewerWearable* wearable = getViewerWearable(type, i);
+ if (!wearable) continue;
+ if (wearable->getItemID() == item_id) return i;
+ }
+ // Fall back to asset id for items whose inventory id can't be resolved.
+ const LLUUID& asset_id = item->getAssetUUID();
for (U32 i = 0; i < wearable_count; ++i)
{
const LLViewerWearable* wearable = getViewerWearable(type, i);
if (!wearable) continue;
- if (wearable->getAssetID() != asset_id) continue;
- return i;
+ if (wearable->getAssetID() == asset_id) return i;
}
return -1;
@@ -1529,6 +1538,37 @@ bool LLAgentWearables::moveWearable(const LLViewerInventoryItem* item, bool clos
return false;
}
+bool LLAgentWearables::moveWearableToIndex(const LLViewerInventoryItem* item, U32 new_index)
+{
+ if (!item) return false;
+ if (!item->isWearableType()) return false;
+
+ LLWearableType::EType type = item->getWearableType();
+ U32 wearable_count = getWearableCount(type);
+ if (wearable_count < 2) return false;
+
+ if (new_index >= wearable_count) new_index = wearable_count - 1;
+
+ S32 cur = getWearableIdxFromItem(item);
+ if (cur < 0) return false;
+ if ((U32)cur == new_index) return true; // already in place
+
+ // step the wearable to its new slot one swap at a time
+ U32 pos = (U32)cur;
+ while (pos < new_index)
+ {
+ if (!swapWearables(type, pos, pos + 1)) return false;
+ ++pos;
+ }
+ while (pos > new_index)
+ {
+ if (!swapWearables(type, pos, pos - 1)) return false;
+ --pos;
+ }
+
+ return true;
+}
+
// static
void LLAgentWearables::createWearable(LLWearableType::EType type, bool wear, const LLUUID& parent_id, std::function<void(const LLUUID&)> created_cb)
{