llinventoryfunctions.cpp
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:9k
源码类别:

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file llfloaterinventory.cpp
  3.  * @brief Implementation of the inventory view and associated stuff.
  4.  *
  5.  * $LicenseInfo:firstyear=2001&license=viewergpl$
  6.  * 
  7.  * Copyright (c) 2001-2010, Linden Research, Inc.
  8.  * 
  9.  * Second Life Viewer Source Code
  10.  * The source code in this file ("Source Code") is provided by Linden Lab
  11.  * to you under the terms of the GNU General Public License, version 2.0
  12.  * ("GPL"), unless you have obtained a separate licensing agreement
  13.  * ("Other License"), formally executed by you and Linden Lab.  Terms of
  14.  * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15.  * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16.  * 
  17.  * There are special exceptions to the terms and conditions of the GPL as
  18.  * it is applied to this Source Code. View the full text of the exception
  19.  * in the file doc/FLOSS-exception.txt in this software distribution, or
  20.  * online at
  21.  * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22.  * 
  23.  * By copying, modifying or distributing this software, you acknowledge
  24.  * that you have read and understood your obligations described above,
  25.  * and agree to abide by those obligations.
  26.  * 
  27.  * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28.  * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29.  * COMPLETENESS OR PERFORMANCE.
  30.  * $/LicenseInfo$
  31.  */
  32. #include "llviewerprecompiledheaders.h"
  33. #include <utility> // for std::pair<>
  34. #include "llinventoryfunctions.h"
  35. // library includes
  36. #include "llagent.h"
  37. #include "llagentwearables.h"
  38. #include "llcallingcard.h"
  39. #include "llfloaterreg.h"
  40. #include "llsdserialize.h"
  41. #include "llfiltereditor.h"
  42. #include "llspinctrl.h"
  43. #include "llui.h"
  44. #include "message.h"
  45. // newview includes
  46. #include "llappearancemgr.h"
  47. #include "llappviewer.h"
  48. //#include "llfirstuse.h"
  49. #include "llfloatercustomize.h"
  50. #include "llfocusmgr.h"
  51. #include "llfolderview.h"
  52. #include "llgesturemgr.h"
  53. #include "lliconctrl.h"
  54. #include "llimview.h"
  55. #include "llinventorybridge.h"
  56. #include "llinventoryclipboard.h"
  57. #include "llinventorymodel.h"
  58. #include "llinventorypanel.h"
  59. #include "lllineeditor.h"
  60. #include "llmenugl.h"
  61. #include "llpreviewanim.h"
  62. #include "llpreviewgesture.h"
  63. #include "llpreviewnotecard.h"
  64. #include "llpreviewscript.h"
  65. #include "llpreviewsound.h"
  66. #include "llpreviewtexture.h"
  67. #include "llresmgr.h"
  68. #include "llscrollbar.h"
  69. #include "llscrollcontainer.h"
  70. #include "llselectmgr.h"
  71. #include "lltabcontainer.h"
  72. #include "lltooldraganddrop.h"
  73. #include "lluictrlfactory.h"
  74. #include "llviewermessage.h"
  75. #include "llviewerobjectlist.h"
  76. #include "llviewerregion.h"
  77. #include "llviewerwindow.h"
  78. #include "llvoavatarself.h"
  79. #include "llwearablelist.h"
  80. BOOL LLInventoryState::sWearNewClothing = FALSE;
  81. LLUUID LLInventoryState::sWearNewClothingTransactionID;
  82. void LLSaveFolderState::setApply(BOOL apply)
  83. {
  84. mApply = apply; 
  85. // before generating new list of open folders, clear the old one
  86. if(!apply) 
  87. {
  88. clearOpenFolders(); 
  89. }
  90. }
  91. void LLSaveFolderState::doFolder(LLFolderViewFolder* folder)
  92. {
  93. LLMemType mt(LLMemType::MTYPE_INVENTORY_DO_FOLDER);
  94. if(mApply)
  95. {
  96. // we're applying the open state
  97. LLInvFVBridge* bridge = (LLInvFVBridge*)folder->getListener();
  98. if(!bridge) return;
  99. LLUUID id(bridge->getUUID());
  100. if(mOpenFolders.find(id) != mOpenFolders.end())
  101. {
  102. folder->setOpen(TRUE);
  103. }
  104. else
  105. {
  106. // keep selected filter in its current state, this is less jarring to user
  107. if (!folder->isSelected())
  108. {
  109. folder->setOpen(FALSE);
  110. }
  111. }
  112. }
  113. else
  114. {
  115. // we're recording state at this point
  116. if(folder->isOpen())
  117. {
  118. LLInvFVBridge* bridge = (LLInvFVBridge*)folder->getListener();
  119. if(!bridge) return;
  120. mOpenFolders.insert(bridge->getUUID());
  121. }
  122. }
  123. }
  124. void LLOpenFilteredFolders::doItem(LLFolderViewItem *item)
  125. {
  126. if (item->getFiltered())
  127. {
  128. item->getParentFolder()->setOpenArrangeRecursively(TRUE, LLFolderViewFolder::RECURSE_UP);
  129. }
  130. }
  131. void LLOpenFilteredFolders::doFolder(LLFolderViewFolder* folder)
  132. {
  133. if (folder->getFiltered() && folder->getParentFolder())
  134. {
  135. folder->getParentFolder()->setOpenArrangeRecursively(TRUE, LLFolderViewFolder::RECURSE_UP);
  136. }
  137. // if this folder didn't pass the filter, and none of its descendants did
  138. else if (!folder->getFiltered() && !folder->hasFilteredDescendants())
  139. {
  140. folder->setOpenArrangeRecursively(FALSE, LLFolderViewFolder::RECURSE_NO);
  141. }
  142. }
  143. void LLSelectFirstFilteredItem::doItem(LLFolderViewItem *item)
  144. {
  145. if (item->getFiltered() && !mItemSelected)
  146. {
  147. item->getRoot()->setSelection(item, FALSE, FALSE);
  148. if (item->getParentFolder())
  149. {
  150. item->getParentFolder()->setOpenArrangeRecursively(TRUE, LLFolderViewFolder::RECURSE_UP);
  151. }
  152. item->getRoot()->scrollToShowSelection();
  153. mItemSelected = TRUE;
  154. }
  155. }
  156. void LLSelectFirstFilteredItem::doFolder(LLFolderViewFolder* folder)
  157. {
  158. if (folder->getFiltered() && !mItemSelected)
  159. {
  160. folder->getRoot()->setSelection(folder, FALSE, FALSE);
  161. if (folder->getParentFolder())
  162. {
  163. folder->getParentFolder()->setOpenArrangeRecursively(TRUE, LLFolderViewFolder::RECURSE_UP);
  164. }
  165. folder->getRoot()->scrollToShowSelection();
  166. mItemSelected = TRUE;
  167. }
  168. }
  169. void LLOpenFoldersWithSelection::doItem(LLFolderViewItem *item)
  170. {
  171. if (item->getParentFolder() && item->isSelected())
  172. {
  173. item->getParentFolder()->setOpenArrangeRecursively(TRUE, LLFolderViewFolder::RECURSE_UP);
  174. }
  175. }
  176. void LLOpenFoldersWithSelection::doFolder(LLFolderViewFolder* folder)
  177. {
  178. if (folder->getParentFolder() && folder->isSelected())
  179. {
  180. folder->getParentFolder()->setOpenArrangeRecursively(TRUE, LLFolderViewFolder::RECURSE_UP);
  181. }
  182. }
  183. static void assign_clothing_bodypart_icon(EInventoryIcon &idx, U32 attachment_point)
  184. {
  185. const EWearableType wearable_type = EWearableType(LLInventoryItem::II_FLAGS_WEARABLES_MASK & attachment_point);
  186. switch(wearable_type)
  187. {
  188. case WT_SHAPE:
  189. idx = BODYPART_SHAPE_ICON_NAME;
  190. break;
  191. case WT_SKIN:
  192. idx = BODYPART_SKIN_ICON_NAME;
  193. break;
  194. case WT_HAIR:
  195. idx = BODYPART_HAIR_ICON_NAME;
  196. break;
  197. case WT_EYES:
  198. idx = BODYPART_EYES_ICON_NAME;
  199. break;
  200. case WT_SHIRT:
  201. idx = CLOTHING_SHIRT_ICON_NAME;
  202. break;
  203. case WT_PANTS:
  204. idx = CLOTHING_PANTS_ICON_NAME;
  205. break;
  206. case WT_SHOES:
  207. idx = CLOTHING_SHOES_ICON_NAME;
  208. break;
  209. case WT_SOCKS:
  210. idx = CLOTHING_SOCKS_ICON_NAME;
  211. break;
  212. case WT_JACKET:
  213. idx = CLOTHING_JACKET_ICON_NAME;
  214. break;
  215. case WT_GLOVES:
  216. idx = CLOTHING_GLOVES_ICON_NAME;
  217. break;
  218. case WT_UNDERSHIRT:
  219. idx = CLOTHING_UNDERSHIRT_ICON_NAME;
  220. break;
  221. case WT_UNDERPANTS:
  222. idx = CLOTHING_UNDERPANTS_ICON_NAME;
  223. break;
  224. case WT_SKIRT:
  225. idx = CLOTHING_SKIRT_ICON_NAME;
  226. break;
  227. case WT_ALPHA:
  228. idx = CLOTHING_ALPHA_ICON_NAME;
  229. break;
  230. case WT_TATTOO:
  231. idx = CLOTHING_TATTOO_ICON_NAME;
  232. break;
  233. default:
  234. break;
  235. }
  236. }
  237.   
  238. const std::string& get_item_icon_name(LLAssetType::EType asset_type,
  239.  LLInventoryType::EType inventory_type,
  240.  U32 attachment_point,
  241.  BOOL item_is_multi )
  242. {
  243. EInventoryIcon idx = OBJECT_ICON_NAME;
  244. if ( item_is_multi )
  245. {
  246. idx = OBJECT_MULTI_ICON_NAME;
  247. }
  248. switch(asset_type)
  249. {
  250. case LLAssetType::AT_TEXTURE:
  251. if(LLInventoryType::IT_SNAPSHOT == inventory_type)
  252. {
  253. idx = SNAPSHOT_ICON_NAME;
  254. }
  255. else
  256. {
  257. idx = TEXTURE_ICON_NAME;
  258. }
  259. break;
  260. case LLAssetType::AT_SOUND:
  261. idx = SOUND_ICON_NAME;
  262. break;
  263. case LLAssetType::AT_CALLINGCARD:
  264. if(attachment_point!= 0)
  265. {
  266. idx = CALLINGCARD_ONLINE_ICON_NAME;
  267. }
  268. else
  269. {
  270. idx = CALLINGCARD_OFFLINE_ICON_NAME;
  271. }
  272. break;
  273. case LLAssetType::AT_LANDMARK:
  274. if(attachment_point!= 0)
  275. {
  276. idx = LANDMARK_VISITED_ICON_NAME;
  277. }
  278. else
  279. {
  280. idx = LANDMARK_ICON_NAME;
  281. }
  282. break;
  283. case LLAssetType::AT_SCRIPT:
  284. case LLAssetType::AT_LSL_TEXT:
  285. case LLAssetType::AT_LSL_BYTECODE:
  286. idx = SCRIPT_ICON_NAME;
  287. break;
  288. case LLAssetType::AT_CLOTHING:
  289. idx = CLOTHING_ICON_NAME;
  290. assign_clothing_bodypart_icon(idx, attachment_point);
  291. break;
  292. case LLAssetType::AT_BODYPART:
  293. idx = BODYPART_ICON_NAME;
  294. assign_clothing_bodypart_icon(idx, attachment_point);
  295. break;
  296. case LLAssetType::AT_NOTECARD:
  297. idx = NOTECARD_ICON_NAME;
  298. break;
  299. case LLAssetType::AT_ANIMATION:
  300. idx = ANIMATION_ICON_NAME;
  301. break;
  302. case LLAssetType::AT_GESTURE:
  303. idx = GESTURE_ICON_NAME;
  304. break;
  305. case LLAssetType::AT_LINK:
  306. idx = LINKITEM_ICON_NAME;
  307. break;
  308. case LLAssetType::AT_LINK_FOLDER:
  309. idx = LINKFOLDER_ICON_NAME;
  310. break;
  311. default:
  312. break;
  313. }
  314. return ICON_NAME[idx];
  315. }
  316. LLUIImagePtr get_item_icon(LLAssetType::EType asset_type,
  317.  LLInventoryType::EType inventory_type,
  318.  U32 attachment_point,
  319.  BOOL item_is_multi)
  320. {
  321. const std::string& icon_name = get_item_icon_name(asset_type, inventory_type, attachment_point, item_is_multi );
  322. return LLUI::getUIImage(icon_name);
  323. }
  324. BOOL get_is_item_worn(const LLUUID& id)
  325. {
  326. const LLViewerInventoryItem* item = gInventory.getItem(id);
  327. if (!item)
  328. return FALSE;
  329. switch(item->getType())
  330. {
  331. case LLAssetType::AT_OBJECT:
  332. {
  333. const LLVOAvatarSelf* my_avatar = gAgent.getAvatarObject();
  334. if(my_avatar && my_avatar->isWearingAttachment(item->getLinkedUUID()))
  335. return TRUE;
  336. break;
  337. }
  338. case LLAssetType::AT_BODYPART:
  339. case LLAssetType::AT_CLOTHING:
  340. if(gAgentWearables.isWearingItem(item->getLinkedUUID()))
  341. return TRUE;
  342. break;
  343. case LLAssetType::AT_GESTURE:
  344. if (LLGestureManager::instance().isGestureActive(item->getLinkedUUID()))
  345. return TRUE;
  346. break;
  347. default:
  348. break;
  349. }
  350. return FALSE;
  351. }