PageRenderTime 41ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

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