PageRenderTime 22ms CodeModel.GetById 7ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llwearabletype.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 159 lines | 110 code | 16 blank | 33 comment | 7 complexity | 3e9242878f2be2110a265af3f29f6628 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llwearabletype.cpp
  3. * @brief LLWearableType class implementation
  4. *
  5. * $LicenseInfo:firstyear=2002&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. #include "llviewerprecompiledheaders.h"
  27. #include "llwearabletype.h"
  28. #include "llinventoryfunctions.h"
  29. #include "lltrans.h"
  30. struct WearableEntry : public LLDictionaryEntry
  31. {
  32. WearableEntry(const std::string &name,
  33. const std::string& default_new_name,
  34. LLAssetType::EType assetType,
  35. LLInventoryIcon::EIconName iconName,
  36. BOOL disable_camera_switch = FALSE,
  37. BOOL allow_multiwear = TRUE) :
  38. LLDictionaryEntry(name),
  39. mAssetType(assetType),
  40. mDefaultNewName(default_new_name),
  41. mLabel(LLTrans::getString(name)),
  42. mIconName(iconName),
  43. mDisableCameraSwitch(disable_camera_switch),
  44. mAllowMultiwear(allow_multiwear)
  45. {
  46. }
  47. const LLAssetType::EType mAssetType;
  48. const std::string mLabel;
  49. const std::string mDefaultNewName; //keep mLabel for backward compatibility
  50. LLInventoryIcon::EIconName mIconName;
  51. BOOL mDisableCameraSwitch;
  52. BOOL mAllowMultiwear;
  53. };
  54. class LLWearableDictionary : public LLSingleton<LLWearableDictionary>,
  55. public LLDictionary<LLWearableType::EType, WearableEntry>
  56. {
  57. public:
  58. LLWearableDictionary();
  59. };
  60. LLWearableDictionary::LLWearableDictionary()
  61. {
  62. addEntry(LLWearableType::WT_SHAPE, new WearableEntry("shape", "New Shape", LLAssetType::AT_BODYPART, LLInventoryIcon::ICONNAME_BODYPART_SHAPE, FALSE, FALSE));
  63. addEntry(LLWearableType::WT_SKIN, new WearableEntry("skin", "New Skin", LLAssetType::AT_BODYPART, LLInventoryIcon::ICONNAME_BODYPART_SKIN, FALSE, FALSE));
  64. addEntry(LLWearableType::WT_HAIR, new WearableEntry("hair", "New Hair", LLAssetType::AT_BODYPART, LLInventoryIcon::ICONNAME_BODYPART_HAIR, FALSE, FALSE));
  65. addEntry(LLWearableType::WT_EYES, new WearableEntry("eyes", "New Eyes", LLAssetType::AT_BODYPART, LLInventoryIcon::ICONNAME_BODYPART_EYES, FALSE, FALSE));
  66. addEntry(LLWearableType::WT_SHIRT, new WearableEntry("shirt", "New Shirt", LLAssetType::AT_CLOTHING, LLInventoryIcon::ICONNAME_CLOTHING_SHIRT, FALSE, TRUE));
  67. addEntry(LLWearableType::WT_PANTS, new WearableEntry("pants", "New Pants", LLAssetType::AT_CLOTHING, LLInventoryIcon::ICONNAME_CLOTHING_PANTS, FALSE, TRUE));
  68. addEntry(LLWearableType::WT_SHOES, new WearableEntry("shoes", "New Shoes", LLAssetType::AT_CLOTHING, LLInventoryIcon::ICONNAME_CLOTHING_SHOES, FALSE, TRUE));
  69. addEntry(LLWearableType::WT_SOCKS, new WearableEntry("socks", "New Socks", LLAssetType::AT_CLOTHING, LLInventoryIcon::ICONNAME_CLOTHING_SOCKS, FALSE, TRUE));
  70. addEntry(LLWearableType::WT_JACKET, new WearableEntry("jacket", "New Jacket", LLAssetType::AT_CLOTHING, LLInventoryIcon::ICONNAME_CLOTHING_JACKET, FALSE, TRUE));
  71. addEntry(LLWearableType::WT_GLOVES, new WearableEntry("gloves", "New Gloves", LLAssetType::AT_CLOTHING, LLInventoryIcon::ICONNAME_CLOTHING_GLOVES, FALSE, TRUE));
  72. addEntry(LLWearableType::WT_UNDERSHIRT, new WearableEntry("undershirt", "New Undershirt", LLAssetType::AT_CLOTHING, LLInventoryIcon::ICONNAME_CLOTHING_UNDERSHIRT, FALSE, TRUE));
  73. addEntry(LLWearableType::WT_UNDERPANTS, new WearableEntry("underpants", "New Underpants", LLAssetType::AT_CLOTHING, LLInventoryIcon::ICONNAME_CLOTHING_UNDERPANTS, FALSE, TRUE));
  74. addEntry(LLWearableType::WT_SKIRT, new WearableEntry("skirt", "New Skirt", LLAssetType::AT_CLOTHING, LLInventoryIcon::ICONNAME_CLOTHING_SKIRT, FALSE, TRUE));
  75. addEntry(LLWearableType::WT_ALPHA, new WearableEntry("alpha", "New Alpha", LLAssetType::AT_CLOTHING, LLInventoryIcon::ICONNAME_CLOTHING_ALPHA, FALSE, TRUE));
  76. addEntry(LLWearableType::WT_TATTOO, new WearableEntry("tattoo", "New Tattoo", LLAssetType::AT_CLOTHING, LLInventoryIcon::ICONNAME_CLOTHING_TATTOO, FALSE, TRUE));
  77. addEntry(LLWearableType::WT_PHYSICS, new WearableEntry("physics", "New Physics", LLAssetType::AT_CLOTHING, LLInventoryIcon::ICONNAME_CLOTHING_PHYSICS, TRUE, TRUE));
  78. addEntry(LLWearableType::WT_INVALID, new WearableEntry("invalid", "Invalid Wearable", LLAssetType::AT_NONE, LLInventoryIcon::ICONNAME_NONE, FALSE, FALSE));
  79. addEntry(LLWearableType::WT_NONE, new WearableEntry("none", "Invalid Wearable", LLAssetType::AT_NONE, LLInventoryIcon::ICONNAME_NONE, FALSE, FALSE));
  80. }
  81. // static
  82. LLWearableType::EType LLWearableType::typeNameToType(const std::string& type_name)
  83. {
  84. const LLWearableDictionary *dict = LLWearableDictionary::getInstance();
  85. const LLWearableType::EType wearable = dict->lookup(type_name);
  86. return wearable;
  87. }
  88. // static
  89. const std::string& LLWearableType::getTypeName(LLWearableType::EType type)
  90. {
  91. const LLWearableDictionary *dict = LLWearableDictionary::getInstance();
  92. const WearableEntry *entry = dict->lookup(type);
  93. if (!entry) return getTypeName(WT_INVALID);
  94. return entry->mName;
  95. }
  96. //static
  97. const std::string& LLWearableType::getTypeDefaultNewName(LLWearableType::EType type)
  98. {
  99. const LLWearableDictionary *dict = LLWearableDictionary::getInstance();
  100. const WearableEntry *entry = dict->lookup(type);
  101. if (!entry) return getTypeDefaultNewName(WT_INVALID);
  102. return entry->mDefaultNewName;
  103. }
  104. // static
  105. const std::string& LLWearableType::getTypeLabel(LLWearableType::EType type)
  106. {
  107. const LLWearableDictionary *dict = LLWearableDictionary::getInstance();
  108. const WearableEntry *entry = dict->lookup(type);
  109. if (!entry) return getTypeLabel(WT_INVALID);
  110. return entry->mLabel;
  111. }
  112. // static
  113. LLAssetType::EType LLWearableType::getAssetType(LLWearableType::EType type)
  114. {
  115. const LLWearableDictionary *dict = LLWearableDictionary::getInstance();
  116. const WearableEntry *entry = dict->lookup(type);
  117. if (!entry) return getAssetType(WT_INVALID);
  118. return entry->mAssetType;
  119. }
  120. // static
  121. LLInventoryIcon::EIconName LLWearableType::getIconName(LLWearableType::EType type)
  122. {
  123. const LLWearableDictionary *dict = LLWearableDictionary::getInstance();
  124. const WearableEntry *entry = dict->lookup(type);
  125. if (!entry) return getIconName(WT_INVALID);
  126. return entry->mIconName;
  127. }
  128. // static
  129. BOOL LLWearableType::getDisableCameraSwitch(LLWearableType::EType type)
  130. {
  131. const LLWearableDictionary *dict = LLWearableDictionary::getInstance();
  132. const WearableEntry *entry = dict->lookup(type);
  133. if (!entry) return FALSE;
  134. return entry->mDisableCameraSwitch;
  135. }
  136. // static
  137. BOOL LLWearableType::getAllowMultiwear(LLWearableType::EType type)
  138. {
  139. const LLWearableDictionary *dict = LLWearableDictionary::getInstance();
  140. const WearableEntry *entry = dict->lookup(type);
  141. if (!entry) return FALSE;
  142. return entry->mAllowMultiwear;
  143. }