summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--indra/newview/llfloaterdeleteenvpreset.cpp44
-rw-r--r--indra/newview/llfloaterdeleteenvpreset.h1
-rw-r--r--indra/newview/llfloaterenvironmentsettings.cpp1
-rw-r--r--indra/newview/llfloaterregioninfo.cpp1
-rw-r--r--indra/newview/llwaterparammanager.cpp166
-rw-r--r--indra/newview/llwaterparammanager.h11
6 files changed, 94 insertions, 130 deletions
diff --git a/indra/newview/llfloaterdeleteenvpreset.cpp b/indra/newview/llfloaterdeleteenvpreset.cpp
index 4fed5b9d5a..3fdbbcae9e 100644
--- a/indra/newview/llfloaterdeleteenvpreset.cpp
+++ b/indra/newview/llfloaterdeleteenvpreset.cpp
@@ -58,6 +58,7 @@ LLFloaterDeleteEnvPreset::LLFloaterDeleteEnvPreset(const LLSD &key)
BOOL LLFloaterDeleteEnvPreset::postBuild()
{
mPresetCombo = getChild<LLComboBox>("preset_combo");
+ mPresetCombo->setCommitCallback(boost::bind(&LLFloaterDeleteEnvPreset::postPopulate, this));
getChild<LLButton>("delete")->setCommitCallback(boost::bind(&LLFloaterDeleteEnvPreset::onBtnDelete, this));
getChild<LLButton>("cancel")->setCommitCallback(boost::bind(&LLFloaterDeleteEnvPreset::onBtnCancel, this));
@@ -65,6 +66,7 @@ BOOL LLFloaterDeleteEnvPreset::postBuild()
// Listen to presets addition/removal.
LLDayCycleManager::instance().setModifyCallback(boost::bind(&LLFloaterDeleteEnvPreset::populateDayCyclesList, this));
LLWLParamManager::instance().setPresetListChangeCallback(boost::bind(&LLFloaterDeleteEnvPreset::populateSkyPresetsList, this));
+ LLWaterParamManager::instance().setPresetListChangeCallback(boost::bind(&LLFloaterDeleteEnvPreset::populateWaterPresetsList, this));
return TRUE;
}
@@ -86,7 +88,6 @@ void LLFloaterDeleteEnvPreset::onOpen(const LLSD& key)
if (param == "water")
{
populateWaterPresetsList();
- getChild<LLButton>("delete")->setEnabled(FALSE); // not implemented yet
}
else if (param == "sky")
{
@@ -110,8 +111,14 @@ void LLFloaterDeleteEnvPreset::onBtnDelete()
if (param == "water")
{
- llwarns << "Deleting water presets not implemented" << llendl;
- return;
+ // Don't allow deleting system presets.
+ if (LLWaterParamManager::instance().isSystemPreset(preset_name))
+ {
+ LLNotificationsUtil::add("WLNoEditDefault");
+ return;
+ }
+
+ confirm_cb = boost::bind(&LLFloaterDeleteEnvPreset::onDeleteWaterPresetConfirmation, this);
}
else if (param == "sky")
{
@@ -168,15 +175,27 @@ void LLFloaterDeleteEnvPreset::populateWaterPresetsList()
mPresetCombo->removeall();
+ std::string cur_preset;
+ LLEnvManagerNew& env_mgr = LLEnvManagerNew::instance();
+ if (!env_mgr.getUseRegionSettings())
+ {
+ cur_preset = env_mgr.getWaterPresetName();
+ }
+
// *TODO: Reload the list when user preferences change.
LLWaterParamManager& water_mgr = LLWaterParamManager::instance();
- LL_DEBUGS("Windlight") << "Current water preset: " << water_mgr.mCurParams.mName << LL_ENDL;
-
const std::map<std::string, LLWaterParamSet> &water_params_map = water_mgr.mParamList;
for (std::map<std::string, LLWaterParamSet>::const_iterator it = water_params_map.begin(); it != water_params_map.end(); it++)
{
std::string name = it->first;
- bool enabled = (name != water_mgr.mCurParams.mName); // don't allow deleting current preset
+
+ // list only user presets
+ if (water_mgr.isSystemPreset(name))
+ {
+ continue;
+ }
+
+ bool enabled = (name != cur_preset); // don't allow deleting current preset
mPresetCombo->add(name, ADD_BOTTOM, enabled);
}
@@ -240,15 +259,15 @@ void LLFloaterDeleteEnvPreset::populateDayCyclesList()
void LLFloaterDeleteEnvPreset::postPopulate()
{
- // Handle empty list.
- S32 n_items = mPresetCombo->getItemCount();
+ // Handle empty list and empty selection.
+ bool has_selection = mPresetCombo->getItemCount() > 1 && mPresetCombo->getSelectedValue().isDefined();
- if (n_items == 0)
+ if (!has_selection)
{
mPresetCombo->setLabel(getString("combo_label"));
}
- getChild<LLButton>("delete")->setEnabled(n_items > 0);
+ getChild<LLButton>("delete")->setEnabled(has_selection);
}
void LLFloaterDeleteEnvPreset::onDeleteDayCycleConfirmation()
@@ -261,3 +280,8 @@ void LLFloaterDeleteEnvPreset::onDeleteSkyPresetConfirmation()
LLWLParamKey key(mPresetCombo->getValue().asString(), LLEnvKey::SCOPE_LOCAL);
LLWLParamManager::instance().removeParamSet(key, true);
}
+
+void LLFloaterDeleteEnvPreset::onDeleteWaterPresetConfirmation()
+{
+ LLWaterParamManager::instance().removeParamSet(mPresetCombo->getValue().asString(), true);
+}
diff --git a/indra/newview/llfloaterdeleteenvpreset.h b/indra/newview/llfloaterdeleteenvpreset.h
index 63f80d89d8..567962dc84 100644
--- a/indra/newview/llfloaterdeleteenvpreset.h
+++ b/indra/newview/llfloaterdeleteenvpreset.h
@@ -53,6 +53,7 @@ private:
void onDeleteDayCycleConfirmation();
void onDeleteSkyPresetConfirmation();
+ void onDeleteWaterPresetConfirmation();
LLComboBox* mPresetCombo;
};
diff --git a/indra/newview/llfloaterenvironmentsettings.cpp b/indra/newview/llfloaterenvironmentsettings.cpp
index 0ec6d1c6c8..4517063460 100644
--- a/indra/newview/llfloaterenvironmentsettings.cpp
+++ b/indra/newview/llfloaterenvironmentsettings.cpp
@@ -78,6 +78,7 @@ BOOL LLFloaterEnvironmentSettings::postBuild()
LLDayCycleManager::instance().setModifyCallback(boost::bind(&LLFloaterEnvironmentSettings::populateDayCyclePresetsList, this));
LLWLParamManager::instance().setPresetListChangeCallback(boost::bind(&LLFloaterEnvironmentSettings::populateSkyPresetsList, this));
+ LLWaterParamManager::instance().setPresetListChangeCallback(boost::bind(&LLFloaterEnvironmentSettings::populateWaterPresetsList, this));
return TRUE;
}
diff --git a/indra/newview/llfloaterregioninfo.cpp b/indra/newview/llfloaterregioninfo.cpp
index 567183b955..cb84eaed34 100644
--- a/indra/newview/llfloaterregioninfo.cpp
+++ b/indra/newview/llfloaterregioninfo.cpp
@@ -3302,6 +3302,7 @@ BOOL LLPanelEnvironmentInfo::postBuild()
LLDayCycleManager::instance().setModifyCallback(boost::bind(&LLPanelEnvironmentInfo::populateDayCyclesList, this));
LLWLParamManager::instance().setPresetListChangeCallback(boost::bind(&LLPanelEnvironmentInfo::populateSkyPresetsList, this));
+ LLWaterParamManager::instance().setPresetListChangeCallback(boost::bind(&LLPanelEnvironmentInfo::populateWaterPresetsList, this));
return TRUE;
}
diff --git a/indra/newview/llwaterparammanager.cpp b/indra/newview/llwaterparammanager.cpp
index d1e0c4c109..d84ccb0ada 100644
--- a/indra/newview/llwaterparammanager.cpp
+++ b/indra/newview/llwaterparammanager.cpp
@@ -79,131 +79,73 @@ LLWaterParamManager::~LLWaterParamManager()
{
}
-void LLWaterParamManager::loadAllPresets(const std::string& file_name)
+void LLWaterParamManager::loadAllPresets()
{
- std::string path_name(gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "windlight/water", ""));
- LL_DEBUGS2("AppInit", "Shaders") << "Loading Default water settings from " << path_name << LL_ENDL;
-
- bool found = true;
- LLDirIterator app_settings_iter(path_name, "*.xml");
- while(found)
- {
- std::string name;
- found = app_settings_iter.next(name);
- if(found)
- {
-
- name=name.erase(name.length()-4);
+ // First, load system (coming out of the box) water presets.
+ loadPresetsFromDir(getSysDir());
- // bugfix for SL-46920: preventing filenames that break stuff.
- char * curl_str = curl_unescape(name.c_str(), name.size());
- std::string unescaped_name(curl_str);
- curl_free(curl_str);
- curl_str = NULL;
-
- LL_DEBUGS2("AppInit", "Shaders") << "name: " << name << LL_ENDL;
- loadPreset(unescaped_name,FALSE);
- }
- }
+ // Then load user presets. Note that user day presets will modify any system ones already loaded.
+ loadPresetsFromDir(getUserDir());
+}
- // And repeat for user presets, note the user presets will modify any system presets already loaded
+void LLWaterParamManager::loadPresetsFromDir(const std::string& dir)
+{
+ LL_INFOS2("AppInit", "Shaders") << "Loading water presets from " << dir << LL_ENDL;
- std::string path_name2(gDirUtilp->getExpandedFilename( LL_PATH_USER_SETTINGS , "windlight/water", ""));
- LL_DEBUGS2("AppInit", "Shaders") << "Loading User water settings from " << path_name2 << LL_ENDL;
-
- found = true;
- LLDirIterator user_settings_iter(path_name2, "*.xml");
- while(found)
+ LLDirIterator dir_iter(dir, "*.xml");
+ while (1)
{
- std::string name;
- found = user_settings_iter.next(name);
- if(found)
+ std::string file;
+ if (!dir_iter.next(file))
{
- name=name.erase(name.length()-4);
-
- // bugfix for SL-46920: preventing filenames that break stuff.
- char * curl_str = curl_unescape(name.c_str(), name.size());
- std::string unescaped_name(curl_str);
- curl_free(curl_str);
- curl_str = NULL;
+ break; // no more files
+ }
- LL_DEBUGS2("AppInit", "Shaders") << "name: " << name << LL_ENDL;
- loadPreset(unescaped_name,FALSE);
+ std::string path = dir + file;
+ if (!loadPreset(path))
+ {
+ llwarns << "Error loading water preset from " << path << llendl;
}
}
-
}
-void LLWaterParamManager::loadPreset(const std::string & name,bool propagate)
+bool LLWaterParamManager::loadPreset(const std::string& path)
{
- // bugfix for SL-46920: preventing filenames that break stuff.
- char * curl_str = curl_escape(name.c_str(), name.size());
- std::string escaped_filename(curl_str);
- curl_free(curl_str);
- curl_str = NULL;
-
- escaped_filename += ".xml";
+ llifstream xml_file;
+ std::string name(gDirUtilp->getBaseFileName(LLURI::unescape(path), /*strip_exten = */ true));
- std::string pathName(gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "windlight/water", escaped_filename));
- LL_DEBUGS2("AppInit", "Shaders") << "Loading water settings from " << pathName << LL_ENDL;
-
- llifstream presetsXML;
- presetsXML.open(pathName.c_str());
-
- // That failed, try loading from the users area instead.
- if(!presetsXML)
+ xml_file.open(path.c_str());
+ if (!xml_file)
{
- pathName=gDirUtilp->getExpandedFilename( LL_PATH_USER_SETTINGS , "windlight/water", escaped_filename);
- LL_DEBUGS2("AppInit", "Shaders") << "Loading User water setting from " << pathName << LL_ENDL;
- presetsXML.clear();
- presetsXML.open(pathName.c_str());
+ return false;
}
- if (presetsXML)
- {
- LLSD paramsData(LLSD::emptyMap());
-
- LLPointer<LLSDParser> parser = new LLSDXMLParser();
+ LL_DEBUGS2("AppInit", "Shaders") << "Loading water " << name << LL_ENDL;
- parser->parse(presetsXML, paramsData, LLSDSerialize::SIZE_UNLIMITED);
+ LLSD params_data;
+ LLPointer<LLSDParser> parser = new LLSDXMLParser();
+ parser->parse(xml_file, params_data, LLSDSerialize::SIZE_UNLIMITED);
+ xml_file.close();
- std::map<std::string, LLWaterParamSet>::iterator mIt = mParamList.find(name);
- if(mIt == mParamList.end())
- {
- addParamSet(name, paramsData);
- }
- else
- {
- setParamSet(name, paramsData);
- }
- presetsXML.close();
- }
- else
+ if (hasParamSet(name))
{
- llwarns << "Can't find " << name << llendl;
- return;
+ setParamSet(name, params_data);
}
-
- if(propagate)
+ else
{
- getParamSet(name, mCurParams);
- propagateParameters();
+ addParamSet(name, params_data);
}
-}
+
+ return true;
+}
void LLWaterParamManager::savePreset(const std::string & name)
{
- // bugfix for SL-46920: preventing filenames that break stuff.
- char * curl_str = curl_escape(name.c_str(), name.size());
- std::string escaped_filename(curl_str);
- curl_free(curl_str);
- curl_str = NULL;
-
- escaped_filename += ".xml";
+ llassert(!name.empty());
// make an empty llsd
LLSD paramsData(LLSD::emptyMap());
- std::string pathName(gDirUtilp->getExpandedFilename( LL_PATH_USER_SETTINGS , "windlight/water", escaped_filename));
+ std::string pathName(getUserDir() + LLURI::escape(name) + ".xml");
// fill it with LLSD windlight params
paramsData = mParamList[name].getAll();
@@ -217,7 +159,6 @@ void LLWaterParamManager::savePreset(const std::string & name)
propagateParameters();
}
-
void LLWaterParamManager::propagateParameters(void)
{
// bind the variables only if we're using shaders
@@ -444,26 +385,25 @@ bool LLWaterParamManager::setParamSet(const std::string& name, const LLSD & para
bool LLWaterParamManager::removeParamSet(const std::string& name, bool delete_from_disk)
{
// remove from param list
- std::map<std::string, LLWaterParamSet>::iterator mIt = mParamList.find(name);
- if(mIt != mParamList.end())
+ std::map<std::string, LLWaterParamSet>::iterator it = mParamList.find(name);
+ if (it == mParamList.end())
{
- mParamList.erase(mIt);
+ LL_WARNS("WindLight") << "No water preset named " << name << LL_ENDL;
+ return false;
}
- if(delete_from_disk)
- {
+ mParamList.erase(it);
- std::string path_name(gDirUtilp->getExpandedFilename( LL_PATH_USER_SETTINGS , "windlight/water", ""));
-
- // use full curl escaped name
- char * curl_str = curl_escape(name.c_str(), name.size());
- std::string escaped_name(curl_str);
- curl_free(curl_str);
- curl_str = NULL;
-
- gDirUtilp->deleteFilesInDir(path_name, escaped_name + ".xml");
+ // remove from file system if requested
+ if (delete_from_disk)
+ {
+ if (gDirUtilp->deleteFilesInDir(getUserDir(), LLURI::escape(name) + ".xml") < 1)
+ {
+ LL_WARNS("WindLight") << "Error removing water preset " << name << " from disk" << LL_ENDL;
+ }
}
+ // signal interested parties
mPresetListChangeSignal();
return true;
}
@@ -501,7 +441,7 @@ F32 LLWaterParamManager::getFogDensity(void)
void LLWaterParamManager::initSingleton()
{
LL_DEBUGS("Windlight") << "Initializing water" << LL_ENDL;
- loadAllPresets(LLStringUtil::null);
+ loadAllPresets();
applyUserPrefs(false);
}
diff --git a/indra/newview/llwaterparammanager.h b/indra/newview/llwaterparammanager.h
index 76891094c2..1f599f57dc 100644
--- a/indra/newview/llwaterparammanager.h
+++ b/indra/newview/llwaterparammanager.h
@@ -218,13 +218,6 @@ class LLWaterParamManager : public LLSingleton<LLWaterParamManager>
public:
typedef boost::signals2::signal<void()> preset_list_signal_t;
- /// load a preset file
- void loadAllPresets(const std::string & fileName);
-
- /// load an individual preset into the sky
-
- void loadPreset(const std::string & name,bool propagate=true);
-
/// save the parameter presets to file
void savePreset(const std::string & name);
@@ -318,6 +311,10 @@ private:
LLWaterParamManager();
~LLWaterParamManager();
+ void loadAllPresets();
+ void loadPresetsFromDir(const std::string& dir);
+ bool loadPreset(const std::string& path);
+
static std::string getSysDir();
static std::string getUserDir();