PageRenderTime 87ms CodeModel.GetById 31ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llsidepanelappearance.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 552 lines | 427 code | 66 blank | 59 comment | 92 complexity | a886df759df4d80ee844605e562ae01c MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llsidepanelappearance.cpp
  3. * @brief Side Bar "Appearance" panel
  4. *
  5. * $LicenseInfo:firstyear=2009&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 "llsidepanelappearance.h"
  28. #include "llaccordionctrltab.h"
  29. #include "llagent.h"
  30. #include "llagentcamera.h"
  31. #include "llagentwearables.h"
  32. #include "llappearancemgr.h"
  33. #include "llfloatersidepanelcontainer.h"
  34. #include "llfolderview.h"
  35. #include "llinventorypanel.h"
  36. #include "llfiltereditor.h"
  37. #include "llfloaterreg.h"
  38. #include "llfloaterworldmap.h"
  39. #include "llfoldervieweventlistener.h"
  40. #include "lloutfitobserver.h"
  41. #include "llpaneleditwearable.h"
  42. #include "llpaneloutfitsinventory.h"
  43. #include "lltextbox.h"
  44. #include "lluictrlfactory.h"
  45. #include "llviewercontrol.h"
  46. #include "llviewerregion.h"
  47. #include "llvoavatarself.h"
  48. #include "llwearable.h"
  49. static LLRegisterPanelClassWrapper<LLSidepanelAppearance> t_appearance("sidepanel_appearance");
  50. class LLCurrentlyWornFetchObserver : public LLInventoryFetchItemsObserver
  51. {
  52. public:
  53. LLCurrentlyWornFetchObserver(const uuid_vec_t &ids,
  54. LLSidepanelAppearance *panel) :
  55. LLInventoryFetchItemsObserver(ids),
  56. mPanel(panel)
  57. {}
  58. ~LLCurrentlyWornFetchObserver() {}
  59. virtual void done()
  60. {
  61. mPanel->inventoryFetched();
  62. gInventory.removeObserver(this);
  63. delete this;
  64. }
  65. private:
  66. LLSidepanelAppearance *mPanel;
  67. };
  68. LLSidepanelAppearance::LLSidepanelAppearance() :
  69. LLPanel(),
  70. mFilterSubString(LLStringUtil::null),
  71. mFilterEditor(NULL),
  72. mOutfitEdit(NULL),
  73. mCurrOutfitPanel(NULL),
  74. mOpened(false)
  75. {
  76. LLOutfitObserver& outfit_observer = LLOutfitObserver::instance();
  77. outfit_observer.addBOFReplacedCallback(boost::bind(&LLSidepanelAppearance::refreshCurrentOutfitName, this, ""));
  78. outfit_observer.addBOFChangedCallback(boost::bind(&LLSidepanelAppearance::refreshCurrentOutfitName, this, ""));
  79. outfit_observer.addCOFChangedCallback(boost::bind(&LLSidepanelAppearance::refreshCurrentOutfitName, this, ""));
  80. gAgentWearables.addLoadingStartedCallback(boost::bind(&LLSidepanelAppearance::setWearablesLoading, this, true));
  81. gAgentWearables.addLoadedCallback(boost::bind(&LLSidepanelAppearance::setWearablesLoading, this, false));
  82. }
  83. LLSidepanelAppearance::~LLSidepanelAppearance()
  84. {
  85. }
  86. // virtual
  87. BOOL LLSidepanelAppearance::postBuild()
  88. {
  89. mOpenOutfitBtn = getChild<LLButton>("openoutfit_btn");
  90. mOpenOutfitBtn->setClickedCallback(boost::bind(&LLSidepanelAppearance::onOpenOutfitButtonClicked, this));
  91. mEditAppearanceBtn = getChild<LLButton>("editappearance_btn");
  92. mEditAppearanceBtn->setClickedCallback(boost::bind(&LLSidepanelAppearance::onEditAppearanceButtonClicked, this));
  93. childSetAction("edit_outfit_btn", boost::bind(&LLSidepanelAppearance::showOutfitEditPanel, this));
  94. mNewOutfitBtn = getChild<LLButton>("newlook_btn");
  95. mNewOutfitBtn->setClickedCallback(boost::bind(&LLSidepanelAppearance::onNewOutfitButtonClicked, this));
  96. mNewOutfitBtn->setEnabled(false);
  97. mFilterEditor = getChild<LLFilterEditor>("Filter");
  98. if (mFilterEditor)
  99. {
  100. mFilterEditor->setCommitCallback(boost::bind(&LLSidepanelAppearance::onFilterEdit, this, _2));
  101. }
  102. mPanelOutfitsInventory = dynamic_cast<LLPanelOutfitsInventory *>(getChild<LLPanel>("panel_outfits_inventory"));
  103. mOutfitEdit = dynamic_cast<LLPanelOutfitEdit*>(getChild<LLPanel>("panel_outfit_edit"));
  104. if (mOutfitEdit)
  105. {
  106. LLButton* back_btn = mOutfitEdit->getChild<LLButton>("back_btn");
  107. if (back_btn)
  108. {
  109. back_btn->setClickedCallback(boost::bind(&LLSidepanelAppearance::showOutfitsInventoryPanel, this));
  110. }
  111. }
  112. mEditWearable = dynamic_cast<LLPanelEditWearable*>(getChild<LLPanel>("panel_edit_wearable"));
  113. if (mEditWearable)
  114. {
  115. LLButton* edit_wearable_back_btn = mEditWearable->getChild<LLButton>("back_btn");
  116. if (edit_wearable_back_btn)
  117. {
  118. edit_wearable_back_btn->setClickedCallback(boost::bind(&LLSidepanelAppearance::showOutfitEditPanel, this));
  119. }
  120. }
  121. mCurrentLookName = getChild<LLTextBox>("currentlook_name");
  122. mOutfitStatus = getChild<LLTextBox>("currentlook_status");
  123. mCurrOutfitPanel = getChild<LLPanel>("panel_currentlook");
  124. setVisibleCallback(boost::bind(&LLSidepanelAppearance::onVisibilityChange,this,_2));
  125. return TRUE;
  126. }
  127. // virtual
  128. void LLSidepanelAppearance::onOpen(const LLSD& key)
  129. {
  130. if (!key.has("type"))
  131. {
  132. // No specific panel requested.
  133. // If we're opened for the first time then show My Outfits.
  134. // Else do nothing.
  135. if (!mOpened)
  136. {
  137. showOutfitsInventoryPanel();
  138. }
  139. }
  140. else
  141. {
  142. // Switch to the requested panel.
  143. std::string type = key["type"].asString();
  144. if (type == "my_outfits")
  145. {
  146. showOutfitsInventoryPanel();
  147. }
  148. else if (type == "edit_outfit")
  149. {
  150. showOutfitEditPanel();
  151. }
  152. else if (type == "edit_shape")
  153. {
  154. showWearableEditPanel();
  155. }
  156. }
  157. mOpened = true;
  158. }
  159. void LLSidepanelAppearance::onVisibilityChange(const LLSD &new_visibility)
  160. {
  161. LLSD visibility;
  162. visibility["visible"] = new_visibility.asBoolean();
  163. visibility["reset_accordion"] = false;
  164. updateToVisibility(visibility);
  165. }
  166. void LLSidepanelAppearance::updateToVisibility(const LLSD &new_visibility)
  167. {
  168. if (new_visibility["visible"].asBoolean())
  169. {
  170. const BOOL is_outfit_edit_visible = mOutfitEdit && mOutfitEdit->getVisible();
  171. const BOOL is_wearable_edit_visible = mEditWearable && mEditWearable->getVisible();
  172. if (is_outfit_edit_visible || is_wearable_edit_visible)
  173. {
  174. const LLWearable *wearable_ptr = mEditWearable->getWearable();
  175. if (!wearable_ptr)
  176. {
  177. llwarns << "Visibility change to invalid wearable" << llendl;
  178. return;
  179. }
  180. // Disable camera switch is currently just for WT_PHYSICS type since we don't want to freeze the avatar
  181. // when editing its physics.
  182. const BOOL disable_camera_motion = LLWearableType::getDisableCameraSwitch(wearable_ptr->getType());
  183. if (!gAgentCamera.cameraCustomizeAvatar() &&
  184. !disable_camera_motion &&
  185. gSavedSettings.getBOOL("AppearanceCameraMovement"))
  186. {
  187. gAgentCamera.changeCameraToCustomizeAvatar();
  188. }
  189. if (is_wearable_edit_visible)
  190. {
  191. if (gAgentWearables.getWearableIndex(wearable_ptr) == LLAgentWearables::MAX_CLOTHING_PER_TYPE)
  192. {
  193. // we're no longer wearing the wearable we were last editing, switch back to outfit editor
  194. showOutfitEditPanel();
  195. }
  196. }
  197. if (is_outfit_edit_visible && new_visibility["reset_accordion"].asBoolean())
  198. {
  199. mOutfitEdit->resetAccordionState();
  200. }
  201. }
  202. }
  203. else
  204. {
  205. if (gAgentCamera.cameraCustomizeAvatar() && gSavedSettings.getBOOL("AppearanceCameraMovement"))
  206. {
  207. gAgentCamera.changeCameraToDefault();
  208. gAgentCamera.resetView();
  209. }
  210. }
  211. }
  212. void LLSidepanelAppearance::onFilterEdit(const std::string& search_string)
  213. {
  214. if (mFilterSubString != search_string)
  215. {
  216. mFilterSubString = search_string;
  217. // Searches are case-insensitive
  218. // but we don't convert the typed string to upper-case so that it can be fed to the web search as-is.
  219. mPanelOutfitsInventory->onSearchEdit(mFilterSubString);
  220. }
  221. }
  222. void LLSidepanelAppearance::onOpenOutfitButtonClicked()
  223. {
  224. const LLViewerInventoryItem *outfit_link = LLAppearanceMgr::getInstance()->getBaseOutfitLink();
  225. if (!outfit_link)
  226. return;
  227. if (!outfit_link->getIsLinkType())
  228. return;
  229. LLAccordionCtrlTab* tab_outfits = mPanelOutfitsInventory->findChild<LLAccordionCtrlTab>("tab_outfits");
  230. if (tab_outfits)
  231. {
  232. tab_outfits->changeOpenClose(FALSE);
  233. LLInventoryPanel *inventory_panel = tab_outfits->findChild<LLInventoryPanel>("outfitslist_tab");
  234. if (inventory_panel)
  235. {
  236. LLFolderView* root = inventory_panel->getRootFolder();
  237. LLFolderViewItem *outfit_folder = root->getItemByID(outfit_link->getLinkedUUID());
  238. if (outfit_folder)
  239. {
  240. outfit_folder->setOpen(!outfit_folder->isOpen());
  241. root->setSelectionFromRoot(outfit_folder,TRUE);
  242. root->scrollToShowSelection();
  243. }
  244. }
  245. }
  246. }
  247. // *TODO: obsolete?
  248. void LLSidepanelAppearance::onEditAppearanceButtonClicked()
  249. {
  250. if (gAgentWearables.areWearablesLoaded())
  251. {
  252. gAgentCamera.changeCameraToCustomizeAvatar();
  253. }
  254. }
  255. void LLSidepanelAppearance::onNewOutfitButtonClicked()
  256. {
  257. if (!mOutfitEdit->getVisible())
  258. {
  259. mPanelOutfitsInventory->onSave();
  260. }
  261. }
  262. void LLSidepanelAppearance::showOutfitsInventoryPanel()
  263. {
  264. toggleWearableEditPanel(FALSE);
  265. toggleOutfitEditPanel(FALSE);
  266. toggleMyOutfitsPanel(TRUE);
  267. }
  268. void LLSidepanelAppearance::showOutfitEditPanel()
  269. {
  270. if (mOutfitEdit && mOutfitEdit->getVisible()) return;
  271. // Accordion's state must be reset in all cases except the one when user
  272. // is returning back to the mOutfitEdit panel from the mEditWearable panel.
  273. // The simplest way to control this is to check the visibility state of the mEditWearable
  274. // BEFORE it is changed by the call to the toggleWearableEditPanel(FALSE, NULL, TRUE).
  275. if (mEditWearable != NULL && !mEditWearable->getVisible() && mOutfitEdit != NULL)
  276. {
  277. mOutfitEdit->resetAccordionState();
  278. }
  279. // If we're exiting the edit wearable view, and the camera was not focused on the avatar
  280. // (e.g. such as if we were editing a physics param), then skip the outfits edit mode since
  281. // otherwise this would trigger the camera focus mode.
  282. if (mEditWearable != NULL && mEditWearable->getVisible() && !gAgentCamera.cameraCustomizeAvatar())
  283. {
  284. showOutfitsInventoryPanel();
  285. return;
  286. }
  287. toggleMyOutfitsPanel(FALSE);
  288. toggleWearableEditPanel(FALSE, NULL, TRUE); // don't switch out of edit appearance mode
  289. toggleOutfitEditPanel(TRUE);
  290. }
  291. void LLSidepanelAppearance::showWearableEditPanel(LLWearable *wearable /* = NULL*/, BOOL disable_camera_switch)
  292. {
  293. toggleMyOutfitsPanel(FALSE);
  294. toggleOutfitEditPanel(FALSE, TRUE); // don't switch out of edit appearance mode
  295. toggleWearableEditPanel(TRUE, wearable, disable_camera_switch);
  296. }
  297. void LLSidepanelAppearance::toggleMyOutfitsPanel(BOOL visible)
  298. {
  299. if (!mPanelOutfitsInventory || mPanelOutfitsInventory->getVisible() == visible)
  300. {
  301. // visibility isn't changing, hence nothing to do
  302. return;
  303. }
  304. mPanelOutfitsInventory->setVisible(visible);
  305. // *TODO: Move these controls to panel_outfits_inventory.xml
  306. // so that we don't need to toggle them explicitly.
  307. mFilterEditor->setVisible(visible);
  308. mNewOutfitBtn->setVisible(visible);
  309. mCurrOutfitPanel->setVisible(visible);
  310. if (visible)
  311. {
  312. mPanelOutfitsInventory->onOpen(LLSD());
  313. }
  314. }
  315. void LLSidepanelAppearance::toggleOutfitEditPanel(BOOL visible, BOOL disable_camera_switch)
  316. {
  317. if (!mOutfitEdit || mOutfitEdit->getVisible() == visible)
  318. {
  319. // visibility isn't changing, hence nothing to do
  320. return;
  321. }
  322. mOutfitEdit->setVisible(visible);
  323. if (visible)
  324. {
  325. mOutfitEdit->onOpen(LLSD());
  326. if (!disable_camera_switch && gSavedSettings.getBOOL("AppearanceCameraMovement") )
  327. {
  328. gAgentCamera.changeCameraToCustomizeAvatar();
  329. }
  330. }
  331. else if (!disable_camera_switch && gSavedSettings.getBOOL("AppearanceCameraMovement") )
  332. {
  333. gAgentCamera.changeCameraToDefault();
  334. gAgentCamera.resetView();
  335. }
  336. }
  337. void LLSidepanelAppearance::toggleWearableEditPanel(BOOL visible, LLWearable *wearable, BOOL disable_camera_switch)
  338. {
  339. if (!mEditWearable || mEditWearable->getVisible() == visible)
  340. {
  341. // visibility isn't changing, hence nothing to do
  342. return;
  343. }
  344. if (!wearable)
  345. {
  346. wearable = gAgentWearables.getWearable(LLWearableType::WT_SHAPE, 0);
  347. }
  348. if (!wearable)
  349. {
  350. return;
  351. }
  352. // Toggle panel visibility.
  353. mEditWearable->setVisible(visible);
  354. if (visible)
  355. {
  356. if (!disable_camera_switch && gSavedSettings.getBOOL("AppearanceCameraMovement") )
  357. {
  358. gAgentCamera.changeCameraToCustomizeAvatar();
  359. }
  360. mEditWearable->setWearable(wearable, disable_camera_switch);
  361. mEditWearable->onOpen(LLSD()); // currently no-op, just for consistency
  362. }
  363. else
  364. {
  365. // Save changes if closing.
  366. mEditWearable->saveChanges();
  367. if (!disable_camera_switch && gSavedSettings.getBOOL("AppearanceCameraMovement") )
  368. {
  369. gAgentCamera.changeCameraToDefault();
  370. gAgentCamera.resetView();
  371. }
  372. }
  373. }
  374. void LLSidepanelAppearance::refreshCurrentOutfitName(const std::string& name)
  375. {
  376. // Set current outfit status (wearing/unsaved).
  377. bool dirty = LLAppearanceMgr::getInstance()->isOutfitDirty();
  378. std::string cof_status_str = getString(dirty ? "Unsaved Changes" : "Now Wearing");
  379. mOutfitStatus->setText(cof_status_str);
  380. if (name == "")
  381. {
  382. std::string outfit_name;
  383. if (LLAppearanceMgr::getInstance()->getBaseOutfitName(outfit_name))
  384. {
  385. mCurrentLookName->setText(outfit_name);
  386. return;
  387. }
  388. std::string string_name = gAgentWearables.isCOFChangeInProgress() ? "Changing outfits" : "No Outfit";
  389. mCurrentLookName->setText(getString(string_name));
  390. mOpenOutfitBtn->setEnabled(FALSE);
  391. }
  392. else
  393. {
  394. mCurrentLookName->setText(name);
  395. // Can't just call update verbs since the folder link may not have been created yet.
  396. mOpenOutfitBtn->setEnabled(TRUE);
  397. }
  398. }
  399. //static
  400. void LLSidepanelAppearance::editWearable(LLWearable *wearable, LLView *data, BOOL disable_camera_switch)
  401. {
  402. LLFloaterSidePanelContainer::showPanel("appearance", LLSD());
  403. LLSidepanelAppearance *panel = dynamic_cast<LLSidepanelAppearance*>(data);
  404. if (panel)
  405. {
  406. panel->showWearableEditPanel(wearable, disable_camera_switch);
  407. }
  408. }
  409. // Fetch currently worn items and only enable the New Look button after everything's been
  410. // fetched. Alternatively, we could stuff this logic into llagentwearables::makeNewOutfitLinks.
  411. void LLSidepanelAppearance::fetchInventory()
  412. {
  413. mNewOutfitBtn->setEnabled(false);
  414. uuid_vec_t ids;
  415. LLUUID item_id;
  416. for(S32 type = (S32)LLWearableType::WT_SHAPE; type < (S32)LLWearableType::WT_COUNT; ++type)
  417. {
  418. for (U32 index = 0; index < gAgentWearables.getWearableCount((LLWearableType::EType)type); ++index)
  419. {
  420. item_id = gAgentWearables.getWearableItemID((LLWearableType::EType)type, index);
  421. if(item_id.notNull())
  422. {
  423. ids.push_back(item_id);
  424. }
  425. }
  426. }
  427. if (isAgentAvatarValid())
  428. {
  429. for (LLVOAvatar::attachment_map_t::const_iterator iter = gAgentAvatarp->mAttachmentPoints.begin();
  430. iter != gAgentAvatarp->mAttachmentPoints.end(); ++iter)
  431. {
  432. LLViewerJointAttachment* attachment = iter->second;
  433. if (!attachment) continue;
  434. for (LLViewerJointAttachment::attachedobjs_vec_t::iterator attachment_iter = attachment->mAttachedObjects.begin();
  435. attachment_iter != attachment->mAttachedObjects.end();
  436. ++attachment_iter)
  437. {
  438. LLViewerObject* attached_object = (*attachment_iter);
  439. if (!attached_object) continue;
  440. const LLUUID& item_id = attached_object->getAttachmentItemID();
  441. if (item_id.isNull()) continue;
  442. ids.push_back(item_id);
  443. }
  444. }
  445. }
  446. LLCurrentlyWornFetchObserver *fetch_worn = new LLCurrentlyWornFetchObserver(ids, this);
  447. fetch_worn->startFetch();
  448. // If no items to be fetched, done will never be triggered.
  449. // TODO: Change LLInventoryFetchItemsObserver::fetchItems to trigger done() on this condition.
  450. if (fetch_worn->isFinished())
  451. {
  452. fetch_worn->done();
  453. }
  454. else
  455. {
  456. gInventory.addObserver(fetch_worn);
  457. }
  458. }
  459. void LLSidepanelAppearance::inventoryFetched()
  460. {
  461. mNewOutfitBtn->setEnabled(true);
  462. }
  463. void LLSidepanelAppearance::setWearablesLoading(bool val)
  464. {
  465. getChildView("wearables_loading_indicator")->setVisible( val);
  466. getChildView("edit_outfit_btn")->setVisible( !val);
  467. if (!val)
  468. {
  469. // refresh outfit name when COF is already changed.
  470. refreshCurrentOutfitName();
  471. }
  472. }
  473. void LLSidepanelAppearance::showDefaultSubpart()
  474. {
  475. if (mEditWearable->getVisible())
  476. {
  477. mEditWearable->showDefaultSubpart();
  478. }
  479. }
  480. void LLSidepanelAppearance::updateScrollingPanelList()
  481. {
  482. if (mEditWearable->getVisible())
  483. {
  484. mEditWearable->updateScrollingPanelList();
  485. }
  486. }