PageRenderTime 38ms CodeModel.GetById 2ms app.highlight 31ms RepoModel.GetById 1ms app.codeStats 1ms

/indra/newview/llviewerattachmenu.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 133 lines | 86 code | 14 blank | 33 comment | 24 complexity | e22ad1d22dc4cc112a4055ea58a4ea21 MD5 | raw file
  1/** 
  2 * @file llviewerattachmenu.cpp
  3 * @brief "Attach to" / "Attach to HUD" submenus.
  4 *
  5 * $LicenseInfo:firstyear=2010&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
 29#include "llviewerattachmenu.h"
 30
 31// project includes
 32#include "llagent.h"
 33#include "llinventorybridge.h" // for rez_attachment()
 34#include "llinventorymodel.h"
 35#include "llviewerinventory.h"
 36#include "llviewermenu.h" // for gMenuHolder
 37#include "llvoavatarself.h"
 38
 39// linden libraries
 40#include "llmenugl.h"
 41#include "lltrans.h"
 42
 43// static
 44void LLViewerAttachMenu::populateMenus(const std::string& attach_to_menu_name, const std::string& attach_to_hud_menu_name)
 45{
 46	// *TODO: share this code with other similar menus
 47	// (inventory panel context menu, in-world object menu).
 48
 49	if (attach_to_menu_name.empty() || attach_to_hud_menu_name.empty() || !isAgentAvatarValid()) return;
 50
 51	LLContextMenu* attach_menu = gMenuHolder->getChild<LLContextMenu>(attach_to_menu_name);
 52	LLContextMenu* attach_hud_menu = gMenuHolder->getChild<LLContextMenu>(attach_to_hud_menu_name);
 53
 54	if (!attach_menu || attach_menu->getChildCount() != 0 ||
 55		!attach_hud_menu || attach_hud_menu->getChildCount() != 0)
 56	{
 57		return;
 58	}
 59
 60	// Populate "Attach to..." / "Attach to HUD..." submenus.
 61	for (LLVOAvatar::attachment_map_t::iterator iter = gAgentAvatarp->mAttachmentPoints.begin();
 62		 iter != gAgentAvatarp->mAttachmentPoints.end(); )
 63	{
 64		LLVOAvatar::attachment_map_t::iterator curiter = iter++;
 65		LLViewerJointAttachment* attachment = curiter->second;
 66		LLMenuItemCallGL::Params p;
 67		std::string submenu_name = attachment->getName();
 68		std::string translated_submenu_name;
 69
 70		if (LLTrans::findString(translated_submenu_name, submenu_name))
 71		{
 72			p.name = (" ") + translated_submenu_name + " ";
 73		}
 74		else
 75		{
 76			p.name = submenu_name;
 77		}
 78
 79		LLSD cbparams;
 80		cbparams["index"] = curiter->first;
 81		cbparams["label"] = p.name;
 82		p.on_click.function_name = "Object.Attach";
 83		p.on_click.parameter = LLSD(attachment->getName());
 84		p.on_enable.function_name = "Attachment.Label";
 85		p.on_enable.parameter = cbparams;
 86
 87		LLMenuItemCallGL* item = LLUICtrlFactory::create<LLMenuItemCallGL>(p);
 88		LLView* parent_menu = attachment->getIsHUDAttachment() ? attach_hud_menu : attach_menu;
 89		parent_menu->addChild(item);
 90	}
 91}
 92
 93// static
 94void LLViewerAttachMenu::attachObjects(const uuid_vec_t& items, const std::string& joint_name)
 95{
 96	LLViewerJointAttachment* attachmentp = NULL;
 97	for (LLVOAvatar::attachment_map_t::iterator iter = gAgentAvatarp->mAttachmentPoints.begin(); 
 98		 iter != gAgentAvatarp->mAttachmentPoints.end(); )
 99	{
100		LLVOAvatar::attachment_map_t::iterator curiter = iter++;
101		LLViewerJointAttachment* attachment = curiter->second;
102		if (attachment->getName() == joint_name)
103		{
104			attachmentp = attachment;
105			break;
106		}
107	}
108	if (attachmentp == NULL)
109	{
110		return;
111	}
112
113	for (uuid_vec_t::const_iterator it = items.begin(); it != items.end(); ++it)
114	{
115		const LLUUID &id = *it;
116		LLViewerInventoryItem* item = (LLViewerInventoryItem*)gInventory.getLinkedItem(id);
117		if(item && gInventory.isObjectDescendentOf(id, gInventory.getRootFolderID()))
118		{
119			rez_attachment(item, attachmentp); // don't replace if called from an "Attach To..." menu
120		}
121		else if(item && item->isFinished())
122		{
123			// must be in library. copy it to our inventory and put it on.
124			LLPointer<LLInventoryCallback> cb = new RezAttachmentCallback(attachmentp);
125			copy_inventory_item(gAgent.getID(),
126								item->getPermissions().getOwner(),
127								item->getUUID(),
128								LLUUID::null,
129								std::string(),
130								cb);
131		}
132	}
133}