STORM-2082 Make code more generic to handle the future camera presets.

meow-7.2.2
Jonathan Yap 2014-11-30 11:24:22 -05:00
parent 34a79a6ece
commit 563e22e81c
5 changed files with 74 additions and 75 deletions

View File

@ -49,14 +49,14 @@ BOOL LLFloaterDeletePrefPreset::postBuild()
void LLFloaterDeletePrefPreset::onOpen(const LLSD& key)
{
std::string param = key.asString();
std::string floater_title = getString(std::string("title_") + param);
std::string mSubdirectory = key.asString();
std::string floater_title = getString(std::string("title_") + mSubdirectory);
setTitle(floater_title);
LLComboBox* combo = getChild<LLComboBox>("preset_combo");
LLPresetsManager::getInstance()->setPresetNamesInComboBox(combo);
LLPresetsManager::getInstance()->setPresetNamesInComboBox(mSubdirectory, combo);
}
void LLFloaterDeletePrefPreset::onBtnDelete()
@ -64,6 +64,7 @@ void LLFloaterDeletePrefPreset::onBtnDelete()
LLComboBox* combo = getChild<LLComboBox>("preset_combo");
std::string name = combo->getSimple();
// Ignore return status
LLPresetsManager::getInstance()->deletePreset(name);
}
@ -71,7 +72,7 @@ void LLFloaterDeletePrefPreset::onPresetsListChange()
{
LLComboBox* combo = getChild<LLComboBox>("preset_combo");
LLPresetsManager::getInstance()->setPresetNamesInComboBox(combo);
LLPresetsManager::getInstance()->setPresetNamesInComboBox(mSubdirectory, combo);
}
void LLFloaterDeletePrefPreset::onBtnCancel()

View File

@ -46,6 +46,8 @@ public:
private:
void onPresetsListChange();
std::string mSubdirectory;
};
#endif // LL_LLFLOATERDELETEPREFPRESET_H

View File

@ -749,7 +749,9 @@ void LLFloaterPreference::onOpen(const LLSD& key)
{
LL_WARNS() << "No " << default_file << " found -- creating one" << LL_ENDL;
// Write current graphic settings to default.xml
LLPresetsManager::getInstance()->savePreset("Default");
// If this name is to be localized additional code will be needed to delete the old default
// when changing languages.
LLPresetsManager::getInstance()->savePreset(PRESETS_GRAPHIC, "Default");
}
}
@ -2160,7 +2162,7 @@ void LLPanelPreferenceGraphics::setPresetNamesInComboBox()
{
LLComboBox* combo = getChild<LLComboBox>("graphic_preset_combo");
LLPresetsManager::getInstance()->setPresetNamesInComboBox(combo);
LLPresetsManager::getInstance()->setPresetNamesInComboBox(PRESETS_GRAPHIC, combo);
}
void LLPanelPreferenceGraphics::draw()

View File

