PageRenderTime 57ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llagentwearables.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 2081 lines | 1614 code | 245 blank | 222 comment | 273 complexity | 4fe5f617409047e528a25ad5b73075c3 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llagentwearables.cpp
  3. * @brief LLAgentWearables class implementation
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #include "llviewerprecompiledheaders.h"
  27. #include "llagentwearables.h"
  28. #include "llaccordionctrltab.h"
  29. #include "llagent.h"
  30. #include "llagentcamera.h"
  31. #include "llagentwearablesfetch.h"
  32. #include "llappearancemgr.h"
  33. #include "llcallbacklist.h"
  34. #include "llfloatersidepanelcontainer.h"
  35. #include "llgesturemgr.h"
  36. #include "llinventorybridge.h"
  37. #include "llinventoryfunctions.h"
  38. #include "llinventoryobserver.h"
  39. #include "llinventorypanel.h"
  40. #include "llmd5.h"
  41. #include "llnotificationsutil.h"
  42. #include "lloutfitobserver.h"
  43. #include "llsidepanelappearance.h"
  44. #include "lltexlayer.h"
  45. #include "lltooldraganddrop.h"
  46. #include "llviewerregion.h"
  47. #include "llvoavatarself.h"
  48. #include "llwearable.h"
  49. #include "llwearablelist.h"
  50. #include <boost/scoped_ptr.hpp>
  51. LLAgentWearables gAgentWearables;
  52. BOOL LLAgentWearables::mInitialWearablesUpdateReceived = FALSE;
  53. using namespace LLVOAvatarDefines;
  54. ///////////////////////////////////////////////////////////////////////////////
  55. // Callback to wear and start editing an item that has just been created.
  56. class LLWearAndEditCallback : public LLInventoryCallback
  57. {
  58. void fire(const LLUUID& inv_item)
  59. {
  60. if (inv_item.isNull()) return;
  61. // Request editing the item after it gets worn.
  62. gAgentWearables.requestEditingWearable(inv_item);
  63. // Wear it.
  64. LLAppearanceMgr::instance().wearItemOnAvatar(inv_item);
  65. }
  66. };
  67. ///////////////////////////////////////////////////////////////////////////////
  68. // HACK: For EXT-3923: Pants item shows in inventory with skin icon and messes with "current look"
  69. // Some db items are corrupted, have inventory flags = 0, implying wearable type = shape, even though
  70. // wearable type stored in asset is some other value.
  71. // Calling this function whenever a wearable is added to increase visibility if this problem
  72. // turns up in other inventories.
  73. void checkWearableAgainstInventory(LLWearable *wearable)
  74. {
  75. if (wearable->getItemID().isNull())
  76. return;
  77. // Check for wearable type consistent with inventory item wearable type.
  78. LLViewerInventoryItem *item = gInventory.getItem(wearable->getItemID());
  79. if (item)
  80. {
  81. if (!item->isWearableType())
  82. {
  83. llwarns << "wearable associated with non-wearable item" << llendl;
  84. }
  85. if (item->getWearableType() != wearable->getType())
  86. {
  87. llwarns << "type mismatch: wearable " << wearable->getName()
  88. << " has type " << wearable->getType()
  89. << " but inventory item " << item->getName()
  90. << " has type " << item->getWearableType() << llendl;
  91. }
  92. }
  93. else
  94. {
  95. llwarns << "wearable inventory item not found" << wearable->getName()
  96. << " itemID " << wearable->getItemID().asString() << llendl;
  97. }
  98. }
  99. void LLAgentWearables::dump()
  100. {
  101. llinfos << "LLAgentWearablesDump" << llendl;
  102. for (S32 i = 0; i < LLWearableType::WT_COUNT; i++)
  103. {
  104. U32 count = getWearableCount((LLWearableType::EType)i);
  105. llinfos << "Type: " << i << " count " << count << llendl;
  106. for (U32 j=0; j<count; j++)
  107. {
  108. LLWearable* wearable = getWearable((LLWearableType::EType)i,j);
  109. if (wearable == NULL)
  110. {
  111. llinfos << " " << j << " NULL wearable" << llendl;
  112. }
  113. llinfos << " " << j << " Name " << wearable->getName()
  114. << " description " << wearable->getDescription() << llendl;
  115. }
  116. }
  117. llinfos << "Total items awaiting wearable update " << mItemsAwaitingWearableUpdate.size() << llendl;
  118. for (std::set<LLUUID>::iterator it = mItemsAwaitingWearableUpdate.begin();
  119. it != mItemsAwaitingWearableUpdate.end();
  120. ++it)
  121. {
  122. llinfos << (*it).asString() << llendl;
  123. }
  124. }
  125. struct LLAgentDumper
  126. {
  127. LLAgentDumper(std::string name):
  128. mName(name)
  129. {
  130. llinfos << llendl;
  131. llinfos << "LLAgentDumper " << mName << llendl;
  132. gAgentWearables.dump();
  133. }
  134. ~LLAgentDumper()
  135. {
  136. llinfos << llendl;
  137. llinfos << "~LLAgentDumper " << mName << llendl;
  138. gAgentWearables.dump();
  139. }
  140. std::string mName;
  141. };
  142. LLAgentWearables::LLAgentWearables() :
  143. mWearablesLoaded(FALSE)
  144. , mCOFChangeInProgress(false)
  145. {
  146. }
  147. LLAgentWearables::~LLAgentWearables()
  148. {
  149. cleanup();
  150. }
  151. void LLAgentWearables::cleanup()
  152. {
  153. }
  154. // static
  155. void LLAgentWearables::initClass()
  156. {
  157. // this can not be called from constructor because its instance is global and is created too early.
  158. // Subscribe to "COF is Saved" signal to notify observers about this (Loading indicator for ex.).
  159. LLOutfitObserver::instance().addCOFSavedCallback(boost::bind(&LLAgentWearables::notifyLoadingFinished, &gAgentWearables));
  160. }
  161. void LLAgentWearables::setAvatarObject(LLVOAvatarSelf *avatar)
  162. {
  163. if (avatar)
  164. {
  165. sendAgentWearablesRequest();
  166. }
  167. }
  168. // wearables
  169. LLAgentWearables::createStandardWearablesAllDoneCallback::~createStandardWearablesAllDoneCallback()
  170. {
  171. llinfos << "destructor - all done?" << llendl;
  172. gAgentWearables.createStandardWearablesAllDone();
  173. }
  174. LLAgentWearables::sendAgentWearablesUpdateCallback::~sendAgentWearablesUpdateCallback()
  175. {
  176. gAgentWearables.sendAgentWearablesUpdate();
  177. }
  178. /**
  179. * @brief Construct a callback for dealing with the wearables.
  180. *
  181. * Would like to pass the agent in here, but we can't safely
  182. * count on it being around later. Just use gAgent directly.
  183. * @param cb callback to execute on completion (??? unused ???)
  184. * @param type Type for the wearable in the agent
  185. * @param wearable The wearable data.
  186. * @param todo Bitmask of actions to take on completion.
  187. */
  188. LLAgentWearables::addWearableToAgentInventoryCallback::addWearableToAgentInventoryCallback(
  189. LLPointer<LLRefCount> cb, LLWearableType::EType type, U32 index, LLWearable* wearable, U32 todo) :
  190. mType(type),
  191. mIndex(index),
  192. mWearable(wearable),
  193. mTodo(todo),
  194. mCB(cb)
  195. {
  196. llinfos << "constructor" << llendl;
  197. }
  198. void LLAgentWearables::addWearableToAgentInventoryCallback::fire(const LLUUID& inv_item)
  199. {
  200. if (mTodo & CALL_CREATESTANDARDDONE)
  201. {
  202. llinfos << "callback fired, inv_item " << inv_item.asString() << llendl;
  203. }
  204. if (inv_item.isNull())
  205. return;
  206. gAgentWearables.addWearabletoAgentInventoryDone(mType, mIndex, inv_item, mWearable);
  207. if (mTodo & CALL_UPDATE)
  208. {
  209. gAgentWearables.sendAgentWearablesUpdate();
  210. }
  211. if (mTodo & CALL_RECOVERDONE)
  212. {
  213. LLAppearanceMgr::instance().addCOFItemLink(inv_item,false);
  214. gAgentWearables.recoverMissingWearableDone();
  215. }
  216. /*
  217. * Do this for every one in the loop
  218. */
  219. if (mTodo & CALL_CREATESTANDARDDONE)
  220. {
  221. LLAppearanceMgr::instance().addCOFItemLink(inv_item,false);
  222. gAgentWearables.createStandardWearablesDone(mType, mIndex);
  223. }
  224. if (mTodo & CALL_MAKENEWOUTFITDONE)
  225. {
  226. gAgentWearables.makeNewOutfitDone(mType, mIndex);
  227. }
  228. if (mTodo & CALL_WEARITEM)
  229. {
  230. LLAppearanceMgr::instance().addCOFItemLink(inv_item, true);
  231. }
  232. }
  233. void LLAgentWearables::addWearabletoAgentInventoryDone(const LLWearableType::EType type,
  234. const U32 index,
  235. const LLUUID& item_id,
  236. LLWearable* wearable)
  237. {
  238. llinfos << "type " << type << " index " << index << " item " << item_id.asString() << llendl;
  239. if (item_id.isNull())
  240. return;
  241. LLUUID old_item_id = getWearableItemID(type,index);
  242. if (wearable)
  243. {
  244. wearable->setItemID(item_id);
  245. if (old_item_id.notNull())
  246. {
  247. gInventory.addChangedMask(LLInventoryObserver::LABEL, old_item_id);
  248. setWearable(type,index,wearable);
  249. }
  250. else
  251. {
  252. pushWearable(type,wearable);
  253. }
  254. }
  255. gInventory.addChangedMask(LLInventoryObserver::LABEL, item_id);
  256. LLViewerInventoryItem* item = gInventory.getItem(item_id);
  257. if (item && wearable)
  258. {
  259. // We're changing the asset id, so we both need to set it
  260. // locally via setAssetUUID() and via setTransactionID() which
  261. // will be decoded on the server. JC
  262. item->setAssetUUID(wearable->getAssetID());
  263. item->setTransactionID(wearable->getTransactionID());
  264. gInventory.addChangedMask(LLInventoryObserver::INTERNAL, item_id);
  265. item->updateServer(FALSE);
  266. }
  267. gInventory.notifyObservers();
  268. }
  269. void LLAgentWearables::sendAgentWearablesUpdate()
  270. {
  271. // First make sure that we have inventory items for each wearable
  272. for (S32 type=0; type < LLWearableType::WT_COUNT; ++type)
  273. {
  274. for (U32 index=0; index < getWearableCount((LLWearableType::EType)type); ++index)
  275. {
  276. LLWearable* wearable = getWearable((LLWearableType::EType)type,index);
  277. if (wearable)
  278. {
  279. if (wearable->getItemID().isNull())
  280. {
  281. LLPointer<LLInventoryCallback> cb =
  282. new addWearableToAgentInventoryCallback(
  283. LLPointer<LLRefCount>(NULL),
  284. (LLWearableType::EType)type,
  285. index,
  286. wearable,
  287. addWearableToAgentInventoryCallback::CALL_NONE);
  288. addWearableToAgentInventory(cb, wearable);
  289. }
  290. else
  291. {
  292. gInventory.addChangedMask(LLInventoryObserver::LABEL,
  293. wearable->getItemID());
  294. }
  295. }
  296. }
  297. }
  298. // Then make sure the inventory is in sync with the avatar.
  299. gInventory.notifyObservers();
  300. // Send the AgentIsNowWearing
  301. gMessageSystem->newMessageFast(_PREHASH_AgentIsNowWearing);
  302. gMessageSystem->nextBlockFast(_PREHASH_AgentData);
  303. gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
  304. gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
  305. lldebugs << "sendAgentWearablesUpdate()" << llendl;
  306. // MULTI-WEARABLE: DEPRECATED: HACK: index to 0- server database tables don't support concept of multiwearables.
  307. for (S32 type=0; type < LLWearableType::WT_COUNT; ++type)
  308. {
  309. gMessageSystem->nextBlockFast(_PREHASH_WearableData);
  310. U8 type_u8 = (U8)type;
  311. gMessageSystem->addU8Fast(_PREHASH_WearableType, type_u8);
  312. LLWearable* wearable = getWearable((LLWearableType::EType)type, 0);
  313. if (wearable)
  314. {
  315. //llinfos << "Sending wearable " << wearable->getName() << llendl;
  316. LLUUID item_id = wearable->getItemID();
  317. const LLViewerInventoryItem *item = gInventory.getItem(item_id);
  318. if (item && item->getIsLinkType())
  319. {
  320. // Get the itemID that this item points to. i.e. make sure
  321. // we are storing baseitems, not their links, in the database.
  322. item_id = item->getLinkedUUID();
  323. }
  324. gMessageSystem->addUUIDFast(_PREHASH_ItemID, item_id);
  325. }
  326. else
  327. {
  328. //llinfos << "Not wearing wearable type " << LLWearableType::getTypeName((LLWearableType::EType)i) << llendl;
  329. gMessageSystem->addUUIDFast(_PREHASH_ItemID, LLUUID::null);
  330. }
  331. lldebugs << " " << LLWearableType::getTypeLabel((LLWearableType::EType)type) << ": " << (wearable ? wearable->getAssetID() : LLUUID::null) << llendl;
  332. }
  333. gAgent.sendReliableMessage();
  334. }
  335. void LLAgentWearables::saveWearable(const LLWearableType::EType type, const U32 index, BOOL send_update,
  336. const std::string new_name)
  337. {
  338. LLWearable* old_wearable = getWearable(type, index);
  339. if(!old_wearable) return;
  340. bool name_changed = !new_name.empty() && (new_name != old_wearable->getName());
  341. if (name_changed || old_wearable->isDirty() || old_wearable->isOldVersion())
  342. {
  343. LLUUID old_item_id = old_wearable->getItemID();
  344. LLWearable* new_wearable = LLWearableList::instance().createCopy(old_wearable);
  345. new_wearable->setItemID(old_item_id); // should this be in LLWearable::copyDataFrom()?
  346. setWearable(type,index,new_wearable);
  347. // old_wearable may still be referred to by other inventory items. Revert
  348. // unsaved changes so other inventory items aren't affected by the changes
  349. // that were just saved.
  350. old_wearable->revertValues();
  351. LLInventoryItem* item = gInventory.getItem(old_item_id);
  352. if (item)
  353. {
  354. std::string item_name = item->getName();
  355. if (name_changed)
  356. {
  357. llinfos << "saveWearable changing name from " << item->getName() << " to " << new_name << llendl;
  358. item_name = new_name;
  359. }
  360. // Update existing inventory item
  361. LLPointer<LLViewerInventoryItem> template_item =
  362. new LLViewerInventoryItem(item->getUUID(),
  363. item->getParentUUID(),
  364. item->getPermissions(),
  365. new_wearable->getAssetID(),
  366. new_wearable->getAssetType(),
  367. item->getInventoryType(),
  368. item_name,
  369. item->getDescription(),
  370. item->getSaleInfo(),
  371. item->getFlags(),
  372. item->getCreationDate());
  373. template_item->setTransactionID(new_wearable->getTransactionID());
  374. template_item->updateServer(FALSE);
  375. gInventory.updateItem(template_item);
  376. if (name_changed)
  377. {
  378. gInventory.notifyObservers();
  379. }
  380. }
  381. else
  382. {
  383. // Add a new inventory item (shouldn't ever happen here)
  384. U32 todo = addWearableToAgentInventoryCallback::CALL_NONE;
  385. if (send_update)
  386. {
  387. todo |= addWearableToAgentInventoryCallback::CALL_UPDATE;
  388. }
  389. LLPointer<LLInventoryCallback> cb =
  390. new addWearableToAgentInventoryCallback(
  391. LLPointer<LLRefCount>(NULL),
  392. type,
  393. index,
  394. new_wearable,
  395. todo);
  396. addWearableToAgentInventory(cb, new_wearable);
  397. return;
  398. }
  399. gAgentAvatarp->wearableUpdated( type, TRUE );
  400. if (send_update)
  401. {
  402. sendAgentWearablesUpdate();
  403. }
  404. }
  405. }
  406. void LLAgentWearables::saveWearableAs(const LLWearableType::EType type,
  407. const U32 index,
  408. const std::string& new_name,
  409. BOOL save_in_lost_and_found)
  410. {
  411. if (!isWearableCopyable(type, index))
  412. {
  413. llwarns << "LLAgent::saveWearableAs() not copyable." << llendl;
  414. return;
  415. }
  416. LLWearable* old_wearable = getWearable(type, index);
  417. if (!old_wearable)
  418. {
  419. llwarns << "LLAgent::saveWearableAs() no old wearable." << llendl;
  420. return;
  421. }
  422. LLInventoryItem* item = gInventory.getItem(getWearableItemID(type,index));
  423. if (!item)
  424. {
  425. llwarns << "LLAgent::saveWearableAs() no inventory item." << llendl;
  426. return;
  427. }
  428. std::string trunc_name(new_name);
  429. LLStringUtil::truncate(trunc_name, DB_INV_ITEM_NAME_STR_LEN);
  430. LLWearable* new_wearable = LLWearableList::instance().createCopy(
  431. old_wearable,
  432. trunc_name);
  433. LLPointer<LLInventoryCallback> cb =
  434. new addWearableToAgentInventoryCallback(
  435. LLPointer<LLRefCount>(NULL),
  436. type,
  437. index,
  438. new_wearable,
  439. addWearableToAgentInventoryCallback::CALL_WEARITEM);
  440. LLUUID category_id;
  441. if (save_in_lost_and_found)
  442. {
  443. category_id = gInventory.findCategoryUUIDForType(
  444. LLFolderType::FT_LOST_AND_FOUND);
  445. }
  446. else
  447. {
  448. // put in same folder as original
  449. category_id = item->getParentUUID();
  450. }
  451. copy_inventory_item(
  452. gAgent.getID(),
  453. item->getPermissions().getOwner(),
  454. item->getUUID(),
  455. category_id,
  456. new_name,
  457. cb);
  458. // old_wearable may still be referred to by other inventory items. Revert
  459. // unsaved changes so other inventory items aren't affected by the changes
  460. // that were just saved.
  461. old_wearable->revertValues();
  462. }
  463. void LLAgentWearables::revertWearable(const LLWearableType::EType type, const U32 index)
  464. {
  465. LLWearable* wearable = getWearable(type, index);
  466. llassert(wearable);
  467. if (wearable)
  468. {
  469. wearable->revertValues();
  470. }
  471. gAgent.sendAgentSetAppearance();
  472. }
  473. void LLAgentWearables::saveAllWearables()
  474. {
  475. //if (!gInventory.isLoaded())
  476. //{
  477. // return;
  478. //}
  479. for (S32 i=0; i < LLWearableType::WT_COUNT; i++)
  480. {
  481. for (U32 j=0; j < getWearableCount((LLWearableType::EType)i); j++)
  482. saveWearable((LLWearableType::EType)i, j, FALSE);
  483. }
  484. sendAgentWearablesUpdate();
  485. }
  486. // Called when the user changes the name of a wearable inventory item that is currently being worn.
  487. void LLAgentWearables::setWearableName(const LLUUID& item_id, const std::string& new_name)
  488. {
  489. for (S32 i=0; i < LLWearableType::WT_COUNT; i++)
  490. {
  491. for (U32 j=0; j < getWearableCount((LLWearableType::EType)i); j++)
  492. {
  493. LLUUID curr_item_id = getWearableItemID((LLWearableType::EType)i,j);
  494. if (curr_item_id == item_id)
  495. {
  496. LLWearable* old_wearable = getWearable((LLWearableType::EType)i,j);
  497. llassert(old_wearable);
  498. if (!old_wearable) continue;
  499. std::string old_name = old_wearable->getName();
  500. old_wearable->setName(new_name);
  501. LLWearable* new_wearable = LLWearableList::instance().createCopy(old_wearable);
  502. new_wearable->setItemID(item_id);
  503. LLInventoryItem* item = gInventory.getItem(item_id);
  504. if (item)
  505. {
  506. new_wearable->setPermissions(item->getPermissions());
  507. }
  508. old_wearable->setName(old_name);
  509. setWearable((LLWearableType::EType)i,j,new_wearable);
  510. sendAgentWearablesUpdate();
  511. break;
  512. }
  513. }
  514. }
  515. }
  516. BOOL LLAgentWearables::isWearableModifiable(LLWearableType::EType type, U32 index) const
  517. {
  518. LLUUID item_id = getWearableItemID(type, index);
  519. return item_id.notNull() ? isWearableModifiable(item_id) : FALSE;
  520. }
  521. BOOL LLAgentWearables::isWearableModifiable(const LLUUID& item_id) const
  522. {
  523. const LLUUID& linked_id = gInventory.getLinkedItemID(item_id);
  524. if (linked_id.notNull())
  525. {
  526. LLInventoryItem* item = gInventory.getItem(linked_id);
  527. if (item && item->getPermissions().allowModifyBy(gAgent.getID(),
  528. gAgent.getGroupID()))
  529. {
  530. return TRUE;
  531. }
  532. }
  533. return FALSE;
  534. }
  535. BOOL LLAgentWearables::isWearableCopyable(LLWearableType::EType type, U32 index) const
  536. {
  537. LLUUID item_id = getWearableItemID(type, index);
  538. if (!item_id.isNull())
  539. {
  540. LLInventoryItem* item = gInventory.getItem(item_id);
  541. if (item && item->getPermissions().allowCopyBy(gAgent.getID(),
  542. gAgent.getGroupID()))
  543. {
  544. return TRUE;
  545. }
  546. }
  547. return FALSE;
  548. }
  549. /*
  550. U32 LLAgentWearables::getWearablePermMask(LLWearableType::EType type)
  551. {
  552. LLUUID item_id = getWearableItemID(type);
  553. if (!item_id.isNull())
  554. {
  555. LLInventoryItem* item = gInventory.getItem(item_id);
  556. if (item)
  557. {
  558. return item->getPermissions().getMaskOwner();
  559. }
  560. }
  561. return PERM_NONE;
  562. }
  563. */
  564. LLInventoryItem* LLAgentWearables::getWearableInventoryItem(LLWearableType::EType type, U32 index)
  565. {
  566. LLUUID item_id = getWearableItemID(type,index);
  567. LLInventoryItem* item = NULL;
  568. if (item_id.notNull())
  569. {
  570. item = gInventory.getItem(item_id);
  571. }
  572. return item;
  573. }
  574. const LLWearable* LLAgentWearables::getWearableFromItemID(const LLUUID& item_id) const
  575. {
  576. const LLUUID& base_item_id = gInventory.getLinkedItemID(item_id);
  577. for (S32 i=0; i < LLWearableType::WT_COUNT; i++)
  578. {
  579. for (U32 j=0; j < getWearableCount((LLWearableType::EType)i); j++)
  580. {
  581. const LLWearable * curr_wearable = getWearable((LLWearableType::EType)i, j);
  582. if (curr_wearable && (curr_wearable->getItemID() == base_item_id))
  583. {
  584. return curr_wearable;
  585. }
  586. }
  587. }
  588. return NULL;
  589. }
  590. LLWearable* LLAgentWearables::getWearableFromItemID(const LLUUID& item_id)
  591. {
  592. const LLUUID& base_item_id = gInventory.getLinkedItemID(item_id);
  593. for (S32 i=0; i < LLWearableType::WT_COUNT; i++)
  594. {
  595. for (U32 j=0; j < getWearableCount((LLWearableType::EType)i); j++)
  596. {
  597. LLWearable * curr_wearable = getWearable((LLWearableType::EType)i, j);
  598. if (curr_wearable && (curr_wearable->getItemID() == base_item_id))
  599. {
  600. return curr_wearable;
  601. }
  602. }
  603. }
  604. return NULL;
  605. }
  606. LLWearable* LLAgentWearables::getWearableFromAssetID(const LLUUID& asset_id)
  607. {
  608. for (S32 i=0; i < LLWearableType::WT_COUNT; i++)
  609. {
  610. for (U32 j=0; j < getWearableCount((LLWearableType::EType)i); j++)
  611. {
  612. LLWearable * curr_wearable = getWearable((LLWearableType::EType)i, j);
  613. if (curr_wearable && (curr_wearable->getAssetID() == asset_id))
  614. {
  615. return curr_wearable;
  616. }
  617. }
  618. }
  619. return NULL;
  620. }
  621. void LLAgentWearables::sendAgentWearablesRequest()
  622. {
  623. gMessageSystem->newMessageFast(_PREHASH_AgentWearablesRequest);
  624. gMessageSystem->nextBlockFast(_PREHASH_AgentData);
  625. gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
  626. gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
  627. gAgent.sendReliableMessage();
  628. }
  629. // static
  630. BOOL LLAgentWearables::selfHasWearable(LLWearableType::EType type)
  631. {
  632. return (gAgentWearables.getWearableCount(type) > 0);
  633. }
  634. LLWearable* LLAgentWearables::getWearable(const LLWearableType::EType type, U32 index)
  635. {
  636. wearableentry_map_t::iterator wearable_iter = mWearableDatas.find(type);
  637. if (wearable_iter == mWearableDatas.end())
  638. {
  639. return NULL;
  640. }
  641. wearableentry_vec_t& wearable_vec = wearable_iter->second;
  642. if (index>=wearable_vec.size())
  643. {
  644. return NULL;
  645. }
  646. else
  647. {
  648. return wearable_vec[index];
  649. }
  650. }
  651. void LLAgentWearables::setWearable(const LLWearableType::EType type, U32 index, LLWearable *wearable)
  652. {
  653. LLWearable *old_wearable = getWearable(type,index);
  654. if (!old_wearable)
  655. {
  656. pushWearable(type,wearable);
  657. return;
  658. }
  659. wearableentry_map_t::iterator wearable_iter = mWearableDatas.find(type);
  660. if (wearable_iter == mWearableDatas.end())
  661. {
  662. llwarns << "invalid type, type " << type << " index " << index << llendl;
  663. return;
  664. }
  665. wearableentry_vec_t& wearable_vec = wearable_iter->second;
  666. if (index>=wearable_vec.size())
  667. {
  668. llwarns << "invalid index, type " << type << " index " << index << llendl;
  669. }
  670. else
  671. {
  672. wearable_vec[index] = wearable;
  673. old_wearable->setLabelUpdated();
  674. wearableUpdated(wearable);
  675. checkWearableAgainstInventory(wearable);
  676. }
  677. }
  678. U32 LLAgentWearables::pushWearable(const LLWearableType::EType type, LLWearable *wearable)
  679. {
  680. if (wearable == NULL)
  681. {
  682. // no null wearables please!
  683. llwarns << "Null wearable sent for type " << type << llendl;
  684. return MAX_CLOTHING_PER_TYPE;
  685. }
  686. if (type < LLWearableType::WT_COUNT || mWearableDatas[type].size() < MAX_CLOTHING_PER_TYPE)
  687. {
  688. mWearableDatas[type].push_back(wearable);
  689. wearableUpdated(wearable);
  690. checkWearableAgainstInventory(wearable);
  691. return mWearableDatas[type].size()-1;
  692. }
  693. return MAX_CLOTHING_PER_TYPE;
  694. }
  695. void LLAgentWearables::wearableUpdated(LLWearable *wearable)
  696. {
  697. gAgentAvatarp->wearableUpdated(wearable->getType(), FALSE);
  698. wearable->refreshName();
  699. wearable->setLabelUpdated();
  700. wearable->pullCrossWearableValues();
  701. // Hack pt 2. If the wearable we just loaded has definition version 24,
  702. // then force a re-save of this wearable after slamming the version number to 22.
  703. // This number was incorrectly incremented for internal builds before release, and
  704. // this fix will ensure that the affected wearables are re-saved with the right version number.
  705. // the versions themselves are compatible. This code can be removed before release.
  706. if( wearable->getDefinitionVersion() == 24 )
  707. {
  708. wearable->setDefinitionVersion(22);
  709. U32 index = getWearableIndex(wearable);
  710. llinfos << "forcing werable type " << wearable->getType() << " to version 22 from 24" << llendl;
  711. saveWearable(wearable->getType(),index,TRUE);
  712. }
  713. }
  714. void LLAgentWearables::popWearable(LLWearable *wearable)
  715. {
  716. if (wearable == NULL)
  717. {
  718. // nothing to do here. move along.
  719. return;
  720. }
  721. U32 index = getWearableIndex(wearable);
  722. LLWearableType::EType type = wearable->getType();
  723. if (index < MAX_CLOTHING_PER_TYPE && index < getWearableCount(type))
  724. {
  725. popWearable(type, index);
  726. }
  727. }
  728. void LLAgentWearables::popWearable(const LLWearableType::EType type, U32 index)
  729. {
  730. LLWearable *wearable = getWearable(type, index);
  731. if (wearable)
  732. {
  733. mWearableDatas[type].erase(mWearableDatas[type].begin() + index);
  734. gAgentAvatarp->wearableUpdated(wearable->getType(), TRUE);
  735. wearable->setLabelUpdated();
  736. }
  737. }
  738. U32 LLAgentWearables::getWearableIndex(const LLWearable *wearable) const
  739. {
  740. if (wearable == NULL)
  741. {
  742. return MAX_CLOTHING_PER_TYPE;
  743. }
  744. const LLWearableType::EType type = wearable->getType();
  745. wearableentry_map_t::const_iterator wearable_iter = mWearableDatas.find(type);
  746. if (wearable_iter == mWearableDatas.end())
  747. {
  748. llwarns << "tried to get wearable index with an invalid type!" << llendl;
  749. return MAX_CLOTHING_PER_TYPE;
  750. }
  751. const wearableentry_vec_t& wearable_vec = wearable_iter->second;
  752. for(U32 index = 0; index < wearable_vec.size(); index++)
  753. {
  754. if (wearable_vec[index] == wearable)
  755. {
  756. return index;
  757. }
  758. }
  759. return MAX_CLOTHING_PER_TYPE;
  760. }
  761. const LLWearable* LLAgentWearables::getWearable(const LLWearableType::EType type, U32 index) const
  762. {
  763. wearableentry_map_t::const_iterator wearable_iter = mWearableDatas.find(type);
  764. if (wearable_iter == mWearableDatas.end())
  765. {
  766. return NULL;
  767. }
  768. const wearableentry_vec_t& wearable_vec = wearable_iter->second;
  769. if (index>=wearable_vec.size())
  770. {
  771. return NULL;
  772. }
  773. else
  774. {
  775. return wearable_vec[index];
  776. }
  777. }
  778. LLWearable* LLAgentWearables::getTopWearable(const LLWearableType::EType type)
  779. {
  780. U32 count = getWearableCount(type);
  781. if ( count == 0)
  782. {
  783. return NULL;
  784. }
  785. return getWearable(type, count-1);
  786. }
  787. LLWearable* LLAgentWearables::getBottomWearable(const LLWearableType::EType type)
  788. {
  789. if (getWearableCount(type) == 0)
  790. {
  791. return NULL;
  792. }
  793. return getWearable(type, 0);
  794. }
  795. U32 LLAgentWearables::getWearableCount(const LLWearableType::EType type) const
  796. {
  797. wearableentry_map_t::const_iterator wearable_iter = mWearableDatas.find(type);
  798. if (wearable_iter == mWearableDatas.end())
  799. {
  800. return 0;
  801. }
  802. const wearableentry_vec_t& wearable_vec = wearable_iter->second;
  803. return wearable_vec.size();
  804. }
  805. U32 LLAgentWearables::getWearableCount(const U32 tex_index) const
  806. {
  807. const LLWearableType::EType wearable_type = LLVOAvatarDictionary::getTEWearableType((LLVOAvatarDefines::ETextureIndex)tex_index);
  808. return getWearableCount(wearable_type);
  809. }
  810. BOOL LLAgentWearables::itemUpdatePending(const LLUUID& item_id) const
  811. {
  812. return mItemsAwaitingWearableUpdate.find(item_id) != mItemsAwaitingWearableUpdate.end();
  813. }
  814. U32 LLAgentWearables::itemUpdatePendingCount() const
  815. {
  816. return mItemsAwaitingWearableUpdate.size();
  817. }
  818. const LLUUID LLAgentWearables::getWearableItemID(LLWearableType::EType type, U32 index) const
  819. {
  820. const LLWearable *wearable = getWearable(type,index);
  821. if (wearable)
  822. return wearable->getItemID();
  823. else
  824. return LLUUID();
  825. }
  826. const LLUUID LLAgentWearables::getWearableAssetID(LLWearableType::EType type, U32 index) const
  827. {
  828. const LLWearable *wearable = getWearable(type,index);
  829. if (wearable)
  830. return wearable->getAssetID();
  831. else
  832. return LLUUID();
  833. }
  834. BOOL LLAgentWearables::isWearingItem(const LLUUID& item_id) const
  835. {
  836. return getWearableFromItemID(item_id) != NULL;
  837. }
  838. // MULTI-WEARABLE: DEPRECATED (see backwards compatibility)
  839. // static
  840. // ! BACKWARDS COMPATIBILITY ! When we stop supporting viewer1.23, we can assume
  841. // that viewers have a Current Outfit Folder and won't need this message, and thus
  842. // we can remove/ignore this whole function. EXCEPT gAgentWearables.notifyLoadingStarted
  843. void LLAgentWearables::processAgentInitialWearablesUpdate(LLMessageSystem* mesgsys, void** user_data)
  844. {
  845. // We should only receive this message a single time. Ignore subsequent AgentWearablesUpdates
  846. // that may result from AgentWearablesRequest having been sent more than once.
  847. if (mInitialWearablesUpdateReceived)
  848. return;
  849. // notify subscribers that wearables started loading. See EXT-7777
  850. // *TODO: find more proper place to not be called from deprecated method.
  851. // Seems such place is found: LLInitialWearablesFetch::processContents()
  852. gAgentWearables.notifyLoadingStarted();
  853. mInitialWearablesUpdateReceived = true;
  854. LLUUID agent_id;
  855. gMessageSystem->getUUIDFast(_PREHASH_AgentData, _PREHASH_AgentID, agent_id);
  856. if (isAgentAvatarValid() && (agent_id == gAgentAvatarp->getID()))
  857. {
  858. gMessageSystem->getU32Fast(_PREHASH_AgentData, _PREHASH_SerialNum, gAgentQueryManager.mUpdateSerialNum);
  859. const S32 NUM_BODY_PARTS = 4;
  860. S32 num_wearables = gMessageSystem->getNumberOfBlocksFast(_PREHASH_WearableData);
  861. if (num_wearables < NUM_BODY_PARTS)
  862. {
  863. // Transitional state. Avatars should always have at least their body parts (hair, eyes, shape and skin).
  864. // The fact that they don't have any here (only a dummy is sent) implies that either:
  865. // 1. This account existed before we had wearables
  866. // 2. The database has gotten messed up
  867. // 3. This is the account's first login (i.e. the wearables haven't been generated yet).
  868. return;
  869. }
  870. // Get the UUID of the current outfit folder (will be created if it doesn't exist)
  871. const LLUUID current_outfit_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_CURRENT_OUTFIT);
  872. LLInitialWearablesFetch* outfit = new LLInitialWearablesFetch(current_outfit_id);
  873. //lldebugs << "processAgentInitialWearablesUpdate()" << llendl;
  874. // Add wearables
  875. // MULTI-WEARABLE: DEPRECATED: Message only supports one wearable per type, will be ignored in future.
  876. gAgentWearables.mItemsAwaitingWearableUpdate.clear();
  877. for (S32 i=0; i < num_wearables; i++)
  878. {
  879. // Parse initial wearables data from message system
  880. U8 type_u8 = 0;
  881. gMessageSystem->getU8Fast(_PREHASH_WearableData, _PREHASH_WearableType, type_u8, i);
  882. if (type_u8 >= LLWearableType::WT_COUNT)
  883. {
  884. continue;
  885. }
  886. const LLWearableType::EType type = (LLWearableType::EType) type_u8;
  887. LLUUID item_id;
  888. gMessageSystem->getUUIDFast(_PREHASH_WearableData, _PREHASH_ItemID, item_id, i);
  889. LLUUID asset_id;
  890. gMessageSystem->getUUIDFast(_PREHASH_WearableData, _PREHASH_AssetID, asset_id, i);
  891. if (asset_id.isNull())
  892. {
  893. LLWearable::removeFromAvatar(type, FALSE);
  894. }
  895. else
  896. {
  897. LLAssetType::EType asset_type = LLWearableType::getAssetType(type);
  898. if (asset_type == LLAssetType::AT_NONE)
  899. {
  900. continue;
  901. }
  902. // MULTI-WEARABLE: DEPRECATED: this message only supports one wearable per type. Should be ignored in future versions
  903. // Store initial wearables data until we know whether we have the current outfit folder or need to use the data.
  904. LLInitialWearablesFetch::InitialWearableData wearable_data(type, item_id, asset_id);
  905. outfit->add(wearable_data);
  906. }
  907. lldebugs << " " << LLWearableType::getTypeLabel(type) << llendl;
  908. }
  909. // Get the complete information on the items in the inventory and set up an observer
  910. // that will trigger when the complete information is fetched.
  911. outfit->startFetch();
  912. if(outfit->isFinished())
  913. {
  914. // everything is already here - call done.
  915. outfit->done();
  916. }
  917. else
  918. {
  919. // it's all on it's way - add an observer, and the inventory
  920. // will call done for us when everything is here.
  921. gInventory.addObserver(outfit);
  922. }
  923. }
  924. }
  925. // Normally, all wearables referred to "AgentWearablesUpdate" will correspond to actual assets in the
  926. // database. If for some reason, we can't load one of those assets, we can try to reconstruct it so that
  927. // the user isn't left without a shape, for example. (We can do that only after the inventory has loaded.)
  928. void LLAgentWearables::recoverMissingWearable(const LLWearableType::EType type, U32 index)
  929. {
  930. // Try to recover by replacing missing wearable with a new one.
  931. LLNotificationsUtil::add("ReplacedMissingWearable");
  932. lldebugs << "Wearable " << LLWearableType::getTypeLabel(type) << " could not be downloaded. Replaced inventory item with default wearable." << llendl;
  933. LLWearable* new_wearable = LLWearableList::instance().createNewWearable(type);
  934. setWearable(type,index,new_wearable);
  935. //new_wearable->writeToAvatar(TRUE);
  936. // Add a new one in the lost and found folder.
  937. // (We used to overwrite the "not found" one, but that could potentially
  938. // destory content.) JC
  939. const LLUUID lost_and_found_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_LOST_AND_FOUND);
  940. LLPointer<LLInventoryCallback> cb =
  941. new addWearableToAgentInventoryCallback(
  942. LLPointer<LLRefCount>(NULL),
  943. type,
  944. index,
  945. new_wearable,
  946. addWearableToAgentInventoryCallback::CALL_RECOVERDONE);
  947. addWearableToAgentInventory(cb, new_wearable, lost_and_found_id, TRUE);
  948. }
  949. void LLAgentWearables::recoverMissingWearableDone()
  950. {
  951. // Have all the wearables that the avatar was wearing at log-in arrived or been fabricated?
  952. updateWearablesLoaded();
  953. if (areWearablesLoaded())
  954. {
  955. // Make sure that the server's idea of the avatar's wearables actually match the wearables.
  956. gAgent.sendAgentSetAppearance();
  957. }
  958. else
  959. {
  960. gInventory.addChangedMask(LLInventoryObserver::LABEL, LLUUID::null);
  961. gInventory.notifyObservers();
  962. }
  963. }
  964. void LLAgentWearables::addLocalTextureObject(const LLWearableType::EType wearable_type, const LLVOAvatarDefines::ETextureIndex texture_type, U32 wearable_index)
  965. {
  966. LLWearable* wearable = getWearable((LLWearableType::EType)wearable_type, wearable_index);
  967. if (!wearable)
  968. {
  969. llerrs << "Tried to add local texture object to invalid wearable with type " << wearable_type << " and index " << wearable_index << llendl;
  970. return;
  971. }
  972. LLLocalTextureObject lto;
  973. wearable->setLocalTextureObject(texture_type, lto);
  974. }
  975. class OnWearableItemCreatedCB: public LLInventoryCallback
  976. {
  977. public:
  978. OnWearableItemCreatedCB():
  979. mWearablesAwaitingItems(LLWearableType::WT_COUNT,NULL)
  980. {
  981. llinfos << "created callback" << llendl;
  982. }
  983. /* virtual */ void fire(const LLUUID& inv_item)
  984. {
  985. llinfos << "One item created " << inv_item.asString() << llendl;
  986. LLViewerInventoryItem *item = gInventory.getItem(inv_item);
  987. mItemsToLink.put(item);
  988. updatePendingWearable(inv_item);
  989. }
  990. ~OnWearableItemCreatedCB()
  991. {
  992. llinfos << "All items created" << llendl;
  993. LLPointer<LLInventoryCallback> link_waiter = new LLUpdateAppearanceOnDestroy;
  994. LLAppearanceMgr::instance().linkAll(LLAppearanceMgr::instance().getCOF(),
  995. mItemsToLink,
  996. link_waiter);
  997. }
  998. void addPendingWearable(LLWearable *wearable)
  999. {
  1000. if (!wearable)
  1001. {
  1002. llwarns << "no wearable" << llendl;
  1003. return;
  1004. }
  1005. LLWearableType::EType type = wearable->getType();
  1006. if (type<LLWearableType::WT_COUNT)
  1007. {
  1008. mWearablesAwaitingItems[type] = wearable;
  1009. }
  1010. else
  1011. {
  1012. llwarns << "invalid type " << type << llendl;
  1013. }
  1014. }
  1015. void updatePendingWearable(const LLUUID& inv_item)
  1016. {
  1017. LLViewerInventoryItem *item = gInventory.getItem(inv_item);
  1018. if (!item)
  1019. {
  1020. llwarns << "no item found" << llendl;
  1021. return;
  1022. }
  1023. if (!item->isWearableType())
  1024. {
  1025. llwarns << "non-wearable item found" << llendl;
  1026. return;
  1027. }
  1028. if (item && item->isWearableType())
  1029. {
  1030. LLWearableType::EType type = item->getWearableType();
  1031. if (type < LLWearableType::WT_COUNT)
  1032. {
  1033. LLWearable *wearable = mWearablesAwaitingItems[type];
  1034. if (wearable)
  1035. wearable->setItemID(inv_item);
  1036. }
  1037. else
  1038. {
  1039. llwarns << "invalid wearable type " << type << llendl;
  1040. }
  1041. }
  1042. }
  1043. private:
  1044. LLInventoryModel::item_array_t mItemsToLink;
  1045. std::vector<LLWearable*> mWearablesAwaitingItems;
  1046. };
  1047. void LLAgentWearables::createStandardWearables()
  1048. {
  1049. llwarns << "Creating standard wearables" << llendl;
  1050. if (!isAgentAvatarValid()) return;
  1051. const BOOL create[LLWearableType::WT_COUNT] =
  1052. {
  1053. TRUE, //LLWearableType::WT_SHAPE
  1054. TRUE, //LLWearableType::WT_SKIN
  1055. TRUE, //LLWearableType::WT_HAIR
  1056. TRUE, //LLWearableType::WT_EYES
  1057. TRUE, //LLWearableType::WT_SHIRT
  1058. TRUE, //LLWearableType::WT_PANTS
  1059. TRUE, //LLWearableType::WT_SHOES
  1060. TRUE, //LLWearableType::WT_SOCKS
  1061. FALSE, //LLWearableType::WT_JACKET
  1062. FALSE, //LLWearableType::WT_GLOVES
  1063. TRUE, //LLWearableType::WT_UNDERSHIRT
  1064. TRUE, //LLWearableType::WT_UNDERPANTS
  1065. FALSE //LLWearableType::WT_SKIRT
  1066. };
  1067. LLPointer<LLInventoryCallback> cb = new OnWearableItemCreatedCB;
  1068. for (S32 i=0; i < LLWearableType::WT_COUNT; i++)
  1069. {
  1070. if (create[i])
  1071. {
  1072. llassert(getWearableCount((LLWearableType::EType)i) == 0);
  1073. LLWearable* wearable = LLWearableList::instance().createNewWearable((LLWearableType::EType)i);
  1074. ((OnWearableItemCreatedCB*)(&(*cb)))->addPendingWearable(wearable);
  1075. // no need to update here...
  1076. LLUUID category_id = LLUUID::null;
  1077. create_inventory_item(gAgent.getID(),
  1078. gAgent.getSessionID(),
  1079. category_id,
  1080. wearable->getTransactionID(),
  1081. wearable->getName(),
  1082. wearable->getDescription(),
  1083. wearable->getAssetType(),
  1084. LLInventoryType::IT_WEARABLE,
  1085. wearable->getType(),
  1086. wearable->getPermissions().getMaskNextOwner(),
  1087. cb);
  1088. }
  1089. }
  1090. }
  1091. void LLAgentWearables::createStandardWearablesDone(S32 type, U32 index)
  1092. {
  1093. llinfos << "type " << type << " index " << index << llendl;
  1094. if (!isAgentAvatarValid()) return;
  1095. gAgentAvatarp->updateVisualParams();
  1096. }
  1097. void LLAgentWearables::createStandardWearablesAllDone()
  1098. {
  1099. // ... because sendAgentWearablesUpdate will notify inventory
  1100. // observers.
  1101. llinfos << "all done?" << llendl;
  1102. mWearablesLoaded = TRUE;
  1103. checkWearablesLoaded();
  1104. notifyLoadingFinished();
  1105. updateServer();
  1106. // Treat this as the first texture entry message, if none received yet
  1107. gAgentAvatarp->onFirstTEMessageReceived();
  1108. }
  1109. void LLAgentWearables::makeNewOutfitDone(S32 type, U32 index)
  1110. {
  1111. LLUUID first_item_id = getWearableItemID((LLWearableType::EType)type, index);
  1112. // Open the inventory and select the first item we added.
  1113. if (first_item_id.notNull())
  1114. {
  1115. LLInventoryPanel *active_panel = LLInventoryPanel::getActiveInventoryPanel();
  1116. if (active_panel)
  1117. {
  1118. active_panel->setSelection(first_item_id, TAKE_FOCUS_NO);
  1119. }
  1120. }
  1121. }
  1122. void LLAgentWearables::addWearableToAgentInventory(LLPointer<LLInventoryCallback> cb,
  1123. LLWearable* wearable,
  1124. const LLUUID& category_id,
  1125. BOOL notify)
  1126. {
  1127. create_inventory_item(gAgent.getID(),
  1128. gAgent.getSessionID(),
  1129. category_id,
  1130. wearable->getTransactionID(),
  1131. wearable->getName(),
  1132. wearable->getDescription(),
  1133. wearable->getAssetType(),
  1134. LLInventoryType::IT_WEARABLE,
  1135. wearable->getType(),
  1136. wearable->getPermissions().getMaskNextOwner(),
  1137. cb);
  1138. }
  1139. void LLAgentWearables::removeWearable(const LLWearableType::EType type, bool do_remove_all, U32 index)
  1140. {
  1141. if (gAgent.isTeen() &&
  1142. (type == LLWearableType::WT_UNDERSHIRT || type == LLWearableType::WT_UNDERPANTS))
  1143. {
  1144. // Can't take off underclothing in simple UI mode or on PG accounts
  1145. // TODO: enable the removing of a single undershirt/underpants if multiple are worn. - Nyx
  1146. return;
  1147. }
  1148. if (getWearableCount(type) == 0)
  1149. {
  1150. // no wearables to remove
  1151. return;
  1152. }
  1153. if (do_remove_all)
  1154. {
  1155. removeWearableFinal(type, do_remove_all, index);
  1156. }
  1157. else
  1158. {
  1159. LLWearable* old_wearable = getWearable(type,index);
  1160. if (old_wearable)
  1161. {
  1162. if (old_wearable->isDirty())
  1163. {
  1164. LLSD payload;
  1165. payload["wearable_type"] = (S32)type;
  1166. payload["wearable_index"] = (S32)index;
  1167. // Bring up view-modal dialog: Save changes? Yes, No, Cancel
  1168. LLNotificationsUtil::add("WearableSave", LLSD(), payload, &LLAgentWearables::onRemoveWearableDialog);
  1169. return;
  1170. }
  1171. else
  1172. {
  1173. removeWearableFinal(type, do_remove_all, index);
  1174. }
  1175. }
  1176. }
  1177. }
  1178. // static
  1179. bool LLAgentWearables::onRemoveWearableDialog(const LLSD& notification, const LLSD& response)
  1180. {
  1181. S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
  1182. LLWearableType::EType type = (LLWearableType::EType)notification["payload"]["wearable_type"].asInteger();
  1183. S32 index = (S32)notification["payload"]["wearable_index"].asInteger();
  1184. switch(option)
  1185. {
  1186. case 0: // "Save"
  1187. gAgentWearables.saveWearable(type, index);
  1188. gAgentWearables.removeWearableFinal(type, false, index);
  1189. break;
  1190. case 1: // "Don't Save"
  1191. gAgentWearables.removeWearableFinal(type, false, index);
  1192. break;
  1193. case 2: // "Cancel"
  1194. break;
  1195. default:
  1196. llassert(0);
  1197. break;
  1198. }
  1199. return false;
  1200. }
  1201. // Called by removeWearable() and onRemoveWearableDialog() to actually do the removal.
  1202. void LLAgentWearables::removeWearableFinal(const LLWearableType::EType type, bool do_remove_all, U32 index)
  1203. {
  1204. //LLAgentDumper dumper("removeWearable");
  1205. if (do_remove_all)
  1206. {
  1207. S32 max_entry = mWearableDatas[type].size()-1;
  1208. for (S32 i=max_entry; i>=0; i--)
  1209. {
  1210. LLWearable* old_wearable = getWearable(type,i);
  1211. //queryWearableCache(); // moved below
  1212. if (old_wearable)
  1213. {
  1214. popWearable(old_wearable);
  1215. old_wearable->removeFromAvatar(TRUE);
  1216. }
  1217. }
  1218. mWearableDatas[type].clear();
  1219. }
  1220. else
  1221. {
  1222. LLWearable* old_wearable = getWearable(type, index);
  1223. //queryWearableCache(); // moved below
  1224. if (old_wearable)
  1225. {
  1226. popWearable(old_wearable);
  1227. old_wearable->removeFromAvatar(TRUE);
  1228. }
  1229. }
  1230. queryWearableCache();
  1231. // Update the server
  1232. updateServer();
  1233. gInventory.notifyObservers();
  1234. }
  1235. // Assumes existing wearables are not dirty.
  1236. void LLAgentWearables::setWearableOutfit(const LLInventoryItem::item_array_t& items,
  1237. const LLDynamicArray< LLWearable* >& wearables,
  1238. BOOL remove)
  1239. {
  1240. llinfos << "setWearableOutfit() start" << llendl;
  1241. // TODO: Removed check for ensuring that teens don't remove undershirt and underwear. Handle later
  1242. if (remove)
  1243. {
  1244. // note: shirt is the first non-body part wearable item. Update if wearable order changes.
  1245. // This loop should remove all clothing, but not any body parts
  1246. for (S32 type = 0; type < (S32)LLWearableType::WT_COUNT; type++)
  1247. {
  1248. if (LLWearableType::getAssetType((LLWearableType::EType)type) == LLAssetType::AT_CLOTHING)
  1249. {
  1250. removeWearable((LLWearableType::EType)type, true, 0);
  1251. }
  1252. }
  1253. }
  1254. S32 count = wearables.count();
  1255. llassert(items.count() == count);
  1256. S32 i;
  1257. for (i = 0; i < count; i++)
  1258. {
  1259. LLWearable* new_wearable = wearables[i];
  1260. LLPointer<LLInventoryItem> new_item = items[i];
  1261. llassert(new_wearable);
  1262. if (new_wearable)
  1263. {
  1264. const LLWearableType::EType type = new_wearable->getType();
  1265. new_wearable->setName(new_item->getName());
  1266. new_wearable->setItemID(new_item->getUUID());
  1267. if (LLWearableType::getAssetType(type) == LLAssetType::AT_BODYPART)
  1268. {
  1269. // exactly one wearable per body part
  1270. setWearable(type,0,new_wearable);
  1271. }
  1272. else
  1273. {
  1274. pushWearable(type,new_wearable);
  1275. }
  1276. wearableUpdated(new_wearable);
  1277. checkWearableAgainstInventory(new_wearable);
  1278. }
  1279. }
  1280. gInventory.notifyObservers();
  1281. if (isAgentAvatarValid())
  1282. {
  1283. gAgentAvatarp->setCompositeUpdatesEnabled(TRUE);
  1284. gAgentAvatarp->updateVisualParams();
  1285. gAgentAvatarp->invalidateAll();
  1286. }
  1287. // Start rendering & update the server
  1288. mWearablesLoaded = TRUE;
  1289. checkWearablesLoaded();
  1290. notifyLoadingFinished();
  1291. queryWearableCache();
  1292. updateServer();
  1293. gAgentAvatarp->dumpAvatarTEs("setWearableOutfit");
  1294. lldebugs << "setWearableOutfit() end" << llendl;
  1295. }
  1296. // User has picked "wear on avatar" from a menu.
  1297. void LLAgentWearables::setWearableItem(LLInventoryItem* new_item, LLWearable* new_wearable, bool do_append)
  1298. {
  1299. //LLAgentDumper dumper("setWearableItem");
  1300. if (isWearingItem(new_item->getUUID()))
  1301. {
  1302. llwarns << "wearable " << new_item->getUUID() << " is already worn" << llendl;
  1303. return;
  1304. }
  1305. const LLWearableType::EType type = new_wearable->getType();
  1306. if (!do_append)
  1307. {
  1308. // Remove old wearable, if any
  1309. // MULTI_WEARABLE: hardwired to 0
  1310. LLWearable* old_wearable = getWearable(type,0);
  1311. if (old_wearable)
  1312. {
  1313. const LLUUID& old_item_id = old_wearable->getItemID();
  1314. if ((old_wearable->getAssetID() == new_wearable->getAssetID()) &&
  1315. (old_item_id == new_item->getUUID()))
  1316. {
  1317. lldebugs << "No change to wearable asset and item: " << LLWearableType::getTypeName(type) << llendl;
  1318. return;
  1319. }
  1320. if (old_wearable->isDirty())
  1321. {
  1322. // Bring up modal dialog: Save changes? Yes, No, Cancel
  1323. LLSD payload;
  1324. payload["item_id"] = new_item->getUUID();
  1325. LLNotificationsUtil::add("WearableSave", LLSD(), payload, boost::bind(onSetWearableDialog, _1, _2, new_wearable));
  1326. return;
  1327. }
  1328. }
  1329. }
  1330. setWearableFinal(new_item, new_wearable, do_append);
  1331. }
  1332. // static
  1333. bool LLAgentWearables::onSetWearableDialog(const LLSD& notification, const LLSD& response, LLWearable* wearable)
  1334. {
  1335. S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
  1336. LLInventoryItem* new_item = gInventory.getItem(notification["payload"]["item_id"].asUUID());
  1337. U32 index = gAgentWearables.getWearableIndex(wearable);
  1338. if (!new_item)
  1339. {
  1340. delete wearable;
  1341. return false;
  1342. }
  1343. switch(option)
  1344. {
  1345. case 0: // "Save"
  1346. gAgentWearables.saveWearable(wearable->getType(),index);
  1347. gAgentWearables.setWearableFinal(new_item, wearable);
  1348. break;
  1349. case 1: // "Don't Save"
  1350. gAgentWearables.setWearableFinal(new_item, wearable);
  1351. break;
  1352. case 2: // "Cancel"
  1353. break;
  1354. default:
  1355. llassert(0);
  1356. break;
  1357. }
  1358. delete wearable;
  1359. return false;
  1360. }
  1361. // Called from setWearableItem() and onSetWearableDialog() to actually set the wearable.
  1362. // MULTI_WEARABLE: unify code after null objects are gone.
  1363. void LLAgentWearables::setWearableFinal(LLInventoryItem* new_item, LLWearable* new_wearable, bool do_append)
  1364. {
  1365. const LLWearableType::EType type = new_wearable->getType();
  1366. if (do_append && getWearableItemID(type,0).notNull())
  1367. {
  1368. new_wearable->setItemID(new_item->getUUID());
  1369. mWearableDatas[type].push_back(new_wearable);
  1370. llinfos << "Added additional wearable for type " << type
  1371. << " size is now " << mWearableDatas[type].size() << llendl;
  1372. checkWearableAgainstInventory(new_wearable);
  1373. }
  1374. else
  1375. {
  1376. // Replace the old wearable with a new one.
  1377. llassert(new_item->getAssetUUID() == new_wearable->getAssetID());
  1378. LLWearable *old_wearable = getWearable(type,0);
  1379. LLUUID old_item_id;
  1380. if (old_wearable)
  1381. {
  1382. old_item_id = old_wearable->getItemID();
  1383. }
  1384. new_wearable->setItemID(new_item->getUUID());
  1385. setWearable(type,0,new_wearable);
  1386. if (old_item_id.notNull())
  1387. {
  1388. gInventory.addChangedMask(LLInventoryObserver::LABEL, old_item_id);
  1389. gInventory.notifyObservers();
  1390. }
  1391. llinfos << "Replaced current element 0 for type " << type
  1392. << " size is now " << mWearableDatas[type].size() << llendl;
  1393. }
  1394. //llinfos << "LLVOAvatar::setWearableItem()" << llendl;
  1395. queryWearableCache();
  1396. //new_wearable->writeToAvatar(TRUE);
  1397. updateServer();
  1398. }
  1399. void LLAgentWearables::queryWearableCache()
  1400. {
  1401. if (!areWearablesLoaded())
  1402. {
  1403. return;
  1404. }
  1405. // Look up affected baked textures.
  1406. // If they exist:
  1407. // disallow updates for affected layersets (until dataserver responds with cache request.)
  1408. // If cache miss, turn updates back on and invalidate composite.
  1409. // If cache hit, modify baked texture entries.
  1410. //
  1411. // Cache requests contain list of hashes for each baked texture entry.
  1412. // Response is list of valid baked texture assets. (same message)
  1413. gMessageSystem->newMessageFast(_PREHASH_AgentCachedTexture);
  1414. gMessageSystem->nextBlockFast(_PREHASH_AgentData);
  1415. gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
  1416. gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
  1417. gMessageSystem->addS32Fast(_PREHASH_SerialNum, gAgentQueryManager.mWearablesCacheQueryID);
  1418. S32 num_queries = 0;
  1419. for (U8 baked_index = 0; baked_index < BAKED_NUM_INDICES; baked_index++)
  1420. {
  1421. LLUUID hash_id = computeBakedTextureHash((EBakedTextureIndex) baked_index);
  1422. if (hash_id.notNull())
  1423. {
  1424. num_queries++;
  1425. // *NOTE: make sure at least one request gets packed
  1426. ETextureIndex te_index = LLVOAvatarDictionary::bakedToLocalTextureIndex((EBakedTextureIndex)baked_index);
  1427. //llinfos << "Requesting texture for hash " << hash << " in baked texture slot " << baked_index << llendl;
  1428. gMessageSystem->nextBlockFast(_PREHASH_WearableData);
  1429. gMessageSystem->addUUIDFast(_PREHASH_ID, hash_id);
  1430. gMessageSystem->addU8Fast(_PREHASH_TextureIndex, (U8)te_index);
  1431. }
  1432. gAgentQueryManager.mActiveCacheQueries[baked_index] = gAgentQueryManager.mWearablesCacheQueryID;
  1433. }
  1434. //VWR-22113: gAgent.getRegion() can return null if invalid, seen here on logout
  1435. if(gAgent.getRegion())
  1436. {
  1437. llinfos << "Requesting texture cache entry for " << num_queries << " baked textures" << llendl;
  1438. gMessageSystem->sendReliable(gAgent.getRegion()->getHost());
  1439. gAgentQueryManager.mNumPendingQueries++;
  1440. gAgentQueryManager.mWearablesCacheQueryID++;
  1441. }
  1442. }
  1443. LLUUID LLAgentWearables::computeBakedTextureHash(LLVOAvatarDefines::EBakedTextureIndex baked_index,
  1444. BOOL generate_valid_hash) // Set to false if you want to upload the baked texture w/o putting it in the cache
  1445. {
  1446. LLUUID hash_id;
  1447. bool hash_computed = false;
  1448. LLMD5 hash;
  1449. const LLVOAvatarDictionary::BakedEntry *baked_dict = LLVOAvatarDictionary::getInstance()->getBakedTexture(baked_index);
  1450. for (U8 i=0; i < baked_dict->mWearables.size(); i++)
  1451. {
  1452. const LLWearableType::EType baked_type = baked_dict->mWearables[i];
  1453. const U32 num_wearables = getWearableCount(baked_type);
  1454. for (U32 index = 0; index < num_wearables; ++index)
  1455. {
  1456. const LLWearable* wearable = getWearable(baked_type,index);
  1457. if (wearable)
  1458. {
  1459. LLUUID asset_id = wearable->getAssetID();
  1460. hash.update((const unsigned char*)asset_id.mData, UUID_BYTES);
  1461. hash_computed = true;
  1462. }
  1463. }
  1464. }
  1465. if (hash_computed)
  1466. {
  1467. hash.update((const unsigned char*)baked_dict->mWearablesHashID.mData, UUID_BYTES);
  1468. // Add some garbage into the hash so that it becomes invalid.
  1469. if (!generate_valid_hash)
  1470. {
  1471. if (isAgentAvatarValid())
  1472. {
  1473. hash.update((const unsigned char*)gAgentAvatarp->getID().mData, UUID_BYTES);
  1474. }
  1475. }
  1476. hash.finalize();
  1477. hash.raw_digest(hash_id.mData);
  1478. }
  1479. return hash_id;
  1480. }
  1481. // User has picked "remove from avatar" from a menu.
  1482. // static
  1483. void LLAgentWearables::userRemoveWearable(const LLWearableType::EType &type, const U32 &index)
  1484. {
  1485. if (!(type==LLWearableType::WT_SHAPE || type==LLWearableType::WT_SKIN || type==LLWearableType::WT_HAIR || type==LLWearableType::WT_EYES)) //&&
  1486. //!((!gAgent.isTeen()) && (type==LLWearableType::WT_UNDERPANTS || type==LLWearableType::WT_UNDERSHIRT)))
  1487. {
  1488. gAgentWearables.removeWearable(type,false,index);
  1489. }
  1490. }
  1491. //static
  1492. void LLAgentWearables::userRemoveWearablesOfType(const LLWearableType::EType &type)
  1493. {
  1494. if (!(type==LLWearableType::WT_SHAPE || type==LLWearableType::WT_SKIN || type==LLWearableType::WT_HAIR || type==LLWearableType::WT_EYES)) //&&
  1495. //!((!gAgent.isTeen()) && (type==LLWearableType::WT_UNDERPANTS || type==LLWearableType::WT_UNDERSHIRT)))
  1496. {
  1497. gAgentWearables.removeWearable(type,true,0);
  1498. }
  1499. }
  1500. // Combines userRemoveAllAttachments() and userAttachMultipleAttachments() logic to
  1501. // get attachments into desired state with minimal number of adds/removes.
  1502. void LLAgentWearables::userUpdateAttachments(LLInventoryModel::item_array_t& obj_item_array)
  1503. {
  1504. // Possible cases:
  1505. // already wearing but not in request set -> take off.
  1506. // already wearing and in request set -> leave alone.
  1507. // not wearing and in request set -> put on.
  1508. if (!isAgentAvatarValid()) return;
  1509. std::set<LLUUID> requested_item_ids;
  1510. std::set<LLUUID> current_item_ids;
  1511. for (S32 i=0; i<obj_item_array.count(); i++)
  1512. requested_item_ids.insert(obj_item_array[i].get()->getLinkedUUID());
  1513. // Build up list of objects to be removed and items currently attached.
  1514. llvo_vec_t objects_to_remove;
  1515. for (LLVOAvatar::attachment_map_t::iterator iter = gAgentAvatarp->mAttachmentPoints.begin();
  1516. iter != gAgentAvatarp->mAttachmentPoints.end();)
  1517. {
  1518. LLVOAvatar::attachment_map_t::iterator curiter = iter++;
  1519. LLViewerJointAttachment* attachment = curiter->second;
  1520. for (LLViewerJointAttachment::attachedobjs_vec_t::iterator attachment_iter = attachment->mAttachedObjects.begin();
  1521. attachment_iter != attachment->mAttachedObjects.end();
  1522. ++attachment_iter)
  1523. {
  1524. LLViewerObject *objectp = (*attachment_iter);
  1525. if (objectp)
  1526. {
  1527. LLUUID object_item_id = objectp->getAttachmentItemID();
  1528. if (requested_item_ids.find(object_item_id) != requested_item_ids.end())
  1529. {
  1530. // Object currently worn, was requested.
  1531. // Flag as currently worn so we won't have to add it again.
  1532. current_item_ids.insert(object_item_id);
  1533. }
  1534. else
  1535. {
  1536. // object currently worn, not requested.
  1537. objects_to_remove.push_back(objectp);
  1538. }
  1539. }
  1540. }
  1541. }
  1542. LLInventoryModel::item_array_t items_to_add;
  1543. for (LLInventoryModel::item_array_t::iterator it = obj_item_array.begin();
  1544. it != obj_item_array.end();
  1545. ++it)
  1546. {
  1547. LLUUID linked_id = (*it).get()->getLinkedUUID();
  1548. if (current_item_ids.find(linked_id) != current_item_ids.end())
  1549. {
  1550. // Requested attachment is already worn.
  1551. }
  1552. else
  1553. {
  1554. // Requested attachment is not worn yet.
  1555. items_to_add.push_back(*it);
  1556. }
  1557. }
  1558. // S32 remove_count = objects_to_remove.size();
  1559. // S32 add_count = items_to_add.size();
  1560. // llinfos << "remove " << remove_count << " add " << add_count << llendl;
  1561. // Remove everything in objects_to_remove
  1562. userRemoveMultipleAttachments(objects_to_remove);
  1563. // Add everything in items_to_add
  1564. userAttachMultipleAttachments(items_to_add);
  1565. }
  1566. void LLAgentWearables::userRemoveMultipleAttachments(llvo_vec_t& objects_to_remove)
  1567. {
  1568. if (!isAgentAvatarValid()) return;
  1569. if (objects_to_remove.empty())
  1570. return;
  1571. gMessageSystem->newMessage("ObjectDetach");
  1572. gMessageSystem->nextBlockFast(_PREHASH_AgentData);
  1573. gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
  1574. gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
  1575. for (llvo_vec_t::iterator it = objects_to_remove.begin();
  1576. it != objects_to_remove.end();
  1577. ++it)
  1578. {
  1579. LLViewerObject *objectp = *it;
  1580. gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
  1581. gMessageSystem->addU32Fast(_PREHASH_ObjectLocalID, objectp->getLocalID());
  1582. }
  1583. gMessageSystem->sendReliable(gAgent.getRegionHost());
  1584. }
  1585. void LLAgentWearables::userRemoveAllAttachments()
  1586. {
  1587. if (!isAgentAvatarValid()) return;
  1588. llvo_vec_t objects_to_remove;
  1589. for (LLVOAvatar::attachment_map_t::iterator iter = gAgentAvatarp->mAttachmentPoints.begin();
  1590. iter != gAgentAvatarp->mAttachmentPoints.end();)
  1591. {
  1592. LLVOAvatar::attachment_map_t::iterator curiter = iter++;
  1593. LLViewerJointAttachment* attachment = curiter->second;
  1594. for (LLViewerJointAttachment::attachedobjs_vec_t::iterator attachment_iter = attachment->mAttachedObjects.begin();
  1595. attachment_iter != attachment->mAttachedObjects.end();
  1596. ++attachment_iter)
  1597. {
  1598. LLViewerObject *attached_object = (*attachment_iter);
  1599. if (attached_object)
  1600. {
  1601. objects_to_remove.push_back(attached_object);
  1602. }
  1603. }
  1604. }
  1605. userRemoveMultipleAttachments(objects_to_remove);
  1606. }
  1607. void LLAgentWearables::userAttachMultipleAttachments(LLInventoryModel::item_array_t& obj_item_array)
  1608. {
  1609. // Build a compound message to send all the objects that need to be rezzed.
  1610. S32 obj_count = obj_item_array.count();
  1611. // Limit number of packets to send
  1612. const S32 MAX_PACKETS_TO_SEND = 10;
  1613. const S32 OBJECTS_PER_PACKET = 4;
  1614. const S32 MAX_OBJECTS_TO_SEND = MAX_PACKETS_TO_SEND * OBJECTS_PER_PACKET;
  1615. if( obj_count > MAX_OBJECTS_TO_SEND )
  1616. {
  1617. obj_count = MAX_OBJECTS_TO_SEND;
  1618. }
  1619. // Create an id to keep the parts of the compound message together
  1620. LLUUID compound_msg_id;
  1621. compound_msg_id.generate();
  1622. LLMessageSystem* msg = gMessageSystem;
  1623. for(S32 i = 0; i < obj_count; ++i)
  1624. {
  1625. if( 0 == (i % OBJECTS_PER_PACKET) )
  1626. {
  1627. // Start a new message chunk
  1628. msg->newMessageFast(_PREHASH_RezMultipleAttachmentsFromInv);
  1629. msg->nextBlockFast(_PREHASH_AgentData);
  1630. msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
  1631. msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
  1632. msg->nextBlockFast(_PREHASH_HeaderData);
  1633. msg->addUUIDFast(_PREHASH_CompoundMsgID, compound_msg_id );
  1634. msg->addU8Fast(_PREHASH_TotalObjects, obj_count );
  1635. msg->addBOOLFast(_PREHASH_FirstDetachAll, false );
  1636. }
  1637. const LLInventoryItem* item = obj_item_array.get(i).get();
  1638. msg->nextBlockFast(_PREHASH_ObjectData );
  1639. msg->addUUIDFast(_PREHASH_ItemID, item->getLinkedUUID());
  1640. msg->addUUIDFast(_PREHASH_OwnerID, item->getPermissions().getOwner());
  1641. msg->addU8Fast(_PREHASH_AttachmentPt, 0 | ATTACHMENT_ADD); // Wear at the previous or default attachment point
  1642. pack_permissions_slam(msg, item->getFlags(), item->getPermissions());
  1643. msg->addStringFast(_PREHASH_Name, item->getName());
  1644. msg->addStringFast(_PREHASH_Description, item->getDescription());
  1645. if( (i+1 == obj_count) || ((OBJECTS_PER_PACKET-1) == (i % OBJECTS_PER_PACKET)) )
  1646. {
  1647. // End of message chunk
  1648. msg->sendReliable( gAgent.getRegion()->getHost() );
  1649. }
  1650. }
  1651. }
  1652. void LLAgentWearables::checkWearablesLoaded() const
  1653. {
  1654. #ifdef SHOW_ASSERT
  1655. U32 item_pend_count = itemUpdatePendingCount();
  1656. if (mWearablesLoaded)
  1657. {
  1658. llassert(item_pend_count==0);
  1659. }
  1660. #endif
  1661. }
  1662. // Returns false if the given wearable is already topmost/bottommost
  1663. // (depending on closer_to_body parameter).
  1664. bool LLAgentWearables::canMoveWearable(const LLUUID& item_id, bool closer_to_body)
  1665. {
  1666. const LLWearable* wearable = getWearableFromItemID(item_id);
  1667. if (!wearable) return false;
  1668. LLWearableType::EType wtype = wearable->getType();
  1669. const LLWearable* marginal_wearable = closer_to_body ? getBottomWearable(wtype) : getTopWearable(wtype);
  1670. if (!marginal_wearable) return false;
  1671. return wearable != marginal_wearable;
  1672. }
  1673. BOOL LLAgentWearables::areWearablesLoaded() const
  1674. {
  1675. checkWearablesLoaded();
  1676. return mWearablesLoaded;
  1677. }
  1678. // MULTI-WEARABLE: DEPRECATED: item pending count relies on old messages that don't support multi-wearables. do not trust to be accurate
  1679. void LLAgentWearables::updateWearablesLoaded()
  1680. {
  1681. mWearablesLoaded = (itemUpdatePendingCount()==0);
  1682. if (mWearablesLoaded)
  1683. {
  1684. notifyLoadingFinished();
  1685. }
  1686. }
  1687. bool LLAgentWearables::canWearableBeRemoved(const LLWearable* wearable) const
  1688. {
  1689. if (!wearable) return false;
  1690. LLWearableType::EType type = wearable->getType();
  1691. // Make sure the user always has at least one shape, skin, eyes, and hair type currently worn.
  1692. return !(((type == LLWearableType::WT_SHAPE) || (type == LLWearableType::WT_SKIN) || (type == LLWearableType::WT_HAIR) || (type == LLWearableType::WT_EYES))
  1693. && (getWearableCount(type) <= 1) );
  1694. }
  1695. void LLAgentWearables::animateAllWearableParams(F32 delta, BOOL upload_bake)
  1696. {
  1697. for( S32 type = 0; type < LLWearableType::WT_COUNT; ++type )
  1698. {
  1699. for (S32 count = 0; count < (S32)getWearableCount((LLWearableType::EType)type); ++count)
  1700. {
  1701. LLWearable *wearable = getWearable((LLWearableType::EType)type,count);
  1702. llassert(wearable);
  1703. if (wearable)
  1704. {
  1705. wearable->animateParams(delta, upload_bake);
  1706. }
  1707. }
  1708. }
  1709. }
  1710. bool LLAgentWearables::moveWearable(const LLViewerInventoryItem* item, bool closer_to_body)
  1711. {
  1712. if (!item) return false;
  1713. if (!item->isWearableType()) return false;
  1714. wearableentry_map_t::iterator wearable_iter = mWearableDatas.find(item->getWearableType());
  1715. if (wearable_iter == mWearableDatas.end()) return false;
  1716. wearableentry_vec_t& wearable_vec = wearable_iter->second;
  1717. if (wearable_vec.empty()) return false;
  1718. const LLUUID& asset_id = item->getAssetUUID();
  1719. //nowhere to move if the wearable is already on any boundary (closest to the body/furthest from the body)
  1720. if (closer_to_body && asset_id == wearable_vec.front()->getAssetID()) return false;
  1721. if (!closer_to_body && asset_id == wearable_vec.back()->getAssetID()) return false;
  1722. for (U32 i = 0; i < wearable_vec.size(); ++i)
  1723. {
  1724. LLWearable* wearable = wearable_vec[i];
  1725. if (!wearable) continue;
  1726. if (wearable->getAssetID() != asset_id) continue;
  1727. //swapping wearables
  1728. U32 swap_i = closer_to_body ? i-1 : i+1;
  1729. wearable_vec[i] = wearable_vec[swap_i];
  1730. wearable_vec[swap_i] = wearable;
  1731. return true;
  1732. }
  1733. return false;
  1734. }
  1735. // static
  1736. void LLAgentWearables::createWearable(LLWearableType::EType type, bool wear, const LLUUID& parent_id)
  1737. {
  1738. if (type == LLWearableType::WT_INVALID || type == LLWearableType::WT_NONE) return;
  1739. LLWearable* wearable = LLWearableList::instance().createNewWearable(type);
  1740. LLAssetType::EType asset_type = wearable->getAssetType();
  1741. LLInventoryType::EType inv_type = LLInventoryType::IT_WEARABLE;
  1742. LLPointer<LLInventoryCallback> cb = wear ? new LLWearAndEditCallback : NULL;
  1743. LLUUID folder_id;
  1744. if (parent_id.notNull())
  1745. {
  1746. folder_id = parent_id;
  1747. }
  1748. else
  1749. {
  1750. LLFolderType::EType folder_type = LLFolderType::assetTypeToFolderType(asset_type);
  1751. folder_id = gInventory.findCategoryUUIDForType(folder_type);
  1752. }
  1753. create_inventory_item(gAgent.getID(), gAgent.getSessionID(),
  1754. folder_id, wearable->getTransactionID(), wearable->getName(),
  1755. wearable->getDescription(), asset_type, inv_type, wearable->getType(),
  1756. wearable->getPermissions().getMaskNextOwner(),
  1757. cb);
  1758. }
  1759. // static
  1760. void LLAgentWearables::editWearable(const LLUUID& item_id)
  1761. {
  1762. LLViewerInventoryItem* item = gInventory.getLinkedItem(item_id);
  1763. if (!item)
  1764. {
  1765. llwarns << "Failed to get linked item" << llendl;
  1766. return;
  1767. }
  1768. LLWearable* wearable = gAgentWearables.getWearableFromItemID(item_id);
  1769. if (!wearable)
  1770. {
  1771. llwarns << "Cannot get wearable" << llendl;
  1772. return;
  1773. }
  1774. if (!gAgentWearables.isWearableModifiable(item->getUUID()))
  1775. {
  1776. llwarns << "Cannot modify wearable" << llendl;
  1777. return;
  1778. }
  1779. const BOOL disable_camera_switch = LLWearableType::getDisableCameraSwitch(wearable->getType());
  1780. LLPanel* panel = LLFloaterSidePanelContainer::getPanel("appearance");
  1781. LLSidepanelAppearance::editWearable(wearable, panel, disable_camera_switch);
  1782. }
  1783. // Request editing the item after it gets worn.
  1784. void LLAgentWearables::requestEditingWearable(const LLUUID& item_id)
  1785. {
  1786. mItemToEdit = gInventory.getLinkedItemID(item_id);
  1787. }
  1788. // Start editing the item if previously requested.
  1789. void LLAgentWearables::editWearableIfRequested(const LLUUID& item_id)
  1790. {
  1791. if (mItemToEdit.notNull() &&
  1792. mItemToEdit == gInventory.getLinkedItemID(item_id))
  1793. {
  1794. LLAgentWearables::editWearable(item_id);
  1795. mItemToEdit.setNull();
  1796. }
  1797. }
  1798. void LLAgentWearables::updateServer()
  1799. {
  1800. sendAgentWearablesUpdate();
  1801. gAgent.sendAgentSetAppearance();
  1802. }
  1803. void LLAgentWearables::populateMyOutfitsFolder(void)
  1804. {
  1805. llinfos << "starting outfit population" << llendl;
  1806. const LLUUID& my_outfits_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_MY_OUTFITS);
  1807. LLLibraryOutfitsFetch* outfits = new LLLibraryOutfitsFetch(my_outfits_id);
  1808. outfits->mMyOutfitsID = my_outfits_id;
  1809. // Get the complete information on the items in the inventory and
  1810. // setup an observer that will wait for that to happen.
  1811. gInventory.addObserver(outfits);
  1812. outfits->startFetch();
  1813. if (outfits->isFinished())
  1814. {
  1815. outfits->done();
  1816. }
  1817. }
  1818. boost::signals2::connection LLAgentWearables::addLoadingStartedCallback(loading_started_callback_t cb)
  1819. {
  1820. return mLoadingStartedSignal.connect(cb);
  1821. }
  1822. boost::signals2::connection LLAgentWearables::addLoadedCallback(loaded_callback_t cb)
  1823. {
  1824. return mLoadedSignal.connect(cb);
  1825. }
  1826. void LLAgentWearables::notifyLoadingStarted()
  1827. {
  1828. mCOFChangeInProgress = true;
  1829. mLoadingStartedSignal();
  1830. }
  1831. void LLAgentWearables::notifyLoadingFinished()
  1832. {
  1833. mCOFChangeInProgress = false;
  1834. mLoadedSignal();
  1835. }
  1836. // EOF