PageRenderTime 43ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llcofwearables.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 759 lines | 542 code | 146 blank | 71 comment | 110 complexity | fcea02d4ac7c59e3d7757b1c26dcd66b MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llcofwearables.cpp
  3. * @brief LLCOFWearables displayes wearables from the current outfit split into three lists (attachments, clothing and body parts)
  4. *
  5. * $LicenseInfo:firstyear=2010&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 "llcofwearables.h"
  28. #include "llaccordionctrl.h"
  29. #include "llaccordionctrltab.h"
  30. #include "llagentdata.h"
  31. #include "llagentwearables.h"
  32. #include "llappearancemgr.h"
  33. #include "llfloatersidepanelcontainer.h"
  34. #include "llinventory.h"
  35. #include "llinventoryfunctions.h"
  36. #include "lllistcontextmenu.h"
  37. #include "llmenugl.h"
  38. #include "llviewermenu.h"
  39. #include "llwearableitemslist.h"
  40. #include "llpaneloutfitedit.h"
  41. #include "lltrans.h"
  42. static LLRegisterPanelClassWrapper<LLCOFWearables> t_cof_wearables("cof_wearables");
  43. const LLSD REARRANGE = LLSD().with("rearrange", LLSD());
  44. static const LLWearableItemNameComparator WEARABLE_NAME_COMPARATOR;
  45. //////////////////////////////////////////////////////////////////////////
  46. class CofContextMenu : public LLListContextMenu
  47. {
  48. protected:
  49. CofContextMenu(LLCOFWearables* cof_wearables)
  50. : mCOFWearables(cof_wearables)
  51. {
  52. llassert(mCOFWearables);
  53. }
  54. void updateCreateWearableLabel(LLMenuGL* menu, const LLUUID& item_id)
  55. {
  56. LLMenuItemGL* menu_item = menu->getChild<LLMenuItemGL>("create_new");
  57. LLWearableType::EType w_type = getWearableType(item_id);
  58. // Hide the "Create new <WEARABLE_TYPE>" if it's irrelevant.
  59. if (w_type == LLWearableType::WT_NONE)
  60. {
  61. menu_item->setVisible(FALSE);
  62. return;
  63. }
  64. // Set proper label for the "Create new <WEARABLE_TYPE>" menu item.
  65. std::string new_label = LLTrans::getString("create_new_" + LLWearableType::getTypeName(w_type));
  66. menu_item->setLabel(new_label);
  67. }
  68. void createNew(const LLUUID& item_id)
  69. {
  70. LLAgentWearables::createWearable(getWearableType(item_id), true);
  71. }
  72. // Get wearable type of the given item.
  73. //
  74. // There is a special case: so-called "dummy items"
  75. // (i.e. the ones that are there just to indicate that you're not wearing
  76. // any wearables of the corresponding type. They are currently grayed out
  77. // and suffixed with "not worn").
  78. // Those items don't have an UUID, but they do have an associated wearable type.
  79. // If the user has invoked context menu for such item,
  80. // we ignore the passed item_id and retrieve wearable type from the item.
  81. LLWearableType::EType getWearableType(const LLUUID& item_id)
  82. {
  83. if (!isDummyItem(item_id))
  84. {
  85. LLViewerInventoryItem* item = gInventory.getLinkedItem(item_id);
  86. if (item && item->isWearableType())
  87. {
  88. return item->getWearableType();
  89. }
  90. }
  91. else if (mCOFWearables) // dummy item selected
  92. {
  93. LLPanelDummyClothingListItem* item;
  94. item = dynamic_cast<LLPanelDummyClothingListItem*>(mCOFWearables->getSelectedItem());
  95. if (item)
  96. {
  97. return item->getWearableType();
  98. }
  99. }
  100. return LLWearableType::WT_NONE;
  101. }
  102. static bool isDummyItem(const LLUUID& item_id)
  103. {
  104. return item_id.isNull();
  105. }
  106. LLCOFWearables* mCOFWearables;
  107. };
  108. //////////////////////////////////////////////////////////////////////////
  109. class CofAttachmentContextMenu : public CofContextMenu
  110. {
  111. public:
  112. CofAttachmentContextMenu(LLCOFWearables* cof_wearables)
  113. : CofContextMenu(cof_wearables)
  114. {
  115. }
  116. protected:
  117. /*virtual*/ LLContextMenu* createMenu()
  118. {
  119. LLUICtrl::CommitCallbackRegistry::ScopedRegistrar registrar;
  120. functor_t take_off = boost::bind(&LLAppearanceMgr::removeItemFromAvatar, LLAppearanceMgr::getInstance(), _1);
  121. registrar.add("Attachment.Detach", boost::bind(handleMultiple, take_off, mUUIDs));
  122. return createFromFile("menu_cof_attachment.xml");
  123. }
  124. };
  125. //////////////////////////////////////////////////////////////////////////
  126. class CofClothingContextMenu : public CofContextMenu
  127. {
  128. public:
  129. CofClothingContextMenu(LLCOFWearables* cof_wearables)
  130. : CofContextMenu(cof_wearables)
  131. {
  132. }
  133. protected:
  134. static void replaceWearable(const LLUUID& item_id)
  135. {
  136. LLPanelOutfitEdit * panel_outfit_edit =
  137. dynamic_cast<LLPanelOutfitEdit*> (LLFloaterSidePanelContainer::getPanel("appearance",
  138. "panel_outfit_edit"));
  139. if (panel_outfit_edit != NULL)
  140. {
  141. panel_outfit_edit->onReplaceMenuItemClicked(item_id);
  142. }
  143. }
  144. /*virtual*/ LLContextMenu* createMenu()
  145. {
  146. LLUICtrl::CommitCallbackRegistry::ScopedRegistrar registrar;
  147. LLUICtrl::EnableCallbackRegistry::ScopedRegistrar enable_registrar;
  148. LLUUID selected_id = mUUIDs.back();
  149. functor_t take_off = boost::bind(&LLAppearanceMgr::removeItemFromAvatar, LLAppearanceMgr::getInstance(), _1);
  150. registrar.add("Clothing.TakeOff", boost::bind(handleMultiple, take_off, mUUIDs));
  151. registrar.add("Clothing.Replace", boost::bind(replaceWearable, selected_id));
  152. registrar.add("Clothing.Edit", boost::bind(LLAgentWearables::editWearable, selected_id));
  153. registrar.add("Clothing.Create", boost::bind(&CofClothingContextMenu::createNew, this, selected_id));
  154. enable_registrar.add("Clothing.OnEnable", boost::bind(&CofClothingContextMenu::onEnable, this, _2));
  155. LLContextMenu* menu = createFromFile("menu_cof_clothing.xml");
  156. llassert(menu);
  157. if (menu)
  158. {
  159. updateCreateWearableLabel(menu, selected_id);
  160. }
  161. return menu;
  162. }
  163. bool onEnable(const LLSD& data)
  164. {
  165. std::string param = data.asString();
  166. LLUUID selected_id = mUUIDs.back();
  167. if ("take_off" == param)
  168. {
  169. return get_is_item_worn(selected_id);
  170. }
  171. else if ("edit" == param)
  172. {
  173. return mUUIDs.size() == 1 && gAgentWearables.isWearableModifiable(selected_id);
  174. }
  175. else if ("replace" == param)
  176. {
  177. return get_is_item_worn(selected_id) && mUUIDs.size() == 1;
  178. }
  179. return true;
  180. }
  181. };
  182. //////////////////////////////////////////////////////////////////////////
  183. class CofBodyPartContextMenu : public CofContextMenu
  184. {
  185. public:
  186. CofBodyPartContextMenu(LLCOFWearables* cof_wearables)
  187. : CofContextMenu(cof_wearables)
  188. {
  189. }
  190. protected:
  191. /*virtual*/ LLContextMenu* createMenu()
  192. {
  193. LLUICtrl::CommitCallbackRegistry::ScopedRegistrar registrar;
  194. LLUICtrl::EnableCallbackRegistry::ScopedRegistrar enable_registrar;
  195. LLUUID selected_id = mUUIDs.back();
  196. LLPanelOutfitEdit* panel_oe = dynamic_cast<LLPanelOutfitEdit*>(LLFloaterSidePanelContainer::getPanel("appearance", "panel_outfit_edit"));
  197. registrar.add("BodyPart.Replace", boost::bind(&LLPanelOutfitEdit::onReplaceMenuItemClicked, panel_oe, selected_id));
  198. registrar.add("BodyPart.Edit", boost::bind(LLAgentWearables::editWearable, selected_id));
  199. registrar.add("BodyPart.Create", boost::bind(&CofBodyPartContextMenu::createNew, this, selected_id));
  200. enable_registrar.add("BodyPart.OnEnable", boost::bind(&CofBodyPartContextMenu::onEnable, this, _2));
  201. LLContextMenu* menu = createFromFile("menu_cof_body_part.xml");
  202. llassert(menu);
  203. if (menu)
  204. {
  205. updateCreateWearableLabel(menu, selected_id);
  206. }
  207. return menu;
  208. }
  209. bool onEnable(const LLSD& data)
  210. {
  211. std::string param = data.asString();
  212. LLUUID selected_id = mUUIDs.back();
  213. if ("edit" == param)
  214. {
  215. return mUUIDs.size() == 1 && gAgentWearables.isWearableModifiable(selected_id);
  216. }
  217. return true;
  218. }
  219. };
  220. //////////////////////////////////////////////////////////////////////////
  221. LLCOFWearables::LLCOFWearables() : LLPanel(),
  222. mAttachments(NULL),
  223. mClothing(NULL),
  224. mBodyParts(NULL),
  225. mLastSelectedList(NULL),
  226. mClothingTab(NULL),
  227. mAttachmentsTab(NULL),
  228. mBodyPartsTab(NULL),
  229. mLastSelectedTab(NULL),
  230. mAccordionCtrl(NULL),
  231. mCOFVersion(-1)
  232. {
  233. mClothingMenu = new CofClothingContextMenu(this);
  234. mAttachmentMenu = new CofAttachmentContextMenu(this);
  235. mBodyPartMenu = new CofBodyPartContextMenu(this);
  236. };
  237. LLCOFWearables::~LLCOFWearables()
  238. {
  239. delete mClothingMenu;
  240. delete mAttachmentMenu;
  241. delete mBodyPartMenu;
  242. }
  243. // virtual
  244. BOOL LLCOFWearables::postBuild()
  245. {
  246. mAttachments = getChild<LLFlatListView>("list_attachments");
  247. mClothing = getChild<LLFlatListView>("list_clothing");
  248. mBodyParts = getChild<LLFlatListView>("list_body_parts");
  249. mClothing->setRightMouseDownCallback(boost::bind(&LLCOFWearables::onListRightClick, this, _1, _2, _3, mClothingMenu));
  250. mAttachments->setRightMouseDownCallback(boost::bind(&LLCOFWearables::onListRightClick, this, _1, _2, _3, mAttachmentMenu));
  251. mBodyParts->setRightMouseDownCallback(boost::bind(&LLCOFWearables::onListRightClick, this, _1, _2, _3, mBodyPartMenu));
  252. //selection across different list/tabs is not supported
  253. mAttachments->setCommitCallback(boost::bind(&LLCOFWearables::onSelectionChange, this, mAttachments));
  254. mClothing->setCommitCallback(boost::bind(&LLCOFWearables::onSelectionChange, this, mClothing));
  255. mBodyParts->setCommitCallback(boost::bind(&LLCOFWearables::onSelectionChange, this, mBodyParts));
  256. mAttachments->setCommitOnSelectionChange(true);
  257. mClothing->setCommitOnSelectionChange(true);
  258. mBodyParts->setCommitOnSelectionChange(true);
  259. //clothing is sorted according to its position relatively to the body
  260. mAttachments->setComparator(&WEARABLE_NAME_COMPARATOR);
  261. mBodyParts->setComparator(&WEARABLE_NAME_COMPARATOR);
  262. mClothingTab = getChild<LLAccordionCtrlTab>("tab_clothing");
  263. mClothingTab->setDropDownStateChangedCallback(boost::bind(&LLCOFWearables::onAccordionTabStateChanged, this, _1, _2));
  264. mAttachmentsTab = getChild<LLAccordionCtrlTab>("tab_attachments");
  265. mAttachmentsTab->setDropDownStateChangedCallback(boost::bind(&LLCOFWearables::onAccordionTabStateChanged, this, _1, _2));
  266. mBodyPartsTab = getChild<LLAccordionCtrlTab>("tab_body_parts");
  267. mBodyPartsTab->setDropDownStateChangedCallback(boost::bind(&LLCOFWearables::onAccordionTabStateChanged, this, _1, _2));
  268. mTab2AssetType[mClothingTab] = LLAssetType::AT_CLOTHING;
  269. mTab2AssetType[mAttachmentsTab] = LLAssetType::AT_OBJECT;
  270. mTab2AssetType[mBodyPartsTab] = LLAssetType::AT_BODYPART;
  271. mAccordionCtrl = getChild<LLAccordionCtrl>("cof_wearables_accordion");
  272. return LLPanel::postBuild();
  273. }
  274. void LLCOFWearables::setAttachmentsTitle()
  275. {
  276. if (mAttachmentsTab)
  277. {
  278. U32 free_slots = MAX_AGENT_ATTACHMENTS - mAttachments->size();
  279. LLStringUtil::format_map_t args_attachments;
  280. args_attachments["[COUNT]"] = llformat ("%d", free_slots);
  281. std::string attachments_title = LLTrans::getString("Attachments remain", args_attachments);
  282. mAttachmentsTab->setTitle(attachments_title);
  283. }
  284. }
  285. void LLCOFWearables::onSelectionChange(LLFlatListView* selected_list)
  286. {
  287. if (!selected_list) return;
  288. if (selected_list != mLastSelectedList)
  289. {
  290. if (selected_list != mAttachments) mAttachments->resetSelection(true);
  291. if (selected_list != mClothing) mClothing->resetSelection(true);
  292. if (selected_list != mBodyParts) mBodyParts->resetSelection(true);
  293. mLastSelectedList = selected_list;
  294. }
  295. onCommit();
  296. }
  297. void LLCOFWearables::onAccordionTabStateChanged(LLUICtrl* ctrl, const LLSD& expanded)
  298. {
  299. bool had_selected_items = mClothing->numSelected() || mAttachments->numSelected() || mBodyParts->numSelected();
  300. mClothing->resetSelection(true);
  301. mAttachments->resetSelection(true);
  302. mBodyParts->resetSelection(true);
  303. bool tab_selection_changed = false;
  304. LLAccordionCtrlTab* tab = dynamic_cast<LLAccordionCtrlTab*>(ctrl);
  305. if (tab && tab != mLastSelectedTab)
  306. {
  307. mLastSelectedTab = tab;
  308. tab_selection_changed = true;
  309. }
  310. if (had_selected_items || tab_selection_changed)
  311. {
  312. //sending commit signal to indicate selection changes
  313. onCommit();
  314. }
  315. }
  316. void LLCOFWearables::refresh()
  317. {
  318. const LLUUID cof_id = LLAppearanceMgr::instance().getCOF();
  319. if (cof_id.isNull())
  320. {
  321. llwarns << "COF ID cannot be NULL" << llendl;
  322. return;
  323. }
  324. LLViewerInventoryCategory* catp = gInventory.getCategory(cof_id);
  325. if (!catp)
  326. {
  327. llwarns << "COF category cannot be NULL" << llendl;
  328. return;
  329. }
  330. // BAP - this check has to be removed because an item name change does not
  331. // change cat version - ie, checking version is not a complete way
  332. // of finding out whether anything has changed in this category.
  333. //if (mCOFVersion == catp->getVersion()) return;
  334. mCOFVersion = catp->getVersion();
  335. // Save current scrollbar position.
  336. typedef std::map<LLFlatListView*, LLRect> scroll_pos_map_t;
  337. scroll_pos_map_t saved_scroll_pos;
  338. saved_scroll_pos[mAttachments] = mAttachments->getVisibleContentRect();
  339. saved_scroll_pos[mClothing] = mClothing->getVisibleContentRect();
  340. saved_scroll_pos[mBodyParts] = mBodyParts->getVisibleContentRect();
  341. // Save current selection.
  342. typedef std::vector<LLSD> values_vector_t;
  343. typedef std::map<LLFlatListView*, values_vector_t> selection_map_t;
  344. selection_map_t preserve_selection;
  345. mAttachments->getSelectedValues(preserve_selection[mAttachments]);
  346. mClothing->getSelectedValues(preserve_selection[mClothing]);
  347. mBodyParts->getSelectedValues(preserve_selection[mBodyParts]);
  348. clear();
  349. LLInventoryModel::cat_array_t cats;
  350. LLInventoryModel::item_array_t cof_items;
  351. gInventory.collectDescendents(cof_id, cats, cof_items, LLInventoryModel::EXCLUDE_TRASH);
  352. populateAttachmentsAndBodypartsLists(cof_items);
  353. LLAppearanceMgr::wearables_by_type_t clothing_by_type(LLWearableType::WT_COUNT);
  354. LLAppearanceMgr::getInstance()->divvyWearablesByType(cof_items, clothing_by_type);
  355. populateClothingList(clothing_by_type);
  356. // Restore previous selection
  357. for (selection_map_t::iterator
  358. iter = preserve_selection.begin(),
  359. iter_end = preserve_selection.end();
  360. iter != iter_end; ++iter)
  361. {
  362. LLFlatListView* list = iter->first;
  363. if (!list) continue;
  364. //restoring selection should not fire commit callbacks
  365. list->setCommitOnSelectionChange(false);
  366. const values_vector_t& values = iter->second;
  367. for (values_vector_t::const_iterator
  368. value_it = values.begin(),
  369. value_it_end = values.end();
  370. value_it != value_it_end; ++value_it)
  371. {
  372. // value_it may be null because of dummy items
  373. // Dummy items have no ID
  374. if(value_it->asUUID().notNull())
  375. {
  376. list->selectItemByValue(*value_it);
  377. }
  378. }
  379. list->setCommitOnSelectionChange(true);
  380. }
  381. // Restore previous scrollbar position.
  382. for (scroll_pos_map_t::const_iterator it = saved_scroll_pos.begin(); it != saved_scroll_pos.end(); ++it)
  383. {
  384. LLFlatListView* list = it->first;
  385. LLRect scroll_pos = it->second;
  386. list->scrollToShowRect(scroll_pos);
  387. }
  388. }
  389. void LLCOFWearables::populateAttachmentsAndBodypartsLists(const LLInventoryModel::item_array_t& cof_items)
  390. {
  391. for (U32 i = 0; i < cof_items.size(); ++i)
  392. {
  393. LLViewerInventoryItem* item = cof_items.get(i);
  394. if (!item) continue;
  395. const LLAssetType::EType item_type = item->getType();
  396. if (item_type == LLAssetType::AT_CLOTHING) continue;
  397. LLPanelInventoryListItemBase* item_panel = NULL;
  398. if (item_type == LLAssetType::AT_OBJECT)
  399. {
  400. item_panel = buildAttachemntListItem(item);
  401. mAttachments->addItem(item_panel, item->getUUID(), ADD_BOTTOM, false);
  402. }
  403. else if (item_type == LLAssetType::AT_BODYPART)
  404. {
  405. item_panel = buildBodypartListItem(item);
  406. if (!item_panel) continue;
  407. mBodyParts->addItem(item_panel, item->getUUID(), ADD_BOTTOM, false);
  408. }
  409. }
  410. if (mAttachments->size())
  411. {
  412. mAttachments->sort();
  413. mAttachments->notify(REARRANGE); //notifying the parent about the list's size change (cause items were added with rearrange=false)
  414. setAttachmentsTitle();
  415. }
  416. else
  417. {
  418. mAttachments->setNoItemsCommentText(LLTrans::getString("no_attachments"));
  419. }
  420. if (mBodyParts->size())
  421. {
  422. mBodyParts->sort();
  423. mBodyParts->notify(REARRANGE);
  424. }
  425. }
  426. //create a clothing list item, update verbs and show/hide line separator
  427. LLPanelClothingListItem* LLCOFWearables::buildClothingListItem(LLViewerInventoryItem* item, bool first, bool last)
  428. {
  429. llassert(item);
  430. if (!item) return NULL;
  431. LLPanelClothingListItem* item_panel = LLPanelClothingListItem::create(item);
  432. if (!item_panel) return NULL;
  433. //updating verbs
  434. //we don't need to use permissions of a link but of an actual/linked item
  435. if (item->getLinkedItem()) item = item->getLinkedItem();
  436. llassert(item);
  437. if (!item) return NULL;
  438. bool allow_modify = item->getPermissions().allowModifyBy(gAgentID);
  439. item_panel->setShowLockButton(!allow_modify);
  440. item_panel->setShowEditButton(allow_modify);
  441. item_panel->setShowMoveUpButton(!first);
  442. item_panel->setShowMoveDownButton(!last);
  443. //setting callbacks
  444. //*TODO move that item panel's inner structure disclosing stuff into the panels
  445. item_panel->childSetAction("btn_delete", boost::bind(mCOFCallbacks.mDeleteWearable));
  446. item_panel->childSetAction("btn_move_up", boost::bind(mCOFCallbacks.mMoveWearableFurther));
  447. item_panel->childSetAction("btn_move_down", boost::bind(mCOFCallbacks.mMoveWearableCloser));
  448. item_panel->childSetAction("btn_edit", boost::bind(mCOFCallbacks.mEditWearable));
  449. //turning on gray separator line for the last item in the items group of the same wearable type
  450. item_panel->setSeparatorVisible(last);
  451. return item_panel;
  452. }
  453. LLPanelBodyPartsListItem* LLCOFWearables::buildBodypartListItem(LLViewerInventoryItem* item)
  454. {
  455. llassert(item);
  456. if (!item) return NULL;
  457. LLPanelBodyPartsListItem* item_panel = LLPanelBodyPartsListItem::create(item);
  458. if (!item_panel) return NULL;
  459. //updating verbs
  460. //we don't need to use permissions of a link but of an actual/linked item
  461. if (item->getLinkedItem()) item = item->getLinkedItem();
  462. llassert(item);
  463. if (!item) return NULL;
  464. bool allow_modify = item->getPermissions().allowModifyBy(gAgentID);
  465. item_panel->setShowLockButton(!allow_modify);
  466. item_panel->setShowEditButton(allow_modify);
  467. //setting callbacks
  468. //*TODO move that item panel's inner structure disclosing stuff into the panels
  469. item_panel->childSetAction("btn_delete", boost::bind(mCOFCallbacks.mDeleteWearable));
  470. item_panel->childSetAction("btn_edit", boost::bind(mCOFCallbacks.mEditWearable));
  471. return item_panel;
  472. }
  473. LLPanelDeletableWearableListItem* LLCOFWearables::buildAttachemntListItem(LLViewerInventoryItem* item)
  474. {
  475. llassert(item);
  476. if (!item) return NULL;
  477. LLPanelAttachmentListItem* item_panel = LLPanelAttachmentListItem::create(item);
  478. if (!item_panel) return NULL;
  479. //setting callbacks
  480. //*TODO move that item panel's inner structure disclosing stuff into the panels
  481. item_panel->childSetAction("btn_delete", boost::bind(mCOFCallbacks.mDeleteWearable));
  482. return item_panel;
  483. }
  484. void LLCOFWearables::populateClothingList(LLAppearanceMgr::wearables_by_type_t& clothing_by_type)
  485. {
  486. llassert(clothing_by_type.size() == LLWearableType::WT_COUNT);
  487. for (U32 type = LLWearableType::WT_SHIRT; type < LLWearableType::WT_COUNT; ++type)
  488. {
  489. U32 size = clothing_by_type[type].size();
  490. if (!size) continue;
  491. LLAppearanceMgr::sortItemsByActualDescription(clothing_by_type[type]);
  492. //clothing items are displayed in reverse order, from furthest ones to closest ones (relatively to the body)
  493. for (U32 i = size; i != 0; --i)
  494. {
  495. LLViewerInventoryItem* item = clothing_by_type[type][i-1];
  496. LLPanelClothingListItem* item_panel = buildClothingListItem(item, i == size, i == 1);
  497. if (!item_panel) continue;
  498. mClothing->addItem(item_panel, item->getUUID(), ADD_BOTTOM, false);
  499. }
  500. }
  501. addClothingTypesDummies(clothing_by_type);
  502. mClothing->notify(REARRANGE);
  503. }
  504. //adding dummy items for missing wearable types
  505. void LLCOFWearables::addClothingTypesDummies(const LLAppearanceMgr::wearables_by_type_t& clothing_by_type)
  506. {
  507. llassert(clothing_by_type.size() == LLWearableType::WT_COUNT);
  508. for (U32 type = LLWearableType::WT_SHIRT; type < LLWearableType::WT_COUNT; type++)
  509. {
  510. U32 size = clothing_by_type[type].size();
  511. if (size) continue;
  512. LLWearableType::EType w_type = static_cast<LLWearableType::EType>(type);
  513. LLPanelInventoryListItemBase* item_panel = LLPanelDummyClothingListItem::create(w_type);
  514. if(!item_panel) continue;
  515. item_panel->childSetAction("btn_add", boost::bind(mCOFCallbacks.mAddWearable));
  516. mClothing->addItem(item_panel, LLUUID::null, ADD_BOTTOM, false);
  517. }
  518. }
  519. LLUUID LLCOFWearables::getSelectedUUID()
  520. {
  521. if (!mLastSelectedList) return LLUUID::null;
  522. return mLastSelectedList->getSelectedUUID();
  523. }
  524. bool LLCOFWearables::getSelectedUUIDs(uuid_vec_t& selected_ids)
  525. {
  526. if (!mLastSelectedList) return false;
  527. mLastSelectedList->getSelectedUUIDs(selected_ids);
  528. return selected_ids.size() != 0;
  529. }
  530. LLPanel* LLCOFWearables::getSelectedItem()
  531. {
  532. if (!mLastSelectedList) return NULL;
  533. return mLastSelectedList->getSelectedItem();
  534. }
  535. void LLCOFWearables::getSelectedItems(std::vector<LLPanel*>& selected_items) const
  536. {
  537. if (mLastSelectedList)
  538. {
  539. mLastSelectedList->getSelectedItems(selected_items);
  540. }
  541. }
  542. void LLCOFWearables::clear()
  543. {
  544. mAttachments->clear();
  545. mClothing->clear();
  546. mBodyParts->clear();
  547. }
  548. LLAssetType::EType LLCOFWearables::getExpandedAccordionAssetType()
  549. {
  550. typedef std::map<std::string, LLAssetType::EType> type_map_t;
  551. static type_map_t type_map;
  552. if (mAccordionCtrl != NULL)
  553. {
  554. const LLAccordionCtrlTab* expanded_tab = mAccordionCtrl->getExpandedTab();
  555. return get_if_there(mTab2AssetType, expanded_tab, LLAssetType::AT_NONE);
  556. }
  557. return LLAssetType::AT_NONE;
  558. }
  559. LLAssetType::EType LLCOFWearables::getSelectedAccordionAssetType()
  560. {
  561. if (mAccordionCtrl != NULL)
  562. {
  563. const LLAccordionCtrlTab* selected_tab = mAccordionCtrl->getSelectedTab();
  564. return get_if_there(mTab2AssetType, selected_tab, LLAssetType::AT_NONE);
  565. }
  566. return LLAssetType::AT_NONE;
  567. }
  568. void LLCOFWearables::expandDefaultAccordionTab()
  569. {
  570. if (mAccordionCtrl != NULL)
  571. {
  572. mAccordionCtrl->expandDefaultTab();
  573. }
  574. }
  575. void LLCOFWearables::onListRightClick(LLUICtrl* ctrl, S32 x, S32 y, LLListContextMenu* menu)
  576. {
  577. if(menu)
  578. {
  579. uuid_vec_t selected_uuids;
  580. if(getSelectedUUIDs(selected_uuids))
  581. {
  582. bool show_menu = false;
  583. for(uuid_vec_t::iterator it = selected_uuids.begin();it!=selected_uuids.end();++it)
  584. {
  585. if ((*it).notNull())
  586. {
  587. show_menu = true;
  588. break;
  589. }
  590. }
  591. if(show_menu)
  592. {
  593. menu->show(ctrl, selected_uuids, x, y);
  594. }
  595. }
  596. }
  597. }
  598. void LLCOFWearables::selectClothing(LLWearableType::EType clothing_type)
  599. {
  600. std::vector<LLPanel*> clothing_items;
  601. mClothing->getItems(clothing_items);
  602. std::vector<LLPanel*>::iterator it;
  603. for (it = clothing_items.begin(); it != clothing_items.end(); ++it )
  604. {
  605. LLPanelClothingListItem* clothing_item = dynamic_cast<LLPanelClothingListItem*>(*it);
  606. if (clothing_item && clothing_item->getWearableType() == clothing_type)
  607. { // clothing item has specified LLWearableType::EType. Select it and exit.
  608. mClothing->selectItem(clothing_item);
  609. break;
  610. }
  611. }
  612. }
  613. //EOF