llinventoryicon.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. /**
  2. * @file llinventoryicon.cpp
  3. * @brief Implementation of the inventory icon.
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 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 "llinventoryicon.h"
  34. #include "lldictionary.h"
  35. #include "llinventory.h"
  36. #include "llui.h"
  37. #include "llsettingstype.h"
  38. #include "llwearabletype.h"
  39. struct IconEntry : public LLDictionaryEntry
  40. {
  41. IconEntry(const std::string& item_name, const LLUIImagePtr icon)
  42. : LLDictionaryEntry(item_name),
  43. mIcon(icon)
  44. {
  45. }
  46. const LLUIImagePtr mIcon;
  47. };
  48. class LLIconDictionary : public LLSingleton<LLIconDictionary>,
  49. public LLDictionary<LLInventoryType::EIconName, IconEntry>
  50. {
  51. friend class LLSingleton<LLIconDictionary>;
  52. public:
  53. LLIconDictionary();
  54. };
  55. LLIconDictionary::LLIconDictionary()
  56. {
  57. static const LLUIImagePtr texture_icon = LLUI::getUIImage("inv_item_texture.tga");
  58. static const LLUIImagePtr sound_icon = LLUI::getUIImage("inv_item_sound.tga");
  59. static const LLUIImagePtr card_online_icon = LLUI::getUIImage("inv_item_callingcard_online.tga");
  60. static const LLUIImagePtr card_offline_icon = LLUI::getUIImage("inv_item_callingcard_offline.tga");
  61. static const LLUIImagePtr landmark_icon = LLUI::getUIImage("inv_item_landmark.tga");
  62. static const LLUIImagePtr landmark_visited_icon = LLUI::getUIImage("inv_item_landmark_visited.tga");
  63. static const LLUIImagePtr script_icon = LLUI::getUIImage("inv_item_script.tga");
  64. static const LLUIImagePtr clothing_icon = LLUI::getUIImage("inv_item_clothing.tga");
  65. static const LLUIImagePtr object_icon = LLUI::getUIImage("inv_item_object.tga");
  66. static const LLUIImagePtr object_multi_icon = LLUI::getUIImage("inv_item_object_multi.tga");
  67. static const LLUIImagePtr notecard_icon = LLUI::getUIImage("inv_item_notecard.tga");
  68. static const LLUIImagePtr snapshot_icon = LLUI::getUIImage("inv_item_snapshot.tga");
  69. static const LLUIImagePtr shape_icon = LLUI::getUIImage("inv_item_shape.tga");
  70. static const LLUIImagePtr skin_icon = LLUI::getUIImage("inv_item_skin.tga");
  71. static const LLUIImagePtr hair_icon = LLUI::getUIImage("inv_item_hair.tga");
  72. static const LLUIImagePtr eyes_icon = LLUI::getUIImage("inv_item_eyes.tga");
  73. static const LLUIImagePtr shirt_icon = LLUI::getUIImage("inv_item_shirt.tga");
  74. static const LLUIImagePtr pants_icon = LLUI::getUIImage("inv_item_pants.tga");
  75. static const LLUIImagePtr shoes_icon = LLUI::getUIImage("inv_item_shoes.tga");
  76. static const LLUIImagePtr socks_icon = LLUI::getUIImage("inv_item_socks.tga");
  77. static const LLUIImagePtr jacket_icon = LLUI::getUIImage("inv_item_jacket.tga");
  78. static const LLUIImagePtr gloves_icon = LLUI::getUIImage("inv_item_gloves.tga");
  79. static const LLUIImagePtr undershirt_icon = LLUI::getUIImage("inv_item_undershirt.tga");
  80. static const LLUIImagePtr underpants_icon = LLUI::getUIImage("inv_item_underpants.tga");
  81. static const LLUIImagePtr skirt_icon = LLUI::getUIImage("inv_item_skirt.tga");
  82. static const LLUIImagePtr alpha_icon = LLUI::getUIImage("inv_item_alpha.tga");
  83. static const LLUIImagePtr tattoo_icon = LLUI::getUIImage("inv_item_tattoo.tga");
  84. static const LLUIImagePtr universal_icon = LLUI::getUIImage("inv_item_universal.tga");
  85. static const LLUIImagePtr physics_icon = LLUI::getUIImage("inv_item_physics.tga");
  86. static const LLUIImagePtr animation_icon = LLUI::getUIImage("inv_item_animation.tga");
  87. static const LLUIImagePtr gesture_icon = LLUI::getUIImage("inv_item_gesture.tga");
  88. static const LLUIImagePtr link_item_icon = LLUI::getUIImage("inv_link_item.tga");
  89. static const LLUIImagePtr link_folder_icon = LLUI::getUIImage("inv_link_folder.tga");
  90. #if LL_MESH_ASSET_SUPPORT
  91. static const LLUIImagePtr mesh_icon = LLUI::getUIImage("inv_item_mesh.tga");
  92. #endif
  93. static const LLUIImagePtr settings_icon = LLUI::getUIImage("inv_item_settings.tga");
  94. static const LLUIImagePtr sky_icon = LLUI::getUIImage("inv_item_sky.tga");
  95. static const LLUIImagePtr water_icon = LLUI::getUIImage("inv_item_water.tga");
  96. static const LLUIImagePtr daycycle_icon = LLUI::getUIImage("inv_item_daycycle.tga");
  97. static const LLUIImagePtr material_icon = LLUI::getUIImage("inv_item_material.tga");
  98. static const LLUIImagePtr invalid_icon = LLUI::getUIImage("inv_item_invalid.tga");
  99. addEntry(LLInventoryType::ICONNAME_TEXTURE,
  100. new IconEntry("inv_item_texture.tga", texture_icon));
  101. addEntry(LLInventoryType::ICONNAME_SOUND,
  102. new IconEntry("inv_item_sound.tga", sound_icon));
  103. addEntry(LLInventoryType::ICONNAME_CALLINGCARD_ONLINE,
  104. new IconEntry("inv_item_callingcard_online.tga", card_online_icon));
  105. addEntry(LLInventoryType::ICONNAME_CALLINGCARD_OFFLINE,
  106. new IconEntry("inv_item_callingcard_offline.tga", card_offline_icon));
  107. addEntry(LLInventoryType::ICONNAME_LANDMARK,
  108. new IconEntry("inv_item_landmark.tga", landmark_icon));
  109. addEntry(LLInventoryType::ICONNAME_LANDMARK_VISITED,
  110. new IconEntry("inv_item_landmark_visited.tga", landmark_visited_icon));
  111. addEntry(LLInventoryType::ICONNAME_SCRIPT,
  112. new IconEntry("inv_item_script.tga", script_icon));
  113. addEntry(LLInventoryType::ICONNAME_CLOTHING,
  114. new IconEntry("inv_item_clothing.tga", clothing_icon));
  115. addEntry(LLInventoryType::ICONNAME_OBJECT,
  116. new IconEntry("inv_item_object.tga", object_icon));
  117. addEntry(LLInventoryType::ICONNAME_OBJECT_MULTI,
  118. new IconEntry("inv_item_object_multi.tga", object_multi_icon));
  119. addEntry(LLInventoryType::ICONNAME_NOTECARD,
  120. new IconEntry("inv_item_notecard.tga", notecard_icon));
  121. addEntry(LLInventoryType::ICONNAME_BODYPART,
  122. new IconEntry("inv_item_skin.tga", skin_icon));
  123. addEntry(LLInventoryType::ICONNAME_SNAPSHOT,
  124. new IconEntry("inv_item_snapshot.tga", snapshot_icon));
  125. addEntry(LLInventoryType::ICONNAME_BODYPART_SHAPE,
  126. new IconEntry("inv_item_shape.tga", shape_icon));
  127. addEntry(LLInventoryType::ICONNAME_BODYPART_SKIN,
  128. new IconEntry("inv_item_skin.tga", skin_icon));
  129. addEntry(LLInventoryType::ICONNAME_BODYPART_HAIR,
  130. new IconEntry("inv_item_hair.tga", hair_icon));
  131. addEntry(LLInventoryType::ICONNAME_BODYPART_EYES,
  132. new IconEntry("inv_item_eyes.tga", eyes_icon));
  133. addEntry(LLInventoryType::ICONNAME_CLOTHING_SHIRT,
  134. new IconEntry("inv_item_shirt.tga", shirt_icon));
  135. addEntry(LLInventoryType::ICONNAME_CLOTHING_PANTS,
  136. new IconEntry("inv_item_pants.tga", pants_icon));
  137. addEntry(LLInventoryType::ICONNAME_CLOTHING_SHOES,
  138. new IconEntry("inv_item_shoes.tga", shoes_icon));
  139. addEntry(LLInventoryType::ICONNAME_CLOTHING_SOCKS,
  140. new IconEntry("inv_item_socks.tga", socks_icon));
  141. addEntry(LLInventoryType::ICONNAME_CLOTHING_JACKET,
  142. new IconEntry("inv_item_jacket.tga", jacket_icon));
  143. addEntry(LLInventoryType::ICONNAME_CLOTHING_GLOVES,
  144. new IconEntry("inv_item_gloves.tga", gloves_icon));
  145. addEntry(LLInventoryType::ICONNAME_CLOTHING_UNDERSHIRT,
  146. new IconEntry("inv_item_undershirt.tga", undershirt_icon));
  147. addEntry(LLInventoryType::ICONNAME_CLOTHING_UNDERPANTS,
  148. new IconEntry("inv_item_underpants.tga", underpants_icon));
  149. addEntry(LLInventoryType::ICONNAME_CLOTHING_SKIRT,
  150. new IconEntry("inv_item_skirt.tga", skirt_icon));
  151. addEntry(LLInventoryType::ICONNAME_CLOTHING_ALPHA,
  152. new IconEntry("inv_item_alpha.tga", alpha_icon));
  153. addEntry(LLInventoryType::ICONNAME_CLOTHING_TATTOO,
  154. new IconEntry("inv_item_tattoo.tga", tattoo_icon));
  155. addEntry(LLInventoryType::ICONNAME_CLOTHING_UNIVERSAL,
  156. new IconEntry("inv_item_universal.tga", universal_icon));
  157. addEntry(LLInventoryType::ICONNAME_CLOTHING_PHYSICS,
  158. new IconEntry("inv_item_physics.tga", physics_icon));
  159. addEntry(LLInventoryType::ICONNAME_ANIMATION,
  160. new IconEntry("inv_item_animation.tga", animation_icon));
  161. addEntry(LLInventoryType::ICONNAME_GESTURE,
  162. new IconEntry("inv_item_gesture.tga", gesture_icon));
  163. addEntry(LLInventoryType::ICONNAME_LINKITEM,
  164. new IconEntry("inv_link_item.tga", link_item_icon));
  165. addEntry(LLInventoryType::ICONNAME_LINKFOLDER,
  166. new IconEntry("inv_link_folder.tga", link_folder_icon));
  167. #if LL_MESH_ASSET_SUPPORT
  168. addEntry(LLInventoryType::ICONNAME_MESH,
  169. new IconEntry("inv_item_mesh.tga", mesh_icon));
  170. #endif
  171. addEntry(LLInventoryType::ICONNAME_SETTINGS,
  172. new IconEntry("inv_item_settings.tga", settings_icon));
  173. addEntry(LLInventoryType::ICONNAME_SETTINGS_SKY,
  174. new IconEntry("inv_item_sky.tga", sky_icon));
  175. addEntry(LLInventoryType::ICONNAME_SETTINGS_WATER,
  176. new IconEntry("inv_item_water.tga", water_icon));
  177. addEntry(LLInventoryType::ICONNAME_SETTINGS_DAY,
  178. new IconEntry("inv_item_daycycle.tga", daycycle_icon));
  179. addEntry(LLInventoryType::ICONNAME_MATERIAL,
  180. new IconEntry("inv_item_material.tga", material_icon));
  181. addEntry(LLInventoryType::ICONNAME_INVALID,
  182. new IconEntry("inv_item_invalid.tga", invalid_icon));
  183. addEntry(LLInventoryType::ICONNAME_NONE,
  184. new IconEntry("NONE", NULL));
  185. }
  186. const LLInventoryType::EIconName LLInventoryIcon::getIconIdx(LLAssetType::EType asset_type,
  187. LLInventoryType::EType inventory_type,
  188. U32 misc_flag,
  189. bool item_is_multi)
  190. {
  191. if (item_is_multi)
  192. {
  193. return LLInventoryType::ICONNAME_OBJECT_MULTI;
  194. }
  195. switch (asset_type)
  196. {
  197. case LLAssetType::AT_TEXTURE:
  198. return inventory_type == LLInventoryType::IT_SNAPSHOT ?
  199. LLInventoryType::ICONNAME_SNAPSHOT :
  200. LLInventoryType::ICONNAME_TEXTURE;
  201. case LLAssetType::AT_SOUND:
  202. return LLInventoryType::ICONNAME_SOUND;
  203. case LLAssetType::AT_CALLINGCARD:
  204. return misc_flag ? LLInventoryType::ICONNAME_CALLINGCARD_ONLINE
  205. : LLInventoryType::ICONNAME_CALLINGCARD_OFFLINE;
  206. case LLAssetType::AT_LANDMARK:
  207. return misc_flag ? LLInventoryType::ICONNAME_LANDMARK_VISITED
  208. : LLInventoryType::ICONNAME_LANDMARK;
  209. case LLAssetType::AT_SCRIPT:
  210. case LLAssetType::AT_LSL_TEXT:
  211. case LLAssetType::AT_LSL_BYTECODE:
  212. return LLInventoryType::ICONNAME_SCRIPT;
  213. case LLAssetType::AT_CLOTHING:
  214. case LLAssetType::AT_BODYPART:
  215. return assignWearableIcon(misc_flag);
  216. case LLAssetType::AT_NOTECARD:
  217. return LLInventoryType::ICONNAME_NOTECARD;
  218. case LLAssetType::AT_ANIMATION:
  219. return LLInventoryType::ICONNAME_ANIMATION;
  220. case LLAssetType::AT_GESTURE:
  221. return LLInventoryType::ICONNAME_GESTURE;
  222. case LLAssetType::AT_LINK:
  223. return LLInventoryType::ICONNAME_LINKITEM;
  224. case LLAssetType::AT_LINK_FOLDER:
  225. return LLInventoryType::ICONNAME_LINKFOLDER;
  226. case LLAssetType::AT_OBJECT:
  227. return LLInventoryType::ICONNAME_OBJECT;
  228. #if LL_MESH_ASSET_SUPPORT
  229. case LLAssetType::AT_MESH:
  230. return LLInventoryType::ICONNAME_MESH;
  231. #endif
  232. case LLAssetType::AT_SETTINGS:
  233. return assignSettingsIcon(misc_flag);
  234. case LLAssetType::AT_MATERIAL:
  235. return LLInventoryType::ICONNAME_MATERIAL;
  236. default:
  237. break;
  238. }
  239. return LLInventoryType::ICONNAME_INVALID;
  240. }
  241. const LLUIImagePtr LLInventoryIcon::getIcon(LLAssetType::EType asset_type,
  242. LLInventoryType::EType inventory_type,
  243. U32 misc_flag,
  244. bool item_is_multi)
  245. {
  246. const LLInventoryType::EIconName idx = getIconIdx(asset_type,
  247. inventory_type, misc_flag,
  248. item_is_multi);
  249. const IconEntry* entry = LLIconDictionary::getInstance()->lookup(idx);
  250. return entry->mIcon;
  251. }
  252. const LLUIImagePtr LLInventoryIcon::getIcon(LLInventoryType::EIconName idx)
  253. {
  254. const IconEntry* entry = LLIconDictionary::getInstance()->lookup(idx);
  255. return entry->mIcon;
  256. }
  257. const std::string& LLInventoryIcon::getIconName(LLAssetType::EType asset_type,
  258. LLInventoryType::EType inventory_type,
  259. U32 misc_flag,
  260. bool item_is_multi)
  261. {
  262. const LLInventoryType::EIconName idx = getIconIdx(asset_type,
  263. inventory_type, misc_flag,
  264. item_is_multi);
  265. return getIconName(idx);
  266. }
  267. const std::string& LLInventoryIcon::getIconName(LLInventoryType::EIconName idx)
  268. {
  269. const IconEntry* entry = LLIconDictionary::getInstance()->lookup(idx);
  270. return entry->mName;
  271. }
  272. LLInventoryType::EIconName LLInventoryIcon::assignWearableIcon(U32 misc_flag)
  273. {
  274. const LLWearableType::EType wearable_type = LLWearableType::inventoryFlagsToWearableType(misc_flag);
  275. return LLWearableType::getIconName(wearable_type);
  276. }
  277. LLInventoryType::EIconName LLInventoryIcon::assignSettingsIcon(U32 misc_flag)
  278. {
  279. const LLSettingsType::EType settings_type = LLSettingsType::fromInventoryFlags(misc_flag);
  280. return LLSettingsType::getIconName(settings_type);
  281. }