llagentwearables.cpp
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:74k
源码类别:

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file llagentwearables.cpp
  3.  * @brief LLAgentWearables class implementation
  4.  *
  5.  * $LicenseInfo:firstyear=2001&license=viewergpl$
  6.  * 
  7.  * Copyright (c) 2001-2010, Linden Research, Inc.
  8.  * 
  9.  * Second Life Viewer Source Code
  10.  * The source code in this file ("Source Code") is provided by Linden Lab
  11.  * to you under the terms of the GNU General Public License, version 2.0
  12.  * ("GPL"), unless you have obtained a separate licensing agreement
  13.  * ("Other License"), formally executed by you and Linden Lab.  Terms of
  14.  * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15.  * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16.  * 
  17.  * There are special exceptions to the terms and conditions of the GPL as
  18.  * it is applied to this Source Code. View the full text of the exception
  19.  * in the file doc/FLOSS-exception.txt in this software distribution, or
  20.  * online at
  21.  * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22.  * 
  23.  * By copying, modifying or distributing this software, you acknowledge
  24.  * that you have read and understood your obligations described above,
  25.  * and agree to abide by those obligations.
  26.  * 
  27.  * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28.  * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29.  * COMPLETENESS OR PERFORMANCE.
  30.  * $/LicenseInfo$
  31.  */
  32. #include "llviewerprecompiledheaders.h"
  33. #include "llagent.h" 
  34. #include "llagentwearables.h"
  35. #include "llcallbacklist.h"
  36. #include "llfloatercustomize.h"
  37. #include "llinventorybridge.h"
  38. #include "llinventoryobserver.h"
  39. #include "llinventorypanel.h"
  40. #include "llnotificationsutil.h"
  41. #include "llviewerregion.h"
  42. #include "llvoavatarself.h"
  43. #include "llwearable.h"
  44. #include "llwearablelist.h"
  45. #include "llgesturemgr.h"
  46. #include "llappearancemgr.h"
  47. #include "lltexlayer.h"
  48. #include "llsidetray.h"
  49. #include "llpaneloutfitsinventory.h"
  50. #include "llfolderview.h"
  51. #include "llaccordionctrltab.h"
  52. #include <boost/scoped_ptr.hpp>
  53. #define USE_CURRENT_OUTFIT_FOLDER
  54. //--------------------------------------------------------------------
  55. // Classes for fetching initial wearables data
  56. //--------------------------------------------------------------------
  57. // Outfit folder fetching callback structure.
  58. class LLInitialWearablesFetch : public LLInventoryFetchDescendentsObserver
  59. {
  60. public:
  61. LLInitialWearablesFetch() {}
  62. ~LLInitialWearablesFetch();
  63. virtual void done();
  64. struct InitialWearableData
  65. {
  66. EWearableType mType;
  67. LLUUID mItemID;
  68. LLUUID mAssetID;
  69. InitialWearableData(EWearableType type, LLUUID& itemID, LLUUID& assetID) :
  70. mType(type),
  71. mItemID(itemID),
  72. mAssetID(assetID)
  73. {}
  74. };
  75. typedef std::vector<InitialWearableData> initial_wearable_data_vec_t;
  76. initial_wearable_data_vec_t mCOFInitialWearables; // Wearables from the Current Outfit Folder
  77. initial_wearable_data_vec_t mAgentInitialWearables; // Wearables from the old agent wearables msg
  78. protected:
  79. void processWearablesMessage();
  80. void processContents();
  81. };
  82. class LLLibraryOutfitsFetch : public LLInventoryFetchDescendentsObserver
  83. {
  84. public:
  85. enum ELibraryOutfitFetchStep {
  86. LOFS_FOLDER = 0,
  87. LOFS_OUTFITS,
  88. LOFS_LIBRARY,
  89. LOFS_IMPORTED,
  90. LOFS_CONTENTS
  91. };
  92. LLLibraryOutfitsFetch() : mCurrFetchStep(LOFS_FOLDER), mOutfitsPopulated(false) 
  93. {
  94. mMyOutfitsID = LLUUID::null;
  95. mClothingID = LLUUID::null;
  96. mLibraryClothingID = LLUUID::null;
  97. mImportedClothingID = LLUUID::null;
  98. mImportedClothingName = "Imported Library Clothing";
  99. }
  100. ~LLLibraryOutfitsFetch() {}
  101. virtual void done();
  102. void doneIdle();
  103. LLUUID mMyOutfitsID;
  104. void importedFolderFetch();
  105. protected:
  106. void folderDone(void);
  107. void outfitsDone(void);
  108. void libraryDone(void);
  109. void importedFolderDone(void);
  110. void contentsDone(void);
  111. enum ELibraryOutfitFetchStep mCurrFetchStep;
  112. typedef std::vector< std::pair< LLUUID, std::string > > cloth_folder_vec_t;
  113. cloth_folder_vec_t mLibraryClothingFolders;
  114. cloth_folder_vec_t mImportedClothingFolders;
  115. bool mOutfitsPopulated;
  116. LLUUID mClothingID;
  117. LLUUID mLibraryClothingID;
  118. LLUUID mImportedClothingID;
  119. std::string mImportedClothingName;
  120. };
  121. LLAgentWearables gAgentWearables;
  122. BOOL LLAgentWearables::mInitialWearablesUpdateReceived = FALSE;
  123. using namespace LLVOAvatarDefines;
  124. // HACK: For EXT-3923: Pants item shows in inventory with skin icon and messes with "current look"
  125. // Some db items are corrupted, have inventory flags = 0, implying wearable type = shape, even though
  126. // wearable type stored in asset is some other value.
  127. // Calling this function whenever a wearable is added to increase visibility if this problem
  128. // turns up in other inventories.
  129. void checkWearableAgainstInventory(LLWearable *wearable)
  130. {
  131. if (wearable->getItemID().isNull())
  132. return;
  133. // Check for wearable type consistent with inventory item wearable type.
  134. LLViewerInventoryItem *item = gInventory.getItem(wearable->getItemID());
  135. if (item)
  136. {
  137. if (!item->isWearableType())
  138. {
  139. llwarns << "wearable associated with non-wearable item" << llendl;
  140. }
  141. if (item->getWearableType() != wearable->getType())
  142. {
  143. llwarns << "type mismatch: wearable " << wearable->getName()
  144. << " has type " << wearable->getType()
  145. << " but inventory item " << item->getName()
  146. << " has type "  << item->getWearableType() << llendl;
  147. }
  148. }
  149. else
  150. {
  151. llwarns << "wearable inventory item not found" << wearable->getName()
  152. << " itemID " << wearable->getItemID().asString() << llendl;
  153. }
  154. }
  155. void LLAgentWearables::dump()
  156. {
  157. llinfos << "LLAgentWearablesDump" << llendl;
  158. for (S32 i = 0; i < WT_COUNT; i++)
  159. {
  160. U32 count = getWearableCount((EWearableType)i);
  161. llinfos << "Type: " << i << " count " << count << llendl;
  162. for (U32 j=0; j<count; j++)
  163. {
  164. LLWearable* wearable = getWearable((EWearableType)i,j);
  165. if (wearable == NULL)
  166. {
  167. llinfos << "    " << j << " NULL wearable" << llendl;
  168. }
  169. llinfos << "    " << j << " Name " << wearable->getName()
  170. << " description " << wearable->getDescription() << llendl;
  171. }
  172. }
  173. llinfos << "Total items awaiting wearable update " << mItemsAwaitingWearableUpdate.size() << llendl;
  174. for (std::set<LLUUID>::iterator it = mItemsAwaitingWearableUpdate.begin();
  175.  it != mItemsAwaitingWearableUpdate.end();
  176.  ++it)
  177. {
  178. llinfos << (*it).asString() << llendl;
  179. }
  180. }
  181. // MULTI-WEARABLE: debugging
  182. struct LLAgentDumper
  183. {
  184. LLAgentDumper(std::string name):
  185. mName(name)
  186. {
  187. llinfos << llendl;
  188. llinfos << "LLAgentDumper " << mName << llendl;
  189. gAgentWearables.dump();
  190. }
  191. ~LLAgentDumper()
  192. {
  193. llinfos << llendl;
  194. llinfos << "~LLAgentDumper " << mName << llendl;
  195. gAgentWearables.dump();
  196. }
  197. std::string mName;
  198. };
  199. LLAgentWearables::LLAgentWearables() :
  200. mWearablesLoaded(FALSE),
  201. mAvatarObject(NULL)
  202. {
  203. }
  204. LLAgentWearables::~LLAgentWearables()
  205. {
  206. cleanup();
  207. }
  208. void LLAgentWearables::cleanup()
  209. {
  210. mAvatarObject = NULL;
  211. }
  212. void LLAgentWearables::setAvatarObject(LLVOAvatarSelf *avatar)
  213. mAvatarObject = avatar;
  214. if (avatar)
  215. {
  216. sendAgentWearablesRequest();
  217. }
  218. }
  219. // wearables
  220. LLAgentWearables::createStandardWearablesAllDoneCallback::~createStandardWearablesAllDoneCallback()
  221. {
  222. gAgentWearables.createStandardWearablesAllDone();
  223. }
  224. LLAgentWearables::sendAgentWearablesUpdateCallback::~sendAgentWearablesUpdateCallback()
  225. {
  226. gAgentWearables.sendAgentWearablesUpdate();
  227. }
  228. /**
  229.  * @brief Construct a callback for dealing with the wearables.
  230.  *
  231.  * Would like to pass the agent in here, but we can't safely
  232.  * count on it being around later.  Just use gAgent directly.
  233.  * @param cb callback to execute on completion (??? unused ???)
  234.  * @param type Type for the wearable in the agent
  235.  * @param wearable The wearable data.
  236.  * @param todo Bitmask of actions to take on completion.
  237.  */
  238. LLAgentWearables::addWearableToAgentInventoryCallback::addWearableToAgentInventoryCallback(
  239. LLPointer<LLRefCount> cb, S32 type, U32 index, LLWearable* wearable, U32 todo) :
  240. mType(type),
  241. mIndex(index),
  242. mWearable(wearable),
  243. mTodo(todo),
  244. mCB(cb)
  245. {
  246. }
  247. void LLAgentWearables::addWearableToAgentInventoryCallback::fire(const LLUUID& inv_item)
  248. {
  249. if (inv_item.isNull())
  250. return;
  251. gAgentWearables.addWearabletoAgentInventoryDone(mType, mIndex, inv_item, mWearable);
  252. if (mTodo & CALL_UPDATE)
  253. {
  254. gAgentWearables.sendAgentWearablesUpdate();
  255. }
  256. if (mTodo & CALL_RECOVERDONE)
  257. {
  258. gAgentWearables.recoverMissingWearableDone();
  259. }
  260. /*
  261.  * Do this for every one in the loop
  262.  */
  263. if (mTodo & CALL_CREATESTANDARDDONE)
  264. {
  265. gAgentWearables.createStandardWearablesDone(mType, mIndex);
  266. }
  267. if (mTodo & CALL_MAKENEWOUTFITDONE)
  268. {
  269. gAgentWearables.makeNewOutfitDone(mType, mIndex);
  270. }
  271. if (mTodo & CALL_WEARITEM)
  272. {
  273. LLAppearanceManager::instance().addCOFItemLink(inv_item, true);
  274. }
  275. }
  276. void LLAgentWearables::addWearabletoAgentInventoryDone(const S32 type,
  277.    const U32 index,
  278.    const LLUUID& item_id,
  279.    LLWearable* wearable)
  280. {
  281. if (item_id.isNull())
  282. return;
  283. LLUUID old_item_id = getWearableItemID((EWearableType)type,index);
  284. if (wearable)
  285. {
  286. wearable->setItemID(item_id);
  287. if (old_item_id.notNull())
  288. {
  289. gInventory.addChangedMask(LLInventoryObserver::LABEL, old_item_id);
  290. setWearable((EWearableType)type,index,wearable);
  291. }
  292. else
  293. {
  294. pushWearable((EWearableType)type,wearable);
  295. }
  296. }
  297. gInventory.addChangedMask(LLInventoryObserver::LABEL, item_id);
  298. LLViewerInventoryItem* item = gInventory.getItem(item_id);
  299. if (item && wearable)
  300. {
  301. // We're changing the asset id, so we both need to set it
  302. // locally via setAssetUUID() and via setTransactionID() which
  303. // will be decoded on the server. JC
  304. item->setAssetUUID(wearable->getAssetID());
  305. item->setTransactionID(wearable->getTransactionID());
  306. gInventory.addChangedMask(LLInventoryObserver::INTERNAL, item_id);
  307. item->updateServer(FALSE);
  308. }
  309. gInventory.notifyObservers();
  310. }
  311. void LLAgentWearables::sendAgentWearablesUpdate()
  312. {
  313. // MULTI-WEARABLE: call i "type" or something.
  314. // First make sure that we have inventory items for each wearable
  315. for (S32 type=0; type < WT_COUNT; ++type)
  316. {
  317. for (U32 j=0; j < getWearableCount((EWearableType)type); ++j)
  318. {
  319. LLWearable* wearable = getWearable((EWearableType)type,j);
  320. if (wearable)
  321. {
  322. if (wearable->getItemID().isNull())
  323. {
  324. LLPointer<LLInventoryCallback> cb =
  325. new addWearableToAgentInventoryCallback(
  326. LLPointer<LLRefCount>(NULL),
  327. type,
  328. j,
  329. wearable,
  330. addWearableToAgentInventoryCallback::CALL_NONE);
  331. addWearableToAgentInventory(cb, wearable);
  332. }
  333. else
  334. {
  335. gInventory.addChangedMask(LLInventoryObserver::LABEL,
  336.   wearable->getItemID());
  337. }
  338. }
  339. }
  340. }
  341. // Then make sure the inventory is in sync with the avatar.
  342. gInventory.notifyObservers();
  343. // Send the AgentIsNowWearing 
  344. gMessageSystem->newMessageFast(_PREHASH_AgentIsNowWearing);
  345. gMessageSystem->nextBlockFast(_PREHASH_AgentData);
  346. gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
  347. gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
  348. lldebugs << "sendAgentWearablesUpdate()" << llendl;
  349. // MULTI-WEARABLE: update for multi-wearables after server-side support is in.
  350. for (S32 type=0; type < WT_COUNT; ++type)
  351. {
  352. gMessageSystem->nextBlockFast(_PREHASH_WearableData);
  353. U8 type_u8 = (U8)type;
  354. gMessageSystem->addU8Fast(_PREHASH_WearableType, type_u8);
  355. // MULTI-WEARABLE: TODO: hacked index to 0, needs to loop over all once messages support this.
  356. LLWearable* wearable = getWearable((EWearableType)type, 0);
  357. if (wearable)
  358. {
  359. //llinfos << "Sending wearable " << wearable->getName() << llendl;
  360. LLUUID item_id = wearable->getItemID();
  361. const LLViewerInventoryItem *item = gInventory.getItem(item_id);
  362. if (item && item->getIsLinkType())
  363. {
  364. // Get the itemID that this item points to.  i.e. make sure
  365. // we are storing baseitems, not their links, in the database.
  366. item_id = item->getLinkedUUID();
  367. }
  368. gMessageSystem->addUUIDFast(_PREHASH_ItemID, item_id);
  369. }
  370. else
  371. {
  372. //llinfos << "Not wearing wearable type " << LLWearableDictionary::getInstance()->getWearable((EWearableType)i) << llendl;
  373. gMessageSystem->addUUIDFast(_PREHASH_ItemID, LLUUID::null);
  374. }
  375. lldebugs << "       " << LLWearableDictionary::getTypeLabel((EWearableType)type) << ": " << (wearable ? wearable->getAssetID() : LLUUID::null) << llendl;
  376. }
  377. gAgent.sendReliableMessage();
  378. }
  379. void LLAgentWearables::saveWearable(const EWearableType type, const U32 index, BOOL send_update)
  380. {
  381. LLWearable* old_wearable = getWearable(type, index);
  382. if (old_wearable && (old_wearable->isDirty() || old_wearable->isOldVersion()))
  383. {
  384. LLUUID old_item_id = old_wearable->getItemID();
  385. LLWearable* new_wearable = LLWearableList::instance().createCopy(old_wearable);
  386. new_wearable->setItemID(old_item_id); // should this be in LLWearable::copyDataFrom()?
  387. setWearable(type,index,new_wearable);
  388. LLInventoryItem* item = gInventory.getItem(old_item_id);
  389. if (item)
  390. {
  391. // Update existing inventory item
  392. LLPointer<LLViewerInventoryItem> template_item =
  393. new LLViewerInventoryItem(item->getUUID(),
  394.   item->getParentUUID(),
  395.   item->getPermissions(),
  396.   new_wearable->getAssetID(),
  397.   new_wearable->getAssetType(),
  398.   item->getInventoryType(),
  399.   item->getName(),
  400.   item->getDescription(),
  401.   item->getSaleInfo(),
  402.   item->getFlags(),
  403.   item->getCreationDate());
  404. template_item->setTransactionID(new_wearable->getTransactionID());
  405. template_item->updateServer(FALSE);
  406. gInventory.updateItem(template_item);
  407. }
  408. else
  409. {
  410. // Add a new inventory item (shouldn't ever happen here)
  411. U32 todo = addWearableToAgentInventoryCallback::CALL_NONE;
  412. if (send_update)
  413. {
  414. todo |= addWearableToAgentInventoryCallback::CALL_UPDATE;
  415. }
  416. LLPointer<LLInventoryCallback> cb =
  417. new addWearableToAgentInventoryCallback(
  418. LLPointer<LLRefCount>(NULL),
  419. (S32)type,
  420. index,
  421. new_wearable,
  422. todo);
  423. addWearableToAgentInventory(cb, new_wearable);
  424. return;
  425. }
  426. gAgent.getAvatarObject()->wearableUpdated( type, TRUE );
  427. if (send_update)
  428. {
  429. sendAgentWearablesUpdate();
  430. }
  431. }
  432. }
  433. void LLAgentWearables::saveWearableAs(const EWearableType type,
  434.   const U32 index,
  435.   const std::string& new_name,
  436.   BOOL save_in_lost_and_found)
  437. {
  438. if (!isWearableCopyable(type, index))
  439. {
  440. llwarns << "LLAgent::saveWearableAs() not copyable." << llendl;
  441. return;
  442. }
  443. LLWearable* old_wearable = getWearable(type, index);
  444. if (!old_wearable)
  445. {
  446. llwarns << "LLAgent::saveWearableAs() no old wearable." << llendl;
  447. return;
  448. }
  449. LLInventoryItem* item = gInventory.getItem(getWearableItemID(type,index));
  450. if (!item)
  451. {
  452. llwarns << "LLAgent::saveWearableAs() no inventory item." << llendl;
  453. return;
  454. }
  455. std::string trunc_name(new_name);
  456. LLStringUtil::truncate(trunc_name, DB_INV_ITEM_NAME_STR_LEN);
  457. LLWearable* new_wearable = LLWearableList::instance().createCopy(
  458. old_wearable,
  459. trunc_name);
  460. LLPointer<LLInventoryCallback> cb =
  461. new addWearableToAgentInventoryCallback(
  462. LLPointer<LLRefCount>(NULL),
  463. type,
  464. index,
  465. new_wearable,
  466. addWearableToAgentInventoryCallback::CALL_WEARITEM);
  467. LLUUID category_id;
  468. if (save_in_lost_and_found)
  469. {
  470. category_id = gInventory.findCategoryUUIDForType(
  471. LLFolderType::FT_LOST_AND_FOUND);
  472. }
  473. else
  474. {
  475. // put in same folder as original
  476. category_id = item->getParentUUID();
  477. }
  478. copy_inventory_item(
  479. gAgent.getID(),
  480. item->getPermissions().getOwner(),
  481. item->getUUID(),
  482. category_id,
  483. new_name,
  484. cb);
  485. }
  486. void LLAgentWearables::revertWearable(const EWearableType type, const U32 index)
  487. {
  488. LLWearable* wearable = getWearable(type, index);
  489. wearable->revertValues();
  490. gAgent.sendAgentSetAppearance();
  491. }
  492. void LLAgentWearables::saveAllWearables()
  493. {
  494. //if (!gInventory.isLoaded())
  495. //{
  496. // return;
  497. //}
  498. for (S32 i=0; i < WT_COUNT; i++)
  499. {
  500. for (U32 j=0; j < getWearableCount((EWearableType)i); j++)
  501. saveWearable((EWearableType)i, j, FALSE);
  502. }
  503. sendAgentWearablesUpdate();
  504. }
  505. // Called when the user changes the name of a wearable inventory item that is currently being worn.
  506. void LLAgentWearables::setWearableName(const LLUUID& item_id, const std::string& new_name)
  507. {
  508. for (S32 i=0; i < WT_COUNT; i++)
  509. {
  510. for (U32 j=0; j < getWearableCount((EWearableType)i); j++)
  511. {
  512. LLUUID curr_item_id = getWearableItemID((EWearableType)i,j);
  513. if (curr_item_id == item_id)
  514. {
  515. LLWearable* old_wearable = getWearable((EWearableType)i,j);
  516. llassert(old_wearable);
  517. std::string old_name = old_wearable->getName();
  518. old_wearable->setName(new_name);
  519. LLWearable* new_wearable = LLWearableList::instance().createCopy(old_wearable);
  520. new_wearable->setItemID(item_id);
  521. LLInventoryItem* item = gInventory.getItem(item_id);
  522. if (item)
  523. {
  524. new_wearable->setPermissions(item->getPermissions());
  525. }
  526. old_wearable->setName(old_name);
  527. setWearable((EWearableType)i,j,new_wearable);
  528. sendAgentWearablesUpdate();
  529. break;
  530. }
  531. }
  532. }
  533. }
  534. BOOL LLAgentWearables::isWearableModifiable(EWearableType type, U32 index) const
  535. {
  536. LLUUID item_id = getWearableItemID(type, index);
  537. if (!item_id.isNull())
  538. {
  539. LLInventoryItem* item = gInventory.getItem(item_id);
  540. if (item && item->getPermissions().allowModifyBy(gAgent.getID(),
  541.  gAgent.getGroupID()))
  542. {
  543. return TRUE;
  544. }
  545. }
  546. return FALSE;
  547. }
  548. BOOL LLAgentWearables::isWearableCopyable(EWearableType type, U32 index) const
  549. {
  550. LLUUID item_id = getWearableItemID(type, index);
  551. if (!item_id.isNull())
  552. {
  553. LLInventoryItem* item = gInventory.getItem(item_id);
  554. if (item && item->getPermissions().allowCopyBy(gAgent.getID(),
  555.    gAgent.getGroupID()))
  556. {
  557. return TRUE;
  558. }
  559. }
  560. return FALSE;
  561. }
  562. /*
  563.   U32 LLAgentWearables::getWearablePermMask(EWearableType type)
  564.   {
  565.   LLUUID item_id = getWearableItemID(type);
  566.   if (!item_id.isNull())
  567.   {
  568.   LLInventoryItem* item = gInventory.getItem(item_id);
  569.   if (item)
  570.   {
  571.   return item->getPermissions().getMaskOwner();
  572.   }
  573.   }
  574.   return PERM_NONE;
  575.   }
  576. */
  577. LLInventoryItem* LLAgentWearables::getWearableInventoryItem(EWearableType type, U32 index)
  578. {
  579. LLUUID item_id = getWearableItemID(type,index);
  580. LLInventoryItem* item = NULL;
  581. if (item_id.notNull())
  582. {
  583. item = gInventory.getItem(item_id);
  584. }
  585. return item;
  586. }
  587. const LLWearable* LLAgentWearables::getWearableFromItemID(const LLUUID& item_id) const
  588. {
  589. for (S32 i=0; i < WT_COUNT; i++)
  590. {
  591. for (U32 j=0; j < getWearableCount((EWearableType)i); j++)
  592. {
  593. const LLWearable * curr_wearable = getWearable((EWearableType)i, j);
  594. if (curr_wearable && (curr_wearable->getItemID() == item_id))
  595. {
  596. return curr_wearable;
  597. }
  598. }
  599. }
  600. return NULL;
  601. }
  602. const LLWearable* LLAgentWearables::getWearableFromAssetID(const LLUUID& asset_id) const
  603. {
  604. for (S32 i=0; i < WT_COUNT; i++)
  605. {
  606. for (U32 j=0; j < getWearableCount((EWearableType)i); j++)
  607. {
  608. const LLWearable * curr_wearable = getWearable((EWearableType)i, j);
  609. if (curr_wearable && (curr_wearable->getAssetID() == asset_id))
  610. {
  611. return curr_wearable;
  612. }
  613. }
  614. }
  615. return NULL;
  616. }
  617. void LLAgentWearables::sendAgentWearablesRequest()
  618. {
  619. gMessageSystem->newMessageFast(_PREHASH_AgentWearablesRequest);
  620. gMessageSystem->nextBlockFast(_PREHASH_AgentData);
  621. gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
  622. gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
  623. gAgent.sendReliableMessage();
  624. }
  625. // static
  626. BOOL LLAgentWearables::selfHasWearable(EWearableType type)
  627. {
  628. return (gAgentWearables.getWearableCount(type) > 0);
  629. }
  630. LLWearable* LLAgentWearables::getWearable(const EWearableType type, U32 index)
  631. {
  632. wearableentry_map_t::iterator wearable_iter = mWearableDatas.find(type);
  633. if (wearable_iter == mWearableDatas.end())
  634. {
  635. return NULL;
  636. }
  637. wearableentry_vec_t& wearable_vec = wearable_iter->second;
  638. if (index>=wearable_vec.size())
  639. {
  640. return NULL;
  641. }
  642. else
  643. {
  644. return wearable_vec[index];
  645. }
  646. }
  647. void LLAgentWearables::setWearable(const EWearableType type, U32 index, LLWearable *wearable)
  648. {
  649. LLWearable *old_wearable = getWearable(type,index);
  650. if (!old_wearable)
  651. {
  652. pushWearable(type,wearable);
  653. return;
  654. }
  655. wearableentry_map_t::iterator wearable_iter = mWearableDatas.find(type);
  656. if (wearable_iter == mWearableDatas.end())
  657. {
  658. llwarns << "invalid type, type " << type << " index " << index << llendl; 
  659. return;
  660. }
  661. wearableentry_vec_t& wearable_vec = wearable_iter->second;
  662. if (index>=wearable_vec.size())
  663. {
  664. llwarns << "invalid index, type " << type << " index " << index << llendl; 
  665. }
  666. else
  667. {
  668. wearable_vec[index] = wearable;
  669. old_wearable->setLabelUpdated();
  670. wearableUpdated(wearable);
  671. checkWearableAgainstInventory(wearable);
  672. }
  673. }
  674. U32 LLAgentWearables::pushWearable(const EWearableType type, LLWearable *wearable)
  675. {
  676. if (wearable == NULL)
  677. {
  678. // no null wearables please!
  679. llwarns << "Null wearable sent for type " << type << llendl;
  680. return MAX_WEARABLES_PER_TYPE;
  681. }
  682. if (type < WT_COUNT || mWearableDatas[type].size() < MAX_WEARABLES_PER_TYPE)
  683. {
  684. mWearableDatas[type].push_back(wearable);
  685. wearableUpdated(wearable);
  686. checkWearableAgainstInventory(wearable);
  687. return mWearableDatas[type].size()-1;
  688. }
  689. return MAX_WEARABLES_PER_TYPE;
  690. }
  691. void LLAgentWearables::wearableUpdated(LLWearable *wearable)
  692. {
  693. mAvatarObject->wearableUpdated(wearable->getType(), TRUE);
  694. wearable->refreshName();
  695. wearable->setLabelUpdated();
  696. wearable->pullCrossWearableValues();
  697. // Hack pt 2. If the wearable we just loaded has definition version 24,
  698. // then force a re-save of this wearable after slamming the version number to 22.
  699. // This number was incorrectly incremented for internal builds before release, and
  700. // this fix will ensure that the affected wearables are re-saved with the right version number.
  701. // the versions themselves are compatible. This code can be removed before release.
  702. if( wearable->getDefinitionVersion() == 24 )
  703. {
  704. wearable->setDefinitionVersion(22);
  705. U32 index = getWearableIndex(wearable);
  706. llinfos << "forcing werable type " << wearable->getType() << " to version 22 from 24" << llendl;
  707. saveWearable(wearable->getType(),index,TRUE);
  708. }
  709. }
  710. void LLAgentWearables::popWearable(LLWearable *wearable)
  711. {
  712. if (wearable == NULL)
  713. {
  714. // nothing to do here. move along.
  715. return;
  716. }
  717. U32 index = getWearableIndex(wearable);
  718. EWearableType type = wearable->getType();
  719. if (index < MAX_WEARABLES_PER_TYPE && index < getWearableCount(type))
  720. {
  721. popWearable(type, index);
  722. }
  723. }
  724. void LLAgentWearables::popWearable(const EWearableType type, U32 index)
  725. {
  726. LLWearable *wearable = getWearable(type, index);
  727. if (wearable)
  728. {
  729. mWearableDatas[type].erase(mWearableDatas[type].begin() + index);
  730. mAvatarObject->wearableUpdated(wearable->getType(), TRUE);
  731. wearable->setLabelUpdated();
  732. }
  733. }
  734. U32 LLAgentWearables::getWearableIndex(LLWearable *wearable)
  735. {
  736. if (wearable == NULL)
  737. {
  738. return MAX_WEARABLES_PER_TYPE;
  739. }
  740. const EWearableType type = wearable->getType();
  741. wearableentry_map_t::const_iterator wearable_iter = mWearableDatas.find(type);
  742. if (wearable_iter == mWearableDatas.end())
  743. {
  744. llwarns << "tried to get wearable index with an invalid type!" << llendl;
  745. return MAX_WEARABLES_PER_TYPE;
  746. }
  747. const wearableentry_vec_t& wearable_vec = wearable_iter->second;
  748. for(U32 index = 0; index < wearable_vec.size(); index++)
  749. {
  750. if (wearable_vec[index] == wearable)
  751. {
  752. return index;
  753. }
  754. }
  755. return MAX_WEARABLES_PER_TYPE;
  756. }
  757. const LLWearable* LLAgentWearables::getWearable(const EWearableType type, U32 index) const
  758. {
  759. wearableentry_map_t::const_iterator wearable_iter = mWearableDatas.find(type);
  760. if (wearable_iter == mWearableDatas.end())
  761. {
  762. return NULL;
  763. }
  764. const wearableentry_vec_t& wearable_vec = wearable_iter->second;
  765. if (index>=wearable_vec.size())
  766. {
  767. return NULL;
  768. }
  769. else
  770. {
  771. return wearable_vec[index];
  772. }
  773. }
  774. LLWearable* LLAgentWearables::getTopWearable(const EWearableType type)
  775. {
  776. U32 count = getWearableCount(type);
  777. if ( count == 0)
  778. {
  779. return NULL;
  780. }
  781. return getWearable(type, count-1);
  782. }
  783. U32 LLAgentWearables::getWearableCount(const EWearableType type) const
  784. {
  785. wearableentry_map_t::const_iterator wearable_iter = mWearableDatas.find(type);
  786. if (wearable_iter == mWearableDatas.end())
  787. {
  788. return 0;
  789. }
  790. const wearableentry_vec_t& wearable_vec = wearable_iter->second;
  791. return wearable_vec.size();
  792. }
  793. U32 LLAgentWearables::getWearableCount(const U32 tex_index) const
  794. {
  795. const EWearableType wearable_type = LLVOAvatarDictionary::getTEWearableType((LLVOAvatarDefines::ETextureIndex)tex_index);
  796. return getWearableCount(wearable_type);
  797. }
  798. BOOL LLAgentWearables::itemUpdatePending(const LLUUID& item_id) const
  799. {
  800. return mItemsAwaitingWearableUpdate.find(item_id) != mItemsAwaitingWearableUpdate.end();
  801. }
  802. U32 LLAgentWearables::itemUpdatePendingCount() const
  803. {
  804. return mItemsAwaitingWearableUpdate.size();
  805. }
  806. const LLUUID LLAgentWearables::getWearableItemID(EWearableType type, U32 index) const
  807. {
  808. const LLWearable *wearable = getWearable(type,index);
  809. if (wearable)
  810. return wearable->getItemID();
  811. else
  812. return LLUUID();
  813. }
  814. const LLUUID LLAgentWearables::getWearableAssetID(EWearableType type, U32 index) const
  815. {
  816. const LLWearable *wearable = getWearable(type,index);
  817. if (wearable)
  818. return wearable->getAssetID();
  819. else
  820. return LLUUID();
  821. }
  822. BOOL LLAgentWearables::isWearingItem(const LLUUID& item_id) const
  823. {
  824. const LLUUID& base_item_id = gInventory.getLinkedItemID(item_id);
  825. if (getWearableFromItemID(base_item_id) != NULL) 
  826. {
  827. return TRUE;
  828. }
  829. return FALSE;
  830. }
  831. // MULTI-WEARABLE: update for multiple
  832. // static
  833. // ! BACKWARDS COMPATIBILITY ! When we stop supporting viewer1.23, we can assume
  834. // that viewers have a Current Outfit Folder and won't need this message, and thus
  835. // we can remove/ignore this whole function.
  836. void LLAgentWearables::processAgentInitialWearablesUpdate(LLMessageSystem* mesgsys, void** user_data)
  837. {
  838. // We should only receive this message a single time.  Ignore subsequent AgentWearablesUpdates
  839. // that may result from AgentWearablesRequest having been sent more than once.
  840. if (mInitialWearablesUpdateReceived)
  841. return;
  842. mInitialWearablesUpdateReceived = true;
  843. LLUUID agent_id;
  844. gMessageSystem->getUUIDFast(_PREHASH_AgentData, _PREHASH_AgentID, agent_id);
  845. LLVOAvatar* avatar = gAgent.getAvatarObject();
  846. if (avatar && (agent_id == avatar->getID()))
  847. {
  848. gMessageSystem->getU32Fast(_PREHASH_AgentData, _PREHASH_SerialNum, gAgentQueryManager.mUpdateSerialNum);
  849. const S32 NUM_BODY_PARTS = 4;
  850. S32 num_wearables = gMessageSystem->getNumberOfBlocksFast(_PREHASH_WearableData);
  851. if (num_wearables < NUM_BODY_PARTS)
  852. {
  853. // Transitional state.  Avatars should always have at least their body parts (hair, eyes, shape and skin).
  854. // The fact that they don't have any here (only a dummy is sent) implies that either:
  855. // 1. This account existed before we had wearables
  856. // 2. The database has gotten messed up
  857. // 3. This is the account's first login (i.e. the wearables haven't been generated yet).
  858. return;
  859. }
  860. // Get the UUID of the current outfit folder (will be created if it doesn't exist)
  861. const LLUUID current_outfit_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_CURRENT_OUTFIT);
  862. LLInitialWearablesFetch* outfit = new LLInitialWearablesFetch();
  863. //lldebugs << "processAgentInitialWearablesUpdate()" << llendl;
  864. // Add wearables
  865. // MULTI-WEARABLE: TODO: update once messages change.  Currently use results to populate the zeroth element.
  866. gAgentWearables.mItemsAwaitingWearableUpdate.clear();
  867. for (S32 i=0; i < num_wearables; i++)
  868. {
  869. // Parse initial wearables data from message system
  870. U8 type_u8 = 0;
  871. gMessageSystem->getU8Fast(_PREHASH_WearableData, _PREHASH_WearableType, type_u8, i);
  872. if (type_u8 >= WT_COUNT)
  873. {
  874. continue;
  875. }
  876. const EWearableType type = (EWearableType) type_u8;
  877. LLUUID item_id;
  878. gMessageSystem->getUUIDFast(_PREHASH_WearableData, _PREHASH_ItemID, item_id, i);
  879. LLUUID asset_id;
  880. gMessageSystem->getUUIDFast(_PREHASH_WearableData, _PREHASH_AssetID, asset_id, i);
  881. if (asset_id.isNull())
  882. {
  883. LLWearable::removeFromAvatar(type, FALSE);
  884. }
  885. else
  886. {
  887. LLAssetType::EType asset_type = LLWearableDictionary::getAssetType(type);
  888. if (asset_type == LLAssetType::AT_NONE)
  889. {
  890. continue;
  891. }
  892. // MULTI-WEARABLE: TODO: update once messages change.  Currently use results to populate the zeroth element.
  893. // Store initial wearables data until we know whether we have the current outfit folder or need to use the data.
  894. LLInitialWearablesFetch::InitialWearableData wearable_data(type, item_id, asset_id); // MULTI-WEARABLE: update
  895. outfit->mAgentInitialWearables.push_back(wearable_data);
  896. }
  897. lldebugs << "       " << LLWearableDictionary::getTypeLabel(type) << llendl;
  898. }
  899. // Get the complete information on the items in the inventory and set up an observer
  900. // that will trigger when the complete information is fetched.
  901. LLInventoryFetchDescendentsObserver::folder_ref_t folders;
  902. folders.push_back(current_outfit_id);
  903. outfit->fetchDescendents(folders);
  904. if(outfit->isEverythingComplete())
  905. {
  906. // everything is already here - call done.
  907. outfit->done();
  908. }
  909. else
  910. {
  911. // it's all on it's way - add an observer, and the inventory
  912. // will call done for us when everything is here.
  913. gInventory.addObserver(outfit);
  914. }
  915. }
  916. }
  917. // A single wearable that the avatar was wearing on start-up has arrived from the database.
  918. // static
  919. void LLAgentWearables::onInitialWearableAssetArrived(LLWearable* wearable, void* userdata)
  920. {
  921. boost::scoped_ptr<LLInitialWearablesFetch::InitialWearableData> wear_data((LLInitialWearablesFetch::InitialWearableData*)userdata); 
  922. const EWearableType type = wear_data->mType;
  923. U32 index = 0;
  924. LLVOAvatarSelf* avatar = gAgent.getAvatarObject();
  925. if (!avatar)
  926. {
  927. return;
  928. }
  929. if (wearable)
  930. {
  931. llassert(type == wearable->getType());
  932. wearable->setItemID(wear_data->mItemID);
  933. index = gAgentWearables.pushWearable(type, wearable);
  934. gAgentWearables.mItemsAwaitingWearableUpdate.erase(wear_data->mItemID);
  935. // disable composites if initial textures are baked
  936. avatar->setupComposites();
  937. avatar->setCompositeUpdatesEnabled(TRUE);
  938. gInventory.addChangedMask(LLInventoryObserver::LABEL, wearable->getItemID());
  939. }
  940. else
  941. {
  942. // Somehow the asset doesn't exist in the database.
  943. gAgentWearables.recoverMissingWearable(type,index);
  944. }
  945. gInventory.notifyObservers();
  946. // Have all the wearables that the avatar was wearing at log-in arrived?
  947. // MULTI-WEARABLE: update when multiple wearables can arrive per type.
  948. gAgentWearables.updateWearablesLoaded();
  949. if (gAgentWearables.areWearablesLoaded())
  950. {
  951. // Can't query cache until all wearables have arrived, so calling this earlier is a no-op.
  952. gAgentWearables.queryWearableCache();
  953. // Make sure that the server's idea of the avatar's wearables actually match the wearables.
  954. gAgent.sendAgentSetAppearance();
  955. // Check to see if there are any baked textures that we hadn't uploaded before we logged off last time.
  956. // If there are any, schedule them to be uploaded as soon as the layer textures they depend on arrive.
  957. if (gAgent.cameraCustomizeAvatar())
  958. {
  959. avatar->requestLayerSetUploads();
  960. }
  961. }
  962. }
  963. // Normally, all wearables referred to "AgentWearablesUpdate" will correspond to actual assets in the
  964. // database.  If for some reason, we can't load one of those assets, we can try to reconstruct it so that
  965. // the user isn't left without a shape, for example.  (We can do that only after the inventory has loaded.)
  966. void LLAgentWearables::recoverMissingWearable(const EWearableType type, U32 index)
  967. {
  968. // Try to recover by replacing missing wearable with a new one.
  969. LLNotificationsUtil::add("ReplacedMissingWearable");
  970. lldebugs << "Wearable " << LLWearableDictionary::getTypeLabel(type) << " could not be downloaded.  Replaced inventory item with default wearable." << llendl;
  971. LLWearable* new_wearable = LLWearableList::instance().createNewWearable(type);
  972. S32 type_s32 = (S32) type;
  973. setWearable(type,index,new_wearable);
  974. //new_wearable->writeToAvatar(TRUE);
  975. // Add a new one in the lost and found folder.
  976. // (We used to overwrite the "not found" one, but that could potentially
  977. // destory content.) JC
  978. const LLUUID lost_and_found_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_LOST_AND_FOUND);
  979. LLPointer<LLInventoryCallback> cb =
  980. new addWearableToAgentInventoryCallback(
  981. LLPointer<LLRefCount>(NULL),
  982. type_s32,
  983. index,
  984. new_wearable,
  985. addWearableToAgentInventoryCallback::CALL_RECOVERDONE);
  986. addWearableToAgentInventory(cb, new_wearable, lost_and_found_id, TRUE);
  987. }
  988. void LLAgentWearables::recoverMissingWearableDone()
  989. {
  990. // Have all the wearables that the avatar was wearing at log-in arrived or been fabricated?
  991. updateWearablesLoaded();
  992. if (areWearablesLoaded())
  993. {
  994. // Make sure that the server's idea of the avatar's wearables actually match the wearables.
  995. gAgent.sendAgentSetAppearance();
  996. }
  997. else
  998. {
  999. gInventory.addChangedMask(LLInventoryObserver::LABEL, LLUUID::null);
  1000. gInventory.notifyObservers();
  1001. }
  1002. }
  1003. void LLAgentWearables::addLocalTextureObject(const EWearableType wearable_type, const LLVOAvatarDefines::ETextureIndex texture_type, U32 wearable_index)
  1004. {
  1005. LLWearable* wearable = getWearable((EWearableType)wearable_type, wearable_index);
  1006. if (!wearable)
  1007. {
  1008. llerrs << "Tried to add local texture object to invalid wearable with type " << wearable_type << " and index " << wearable_index << llendl;
  1009. return;
  1010. }
  1011. LLLocalTextureObject lto;
  1012. wearable->setLocalTextureObject(texture_type, lto);
  1013. }
  1014. void LLAgentWearables::createStandardWearables(BOOL female)
  1015. {
  1016. llwarns << "Creating Standard " << (female ? "female" : "male")
  1017. << " Wearables" << llendl;
  1018. if (mAvatarObject.isNull())
  1019. {
  1020. return;
  1021. }
  1022. mAvatarObject->setSex(female ? SEX_FEMALE : SEX_MALE);
  1023. const BOOL create[WT_COUNT] = 
  1024. {
  1025. TRUE,  //WT_SHAPE
  1026. TRUE,  //WT_SKIN
  1027. TRUE,  //WT_HAIR
  1028. TRUE,  //WT_EYES
  1029. TRUE,  //WT_SHIRT
  1030. TRUE,  //WT_PANTS
  1031. TRUE,  //WT_SHOES
  1032. TRUE,  //WT_SOCKS
  1033. FALSE, //WT_JACKET
  1034. FALSE, //WT_GLOVES
  1035. TRUE,  //WT_UNDERSHIRT
  1036. TRUE,  //WT_UNDERPANTS
  1037. FALSE  //WT_SKIRT
  1038. };
  1039. for (S32 i=0; i < WT_COUNT; i++)
  1040. {
  1041. bool once = false;
  1042. LLPointer<LLRefCount> donecb = NULL;
  1043. if (create[i])
  1044. {
  1045. if (!once)
  1046. {
  1047. once = true;
  1048. donecb = new createStandardWearablesAllDoneCallback;
  1049. }
  1050. llassert(getWearableCount((EWearableType)i) == 0);
  1051. LLWearable* wearable = LLWearableList::instance().createNewWearable((EWearableType)i);
  1052. U32 index = pushWearable((EWearableType)i,wearable);
  1053. // no need to update here...
  1054. LLPointer<LLInventoryCallback> cb =
  1055. new addWearableToAgentInventoryCallback(
  1056. donecb,
  1057. i,
  1058. index,
  1059. wearable,
  1060. addWearableToAgentInventoryCallback::CALL_CREATESTANDARDDONE);
  1061. addWearableToAgentInventory(cb, wearable, LLUUID::null, FALSE);
  1062. }
  1063. }
  1064. }
  1065. void LLAgentWearables::createStandardWearablesDone(S32 type, U32 index)
  1066. {
  1067. if (mAvatarObject)
  1068. {
  1069. mAvatarObject->updateVisualParams();
  1070. }
  1071. }
  1072. void LLAgentWearables::createStandardWearablesAllDone()
  1073. {
  1074. // ... because sendAgentWearablesUpdate will notify inventory
  1075. // observers.
  1076. mWearablesLoaded = TRUE; 
  1077. checkWearablesLoaded();
  1078. updateServer();
  1079. // Treat this as the first texture entry message, if none received yet
  1080. mAvatarObject->onFirstTEMessageReceived();
  1081. }
  1082. // MULTI-WEARABLE: Properly handle multiwearables later.
  1083. void LLAgentWearables::getAllWearablesArray(LLDynamicArray<S32>& wearables)
  1084. {
  1085. for( S32 i = 0; i < WT_COUNT; ++i )
  1086. {
  1087. if (getWearableCount((EWearableType) i) !=  0)
  1088. {
  1089. wearables.push_back(i);
  1090. }
  1091. }
  1092. }
  1093. // Note: wearables_to_include should be a list of EWearableType types
  1094. // attachments_to_include should be a list of attachment points
  1095. void LLAgentWearables::makeNewOutfit(const std::string& new_folder_name,
  1096.  const LLDynamicArray<S32>& wearables_to_include,
  1097.  const LLDynamicArray<S32>& attachments_to_include,
  1098.  BOOL rename_clothing)
  1099. {
  1100. if (mAvatarObject.isNull())
  1101. {
  1102. return;
  1103. }
  1104. // First, make a folder in the Clothes directory.
  1105. LLUUID folder_id = gInventory.createNewCategory(
  1106. gInventory.findCategoryUUIDForType(LLFolderType::FT_CLOTHING),
  1107. LLFolderType::FT_NONE,
  1108. new_folder_name);
  1109. bool found_first_item = false;
  1110. ///////////////////
  1111. // Wearables
  1112. if (wearables_to_include.count())
  1113. {
  1114. // Then, iterate though each of the wearables and save copies of them in the folder.
  1115. S32 i;
  1116. S32 count = wearables_to_include.count();
  1117. LLDynamicArray<LLUUID> delete_items;
  1118. LLPointer<LLRefCount> cbdone = NULL;
  1119. for (i = 0; i < count; ++i)
  1120. {
  1121. const S32 type = wearables_to_include[i];
  1122. for (U32 j=0; j<getWearableCount((EWearableType)i); j++)
  1123. {
  1124. LLWearable* old_wearable = getWearable((EWearableType)type, j);
  1125. if (old_wearable)
  1126. {
  1127. std::string new_name;
  1128. LLWearable* new_wearable;
  1129. new_wearable = LLWearableList::instance().createCopy(old_wearable);
  1130. if (rename_clothing)
  1131. {
  1132. new_name = new_folder_name;
  1133. new_name.append(" ");
  1134. new_name.append(old_wearable->getTypeLabel());
  1135. LLStringUtil::truncate(new_name, DB_INV_ITEM_NAME_STR_LEN);
  1136. new_wearable->setName(new_name);
  1137. }
  1138. LLViewerInventoryItem* item = gInventory.getItem(getWearableItemID((EWearableType)type,j));
  1139. S32 todo = addWearableToAgentInventoryCallback::CALL_NONE;
  1140. if (!found_first_item)
  1141. {
  1142. found_first_item = true;
  1143. /* set the focus to the first item */
  1144. todo |= addWearableToAgentInventoryCallback::CALL_MAKENEWOUTFITDONE;
  1145. /* send the agent wearables update when done */
  1146. cbdone = new sendAgentWearablesUpdateCallback;
  1147. }
  1148. LLPointer<LLInventoryCallback> cb =
  1149. new addWearableToAgentInventoryCallback(
  1150. cbdone,
  1151. type,
  1152. j,
  1153. new_wearable,
  1154. todo);
  1155. llassert(item);
  1156. if (item)
  1157. {
  1158. if (isWearableCopyable((EWearableType)type, j))
  1159. {
  1160. copy_inventory_item(
  1161.     gAgent.getID(),
  1162.     item->getPermissions().getOwner(),
  1163.     item->getUUID(),
  1164.     folder_id,
  1165.     new_name,
  1166.     cb);
  1167. }
  1168. else
  1169. {
  1170. move_inventory_item(
  1171.     gAgent.getID(),
  1172.     gAgent.getSessionID(),
  1173.     item->getUUID(),
  1174.     folder_id,
  1175.     new_name,
  1176.     cb);
  1177. }
  1178. }
  1179. }
  1180. }
  1181. }
  1182. gInventory.notifyObservers();
  1183. }
  1184. ///////////////////
  1185. // Attachments
  1186. if (attachments_to_include.count())
  1187. {
  1188. BOOL msg_started = FALSE;
  1189. LLMessageSystem* msg = gMessageSystem;
  1190. for (S32 i = 0; i < attachments_to_include.count(); i++)
  1191. {
  1192. S32 attachment_pt = attachments_to_include[i];
  1193. LLViewerJointAttachment* attachment = get_if_there(mAvatarObject->mAttachmentPoints, attachment_pt, (LLViewerJointAttachment*)NULL);
  1194. if (!attachment) continue;
  1195. for (LLViewerJointAttachment::attachedobjs_vec_t::iterator attachment_iter = attachment->mAttachedObjects.begin();
  1196.  attachment_iter != attachment->mAttachedObjects.end();
  1197.  ++attachment_iter)
  1198. {
  1199. LLViewerObject *attached_object = (*attachment_iter);
  1200. if(!attached_object) continue;
  1201. const LLUUID& item_id = (*attachment_iter)->getItemID();
  1202. if(item_id.isNull()) continue;
  1203. LLInventoryItem* item = gInventory.getItem(item_id);
  1204. if(!item) continue;
  1205. if(!msg_started)
  1206. {
  1207. msg_started = TRUE;
  1208. msg->newMessage("CreateNewOutfitAttachments");
  1209. msg->nextBlock("AgentData");
  1210. msg->addUUID("AgentID", gAgent.getID());
  1211. msg->addUUID("SessionID", gAgent.getSessionID());
  1212. msg->nextBlock("HeaderData");
  1213. msg->addUUID("NewFolderID", folder_id);
  1214. }
  1215. msg->nextBlock("ObjectData");
  1216. msg->addUUID("OldItemID", item_id);
  1217. msg->addUUID("OldFolderID", item->getParentUUID());
  1218. }
  1219. }
  1220. if (msg_started)
  1221. {
  1222. gAgent.sendReliableMessage();
  1223. }
  1224. }
  1225. class LLShowCreatedOutfit: public LLInventoryCallback
  1226. {
  1227. public:
  1228. LLShowCreatedOutfit(LLUUID& folder_id):
  1229. mFolderID(folder_id)
  1230. {
  1231. }
  1232. virtual ~LLShowCreatedOutfit()
  1233. {
  1234. LLSD key;
  1235. LLSideTray::getInstance()->showPanel("panel_outfits_inventory", key);
  1236. LLPanelOutfitsInventory *outfit_panel =
  1237. dynamic_cast<LLPanelOutfitsInventory*>(LLSideTray::getInstance()->getPanel("panel_outfits_inventory"));
  1238. if (outfit_panel)
  1239. {
  1240. outfit_panel->getRootFolder()->clearSelection();
  1241. outfit_panel->getRootFolder()->setSelectionByID(mFolderID, TRUE);
  1242. }
  1243. LLAccordionCtrlTab* tab_outfits = outfit_panel ? outfit_panel->findChild<LLAccordionCtrlTab>("tab_outfits") : 0;
  1244. if (tab_outfits && !tab_outfits->getDisplayChildren())
  1245. {
  1246. tab_outfits->changeOpenClose(tab_outfits->getDisplayChildren());
  1247. }
  1248. LLAppearanceManager::instance().updateIsDirty();
  1249. LLAppearanceManager::instance().updatePanelOutfitName("");
  1250. }
  1251. virtual void fire(const LLUUID&)
  1252. {
  1253. }
  1254. private:
  1255. LLUUID mFolderID;
  1256. };
  1257. LLUUID LLAgentWearables::makeNewOutfitLinks(const std::string& new_folder_name)
  1258. {
  1259. if (mAvatarObject.isNull())
  1260. {
  1261. return LLUUID::null;
  1262. }
  1263. // First, make a folder in the My Outfits directory.
  1264. const LLUUID parent_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_MY_OUTFITS);
  1265. LLUUID folder_id = gInventory.createNewCategory(
  1266. parent_id,
  1267. LLFolderType::FT_OUTFIT,
  1268. new_folder_name);
  1269. LLPointer<LLInventoryCallback> cb = new LLShowCreatedOutfit(folder_id);
  1270. LLAppearanceManager::instance().shallowCopyCategoryContents(LLAppearanceManager::instance().getCOF(),folder_id, cb);
  1271. LLAppearanceManager::instance().createBaseOutfitLink(folder_id, cb);
  1272. return folder_id;
  1273. }
  1274. void LLAgentWearables::makeNewOutfitDone(S32 type, U32 index)
  1275. {
  1276. LLUUID first_item_id = getWearableItemID((EWearableType)type, index);
  1277. // Open the inventory and select the first item we added.
  1278. if (first_item_id.notNull())
  1279. {
  1280. LLInventoryPanel *active_panel = LLInventoryPanel::getActiveInventoryPanel();
  1281. if (active_panel)
  1282. {
  1283. active_panel->setSelection(first_item_id, TAKE_FOCUS_NO);
  1284. }
  1285. }
  1286. }
  1287. void LLAgentWearables::addWearableToAgentInventory(LLPointer<LLInventoryCallback> cb,
  1288.    LLWearable* wearable,
  1289.    const LLUUID& category_id,
  1290.    BOOL notify)
  1291. {
  1292. create_inventory_item(gAgent.getID(),
  1293.   gAgent.getSessionID(),
  1294.   category_id,
  1295.   wearable->getTransactionID(),
  1296.   wearable->getName(),
  1297.   wearable->getDescription(),
  1298.   wearable->getAssetType(),
  1299.   LLInventoryType::IT_WEARABLE,
  1300.   wearable->getType(),
  1301.   wearable->getPermissions().getMaskNextOwner(),
  1302.   cb);
  1303. }
  1304. void LLAgentWearables::removeWearable(const EWearableType type, bool do_remove_all, U32 index)
  1305. {
  1306. if (gAgent.isTeen() &&
  1307. (type == WT_UNDERSHIRT || type == WT_UNDERPANTS))
  1308. {
  1309. // Can't take off underclothing in simple UI mode or on PG accounts
  1310. // TODO: enable the removing of a single undershirt/underpants if multiple are worn. - Nyx
  1311. return;
  1312. }
  1313. if (getWearableCount(type) == 0)
  1314. {
  1315. // no wearables to remove
  1316. return;
  1317. }
  1318. if (do_remove_all)
  1319. {
  1320. removeWearableFinal(type, do_remove_all, index);
  1321. }
  1322. else
  1323. {
  1324. LLWearable* old_wearable = getWearable(type,index);
  1325. if (old_wearable)
  1326. {
  1327. if (old_wearable->isDirty())
  1328. {
  1329. LLSD payload;
  1330. payload["wearable_type"] = (S32)type;
  1331. // Bring up view-modal dialog: Save changes? Yes, No, Cancel
  1332. LLNotificationsUtil::add("WearableSave", LLSD(), payload, &LLAgentWearables::onRemoveWearableDialog);
  1333. return;
  1334. }
  1335. else
  1336. {
  1337. removeWearableFinal(type, do_remove_all, index);
  1338. }
  1339. }
  1340. }
  1341. }
  1342. // MULTI_WEARABLE: assuming one wearable per type.
  1343. // MULTI_WEARABLE: hardwiring 0th elt for now - notification needs to change.
  1344. // static 
  1345. bool LLAgentWearables::onRemoveWearableDialog(const LLSD& notification, const LLSD& response)
  1346. {
  1347. S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
  1348. EWearableType type = (EWearableType)notification["payload"]["wearable_type"].asInteger();
  1349. switch(option)
  1350. {
  1351. case 0:  // "Save"
  1352. gAgentWearables.saveWearable(type, 0);
  1353. gAgentWearables.removeWearableFinal(type, false, 0);
  1354. break;
  1355. case 1:  // "Don't Save"
  1356. gAgentWearables.removeWearableFinal(type, false, 0);
  1357. break;
  1358. case 2: // "Cancel"
  1359. break;
  1360. default:
  1361. llassert(0);
  1362. break;
  1363. }
  1364. return false;
  1365. }
  1366. // Called by removeWearable() and onRemoveWearableDialog() to actually do the removal.
  1367. void LLAgentWearables::removeWearableFinal(const EWearableType type, bool do_remove_all, U32 index)
  1368. {
  1369. //LLAgentDumper dumper("removeWearable");
  1370. if (do_remove_all)
  1371. {
  1372. S32 max_entry = mWearableDatas[type].size()-1;
  1373. for (S32 i=max_entry; i>=0; i--)
  1374. {
  1375. LLWearable* old_wearable = getWearable(type,i);
  1376. //queryWearableCache(); // moved below
  1377. if (old_wearable)
  1378. {
  1379. popWearable(old_wearable);
  1380. old_wearable->removeFromAvatar(TRUE);
  1381. }
  1382. }
  1383. mWearableDatas[type].clear();
  1384. }
  1385. else
  1386. {
  1387. LLWearable* old_wearable = getWearable(type, index);
  1388. //queryWearableCache(); // moved below
  1389. if (old_wearable)
  1390. {
  1391. popWearable(old_wearable);
  1392. old_wearable->removeFromAvatar(TRUE);
  1393. }
  1394. }
  1395. queryWearableCache();
  1396. // Update the server
  1397. updateServer();
  1398. gInventory.notifyObservers();
  1399. }
  1400. // Assumes existing wearables are not dirty.
  1401. // MULTI_WEARABLE: assumes one wearable per type.
  1402. void LLAgentWearables::setWearableOutfit(const LLInventoryItem::item_array_t& items,
  1403.  const LLDynamicArray< LLWearable* >& wearables,
  1404.  BOOL remove)
  1405. {
  1406. lldebugs << "setWearableOutfit() start" << llendl;
  1407. BOOL wearables_to_remove[WT_COUNT];
  1408. wearables_to_remove[WT_SHAPE] = FALSE;
  1409. wearables_to_remove[WT_SKIN] = FALSE;
  1410. wearables_to_remove[WT_HAIR] = FALSE;
  1411. wearables_to_remove[WT_EYES] = FALSE;
  1412. wearables_to_remove[WT_SHIRT] = remove;
  1413. wearables_to_remove[WT_PANTS] = remove;
  1414. wearables_to_remove[WT_SHOES] = remove;
  1415. wearables_to_remove[WT_SOCKS] = remove;
  1416. wearables_to_remove[WT_JACKET] = remove;
  1417. wearables_to_remove[WT_GLOVES] = remove;
  1418. wearables_to_remove[WT_UNDERSHIRT] = (!gAgent.isTeen()) & remove;
  1419. wearables_to_remove[WT_UNDERPANTS] = (!gAgent.isTeen()) & remove;
  1420. wearables_to_remove[WT_SKIRT] = remove;
  1421. wearables_to_remove[WT_ALPHA] = remove;
  1422. wearables_to_remove[WT_TATTOO] = remove;
  1423. S32 count = wearables.count();
  1424. llassert(items.count() == count);
  1425. S32 i;
  1426. for (i = 0; i < count; i++)
  1427. {
  1428. LLWearable* new_wearable = wearables[i];
  1429. LLPointer<LLInventoryItem> new_item = items[i];
  1430. llassert(new_wearable);
  1431. if (new_wearable)
  1432. {
  1433. const EWearableType type = new_wearable->getType();
  1434. wearables_to_remove[type] = FALSE;
  1435. // MULTI_WEARABLE: using 0th
  1436. LLWearable* old_wearable = getWearable(type, 0);
  1437. if (old_wearable)
  1438. {
  1439. const LLUUID& old_item_id = getWearableItemID(type, 0);
  1440. if ((old_wearable->getAssetID() == new_wearable->getAssetID()) &&
  1441.     (old_item_id == new_item->getUUID()))
  1442. {
  1443. lldebugs << "No change to wearable asset and item: " << LLWearableDictionary::getInstance()->getWearableEntry(type) << llendl;
  1444. continue;
  1445. }
  1446. // Assumes existing wearables are not dirty.
  1447. if (old_wearable->isDirty())
  1448. {
  1449. llassert(0);
  1450. continue;
  1451. }
  1452. }
  1453. new_wearable->setItemID(new_item->getUUID());
  1454. setWearable(type,0,new_wearable);
  1455. }
  1456. }
  1457. std::vector<LLWearable*> wearables_being_removed;
  1458. for (i = 0; i < WT_COUNT; i++)
  1459. {
  1460. if (wearables_to_remove[i])
  1461. {
  1462. // MULTI_WEARABLE: assuming 0th
  1463. LLWearable* wearable = getWearable((EWearableType)i, 0);
  1464. const LLUUID &item_id = getWearableItemID((EWearableType)i,0);
  1465. gInventory.addChangedMask(LLInventoryObserver::LABEL, item_id);
  1466. if (wearable)
  1467. {
  1468. wearables_being_removed.push_back(wearable);
  1469. }
  1470. removeWearable((EWearableType)i,true,0);
  1471. }
  1472. }
  1473. gInventory.notifyObservers();
  1474. std::vector<LLWearable*>::iterator wearable_iter;
  1475. for (wearable_iter = wearables_being_removed.begin(); 
  1476.  wearable_iter != wearables_being_removed.end();
  1477.  ++wearable_iter)
  1478. {
  1479. LLWearable* wearablep = *wearable_iter;
  1480. if (wearablep)
  1481. {
  1482. wearablep->removeFromAvatar(TRUE);
  1483. }
  1484. }
  1485. if (mAvatarObject)
  1486. {
  1487. mAvatarObject->updateVisualParams();
  1488. mAvatarObject->invalidateAll();
  1489. }
  1490. // Start rendering & update the server
  1491. mWearablesLoaded = TRUE; 
  1492. checkWearablesLoaded();
  1493. queryWearableCache();
  1494. updateServer();
  1495. lldebugs << "setWearableOutfit() end" << llendl;
  1496. }
  1497. // User has picked "wear on avatar" from a menu.
  1498. void LLAgentWearables::setWearableItem(LLInventoryItem* new_item, LLWearable* new_wearable, bool do_append)
  1499. {
  1500. //LLAgentDumper dumper("setWearableItem");
  1501. if (isWearingItem(new_item->getUUID()))
  1502. {
  1503. llwarns << "wearable " << new_item->getUUID() << " is already worn" << llendl;
  1504. return;
  1505. }
  1506. const EWearableType type = new_wearable->getType();
  1507. if (!do_append)
  1508. {
  1509. // Remove old wearable, if any
  1510. // MULTI_WEARABLE: hardwired to 0
  1511. LLWearable* old_wearable = getWearable(type,0);
  1512. if (old_wearable)
  1513. {
  1514. const LLUUID& old_item_id = old_wearable->getItemID();
  1515. if ((old_wearable->getAssetID() == new_wearable->getAssetID()) &&
  1516. (old_item_id == new_item->getUUID()))
  1517. {
  1518. lldebugs << "No change to wearable asset and item: " << LLWearableDictionary::getInstance()->getWearableEntry(type) << llendl;
  1519. return;
  1520. }
  1521. if (old_wearable->isDirty())
  1522. {
  1523. // Bring up modal dialog: Save changes? Yes, No, Cancel
  1524. LLSD payload;
  1525. payload["item_id"] = new_item->getUUID();
  1526. LLNotificationsUtil::add("WearableSave", LLSD(), payload, boost::bind(onSetWearableDialog, _1, _2, new_wearable));
  1527. return;
  1528. }
  1529. }
  1530. }
  1531. setWearableFinal(new_item, new_wearable, do_append);
  1532. }
  1533. // static 
  1534. bool LLAgentWearables::onSetWearableDialog(const LLSD& notification, const LLSD& response, LLWearable* wearable)
  1535. {
  1536. S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
  1537. LLInventoryItem* new_item = gInventory.getItem(notification["payload"]["item_id"].asUUID());
  1538. if (!new_item)
  1539. {
  1540. delete wearable;
  1541. return false;
  1542. }
  1543. switch(option)
  1544. {
  1545. case 0:  // "Save"
  1546. // MULTI_WEARABLE: assuming 0th
  1547. gAgentWearables.saveWearable(wearable->getType(),0);
  1548. gAgentWearables.setWearableFinal(new_item, wearable);
  1549. break;
  1550. case 1:  // "Don't Save"
  1551. gAgentWearables.setWearableFinal(new_item, wearable);
  1552. break;
  1553. case 2: // "Cancel"
  1554. break;
  1555. default:
  1556. llassert(0);
  1557. break;
  1558. }
  1559. delete wearable;
  1560. return false;
  1561. }
  1562. // Called from setWearableItem() and onSetWearableDialog() to actually set the wearable.
  1563. // MULTI_WEARABLE: unify code after null objects are gone.
  1564. void LLAgentWearables::setWearableFinal(LLInventoryItem* new_item, LLWearable* new_wearable, bool do_append)
  1565. {
  1566. const EWearableType type = new_wearable->getType();
  1567. if (do_append && getWearableItemID(type,0).notNull())
  1568. {
  1569. new_wearable->setItemID(new_item->getUUID());
  1570. mWearableDatas[type].push_back(new_wearable);
  1571. llinfos << "Added additional wearable for type " << type
  1572. << " size is now " << mWearableDatas[type].size() << llendl;
  1573. checkWearableAgainstInventory(new_wearable);
  1574. }
  1575. else
  1576. {
  1577. // Replace the old wearable with a new one.
  1578. llassert(new_item->getAssetUUID() == new_wearable->getAssetID());
  1579. LLWearable *old_wearable = getWearable(type,0);
  1580. LLUUID old_item_id;
  1581. if (old_wearable)
  1582. {
  1583. old_item_id = old_wearable->getItemID();
  1584. }
  1585. new_wearable->setItemID(new_item->getUUID());
  1586. setWearable(type,0,new_wearable);
  1587. if (old_item_id.notNull())
  1588. {
  1589. gInventory.addChangedMask(LLInventoryObserver::LABEL, old_item_id);
  1590. gInventory.notifyObservers();
  1591. }
  1592. llinfos << "Replaced current element 0 for type " << type
  1593. << " size is now " << mWearableDatas[type].size() << llendl;
  1594. }
  1595. //llinfos << "LLVOAvatar::setWearableItem()" << llendl;
  1596. queryWearableCache();
  1597. //new_wearable->writeToAvatar(TRUE);
  1598. updateServer();
  1599. }
  1600. void LLAgentWearables::queryWearableCache()
  1601. {
  1602. if (!areWearablesLoaded())
  1603. {
  1604. return;
  1605. }
  1606. // Look up affected baked textures.
  1607. // If they exist:
  1608. // disallow updates for affected layersets (until dataserver responds with cache request.)
  1609. // If cache miss, turn updates back on and invalidate composite.
  1610. // If cache hit, modify baked texture entries.
  1611. //
  1612. // Cache requests contain list of hashes for each baked texture entry.
  1613. // Response is list of valid baked texture assets. (same message)
  1614. gMessageSystem->newMessageFast(_PREHASH_AgentCachedTexture);
  1615. gMessageSystem->nextBlockFast(_PREHASH_AgentData);
  1616. gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
  1617. gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
  1618. gMessageSystem->addS32Fast(_PREHASH_SerialNum, gAgentQueryManager.mWearablesCacheQueryID);
  1619. S32 num_queries = 0;
  1620. for (U8 baked_index = 0; baked_index < BAKED_NUM_INDICES; baked_index++)
  1621. {
  1622. const LLVOAvatarDictionary::BakedEntry *baked_dict = LLVOAvatarDictionary::getInstance()->getBakedTexture((EBakedTextureIndex)baked_index);
  1623. LLUUID hash;
  1624. for (U8 i=0; i < baked_dict->mWearables.size(); i++)
  1625. {
  1626. const EWearableType baked_type = baked_dict->mWearables[i];
  1627. // MULTI_WEARABLE: not order-dependent
  1628. const U32 num_wearables = getWearableCount(baked_type);
  1629. for (U32 index = 0; index < num_wearables; ++index)
  1630. {
  1631. const LLWearable* wearable = getWearable(baked_type,index);
  1632. if (wearable)
  1633. {
  1634. hash ^= wearable->getAssetID();
  1635. }
  1636. }
  1637. }
  1638. if (hash.notNull())
  1639. {
  1640. hash ^= baked_dict->mWearablesHashID;
  1641. num_queries++;
  1642. // *NOTE: make sure at least one request gets packed
  1643. //llinfos << "Requesting texture for hash " << hash << " in baked texture slot " << baked_index << llendl;
  1644. gMessageSystem->nextBlockFast(_PREHASH_WearableData);
  1645. gMessageSystem->addUUIDFast(_PREHASH_ID, hash);
  1646. gMessageSystem->addU8Fast(_PREHASH_TextureIndex, (U8)baked_index);
  1647. }
  1648. gAgentQueryManager.mActiveCacheQueries[baked_index] = gAgentQueryManager.mWearablesCacheQueryID;
  1649. }
  1650. llinfos << "Requesting texture cache entry for " << num_queries << " baked textures" << llendl;
  1651. gMessageSystem->sendReliable(gAgent.getRegion()->getHost());
  1652. gAgentQueryManager.mNumPendingQueries++;
  1653. gAgentQueryManager.mWearablesCacheQueryID++;
  1654. }
  1655. // MULTI_WEARABLE: need a way to specify by wearable rather than by type.
  1656. // User has picked "remove from avatar" from a menu.
  1657. // static
  1658. void LLAgentWearables::userRemoveWearable(EWearableType& type)
  1659. {
  1660. if (!(type==WT_SHAPE || type==WT_SKIN || type==WT_HAIR)) //&&
  1661. //!((!gAgent.isTeen()) && (type==WT_UNDERPANTS || type==WT_UNDERSHIRT)))
  1662. {
  1663. // MULTI_WEARABLE: fixed to 0th for now.
  1664. gAgentWearables.removeWearable(type,false,0);
  1665. }
  1666. }
  1667. // static
  1668. void LLAgentWearables::userRemoveAllClothes()
  1669. {
  1670. // We have to do this up front to avoid having to deal with the case of multiple wearables being dirty.
  1671. if (gFloaterCustomize)
  1672. {
  1673. gFloaterCustomize->askToSaveIfDirty(userRemoveAllClothesStep2);
  1674. }
  1675. else
  1676. {
  1677. userRemoveAllClothesStep2(TRUE);
  1678. }
  1679. }
  1680. // static
  1681. void LLAgentWearables::userRemoveAllClothesStep2(BOOL proceed)
  1682. {
  1683. if (proceed)
  1684. {
  1685. gAgentWearables.removeWearable(WT_SHIRT,true,0);
  1686. gAgentWearables.removeWearable(WT_PANTS,true,0);
  1687. gAgentWearables.removeWearable(WT_SHOES,true,0);
  1688. gAgentWearables.removeWearable(WT_SOCKS,true,0);
  1689. gAgentWearables.removeWearable(WT_JACKET,true,0);
  1690. gAgentWearables.removeWearable(WT_GLOVES,true,0);
  1691. gAgentWearables.removeWearable(WT_UNDERSHIRT,true,0);
  1692. gAgentWearables.removeWearable(WT_UNDERPANTS,true,0);
  1693. gAgentWearables.removeWearable(WT_SKIRT,true,0);
  1694. gAgentWearables.removeWearable(WT_ALPHA,true,0);
  1695. gAgentWearables.removeWearable(WT_TATTOO,true,0);
  1696. }
  1697. }
  1698. // Combines userRemoveAllAttachments() and userAttachMultipleAttachments() logic to
  1699. // get attachments into desired state with minimal number of adds/removes.
  1700. void LLAgentWearables::userUpdateAttachments(LLInventoryModel::item_array_t& obj_item_array)
  1701. {
  1702. // Possible cases:
  1703. // already wearing but not in request set -> take off.
  1704. // already wearing and in request set -> leave alone.
  1705. // not wearing and in request set -> put on.
  1706. LLVOAvatar* avatarp = gAgent.getAvatarObject();
  1707. if (!avatarp)
  1708. {
  1709. llwarns << "No avatar found." << llendl;
  1710. return;
  1711. }
  1712. std::set<LLUUID> requested_item_ids;
  1713. std::set<LLUUID> current_item_ids;
  1714. for (S32 i=0; i<obj_item_array.count(); i++)
  1715. requested_item_ids.insert(obj_item_array[i].get()->getLinkedUUID());
  1716. // Build up list of objects to be removed and items currently attached.
  1717. llvo_vec_t objects_to_remove;
  1718. for (LLVOAvatar::attachment_map_t::iterator iter = avatarp->mAttachmentPoints.begin(); 
  1719.  iter != avatarp->mAttachmentPoints.end();)
  1720. {
  1721. LLVOAvatar::attachment_map_t::iterator curiter = iter++;
  1722. LLViewerJointAttachment* attachment = curiter->second;
  1723. for (LLViewerJointAttachment::attachedobjs_vec_t::iterator attachment_iter = attachment->mAttachedObjects.begin();
  1724.  attachment_iter != attachment->mAttachedObjects.end();
  1725.  ++attachment_iter)
  1726. {
  1727. LLViewerObject *objectp = (*attachment_iter);
  1728. if (objectp)
  1729. {
  1730. LLUUID object_item_id = objectp->getItemID();
  1731. if (requested_item_ids.find(object_item_id) != requested_item_ids.end())
  1732. {
  1733. // Object currently worn, was requested.
  1734. // Flag as currently worn so we won't have to add it again.
  1735. current_item_ids.insert(object_item_id);
  1736. }
  1737. else
  1738. {
  1739. // object currently worn, not requested.
  1740. objects_to_remove.push_back(objectp);
  1741. }
  1742. }
  1743. }
  1744. }
  1745. LLInventoryModel::item_array_t items_to_add;
  1746. for (LLInventoryModel::item_array_t::iterator it = obj_item_array.begin();
  1747.  it != obj_item_array.end();
  1748.  ++it)
  1749. {
  1750. LLUUID linked_id = (*it).get()->getLinkedUUID();
  1751. if (current_item_ids.find(linked_id) != current_item_ids.end())
  1752. {
  1753. // Requested attachment is already worn.
  1754. }
  1755. else
  1756. {
  1757. // Requested attachment is not worn yet.
  1758. items_to_add.push_back(*it);
  1759. }
  1760. }
  1761. // S32 remove_count = objects_to_remove.size();
  1762. // S32 add_count = items_to_add.size();
  1763. // llinfos << "remove " << remove_count << " add " << add_count << llendl;
  1764. // Remove everything in objects_to_remove
  1765. userRemoveMultipleAttachments(objects_to_remove);
  1766. // Add everything in items_to_add
  1767. userAttachMultipleAttachments(items_to_add);
  1768. }
  1769. void LLAgentWearables::userRemoveMultipleAttachments(llvo_vec_t& objects_to_remove)
  1770. {
  1771. LLVOAvatar* avatarp = gAgent.getAvatarObject();
  1772. if (!avatarp)
  1773. {
  1774. llwarns << "No avatar found." << llendl;
  1775. return;
  1776. }
  1777. if (objects_to_remove.empty())
  1778. return;
  1779. gMessageSystem->newMessage("ObjectDetach");
  1780. gMessageSystem->nextBlockFast(_PREHASH_AgentData);
  1781. gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
  1782. gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
  1783. for (llvo_vec_t::iterator it = objects_to_remove.begin();
  1784.  it != objects_to_remove.end();
  1785.  ++it)
  1786. {
  1787. LLViewerObject *objectp = *it;
  1788. gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
  1789. gMessageSystem->addU32Fast(_PREHASH_ObjectLocalID, objectp->getLocalID());
  1790. }
  1791. gMessageSystem->sendReliable(gAgent.getRegionHost());
  1792. }
  1793. void LLAgentWearables::userRemoveAllAttachments()
  1794. {
  1795. LLVOAvatar* avatarp = gAgent.getAvatarObject();
  1796. if (!avatarp)
  1797. {
  1798. llwarns << "No avatar found." << llendl;
  1799. return;
  1800. }
  1801. llvo_vec_t objects_to_remove;
  1802. for (LLVOAvatar::attachment_map_t::iterator iter = avatarp->mAttachmentPoints.begin(); 
  1803.  iter != avatarp->mAttachmentPoints.end();)
  1804. {
  1805. LLVOAvatar::attachment_map_t::iterator curiter = iter++;
  1806. LLViewerJointAttachment* attachment = curiter->second;
  1807. for (LLViewerJointAttachment::attachedobjs_vec_t::iterator attachment_iter = attachment->mAttachedObjects.begin();
  1808.  attachment_iter != attachment->mAttachedObjects.end();
  1809.  ++attachment_iter)
  1810. {
  1811. LLViewerObject *attached_object = (*attachment_iter);
  1812. if (attached_object)
  1813. {
  1814. objects_to_remove.push_back(attached_object);
  1815. }
  1816. }
  1817. }
  1818. userRemoveMultipleAttachments(objects_to_remove);
  1819. }
  1820. void LLAgentWearables::userAttachMultipleAttachments(LLInventoryModel::item_array_t& obj_item_array)
  1821. {
  1822. // Build a compound message to send all the objects that need to be rezzed.
  1823. S32 obj_count = obj_item_array.count();
  1824. // Limit number of packets to send
  1825. const S32 MAX_PACKETS_TO_SEND = 10;
  1826. const S32 OBJECTS_PER_PACKET = 4;
  1827. const S32 MAX_OBJECTS_TO_SEND = MAX_PACKETS_TO_SEND * OBJECTS_PER_PACKET;
  1828. if( obj_count > MAX_OBJECTS_TO_SEND )
  1829. {
  1830. obj_count = MAX_OBJECTS_TO_SEND;
  1831. }
  1832. // Create an id to keep the parts of the compound message together
  1833. LLUUID compound_msg_id;
  1834. compound_msg_id.generate();
  1835. LLMessageSystem* msg = gMessageSystem;
  1836. for(S32 i = 0; i < obj_count; ++i)
  1837. {
  1838. if( 0 == (i % OBJECTS_PER_PACKET) )
  1839. {
  1840. // Start a new message chunk
  1841. msg->newMessageFast(_PREHASH_RezMultipleAttachmentsFromInv);
  1842. msg->nextBlockFast(_PREHASH_AgentData);
  1843. msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
  1844. msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
  1845. msg->nextBlockFast(_PREHASH_HeaderData);
  1846. msg->addUUIDFast(_PREHASH_CompoundMsgID, compound_msg_id );
  1847. msg->addU8Fast(_PREHASH_TotalObjects, obj_count );
  1848. msg->addBOOLFast(_PREHASH_FirstDetachAll, false );
  1849. }
  1850. const LLInventoryItem* item = obj_item_array.get(i).get();
  1851. msg->nextBlockFast(_PREHASH_ObjectData );
  1852. msg->addUUIDFast(_PREHASH_ItemID, item->getLinkedUUID());
  1853. msg->addUUIDFast(_PREHASH_OwnerID, item->getPermissions().getOwner());
  1854. msg->addU8Fast(_PREHASH_AttachmentPt, 0 ); // Wear at the previous or default attachment point
  1855. pack_permissions_slam(msg, item->getFlags(), item->getPermissions());
  1856. msg->addStringFast(_PREHASH_Name, item->getName());
  1857. msg->addStringFast(_PREHASH_Description, item->getDescription());
  1858. if( (i+1 == obj_count) || ((OBJECTS_PER_PACKET-1) == (i % OBJECTS_PER_PACKET)) )
  1859. {
  1860. // End of message chunk
  1861. msg->sendReliable( gAgent.getRegion()->getHost() );
  1862. }
  1863. }
  1864. }
  1865. void LLAgentWearables::checkWearablesLoaded() const
  1866. {
  1867. #ifdef SHOW_ASSERT
  1868. U32 item_pend_count = itemUpdatePendingCount();
  1869. if (mWearablesLoaded)
  1870. {
  1871. llassert(item_pend_count==0);
  1872. }
  1873. #endif
  1874. }
  1875. BOOL LLAgentWearables::areWearablesLoaded() const
  1876. {
  1877. checkWearablesLoaded();
  1878. return mWearablesLoaded;
  1879. }
  1880. // MULTI-WEARABLE: update for multiple indices.
  1881. void LLAgentWearables::updateWearablesLoaded()
  1882. {
  1883. mWearablesLoaded = (itemUpdatePendingCount()==0);
  1884. }
  1885. bool LLAgentWearables::canWearableBeRemoved(const LLWearable* wearable) const
  1886. {
  1887. if (!wearable) return false;
  1888. EWearableType type = wearable->getType();
  1889. // Make sure the user always has at least one shape, skin, eyes, and hair type currently worn.
  1890. return !(((type == WT_SHAPE) || (type == WT_SKIN) || (type == WT_HAIR) || (type == WT_EYES))
  1891.  && (getWearableCount(type) <= 1) );   
  1892. }
  1893. void LLAgentWearables::animateAllWearableParams(F32 delta, BOOL upload_bake)
  1894. {
  1895. for( S32 type = 0; type < WT_COUNT; ++type )
  1896. {
  1897. for (S32 count = 0; count < (S32)getWearableCount((EWearableType)type); ++count)
  1898. {
  1899. LLWearable *wearable = getWearable((EWearableType)type,count);
  1900. wearable->animateParams(delta, upload_bake);
  1901. }
  1902. }
  1903. }
  1904. void LLAgentWearables::updateServer()
  1905. {
  1906. sendAgentWearablesUpdate();
  1907. gAgent.sendAgentSetAppearance();
  1908. }
  1909. void LLAgentWearables::populateMyOutfitsFolder(void)
  1910. {
  1911. llinfos << "starting outfit populate" << llendl;
  1912. LLLibraryOutfitsFetch* outfits = new LLLibraryOutfitsFetch();
  1913. // Get the complete information on the items in the inventory and 
  1914. // setup an observer that will wait for that to happen.
  1915. LLInventoryFetchDescendentsObserver::folder_ref_t folders;
  1916. outfits->mMyOutfitsID = gInventory.findCategoryUUIDForType(LLFolderType::FT_MY_OUTFITS);
  1917. folders.push_back(outfits->mMyOutfitsID);
  1918. gInventory.addObserver(outfits);
  1919. outfits->fetchDescendents(folders);
  1920. if (outfits->isEverythingComplete())
  1921. {
  1922. outfits->done();
  1923. }
  1924. }
  1925. void LLLibraryOutfitsFetch::done()
  1926. {
  1927. // Delay this until idle() routine, since it's a heavy operation and
  1928. // we also can't have it run within notifyObservers.
  1929. doOnIdle(boost::bind(&LLLibraryOutfitsFetch::doneIdle,this));
  1930. gInventory.removeObserver(this); // Prevent doOnIdle from being added twice.
  1931. }
  1932. void LLLibraryOutfitsFetch::doneIdle()
  1933. {
  1934. gInventory.addObserver(this); // Add this back in since it was taken out during ::done()
  1935. switch (mCurrFetchStep)
  1936. {
  1937. case LOFS_FOLDER:
  1938. folderDone();
  1939. mCurrFetchStep = LOFS_OUTFITS;
  1940. break;
  1941. case LOFS_OUTFITS:
  1942. outfitsDone();
  1943. mCurrFetchStep = LOFS_LIBRARY;
  1944. break;
  1945. case LOFS_LIBRARY:
  1946. libraryDone();
  1947. mCurrFetchStep = LOFS_IMPORTED;
  1948. break;
  1949. case LOFS_IMPORTED:
  1950. importedFolderDone();
  1951. mCurrFetchStep = LOFS_CONTENTS;
  1952. break;
  1953. case LOFS_CONTENTS:
  1954. contentsDone();
  1955. break;
  1956. default:
  1957. llwarns << "Got invalid state for outfit fetch: " << mCurrFetchStep << llendl;
  1958. mOutfitsPopulated = TRUE;
  1959. break;
  1960. }
  1961. // We're completely done.  Cleanup.
  1962. if (mOutfitsPopulated)
  1963. {
  1964. gInventory.removeObserver(this);
  1965. delete this;
  1966. return;
  1967. }
  1968. }
  1969. void LLLibraryOutfitsFetch::folderDone(void)
  1970. {
  1971. LLInventoryModel::cat_array_t cat_array;
  1972. LLInventoryModel::item_array_t wearable_array;
  1973. gInventory.collectDescendents(mMyOutfitsID, cat_array, wearable_array, 
  1974.   LLInventoryModel::EXCLUDE_TRASH);
  1975. // Early out if we already have items in My Outfits.
  1976. if (cat_array.count() > 0 || wearable_array.count() > 0)
  1977. {
  1978. mOutfitsPopulated = true;
  1979. return;
  1980. }
  1981. mClothingID = gInventory.findCategoryUUIDForType(LLFolderType::FT_CLOTHING);
  1982. mLibraryClothingID = gInventory.findCategoryUUIDForType(LLFolderType::FT_CLOTHING, false, true);
  1983. mCompleteFolders.clear();
  1984. // Get the complete information on the items in the inventory.
  1985. LLInventoryFetchDescendentsObserver::folder_ref_t folders;
  1986. folders.push_back(mClothingID);
  1987. folders.push_back(mLibraryClothingID);
  1988. fetchDescendents(folders);
  1989. if (isEverythingComplete())
  1990. {
  1991. done();
  1992. }
  1993. }
  1994. void LLLibraryOutfitsFetch::outfitsDone(void)
  1995. {
  1996. LLInventoryModel::cat_array_t cat_array;
  1997. LLInventoryModel::item_array_t wearable_array;
  1998. LLInventoryFetchDescendentsObserver::folder_ref_t folders;
  1999. // Collect the contents of the Library's Clothing folder
  2000. gInventory.collectDescendents(mLibraryClothingID, cat_array, wearable_array, 
  2001.   LLInventoryModel::EXCLUDE_TRASH);
  2002. llassert(cat_array.count() > 0);
  2003. for (LLInventoryModel::cat_array_t::const_iterator iter = cat_array.begin();
  2004.  iter != cat_array.end();
  2005.  ++iter)
  2006. {
  2007. const LLViewerInventoryCategory *cat = iter->get();
  2008. // Get the names and id's of every outfit in the library, except for ruth and other "misc" outfits.
  2009. if (cat->getName() != "More Outfits" && cat->getName() != "Ruth")
  2010. {
  2011. // Get the name of every outfit in the library 
  2012. folders.push_back(cat->getUUID());
  2013. mLibraryClothingFolders.push_back(std::make_pair(cat->getUUID(), cat->getName()));
  2014. }
  2015. }
  2016. // Collect the contents of your Inventory Clothing folder
  2017. cat_array.clear();
  2018. wearable_array.clear();
  2019. gInventory.collectDescendents(mClothingID, cat_array, wearable_array, 
  2020.   LLInventoryModel::EXCLUDE_TRASH);
  2021. // Check if you already have an "Imported Library Clothing" folder
  2022. for (LLInventoryModel::cat_array_t::const_iterator iter = cat_array.begin();
  2023.  iter != cat_array.end();
  2024.  ++iter)
  2025. {
  2026. const LLViewerInventoryCategory *cat = iter->get();
  2027. if (cat->getName() == mImportedClothingName)
  2028. {
  2029. mImportedClothingID = cat->getUUID();
  2030. }
  2031. }
  2032. mCompleteFolders.clear();
  2033. fetchDescendents(folders);
  2034. if (isEverythingComplete())
  2035. {
  2036. done();
  2037. }
  2038. }
  2039. class LLLibraryOutfitsCopyDone: public LLInventoryCallback
  2040. {
  2041. public:
  2042. LLLibraryOutfitsCopyDone(LLLibraryOutfitsFetch * fetcher):
  2043. mFireCount(0), mLibraryOutfitsFetcher(fetcher)
  2044. {
  2045. }
  2046. virtual ~LLLibraryOutfitsCopyDone()
  2047. {
  2048. if (!LLApp::isExiting() && mLibraryOutfitsFetcher)
  2049. {
  2050. gInventory.addObserver(mLibraryOutfitsFetcher);
  2051. mLibraryOutfitsFetcher->done();
  2052. }
  2053. }
  2054. /* virtual */ void fire(const LLUUID& inv_item)
  2055. {
  2056. mFireCount++;
  2057. }
  2058. private:
  2059. U32 mFireCount;
  2060. LLLibraryOutfitsFetch * mLibraryOutfitsFetcher;
  2061. };
  2062. void LLLibraryOutfitsFetch::libraryDone(void)
  2063. {
  2064. // Copy the clothing folders from the library into the imported clothing folder if necessary.
  2065. if (mImportedClothingID == LLUUID::null)
  2066. {
  2067. gInventory.removeObserver(this);
  2068. LLPointer<LLInventoryCallback> copy_waiter = new LLLibraryOutfitsCopyDone(this);
  2069. mImportedClothingID = gInventory.createNewCategory(mClothingID,
  2070.    LLFolderType::FT_NONE,
  2071.    mImportedClothingName);
  2072. for (cloth_folder_vec_t::const_iterator iter = mLibraryClothingFolders.begin();
  2073.  iter != mLibraryClothingFolders.end();
  2074.  ++iter)
  2075. {
  2076. LLUUID folder_id = gInventory.createNewCategory(mImportedClothingID,
  2077. LLFolderType::FT_NONE,
  2078. iter->second);
  2079. LLAppearanceManager::getInstance()->shallowCopyCategoryContents(iter->first, folder_id, copy_waiter);
  2080. }
  2081. }
  2082. else
  2083. {
  2084. // Skip straight to fetching the contents of the imported folder
  2085. importedFolderFetch();
  2086. }
  2087. }
  2088. void LLLibraryOutfitsFetch::importedFolderFetch(void)
  2089. {
  2090. // Fetch the contents of the Imported Clothing Folder
  2091. LLInventoryFetchDescendentsObserver::folder_ref_t folders;
  2092. folders.push_back(mImportedClothingID);
  2093. mCompleteFolders.clear();
  2094. fetchDescendents(folders);
  2095. if (isEverythingComplete())
  2096. {
  2097. done();
  2098. }
  2099. }
  2100. void LLLibraryOutfitsFetch::importedFolderDone(void)
  2101. {
  2102. LLInventoryModel::cat_array_t cat_array;
  2103. LLInventoryModel::item_array_t wearable_array;
  2104. LLInventoryFetchDescendentsObserver::folder_ref_t folders;
  2105. // Collect the contents of the Imported Clothing folder
  2106. gInventory.collectDescendents(mImportedClothingID, cat_array, wearable_array, 
  2107.   LLInventoryModel::EXCLUDE_TRASH);
  2108. for (LLInventoryModel::cat_array_t::const_iterator iter = cat_array.begin();
  2109.  iter != cat_array.end();
  2110.  ++iter)
  2111. {
  2112. const LLViewerInventoryCategory *cat = iter->get();
  2113. // Get the name of every imported outfit
  2114. folders.push_back(cat->getUUID());
  2115. mImportedClothingFolders.push_back(std::make_pair(cat->getUUID(), cat->getName()));
  2116. }
  2117. mCompleteFolders.clear();
  2118. fetchDescendents(folders);
  2119. if (isEverythingComplete())
  2120. {
  2121. done();
  2122. }
  2123. }
  2124. void LLLibraryOutfitsFetch::contentsDone(void)
  2125. {
  2126. LLInventoryModel::cat_array_t cat_array;
  2127. LLInventoryModel::item_array_t wearable_array;
  2128. for (cloth_folder_vec_t::const_iterator folder_iter = mImportedClothingFolders.begin();
  2129.  folder_iter != mImportedClothingFolders.end();
  2130.  ++folder_iter)
  2131. {
  2132. // First, make a folder in the My Outfits directory.
  2133. LLUUID new_outfit_folder_id = gInventory.createNewCategory(mMyOutfitsID, LLFolderType::FT_OUTFIT, folder_iter->second);
  2134. cat_array.clear();
  2135. wearable_array.clear();
  2136. // Collect the contents of each imported clothing folder, so we can create new outfit links for it
  2137. gInventory.collectDescendents(folder_iter->first, cat_array, wearable_array, 
  2138.   LLInventoryModel::EXCLUDE_TRASH);
  2139. for (LLInventoryModel::item_array_t::const_iterator wearable_iter = wearable_array.begin();
  2140.  wearable_iter != wearable_array.end();
  2141.  ++wearable_iter)
  2142. {
  2143. const LLViewerInventoryItem *item = wearable_iter->get();
  2144. link_inventory_item(gAgent.getID(),
  2145. item->getLinkedUUID(),
  2146. new_outfit_folder_id,
  2147. item->getName(),
  2148. LLAssetType::AT_LINK,
  2149. NULL);
  2150. }
  2151. }
  2152. mOutfitsPopulated = true;
  2153. }
  2154. //--------------------------------------------------------------------
  2155. // InitialWearablesFetch
  2156. // 
  2157. // This grabs contents from the COF and processes them.
  2158. // The processing is handled in idle(), i.e. outside of done(),
  2159. // to avoid gInventory.notifyObservers recursion.
  2160. //--------------------------------------------------------------------
  2161. LLInitialWearablesFetch::~LLInitialWearablesFetch()
  2162. {
  2163. }
  2164. // virtual
  2165. void LLInitialWearablesFetch::done()
  2166. {
  2167. // Delay processing the actual results of this so it's not handled within
  2168. // gInventory.notifyObservers.  The results will be handled in the next
  2169. // idle tick instead.
  2170. gInventory.removeObserver(this);
  2171. doOnIdle(boost::bind(&LLInitialWearablesFetch::processContents,this));
  2172. }
  2173. void LLInitialWearablesFetch::processContents()
  2174. {
  2175. // Fetch the wearable items from the Current Outfit Folder
  2176. LLInventoryModel::cat_array_t cat_array;
  2177. LLInventoryModel::item_array_t wearable_array;
  2178. LLFindWearables is_wearable;
  2179. gInventory.collectDescendentsIf(mCompleteFolders.front(), cat_array, wearable_array, 
  2180. LLInventoryModel::EXCLUDE_TRASH, is_wearable);
  2181. LLAppearanceManager::instance().setAttachmentInvLinkEnable(true);
  2182. if (wearable_array.count() > 0)
  2183. {
  2184. LLAppearanceManager::instance().updateAppearanceFromCOF();
  2185. }
  2186. else
  2187. {
  2188. // if we're constructing the COF from the wearables message, we don't have a proper outfit link
  2189. LLAppearanceManager::instance().setOutfitDirty(true);
  2190. processWearablesMessage();
  2191. }
  2192. delete this;
  2193. }
  2194. class LLFetchAndLinkObserver: public LLInventoryFetchObserver
  2195. {
  2196. public:
  2197. LLFetchAndLinkObserver(LLInventoryFetchObserver::item_ref_t& ids):
  2198. m_ids(ids),
  2199. LLInventoryFetchObserver(true)
  2200. {
  2201. }
  2202. ~LLFetchAndLinkObserver()
  2203. {
  2204. }
  2205. virtual void done()
  2206. {
  2207. gInventory.removeObserver(this);
  2208. // Link to all fetched items in COF.
  2209. for (LLInventoryFetchObserver::item_ref_t::iterator it = m_ids.begin();
  2210.  it != m_ids.end();
  2211.  ++it)
  2212. {
  2213. LLUUID id = *it;
  2214. LLViewerInventoryItem *item = gInventory.getItem(*it);
  2215. if (!item)
  2216. {
  2217. llwarns << "fetch failed!" << llendl;
  2218. continue;
  2219. }
  2220. link_inventory_item(gAgent.getID(), item->getLinkedUUID(), LLAppearanceManager::instance().getCOF(), item->getName(),
  2221. LLAssetType::AT_LINK, LLPointer<LLInventoryCallback>(NULL));
  2222. }
  2223. }
  2224. private:
  2225. LLInventoryFetchObserver::item_ref_t m_ids;
  2226. };
  2227. void LLInitialWearablesFetch::processWearablesMessage()
  2228. {
  2229. if (!mAgentInitialWearables.empty()) // We have an empty current outfit folder, use the message data instead.
  2230. {
  2231. const LLUUID current_outfit_id = LLAppearanceManager::instance().getCOF();
  2232. LLInventoryFetchObserver::item_ref_t ids;
  2233. for (U8 i = 0; i < mAgentInitialWearables.size(); ++i)
  2234. {
  2235. // Populate the current outfit folder with links to the wearables passed in the message
  2236. InitialWearableData *wearable_data = new InitialWearableData(mAgentInitialWearables[i]); // This will be deleted in the callback.
  2237. if (wearable_data->mAssetID.notNull())
  2238. {
  2239. #ifdef USE_CURRENT_OUTFIT_FOLDER
  2240. ids.push_back(wearable_data->mItemID);
  2241. #endif
  2242. // Fetch the wearables
  2243. LLWearableList::instance().getAsset(wearable_data->mAssetID,
  2244. LLStringUtil::null,
  2245. LLWearableDictionary::getAssetType(wearable_data->mType),
  2246. LLAgentWearables::onInitialWearableAssetArrived, (void*)(wearable_data));
  2247. }
  2248. else
  2249. {
  2250. llinfos << "Invalid wearable, type " << wearable_data->mType << " itemID "
  2251. << wearable_data->mItemID << " assetID " << wearable_data->mAssetID << llendl;
  2252. delete wearable_data;
  2253. }
  2254. }
  2255. // Add all current attachments to the requested items as well.
  2256. LLVOAvatarSelf* avatar = gAgent.getAvatarObject();
  2257. if( avatar )
  2258. {
  2259. for (LLVOAvatar::attachment_map_t::const_iterator iter = avatar->mAttachmentPoints.begin(); 
  2260.  iter != avatar->mAttachmentPoints.end(); ++iter)
  2261. {
  2262. LLViewerJointAttachment* attachment = iter->second;
  2263. if (!attachment) continue;
  2264. for (LLViewerJointAttachment::attachedobjs_vec_t::iterator attachment_iter = attachment->mAttachedObjects.begin();
  2265.  attachment_iter != attachment->mAttachedObjects.end();
  2266.  ++attachment_iter)
  2267. {
  2268. LLViewerObject* attached_object = (*attachment_iter);
  2269. if (!attached_object) continue;
  2270. const LLUUID& item_id = attached_object->getItemID();
  2271. if (item_id.isNull()) continue;
  2272. ids.push_back(item_id);
  2273. }
  2274. }
  2275. }
  2276. // Need to fetch the inventory items for ids, then create links to them after they arrive.
  2277. LLFetchAndLinkObserver *fetcher = new LLFetchAndLinkObserver(ids);
  2278. fetcher->fetchItems(ids);
  2279. // If no items to be fetched, done will never be triggered.
  2280. // TODO: Change LLInventoryFetchObserver::fetchItems to trigger done() on this condition.
  2281. if (fetcher->isEverythingComplete())
  2282. {
  2283. fetcher->done();
  2284. }
  2285. else
  2286. {
  2287. gInventory.addObserver(fetcher);
  2288. }
  2289. }
  2290. else
  2291. {
  2292. LL_WARNS("Wearables") << "No current outfit folder items found and no initial wearables fallback message received." << LL_ENDL;
  2293. }
  2294. }