diff options
Diffstat (limited to 'indra/newview/llpaneloutfitsinventory.cpp')
-rw-r--r-- | indra/newview/llpaneloutfitsinventory.cpp | 238 |
1 files changed, 201 insertions, 37 deletions
diff --git a/indra/newview/llpaneloutfitsinventory.cpp b/indra/newview/llpaneloutfitsinventory.cpp index 59c1fb4f3c..8b451c156c 100644 --- a/indra/newview/llpaneloutfitsinventory.cpp +++ b/indra/newview/llpaneloutfitsinventory.cpp @@ -42,6 +42,7 @@ #include "llfloaterworldmap.h" #include "llfloaterinventory.h" #include "llfoldervieweventlistener.h" +#include "llinventorybridge.h" #include "llinventoryfunctions.h" #include "llinventorymodelbackgroundfetch.h" #include "llinventorypanel.h" @@ -49,7 +50,9 @@ #include "lllineeditor.h" #include "llmodaldialog.h" #include "llnotificationsutil.h" +#include "lloutfitobserver.h" #include "lloutfitslist.h" +#include "llsaveoutfitcombobtn.h" #include "llsidepanelappearance.h" #include "llsidetray.h" #include "lltabcontainer.h" @@ -69,18 +72,149 @@ static const std::string COF_TAB_NAME = "cof_tab"; static LLRegisterPanelClassWrapper<LLPanelOutfitsInventory> t_inventory("panel_outfits_inventory"); +class LLOutfitListGearMenu +{ +public: + LLOutfitListGearMenu(LLOutfitsList* olist) + : mOutfitList(olist), + mMenu(NULL) + { + llassert_always(mOutfitList); + + LLUICtrl::CommitCallbackRegistry::ScopedRegistrar registrar; + LLUICtrl::EnableCallbackRegistry::ScopedRegistrar enable_registrar; + + registrar.add("Gear.Wear", boost::bind(&LLOutfitListGearMenu::onWear, this)); + registrar.add("Gear.TakeOff", boost::bind(&LLOutfitListGearMenu::onTakeOff, this)); + registrar.add("Gear.Rename", boost::bind(&LLOutfitListGearMenu::onRename, this)); + registrar.add("Gear.Delete", boost::bind(&LLOutfitListGearMenu::onDelete, this)); + registrar.add("Gear.Create", boost::bind(&LLOutfitListGearMenu::onCreate, this, _2)); + + enable_registrar.add("Gear.OnEnable", boost::bind(&LLOutfitListGearMenu::onEnable, this, _2)); + + mMenu = LLUICtrlFactory::getInstance()->createFromFile<LLMenuGL>( + "menu_outfit_gear.xml", gMenuHolder, LLViewerMenuHolderGL::child_registry_t::instance()); + llassert(mMenu); + } + + LLMenuGL* getMenu() { return mMenu; } + +private: + const LLUUID& getSelectedOutfitID() + { + return mOutfitList->getSelectedOutfitUUID(); + } + + LLViewerInventoryCategory* getSelectedOutfit() + { + const LLUUID& selected_outfit_id = getSelectedOutfitID(); + if (selected_outfit_id.isNull()) + { + return NULL; + } + + LLViewerInventoryCategory* cat = gInventory.getCategory(selected_outfit_id); + return cat; + } + + void onWear() + { + LLViewerInventoryCategory* selected_outfit = getSelectedOutfit(); + if (selected_outfit) + { + LLAppearanceMgr::instance().wearInventoryCategory( + selected_outfit, /*copy=*/ FALSE, /*append=*/ FALSE); + } + } + + void onTakeOff() + { + const LLUUID& selected_outfit_id = getSelectedOutfitID(); + if (selected_outfit_id.notNull()) + { + LLAppearanceMgr::instance().takeOffOutfit(selected_outfit_id); + } + } + + void onRename() + { + const LLUUID& selected_outfit_id = getSelectedOutfitID(); + if (selected_outfit_id.notNull()) + { + LLAppearanceMgr::instance().renameOutfit(selected_outfit_id); + } + } + + void onDelete() + { + const LLUUID& selected_outfit_id = getSelectedOutfitID(); + if (selected_outfit_id.notNull()) + { + remove_category(&gInventory, selected_outfit_id); + } + } + + void onCreate(const LLSD& data) + { + LLWearableType::EType type = LLWearableType::typeNameToType(data.asString()); + if (type == LLWearableType::WT_NONE) + { + llwarns << "Invalid wearable type" << llendl; + return; + } + + LLAgentWearables::createWearable(type, true); + } + + bool onEnable(LLSD::String param) + { + const LLUUID& selected_outfit_id = getSelectedOutfitID(); + bool is_worn = LLAppearanceMgr::instance().getBaseOutfitUUID() == selected_outfit_id; + + if ("wear" == param) + { + return !is_worn; + } + else if ("take_off" == param) + { + return is_worn; + } + else if ("rename" == param) + { + return get_is_category_renameable(&gInventory, selected_outfit_id); + } + else if ("delete" == param) + { + return LLAppearanceMgr::instance().getCanRemoveOutfit(selected_outfit_id); + } + + return true; + } + + LLOutfitsList* mOutfitList; + LLMenuGL* mMenu; +}; LLPanelOutfitsInventory::LLPanelOutfitsInventory() : mMyOutfitsPanel(NULL), mCurrentOutfitPanel(NULL), - mParent(NULL) + mParent(NULL), + mGearMenu(NULL), + mInitialized(false) { mSavedFolderState = new LLSaveFolderState(); mSavedFolderState->setApply(FALSE); + gAgentWearables.addLoadedCallback(boost::bind(&LLPanelOutfitsInventory::onWearablesLoaded, this)); + + LLOutfitObserver& observer = LLOutfitObserver::instance(); + observer.addBOFChangedCallback(boost::bind(&LLPanelOutfitsInventory::updateVerbs, this)); + observer.addCOFChangedCallback(boost::bind(&LLPanelOutfitsInventory::updateVerbs, this)); + observer.addOutfitLockChangedCallback(boost::bind(&LLPanelOutfitsInventory::updateVerbs, this)); } LLPanelOutfitsInventory::~LLPanelOutfitsInventory() { + delete mGearMenu; delete mSavedFolderState; } @@ -90,12 +224,35 @@ BOOL LLPanelOutfitsInventory::postBuild() initTabPanels(); initListCommandsHandlers(); + // Fetch your outfits folder so that the links are in memory. + // ( This is only necessary if we want to show a warning if a user deletes an item that has a + // a link in an outfit, see "ConfirmItemDeleteHasLinks". ) + const LLUUID &outfits_cat = gInventory.findCategoryUUIDForType(LLFolderType::FT_OUTFIT, false); + if (outfits_cat.notNull()) + { + LLInventoryModelBackgroundFetch::instance().start(outfits_cat); + } + + mSaveComboBtn.reset(new LLSaveOutfitComboBtn(this, true)); + return TRUE; } // virtual void LLPanelOutfitsInventory::onOpen(const LLSD& key) { + if (!mInitialized) + { + LLSidepanelAppearance* panel_appearance = getAppearanceSP(); + if (panel_appearance) + { + // *TODO: move these methods to LLPanelOutfitsInventory? + panel_appearance->fetchInventory(); + panel_appearance->refreshCurrentOutfitName(); + } + mInitialized = true; + } + // Make sure we know which tab is selected, update the filter, // and update verbs. onTabChange(); @@ -124,11 +281,6 @@ void LLPanelOutfitsInventory::onOpen(const LLSD& key) void LLPanelOutfitsInventory::updateVerbs() { - if (mParent) - { - mParent->updateVerbs(); - } - if (mListCommands) { updateListCommands(); @@ -190,6 +342,7 @@ void LLPanelOutfitsInventory::onWearButtonClick() if (!isCOFPanelActive()) { mMyOutfitsPanel->performAction("replaceoutfit"); + setWearablesLoading(true); } else { @@ -243,8 +396,7 @@ bool LLPanelOutfitsInventory::onSaveCommit(const LLSD& notification, const LLSD& { LLUUID outfit_folder = LLAppearanceMgr::getInstance()->makeNewOutfitLinks(outfit_name); - LLSidepanelAppearance* panel_appearance = - dynamic_cast<LLSidepanelAppearance *>(LLSideTray::getInstance()->getPanel("sidepanel_appearance")); + LLSidepanelAppearance* panel_appearance = getAppearanceSP(); if (panel_appearance) { panel_appearance->showOutfitsInventoryPanel(); @@ -353,9 +505,8 @@ void LLPanelOutfitsInventory::initListCommandsHandlers() { mListCommands = getChild<LLPanel>("bottom_panel"); - mListCommands->childSetAction("options_gear_btn", boost::bind(&LLPanelOutfitsInventory::onGearButtonClick, this)); + mListCommands->childSetAction("options_gear_btn", boost::bind(&LLPanelOutfitsInventory::showGearMenu, this)); mListCommands->childSetAction("trash_btn", boost::bind(&LLPanelOutfitsInventory::onTrashButtonClick, this)); - mListCommands->childSetAction("make_outfit_btn", boost::bind(&LLPanelOutfitsInventory::onAddButtonClick, this)); mListCommands->childSetAction("wear_btn", boost::bind(&LLPanelOutfitsInventory::onWearButtonClick, this)); LLDragAndDropButton* trash_btn = mListCommands->getChild<LLDragAndDropButton>("trash_btn"); @@ -365,42 +516,29 @@ void LLPanelOutfitsInventory::initListCommandsHandlers() , _7 // EAcceptance* accept )); - mCommitCallbackRegistrar.add("panel_outfits_inventory_gear_default.Custom.Action", - boost::bind(&LLPanelOutfitsInventory::onCustomAction, this, _2)); - mEnableCallbackRegistrar.add("panel_outfits_inventory_gear_default.Enable", - boost::bind(&LLPanelOutfitsInventory::isActionEnabled, this, _2)); - mMenuGearDefault = LLUICtrlFactory::getInstance()->createFromFile<LLMenuGL>("panel_outfits_inventory_gear_default.xml", gMenuHolder, LLViewerMenuHolderGL::child_registry_t::instance()); + mGearMenu = new LLOutfitListGearMenu(mMyOutfitsPanel); } void LLPanelOutfitsInventory::updateListCommands() { bool trash_enabled = isActionEnabled("delete"); bool wear_enabled = isActionEnabled("wear"); - bool make_outfit_enabled = isActionEnabled("make_outfit"); + bool make_outfit_enabled = isActionEnabled("save_outfit"); mListCommands->childSetEnabled("trash_btn", trash_enabled); mListCommands->childSetEnabled("wear_btn", wear_enabled); mListCommands->childSetVisible("wear_btn", wear_enabled); - mListCommands->childSetEnabled("make_outfit_btn", make_outfit_enabled); -} - -void LLPanelOutfitsInventory::onGearButtonClick() -{ - showActionMenu(mMenuGearDefault,"options_gear_btn"); + mSaveComboBtn->setMenuItemEnabled("save_outfit", make_outfit_enabled); } -void LLPanelOutfitsInventory::onAddButtonClick() -{ - onSave(); -} - -void LLPanelOutfitsInventory::showActionMenu(LLMenuGL* menu, std::string spawning_view_name) +void LLPanelOutfitsInventory::showGearMenu() { + LLMenuGL* menu = mGearMenu ? mGearMenu->getMenu() : NULL; if (menu) { menu->buildDrawLabels(); menu->updateParent(LLMenuGL::sMenuContainer); - LLView* spawning_view = getChild<LLView> (spawning_view_name); + LLView* spawning_view = getChild<LLView>("options_gear_btn"); S32 menu_x, menu_y; //show menu in co-ordinates of panel spawning_view->localPointToOtherView(0, spawning_view->getRect().getHeight(), &menu_x, &menu_y, this); @@ -482,8 +620,7 @@ BOOL LLPanelOutfitsInventory::isActionEnabled(const LLSD& userdata) LLFolderView* root = getActivePanel()->getRootFolder(); if (root) { - std::set<LLUUID> selection_set; - root->getSelectionList(selection_set); + std::set<LLUUID> selection_set = root->getSelectionList(); can_delete = (selection_set.size() > 0); for (std::set<LLUUID>::iterator iter = selection_set.begin(); iter != selection_set.end(); @@ -504,8 +641,7 @@ BOOL LLPanelOutfitsInventory::isActionEnabled(const LLSD& userdata) LLFolderView* root = getActivePanel()->getRootFolder(); if (root) { - std::set<LLUUID> selection_set; - root->getSelectionList(selection_set); + std::set<LLUUID> selection_set = root->getSelectionList(); can_delete = (selection_set.size() > 0); for (std::set<LLUUID>::iterator iter = selection_set.begin(); iter != selection_set.end(); @@ -533,9 +669,12 @@ BOOL LLPanelOutfitsInventory::isActionEnabled(const LLSD& userdata) return FALSE; } } - if (command_name == "make_outfit") + if (command_name == "save_outfit") { - return TRUE; + 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; } if (command_name == "edit" || @@ -557,8 +696,7 @@ bool LLPanelOutfitsInventory::hasItemsSelected() LLFolderView* root = getActivePanel()->getRootFolder(); if (root) { - std::set<LLUUID> selection_set; - root->getSelectionList(selection_set); + std::set<LLUUID> selection_set = root->getSelectionList(); has_items_selected = (selection_set.size() > 0); } } @@ -623,6 +761,7 @@ void LLPanelOutfitsInventory::onTabChange() else { mMyOutfitsPanel->setFilterSubString(mFilterSubString); + mMyOutfitsPanel->onOpen(LLSD()); } updateVerbs(); @@ -642,3 +781,28 @@ BOOL LLPanelOutfitsInventory::isCOFPanelActive() const { return (childGetVisibleTab("appearance_tabs")->getName() == COF_TAB_NAME); } + +void LLPanelOutfitsInventory::setWearablesLoading(bool val) +{ + mListCommands->childSetEnabled("wear_btn", !val); + + llassert(mParent); + if (mParent) + { + mParent->setWearablesLoading(val); + } +} + +void LLPanelOutfitsInventory::onWearablesLoaded() +{ + setWearablesLoading(false); +} + +// static +LLSidepanelAppearance* LLPanelOutfitsInventory::getAppearanceSP() +{ + static LLSidepanelAppearance* panel_appearance = + dynamic_cast<LLSidepanelAppearance*> + (LLSideTray::getInstance()->getPanel("sidepanel_appearance")); + return panel_appearance; +} |