@ -45,7 +45,8 @@ LLPresetsManager::~LLPresetsManager()
{
}
std::string LLPresetsManager::getUserDir(const std::string& subdirectory)
//std::string LLPresetsManager::getUserDir(const std::string& subdirectory)
std::string LLPresetsManager::getPresetsDir(const std::string& subdirectory)
{
std::string presets_path = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, PRESETS_DIR);
std::string full_path;
@ -64,22 +65,7 @@ std::string LLPresetsManager::getUserDir(const std::string& subdirectory)
return full_path;
}
std::string LLPresetsManager::getCameraPresetsDir()
{
return getUserDir(PRESETS_CAMERA);
}
std::string LLPresetsManager::getGraphicPresetsDir()
{
return getUserDir(PRESETS_GRAPHIC);
}
void LLPresetsManager::getPresetNames(preset_name_list_t& presets) const
{
presets = mPresetNames;
}
void LLPresetsManager::loadPresetNamesFromDir(const std::string& dir)
void LLPresetsManager::loadPresetNamesFromDir(const std::string& dir, preset_name_list_t& presets)
{
LL_INFOS("AppInit") << "Loading presets from " << dir << LL_ENDL;
@ -106,48 +92,61 @@ void LLPresetsManager::loadPresetNamesFromDir(const std::string& dir)
}
}
}
presets = mPresetNames;
}
void LLPresetsManager::savePreset(const std::string& name)
void LLPresetsManager::savePreset(const std::string& subdirectory, const std::string& name)
{
llassert(!name.empty());
std::vector<std::string> name_list;
// This ugliness is the current list of all the control variables in the graphics and hardware
// preferences floaters. Additions or subtractions to the floaters must also be reflected here.
std::vector<std::string> name_list = boost::assign::list_of
("RenderQualityPerformance")
("RenderFarClip")
("RenderMaxPartCount")
("RenderGlowResolutionPow")
("RenderTerrainDetail")
("RenderAvatarLODFactor")
("RenderAvatarMaxVisible")
("RenderUseImpostors")
("RenderTerrainLODFactor")
("RenderTreeLODFactor")
("RenderVolumeLODFactor")
("RenderFlexTimeFactor")
("RenderTransparentWater")
("RenderObjectBump")
("RenderLocalLights")
("VertexShaderEnable")
("RenderAvatarVP")
("RenderAvatarCloth")
("RenderReflectionDetail")
("WindLightUseAtmosShaders")
("WLSkyDetail")
("RenderDeferred")
("RenderDeferredSSAO")
("RenderDepthOfField")
("RenderShadowDetail")
// preferences floaters or the settings for camera views.
// Additions or subtractions to the control variables in the floaters must also be reflected here.
if(PRESETS_GRAPHIC == subdirectory)
{
name_list = boost::assign::list_of
("RenderQualityPerformance")
("RenderFarClip")
("RenderMaxPartCount")
("RenderGlowResolutionPow")
("RenderTerrainDetail")
("RenderAvatarLODFactor")
("RenderAvatarMaxVisible")
("RenderUseImpostors")
("RenderTerrainLODFactor")
("RenderTreeLODFactor")
("RenderVolumeLODFactor")
("RenderFlexTimeFactor")
("RenderTransparentWater")
("RenderObjectBump")
("RenderLocalLights")
("VertexShaderEnable")
("RenderAvatarVP")
("RenderAvatarCloth")
("RenderReflectionDetail")
("WindLightUseAtmosShaders")
("WLSkyDetail")
("RenderDeferred")
("RenderDeferredSSAO")
("RenderDepthOfField")
("RenderShadowDetail")
("RenderAnisotropic")
("RenderFSAASamples")
("RenderGamma")
("RenderVBOEnable")
("RenderCompressTextures")
("TextureMemory")
("RenderFogRatio");
("RenderAnisotropic")
("RenderFSAASamples")
("RenderGamma")
("RenderVBOEnable")
("RenderCompressTextures")
("TextureMemory")
("RenderFogRatio");
}
if(PRESETS_CAMERA == subdirectory)
{
name_list = boost::assign::list_of
("Placeholder");
}
// make an empty llsd
LLSD paramsData(LLSD::emptyMap());
@ -166,7 +165,7 @@ void LLPresetsManager::savePreset(const std::string& name)
paramsData[ctrl_name]["Value"] = value;
}
std::string pathName(getUserDir(PRESETS_GRAPHIC) + "\\" + LLURI::escape(name) + ".xml");
std::string pathName(getPresetsDir(subdirectory) + "\\" + LLURI::escape(name) + ".xml");
// write to file
llofstream presetsXML(pathName);
@ -178,17 +177,16 @@ void LLPresetsManager::savePreset(const std::string& name)
mPresetListChangeSignal();
}
void LLPresetsManager::setPresetNamesInComboBox(LLComboBox* combo)
void LLPresetsManager::setPresetNamesInComboBox(const std::string& subdirectory, LLComboBox* combo)
{
combo->clearRows();
std::string presets_dir = getGraphicPresetsDir();
std::string presets_dir = getPresetsDir(subdirectory);
if (!presets_dir.empty())
{
loadPresetNamesFromDir(presets_dir);
std::list<std::string> preset_names;
getPresetNames(preset_names);
loadPresetNamesFromDir(presets_dir, preset_names);
combo->setLabel(LLTrans::getString("preset_combo_label"));
@ -206,9 +204,9 @@ void LLPresetsManager::setPresetNamesInComboBox(LLComboBox* combo)
void LLPresetsManager::loadPreset(const std::string& name)
{
std::string pathName(getUserDir(PRESETS_GRAPHIC) + "\\" + LLURI::escape(name) + ".xml");
std::string full_path(getPresetsDir(PRESETS_GRAPHIC) + "\\" + LLURI::escape(name) + ".xml");
gSavedSettings.loadFromFile(pathName, false, true);
gSavedSettings.loadFromFile(full_path, false, true);
}
bool LLPresetsManager::deletePreset(const std::string& name)
@ -221,10 +219,10 @@ bool LLPresetsManager::deletePreset(const std::string& name)
return false;
}
// (*TODO Should the name be escaped here?
if (gDirUtilp->deleteFilesInDir(getUserDir(PRESETS_GRAPHIC), name + ".xml") < 1)
if (gDirUtilp->deleteFilesInDir(getPresetsDir(PRESETS_GRAPHIC), LLURI::escape(name) + ".xml") < 1)
{
LL_WARNS("Presets") << "Error removing preset " << name << " from disk" << LL_ENDL;
return false;
}
else
{

View File

@ -42,13 +42,11 @@ public:
typedef std::list<std::string> preset_name_list_t;
typedef boost::signals2::signal<void()> preset_list_signal_t;
void setPresetNamesInComboBox(LLComboBox* combo);
void getPresetNames(preset_name_list_t& presets) const;
void loadPresetNamesFromDir(const std::string& dir);
void savePreset(const std::string & name);
static std::string getPresetsDir(const std::string& subdirectory);
void setPresetNamesInComboBox(const std::string& subdirectory, LLComboBox* combo);
void loadPresetNamesFromDir(const std::string& dir, preset_name_list_t& presets);
void savePreset(const std::string& subdirectory, const std::string & name);
void loadPreset(const std::string & name);
static std::string getCameraPresetsDir();
static std::string getGraphicPresetsDir();
bool deletePreset(const std::string& name);
/// Emitted when a preset gets loaded or deleted.
@ -60,8 +58,6 @@ public:
LLPresetsManager();
~LLPresetsManager();
static std::string getUserDir(const std::string& subdirectory);
preset_list_signal_t mPresetListChangeSignal;
};