diff options
Diffstat (limited to 'indra/newview')
-rw-r--r-- | indra/newview/llfloaterdeleteenvpreset.cpp | 57 | ||||
-rw-r--r-- | indra/newview/llfloaterdeleteenvpreset.h | 1 | ||||
-rw-r--r-- | indra/newview/llfloatereditdaycycle.cpp | 1 | ||||
-rw-r--r-- | indra/newview/llfloatereditsky.cpp | 2 | ||||
-rw-r--r-- | indra/newview/llfloatereditwater.cpp | 694 | ||||
-rw-r--r-- | indra/newview/llfloatereditwater.h | 70 | ||||
-rw-r--r-- | indra/newview/llfloaterenvironmentsettings.cpp | 1 | ||||
-rw-r--r-- | indra/newview/llfloaterregioninfo.cpp | 1 | ||||
-rw-r--r-- | indra/newview/llwaterparammanager.cpp | 211 | ||||
-rw-r--r-- | indra/newview/llwaterparammanager.h | 26 | ||||
-rw-r--r-- | indra/newview/llwlparammanager.h | 2 | ||||
-rw-r--r-- | indra/newview/skins/default/xui/en/floater_edit_water_preset.xml | 31 |
12 files changed, 933 insertions, 164 deletions
diff --git a/indra/newview/llfloaterdeleteenvpreset.cpp b/indra/newview/llfloaterdeleteenvpreset.cpp index 4fed5b9d5a..ef50ace357 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); } @@ -229,10 +248,19 @@ void LLFloaterDeleteEnvPreset::populateDayCyclesList() cur_day = env_mgr.getDayCycleName(); } - const LLDayCycleManager::dc_map_t& map = LLDayCycleManager::instance().getPresets(); + LLDayCycleManager& day_mgr = LLDayCycleManager::instance(); + const LLDayCycleManager::dc_map_t& map = day_mgr.getPresets(); for (LLDayCycleManager::dc_map_t::const_iterator it = map.begin(); it != map.end(); ++it) { - mPresetCombo->add(it->first, ADD_BOTTOM, it->first != cur_day); + const std::string& name = it->first; + + // list only user presets + if (day_mgr.isSystemPreset(name)) + { + continue; + } + + mPresetCombo->add(name, ADD_BOTTOM, name != cur_day); } postPopulate(); @@ -240,15 +268,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 +289,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/llfloatereditdaycycle.cpp b/indra/newview/llfloatereditdaycycle.cpp index ebb8369c8f..2cbe889322 100644 --- a/indra/newview/llfloatereditdaycycle.cpp +++ b/indra/newview/llfloatereditdaycycle.cpp @@ -129,6 +129,7 @@ void LLFloaterEditDayCycle::initCallbacks(void) { mDayCycleNameEditor->setKeystrokeCallback(boost::bind(&LLFloaterEditDayCycle::onDayCycleNameEdited, this), NULL); mDayCyclesCombo->setCommitCallback(boost::bind(&LLFloaterEditDayCycle::onDayCycleSelected, this)); + mDayCyclesCombo->setTextEntryCallback(boost::bind(&LLFloaterEditDayCycle::onDayCycleNameEdited, this)); mTimeSlider->setCommitCallback(boost::bind(&LLFloaterEditDayCycle::onTimeSliderMoved, this)); mKeysSlider->setCommitCallback(boost::bind(&LLFloaterEditDayCycle::onKeyTimeMoved, this)); mTimeCtrl->setCommitCallback(boost::bind(&LLFloaterEditDayCycle::onKeyTimeChanged, this)); diff --git a/indra/newview/llfloatereditsky.cpp b/indra/newview/llfloatereditsky.cpp index 7b8e3b89ca..27280565c7 100644 --- a/indra/newview/llfloatereditsky.cpp +++ b/indra/newview/llfloatereditsky.cpp @@ -962,7 +962,7 @@ void LLFloaterEditSky::onRegionInfoUpdate() { bool can_edit = true; - // If we've selected the region day cycle for editing. + // If we've selected a region sky preset for editing. if (getSelectedSkyPreset().scope == LLEnvKey::SCOPE_REGION) { // check whether we have the access diff --git a/indra/newview/llfloatereditwater.cpp b/indra/newview/llfloatereditwater.cpp index 4007c27066..a5d392afc6 100644 --- a/indra/newview/llfloatereditwater.cpp +++ b/indra/newview/llfloatereditwater.cpp @@ -30,22 +30,42 @@ // libs #include "llbutton.h" +#include "llcheckboxctrl.h" +#include "llcolorswatch.h" +#include "llcombobox.h" +//#include "llnotifications.h" +#include "llnotificationsutil.h" +#include "llsliderctrl.h" +#include "lltexturectrl.h" // newview +#include "llagent.h" +#include "llregioninfomodel.h" +#include "llviewerregion.h" +#include "llwaterparammanager.h" + +#undef max // Fixes a Windows compiler error LLFloaterEditWater::LLFloaterEditWater(const LLSD &key) : LLFloater(key) +, mWaterPresetNameEditor(NULL) +, mWaterPresetCombo(NULL) +, mMakeDefaultCheckBox(NULL) +, mSaveButton(NULL) { } // virtual BOOL LLFloaterEditWater::postBuild() { - getChild<LLButton>("cancel")->setCommitCallback(boost::bind(&LLFloaterEditWater::onBtnCancel, this)); + mWaterPresetNameEditor = getChild<LLLineEditor>("water_preset_name"); + mWaterPresetCombo = getChild<LLComboBox>("water_preset_combo"); + mMakeDefaultCheckBox = getChild<LLCheckBoxCtrl>("make_default_cb"); + mSaveButton = getChild<LLButton>("save"); - // Disable some non-functional controls. - getChildView("water_preset_combo")->setEnabled(FALSE); - getChildView("save")->setEnabled(FALSE); + initCallbacks(); + refreshWaterPresetsList(); + syncControls(); return TRUE; } @@ -53,6 +73,7 @@ BOOL LLFloaterEditWater::postBuild() // virtual void LLFloaterEditWater::onOpen(const LLSD& key) { + bool new_preset = isNewPreset(); std::string param = key.asString(); std::string floater_title = getString(std::string("title_") + param); std::string hint = getString(std::string("hint_" + param)); @@ -64,10 +85,673 @@ void LLFloaterEditWater::onOpen(const LLSD& key) getChild<LLUICtrl>("hint")->setValue(hint); // Hide the hint to the right of the combo if we're invoked to create a new preset. - getChildView("note")->setVisible(param == "edit"); + getChildView("note")->setVisible(!new_preset); + + // Switch between the water presets combobox and preset name input field. + mWaterPresetCombo->setVisible(!new_preset); + mWaterPresetNameEditor->setVisible(new_preset); + + reset(); +} + +// virtual +void LLFloaterEditWater::onClose(bool app_quitting) +{ + if (!app_quitting) // there's no point to change environment if we're quitting + { + LLEnvManagerNew::instance().usePrefs(); // revert changes made to current environment + } +} + +// virtual +void LLFloaterEditWater::draw() +{ + syncControls(); + LLFloater::draw(); +} + +void LLFloaterEditWater::initCallbacks(void) +{ + mWaterPresetNameEditor->setKeystrokeCallback(boost::bind(&LLFloaterEditWater::onWaterPresetNameEdited, this), NULL); + mWaterPresetCombo->setCommitCallback(boost::bind(&LLFloaterEditWater::onWaterPresetSelected, this)); + mWaterPresetCombo->setTextEntryCallback(boost::bind(&LLFloaterEditWater::onWaterPresetNameEdited, this)); + + mSaveButton->setCommitCallback(boost::bind(&LLFloaterEditWater::onBtnSave, this)); + getChild<LLButton>("cancel")->setCommitCallback(boost::bind(&LLFloaterEditWater::onBtnCancel, this)); + + LLEnvManagerNew::instance().setRegionSettingsChangeCallback(boost::bind(&LLFloaterEditWater::onRegionSettingsChange, this)); + LLWaterParamManager::instance().setPresetListChangeCallback(boost::bind(&LLFloaterEditWater::onWaterPresetListChange, this)); + + // Connect to region info updates. + LLRegionInfoModel::instance().setUpdateCallback(boost::bind(&LLFloaterEditWater::onRegionInfoUpdate, this)); + + //------------------------------------------------------------------------- + + LLWaterParamManager& water_mgr = LLWaterParamManager::instance(); + + getChild<LLUICtrl>("WaterFogColor")->setCommitCallback(boost::bind(&LLFloaterEditWater::onWaterFogColorMoved, this, _1, &water_mgr.mFogColor)); + //getChild<LLUICtrl>("WaterGlow")->setCommitCallback(boost::bind(&LLFloaterEditWater::onColorControlAMoved, this, _1, &water_mgr.mFogColor)); + + // fog density + getChild<LLUICtrl>("WaterFogDensity")->setCommitCallback(boost::bind(&LLFloaterEditWater::onExpFloatControlMoved, this, _1, &water_mgr.mFogDensity)); + getChild<LLUICtrl>("WaterUnderWaterFogMod")->setCommitCallback(boost::bind(&LLFloaterEditWater::onFloatControlMoved, this, _1, &water_mgr.mUnderWaterFogMod)); + + // blue density + getChild<LLUICtrl>("WaterNormalScaleX")->setCommitCallback(boost::bind(&LLFloaterEditWater::onVector3ControlXMoved, this, _1, &water_mgr.mNormalScale)); + getChild<LLUICtrl>("WaterNormalScaleY")->setCommitCallback(boost::bind(&LLFloaterEditWater::onVector3ControlYMoved, this, _1, &water_mgr.mNormalScale)); + getChild<LLUICtrl>("WaterNormalScaleZ")->setCommitCallback(boost::bind(&LLFloaterEditWater::onVector3ControlZMoved, this, _1, &water_mgr.mNormalScale)); + + // fresnel + getChild<LLUICtrl>("WaterFresnelScale")->setCommitCallback(boost::bind(&LLFloaterEditWater::onFloatControlMoved, this, _1, &water_mgr.mFresnelScale)); + getChild<LLUICtrl>("WaterFresnelOffset")->setCommitCallback(boost::bind(&LLFloaterEditWater::onFloatControlMoved, this, _1, &water_mgr.mFresnelOffset)); + + // scale above/below + getChild<LLUICtrl>("WaterScaleAbove")->setCommitCallback(boost::bind(&LLFloaterEditWater::onFloatControlMoved, this, _1, &water_mgr.mScaleAbove)); + getChild<LLUICtrl>("WaterScaleBelow")->setCommitCallback(boost::bind(&LLFloaterEditWater::onFloatControlMoved, this, _1, &water_mgr.mScaleBelow)); + + // blur mult + getChild<LLUICtrl>("WaterBlurMult")->setCommitCallback(boost::bind(&LLFloaterEditWater::onFloatControlMoved, this, _1, &water_mgr.mBlurMultiplier)); + + // wave direction + getChild<LLUICtrl>("WaterWave1DirX")->setCommitCallback(boost::bind(&LLFloaterEditWater::onVector2ControlXMoved, this, _1, &water_mgr.mWave1Dir)); + getChild<LLUICtrl>("WaterWave1DirY")->setCommitCallback(boost::bind(&LLFloaterEditWater::onVector2ControlYMoved, this, _1, &water_mgr.mWave1Dir)); + getChild<LLUICtrl>("WaterWave2DirX")->setCommitCallback(boost::bind(&LLFloaterEditWater::onVector2ControlXMoved, this, _1, &water_mgr.mWave2Dir)); + getChild<LLUICtrl>("WaterWave2DirY")->setCommitCallback(boost::bind(&LLFloaterEditWater::onVector2ControlYMoved, this, _1, &water_mgr.mWave2Dir)); + + LLTextureCtrl* texture_ctrl = getChild<LLTextureCtrl>("WaterNormalMap"); + texture_ctrl->setDefaultImageAssetID(DEFAULT_WATER_NORMAL); + texture_ctrl->setCommitCallback(boost::bind(&LLFloaterEditWater::onNormalMapPicked, this, _1)); +} + +//============================================================================= + +void LLFloaterEditWater::syncControls() +{ + // *TODO: Eliminate slow getChild() calls. + + bool err; + + LLWaterParamManager& water_mgr = LLWaterParamManager::instance(); + + LLWaterParamSet& current_params = water_mgr.mCurParams; + + // blue horizon + water_mgr.mFogColor = current_params.getVector4(water_mgr.mFogColor.mName, err); + + LLColor4 col = water_mgr.getFogColor(); + //getChild<LLUICtrl>("WaterGlow")->setValue(col.mV[3]); + col.mV[3] = 1.0f; + getChild<LLColorSwatchCtrl>("WaterFogColor")->set(col); + + // fog and wavelets + water_mgr.mFogDensity.mExp = + log(current_params.getFloat(water_mgr.mFogDensity.mName, err)) / + log(water_mgr.mFogDensity.mBase); + water_mgr.setDensitySliderValue(water_mgr.mFogDensity.mExp); + getChild<LLUICtrl>("WaterFogDensity")->setValue(water_mgr.mFogDensity.mExp); + + water_mgr.mUnderWaterFogMod.mX = + current_params.getFloat(water_mgr.mUnderWaterFogMod.mName, err); + getChild<LLUICtrl>("WaterUnderWaterFogMod")->setValue(water_mgr.mUnderWaterFogMod.mX); + + water_mgr.mNormalScale = current_params.getVector3(water_mgr.mNormalScale.mName, err); + getChild<LLUICtrl>("WaterNormalScaleX")->setValue(water_mgr.mNormalScale.mX); + getChild<LLUICtrl>("WaterNormalScaleY")->setValue(water_mgr.mNormalScale.mY); + getChild<LLUICtrl>("WaterNormalScaleZ")->setValue(water_mgr.mNormalScale.mZ); + + // Fresnel + water_mgr.mFresnelScale.mX = current_params.getFloat(water_mgr.mFresnelScale.mName, err); + getChild<LLUICtrl>("WaterFresnelScale")->setValue(water_mgr.mFresnelScale.mX); + water_mgr.mFresnelOffset.mX = current_params.getFloat(water_mgr.mFresnelOffset.mName, err); + getChild<LLUICtrl>("WaterFresnelOffset")->setValue(water_mgr.mFresnelOffset.mX); + + // Scale Above/Below + water_mgr.mScaleAbove.mX = current_params.getFloat(water_mgr.mScaleAbove.mName, err); + getChild<LLUICtrl>("WaterScaleAbove")->setValue(water_mgr.mScaleAbove.mX); + water_mgr.mScaleBelow.mX = current_params.getFloat(water_mgr.mScaleBelow.mName, err); + getChild<LLUICtrl>("WaterScaleBelow")->setValue(water_mgr.mScaleBelow.mX); + + // blur mult + water_mgr.mBlurMultiplier.mX = current_params.getFloat(water_mgr.mBlurMultiplier.mName, err); + getChild<LLUICtrl>("WaterBlurMult")->setValue(water_mgr.mBlurMultiplier.mX); + + // wave directions + water_mgr.mWave1Dir = current_params.getVector2(water_mgr.mWave1Dir.mName, err); + getChild<LLUICtrl>("WaterWave1DirX")->setValue(water_mgr.mWave1Dir.mX); + getChild<LLUICtrl>("WaterWave1DirY")->setValue(water_mgr.mWave1Dir.mY); + + water_mgr.mWave2Dir = current_params.getVector2(water_mgr.mWave2Dir.mName, err); + getChild<LLUICtrl>("WaterWave2DirX")->setValue(water_mgr.mWave2Dir.mX); + getChild<LLUICtrl>("WaterWave2DirY")->setValue(water_mgr.mWave2Dir.mY); + + LLTextureCtrl* textCtrl = getChild<LLTextureCtrl>("WaterNormalMap"); + textCtrl->setImageAssetID(water_mgr.getNormalMapID()); +} + +// color control callbacks +void LLFloaterEditWater::onColorControlRMoved(LLUICtrl* ctrl, WaterColorControl* color_ctrl) +{ + LLSliderCtrl* sldr_ctrl = static_cast<LLSliderCtrl*>(ctrl); + + color_ctrl->mR = sldr_ctrl->getValueF32(); + + // move i if it's the max + if (color_ctrl->mR >= color_ctrl->mG + && color_ctrl->mR >= color_ctrl->mB + && color_ctrl->mHasSliderName) + { + color_ctrl->mI = color_ctrl->mR; + std::string name = color_ctrl->mSliderName; + name.append("I"); + + getChild<LLUICtrl>(name)->setValue(color_ctrl->mR); + } + + color_ctrl->update(LLWaterParamManager::getInstance()->mCurParams); + + LLWaterParamManager::getInstance()->propagateParameters(); +} + +void LLFloaterEditWater::onColorControlGMoved(LLUICtrl* ctrl, WaterColorControl* color_ctrl) +{ + LLSliderCtrl* sldr_ctrl = static_cast<LLSliderCtrl*>(ctrl); + + color_ctrl->mG = sldr_ctrl->getValueF32(); + + // move i if it's the max + if (color_ctrl->mG >= color_ctrl->mR + && color_ctrl->mG >= color_ctrl->mB + && color_ctrl->mHasSliderName) + { + color_ctrl->mI = color_ctrl->mG; + std::string name = color_ctrl->mSliderName; + name.append("I"); + + getChild<LLUICtrl>(name)->setValue(color_ctrl->mG); + + } + + color_ctrl->update(LLWaterParamManager::getInstance()->mCurParams); + + LLWaterParamManager::getInstance()->propagateParameters(); +} + +void LLFloaterEditWater::onColorControlBMoved(LLUICtrl* ctrl, WaterColorControl* color_ctrl) +{ + LLSliderCtrl* sldr_ctrl = static_cast<LLSliderCtrl*>(ctrl); + + color_ctrl->mB = sldr_ctrl->getValueF32(); + + // move i if it's the max + if (color_ctrl->mB >= color_ctrl->mR + && color_ctrl->mB >= color_ctrl->mG + && color_ctrl->mHasSliderName) + { + color_ctrl->mI = color_ctrl->mB; + std::string name = color_ctrl->mSliderName; + name.append("I"); + + getChild<LLUICtrl>(name)->setValue(color_ctrl->mB); + } + + color_ctrl->update(LLWaterParamManager::getInstance()->mCurParams); + + LLWaterParamManager::getInstance()->propagateParameters(); +} + +void LLFloaterEditWater::onColorControlAMoved(LLUICtrl* ctrl, WaterColorControl* color_ctrl) +{ + LLSliderCtrl* sldr_ctrl = static_cast<LLSliderCtrl*>(ctrl); + + color_ctrl->mA = sldr_ctrl->getValueF32(); + + color_ctrl->update(LLWaterParamManager::getInstance()->mCurParams); + + LLWaterParamManager::getInstance()->propagateParameters(); +} + + +void LLFloaterEditWater::onColorControlIMoved(LLUICtrl* ctrl, WaterColorControl* color_ctrl) +{ + LLSliderCtrl* sldr_ctrl = static_cast<LLSliderCtrl*>(ctrl); + + color_ctrl->mI = sldr_ctrl->getValueF32(); + + // only for sliders where we pass a name + if (color_ctrl->mHasSliderName) + { + // set it to the top + F32 maxVal = std::max(std::max(color_ctrl->mR, color_ctrl->mG), color_ctrl->mB); + F32 iVal; + + iVal = color_ctrl->mI; + + // get the names of the other sliders + std::string rName = color_ctrl->mSliderName; + rName.append("R"); + std::string gName = color_ctrl->mSliderName; + gName.append("G"); + std::string bName = color_ctrl->mSliderName; + bName.append("B"); + + // handle if at 0 + if (iVal == 0) + { + color_ctrl->mR = 0; + color_ctrl->mG = 0; + color_ctrl->mB = 0; + + // if all at the start + // set them all to the intensity + } + else if (maxVal == 0) + { + color_ctrl->mR = iVal; + color_ctrl->mG = iVal; + color_ctrl->mB = iVal; + } + else + { + // add delta amounts to each + F32 delta = (iVal - maxVal) / maxVal; + color_ctrl->mR *= (1.0f + delta); + color_ctrl->mG *= (1.0f + delta); + color_ctrl->mB *= (1.0f + delta); + } + + // set the sliders to the new vals + getChild<LLUICtrl>(rName)->setValue(color_ctrl->mR); + getChild<LLUICtrl>(gName)->setValue(color_ctrl->mG); + getChild<LLUICtrl>(bName)->setValue(color_ctrl->mB); + } + + // now update the current parameters and send them to shaders + color_ctrl->update(LLWaterParamManager::getInstance()->mCurParams); + LLWaterParamManager::getInstance()->propagateParameters(); +} + +// vector control callbacks +void LLFloaterEditWater::onVector3ControlXMoved(LLUICtrl* ctrl, WaterVector3Control* vector_ctrl) +{ + LLSliderCtrl* sldr_ctrl = static_cast<LLSliderCtrl*>(ctrl); + + vector_ctrl->mX = sldr_ctrl->getValueF32(); + + vector_ctrl->update(LLWaterParamManager::getInstance()->mCurParams); + + LLWaterParamManager::getInstance()->propagateParameters(); +} + +// vector control callbacks +void LLFloaterEditWater::onVector3ControlYMoved(LLUICtrl* ctrl, WaterVector3Control* vector_ctrl) +{ + LLSliderCtrl* sldr_ctrl = static_cast<LLSliderCtrl*>(ctrl); + + vector_ctrl->mY = sldr_ctrl->getValueF32(); + + vector_ctrl->update(LLWaterParamManager::getInstance()->mCurParams); + + LLWaterParamManager::getInstance()->propagateParameters(); +} + +// vector control callbacks +void LLFloaterEditWater::onVector3ControlZMoved(LLUICtrl* ctrl, WaterVector3Control* vector_ctrl) +{ + LLSliderCtrl* sldr_ctrl = static_cast<LLSliderCtrl*>(ctrl); + + vector_ctrl->mZ = sldr_ctrl->getValueF32(); + + vector_ctrl->update(LLWaterParamManager::getInstance()->mCurParams); + + LLWaterParamManager::getInstance()->propagateParameters(); +} + + +// vector control callbacks +void LLFloaterEditWater::onVector2ControlXMoved(LLUICtrl* ctrl, WaterVector2Control* vector_ctrl) +{ + LLSliderCtrl* sldr_ctrl = static_cast<LLSliderCtrl*>(ctrl); + + vector_ctrl->mX = sldr_ctrl->getValueF32(); + + vector_ctrl->update(LLWaterParamManager::getInstance()->mCurParams); + + LLWaterParamManager::getInstance()->propagateParameters(); +} + +// vector control callbacks +void LLFloaterEditWater::onVector2ControlYMoved(LLUICtrl* ctrl, WaterVector2Control* vector_ctrl) +{ + LLSliderCtrl* sldr_ctrl = static_cast<LLSliderCtrl*>(ctrl); + + vector_ctrl->mY = sldr_ctrl->getValueF32(); + + vector_ctrl->update(LLWaterParamManager::getInstance()->mCurParams); + + LLWaterParamManager::getInstance()->propagateParameters(); +} + +void LLFloaterEditWater::onFloatControlMoved(LLUICtrl* ctrl, WaterFloatControl* floatControl) +{ + LLSliderCtrl* sldr_ctrl = static_cast<LLSliderCtrl*>(ctrl); + + floatControl->mX = sldr_ctrl->getValueF32() / floatControl->mMult; + + floatControl->update(LLWaterParamManager::getInstance()->mCurParams); + LLWaterParamManager::getInstance()->propagateParameters(); +} + +void LLFloaterEditWater::onExpFloatControlMoved(LLUICtrl* ctrl, WaterExpFloatControl* expFloatControl) +{ + LLSliderCtrl* sldr_ctrl = static_cast<LLSliderCtrl*>(ctrl); + + F32 val = sldr_ctrl->getValueF32(); + expFloatControl->mExp = val; + LLWaterParamManager::getInstance()->setDensitySliderValue(val); + + expFloatControl->update(LLWaterParamManager::getInstance()->mCurParams); + LLWaterParamManager::getInstance()->propagateParameters(); +} + +void LLFloaterEditWater::onWaterFogColorMoved(LLUICtrl* ctrl, WaterColorControl* color_ctrl) +{ + LLColorSwatchCtrl* swatch = static_cast<LLColorSwatchCtrl*>(ctrl); + *color_ctrl = swatch->get(); + + color_ctrl->update(LLWaterParamManager::getInstance()->mCurParams); + LLWaterParamManager::getInstance()->propagateParameters(); +} + +void LLFloaterEditWater::onNormalMapPicked(LLUICtrl* ctrl) +{ + LLTextureCtrl* textCtrl = static_cast<LLTextureCtrl*>(ctrl); + LLUUID textID = textCtrl->getImageAssetID(); + LLWaterParamManager::getInstance()->setNormalMapID(textID); +} + +//============================================================================= + +void LLFloaterEditWater::reset() +{ + if (isNewPreset()) + { + mWaterPresetNameEditor->setValue(LLSD()); + mSaveButton->setEnabled(FALSE); // will be enabled as soon as users enters a name + } + else + { + refreshWaterPresetsList(); + + // Disable controls until a water preset to edit is selected. + enableEditing(false); + } +} + +bool LLFloaterEditWater::isNewPreset() const +{ + return mKey.asString() == "new"; +} + +void LLFloaterEditWater::refreshWaterPresetsList() +{ + mWaterPresetCombo->removeall(); + +#if 0 // *TODO: enable when we have a clear workflow to edit existing region environment + // If the region already has water params, add them to the list. + const LLEnvironmentSettings& region_settings = LLEnvManagerNew::instance().getRegionSettings(); + if (region_settings.getWaterParams().size() != 0) + { + const std::string& region_name = gAgent.getRegion()->getName(); + mWaterPresetCombo->add(region_name, LLSD().with(0, region_name).with(1, LLEnvKey::SCOPE_REGION)); + mWaterPresetCombo->addSeparator(); + } +#endif + + // Add local water presets. + const std::map<std::string, LLWaterParamSet> &water_params_map = LLWaterParamManager::instance().mParamList; + for (std::map<std::string, LLWaterParamSet>::const_iterator it = water_params_map.begin(); it != water_params_map.end(); it++) + { + mWaterPresetCombo->add(it->first, LLSD().with(0, it->first).with(1, LLEnvKey::SCOPE_LOCAL)); + } + + mWaterPresetCombo->setLabel(getString("combo_label")); +} + +void LLFloaterEditWater::enableEditing(bool enable) +{ + // Enable/disable water controls. + getChild<LLPanel>("panel_water_preset")->setCtrlsEnabled(enable); + + // Enable/disable saving. + mSaveButton->setEnabled(enable); + mMakeDefaultCheckBox->setEnabled(enable); +} + +void LLFloaterEditWater::saveRegionWater() +{ + llassert(getCurrentScope() == LLEnvKey::SCOPE_REGION); // make sure we're editing region water + + LL_DEBUGS("Windlight") << "Saving region water preset" << llendl; + + //LLWaterParamSet region_water = water_mgr.mCurParams; + + // *TODO: save to cached region settings. + LL_WARNS("Windlight") << "Saving region water is not fully implemented yet" << LL_ENDL; +} + +std::string LLFloaterEditWater::getCurrentPresetName() const +{ + std::string name; + LLEnvKey::EScope scope; + getSelectedPreset(name, scope); + return name; +} + +LLEnvKey::EScope LLFloaterEditWater::getCurrentScope() const +{ + std::string name; + LLEnvKey::EScope scope; + getSelectedPreset(name, scope); + return scope; +} + +void LLFloaterEditWater::getSelectedPreset(std::string& name, LLEnvKey::EScope& scope) const +{ + if (mWaterPresetNameEditor->getVisible()) + { + name = mWaterPresetNameEditor->getText(); + scope = LLEnvKey::SCOPE_LOCAL; + } + else + { + LLSD combo_val = mWaterPresetCombo->getValue(); + + if (!combo_val.isArray()) // manually typed text + { + name = combo_val.asString(); + scope = LLEnvKey::SCOPE_LOCAL; + } + else + { + name = combo_val[0].asString(); + scope = (LLEnvKey::EScope) combo_val[1].asInteger(); + } + } +} + +void LLFloaterEditWater::onWaterPresetNameEdited() +{ + // Disable saving a water preset having empty name. + mSaveButton->setEnabled(!getCurrentPresetName().empty()); +} + +void LLFloaterEditWater::onWaterPresetSelected() +{ + LLWaterParamSet water_params; + std::string name; + LLEnvKey::EScope scope; + + getSelectedPreset(name, scope); + + // Display selected preset. + if (scope == LLEnvKey::SCOPE_REGION) + { + water_params.setAll(LLEnvManagerNew::instance().getRegionSettings().getWaterParams()); + } + else // local preset selected + { + if (!LLWaterParamManager::instance().getParamSet(name, water_params)) + { + // Manually entered string? + LL_WARNS("Windlight") << "No water preset named " << name << LL_ENDL; + return; + } + } + + LLEnvManagerNew::instance().useWaterParams(water_params.getAll()); + + bool can_edit = (scope == LLEnvKey::SCOPE_LOCAL || LLEnvManagerNew::canEditRegionSettings()); + enableEditing(can_edit); + + mMakeDefaultCheckBox->setEnabled(scope == LLEnvKey::SCOPE_LOCAL); +} + +bool LLFloaterEditWater::onSaveAnswer(const LLSD& notification, const LLSD& response) +{ + S32 option = LLNotificationsUtil::getSelectedOption(notification, response); + + // If they choose save, do it. Otherwise, don't do anything + if (option == 0) + { + onSaveConfirmed(); + } + + return false; +} + +void LLFloaterEditWater::onSaveConfirmed() +{ + // Save currently displayed water params to the selected preset. + std::string name = getCurrentPresetName(); + + LL_DEBUGS("Windlight") << "Saving sky preset " << name << LL_ENDL; + LLWaterParamManager& water_mgr = LLWaterParamManager::instance(); + if (water_mgr.hasParamSet(name)) + { + water_mgr.setParamSet(name, water_mgr.mCurParams); + } + else + { + water_mgr.addParamSet(name, water_mgr.mCurParams); + } + + water_mgr.savePreset(name); + + // Change preference if requested. + if (mMakeDefaultCheckBox->getEnabled() && mMakeDefaultCheckBox->getValue()) + { + LL_DEBUGS("Windlight") << name << " is now the new preferred water preset" << llendl; + LLEnvManagerNew::instance().setUseWaterPreset(name); + } + + closeFloater(); +} + +void LLFloaterEditWater::onBtnSave() +{ + LLEnvKey::EScope scope; + std::string name; + getSelectedPreset(name, scope); + + if (scope == LLEnvKey::SCOPE_REGION) + { + saveRegionWater(); + closeFloater(); + return; + } + + if (name.empty()) + { + // *TODO: show an alert + llwarns << "Empty water preset name" << llendl; + return; + } + + // Don't allow overwriting system presets. + LLWaterParamManager& water_mgr = LLWaterParamManager::instance(); + if (water_mgr.isSystemPreset(name)) + { + LLNotificationsUtil::add("WLNoEditDefault"); + return; + } + + // Save, ask for confirmation for overwriting an existing preset. + if (water_mgr.hasParamSet(name)) + { + LLNotificationsUtil::add("WLSavePresetAlert", LLSD(), LLSD(), boost::bind(&LLFloaterEditWater::onSaveAnswer, this, _1, _2)); + } + else + { + // new preset, hence no confirmation needed + onSaveConfirmed(); + } } void LLFloaterEditWater::onBtnCancel() { closeFloater(); } + +void LLFloaterEditWater::onWaterPresetListChange() +{ + std::string name; + LLEnvKey::EScope scope; + getSelectedPreset(name, scope); // preset being edited + + if (scope == LLEnvKey::SCOPE_LOCAL && !LLWaterParamManager::instance().hasParamSet(name)) + { + // Preset we've been editing doesn't exist anymore. Close the floater. + closeFloater(false); + } + else + { + // A new preset has been added. + // Refresh the presets list, though it may not make sense as the floater is about to be closed. + refreshWaterPresetsList(); + } +} + +void LLFloaterEditWater::onRegionSettingsChange() +{ + // If creating a new preset, don't bother. + if (isNewPreset()) + { + return; + } + + if (getCurrentScope() == LLEnvKey::SCOPE_REGION) // if editing region water + { + // reset the floater to its initial state + reset(); + + // *TODO: Notify user? + } + else // editing a local preset + { + refreshWaterPresetsList(); + } +} + +void LLFloaterEditWater::onRegionInfoUpdate() +{ + bool can_edit = true; + + // If we've selected the region water for editing. + if (getCurrentScope() == LLEnvKey::SCOPE_REGION) + { + // check whether we have the access + can_edit = LLEnvManagerNew::canEditRegionSettings(); + } + + enableEditing(can_edit); +} diff --git a/indra/newview/llfloatereditwater.h b/indra/newview/llfloatereditwater.h index a904555787..2211bca59f 100644 --- a/indra/newview/llfloatereditwater.h +++ b/indra/newview/llfloatereditwater.h @@ -28,6 +28,18 @@ #define LL_LLFLOATEREDITWATER_H #include "llfloater.h" +#include "llenvmanager.h" // for LLEnvKey + +class LLButton; +class LLCheckBoxCtrl; +class LLComboBox; +class LLLineEditor; + +struct WaterVector2Control; +struct WaterVector3Control; +struct WaterColorControl; +struct WaterFloatControl; +struct WaterExpFloatControl; class LLFloaterEditWater : public LLFloater { @@ -38,8 +50,66 @@ public: /*virtual*/ BOOL postBuild(); /*virtual*/ void onOpen(const LLSD& key); + /*virtual*/ void onClose(bool app_quitting); + /*virtual*/ void draw(); + +private: + void initCallbacks(void); + + //-- WL stuff begins ------------------------------------------------------ + + void syncControls(); /// sync up sliders with parameters + + // general purpose callbacks for dealing with color controllers + void onColorControlRMoved(LLUICtrl* ctrl, WaterColorControl* color_ctrl); + void onColorControlGMoved(LLUICtrl* ctrl, WaterColorControl* color_ctrl); + void onColorControlBMoved(LLUICtrl* ctrl, WaterColorControl* color_ctrl); + void onColorControlAMoved(LLUICtrl* ctrl, WaterColorControl* color_ctrl); + void onColorControlIMoved(LLUICtrl* ctrl, WaterColorControl* color_ctrl); + + void onVector3ControlXMoved(LLUICtrl* ctrl, WaterVector3Control* vector_ctrl); + void onVector3ControlYMoved(LLUICtrl* ctrl, WaterVector3Control* vector_ctrl); + void onVector3ControlZMoved(LLUICtrl* ctrl, WaterVector3Control* vector_ctrl); + + void onVector2ControlXMoved(LLUICtrl* ctrl, WaterVector2Control* vector_ctrl); + void onVector2ControlYMoved(LLUICtrl* ctrl, WaterVector2Control* vector_ctrl); + + void onFloatControlMoved(LLUICtrl* ctrl, WaterFloatControl* floatControl); + void onExpFloatControlMoved(LLUICtrl* ctrl, WaterExpFloatControl* expFloatControl); + + void onWaterFogColorMoved(LLUICtrl* ctrl, WaterColorControl* color_ctrl); + + void onNormalMapPicked(LLUICtrl* ctrl); /// handle if they choose a new normal map + + //-- WL stuff ends -------------------------------------------------------- + + void reset(); + bool isNewPreset() const; + void refreshWaterPresetsList(); + void enableEditing(bool enable); + void saveRegionWater(); + + std::string getCurrentPresetName() const; + LLEnvKey::EScope getCurrentScope() const; + void getSelectedPreset(std::string& name, LLEnvKey::EScope& scope) const; + + void onWaterPresetNameEdited(); + void onWaterPresetSelected(); + bool onSaveAnswer(const LLSD& notification, const LLSD& response); + void onSaveConfirmed(); + + void onBtnSave(); void onBtnCancel(); + + void onWaterPresetListChange(); + void onRegionSettingsChange(); + void onRegionInfoUpdate(); + + LLLineEditor* mWaterPresetNameEditor; + LLComboBox* mWaterPresetCombo; + LLCheckBoxCtrl* mMakeDefaultCheckBox; + LLButton* mSaveButton; }; #endif // LL_LLFLOATEREDITWATER_H 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 5df807f740..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); - - // 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; + // First, load system (coming out of the box) water presets. + loadPresetsFromDir(getSysDir()); - 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; + llifstream xml_file; + std::string name(gDirUtilp->getBaseFileName(LLURI::unescape(path), /*strip_exten = */ true)); - escaped_filename += ".xml"; - - 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 @@ -387,6 +328,7 @@ bool LLWaterParamManager::addParamSet(const std::string& name, LLWaterParamSet& if(mIt == mParamList.end()) { mParamList[name] = param; + mPresetListChangeSignal(); return true; } @@ -395,17 +337,9 @@ bool LLWaterParamManager::addParamSet(const std::string& name, LLWaterParamSet& BOOL LLWaterParamManager::addParamSet(const std::string& name, LLSD const & param) { - // add a new one if not one there already - std::map<std::string, LLWaterParamSet>::const_iterator finder = mParamList.find(name); - if(finder == mParamList.end()) - { - mParamList[name].setAll(param); - return TRUE; - } - else - { - return FALSE; - } + LLWaterParamSet param_set; + param_set.setAll(param); + return addParamSet(name, param_set); } bool LLWaterParamManager::getParamSet(const std::string& name, LLWaterParamSet& param) @@ -422,6 +356,12 @@ bool LLWaterParamManager::getParamSet(const std::string& name, LLWaterParamSet& return false; } +bool LLWaterParamManager::hasParamSet(const std::string& name) +{ + LLWaterParamSet dummy; + return getParamSet(name, dummy); +} + bool LLWaterParamManager::setParamSet(const std::string& name, LLWaterParamSet& param) { mParamList[name] = param; @@ -445,29 +385,40 @@ 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; } +bool LLWaterParamManager::isSystemPreset(const std::string& preset_name) +{ + // *TODO: file system access is excessive here. + return gDirUtilp->fileExists(getSysDir() + LLURI::escape(preset_name) + ".xml"); +} + +boost::signals2::connection LLWaterParamManager::setPresetListChangeCallback(const preset_list_signal_t::slot_type& cb) +{ + return mPresetListChangeSignal.connect(cb); +} + F32 LLWaterParamManager::getFogDensity(void) { bool err; @@ -490,6 +441,18 @@ F32 LLWaterParamManager::getFogDensity(void) void LLWaterParamManager::initSingleton() { LL_DEBUGS("Windlight") << "Initializing water" << LL_ENDL; - loadAllPresets(LLStringUtil::null); + loadAllPresets(); applyUserPrefs(false); } + +// static +std::string LLWaterParamManager::getSysDir() +{ + return gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "windlight/water", ""); +} + +// static +std::string LLWaterParamManager::getUserDir() +{ + return gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS , "windlight/water", ""); +} diff --git a/indra/newview/llwaterparammanager.h b/indra/newview/llwaterparammanager.h index fcf1f8e23d..1f599f57dc 100644 --- a/indra/newview/llwaterparammanager.h +++ b/indra/newview/llwaterparammanager.h @@ -216,13 +216,7 @@ class LLWaterParamManager : public LLSingleton<LLWaterParamManager> { LOG_CLASS(LLWaterParamManager); public: - - /// 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); + typedef boost::signals2::signal<void()> preset_list_signal_t; /// save the parameter presets to file void savePreset(const std::string & name); @@ -248,6 +242,9 @@ public: /// get a param from the list bool getParamSet(const std::string& name, LLWaterParamSet& param); + /// check whether the preset is in the list + bool hasParamSet(const std::string& name); + /// set the param in the list with a new param bool setParamSet(const std::string& name, LLWaterParamSet& param); @@ -258,6 +255,12 @@ public: /// returns true if successful bool removeParamSet(const std::string& name, bool delete_from_disk); + /// @return true if the preset comes out of the box + bool isSystemPreset(const std::string& preset_name); + + /// Emitted when a preset gets added or deleted. + boost::signals2::connection setPresetListChangeCallback(const preset_list_signal_t::slot_type& cb); + /// set the normap map we want for water bool setNormalMapID(const LLUUID& img); @@ -308,8 +311,17 @@ 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(); + LLVector4 mWaterPlane; F32 mWaterFogKS; + + preset_list_signal_t mPresetListChangeSignal; }; inline void LLWaterParamManager::setDensitySliderValue(F32 val) diff --git a/indra/newview/llwlparammanager.h b/indra/newview/llwlparammanager.h index 73bf97f392..8e1e0ddaff 100644 --- a/indra/newview/llwlparammanager.h +++ b/indra/newview/llwlparammanager.h @@ -270,7 +270,7 @@ public: /// get a param set (preset) from the list bool getParamSet(const LLWLParamKey& key, LLWLParamSet& param); - /// get a param set (preset) from the list + /// check whether the preset is in the list bool hasParamSet(const LLWLParamKey& key); /// set the param in the list with a new param diff --git a/indra/newview/skins/default/xui/en/floater_edit_water_preset.xml b/indra/newview/skins/default/xui/en/floater_edit_water_preset.xml index 77484bcfea..7d7e170c1e 100644 --- a/indra/newview/skins/default/xui/en/floater_edit_water_preset.xml +++ b/indra/newview/skins/default/xui/en/floater_edit_water_preset.xml @@ -13,6 +13,7 @@ <string name="title_edit">Edit a Water Preset</string> <string name="hint_new">Name your preset, adjust the controls to create it, and click "Save".</string> <string name="hint_edit">To edit your water preset, adjust the controls and click "Save".</string> + <string name="combo_label">-Select a preset-</string> <text follows="top|left|right" @@ -45,12 +46,14 @@ max_chars="100" name="water_preset_combo" top_delta="-5" - width="200"> - <combo_box.item - label="-Select a preset-" - name="item0" - value="any" /> - </combo_box> + width="200"/> + + <line_editor + height="20" + left_delta="0" + name="water_preset_name" + top_delta="0" + width="200" /> <text follows="top|left|right" @@ -115,9 +118,9 @@ layout="topleft" left_delta="-15" top_pad="0" - name="water_fog_destiny_label" + name="water_fog_density_label" width="200"> - Fog Destiny Exponent + Fog Density Exponent </text> <slider decimal_digits="1" @@ -127,7 +130,7 @@ layout="topleft" left_delta="15" max_val="10" - name="fog_destiny_exponent" + name="WaterFogDensity" top_pad="10" width="200"/> @@ -140,7 +143,7 @@ top_pad="15" name="underwater_fog_modifier_label" width="200"> - Underwater For Modifier + Underwater Fog Modifier </text> <slider decimal_digits="1" @@ -150,7 +153,7 @@ layout="topleft" left_delta="15" max_val="10" - name="underwater_fog_modifier" + name="WaterUnderWaterFogMod" top_pad="10" width="200"/> @@ -175,7 +178,7 @@ layout="topleft" max_val="4" min_val="-4" - name="water_wave_direction_x" + name="WaterWave1DirX" top_pad="10" width="216"/> <slider @@ -188,7 +191,7 @@ layout="topleft" max_val="4" min_val="-4" - name="water_wave_direction_y" + name="WaterWave1DirY" top_pad="5" width="216"/> @@ -421,7 +424,7 @@ label="Make this preset my new water setting" layout="topleft" left="430" - name="new_water_preset_chb" + name="make_default_cb" top_pad="30" width="280"/> |