PageRenderTime 40ms CodeModel.GetById 19ms app.highlight 17ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llagentwearables.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 310 lines | 184 code | 48 blank | 78 comment | 0 complexity | 6379952115567d0fec344df1e20e1047 MD5 | raw file
  1/** 
  2 * @file llagentwearables.h
  3 * @brief LLAgentWearables class header file
  4 *
  5 * $LicenseInfo:firstyear=2000&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_LLAGENTWEARABLES_H
 28#define LL_LLAGENTWEARABLES_H
 29
 30// libraries
 31#include "llmemory.h"
 32#include "llui.h"
 33#include "lluuid.h"
 34#include "llinventory.h"
 35
 36// newview
 37#include "llinventorymodel.h"
 38#include "llviewerinventory.h"
 39#include "llvoavatardefines.h"
 40
 41class LLInventoryItem;
 42class LLVOAvatarSelf;
 43class LLWearable;
 44class LLInitialWearablesFetch;
 45class LLViewerObject;
 46class LLTexLayerTemplate;
 47
 48class LLAgentWearables : public LLInitClass<LLAgentWearables>
 49{
 50	//--------------------------------------------------------------------
 51	// Constructors / destructors / Initializers
 52	//--------------------------------------------------------------------
 53public:
 54	friend class LLInitialWearablesFetch;
 55
 56	LLAgentWearables();
 57	virtual ~LLAgentWearables();
 58	void 			setAvatarObject(LLVOAvatarSelf *avatar);
 59	void			createStandardWearables(); 
 60	void			cleanup();
 61	void			dump();
 62
 63	// LLInitClass interface
 64	static void initClass();
 65protected:
 66	void			createStandardWearablesDone(S32 type, U32 index/* = 0*/);
 67	void			createStandardWearablesAllDone();
 68	
 69	//--------------------------------------------------------------------
 70	// Queries
 71	//--------------------------------------------------------------------
 72public:
 73	BOOL			isWearingItem(const LLUUID& item_id) const;
 74	BOOL			isWearableModifiable(LLWearableType::EType type, U32 index /*= 0*/) const;
 75	BOOL			isWearableModifiable(const LLUUID& item_id) const;
 76
 77	BOOL			isWearableCopyable(LLWearableType::EType type, U32 index /*= 0*/) const;
 78	BOOL			areWearablesLoaded() const;
 79	bool			isCOFChangeInProgress() const { return mCOFChangeInProgress; }
 80	void			updateWearablesLoaded();
 81	void			checkWearablesLoaded() const;
 82	bool			canMoveWearable(const LLUUID& item_id, bool closer_to_body);
 83	
 84	// Note: False for shape, skin, eyes, and hair, unless you have MORE than 1.
 85	bool			canWearableBeRemoved(const LLWearable* wearable) const;
 86
 87	void			animateAllWearableParams(F32 delta, BOOL upload_bake);
 88
 89	//--------------------------------------------------------------------
 90	// Accessors
 91	//--------------------------------------------------------------------
 92public:
 93	const LLUUID		getWearableItemID(LLWearableType::EType type, U32 index /*= 0*/) const;
 94	const LLUUID		getWearableAssetID(LLWearableType::EType type, U32 index /*= 0*/) const;
 95	const LLWearable*	getWearableFromItemID(const LLUUID& item_id) const;
 96	LLWearable*	getWearableFromItemID(const LLUUID& item_id);
 97	LLWearable*	getWearableFromAssetID(const LLUUID& asset_id);
 98	LLInventoryItem*	getWearableInventoryItem(LLWearableType::EType type, U32 index /*= 0*/);
 99	static BOOL			selfHasWearable(LLWearableType::EType type);
