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

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file llpaneleditwearable.cpp
  3.  * @brief UI panel for editing of a particular wearable item.
  4.  *
  5.  * $LicenseInfo:firstyear=2009&license=viewergpl$
  6.  * 
  7.  * Copyright (c) 2009-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 "llpaneleditwearable.h"
  34. #include "llpanel.h"
  35. #include "llwearable.h"
  36. #include "lluictrl.h"
  37. #include "llscrollingpanellist.h"
  38. #include "llvisualparam.h"
  39. #include "lltoolmorph.h"
  40. #include "llviewerjointmesh.h"
  41. #include "lltrans.h"
  42. #include "llbutton.h"
  43. #include "llsliderctrl.h"
  44. #include "llagent.h"
  45. #include "llvoavatarself.h"
  46. #include "lltexteditor.h"
  47. #include "lltextbox.h"
  48. #include "llaccordionctrltab.h"
  49. #include "llagentwearables.h"
  50. #include "llscrollingpanelparam.h"
  51. // register panel with appropriate XML
  52. static LLRegisterPanelClassWrapper<LLPanelEditWearable> t_edit_wearable("panel_edit_wearable");
  53. // subparts of the UI for focus, camera position, etc.
  54. enum ESubpart {
  55. SUBPART_SHAPE_HEAD = 1, // avoid 0
  56. SUBPART_SHAPE_EYES,
  57. SUBPART_SHAPE_EARS,
  58. SUBPART_SHAPE_NOSE,
  59. SUBPART_SHAPE_MOUTH,
  60. SUBPART_SHAPE_CHIN,
  61. SUBPART_SHAPE_TORSO,
  62. SUBPART_SHAPE_LEGS,
  63. SUBPART_SHAPE_WHOLE,
  64. SUBPART_SHAPE_DETAIL,
  65. SUBPART_SKIN_COLOR,
  66. SUBPART_SKIN_FACEDETAIL,
  67. SUBPART_SKIN_MAKEUP,
  68. SUBPART_SKIN_BODYDETAIL,
  69. SUBPART_HAIR_COLOR,
  70. SUBPART_HAIR_STYLE,
  71. SUBPART_HAIR_EYEBROWS,
  72. SUBPART_HAIR_FACIAL,
  73. SUBPART_EYES,
  74. SUBPART_SHIRT,
  75. SUBPART_PANTS,
  76. SUBPART_SHOES,
  77. SUBPART_SOCKS,
  78. SUBPART_JACKET,
  79. SUBPART_GLOVES,
  80. SUBPART_UNDERSHIRT,
  81. SUBPART_UNDERPANTS,
  82. SUBPART_SKIRT,
  83. SUBPART_ALPHA,
  84. SUBPART_TATTOO
  85.  };
  86. typedef std::vector<ESubpart> subpart_vec_t;
  87. // Locally defined classes
  88. class LLEditWearableDictionary : public LLSingleton<LLEditWearableDictionary>
  89. {
  90. //--------------------------------------------------------------------
  91. // Constructors and Destructors
  92. //--------------------------------------------------------------------
  93. public:
  94. LLEditWearableDictionary();
  95. virtual ~LLEditWearableDictionary();
  96. //--------------------------------------------------------------------
  97. // Wearable Types
  98. //--------------------------------------------------------------------
  99. public:
  100. struct WearableEntry : public LLDictionaryEntry
  101. {
  102. WearableEntry(EWearableType type,
  103.   const std::string &title,
  104.   const std::string &desc_title,
  105.   U8 num_subparts, ... ); // number of subparts followed by a list of ESubparts
  106. const EWearableType mWearableType;
  107. const std::string   mTitle;
  108. const std::string mDescTitle;
  109. subpart_vec_t mSubparts;
  110. };
  111. struct Wearables : public LLDictionary<EWearableType, WearableEntry>
  112. {
  113. Wearables();
  114. } mWearables;
  115. const WearableEntry* getWearable(EWearableType type) const { return mWearables.lookup(type); }
  116. //--------------------------------------------------------------------
  117. // Subparts
  118. //--------------------------------------------------------------------
  119. public:
  120. struct SubpartEntry : public LLDictionaryEntry
  121. {
  122. SubpartEntry(ESubpart part,
  123.  const std::string &joint,
  124.  const std::string &edit_group,
  125.  const std::string &param_list,
  126.  const std::string &accordion_tab,
  127.  const LLVector3d  &target_offset,
  128.  const LLVector3d  &camera_offset,
  129.  const ESex     &sex);
  130. ESubpart mSubpart;
  131. std::string mTargetJoint;
  132. std::string mEditGroup;
  133. std::string mParamList;
  134. std::string mAccordionTab;
  135. LLVector3d mTargetOffset;
  136. LLVector3d mCameraOffset;
  137. ESex mSex;
  138. };
  139. struct Subparts : public LLDictionary<ESubpart, SubpartEntry>
  140. {
  141. Subparts();
  142. } mSubparts;
  143. const SubpartEntry*  getSubpart(ESubpart subpart) const { return mSubparts.lookup(subpart); }
  144. };
  145. LLEditWearableDictionary::LLEditWearableDictionary()
  146. {
  147. }
  148. //virtual 
  149. LLEditWearableDictionary::~LLEditWearableDictionary()
  150. {
  151. }
  152. LLEditWearableDictionary::Wearables::Wearables()
  153. {
  154. addEntry(WT_SHAPE, new WearableEntry(WT_SHAPE,"edit_shape_title","shape_desc_text",9, SUBPART_SHAPE_HEAD, SUBPART_SHAPE_EYES, SUBPART_SHAPE_EARS, SUBPART_SHAPE_NOSE, SUBPART_SHAPE_MOUTH, SUBPART_SHAPE_CHIN, SUBPART_SHAPE_TORSO, SUBPART_SHAPE_LEGS, SUBPART_SHAPE_WHOLE));
  155. addEntry(WT_SKIN, new WearableEntry(WT_SKIN,"edit_skin_title","skin_desc_text",4, SUBPART_SKIN_COLOR, SUBPART_SKIN_FACEDETAIL, SUBPART_SKIN_MAKEUP, SUBPART_SKIN_BODYDETAIL));
  156. addEntry(WT_HAIR, new WearableEntry(WT_HAIR,"edit_hair_title","hair_desc_text",4, SUBPART_HAIR_COLOR, SUBPART_HAIR_STYLE, SUBPART_HAIR_EYEBROWS, SUBPART_HAIR_FACIAL));
  157. addEntry(WT_EYES, new WearableEntry(WT_EYES,"edit_eyes_title","eyes_desc_text",1, SUBPART_EYES));
  158. addEntry(WT_SHIRT, new WearableEntry(WT_SHIRT,"edit_shirt_title","shirt_desc_text",1, SUBPART_SHIRT));
  159. addEntry(WT_PANTS, new WearableEntry(WT_PANTS,"edit_pants_title","pants_desc_text",1, SUBPART_PANTS));
  160. addEntry(WT_SHOES, new WearableEntry(WT_SHOES,"edit_shoes_title","shoes_desc_text",1, SUBPART_SHOES));
  161. addEntry(WT_SOCKS, new WearableEntry(WT_SOCKS,"edit_socks_title","socks_desc_text",1, SUBPART_SOCKS));
  162. addEntry(WT_JACKET, new WearableEntry(WT_JACKET,"edit_jacket_title","jacket_desc_text",1, SUBPART_JACKET));
  163. addEntry(WT_GLOVES, new WearableEntry(WT_GLOVES,"edit_gloves_title","gloves_desc_text",1, SUBPART_GLOVES));
  164. addEntry(WT_UNDERSHIRT, new WearableEntry(WT_UNDERSHIRT,"edit_undershirt_title","undershirt_desc_text",1, SUBPART_UNDERSHIRT));
  165. addEntry(WT_UNDERPANTS, new WearableEntry(WT_UNDERPANTS,"edit_underpants_title","underpants_desc_text",1, SUBPART_UNDERPANTS));
  166. addEntry(WT_SKIRT, new WearableEntry(WT_SKIRT,"edit_skirt_title","skirt_desc_text",1, SUBPART_SKIRT));
  167. addEntry(WT_ALPHA, new WearableEntry(WT_ALPHA,"edit_alpha_title","alpha_desc_text",1, SUBPART_ALPHA));
  168. addEntry(WT_TATTOO, new WearableEntry(WT_TATTOO,"edit_tattoo_title","tattoo_desc_text",1, SUBPART_TATTOO));
  169. }
  170. LLEditWearableDictionary::WearableEntry::WearableEntry(EWearableType type,
  171.   const std::string &title,
  172.   const std::string &desc_title,
  173.   U8 num_subparts, ... ) :
  174. LLDictionaryEntry(title),
  175. mWearableType(type),
  176. mTitle(title),
  177. mDescTitle(desc_title)
  178. {
  179. va_list argp;
  180. va_start(argp, num_subparts);
  181. for (U8 i = 0; i < num_subparts; ++i)
  182. {
  183. ESubpart part = (ESubpart)va_arg(argp,int);
  184. mSubparts.push_back(part);
  185. }
  186. }
  187. LLEditWearableDictionary::Subparts::Subparts()
  188. {
  189. addEntry(SUBPART_SHAPE_WHOLE, new SubpartEntry(SUBPART_SHAPE_WHOLE, "mPelvis", "shape_body","shape_body_param_list", "shape_body_tab", LLVector3d(0.f, 0.f, 0.1f), LLVector3d(-2.5f, 0.5f, 0.8f),SEX_BOTH));
  190. addEntry(SUBPART_SHAPE_HEAD, new SubpartEntry(SUBPART_SHAPE_HEAD, "mHead", "shape_head", "shape_head_param_list", "shape_head_tab", LLVector3d(0.f, 0.f, 0.05f), LLVector3d(-0.5f, 0.05f, 0.07f),SEX_BOTH));
  191. addEntry(SUBPART_SHAPE_EYES, new SubpartEntry(SUBPART_SHAPE_EYES, "mHead", "shape_eyes", "shape_eyes_param_list", "shape_eyes_tab", LLVector3d(0.f, 0.f, 0.05f), LLVector3d(-0.5f, 0.05f, 0.07f),SEX_BOTH));
  192. addEntry(SUBPART_SHAPE_EARS, new SubpartEntry(SUBPART_SHAPE_EARS, "mHead", "shape_ears", "shape_ears_param_list", "shape_ears_tab", LLVector3d(0.f, 0.f, 0.05f), LLVector3d(-0.5f, 0.05f, 0.07f),SEX_BOTH));
  193. addEntry(SUBPART_SHAPE_NOSE, new SubpartEntry(SUBPART_SHAPE_NOSE, "mHead", "shape_nose", "shape_nose_param_list", "shape_nose_tab", LLVector3d(0.f, 0.f, 0.05f), LLVector3d(-0.5f, 0.05f, 0.07f),SEX_BOTH));
  194. addEntry(SUBPART_SHAPE_MOUTH, new SubpartEntry(SUBPART_SHAPE_MOUTH, "mHead", "shape_mouth", "shape_mouth_param_list", "shape_mouth_tab", LLVector3d(0.f, 0.f, 0.05f), LLVector3d(-0.5f, 0.05f, 0.07f),SEX_BOTH));
  195. addEntry(SUBPART_SHAPE_CHIN, new SubpartEntry(SUBPART_SHAPE_CHIN, "mHead", "shape_chin", "shape_chin_param_list", "shape_chin_tab", LLVector3d(0.f, 0.f, 0.05f), LLVector3d(-0.5f, 0.05f, 0.07f),SEX_BOTH));
  196. addEntry(SUBPART_SHAPE_TORSO, new SubpartEntry(SUBPART_SHAPE_TORSO, "mTorso", "shape_torso", "shape_torso_param_list", "shape_torso_tab", LLVector3d(0.f, 0.f, 0.3f), LLVector3d(-1.f, 0.15f, 0.3f),SEX_BOTH));
  197. addEntry(SUBPART_SHAPE_LEGS, new SubpartEntry(SUBPART_SHAPE_LEGS, "mPelvis", "shape_legs", "shape_legs_param_list", "shape_legs_tab", LLVector3d(0.f, 0.f, -0.5f), LLVector3d(-1.6f, 0.15f, -0.5f),SEX_BOTH));
  198. addEntry(SUBPART_SKIN_COLOR, new SubpartEntry(SUBPART_SKIN_COLOR, "mHead", "skin_color", "skin_color_param_list", "skin_color_tab", LLVector3d(0.f, 0.f, 0.05f), LLVector3d(-0.5f, 0.05f, 0.07f),SEX_BOTH));
  199. addEntry(SUBPART_SKIN_FACEDETAIL, new SubpartEntry(SUBPART_SKIN_FACEDETAIL, "mHead", "skin_facedetail", "skin_face_param_list", "skin_face_tab", LLVector3d(0.f, 0.f, 0.05f), LLVector3d(-0.5f, 0.05f, 0.07f),SEX_BOTH));
  200. addEntry(SUBPART_SKIN_MAKEUP, new SubpartEntry(SUBPART_SKIN_MAKEUP, "mHead", "skin_makeup", "skin_makeup_param_list", "skin_makeup_tab", LLVector3d(0.f, 0.f, 0.05f), LLVector3d(-0.5f, 0.05f, 0.07f),SEX_BOTH));
  201. addEntry(SUBPART_SKIN_BODYDETAIL, new SubpartEntry(SUBPART_SKIN_BODYDETAIL, "mPelvis", "skin_bodydetail", "skin_body_param_list", "skin_body_tab", LLVector3d(0.f, 0.f, -0.2f), LLVector3d(-2.5f, 0.5f, 0.5f),SEX_BOTH));
  202. addEntry(SUBPART_HAIR_COLOR, new SubpartEntry(SUBPART_HAIR_COLOR, "mHead", "hair_color", "hair_color_param_list", "hair_color_tab", LLVector3d(0.f, 0.f, 0.10f), LLVector3d(-0.4f, 0.05f, 0.10f),SEX_BOTH));
  203. addEntry(SUBPART_HAIR_STYLE, new SubpartEntry(SUBPART_HAIR_STYLE, "mHead", "hair_style", "hair_style_param_list", "hair_style_tab", LLVector3d(0.f, 0.f, 0.10f), LLVector3d(-0.4f, 0.05f, 0.10f),SEX_BOTH));
  204. addEntry(SUBPART_HAIR_EYEBROWS, new SubpartEntry(SUBPART_HAIR_EYEBROWS, "mHead", "hair_eyebrows", "hair_eyebrows_param_list", "hair_eyebrows_tab", LLVector3d(0.f, 0.f, 0.05f), LLVector3d(-0.5f, 0.05f, 0.07f),SEX_BOTH));
  205. addEntry(SUBPART_HAIR_FACIAL, new SubpartEntry(SUBPART_HAIR_FACIAL, "mHead", "hair_facial", "hair_facial_param_list", "hair_facial_tab", LLVector3d(0.f, 0.f, 0.05f), LLVector3d(-0.5f, 0.05f, 0.07f),SEX_MALE));
  206. addEntry(SUBPART_EYES, new SubpartEntry(SUBPART_EYES, "mHead", "eyes", "eyes_main_param_list", "eyes_main_tab", LLVector3d(0.f, 0.f, 0.05f), LLVector3d(-0.5f, 0.05f, 0.07f),SEX_BOTH));
  207. addEntry(SUBPART_SHIRT, new SubpartEntry(SUBPART_SHIRT, "mTorso", "shirt", "shirt_main_param_list", "shirt_main_tab", LLVector3d(0.f, 0.f, 0.3f), LLVector3d(-1.f, 0.15f, 0.3f),SEX_BOTH));
  208. addEntry(SUBPART_PANTS, new SubpartEntry(SUBPART_PANTS, "mPelvis", "pants", "pants_main_param_list", "pants_main_tab", LLVector3d(0.f, 0.f, -0.5f), LLVector3d(-1.6f, 0.15f, -0.5f),SEX_BOTH));
  209. addEntry(SUBPART_SHOES, new SubpartEntry(SUBPART_SHOES, "mPelvis", "shoes", "shoes_main_param_list", "shoes_main_tab", LLVector3d(0.f, 0.f, -0.5f), LLVector3d(-1.6f, 0.15f, -0.5f),SEX_BOTH));
  210. addEntry(SUBPART_SOCKS, new SubpartEntry(SUBPART_SOCKS, "mPelvis", "socks", "socks_main_param_list", "socks_main_tab", LLVector3d(0.f, 0.f, -0.5f), LLVector3d(-1.6f, 0.15f, -0.5f),SEX_BOTH));
  211. addEntry(SUBPART_JACKET, new SubpartEntry(SUBPART_JACKET, "mTorso", "jacket", "jacket_main_param_list", "jacket_main_tab", LLVector3d(0.f, 0.f, 0.f), LLVector3d(-2.f, 0.1f, 0.3f),SEX_BOTH));
  212. addEntry(SUBPART_SKIRT, new SubpartEntry(SUBPART_SKIRT, "mPelvis", "skirt", "skirt_main_param_list", "skirt_main_tab", LLVector3d(0.f, 0.f, -0.5f), LLVector3d(-1.6f, 0.15f, -0.5f),SEX_BOTH));
  213. addEntry(SUBPART_GLOVES, new SubpartEntry(SUBPART_GLOVES, "mTorso", "gloves", "gloves_main_param_list", "gloves_main_tab", LLVector3d(0.f, 0.f, 0.f), LLVector3d(-1.f, 0.15f, 0.f),SEX_BOTH));
  214. addEntry(SUBPART_UNDERSHIRT, new SubpartEntry(SUBPART_UNDERSHIRT, "mTorso", "undershirt", "undershirt_main_param_list", "undershirt_main_tab", LLVector3d(0.f, 0.f, 0.3f), LLVector3d(-1.f, 0.15f, 0.3f),SEX_BOTH));
  215. addEntry(SUBPART_UNDERPANTS, new SubpartEntry(SUBPART_UNDERPANTS, "mPelvis", "underpants", "underpants_main_param_list", "underpants_main_tab", LLVector3d(0.f, 0.f, -0.5f), LLVector3d(-1.6f, 0.15f, -0.5f),SEX_BOTH));
  216. addEntry(SUBPART_ALPHA, new SubpartEntry(SUBPART_ALPHA, "mPelvis", "alpha", "alpha_main_param_list", "alpha_main_tab", LLVector3d(0.f, 0.f, 0.1f), LLVector3d(-2.5f, 0.5f, 0.8f),SEX_BOTH));
  217. addEntry(SUBPART_TATTOO, new SubpartEntry(SUBPART_TATTOO, "mPelvis", "tattoo", "tattoo_main_param_list", "tattoo_main_tab", LLVector3d(0.f, 0.f, 0.1f), LLVector3d(-2.5f, 0.5f, 0.8f),SEX_BOTH));
  218. }
  219. LLEditWearableDictionary::SubpartEntry::SubpartEntry(ESubpart part,
  220.  const std::string &joint,
  221.  const std::string &edit_group,
  222.  const std::string &param_list,
  223.  const std::string &accordion_tab,
  224.  const LLVector3d  &target_offset,
  225.  const LLVector3d  &camera_offset,
  226.  const ESex     &sex) :
  227. LLDictionaryEntry(edit_group),
  228. mSubpart(part),
  229. mTargetJoint(joint),
  230. mEditGroup(edit_group),
  231. mParamList(param_list),
  232. mAccordionTab(accordion_tab),
  233. mTargetOffset(target_offset),
  234. mCameraOffset(camera_offset),
  235. mSex(sex)
  236. {
  237. }
  238. // LLPanelEditWearable
  239. LLPanelEditWearable::LLPanelEditWearable()
  240. : LLPanel()
  241. {
  242. }
  243. //virtual
  244. LLPanelEditWearable::~LLPanelEditWearable()
  245. {
  246. }
  247. // virtual 
  248. BOOL LLPanelEditWearable::postBuild()
  249. {
  250. // buttons
  251. mBtnRevert = getChild<LLButton>("revert_button");
  252. mBtnRevert->setClickedCallback(boost::bind(&LLPanelEditWearable::onRevertButtonClicked, this));
  253. mBtnBack = getChild<LLButton>("back_btn");
  254. // handled at appearance panel level?
  255. //mBtnBack->setClickedCallback(boost::bind(&LLPanelEditWearable::onBackButtonClicked, this));
  256. mTextEditor = getChild<LLTextEditor>("description");
  257. mPanelTitle = getChild<LLTextBox>("edit_wearable_title");
  258. mDescTitle = getChild<LLTextBox>("description_text");
  259. // The following panels will be shown/hidden based on what wearable we're editing
  260. // body parts
  261. mPanelShape = getChild<LLPanel>("edit_shape_panel");
  262. mPanelSkin = getChild<LLPanel>("edit_skin_panel");
  263. mPanelEyes = getChild<LLPanel>("edit_eyes_panel");
  264. mPanelHair = getChild<LLPanel>("edit_hair_panel");
  265. //clothes
  266. mPanelShirt = getChild<LLPanel>("edit_shirt_panel");
  267. mPanelPants = getChild<LLPanel>("edit_pants_panel");
  268. mPanelShoes = getChild<LLPanel>("edit_shoes_panel");
  269. mPanelSocks = getChild<LLPanel>("edit_socks_panel");
  270. mPanelJacket = getChild<LLPanel>("edit_jacket_panel");
  271. mPanelGloves = getChild<LLPanel>("edit_gloves_panel");
  272. mPanelUndershirt = getChild<LLPanel>("edit_undershirt_panel");
  273. mPanelUnderpants = getChild<LLPanel>("edit_underpants_panel");
  274. mPanelSkirt = getChild<LLPanel>("edit_skirt_panel");
  275. mPanelAlpha = getChild<LLPanel>("edit_alpha_panel");
  276. mPanelTattoo = getChild<LLPanel>("edit_tattoo_panel");
  277. mWearablePtr = NULL;
  278. return TRUE;
  279. }
  280. // virtual 
  281. // LLUICtrl
  282. BOOL LLPanelEditWearable::isDirty() const
  283. {
  284. BOOL isDirty = FALSE;
  285. if (mWearablePtr)
  286. {
  287. if (mWearablePtr->isDirty() ||
  288. mWearablePtr->getName().compare(mTextEditor->getText()) != 0)
  289. {
  290. isDirty = TRUE;
  291. }
  292. }
  293. return isDirty;
  294. }
  295. //virtual
  296. void LLPanelEditWearable::draw()
  297. {
  298. BOOL is_dirty = isDirty();
  299. mBtnRevert->setEnabled(is_dirty);
  300. LLPanel::draw();
  301. }
  302. void LLPanelEditWearable::setWearable(LLWearable *wearable)
  303. {
  304. showWearable(mWearablePtr, FALSE);
  305. mWearablePtr = wearable;
  306. showWearable(mWearablePtr, TRUE);
  307. initializePanel();
  308. }
  309. //static 
  310. void LLPanelEditWearable::onRevertButtonClicked(void* userdata)
  311. {
  312. LLPanelEditWearable *panel = (LLPanelEditWearable*) userdata;
  313. panel->revertChanges();
  314. }
  315. void LLPanelEditWearable::saveChanges()
  316. {
  317. if (!mWearablePtr || !isDirty())
  318. {
  319. // do nothing if no unsaved changes
  320. return;
  321. }
  322. U32 index = gAgentWearables.getWearableIndex(mWearablePtr);
  323. if (mWearablePtr->getName().compare(mTextEditor->getText()) != 0)
  324. {
  325. // the name of the wearable has changed, re-save wearable with new name
  326. gAgentWearables.saveWearableAs(mWearablePtr->getType(), index, mTextEditor->getText(), FALSE);
  327. }
  328. else
  329. {
  330. gAgentWearables.saveWearable(mWearablePtr->getType(), index);
  331. }
  332. }
  333. void LLPanelEditWearable::revertChanges()
  334. {
  335. if (!mWearablePtr || !isDirty())
  336. {
  337. // no unsaved changes to revert
  338. return;
  339. }
  340. mWearablePtr->revertValues();
  341. mTextEditor->setText(mWearablePtr->getName());
  342. }
  343. void LLPanelEditWearable::showWearable(LLWearable* wearable, BOOL show)
  344. {
  345. if (!wearable)
  346. {
  347. return;
  348. }
  349. EWearableType type = wearable->getType();
  350. LLPanel *targetPanel = NULL;
  351. std::string title;
  352. std::string description_title;
  353. const LLEditWearableDictionary::WearableEntry *entry = LLEditWearableDictionary::getInstance()->getWearable(type);
  354. if (!entry)
  355. {
  356. llwarns << "called LLPanelEditWearable::showWearable with an invalid wearable type! (" << type << ")" << llendl;
  357. return;
  358. }
  359. targetPanel = getPanel(type);
  360. title = getString(entry->mTitle);
  361. description_title = getString(entry->mDescTitle);
  362. targetPanel->setVisible(show);
  363. if (show)
  364. {
  365. mPanelTitle->setText(title);
  366. mDescTitle->setText(description_title);
  367. }
  368. }
  369. void LLPanelEditWearable::initializePanel()
  370. {
  371. if (!mWearablePtr)
  372. {
  373. // cannot initialize with a null reference.
  374. return;
  375. }
  376. EWearableType type = mWearablePtr->getType();
  377. // set name
  378. mTextEditor->setText(mWearablePtr->getName());
  379. // clear and rebuild visual param list
  380. const LLEditWearableDictionary::WearableEntry *wearable_entry = LLEditWearableDictionary::getInstance()->getWearable(type);
  381. if (!wearable_entry)
  382. {
  383. llwarns << "could not get wearable dictionary entry for wearable of type: " << type << llendl;
  384. return;
  385. }
  386. U8 num_subparts = wearable_entry->mSubparts.size();
  387. for (U8 index = 0; index < num_subparts; ++index)
  388. {
  389. // dive into data structures to get the panel we need
  390. ESubpart subpart_e = wearable_entry->mSubparts[index];
  391. const LLEditWearableDictionary::SubpartEntry *subpart_entry = LLEditWearableDictionary::getInstance()->getSubpart(subpart_e);
  392. if (!subpart_entry)
  393. {
  394. llwarns << "could not get wearable subpart dictionary entry for subpart: " << subpart_e << llendl;
  395. continue;
  396. }
  397. const std::string scrolling_panel = subpart_entry->mParamList;
  398. const std::string accordion_tab = subpart_entry->mAccordionTab;
  399. LLScrollingPanelList *panel_list = getChild<LLScrollingPanelList>(scrolling_panel);
  400. LLAccordionCtrlTab *tab = getChild<LLAccordionCtrlTab>(accordion_tab);
  401. if (!panel_list)
  402. {
  403. llwarns << "could not get scrolling panel list: " << scrolling_panel << llendl;
  404. continue;
  405. }
  406. if (!tab)
  407. {
  408. llwarns << "could not get llaccordionctrltab from UI with name: " << accordion_tab << llendl;
  409. continue;
  410. }
  411. // what edit group do we want to extract params for?
  412. const std::string edit_group = subpart_entry->mEditGroup;
  413. // storage for ordered list of visual params
  414. value_map_t sorted_params;
  415. getSortedParams(sorted_params, edit_group);
  416. buildParamList(panel_list, sorted_params, tab);
  417. updateScrollingPanelUI();
  418. }
  419. }
  420. void LLPanelEditWearable::updateScrollingPanelUI()
  421. {
  422. // do nothing if we don't have a valid wearable we're editing
  423. if (mWearablePtr == NULL)
  424. {
  425. return;
  426. }
  427. EWearableType type = mWearablePtr->getType();
  428. LLPanel *panel = getPanel(type);
  429. if(panel && (mWearablePtr->getItemID().notNull()))
  430. {
  431. const LLEditWearableDictionary::WearableEntry *wearable_entry = LLEditWearableDictionary::getInstance()->getWearable(type);
  432. U8 num_subparts = wearable_entry->mSubparts.size();
  433. LLScrollingPanelParam::sUpdateDelayFrames = 0;
  434. for (U8 index = 0; index < num_subparts; ++index)
  435. {
  436. // dive into data structures to get the panel we need
  437. ESubpart subpart_e = wearable_entry->mSubparts[index];
  438. const LLEditWearableDictionary::SubpartEntry *subpart_entry = LLEditWearableDictionary::getInstance()->getSubpart(subpart_e);
  439. const std::string scrolling_panel = subpart_entry->mParamList;
  440. LLScrollingPanelList *panel_list = getChild<LLScrollingPanelList>(scrolling_panel);
  441. if (!panel_list)
  442. {
  443. llwarns << "could not get scrolling panel list: " << scrolling_panel << llendl;
  444. continue;
  445. }
  446. panel_list->updatePanels(TRUE);
  447. }
  448. }
  449. }
  450. LLPanel* LLPanelEditWearable::getPanel(EWearableType type)
  451. {
  452. switch (type)
  453. {
  454. case WT_SHAPE:
  455. return mPanelShape;
  456. break;
  457. case WT_SKIN:
  458. return mPanelSkin;
  459. break;
  460. case WT_HAIR:
  461. return mPanelHair;
  462. break;
  463. case WT_EYES:
  464. return mPanelEyes;
  465. break;
  466. case WT_SHIRT:
  467. return mPanelShirt;
  468. break;
  469. case WT_PANTS:
  470. return mPanelPants;
  471. break;
  472. case WT_SHOES:
  473. return mPanelShoes;
  474. break;
  475. case WT_SOCKS:
  476. return mPanelSocks;
  477. break;
  478. case WT_JACKET:
  479. return mPanelJacket;
  480. break;
  481. case WT_GLOVES:
  482. return mPanelGloves;
  483. break;
  484. case WT_UNDERSHIRT:
  485. return mPanelUndershirt;
  486. break;
  487. case WT_UNDERPANTS:
  488. return mPanelUnderpants;
  489. break;
  490. case WT_SKIRT:
  491. return mPanelSkirt;
  492. break;
  493. case WT_ALPHA:
  494. return mPanelAlpha;
  495. break;
  496. case WT_TATTOO:
  497. return mPanelTattoo;
  498. break;
  499. default:
  500. break;
  501. }
  502. return NULL;
  503. }
  504. void LLPanelEditWearable::getSortedParams(value_map_t &sorted_params, const std::string &edit_group)
  505. {
  506. LLWearable::visual_param_vec_t param_list;
  507. ESex avatar_sex = gAgent.getAvatarObject()->getSex();
  508. mWearablePtr->getVisualParams(param_list);
  509. for (LLWearable::visual_param_vec_t::iterator iter = param_list.begin();
  510. iter != param_list.end();
  511. ++iter)
  512. {
  513. LLViewerVisualParam *param = (LLViewerVisualParam*) *iter;
  514. if (param->getID() == -1
  515. || param->getGroup() != VISUAL_PARAM_GROUP_TWEAKABLE 
  516. || param->getEditGroup() != edit_group 
  517. || !(param->getSex() & avatar_sex))
  518. {
  519. continue;
  520. }
  521. value_map_t::value_type vt(-param->getDisplayOrder(), param);
  522. llassert( sorted_params.find(-param->getDisplayOrder()) == sorted_params.end() ); //check for duplicates
  523. sorted_params.insert(vt);
  524. }
  525. }
  526. void LLPanelEditWearable::buildParamList(LLScrollingPanelList *panel_list, value_map_t &sorted_params, LLAccordionCtrlTab *tab)
  527. {
  528. // sorted_params is sorted according to magnitude of effect from
  529. // least to greatest.  Adding to the front of the child list
  530. // reverses that order.
  531. if( panel_list )
  532. {
  533. panel_list->clearPanels();
  534. value_map_t::iterator end = sorted_params.end();
  535. S32 height = 0;
  536. for(value_map_t::iterator it = sorted_params.begin(); it != end; ++it)
  537. {
  538. LLPanel::Params p;
  539. p.name("LLScrollingPanelParam");
  540. p.rect(LLRect(0, LLScrollingPanelParam::PARAM_PANEL_HEIGHT, LLScrollingPanelParam::PARAM_PANEL_WIDTH, 0 ));
  541. LLScrollingPanelParam* panel_param = new LLScrollingPanelParam( p, NULL, (*it).second, TRUE, this->getWearable());
  542. height = panel_list->addPanel( panel_param );
  543. }
  544. S32 width = tab->getRect().getWidth();
  545. tab->reshape(width,height + tab->getHeaderHeight()+10,FALSE);
  546. }
  547. }