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