From 9ad26f5e8f712c1989cc8749c8bfa6a867cc9e50 Mon Sep 17 00:00:00 2001 From: Vadim Savchuk Date: Wed, 9 Jun 2010 14:25:22 +0300 Subject: EXT-7611 FIXED Enabled the "Create new [TYPE]" context menu item for non-worn items in the outfit editor. Reviewed by Nyx at https://codereview.productengine.com/secondlife/r/535/ --HG-- branch : product-engine --- indra/newview/llcofwearables.cpp | 90 +++++++++++++++++++++++++++++++++------- 1 file changed, 74 insertions(+), 16 deletions(-) (limited to 'indra/newview/llcofwearables.cpp') diff --git a/indra/newview/llcofwearables.cpp b/indra/newview/llcofwearables.cpp index 916d53da3c..611396b0e5 100644 --- a/indra/newview/llcofwearables.cpp +++ b/indra/newview/llcofwearables.cpp @@ -58,13 +58,19 @@ static const LLWearableItemNameComparator WEARABLE_NAME_COMPARATOR; class CofContextMenu : public LLListContextMenu { protected: - static void updateCreateWearableLabel(LLMenuGL* menu, const LLUUID& item_id) + CofContextMenu(LLCOFWearables* cof_wearables) + : mCOFWearables(cof_wearables) + { + llassert(mCOFWearables); + } + + void updateCreateWearableLabel(LLMenuGL* menu, const LLUUID& item_id) { LLMenuItemGL* menu_item = menu->getChild("create_new"); + LLWearableType::EType w_type = getWearableType(item_id); // Hide the "Create new " if it's irrelevant. - LLViewerInventoryItem* item = gInventory.getLinkedItem(item_id); - if (!item || !item->isWearableType()) + if (w_type == LLWearableType::WT_NONE) { menu_item->setVisible(FALSE); return; @@ -72,25 +78,67 @@ protected: // Set proper label for the "Create new " menu item. LLStringUtil::format_map_t args; - LLWearableType::EType w_type = item->getWearableType(); args["[WEARABLE_TYPE]"] = LLWearableType::getTypeDefaultNewName(w_type); std::string new_label = LLTrans::getString("CreateNewWearable", args); menu_item->setLabel(new_label); } - static void createNew(const LLUUID& item_id) + void createNew(const LLUUID& item_id) { - LLViewerInventoryItem* item = gInventory.getLinkedItem(item_id); - if (!item || !item->isWearableType()) return; + LLAgentWearables::createWearable(getWearableType(item_id), true); + } + + // Get wearable type of the given item. + // + // There is a special case: so-called "dummy items" + // (i.e. the ones that are there just to indicate that you're not wearing + // any wearables of the corresponding type. They are currently grayed out + // and suffixed with "not worn"). + // Those items don't have an UUID, but they do have an associated wearable type. + // If the user has invoked context menu for such item, + // we ignore the passed item_id and retrieve wearable type from the item. + LLWearableType::EType getWearableType(const LLUUID& item_id) + { + if (!isDummyItem(item_id)) + { + LLViewerInventoryItem* item = gInventory.getLinkedItem(item_id); + if (item && item->isWearableType()) + { + return item->getWearableType(); + } + } + else if (mCOFWearables) // dummy item selected + { + LLPanelDummyClothingListItem* item; + + item = dynamic_cast(mCOFWearables->getSelectedItem()); + if (item) + { + return item->getWearableType(); + } + } + + return LLWearableType::WT_NONE; + } - LLAgentWearables::createWearable(item->getWearableType(), true); + static bool isDummyItem(const LLUUID& item_id) + { + return item_id.isNull(); } + + LLCOFWearables* mCOFWearables; }; ////////////////////////////////////////////////////////////////////////// -class CofAttachmentContextMenu : public LLListContextMenu +class CofAttachmentContextMenu : public CofContextMenu { +public: + CofAttachmentContextMenu(LLCOFWearables* cof_wearables) + : CofContextMenu(cof_wearables) + { + } + protected: /*virtual*/ LLContextMenu* createMenu() @@ -108,8 +156,13 @@ protected: class CofClothingContextMenu : public CofContextMenu { -protected: +public: + CofClothingContextMenu(LLCOFWearables* cof_wearables) + : CofContextMenu(cof_wearables) + { + } +protected: /*virtual*/ LLContextMenu* createMenu() { LLUICtrl::CommitCallbackRegistry::ScopedRegistrar registrar; @@ -121,7 +174,7 @@ protected: registrar.add("Clothing.MoveUp", boost::bind(moveWearable, selected_id, false)); registrar.add("Clothing.MoveDown", boost::bind(moveWearable, selected_id, true)); registrar.add("Clothing.Edit", boost::bind(LLAgentWearables::editWearable, selected_id)); - registrar.add("Clothing.Create", boost::bind(createNew, selected_id)); + registrar.add("Clothing.Create", boost::bind(&CofClothingContextMenu::createNew, this, selected_id)); enable_registrar.add("Clothing.OnEnable", boost::bind(&CofClothingContextMenu::onEnable, this, _2)); @@ -171,8 +224,13 @@ protected: class CofBodyPartContextMenu : public CofContextMenu { -protected: +public: + CofBodyPartContextMenu(LLCOFWearables* cof_wearables) + : CofContextMenu(cof_wearables) + { + } +protected: /*virtual*/ LLContextMenu* createMenu() { LLUICtrl::CommitCallbackRegistry::ScopedRegistrar registrar; @@ -184,7 +242,7 @@ protected: LLPanelOutfitEdit* panel_oe = dynamic_cast(LLSideTray::getInstance()->getPanel("panel_outfit_edit")); registrar.add("BodyPart.Replace", boost::bind(&LLPanelOutfitEdit::onReplaceBodyPartMenuItemClicked, panel_oe, selected_id)); registrar.add("BodyPart.Edit", boost::bind(LLAgentWearables::editWearable, selected_id)); - registrar.add("BodyPart.Create", boost::bind(createNew, selected_id)); + registrar.add("BodyPart.Create", boost::bind(&CofBodyPartContextMenu::createNew, this, selected_id)); enable_registrar.add("BodyPart.OnEnable", boost::bind(&CofBodyPartContextMenu::onEnable, this, _2)); @@ -219,9 +277,9 @@ LLCOFWearables::LLCOFWearables() : LLPanel(), mBodyParts(NULL), mLastSelectedList(NULL) { - mClothingMenu = new CofClothingContextMenu(); - mAttachmentMenu = new CofAttachmentContextMenu(); - mBodyPartMenu = new CofBodyPartContextMenu(); + mClothingMenu = new CofClothingContextMenu(this); + mAttachmentMenu = new CofAttachmentContextMenu(this); + mBodyPartMenu = new CofBodyPartContextMenu(this); }; LLCOFWearables::~LLCOFWearables() -- cgit v1.2.3