llwearabletype.cpp 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /**
  2. * @file llwearabletype.cpp
  3. * @brief LLWearableType class implementation
  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 "linden_common.h"
  33. #include "llwearabletype.h"
  34. #include "lldictionary.h"
  35. #include "llinventory.h"
  36. static LLTranslationBridge::ptr_t sTrans;
  37. //static
  38. void LLWearableType::initClass(LLTranslationBridge::ptr_t trans)
  39. {
  40. sTrans = trans;
  41. }
  42. //static
  43. void LLWearableType::cleanupClass()
  44. {
  45. sTrans.reset();
  46. }
  47. struct WearableEntry : public LLDictionaryEntry
  48. {
  49. WearableEntry(const std::string& name,
  50. const std::string& default_new_name,
  51. LLAssetType::EType assetType,
  52. LLInventoryType::EIconName iconName,
  53. bool disable_camera_switch = false,
  54. bool allow_multiwear = true)
  55. : LLDictionaryEntry(name),
  56. mAssetType(assetType),
  57. mDefaultNewName(default_new_name),
  58. mIconName(iconName),
  59. mDisableCameraSwitch(disable_camera_switch),
  60. mAllowMultiwear(allow_multiwear)
  61. {
  62. if (sTrans)
  63. {
  64. mLabel = sTrans->getString(name);
  65. }
  66. else
  67. {
  68. llwarns << "No translation bridge: WearableEntry '" << name
  69. << "' will be left untranslated." << llendl;
  70. }
  71. if (mLabel.empty())
  72. {
  73. mLabel = name;
  74. }
  75. }
  76. const LLAssetType::EType mAssetType;
  77. // Keeping mLabel for backward compatibility !
  78. std::string mLabel;
  79. const std::string mDefaultNewName;
  80. LLInventoryType::EIconName mIconName;
  81. bool mDisableCameraSwitch;
  82. bool mAllowMultiwear;
  83. };
  84. class LLWearableDictionary final : public LLDictionary<LLWearableType::EType,
  85. WearableEntry>
  86. {
  87. public:
  88. LLWearableDictionary();
  89. };
  90. // Since it is a small structure, let's initialize it unconditionally (i.e.
  91. // even if we do not log in) at global scope. This saves having to bother with
  92. // a costly LLSingleton (slow, lot's of CPU cycles and cache lines wasted) or
  93. // to find the right place where to construct the class on login...
  94. LLWearableDictionary gWearableDictionary;
  95. LLWearableDictionary::LLWearableDictionary()
  96. {
  97. addEntry(LLWearableType::WT_SHAPE, new WearableEntry("shape", "New Shape", LLAssetType::AT_BODYPART, LLInventoryType::ICONNAME_BODYPART_SHAPE, false, false));
  98. addEntry(LLWearableType::WT_SKIN, new WearableEntry("skin", "New Skin", LLAssetType::AT_BODYPART, LLInventoryType::ICONNAME_BODYPART_SKIN, false, false));
  99. addEntry(LLWearableType::WT_HAIR, new WearableEntry("hair", "New Hair", LLAssetType::AT_BODYPART, LLInventoryType::ICONNAME_BODYPART_HAIR, false, false));
  100. addEntry(LLWearableType::WT_EYES, new WearableEntry("eyes", "New Eyes", LLAssetType::AT_BODYPART, LLInventoryType::ICONNAME_BODYPART_EYES, false, false));
  101. addEntry(LLWearableType::WT_SHIRT, new WearableEntry("shirt", "New Shirt", LLAssetType::AT_CLOTHING, LLInventoryType::ICONNAME_CLOTHING_SHIRT, false, true));
  102. addEntry(LLWearableType::WT_PANTS, new WearableEntry("pants", "New Pants", LLAssetType::AT_CLOTHING, LLInventoryType::ICONNAME_CLOTHING_PANTS, false, true));
  103. addEntry(LLWearableType::WT_SHOES, new WearableEntry("shoes", "New Shoes", LLAssetType::AT_CLOTHING, LLInventoryType::ICONNAME_CLOTHING_SHOES, false, true));
  104. addEntry(LLWearableType::WT_SOCKS, new WearableEntry("socks", "New Socks", LLAssetType::AT_CLOTHING, LLInventoryType::ICONNAME_CLOTHING_SOCKS, false, true));
  105. addEntry(LLWearableType::WT_JACKET, new WearableEntry("jacket", "New Jacket", LLAssetType::AT_CLOTHING, LLInventoryType::ICONNAME_CLOTHING_JACKET, false, true));
  106. addEntry(LLWearableType::WT_GLOVES, new WearableEntry("gloves", "New Gloves", LLAssetType::AT_CLOTHING, LLInventoryType::ICONNAME_CLOTHING_GLOVES, false, true));
  107. addEntry(LLWearableType::WT_UNDERSHIRT, new WearableEntry("undershirt", "New Undershirt", LLAssetType::AT_CLOTHING, LLInventoryType::ICONNAME_CLOTHING_UNDERSHIRT, false, true));
  108. addEntry(LLWearableType::WT_UNDERPANTS, new WearableEntry("underpants", "New Underpants", LLAssetType::AT_CLOTHING, LLInventoryType::ICONNAME_CLOTHING_UNDERPANTS, false, true));
  109. addEntry(LLWearableType::WT_SKIRT, new WearableEntry("skirt", "New Skirt", LLAssetType::AT_CLOTHING, LLInventoryType::ICONNAME_CLOTHING_SKIRT, false, true));
  110. addEntry(LLWearableType::WT_ALPHA, new WearableEntry("alpha", "New Alpha", LLAssetType::AT_CLOTHING, LLInventoryType::ICONNAME_CLOTHING_ALPHA, false, true));
  111. addEntry(LLWearableType::WT_TATTOO, new WearableEntry("tattoo", "New Tattoo", LLAssetType::AT_CLOTHING, LLInventoryType::ICONNAME_CLOTHING_TATTOO, false, true));
  112. addEntry(LLWearableType::WT_UNIVERSAL, new WearableEntry("universal", "New Universal", LLAssetType::AT_CLOTHING, LLInventoryType::ICONNAME_CLOTHING_UNIVERSAL, false, true));
  113. addEntry(LLWearableType::WT_PHYSICS, new WearableEntry("physics", "New Physics", LLAssetType::AT_CLOTHING, LLInventoryType::ICONNAME_CLOTHING_PHYSICS, true, true));
  114. addEntry(LLWearableType::WT_INVALID, new WearableEntry("invalid", "Invalid Wearable", LLAssetType::AT_NONE, LLInventoryType::ICONNAME_NONE, false, false));
  115. addEntry(LLWearableType::WT_NONE, new WearableEntry("none", "Invalid Wearable", LLAssetType::AT_NONE, LLInventoryType::ICONNAME_NONE, false, false));
  116. }
  117. //static
  118. LLWearableType::EType LLWearableType::typeNameToType(const std::string& type_name)
  119. {
  120. const LLWearableType::EType wearable = gWearableDictionary.lookup(type_name);
  121. return wearable;
  122. }
  123. //static
  124. const std::string& LLWearableType::getTypeName(LLWearableType::EType type)
  125. {
  126. const WearableEntry* entry = gWearableDictionary.lookup(type);
  127. return entry ? entry->mName : getTypeName(WT_INVALID);
  128. }
  129. //static
  130. std::string LLWearableType::getCapitalizedTypeName(LLWearableType::EType type)
  131. {
  132. const WearableEntry* entry = gWearableDictionary.lookup(type);
  133. std::string name;
  134. if (entry)
  135. {
  136. name = entry->mName;
  137. }
  138. else
  139. {
  140. name = getTypeName(WT_INVALID);
  141. }
  142. name[0] = toupper(name[0]);
  143. return name;
  144. }
  145. //static
  146. const std::string& LLWearableType::getTypeDefaultNewName(LLWearableType::EType type)
  147. {
  148. const WearableEntry* entry = gWearableDictionary.lookup(type);
  149. return entry ? entry->mDefaultNewName : getTypeDefaultNewName(WT_INVALID);
  150. }
  151. //static
  152. const std::string& LLWearableType::getTypeLabel(LLWearableType::EType type)
  153. {
  154. const WearableEntry* entry = gWearableDictionary.lookup(type);
  155. return entry ? entry->mLabel : getTypeLabel(WT_INVALID);
  156. }
  157. //static
  158. LLAssetType::EType LLWearableType::getAssetType(LLWearableType::EType type)
  159. {
  160. const WearableEntry* entry = gWearableDictionary.lookup(type);
  161. return entry ? entry->mAssetType : getAssetType(WT_INVALID);
  162. }
  163. //static
  164. LLInventoryType::EIconName LLWearableType::getIconName(LLWearableType::EType type)
  165. {
  166. const WearableEntry* entry = gWearableDictionary.lookup(type);
  167. return entry ? entry->mIconName : getIconName(WT_INVALID);
  168. }
  169. //static
  170. bool LLWearableType::getDisableCameraSwitch(LLWearableType::EType type)
  171. {
  172. const WearableEntry* entry = gWearableDictionary.lookup(type);
  173. return entry && entry->mDisableCameraSwitch;
  174. }
  175. //static
  176. bool LLWearableType::getAllowMultiwear(LLWearableType::EType type)
  177. {
  178. const WearableEntry* entry = gWearableDictionary.lookup(type);
  179. return entry && entry->mAllowMultiwear;
  180. }
  181. //static
  182. LLWearableType::EType LLWearableType::inventoryFlagsToWearableType(U32 flags)
  183. {
  184. return (LLWearableType::EType)(flags & LLInventoryItem::II_FLAGS_SUBTYPE_MASK);
  185. }