hbfloatermakenewoutfit.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. /**
  2. * @file hbfloatermakenewoutfit.cpp
  3. * @brief The Make New Outfit floater implementation
  4. *
  5. * $LicenseInfo:firstyear=2011&license=viewergpl$
  6. *
  7. * Copyright (c) 2011-2015 Henri Beauchamp
  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 "hbfloatermakenewoutfit.h"
  34. #include "llbutton.h"
  35. #include "llcheckboxctrl.h"
  36. #include "llscrolllistctrl.h"
  37. #include "lltrans.h"
  38. #include "lluictrlfactory.h"
  39. #include "llagent.h"
  40. #include "llagentwearables.h"
  41. #include "llviewercontrol.h"
  42. #include "llvoavatarself.h"
  43. //static
  44. uuid_list_t HBFloaterMakeNewOutfit::sFetchingRequests;
  45. uuid_list_t HBFloaterMakeNewOutfit::sUnderpants;
  46. uuid_list_t HBFloaterMakeNewOutfit::sUndershirts;
  47. HBFloaterMakeNewOutfit::HBFloaterMakeNewOutfit(const LLSD&)
  48. : mIsDirty(true),
  49. mSaveStatusDirty(true)
  50. {
  51. LLUICtrlFactory::getInstance()->buildFloater(this,
  52. "floater_make_new_outfit.xml");
  53. }
  54. //virtual
  55. HBFloaterMakeNewOutfit::~HBFloaterMakeNewOutfit()
  56. {
  57. sFetchingRequests.clear();
  58. }
  59. //virtual
  60. bool HBFloaterMakeNewOutfit::postBuild()
  61. {
  62. mSaveButton = getChild<LLButton>("save_btn");
  63. mSaveButton->setClickedCallback(onButtonSave, this);
  64. childSetAction("cancel_btn", onButtonCancel, this);
  65. mShapeCheck = getChild<LLCheckBoxCtrl>("checkbox_shape");
  66. mShapeCheck->setCommitCallback(onCommitCheckBox);
  67. mShapeCheck->setCallbackUserData(this);
  68. mSkinCheck = getChild<LLCheckBoxCtrl>("checkbox_skin");
  69. mSkinCheck->setCommitCallback(onCommitCheckBox);
  70. mSkinCheck->setCallbackUserData(this);
  71. mHairCheck = getChild<LLCheckBoxCtrl>("checkbox_hair");
  72. mHairCheck->setCommitCallback(onCommitCheckBox);
  73. mHairCheck->setCallbackUserData(this);
  74. mEyesCheck = getChild<LLCheckBoxCtrl>("checkbox_eyes");
  75. mEyesCheck->setCommitCallback(onCommitCheckBox);
  76. mEyesCheck->setCallbackUserData(this);
  77. mAttachmentsList = getChild<LLScrollListCtrl>("attachments_list");
  78. mAttachmentsList->setCommitOnSelectionChange(true);
  79. mAttachmentsList->setCommitCallback(onCommitCheckBox);
  80. mAttachmentsList->setCallbackUserData(this);
  81. mWearablesList = getChild<LLScrollListCtrl>("wearables_list");
  82. mWearablesList->setCommitOnSelectionChange(true);
  83. mWearablesList->setCommitCallback(onCommitWearableList);
  84. mWearablesList->setCallbackUserData(this);
  85. mRenameCheck = getChild<LLCheckBoxCtrl>("checkbox_rename");
  86. mUseNoCopyLinksCheck = getChild<LLCheckBoxCtrl>("checkbox_nocopy_links");
  87. mUseClothesLinksCheck = getChild<LLCheckBoxCtrl>("checkbox_clothes_links");
  88. mUseAllLinksCheck = getChild<LLCheckBoxCtrl>("checkbox_all_links");
  89. mUseAllLinksCheck->setCommitCallback(onCommitCheckBoxLinkAll);
  90. mUseAllLinksCheck->setCallbackUserData(this);
  91. bool use_links_always = gSavedSettings.getBool("UseInventoryLinksAlways");
  92. mUseNoCopyLinksCheck->setEnabled(!use_links_always);
  93. mUseClothesLinksCheck->setEnabled(!use_links_always);
  94. mRenameCheck->setEnabled(!use_links_always);
  95. return true;
  96. }
  97. //virtual
  98. void HBFloaterMakeNewOutfit::draw()
  99. {
  100. if (mIsDirty && isAgentAvatarValid())
  101. {
  102. mIsDirty = false;
  103. LLScrollListItem* scroll_item;
  104. LLViewerInventoryItem* inv_item;
  105. // Update wearables list
  106. S32 scrollpos = mWearablesList->getScrollPos();
  107. S32 selected = mWearablesList->getFirstSelectedIndex();
  108. mWearablesList->deleteAllItems();
  109. sUndershirts.clear();
  110. sUnderpants.clear();
  111. for (S32 type = (S32)LLWearableType::WT_SHIRT;
  112. type < (S32)LLWearableType::WT_COUNT; ++type)
  113. {
  114. std::string type_name =
  115. LLTrans::getString(LLWearableType::getTypeLabel((LLWearableType::EType)type));
  116. for (U32 index = 0,
  117. count = gAgentWearables.getWearableCount((LLWearableType::EType)type);
  118. index < count; ++index)
  119. {
  120. LLViewerWearable* wearable =
  121. gAgentWearables.getViewerWearable((LLWearableType::EType)type,
  122. index);
  123. if (!wearable) continue;
  124. inv_item = gInventory.getItem(wearable->getItemID());
  125. if (!inv_item) continue;
  126. LLUUID item_id = inv_item->getLinkedUUID();
  127. LLSD element;
  128. element["id"] = item_id;
  129. element["columns"][0]["column"] = "selection";
  130. element["columns"][0]["type"] = "checkbox";
  131. element["columns"][0]["value"] = true;
  132. element["columns"][1]["column"] = "wearable";
  133. element["columns"][1]["type"] = "text";
  134. element["columns"][1]["value"] = inv_item->getName();
  135. element["columns"][1]["font"] = "SANSSERIF_SMALL";
  136. element["columns"][2]["column"] = "type";
  137. element["columns"][2]["type"] = "text";
  138. element["columns"][2]["value"] = type_name;
  139. element["columns"][2]["font"] = "SANSSERIF_SMALL";
  140. scroll_item = mWearablesList->addElement(element, ADD_BOTTOM);
  141. if (!scroll_item) continue; // Out of memory ?
  142. #if LL_TEEN_WERABLE_RESTRICTIONS
  143. if (gAgent.isTeen())
  144. {
  145. if (type == LLWearableType::WT_UNDERSHIRT)
  146. {
  147. sUndershirts.emplace(item_id);
  148. }
  149. else if (type == LLWearableType::WT_UNDERPANTS)
  150. {
  151. sUnderpants.emplace(item_id);
  152. }
  153. }
  154. #endif
  155. }
  156. }
  157. mWearablesList->setScrollPos(scrollpos);
  158. if (selected >= 0)
  159. {
  160. mWearablesList->selectNthItem(selected);
  161. }
  162. // Update attachments list
  163. scrollpos = mAttachmentsList->getScrollPos();
  164. selected = mAttachmentsList->getFirstSelectedIndex();
  165. mAttachmentsList->deleteAllItems();
  166. for (S32 i = 0, count = gAgentAvatarp->mAttachedObjectsVector.size();
  167. i < count; ++i)
  168. {
  169. LLViewerJointAttachment* vatt =
  170. gAgentAvatarp->mAttachedObjectsVector[i].second;
  171. if (!vatt) continue; // Paranoia
  172. std::string joint_name = LLTrans::getString(vatt->getName());
  173. LLViewerObject* vobj =
  174. gAgentAvatarp->mAttachedObjectsVector[i].first;
  175. if (!vobj) continue; // Paranoia
  176. const LLUUID& item_id = vobj->getAttachmentItemID();
  177. if (item_id.isNull()) continue;
  178. inv_item = gInventory.getItem(item_id);
  179. if (!inv_item) continue;
  180. // Make sure all attached inventory items are complete, so
  181. // that we can safely copy them later...
  182. bool complete = true;
  183. if (!inv_item->isFinished())
  184. {
  185. if (!sFetchingRequests.count(item_id))
  186. {
  187. sFetchingRequests.emplace(item_id);
  188. inv_item->fetchFromServer();
  189. }
  190. complete = false;
  191. // refresh UI till all items are complete
  192. mIsDirty = true;
  193. }
  194. LLSD element;
  195. element["id"] = inv_item->getLinkedUUID();
  196. element["columns"][0]["column"] = "selection";
  197. element["columns"][0]["type"] = "checkbox";
  198. element["columns"][0]["value"] = complete;
  199. element["columns"][1]["column"] = "attachment";
  200. element["columns"][1]["type"] = "text";
  201. element["columns"][1]["value"] = inv_item->getName();
  202. element["columns"][1]["font"] = "SANSSERIF_SMALL";
  203. element["columns"][2]["column"] = "joint";
  204. element["columns"][2]["type"] = "text";
  205. element["columns"][2]["value"] = joint_name;
  206. element["columns"][2]["font"] = "SANSSERIF_SMALL";
  207. scroll_item = mAttachmentsList->addElement(element, ADD_BOTTOM);
  208. if (!scroll_item) continue; // Out of memory ?
  209. scroll_item->setEnabled(complete);
  210. }
  211. mAttachmentsList->setScrollPos(scrollpos);
  212. if (selected >= 0)
  213. {
  214. mAttachmentsList->selectNthItem(selected);
  215. }
  216. // Force a refresh of the Save button status
  217. mSaveStatusDirty = true;
  218. }
  219. if (mSaveStatusDirty)
  220. {
  221. mSaveStatusDirty = false;
  222. mSaveButton->setEnabled(hasCheckedItems());
  223. }
  224. LLFloater::draw();
  225. }
  226. bool HBFloaterMakeNewOutfit::hasCheckedItems()
  227. {
  228. // Check the body parts
  229. if (mShapeCheck->get() || mSkinCheck->get() || mHairCheck->get() ||
  230. mEyesCheck->get())
  231. {
  232. return true;
  233. }
  234. // Check the wearables
  235. std::vector<LLScrollListItem*> items = mWearablesList->getAllData();
  236. for (S32 i = 0, count = items.size(); i < count; ++i)
  237. {
  238. LLScrollListItem* item = items[i];
  239. if (item && item->getColumn(0)->getValue().asBoolean())
  240. {
  241. return true;
  242. }
  243. }
  244. // Finally, check the attachments
  245. items = mAttachmentsList->getAllData();
  246. for (S32 i = 0, count = items.size(); i < count; ++i)
  247. {
  248. LLScrollListItem* item = items[i];
  249. if (item && item->getColumn(0)->getValue().asBoolean())
  250. {
  251. return true;
  252. }
  253. }
  254. return false;
  255. }
  256. void HBFloaterMakeNewOutfit::getIncludedItems(uuid_vec_t& wearables_to_include,
  257. uuid_vec_t& attachments_to_include)
  258. {
  259. // First, deal with body parts check boxes
  260. wearables_to_include.clear();
  261. for (S32 type = 0; type <= (S32)LLWearableType::WT_EYES; ++type)
  262. {
  263. std::string name =
  264. LLWearableType::getTypeLabel((LLWearableType::EType)type);
  265. std::string label = "checkbox_" + name;
  266. LLStringUtil::toLower(label);
  267. if (!childGetValue(label.c_str()).asBoolean()) continue;
  268. if (!gAgentWearables.getWearableCount((LLWearableType::EType)type))
  269. {
  270. llwarns << "Avatar not fully rezzed. Missing body part: "
  271. << name << llendl;
  272. continue;
  273. }
  274. LLViewerWearable* wearable =
  275. gAgentWearables.getViewerWearable((LLWearableType::EType)type, 0);
  276. if (!wearable)
  277. {
  278. llwarns << "Could not find wearable item for body part: " << name
  279. << llendl;
  280. continue;
  281. }
  282. LLViewerInventoryItem* inv_item =
  283. gInventory.getItem(wearable->getItemID());
  284. if (inv_item)
  285. {
  286. wearables_to_include.emplace_back(inv_item->getLinkedUUID());
  287. }
  288. else
  289. {
  290. llwarns << "Could not find inventory item for body part: " << name
  291. << llendl;
  292. }
  293. }
  294. // Then, add all selected wearables in the list
  295. std::vector<LLScrollListItem*> items = mWearablesList->getAllData();
  296. wearables_to_include.reserve(wearables_to_include.size() + items.size());
  297. for (S32 i = 0, count = items.size(); i < count; ++i)
  298. {
  299. LLScrollListItem* item = items[i];
  300. if (item && item->getColumn(0)->getValue().asBoolean())
  301. {
  302. wearables_to_include.emplace_back(item->getValue().asUUID());
  303. }
  304. }
  305. // Finally, deal with the attachments
  306. items = mAttachmentsList->getAllData();
  307. attachments_to_include.reserve(items.size());
  308. for (S32 i = 0, count = items.size(); i < count; ++i)
  309. {
  310. LLScrollListItem* item = items[i];
  311. if (item && item->getColumn(0)->getValue().asBoolean())
  312. {
  313. attachments_to_include.emplace_back(item->getValue().asUUID());
  314. }
  315. }
  316. }
  317. //static
  318. void HBFloaterMakeNewOutfit::setDirty()
  319. {
  320. HBFloaterMakeNewOutfit* self = findInstance();
  321. if (self)
  322. {
  323. self->mIsDirty = true;
  324. }
  325. }
  326. //static
  327. void HBFloaterMakeNewOutfit::onCommitWearableList(LLUICtrl* ctrl,
  328. void* user_data)
  329. {
  330. HBFloaterMakeNewOutfit* self = (HBFloaterMakeNewOutfit*)user_data;
  331. if (self)
  332. {
  333. self->mSaveStatusDirty = true;
  334. #if LL_TEEN_WERABLE_RESTRICTIONS
  335. // Enforce strict underwears for teens
  336. LLScrollListItem* item = dynamic_cast<LLScrollListItem*>(ctrl);
  337. if (gAgent.isTeen() && item &&
  338. !item->getColumn(0)->getValue().asBoolean())
  339. {
  340. LLUUID item_id = item->getValue();
  341. if (sUnderpants.count(item_id))
  342. {
  343. if (sUnderpants.size() > 1)
  344. {
  345. sUnderpants.erase(item_id);
  346. }
  347. else
  348. {
  349. item->getColumn(0)->setValue(true);
  350. }
  351. }
  352. else if (sUndershirts.count(item_id))
  353. {
  354. if (sUndershirts.size() > 1)
  355. {
  356. sUndershirts.erase(item_id);
  357. }
  358. else
  359. {
  360. item->getColumn(0)->setValue(true);
  361. }
  362. }
  363. }
  364. #endif
  365. }
  366. }
  367. //static
  368. void HBFloaterMakeNewOutfit::onCommitCheckBox(LLUICtrl*, void* user_data)
  369. {
  370. HBFloaterMakeNewOutfit* self = (HBFloaterMakeNewOutfit*)user_data;
  371. if (self)
  372. {
  373. self->mSaveStatusDirty = true;
  374. }
  375. }
  376. //static
  377. void HBFloaterMakeNewOutfit::onCommitCheckBoxLinkAll(LLUICtrl* ctrl,
  378. void* user_data)
  379. {
  380. HBFloaterMakeNewOutfit* self = (HBFloaterMakeNewOutfit*)user_data;
  381. LLCheckBoxCtrl* check = (LLCheckBoxCtrl*)ctrl;
  382. if (self && check)
  383. {
  384. bool enable = !check->get();
  385. self->mUseNoCopyLinksCheck->setEnabled(enable);
  386. self->mUseClothesLinksCheck->setEnabled(enable);
  387. self->mRenameCheck->setEnabled(enable);
  388. }
  389. }
  390. //static
  391. void HBFloaterMakeNewOutfit::onButtonSave(void* user_data)
  392. {
  393. HBFloaterMakeNewOutfit* self = (HBFloaterMakeNewOutfit*)user_data;
  394. if (self)
  395. {
  396. std::string folder = self->childGetValue("name_lineeditor").asString();
  397. bool rename_clothing = self->mRenameCheck->getValue().asBoolean();
  398. uuid_vec_t wearables, attachments;
  399. self->getIncludedItems(wearables, attachments);
  400. gAgentWearables.makeNewOutfit(folder, wearables, attachments,
  401. rename_clothing);
  402. self->close();
  403. }
  404. }
  405. //static
  406. void HBFloaterMakeNewOutfit::onButtonCancel(void* user_data)
  407. {
  408. HBFloaterMakeNewOutfit* self = (HBFloaterMakeNewOutfit*)user_data;
  409. if (self)
  410. {
  411. self->close();
  412. }
  413. }