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