Commit 33e03c6e authored by NiranV's avatar NiranV

Added: Ability to save presets as inventory items from within Edit Sky/Water windows.

Fixed: Saving presets fails because the folder doesn't yet exist.
Fixed: Loading a local preset in "Fixed Environment" makes all further changes not apply.
Fixed: Sun/Cloud/Moon/Water texture ids are not saved into the local preset even if we have the permissions to do so.
Changed: Consoliderated newly added save as item and old save locally into a "Save Dropdown" button defaulting to saving locally.
Changed: Renamed "Reset" button to "Reset To Region Default" to make it clearer what it actually does.
Changed: Load order of presets to put custom presets back at the top and system presets below that.
parent e9a5646a
......@@ -464,17 +464,19 @@ struct SortItemPtrsByName
bool BDFunctions::checkPermissions(LLUUID uuid)
{
const LLInventoryItem *item = gInventory.getItem(uuid);
if (!item)
return false;
LLPermissions perms = item->getPermissions();
if (!perms.allowTransferTo(gAgentID)
&& !perms.allowModifyBy(gAgentID)
&& !perms.allowCopyBy(gAgentID))
return false;
LLViewerInventoryItem *item = gInventory.getItem(uuid);
if (item)
{
LLPermissions perms = item->getPermissions();
if (perms.allowOperationBy(PERM_TRANSFER, gAgent.getID())
&& perms.allowOperationBy(PERM_MODIFY, gAgent.getID())
&& perms.allowOperationBy(PERM_COPY, gAgent.getID()))
{
return true;
}
}
return true;
return false;
}
void BDFunctions::addInventoryPresets(LLComboBox* combo, LLSettingsBase::ptr_t settings)
......@@ -483,7 +485,7 @@ void BDFunctions::addInventoryPresets(LLComboBox* combo, LLSettingsBase::ptr_t s
LLSettingsType::type_e type = settings->getSettingsType() == "sky" ? LLSettingsType::ST_SKY : LLSettingsType::ST_WATER;
// Get all inventory items that are animations
// Get all inventory items that are settings
LLViewerInventoryCategory::cat_array_t cats;
LLViewerInventoryItem::item_array_t items;
LLIsTypeWithPermissions is_copyable_animation(LLAssetType::AT_SETTINGS,
......@@ -496,28 +498,33 @@ void BDFunctions::addInventoryPresets(LLComboBox* combo, LLSettingsBase::ptr_t s
LLInventoryModel::EXCLUDE_TRASH,
is_copyable_animation);
// Copy into something we can sort
std::vector<LLViewerInventoryItem*> animations;
//BD - Copy into something we can sort
std::vector<LLViewerInventoryItem*> presets;
S32 i;
S32 count = items.size();
for (i = 0; i < count; ++i)
{
animations.push_back(items.at(i));
presets.push_back(items.at(i));
}
// Do the sort
std::sort(animations.begin(), animations.end(), SortItemPtrsByName());
//BD - Do the sort
std::sort(presets.begin(), presets.end(), SortItemPtrsByName());
combo->addSeparator();
//BD - Add the inventory presets separator if we found some.
if (count > 0)
{
combo->addSeparator(ADD_BOTTOM, "Inventory Presets");
}
// And load up the combobox
std::vector<LLViewerInventoryItem*>::iterator it;
for (it = animations.begin(); it != animations.end(); ++it)
for (it = presets.begin(); it != presets.end(); ++it)
{
LLViewerInventoryItem* item = *it;
if (item->getSettingsType() == type)
{
combo->add(item->getName(), item->getUUID(), ADD_BOTTOM);
}
}
}
......@@ -617,39 +624,10 @@ void BDFunctions::savePreset(std::string name, LLSettingsBase::ptr_t settings)
LLSD Params;
std::string folder;
Params = settings->getSettings();
if (settings->getSettingsType() == "sky")
{
folder = "skies";
LLSettingsSky::ptr_t sky = std::static_pointer_cast<LLSettingsSky>(settings);
if (sky)
{
//BD - Remove sun/cloud/moon texture information from preset if we don't have
// permissions to include them.
if (!checkPermissions(sky->getMoonTextureId()))
Params.erase("moon_id");
if (!checkPermissions(sky->getSunTextureId()))
Params.erase("sun_id");
if (!checkPermissions(sky->getCloudNoiseTextureId()))
Params.erase("cloud_id");
}
}
else
{
folder = "water";
LLSettingsWater::ptr_t water = std::static_pointer_cast<LLSettingsWater>(settings);
if (water)
{
//BD - Remove water texture information from preset if we don't have
// permissions to include them.
if (!checkPermissions(water->getNormalMapID()))
Params.erase("normal_map");
}
}
folder = settings->getSettingsType() == "sky" ? "skies" : "water";
// make an empty llsd
std::string pathName(getUserDir(folder) + escapeString(name) + ".xml");
std::string pathName(getWindlightDir(folder) + escapeString(name) + ".xml");
Params["version"] = "eep";
......@@ -673,7 +651,7 @@ void BDFunctions::deletePreset(std::string name, std::string folder)
}
else
{
std::string path_name(getUserDir(folder));
std::string path_name(getWindlightDir(folder));
std::string escaped_name = escapeString(name);
if (gDirUtilp->deleteFilesInDir(path_name, escaped_name + ".xml") < 1)
......@@ -689,45 +667,61 @@ void BDFunctions::loadPresetsFromDir(LLComboBox* combo, std::string folder)
if (!combo || folder.empty()) return;
bool is_sky = folder == "skies";
bool success = false;
combo->clearRows();
std::string dir = getSysDir(folder);
std::string dir = getWindlightDir(folder);
std::string file;
if (!dir.empty() || gDirUtilp->fileExists(dir))
{
LLDirIterator dir_iter(dir, "*.xml");
while (dir_iter.next(file))
LLDirIterator dir_it(dir, "*.xml");
while (dir_it.next(file))
{
std::string path = gDirUtilp->add(dir, file);
std::string name = gDirUtilp->getBaseFileName(LLURI::unescape(path), true);
combo->add(name);
if (is_sky)
mDefaultSkyPresets[name] = name;
else
mDefaultWaterPresets[name] = name;
//BD - Skip adding if we couldn't load it.
if (!doLoadPreset(path))
{
LL_WARNS() << "Error loading sky preset from " << path << LL_ENDL;
continue;
}
combo->add(name);
success = true;
}
}
combo->addSeparator();
//BD - Add the user presets separator if we found user presets.
if (success)
{
combo->addSeparator(ADD_TOP, "User Presets");
}
//BD - We assume they are always there.
combo->addSeparator(ADD_BOTTOM, "System Presets");
dir = getUserDir(folder);
dir = getWindlightDir(folder, true);
if (!dir.empty() || gDirUtilp->fileExists(dir))
{
LLDirIterator dir_it(dir, "*.xml");
while (dir_it.next(file))
LLDirIterator dir_iter(dir, "*.xml");
while (dir_iter.next(file))
{
std::string path = gDirUtilp->add(dir, file);
std::string name = gDirUtilp->getBaseFileName(LLURI::unescape(path), true);
combo->add(name);
//BD - Skip adding if we couldn't load it.
if (!doLoadPreset(path))
{
LL_WARNS() << "Error loading sky preset from " << path << LL_ENDL;
continue;
}
combo->add(name);
if (is_sky)
mDefaultSkyPresets[name] = name;
else
mDefaultWaterPresets[name] = name;
}
}
}
......@@ -755,19 +749,26 @@ bool BDFunctions::doLoadPreset(const std::string& path)
//BD - Multiple Viewer Presets
// static
std::string BDFunctions::getSysDir(std::string folder)
std::string BDFunctions::getWindlightDir(std::string folder, bool system)
{
if (folder.empty()) return NULL;
std::string sys_dir = gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "windlight", folder, "");
return sys_dir;
}
ELLPath path_enum = system ? LL_PATH_APP_SETTINGS : LL_PATH_USER_SETTINGS;
// static
std::string BDFunctions::getUserDir(std::string folder)
{
if (folder.empty()) return NULL;
//BD - Check for the top level folder first
std::string sys_dir = gDirUtilp->getExpandedFilename(path_enum, "windlight");
if (!gDirUtilp->fileExists(sys_dir))
{
LLFile::mkdir(sys_dir);
}
std::string user_dir = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, "windlight", folder, "");
return user_dir;
sys_dir = gDirUtilp->getExpandedFilename(path_enum, "windlight", folder);
if (!gDirUtilp->fileExists(sys_dir))
{
LL_WARNS("Windlight") << "Couldn't find folder: " << sys_dir << " - creating one." << LL_ENDL;
LLFile::mkdir(sys_dir);
}
sys_dir = gDirUtilp->getExpandedFilename(path_enum, "windlight", folder, "");
return sys_dir;
}
\ No newline at end of file
......@@ -67,8 +67,7 @@ class BDFunctions
void loadPresetsFromDir(LLComboBox* combo, std::string folder = "skies");
bool doLoadPreset(const std::string& path);
void loadAllPresets(LLSD& presets);
static std::string getSysDir(std::string folder);
static std::string getUserDir(std::string folder);
static std::string getWindlightDir(std::string folder, bool system = false);
bool checkPermissions(LLUUID uuid);
void onSelectPreset(LLComboBox* combo, LLSettingsBase::ptr_t settings);
void addInventoryPresets(LLComboBox* combo, LLSettingsBase::ptr_t settings);
......
......@@ -46,6 +46,8 @@
#include "llinventorymodel.h"
#include "llinventoryfunctions.h"
#include "llagent.h"
#include "lltrans.h"
#include "llflyoutcombobtn.h"
//=========================================================================
......@@ -125,6 +127,9 @@ namespace
const std::string FIELD_SKY_DENSITY_ABSORPTION_CONSTANT("absorption_constant");
const std::string FIELD_SKY_DENSITY_ABSORPTION_MAX_ALTITUDE("absorption_max_altitude");
const std::string ACTION_SAVELOCAL("save_as_local_setting");
const std::string ACTION_SAVEAS("save_as_new_settings");
const std::string BTN_RESET("reset");
const std::string BTN_SAVE("save");
const std::string BTN_DELETE("delete");
......@@ -132,6 +137,10 @@ namespace
const std::string EDITOR_NAME("sky_preset_combo");
const std::string BUTTON_NAME_COMMIT("btn_commit");
const std::string BUTTON_NAME_FLYOUT("btn_flyout");
const std::string XML_FLYOUTMENU_FILE("menu_save_settings_adjust.xml");
const F32 SLIDER_SCALE_SUN_AMBIENT(3.0f);
const F32 SLIDER_SCALE_BLUE_HORIZON_DENSITY(2.0f);
const F32 SLIDER_SCALE_GLOW_R(20.0f);
......@@ -244,9 +253,12 @@ BOOL LLFloaterEnvironmentAdjust::postBuild()
getChild<LLUICtrl>(BTN_RESET)->setCommitCallback([this](LLUICtrl *, const LLSD &) { onButtonReset(); });
getChild<LLUICtrl>(BTN_DELETE)->setCommitCallback([this](LLUICtrl *, const LLSD &) { onButtonDelete(); });
getChild<LLUICtrl>(BTN_SAVE)->setCommitCallback([this](LLUICtrl *, const LLSD &) { onButtonSave(); });
//getChild<LLUICtrl>(BTN_SAVE)->setCommitCallback([this](LLUICtrl *, const LLSD &) { onButtonSave(); });
getChild<LLUICtrl>(BTN_IMPORT)->setCommitCallback([this](LLUICtrl *, const LLSD &) { onButtonImport(); });
mFlyoutControl = new LLFlyoutComboBtnCtrl(this, BTN_SAVE, BUTTON_NAME_FLYOUT, XML_FLYOUTMENU_FILE, false);
mFlyoutControl->setAction([this](LLUICtrl *ctrl, const LLSD &data) { onButtonApply(ctrl, data); });
mNameCombo = getChild<LLComboBox>(EDITOR_NAME);
mNameCombo->setCommitCallback([this](LLUICtrl *, const LLSD &) { onSelectPreset(); });
......@@ -389,6 +401,9 @@ void LLFloaterEnvironmentAdjust::captureCurrentEnvironment()
environment.setSelectedEnvironment(LLEnvironment::ENV_LOCAL);
environment.updateEnvironment(LLEnvironment::TRANSITION_INSTANT);
mSunImageChanged = false;
mCloudImageChanged = false;
mMoonImageChanged = false;
}
void LLFloaterEnvironmentAdjust::onButtonReset()
......@@ -597,6 +612,7 @@ void LLFloaterEnvironmentAdjust::onSunImageChanged()
if (!mLiveSky) return;
mLiveSky->setSunTextureId(mSunImage->getValue().asUUID());
mLiveSky->update();
mSunImageChanged = true;
}
void LLFloaterEnvironmentAdjust::onMoonRotationXChanged()
......@@ -645,6 +661,7 @@ void LLFloaterEnvironmentAdjust::onMoonImageChanged()
if (!mLiveSky) return;
mLiveSky->setMoonTextureId(mMoonImage->getValue().asUUID());
mLiveSky->update();
mMoonImageChanged = true;
}
void LLFloaterEnvironmentAdjust::onMoonScaleChanged()
......@@ -700,8 +717,8 @@ void LLFloaterEnvironmentAdjust::onCloudScrollChanged()
void LLFloaterEnvironmentAdjust::onCloudMapChanged()
{
if (!mLiveSky) return;
LLTextureCtrl* ctrl = mCloudImage;
mLiveSky->setCloudNoiseTextureId(ctrl->getValue().asUUID());
mLiveSky->setCloudNoiseTextureId(mCloudImage->getValue().asUUID());
mCloudImageChanged = true;
}
void LLFloaterEnvironmentAdjust::onCloudDensityChanged()
......@@ -718,14 +735,127 @@ void LLFloaterEnvironmentAdjust::onCloudDetailChanged()
mLiveSky->setCloudPosDensity2(detail);
}
void LLFloaterEnvironmentAdjust::onButtonApply(LLUICtrl *ctrl, const LLSD &data)
{
std::string ctrl_action = ctrl->getName();
std::string local_desc;
LLSettingsBase::ptr_t setting_clone;
bool is_local = false; // because getString can be empty
if (mLiveSky)
{
setting_clone = mLiveSky->buildClone();
if (LLLocalBitmapMgr::getInstance()->isLocal(mLiveSky->getSunTextureId()))
{
local_desc = LLTrans::getString("EnvironmentSun");
is_local = true;
}
else if (LLLocalBitmapMgr::getInstance()->isLocal(mLiveSky->getMoonTextureId()))
{
local_desc = LLTrans::getString("EnvironmentMoon");
is_local = true;
}
else if (LLLocalBitmapMgr::getInstance()->isLocal(mLiveSky->getCloudNoiseTextureId()))
{
local_desc = LLTrans::getString("EnvironmentCloudNoise");
is_local = true;
}
else if (LLLocalBitmapMgr::getInstance()->isLocal(mLiveSky->getBloomTextureId()))
{
local_desc = LLTrans::getString("EnvironmentBloom");
is_local = true;
}
}
if (is_local)
{
LLSD args;
args["FIELD"] = local_desc;
LLNotificationsUtil::add("WLLocalTextureFixedBlock", args);
return;
}
if (ctrl_action == ACTION_SAVELOCAL)
{
onButtonSave();
}
else if (ctrl_action == ACTION_SAVEAS)
{
LLSD args;
args["DESC"] = mLiveSky->getName();
LLNotificationsUtil::add("SaveSettingAs", args, LLSD(), boost::bind(&LLFloaterEnvironmentAdjust::onSaveAsCommit, this, _1, _2, setting_clone));
}
/*else if ((ctrl_action == ACTION_APPLY_LOCAL) ||
(ctrl_action == ACTION_APPLY_PARCEL) ||
(ctrl_action == ACTION_APPLY_REGION))
{
doApplyEnvironment(ctrl_action, setting_clone);
}*/
else
{
LL_WARNS("ENVIRONMENT") << "Unknown settings action '" << ctrl_action << "'" << LL_ENDL;
}
}
void LLFloaterEnvironmentAdjust::onSaveAsCommit(const LLSD& notification, const LLSD& response, const LLSettingsBase::ptr_t &settings)
{
S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
if (0 == option)
{
std::string settings_name = response["message"].asString();
LLInventoryObject::correctInventoryName(settings_name);
if (settings_name.empty())
{
// Ideally notification should disable 'OK' button if name won't fit our requirements,
// for now either display notification, or use some default name
settings_name = "Unnamed";
}
doApplyCreateNewInventory(settings_name, settings);
}
}
void LLFloaterEnvironmentAdjust::doApplyCreateNewInventory(std::string settings_name, const LLSettingsBase::ptr_t &settings)
{
LLUUID parent_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_SETTINGS);
// This method knows what sort of settings object to create.
LLSettingsVOBase::createInventoryItem(settings, parent_id, settings_name,
[this](LLUUID asset_id, LLUUID inventory_id, LLUUID, LLSD results) { onInventoryCreated(asset_id, inventory_id, results); });
}
void LLFloaterEnvironmentAdjust::onInventoryCreated(LLUUID asset_id, LLUUID inventory_id, LLSD results)
{
LL_WARNS("ENVIRONMENT") << "Inventory item " << inventory_id << " has been created with asset " << asset_id << " results are:" << results << LL_ENDL;
if (inventory_id.isNull() || !results["success"].asBoolean())
{
LLNotificationsUtil::add("CantCreateInventory");
return;
}
}
//BD - Windlight Stuff
//=====================================================================================================
void LLFloaterEnvironmentAdjust::onButtonSave()
{
if (!mLiveSky) return;
gDragonLibrary.savePreset(mNameCombo->getValue(), mLiveSky);
LLSettingsSky::ptr_t sky = mLiveSky->buildClone();
//BD - Using local window saved booleans is not the safest method of checking
// but should work just fine for now until i change the actual windlight settings
// item to track whether the UUID's have changed or not.
if (mSunImageChanged && !gDragonLibrary.checkPermissions(mSunImage->getImageItemID()))
sky->setSunTextureId(LLUUID::null);
if (mMoonImageChanged && !gDragonLibrary.checkPermissions(mMoonImage->getImageItemID()))
sky->setMoonTextureId(LLUUID::null);
if (mCloudImageChanged && !gDragonLibrary.checkPermissions(mCloudImage->getImageItemID()))
sky->setCloudNoiseTextureId(LLUUID::null);
gDragonLibrary.savePreset(mNameCombo->getValue(), sky);
gDragonLibrary.loadPresetsFromDir(mNameCombo, "skies");
gDragonLibrary.addInventoryPresets(mNameCombo, mLiveSky);
gDragonLibrary.addInventoryPresets(mNameCombo, sky);
}
void LLFloaterEnvironmentAdjust::onButtonDelete()
......
......@@ -31,6 +31,7 @@
#include "llsettingsbase.h"
#include "llsettingssky.h"
#include "llenvironment.h"
#include "llflyoutcombobtn.h"
#include "boost/signals2.hpp"
......@@ -64,6 +65,11 @@ class LLFloaterEnvironmentAdjust : public LLFloater
void onEnvironmentUpdated(LLEnvironment::EnvSelection_t env, S32 version);
void onButtonApply(LLUICtrl *ctrl, const LLSD &data);
void onSaveAsCommit(const LLSD& notification, const LLSD& response, const LLSettingsBase::ptr_t &settings);
void onInventoryCreated(LLUUID asset_id, LLUUID inventory_id, LLSD results);
virtual void doApplyCreateNewInventory(std::string settings_name, const LLSettingsBase::ptr_t &settings);
//BD - Atmosphere
void onAmbientLightChanged();
void onBlueHorizonChanged();
......@@ -115,6 +121,10 @@ class LLFloaterEnvironmentAdjust : public LLFloater
LLSettingsSky::ptr_t mLiveSky;
LLEnvironment::connection_t mEventConnection;
bool mSunImageChanged;
bool mCloudImageChanged;
bool mMoonImageChanged;
//BD - Atmosphere
LLColorSwatchCtrl* mAmbientLight;
LLColorSwatchCtrl* mBlueHorizon;
......@@ -160,6 +170,7 @@ class LLFloaterEnvironmentAdjust : public LLFloater
LLUICtrl* mCloudDetailD;
LLComboBox* mNameCombo;
LLFlyoutComboBtnCtrl * mFlyoutControl;
LLVector3 mPreviousMoonRot;
LLVector3 mPreviousSunRot;
......
......@@ -82,6 +82,7 @@ namespace
const std::string BUTTON_NAME_LOAD("btn_load");
const std::string ACTION_SAVE("save_settings");
const std::string ACTION_SAVELOCAL("save_as_local_setting");
const std::string ACTION_SAVEAS("save_as_new_settings");
const std::string ACTION_COMMIT("commit_changes");
const std::string ACTION_APPLY_LOCAL("apply_local");
......@@ -158,7 +159,7 @@ BOOL LLFloaterFixedEnvironment::postBuild()
//BD
//getChild<LLUICtrl>(BTN_RESET)->setCommitCallback([this](LLUICtrl *, const LLSD &) { onButtonReset(); });
getChild<LLUICtrl>(BTN_DELETE)->setCommitCallback([this](LLUICtrl *, const LLSD &) { onButtonDelete(); });
getChild<LLUICtrl>(BTN_SAVE)->setCommitCallback([this](LLUICtrl *, const LLSD &) { onButtonSave(); });
//getChild<LLUICtrl>(BTN_SAVE)->setCommitCallback([this](LLUICtrl *, const LLSD &) { onButtonSave(); });
mFlyoutControl = new LLFlyoutComboBtnCtrl(this, BUTTON_NAME_COMMIT, BUTTON_NAME_FLYOUT, XML_FLYOUTMENU_FILE, false);
mFlyoutControl->setAction([this](LLUICtrl *ctrl, const LLSD &data) { onButtonApply(ctrl, data); });
......@@ -475,6 +476,10 @@ void LLFloaterFixedEnvironment::onButtonApply(LLUICtrl *ctrl, const LLSD &data)
{
doApplyUpdateInventory(setting_clone);
}
else if (ctrl_action == ACTION_SAVELOCAL)
{
onButtonSave();
}
else if (ctrl_action == ACTION_SAVEAS)
{
LLSD args;
......@@ -933,11 +938,101 @@ void LLFloaterFixedEnvironment::onButtonDelete()
void LLFloaterFixedEnvironment::onSelectPreset()
{
gDragonLibrary.onSelectPreset(mTxtName, mSettings);
//BD - Don't use the escaped string.
mSettings->setName(mTxtName->getValue().asString());
std::string type = mSettings->getSettingsType();
std::string folder = type == "sky" ? "skies" : "water";
//BD - First attempt to load it as inventory item.
if (mTxtName->getValue().isUUID())
{
LLUUID uuid = mTxtName->getValue();
LLViewerInventoryItem* item = gInventory.getItem(uuid);
if (item)
{
LLSettingsVOBase::getSettingsAsset(item->getAssetUUID(), [this](LLUUID asset_id, LLSettingsBase::ptr_t settings, S32 status, LLExtStat) { loadItem(settings); });
//BD - Assume loading was successful.
return;
}
}
//BD - Loading as inventory item failed so it must be a local preset.
std::string name = gDragonLibrary.escapeString(mTxtName->getValue().asString());
std::string dir = gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "windlight/" + folder, name + ".xml");
if (!loadPreset(dir, type))
{
//BD - Last attempt, try to find it in user_settings.
dir = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, "windlight/" + folder, name + ".xml");
if (!loadPreset(dir, type))
{
LLNotificationsUtil::add("BDCantLoadPreset");
LL_WARNS("Windlight") << "Failed to load sky preset from:" << dir << LL_ENDL;
}
}
}
void LLFloaterFixedEnvironment::loadItem(LLSettingsBase::ptr_t settings)
{
if (!settings) return;
setDirtyFlag();
LLEnvironment &env(LLEnvironment::instance());
std::string type = settings->getSettingsType();
if (type == "sky")
{
env.setEnvironment(LLEnvironment::ENV_EDIT, std::static_pointer_cast<LLSettingsSky>(settings));
setEditSettings(std::static_pointer_cast<LLSettingsSky>(settings));
}
else
{
env.setEnvironment(LLEnvironment::ENV_EDIT, std::static_pointer_cast<LLSettingsWater>(settings));
setEditSettings(std::static_pointer_cast<LLSettingsWater>(settings));
}
env.updateEnvironment(LLEnvironment::TRANSITION_FAST, true);
}
refresh();
bool LLFloaterFixedEnvironment::loadPreset(std::string filename, std::string type)
{
if (filename.empty()) return false;
llifstream xml_file;
xml_file.open(filename);
if (!xml_file)
return false;
LLSD params_data;
LLPointer<LLSDParser> parser = new LLSDXMLParser();
if (parser->parse(xml_file, params_data, LLSDSerialize::SIZE_UNLIMITED) == LLSDParser::PARSE_FAILURE)
{
xml_file.close();
LLNotificationsUtil::add("BDCantParsePreset");
return false;
}
xml_file.close();
LLSD messages;
LLSettingsBase::ptr_t settings;
if (type == "sky")
{
settings = !params_data.has("version") ? LLEnvironment::instance().createSkyFromLegacyPreset(filename, messages)
: LLEnvironment::instance().createSkyFromPreset(filename, messages);
}
else
{
settings = !params_data.has("version") ? LLEnvironment::instance().createWaterFromLegacyPreset(filename, messages)
: LLEnvironment::instance().createWaterFromPreset(filename, messages);
}
if (!settings)
{
LLNotificationsUtil::add("WLImportFail", messages);
return false;
}
loadInventoryItem(LLUUID::null);
loadItem(settings);
return true;
}
\ No newline at end of file
......@@ -136,6 +136,8 @@ class LLFloaterFixedEnvironment : public LLFloater
void onButtonSave();
void onButtonDelete();
void onSelectPreset();
bool loadPreset(std::string filename, std::string type);
void loadItem(LLSettingsBase::ptr_t settings);
};
class LLFloaterFixedEnvironmentWater : public LLFloaterFixedEnvironment
......
......@@ -46,6 +46,8 @@
#include "llinventorymodel.h"
#include "llinventoryfunctions.h"
#include "llagent.h"
#include "lltrans.h"
#include "llflyoutcombobtn.h"
//=========================================================================
......@@ -78,6 +80,9 @@ namespace
const std::string FIELD_WATER_WAVE2_X("water_wave2_x");
const std::string FIELD_WATER_WAVE2_Y("water_wave2_y");
const std::string ACTION_SAVELOCAL("save_as_local_setting");
const std::string ACTION_SAVEAS("save_as_new_settings");
const std::string BTN_RESET("reset");
const std::string BTN_SAVE("save");
const std::string BTN_DELETE("delete");
......@@ -85,6 +90,10 @@ namespace
const std::string EDITOR_NAME("water_preset_combo");
const std::string BUTTON_NAME_COMMIT("btn_commit");
const std::string BUTTON_NAME_FLYOUT("btn_flyout");
const std::string XML_FLYOUTMENU_FILE("menu_save_settings_adjust.xml");
const F32 SLIDER_SCALE_SUN_AMBIENT(3.0f);
const F32 SLIDER_SCALE_BLUE_HORIZON_DENSITY(2.0f);
const F32 SLIDER_SCALE_GLOW_R(20.0f);
......@@ -147,9 +156,12 @@ BOOL LLFloaterWaterAdjust::postBuild()
getChild<LLUICtrl>(BTN_RESET)->setCommitCallback([this](LLUICtrl *, const LLSD &) { onButtonReset(); });
getChild<LLUICtrl>(BTN_DELETE)->setCommitCallback([this](LLUICtrl *, const LLSD &) { onButtonDelete(); });
getChild<LLUICtrl>(BTN_SAVE)->setCommitCallback([this](LLUICtrl *, const LLSD &) { onButtonSave(); });
//getChild<LLUICtrl>(BTN_SAVE)->setCommitCallback([this](LLUICtrl *, const LLSD &) { onButtonSave(); });
getChild<LLUICtrl>(BTN_IMPORT)->setCommitCallback([this](LLUICtrl *, const LLSD &) { onButtonImport(); });
mFlyoutControl = new LLFlyoutComboBtnCtrl(this, BTN_SAVE, BUTTON_NAME_FLYOUT, XML_FLYOUTMENU_FILE, false);
mFlyoutControl->setAction([this](LLUICtrl *ctrl, const LLSD &data) { onButtonApply(ctrl, data); });
mNameCombo = getChild<LLComboBox>(EDITOR_NAME);
mNameCombo->setCommitCallback([this](LLUICtrl *, const LLSD &) { onSelectPreset(); });
......@@ -244,6 +256,7 @@ void LLFloaterWaterAdjust::captureCurrentEnvironment()
environment.setSelectedEnvironment(LLEnvironment::ENV_LOCAL);
environment.updateEnvironment(LLEnvironment::TRANSITION_INSTANT);
mWaterImageChanged = false;
}
void LLFloaterWaterAdjust::onButtonReset()
......@@ -340,6 +353,7 @@ void LLFloaterWaterAdjust::onNormalMapChanged()
if (!mLiveWater) return;
mLiveWater->setNormalMapID(mTxtNormalMap->getImageAssetID());