From d6a5375d9e490c8b03b032bbe1fc08e30ebf1cd3 Mon Sep 17 00:00:00 2001 From: Armin Weatherwax Date: Fri, 27 Aug 2010 01:42:20 +0200 Subject: Katharine Berry: Save to Inventory in water floater. --- linden/indra/newview/llfloaterwater.cpp | 75 ++++++++++++++++++++++ linden/indra/newview/llfloaterwater.h | 6 ++ linden/indra/newview/llwaterparammanager.cpp | 56 ++++++++++++++++ linden/indra/newview/llwaterparammanager.h | 3 + linden/indra/newview/llwlparammanager.cpp | 1 - .../skins/default/xui/en-us/floater_water.xml | 5 +- 6 files changed, 144 insertions(+), 2 deletions(-) diff --git a/linden/indra/newview/llfloaterwater.cpp b/linden/indra/newview/llfloaterwater.cpp index 32c2b75..f08beea 100644 --- a/linden/indra/newview/llfloaterwater.cpp +++ b/linden/indra/newview/llfloaterwater.cpp @@ -50,6 +50,10 @@ #include "llboost.h" #include "llmultisliderctrl.h" +#include "llagent.h" +#include "llinventorymodel.h" +#include "llviewerinventory.h" + #include "v4math.h" #include "llviewerdisplay.h" #include "llviewercontrol.h" @@ -157,6 +161,7 @@ void LLFloaterWater::initCallbacks(void) { //childSetAction("WaterLoadPreset", onLoadPreset, comboBox); childSetAction("WaterNewPreset", onNewPreset, comboBox); childSetAction("WaterSavePreset", onSavePreset, comboBox); + childSetAction("WaterSaveNotecard", onSaveNotecard, comboBox); childSetAction("WaterDeletePreset", onDeletePreset, comboBox); // wave direction @@ -644,6 +649,76 @@ void LLFloaterWater::onSavePreset(void* userData) LLNotifications::instance().add("WLSavePresetAlert", LLSD(), LLSD(), saveAlertCallback); } +class KVFloaterWaterNotecardCreatedCallback : public LLInventoryCallback +{ +public: + void fire(const LLUUID& inv_item); +}; + +void LLFloaterWater::onSaveNotecard(void* userData) +{ + // get the name + LLComboBox* comboBox = sWaterMenu->getChild("WaterPresetsCombo"); + + // don't save the empty name + if(comboBox->getSelectedItemLabel() == "") + { + return; + } + + // Check if this is already a notecard. + if(LLWaterParamManager::instance()->mCurParams.mInventoryID.notNull()) + { + LLNotifications::instance().add("KittyWLSaveNotecardAlert", LLSD(), LLSD(), saveNotecardCallback); + } + else + { + // Make sure we have a ".ww" extension. + std::string name = comboBox->getSelectedItemLabel(); + if(name.length() > 2 && name.compare(name.length() - 3, 3, ".ww") != 0) + { + name += ".ww"; + } + LLPointer cb = new KVFloaterWaterNotecardCreatedCallback(); + // Create a notecard and then save it. + create_inventory_item(gAgent.getID(), + gAgent.getSessionID(), + LLUUID::null, + LLTransactionID::tnull, + name, + "Water settings (Kitty Viewer compatible)", + LLAssetType::AT_NOTECARD, + LLInventoryType::IT_NOTECARD, + NOT_WEARABLE, + PERM_ITEM_UNRESTRICTED, + cb); + + } +} + +void KVFloaterWaterNotecardCreatedCallback::fire(const LLUUID& inv_item) +{ + LLWaterParamManager * param_mgr = LLWaterParamManager::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 LLFloaterWater::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) + { + LLWaterParamManager * param_mgr = LLWaterParamManager::instance(); + param_mgr->setParamSet(param_mgr->mCurParams.mName, param_mgr->mCurParams); + param_mgr->savePresetToNotecard(param_mgr->mCurParams.mName); + } + return false; +} + bool LLFloaterWater::saveAlertCallback(const LLSD& notification, const LLSD& response) { S32 option = LLNotification::getSelectedOption(notification, response); diff --git a/linden/indra/newview/llfloaterwater.h b/linden/indra/newview/llfloaterwater.h index f0944e1..0a47627 100644 --- a/linden/indra/newview/llfloaterwater.h +++ b/linden/indra/newview/llfloaterwater.h @@ -96,6 +96,12 @@ public: /// when user hits the save preset 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/llwaterparammanager.cpp b/linden/indra/newview/llwaterparammanager.cpp index 0b08b14..e01506e 100644 --- a/linden/indra/newview/llwaterparammanager.cpp +++ b/linden/indra/newview/llwaterparammanager.cpp @@ -298,6 +298,62 @@ void LLWaterParamManager::savePreset(const std::string & name) propagateParameters(); } +// Yes, this function is completely identical to LLWLParamManager::savePresetToNotecard. +// I feel some refactoring of this whole WindLight thing would be generally beneficial. +// Damned if I'm going to be the one to do it, though. +bool LLWaterParamManager::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(); + 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 LLWaterParamManager::propagateParameters(void) { diff --git a/linden/indra/newview/llwaterparammanager.h b/linden/indra/newview/llwaterparammanager.h index baac4cf..588e436 100644 --- a/linden/indra/newview/llwaterparammanager.h +++ b/linden/indra/newview/llwaterparammanager.h @@ -245,6 +245,9 @@ public: /// save the parameter presets to file void savePreset(const std::string & name); + + /// save the parameter presets to file + bool savePresetToNotecard(const std::string & name); /// send the parameters to the shaders void propagateParameters(void); diff --git a/linden/indra/newview/llwlparammanager.cpp b/linden/indra/newview/llwlparammanager.cpp index d7df7ae..31471d7 100644 --- a/linden/indra/newview/llwlparammanager.cpp +++ b/linden/indra/newview/llwlparammanager.cpp @@ -319,7 +319,6 @@ bool LLWLParamManager::savePresetToNotecard(const std::string & name) 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 diff --git a/linden/indra/newview/skins/default/xui/en-us/floater_water.xml b/linden/indra/newview/skins/default/xui/en-us/floater_water.xml index 7038c93..c7e5d83 100644 --- a/linden/indra/newview/skins/default/xui/en-us/floater_water.xml +++ b/linden/indra/newview/skins/default/xui/en-us/floater_water.xml @@ -24,9 +24,12 @@ label="New" label_selected="New" left_delta="40" mouse_opaque="true" name="WaterNewPreset" scale_image="true" width="70" />