From 69f6caac73d406b0f0fe9b913e9d2f439677b279 Mon Sep 17 00:00:00 2001
From: Andrey Kleshchev <andreykproductengine@lindenlab.com>
Date: Fri, 17 Feb 2023 23:08:31 +0200
Subject: SL-19117 Fix thumbnail preview not working for outfits

---
 indra/newview/llinspecttexture.cpp | 57 ++++++++++++++++++++++++++++----------
 1 file changed, 42 insertions(+), 15 deletions(-)

diff --git a/indra/newview/llinspecttexture.cpp b/indra/newview/llinspecttexture.cpp
index 8a8d7ed1bb..de0d65eb7e 100644
--- a/indra/newview/llinspecttexture.cpp
+++ b/indra/newview/llinspecttexture.cpp
@@ -75,11 +75,11 @@ void LLInspectTexture::onOpen(const LLSD& sdData)
 	// Start fade animation
 	LLInspect::onOpen(sdData);
 
-	bool fIsAsset = sdData.has("asset_id");
+	bool fIsAsset = sdData.has("thumbnail_id");
 	bool fIsInventory = sdData.has("item_id");
 
 	// Skip if we're being asked to display the same thing
-	const LLUUID idAsset = (fIsAsset) ? sdData["asset_id"].asUUID() : LLUUID::null;
+	const LLUUID idAsset = (fIsAsset) ? sdData["thumbnail_id"].asUUID() : LLUUID::null;
 	const LLUUID idItem = (fIsInventory) ? sdData["item_id"].asUUID() : LLUUID::null;
 	if ( (getVisible()) && ( ((fIsAsset) && (idAsset == mAssetId)) || ((fIsInventory) && (idItem == mItemId)) ) )
 	{
@@ -134,13 +134,27 @@ BOOL LLInspectTexture::postBuild()
 // Helper functions
 //
 
+class LLIsTextureType : public LLInventoryCollectFunctor
+{
+public:
+    LLIsTextureType() {}
+    virtual ~LLIsTextureType() {}
+    virtual bool operator()(LLInventoryCategory* cat,
+        LLInventoryItem* item);
+};
+
+bool LLIsTextureType::operator()(LLInventoryCategory* cat, LLInventoryItem* item)
+{
+    return item && (item->getType() == LLAssetType::AT_TEXTURE);
+}
+
 LLToolTip* LLInspectTextureUtil::createInventoryToolTip(LLToolTip::Params p)
 {
     const LLSD& sdTooltip = p.create_params;
     
     if (sdTooltip.has("thumbnail_id") && sdTooltip["thumbnail_id"].asUUID().notNull())
     {
-        // go straight for tooltip regardless of type
+        // go straight for thumbnail regardless of type
         return LLUICtrlFactory::create<LLTextureToolTip>(p);
     }
 
@@ -152,18 +166,31 @@ LLToolTip* LLInspectTextureUtil::createInventoryToolTip(LLToolTip::Params p)
 				if (sdTooltip.has("item_id"))
 				{
 					const LLUUID idCategory = sdTooltip["item_id"].asUUID();
-
-					LLInventoryModel::cat_array_t cats;
-					LLInventoryModel::item_array_t items;
-					LLIsOfAssetType f(LLAssetType::AT_TEXTURE);
-					gInventory.getDirectDescendentsOf(idCategory, cats, items, f);
-
-					// Exactly one texture found => show the texture tooltip
-					if (1 == items.size())
-					{
-						p.create_params.getValue()["asset_id"] = items.front()->getAssetUUID();
-						return LLUICtrlFactory::create<LLTextureToolTip>(p);
-					}
+                    LLViewerInventoryCategory* cat = gInventory.getCategory(idCategory);
+                    if (cat && cat->getPreferredType() == LLFolderType::FT_OUTFIT)
+                    {
+                        LLInventoryModel::cat_array_t cats;
+                        LLInventoryModel::item_array_t items;
+                        // Not LLIsOfAssetType, because we allow links
+                        LLIsTextureType f;
+                        gInventory.getDirectDescendentsOf(idCategory, cats, items, f);
+
+                        // Exactly one texture found => show the texture tooltip
+                        if (1 == items.size())
+                        {
+                            LLViewerInventoryItem* item = items.front();
+                            if (item && item->getIsLinkType())
+                            {
+                                item = item->getLinkedItem();
+                            }
+                            if (item)
+                            {
+                                // Todo: write this into folder's thumbnail id
+                                p.create_params.getValue()["thumbnail_id"] = item->getAssetUUID();
+                                return LLUICtrlFactory::create<LLTextureToolTip>(p);
+                            }
+                        }
+                    }
 				}
 
 				// No or more than one texture found => show default tooltip
-- 
cgit v1.2.3