From e2be2beaf9a9b6bca19bdd4b36fc7adb681349e9 Mon Sep 17 00:00:00 2001 From: Armin Weatherwax Date: Thu, 26 Aug 2010 20:30:07 +0200 Subject: Katharine Berry: We can save inventory presets to inventory directly. How exciting. issues from porting: buttons need love --- linden/indra/newview/llfloaterwindlight.cpp | 82 +++++++++++++++++++++- linden/indra/newview/llfloaterwindlight.h | 8 ++- linden/indra/newview/llwlparammanager.cpp | 77 +++++++++++++++++++- linden/indra/newview/llwlparammanager.h | 5 +- linden/indra/newview/llwlparamset.h | 3 +- .../xui/en-us/floater_windlight_options.xml | 7 +- 6 files changed, 172 insertions(+), 10 deletions(-) (limited to 'linden/indra/newview') diff --git a/linden/indra/newview/llfloaterwindlight.cpp b/linden/indra/newview/llfloaterwindlight.cpp index 42adba8..8cdc634 100644 --- a/linden/indra/newview/llfloaterwindlight.cpp +++ b/linden/indra/newview/llfloaterwindlight.cpp @@ -50,6 +50,10 @@ #include "lltabcontainer.h" #include "llboost.h" +#include "llagent.h" +#include "llinventorymodel.h" +#include "llviewerinventory.h" + #include "v4math.h" #include "llviewerdisplay.h" #include "llviewercontrol.h" @@ -222,6 +226,7 @@ void LLFloaterWindLight::initCallbacks(void) { //childSetAction("WLLoadPreset", onLoadPreset, comboBox); childSetAction("WLNewPreset", onNewPreset, comboBox); childSetAction("WLSavePreset", onSavePreset, comboBox); + childSetAction("WLSaveNotecard", onSaveNotecard, comboBox); childSetAction("WLDeletePreset", onDeletePreset, comboBox); comboBox->setCommitCallback(onChangePresetName); @@ -837,6 +842,76 @@ void LLFloaterWindLight::onSavePreset(void* userData) LLNotifications::instance().add("WLSavePresetAlert", LLSD(), LLSD(), saveAlertCallback); } +class KVFloaterWindLightNotecardCreatedCallback : public LLInventoryCallback +{ +public: + void fire(const LLUUID& inv_item); +}; + +void LLFloaterWindLight::onSaveNotecard(void* userData) +{ + // get the name + LLComboBox* comboBox = sWindLight->getChild( + "WLPresetsCombo"); + + // don't save the empty name + if(comboBox->getSelectedItemLabel() == "") + { + return; + } + + // Check if this is already a notecard. + if(LLWLParamManager::instance()->mCurParams.mInventoryID.notNull()) + { + LLNotifications::instance().add("KittyWLSaveNotecardAlert", LLSD(), LLSD(), saveNotecardCallback); + } + else + { + // Make sure we have a ".wl" extension. + std::string name = comboBox->getSelectedItemLabel(); + if(name.length() > 2 && name.compare(name.length() - 3, 3, ".wl") != 0) + { + name += ".wl"; + } + LLPointer cb = new KVFloaterWindLightNotecardCreatedCallback(); + // Create a notecard and then save it. + create_inventory_item(gAgent.getID(), + gAgent.getSessionID(), + LLUUID::null, + LLTransactionID::tnull, + name, + "WindLight settings (Kitty Viewer compatible)", + LLAssetType::AT_NOTECARD, + LLInventoryType::IT_NOTECARD, + NOT_WEARABLE, + PERM_ITEM_UNRESTRICTED, + cb); + + } +} + +void KVFloaterWindLightNotecardCreatedCallback::fire(const LLUUID& inv_item) +{ + LLWLParamManager * param_mgr = LLWLParamManager::instance(); + param_mgr->setParamSet(param_mgr->mCurParams.mName, param_mgr->mCurParams); + param_mgr->mParamList[param_mgr->mCurParams.mName].mInventoryID = inv_item; + param_mgr->mCurParams.mInventoryID = inv_item; + LL_INFOS("WindLight") << "Created inventory item " << inv_item << LL_ENDL; + param_mgr->savePresetToNotecard(param_mgr->mCurParams.mName); +} + +bool LLFloaterWindLight::saveNotecardCallback(const LLSD& notification, const LLSD& response) +{ + S32 option = LLNotification::getSelectedOption(notification, response); + // if they choose save, do it. Otherwise, don't do anything + if(option == 0) + { + LLWLParamManager * param_mgr = LLWLParamManager::instance(); + param_mgr->setParamSet(param_mgr->mCurParams.mName, param_mgr->mCurParams); + param_mgr->savePresetToNotecard(param_mgr->mCurParams.mName); + } + return false; +} bool LLFloaterWindLight::saveAlertCallback(const LLSD& notification, const LLSD& response) { @@ -948,9 +1023,10 @@ void LLFloaterWindLight::onChangePresetName(LLUICtrl* ctrl, void * userData) { return; } - - LLWLParamManager::instance()->loadPreset( - combo_box->getSelectedValue().asString()); + //impfixme fix of an mystherious crash? : kittyviewer: if(!data.empty()) + // + LLWLParamManager::instance()->loadPreset(combo_box->getSelectedValue().asString()); + LL_INFOS("WindLight") << "Current inventory ID: " << LLWLParamManager::instance()->mCurParams.mInventoryID << LL_ENDL; sWindLight->syncMenu(); } diff --git a/linden/indra/newview/llfloaterwindlight.h b/linden/indra/newview/llfloaterwindlight.h index 23e3056..9656803 100644 --- a/linden/indra/newview/llfloaterwindlight.h +++ b/linden/indra/newview/llfloaterwindlight.h @@ -91,9 +91,15 @@ public: /// when user hits the load preset button static void onNewPreset(void* userData); - /// when user hits the save preset button + /// when user hits the save to file button static void onSavePreset(void* userData); + /// when user hits the save to inventory button + static void onSaveNotecard(void* userData); + + /// prompts a user when overwriting a preset notecard + static bool saveNotecardCallback(const LLSD& notification, const LLSD& response); + /// prompts a user when overwriting a preset static bool saveAlertCallback(const LLSD& notification, const LLSD& response); diff --git a/linden/indra/newview/llwlparammanager.cpp b/linden/indra/newview/llwlparammanager.cpp index 74fa8f3..b3c2b0b 100644 --- a/linden/indra/newview/llwlparammanager.cpp +++ b/linden/indra/newview/llwlparammanager.cpp @@ -67,6 +67,10 @@ #include "llmemorystream.h" #include "llnotify.h" #include "llagent.h" +#include "llinventorymodel.h" +#include "llviewerinventory.h" +#include "llviewerregion.h" +#include "llassetuploadresponders.h" #include "curl/curl.h" @@ -243,7 +247,7 @@ void LLWLParamManager::loadPresetNotecard(const std::string& name, const LLUUID& asset_id, LLAssetType::AT_NOTECARD, &loadWindlightNotecard, - (void*)name.c_str()); + (void*)&inv_id); } void LLWLParamManager::savePresets(const std::string & fileName) @@ -269,6 +273,63 @@ void LLWLParamManager::savePresets(const std::string & fileName) formatter->format(paramsData, presetsXML, LLSDFormatter::OPTIONS_PRETTY); presetsXML.close(); + + propagateParameters(); +} + +bool LLWLParamManager::savePresetToNotecard(const std::string & name) +{ + // make an empty llsd + LLSD paramsData(LLSD::emptyMap()); + + // fill it with LLSD windlight params + paramsData = mParamList[name].getAll(); + + // get some XML + std::ostringstream presetsXML; + LLPointer formatter = new LLSDXMLFormatter(); + formatter->format(paramsData, presetsXML, LLSDFormatter::OPTIONS_PRETTY); + + // Write it to a notecard + LLNotecard notecard; + notecard.setText(presetsXML.str()); + + LLInventoryItem *item = gInventory.getItem(mParamList[name].mInventoryID); + if(!item) + { + mParamList[name].mInventoryID = LLUUID::null; + return false; + } + std::string agent_url = gAgent.getRegion()->getCapability("UpdateNotecardAgentInventory"); + if(!agent_url.empty()) + { + LLTransactionID tid; + LLAssetID asset_id; + tid.generate(); + asset_id = tid.makeAssetID(gAgent.getSecureSessionID()); + + LLVFile file(gVFS, asset_id, LLAssetType::AT_NOTECARD, LLVFile::APPEND); + + std::ostringstream stream; + notecard.exportStream(stream); + std::string buffer = stream.str(); + + S32 size = buffer.length() + 1; + file.setMaxSize(size); + file.write((U8*)buffer.c_str(), size); + LLSD body; + body["item_id"] = item->getUUID(); + LL_INFOS("WindLight") << body << LL_ENDL; + LLHTTPClient::post(agent_url, body, new LLUpdateAgentInventoryResponder(body, asset_id, LLAssetType::AT_NOTECARD)); + } + else + { + LL_WARNS("WindLight") << "Stuff the legacy system." << LL_ENDL; + return false; + } + + propagateParameters(); + return true; } void LLWLParamManager::loadPreset(const std::string & name,bool propagate) @@ -659,7 +720,14 @@ LLWLParamManager * LLWLParamManager::instance() void LLWLParamManager::loadWindlightNotecard(LLVFS *vfs, const LLUUID& asset_id, LLAssetType::EType asset_type, void *user_data, S32 status, LLExtStat ext_status) { - std::string name = std::string((char*)user_data); + LLUUID inventory_id(*((LLUUID*)user_data)); + std::string name = "WindLight Setting.wl"; + LLViewerInventoryItem *item = gInventory.getItem(inventory_id); + if(item) + { + inventory_id = item->getUUID(); + name = item->getName(); + } if(LL_ERR_NOERR == status) { LLVFile file(vfs, asset_id, asset_type, LLVFile::READ); @@ -685,6 +753,11 @@ void LLWLParamManager::loadWindlightNotecard(LLVFS *vfs, const LLUUID& asset_id, subs["NAME"] = name; LLNotifications::getInstance()->add("KittyInvalidWindlightNotecard", subs); } + else + { + // We can do this because we know mCurParams + sInstance->mParamList[name].mInventoryID = inventory_id; + } } } diff --git a/linden/indra/newview/llwlparammanager.h b/linden/indra/newview/llwlparammanager.h index c506c11..612a507 100644 --- a/linden/indra/newview/llwlparammanager.h +++ b/linden/indra/newview/llwlparammanager.h @@ -154,9 +154,12 @@ public: /// Load an individual preset from a notecard. void loadPresetNotecard(const std::string& name, const LLUUID& asset_id, const LLUUID& inv_id); - + /// save the parameter presets to file void savePreset(const std::string & name); + + /// save the parameter presets to file + bool savePresetToNotecard(const std::string & name); /// Set shader uniforms dirty, so they'll update automatically. void propagateParameters(void); diff --git a/linden/indra/newview/llwlparamset.h b/linden/indra/newview/llwlparamset.h index 21d646f..038490d 100644 --- a/linden/indra/newview/llwlparamset.h +++ b/linden/indra/newview/llwlparamset.h @@ -49,7 +49,8 @@ class LLWLParamSet { friend class LLWLParamManager; public: - std::string mName; + std::string mName; + LLUUID mInventoryID; private: diff --git a/linden/indra/newview/skins/default/xui/en-us/floater_windlight_options.xml b/linden/indra/newview/skins/default/xui/en-us/floater_windlight_options.xml index 471b3e5..529ed63 100644 --- a/linden/indra/newview/skins/default/xui/en-us/floater_windlight_options.xml +++ b/linden/indra/newview/skins/default/xui/en-us/floater_windlight_options.xml @@ -24,10 +24,13 @@ label="New" label_selected="New" left_delta="40" mouse_opaque="true" name="WLNewPreset" scale_image="true" width="70" />