summaryrefslogtreecommitdiff
path: root/indra/newview/llpanelwearing.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/llpanelwearing.cpp')
-rw-r--r--indra/newview/llpanelwearing.cpp209
1 files changed, 209 insertions, 0 deletions
diff --git a/indra/newview/llpanelwearing.cpp b/indra/newview/llpanelwearing.cpp
new file mode 100644
index 0000000000..8b1682b901
--- /dev/null
+++ b/indra/newview/llpanelwearing.cpp
@@ -0,0 +1,209 @@
+/**
+ * @file llpanelwearing.cpp
+ * @brief List of agent's worn items.
+ *
+ * $LicenseInfo:firstyear=2010&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (C) 2010, Linden Research, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
+ * $/LicenseInfo$
+ */
+
+#include "llviewerprecompiledheaders.h"
+
+#include "llpanelwearing.h"
+
+#include "llappearancemgr.h"
+#include "llinventorymodel.h"
+#include "llinventoryobserver.h"
+#include "llsidetray.h"
+#include "llviewermenu.h"
+#include "llwearableitemslist.h"
+
+// Context menu and Gear menu helper.
+static void edit_outfit()
+{
+ LLSideTray::getInstance()->showPanel("sidepanel_appearance", LLSD().with("type", "edit_outfit"));
+}
+
+//////////////////////////////////////////////////////////////////////////
+
+class LLWearingGearMenu
+{
+public:
+ LLWearingGearMenu()
+ : mMenu(NULL)
+ {
+ LLUICtrl::CommitCallbackRegistry::ScopedRegistrar registrar;
+
+ registrar.add("Gear.Edit", boost::bind(&edit_outfit));
+
+ mMenu = LLUICtrlFactory::getInstance()->createFromFile<LLMenuGL>(
+ "menu_wearing_gear.xml", gMenuHolder, LLViewerMenuHolderGL::child_registry_t::instance());
+ llassert(mMenu);
+ }
+
+ void show(LLView* spawning_view)
+ {
+ if (!mMenu) return;
+
+ mMenu->buildDrawLabels();
+ mMenu->updateParent(LLMenuGL::sMenuContainer);
+ S32 menu_x = 0;
+ S32 menu_y = spawning_view->getRect().getHeight() + mMenu->getRect().getHeight();
+ LLMenuGL::showPopup(spawning_view, mMenu, menu_x, menu_y);
+ }
+
+private:
+ LLMenuGL* mMenu;
+};
+
+//////////////////////////////////////////////////////////////////////////
+
+class LLWearingContextMenu : public LLListContextMenu
+{
+protected:
+ /* virtual */ LLContextMenu* createMenu()
+ {
+ LLUICtrl::CommitCallbackRegistry::ScopedRegistrar registrar;
+
+ registrar.add("Wearing.Edit", boost::bind(&edit_outfit));
+
+ return createFromFile("menu_wearing_tab.xml");
+ }
+};
+
+//////////////////////////////////////////////////////////////////////////
+
+std::string LLPanelAppearanceTab::sFilterSubString = LLStringUtil::null;
+
+static LLRegisterPanelClassWrapper<LLPanelWearing> t_panel_wearing("panel_wearing");
+
+LLPanelWearing::LLPanelWearing()
+ : LLPanelAppearanceTab()
+ , mCOFItemsList(NULL)
+ , mIsInitialized(false)
+{
+ mCategoriesObserver = new LLInventoryCategoriesObserver();
+
+ mGearMenu = new LLWearingGearMenu();
+ mContextMenu = new LLWearingContextMenu();
+}
+
+LLPanelWearing::~LLPanelWearing()
+{
+ delete mGearMenu;
+ delete mContextMenu;
+
+ if (gInventory.containsObserver(mCategoriesObserver))
+ {
+ gInventory.removeObserver(mCategoriesObserver);
+ delete mCategoriesObserver;
+ }
+}
+
+BOOL LLPanelWearing::postBuild()
+{
+ mCOFItemsList = getChild<LLWearableItemsList>("cof_items_list");
+ mCOFItemsList->setRightMouseDownCallback(boost::bind(&LLPanelWearing::onWearableItemsListRightClick, this, _1, _2, _3));
+
+ return TRUE;
+}
+
+//virtual
+void LLPanelWearing::onOpen(const LLSD& /*info*/)
+{
+ if (!mIsInitialized)
+ {
+ // *TODO: I'm not sure is this check necessary but it never match while developing.
+ if (!gInventory.isInventoryUsable())
+ return;
+
+ const LLUUID cof = gInventory.findCategoryUUIDForType(LLFolderType::FT_CURRENT_OUTFIT);
+
+ // *TODO: I'm not sure is this check necessary but it never match while developing.
+ LLViewerInventoryCategory* category = gInventory.getCategory(cof);
+ if (!category)
+ return;
+
+ gInventory.addObserver(mCategoriesObserver);
+
+ // Start observing changes in Current Outfit category.
+ mCategoriesObserver->addCategory(cof, boost::bind(&LLWearableItemsList::updateList, mCOFItemsList, cof));
+
+ // Fetch Current Outfit contents and refresh the list to display
+ // initially fetched items. If not all items are fetched now
+ // the observer will refresh the list as soon as the new items
+ // arrive.
+ category->fetch();
+
+ mCOFItemsList->updateList(cof);
+
+ mIsInitialized = true;
+ }
+}
+
+// virtual
+void LLPanelWearing::setFilterSubString(const std::string& string)
+{
+ sFilterSubString = string;
+ mCOFItemsList->setFilterSubString(sFilterSubString);
+}
+
+// virtual
+bool LLPanelWearing::isActionEnabled(const LLSD& userdata)
+{
+ const std::string command_name = userdata.asString();
+
+ if (command_name == "save_outfit")
+ {
+ bool outfit_locked = LLAppearanceMgr::getInstance()->isOutfitLocked();
+ bool outfit_dirty = LLAppearanceMgr::getInstance()->isOutfitDirty();
+ // allow save only if outfit isn't locked and is dirty
+ return !outfit_locked && outfit_dirty;
+ }
+ return false;
+}
+
+// virtual
+void LLPanelWearing::showGearMenu(LLView* spawning_view)
+{
+ if (!mGearMenu) return;
+ mGearMenu->show(spawning_view);
+}
+
+boost::signals2::connection LLPanelWearing::setSelectionChangeCallback(commit_callback_t cb)
+{
+ if (!mCOFItemsList) return boost::signals2::connection();
+
+ return mCOFItemsList->setCommitCallback(cb);
+}
+
+void LLPanelWearing::onWearableItemsListRightClick(LLUICtrl* ctrl, S32 x, S32 y)
+{
+ LLWearableItemsList* list = dynamic_cast<LLWearableItemsList*>(ctrl);
+ if (!list) return;
+
+ uuid_vec_t selected_uuids;
+
+ list->getSelectedUUIDs(selected_uuids);
+
+ mContextMenu->show(ctrl, selected_uuids, x, y);
+}
+
+// EOF