100	LLWearable*			getWearable(const LLWearableType::EType type, U32 index /*= 0*/); 
101	const LLWearable* 	getWearable(const LLWearableType::EType type, U32 index /*= 0*/) const;
102	LLWearable*		getTopWearable(const LLWearableType::EType type);
103	LLWearable*		getBottomWearable(const LLWearableType::EType type);
104	U32				getWearableCount(const LLWearableType::EType type) const;
105	U32				getWearableCount(const U32 tex_index) const;
106
107	static const U32 MAX_CLOTHING_PER_TYPE = 5; 
108
109
110	//--------------------------------------------------------------------
111	// Setters
112	//--------------------------------------------------------------------
113
114private:
115	// Low-level data structure setter - public access is via setWearableItem, etc.
116	void 			setWearable(const LLWearableType::EType type, U32 index, LLWearable *wearable);
117	U32 			pushWearable(const LLWearableType::EType type, LLWearable *wearable);
118	void			wearableUpdated(LLWearable *wearable);
119	void 			popWearable(LLWearable *wearable);
120	void			popWearable(const LLWearableType::EType type, U32 index);
121	
122public:
123	void			setWearableItem(LLInventoryItem* new_item, LLWearable* wearable, bool do_append = false);
124	void			setWearableOutfit(const LLInventoryItem::item_array_t& items, const LLDynamicArray< LLWearable* >& wearables, BOOL remove);
125	void			setWearableName(const LLUUID& item_id, const std::string& new_name);
126	void			addLocalTextureObject(const LLWearableType::EType wearable_type, const LLVOAvatarDefines::ETextureIndex texture_type, U32 wearable_index);
127	U32				getWearableIndex(const LLWearable *wearable) const;
128
129protected:
130	void			setWearableFinal(LLInventoryItem* new_item, LLWearable* new_wearable, bool do_append = false);
131	static bool		onSetWearableDialog(const LLSD& notification, const LLSD& response, LLWearable* wearable);
132
133	void			addWearableToAgentInventory(LLPointer<LLInventoryCallback> cb,
134												LLWearable* wearable, 
135												const LLUUID& category_id = LLUUID::null,
136												BOOL notify = TRUE);
137	void 			addWearabletoAgentInventoryDone(const LLWearableType::EType type,
138													const U32 index,
139													const LLUUID& item_id,
140													LLWearable* wearable);
141	void			recoverMissingWearable(const LLWearableType::EType type, U32 index /*= 0*/);
142	void			recoverMissingWearableDone();
143
144	//--------------------------------------------------------------------
145	// Editing/moving wearables
146	//--------------------------------------------------------------------
147
148public:
149	static void		createWearable(LLWearableType::EType type, bool wear = false, const LLUUID& parent_id = LLUUID::null);
150	static void		editWearable(const LLUUID& item_id);
151	bool			moveWearable(const LLViewerInventoryItem* item, bool closer_to_body);
152
153	void			requestEditingWearable(const LLUUID& item_id);
154	void			editWearableIfRequested(const LLUUID& item_id);
155
156private:
157	LLUUID			mItemToEdit;
158
159	//--------------------------------------------------------------------
160	// Removing wearables
161	//--------------------------------------------------------------------
162public:
163	void			removeWearable(const LLWearableType::EType type, bool do_remove_all /*= false*/, U32 index /*= 0*/);
164private:
165	void			removeWearableFinal(const LLWearableType::EType type, bool do_remove_all /*= false*/, U32 index /*= 0*/);
166protected:
167	static bool		onRemoveWearableDialog(const LLSD& notification, const LLSD& response);
168	
169	//--------------------------------------------------------------------
170	// Server Communication
171	//--------------------------------------------------------------------
172public:
173	// Processes the initial wearables update message (if necessary, since the outfit folder makes it redundant)
174	static void		processAgentInitialWearablesUpdate(LLMessageSystem* mesgsys, void** user_data);
175	LLUUID			computeBakedTextureHash(LLVOAvatarDefines::EBakedTextureIndex baked_index,
176											BOOL generate_valid_hash = TRUE);
177
178protected:
179	void			sendAgentWearablesUpdate();
180	void			sendAgentWearablesRequest();
181	void			queryWearableCache();
182	void 			updateServer();
183	static void		onInitialWearableAssetArrived(LLWearable* wearable, void* userdata);
184
185	//--------------------------------------------------------------------
186	// Outfits
187	//--------------------------------------------------------------------
188public:
189	
190	// Should only be called if we *know* we've never done so before, since users may
191	// not want the Library outfits to stay in their quick outfit selector and can delete them.
192	void			populateMyOutfitsFolder();
193
194private:
195	void			makeNewOutfitDone(S32 type, U32 index); 
196
197	//--------------------------------------------------------------------
198	// Save Wearables
199	//--------------------------------------------------------------------
200public:	
201	void			saveWearableAs(const LLWearableType::EType type, const U32 index, const std::string& new_name, BOOL save_in_lost_and_found);
202	void			saveWearable(const LLWearableType::EType type, const U32 index, BOOL send_update = TRUE,
203								 const std::string new_name = "");
204	void			saveAllWearables();
205	void			revertWearable(const LLWearableType::EType type, const U32 index);
206
207	//--------------------------------------------------------------------
208	// Static UI hooks
209	//--------------------------------------------------------------------
210public:
211	static void		userRemoveWearable(const LLWearableType::EType &type, const U32 &index);
212	static void		userRemoveWearablesOfType(const LLWearableType::EType &type);
213	
214	typedef std::vector<LLViewerObject*> llvo_vec_t;
215
216	static void 	userUpdateAttachments(LLInventoryModel::item_array_t& obj_item_array);
217	static void		userRemoveMultipleAttachments(llvo_vec_t& llvo_array);
218	static void		userRemoveAllAttachments();
219	static void		userAttachMultipleAttachments(LLInventoryModel::item_array_t& obj_item_array);
220
221	BOOL			itemUpdatePending(const LLUUID& item_id) const;
222	U32				itemUpdatePendingCount() const;
223
224	//--------------------------------------------------------------------
225	// Signals
226	//--------------------------------------------------------------------
227public:
228	typedef boost::function<void()>			loading_started_callback_t;
229	typedef boost::signals2::signal<void()>	loading_started_signal_t;
230	boost::signals2::connection				addLoadingStartedCallback(loading_started_callback_t cb);
231
232	typedef boost::function<void()>			loaded_callback_t;
233	typedef boost::signals2::signal<void()>	loaded_signal_t;
234	boost::signals2::connection				addLoadedCallback(loaded_callback_t cb);
235
236	void									notifyLoadingStarted();
237	void									notifyLoadingFinished();
238
239private:
240	loading_started_signal_t				mLoadingStartedSignal; // should be called before wearables are changed
241	loaded_signal_t							mLoadedSignal; // emitted when all agent wearables get loaded
242
243	//--------------------------------------------------------------------
244	// Member variables
245	//--------------------------------------------------------------------
246private:
247	typedef std::vector<LLWearable*> wearableentry_vec_t; // all wearables of a certain type (EG all shirts)
248	typedef std::map<LLWearableType::EType, wearableentry_vec_t> wearableentry_map_t;	// wearable "categories" arranged by wearable type
249	wearableentry_map_t mWearableDatas;
250
251	static BOOL		mInitialWearablesUpdateReceived;
252	BOOL			mWearablesLoaded;
253	std::set<LLUUID>	mItemsAwaitingWearableUpdate;
254
255	/**
256	 * True if agent's outfit is being changed now.
257	 */
258	BOOL			mCOFChangeInProgress;
259	
260	//--------------------------------------------------------------------------------
261	// Support classes
262	//--------------------------------------------------------------------------------
263private:
264	class createStandardWearablesAllDoneCallback : public LLRefCount
265	{
266	protected:
267		~createStandardWearablesAllDoneCallback();
268	};
269	class sendAgentWearablesUpdateCallback : public LLRefCount
270	{
271	protected:
272		~sendAgentWearablesUpdateCallback();
273	};
274
275	class addWearableToAgentInventoryCallback : public LLInventoryCallback
276	{
277	public:
278		enum ETodo
279		{
280			CALL_NONE = 0,
281			CALL_UPDATE = 1,
282			CALL_RECOVERDONE = 2,
283			CALL_CREATESTANDARDDONE = 4,
284			CALL_MAKENEWOUTFITDONE = 8,
285			CALL_WEARITEM = 16
286		};
287
288		addWearableToAgentInventoryCallback(LLPointer<LLRefCount> cb,
289											LLWearableType::EType type,
290											U32 index,
291											LLWearable* wearable,
292											U32 todo = CALL_NONE);
293		virtual void fire(const LLUUID& inv_item);
294	private:
295		LLWearableType::EType mType;
296		U32 mIndex;
297		LLWearable* mWearable;
298		U32 mTodo;
299		LLPointer<LLRefCount> mCB;
300	};
301
302}; // LLAgentWearables
303
304extern LLAgentWearables gAgentWearables;
305
306//--------------------------------------------------------------------
307// Types
308//--------------------------------------------------------------------	
309
310#endif // LL_AGENTWEARABLES_H