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