PageRenderTime 82ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llwearableitemslist.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 479 lines | 239 code | 90 blank | 150 comment | 2 complexity | 393e7d6aea2ba838023eeee557ff5400 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llwearableitemslist.h
  3. * @brief A flat list of wearable items.
  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. #ifndef LL_LLWEARABLEITEMSLIST_H
  27. #define LL_LLWEARABLEITEMSLIST_H
  28. // libs
  29. #include "llpanel.h"
  30. #include "llsingleton.h"
  31. // newview
  32. #include "llinventoryitemslist.h"
  33. #include "llinventorylistitem.h"
  34. #include "lllistcontextmenu.h"
  35. #include "llwearabletype.h"
  36. /**
  37. * @class LLPanelWearableListItem
  38. *
  39. * Extends LLPanelInventoryListItemBase:
  40. * - makes side widgets show on mouse_enter and hide on
  41. * mouse_leave events.
  42. * - provides callback for button clicks
  43. */
  44. class LLPanelWearableListItem : public LLPanelInventoryListItemBase
  45. {
  46. LOG_CLASS(LLPanelWearableListItem);
  47. public:
  48. /**
  49. * Shows buttons when mouse is over
  50. */
  51. /*virtual*/ void onMouseEnter(S32 x, S32 y, MASK mask);
  52. /**
  53. * Hides buttons when mouse is out
  54. */
  55. /*virtual*/ void onMouseLeave(S32 x, S32 y, MASK mask);
  56. protected:
  57. LLPanelWearableListItem(LLViewerInventoryItem* item, const Params& params);
  58. };
  59. /**
  60. * @class LLPanelWearableOutfitItem
  61. *
  62. * Outfit item for "My Outfits" list.
  63. * Extends LLPanelInventoryListItemBase with handling
  64. * double click to wear the item.
  65. */
  66. class LLPanelWearableOutfitItem : public LLPanelInventoryListItemBase
  67. {
  68. LOG_CLASS(LLPanelWearableOutfitItem);
  69. public:
  70. static LLPanelWearableOutfitItem* create(LLViewerInventoryItem* item,
  71. bool worn_indication_enabled);
  72. /**
  73. * Updates item name and (worn) suffix.
  74. */
  75. /*virtual*/ void updateItem(const std::string& name,
  76. EItemState item_state = IS_DEFAULT);
  77. protected:
  78. LLPanelWearableOutfitItem(LLViewerInventoryItem* item,
  79. bool worn_indication_enabled, const Params& params);
  80. private:
  81. bool mWornIndicationEnabled;
  82. };
  83. class LLPanelDeletableWearableListItem : public LLPanelWearableListItem
  84. {
  85. LOG_CLASS(LLPanelDeletableWearableListItem);
  86. public:
  87. struct Params : public LLInitParam::Block<Params, LLPanelWearableListItem::Params>
  88. {
  89. Optional<LLButton::Params> delete_btn;
  90. Params();
  91. };
  92. static LLPanelDeletableWearableListItem* create(LLViewerInventoryItem* item);
  93. virtual ~LLPanelDeletableWearableListItem() {};
  94. /*virtual*/ BOOL postBuild();
  95. /**
  96. * Make button visible during mouse over event.
  97. */
  98. inline void setShowDeleteButton(bool show) { setShowWidget("btn_delete", show); }
  99. protected:
  100. LLPanelDeletableWearableListItem(LLViewerInventoryItem* item, const Params& params);
  101. };
  102. /** Outfit list item for an attachment */
  103. class LLPanelAttachmentListItem : public LLPanelDeletableWearableListItem
  104. {
  105. LOG_CLASS(LLPanelAttachmentListItem);
  106. public:
  107. static LLPanelAttachmentListItem* create(LLViewerInventoryItem* item);
  108. virtual ~LLPanelAttachmentListItem() {};
  109. /** Set item title. Joint name is added to the title in parenthesis */
  110. /*virtual*/ void updateItem(const std::string& name,
  111. EItemState item_state = IS_DEFAULT);
  112. protected:
  113. LLPanelAttachmentListItem(LLViewerInventoryItem* item, const Params& params) : LLPanelDeletableWearableListItem(item, params) {};
  114. };
  115. /**
  116. * @class LLPanelClothingListItem
  117. *
  118. * Provides buttons for editing, moving, deleting a wearable.
  119. */
  120. class LLPanelClothingListItem : public LLPanelDeletableWearableListItem
  121. {
  122. LOG_CLASS(LLPanelClothingListItem);
  123. public:
  124. struct Params : public LLInitParam::Block<Params, LLPanelDeletableWearableListItem::Params>
  125. {
  126. Optional<LLButton::Params> up_btn,
  127. down_btn,
  128. edit_btn;
  129. Optional<LLPanel::Params> lock_panel,
  130. edit_panel;
  131. Optional<LLIconCtrl::Params> lock_icon;
  132. Params();
  133. };
  134. static LLPanelClothingListItem* create(LLViewerInventoryItem* item);
  135. virtual ~LLPanelClothingListItem();
  136. /*virtual*/ BOOL postBuild();
  137. /**
  138. * Make button visible during mouse over event.
  139. */
  140. inline void setShowMoveUpButton(bool show) { setShowWidget("btn_move_up", show); }
  141. inline void setShowMoveDownButton(bool show) { setShowWidget("btn_move_down", show); }
  142. inline void setShowLockButton(bool show) { setShowWidget("btn_lock", show); }
  143. inline void setShowEditButton(bool show) { setShowWidget("btn_edit_panel", show); }
  144. protected:
  145. LLPanelClothingListItem(LLViewerInventoryItem* item, const Params& params);
  146. };
  147. class LLPanelBodyPartsListItem : public LLPanelWearableListItem
  148. {
  149. LOG_CLASS(LLPanelBodyPartsListItem);
  150. public:
  151. struct Params : public LLInitParam::Block<Params, LLPanelWearableListItem::Params>
  152. {
  153. Optional<LLButton::Params> edit_btn;
  154. Optional<LLPanel::Params> lock_panel,
  155. edit_panel;
  156. Optional<LLIconCtrl::Params> lock_icon;
  157. Params();
  158. };
  159. static LLPanelBodyPartsListItem* create(LLViewerInventoryItem* item);
  160. virtual ~LLPanelBodyPartsListItem();
  161. /*virtual*/ BOOL postBuild();
  162. /**
  163. * Make button visible during mouse over event.
  164. */
  165. inline void setShowLockButton(bool show) { setShowWidget("btn_lock", show); }
  166. inline void setShowEditButton(bool show) { setShowWidget("btn_edit_panel", show); }
  167. protected:
  168. LLPanelBodyPartsListItem(LLViewerInventoryItem* item, const Params& params);
  169. };
  170. /**
  171. * @class LLPanelDummyClothingListItem
  172. *
  173. * A dummy item panel - displays grayed clothing icon, grayed title '<clothing> not worn' and 'add' button
  174. */
  175. class LLPanelDummyClothingListItem : public LLPanelWearableListItem
  176. {
  177. public:
  178. struct Params : public LLInitParam::Block<Params, LLPanelWearableListItem::Params>
  179. {
  180. Optional<LLPanel::Params> add_panel;
  181. Optional<LLButton::Params> add_btn;
  182. Params();
  183. };
  184. static LLPanelDummyClothingListItem* create(LLWearableType::EType w_type);
  185. /*virtual*/ BOOL postBuild();
  186. LLWearableType::EType getWearableType() const;
  187. protected:
  188. LLPanelDummyClothingListItem(LLWearableType::EType w_type, const Params& params);
  189. static std::string wearableTypeToString(LLWearableType::EType w_type);
  190. private:
  191. LLWearableType::EType mWearableType;
  192. };
  193. /**
  194. * @class LLWearableListItemComparator
  195. *
  196. * Abstract comparator of wearable list items.
  197. */
  198. class LLWearableListItemComparator : public LLFlatListView::ItemComparator
  199. {
  200. LOG_CLASS(LLWearableListItemComparator);
  201. public:
  202. LLWearableListItemComparator() {};
  203. virtual ~LLWearableListItemComparator() {};
  204. virtual bool compare(const LLPanel* item1, const LLPanel* item2) const
  205. {
  206. const LLPanelInventoryListItemBase* wearable_item1 = dynamic_cast<const LLPanelInventoryListItemBase*>(item1);
  207. const LLPanelInventoryListItemBase* wearable_item2 = dynamic_cast<const LLPanelInventoryListItemBase*>(item2);
  208. if (!wearable_item1 || !wearable_item2)
  209. {
  210. llwarning("item1 and item2 cannot be null", 0);
  211. return true;
  212. }
  213. return doCompare(wearable_item1, wearable_item2);
  214. }
  215. protected:
  216. /**
  217. * Returns true if wearable_item1 < wearable_item2, false otherwise
  218. * Implement this method in your particular comparator.
  219. */
  220. virtual bool doCompare(const LLPanelInventoryListItemBase* wearable_item1, const LLPanelInventoryListItemBase* wearable_item2) const = 0;
  221. };
  222. /**
  223. * @class LLWearableItemNameComparator
  224. *
  225. * Comparator for sorting wearable list items by name.
  226. */
  227. class LLWearableItemNameComparator : public LLWearableListItemComparator
  228. {
  229. LOG_CLASS(LLWearableItemNameComparator);
  230. public:
  231. LLWearableItemNameComparator() {};
  232. virtual ~LLWearableItemNameComparator() {};
  233. protected:
  234. /*virtual*/ bool doCompare(const LLPanelInventoryListItemBase* wearable_item1, const LLPanelInventoryListItemBase* wearable_item2) const;
  235. };
  236. /**
  237. * @class LLWearableItemTypeNameComparator
  238. *
  239. * Comparator for sorting wearable list items by type and name.
  240. */
  241. class LLWearableItemTypeNameComparator : public LLWearableItemNameComparator
  242. {
  243. LOG_CLASS(LLWearableItemTypeNameComparator);
  244. public:
  245. LLWearableItemTypeNameComparator();
  246. virtual ~LLWearableItemTypeNameComparator() {};
  247. enum ETypeListOrder
  248. {
  249. ORDER_RANK_1 = 1,
  250. ORDER_RANK_2,
  251. ORDER_RANK_3,
  252. ORDER_RANK_UNKNOWN
  253. };
  254. void setOrder(LLAssetType::EType items_of_type, ETypeListOrder order_priority, bool sort_items_by_name, bool sort_wearable_items_by_name);
  255. protected:
  256. /**
  257. * All information about sort order is stored in mWearableOrder map
  258. *
  259. * mWearableOrder : KEYS VALUES
  260. * [LLAssetType] [struct LLWearableTypeOrder]
  261. *
  262. *---------------------------------------------------------------------------------------------
  263. * I. Determines order (ORDER_RANK) in which items of LLAssetType should be displayed in list.
  264. * For example by spec in MY OUTFITS the order is:
  265. * 1. AT_CLOTHING (ORDER_RANK_1)
  266. * 2. AT_OBJECT (ORDER_RANK_2)
  267. * 3. AT_BODYPART (ORDER_RANK_3)
  268. *
  269. * II.Items of each type(LLAssetType) are sorted by name or type(LLWearableType)
  270. * For example by spec in MY OUTFITS the order within each items type(LLAssetType) is:
  271. * 1. AT_OBJECTS (abc order)
  272. * 2. AT_CLOTHINGS
  273. * - by type (types order determined in LLWearableType::EType)
  274. * - outer layer on top
  275. * 3. AT_BODYPARTS (abc order)
  276. *---------------------------------------------------------------------------------------------
  277. *
  278. * For each LLAssetType (KEYS in mWearableOrder) the information about:
  279. *
  280. * I. ORDER_RANK (the flag is LLWearableTypeOrder::mOrderPriority)
  281. *
  282. * II. whether items of this LLAssetType type should be ordered
  283. * by name or by LLWearableType::EType (the flag is LLWearableTypeOrder::mSortAssetTypeByName)
  284. *
  285. * III.whether items of LLWearableType type within this LLAssetType
  286. * should be ordered by name (the flag is LLWearableTypeOrder::mSortWearableTypeByName)
  287. *
  288. * holds in mWearableOrder map as VALUES (struct LLWearableTypeOrder).
  289. */
  290. /*virtual*/ bool doCompare(const LLPanelInventoryListItemBase* wearable_item1, const LLPanelInventoryListItemBase* wearable_item2) const;
  291. private:
  292. struct LLWearableTypeOrder
  293. {
  294. ETypeListOrder mOrderPriority;
  295. bool mSortAssetTypeByName;
  296. bool mSortWearableTypeByName;
  297. LLWearableTypeOrder(ETypeListOrder order_priority, bool sort_asset_by_name, bool sort_wearable_by_name);
  298. LLWearableTypeOrder() : mOrderPriority(ORDER_RANK_UNKNOWN), mSortAssetTypeByName(false), mSortWearableTypeByName(false) {};
  299. };
  300. ETypeListOrder getTypeListOrder(LLAssetType::EType item_type) const;
  301. bool sortAssetTypeByName(LLAssetType::EType item_type) const;
  302. bool sortWearableTypeByName(LLAssetType::EType item_type) const;
  303. typedef std::map<LLAssetType::EType,LLWearableTypeOrder> wearable_type_order_map_t;
  304. wearable_type_order_map_t mWearableOrder;
  305. };
  306. /**
  307. * @class LLWearableItemCreationDateComparator
  308. *
  309. * Comparator for sorting wearable list items by creation date (newest go first).
  310. */
  311. class LLWearableItemCreationDateComparator : public LLWearableItemNameComparator
  312. {
  313. LOG_CLASS(LLWearableItemCreationDateComparator);
  314. protected:
  315. /*virtual*/ bool doCompare(const LLPanelInventoryListItemBase* item1, const LLPanelInventoryListItemBase* item2) const;
  316. };
  317. /**
  318. * @class LLWearableItemsList
  319. *
  320. * A flat list of wearable inventory items.
  321. * Collects all items that can be a part of an outfit from
  322. * an inventory category specified by UUID and displays them
  323. * as a flat list.
  324. */
  325. class LLWearableItemsList : public LLInventoryItemsList
  326. {
  327. public:
  328. /**
  329. * Context menu.
  330. *
  331. * This menu is likely to be used from outside
  332. * (e.g. for items selected across multiple wearable lists),
  333. * so making it a singleton.
  334. */
  335. class ContextMenu : public LLListContextMenu, public LLSingleton<ContextMenu>
  336. {
  337. public:
  338. ContextMenu();
  339. /*virtual*/ void show(LLView* spawning_view, const uuid_vec_t& uuids, S32 x, S32 y);
  340. protected:
  341. enum {
  342. MASK_CLOTHING = 0x01,
  343. MASK_BODYPART = 0x02,
  344. MASK_ATTACHMENT = 0x04,
  345. MASK_UNKNOWN = 0x08,
  346. };
  347. /* virtual */ LLContextMenu* createMenu();
  348. void updateItemsVisibility(LLContextMenu* menu);
  349. void updateItemsLabels(LLContextMenu* menu);
  350. static void setMenuItemVisible(LLContextMenu* menu, const std::string& name, bool val);
  351. static void setMenuItemEnabled(LLContextMenu* menu, const std::string& name, bool val);
  352. static void updateMask(U32& mask, LLAssetType::EType at);
  353. static void createNewWearable(const LLUUID& item_id);
  354. static bool canAddWearables(const uuid_vec_t& item_ids);
  355. LLWearableItemsList* mParent;
  356. };
  357. struct Params : public LLInitParam::Block<Params, LLInventoryItemsList::Params>
  358. {
  359. Optional<bool> standalone;
  360. Optional<bool> worn_indication_enabled;
  361. Params();
  362. };
  363. typedef enum e_sort_order {
  364. // Values should be compatible with InventorySortOrder setting.
  365. E_SORT_BY_NAME = 0,
  366. E_SORT_BY_MOST_RECENT = 1,
  367. E_SORT_BY_TYPE_LAYER = 2,
  368. E_SORT_BY_TYPE_NAME = 3,
  369. } ESortOrder;
  370. virtual ~LLWearableItemsList();
  371. /*virtual*/ void addNewItem(LLViewerInventoryItem* item, bool rearrange = true);
  372. void updateList(const LLUUID& category_id);
  373. /**
  374. * Update items that match UUIDs from changed_items_uuids
  375. * or links that point at such items.
  376. */
  377. void updateChangedItems(const uuid_vec_t& changed_items_uuids);
  378. bool isStandalone() const { return mIsStandalone; }
  379. ESortOrder getSortOrder() const { return mSortOrder; }
  380. void setSortOrder(ESortOrder sort_order, bool sort_now = true);
  381. protected:
  382. friend class LLUICtrlFactory;
  383. LLWearableItemsList(const LLWearableItemsList::Params& p);
  384. void onRightClick(S32 x, S32 y);
  385. bool mIsStandalone;
  386. bool mWornIndicationEnabled;
  387. ESortOrder mSortOrder;
  388. };
  389. #endif //LL_LLWEARABLEITEMSLIST_H