PageRenderTime 36ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llfloatereditwater.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 772 lines | 513 code | 160 blank | 99 comment | 54 complexity | f68aa3ad4722d4531ebdea8c7a92df95 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llfloatereditwater.cpp
  3. * @brief Floater to create or edit a water preset
  4. *
  5. * $LicenseInfo:firstyear=2011&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2011, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #include "llviewerprecompiledheaders.h"
  27. #include "llfloatereditwater.h"
  28. // libs
  29. #include "llbutton.h"
  30. #include "llcheckboxctrl.h"
  31. #include "llcolorswatch.h"
  32. #include "llcombobox.h"
  33. //#include "llnotifications.h"
  34. #include "llnotificationsutil.h"
  35. #include "llsliderctrl.h"
  36. #include "lltexturectrl.h"
  37. // newview
  38. #include "llagent.h"
  39. #include "llregioninfomodel.h"
  40. #include "llviewerregion.h"
  41. #include "llwaterparammanager.h"
  42. #undef max // Fixes a Windows compiler error
  43. LLFloaterEditWater::LLFloaterEditWater(const LLSD &key)
  44. : LLFloater(key)
  45. , mWaterPresetNameEditor(NULL)
  46. , mWaterPresetCombo(NULL)
  47. , mMakeDefaultCheckBox(NULL)
  48. , mSaveButton(NULL)
  49. {
  50. }
  51. // virtual
  52. BOOL LLFloaterEditWater::postBuild()
  53. {
  54. mWaterPresetNameEditor = getChild<LLLineEditor>("water_preset_name");
  55. mWaterPresetCombo = getChild<LLComboBox>("water_preset_combo");
  56. mMakeDefaultCheckBox = getChild<LLCheckBoxCtrl>("make_default_cb");
  57. mSaveButton = getChild<LLButton>("save");
  58. initCallbacks();
  59. refreshWaterPresetsList();
  60. syncControls();
  61. return TRUE;
  62. }
  63. // virtual
  64. void LLFloaterEditWater::onOpen(const LLSD& key)
  65. {
  66. bool new_preset = isNewPreset();
  67. std::string param = key.asString();
  68. std::string floater_title = getString(std::string("title_") + param);
  69. std::string hint = getString(std::string("hint_" + param));
  70. // Update floater title.
  71. setTitle(floater_title);
  72. // Update the hint at the top.
  73. getChild<LLUICtrl>("hint")->setValue(hint);
  74. // Hide the hint to the right of the combo if we're invoked to create a new preset.
  75. getChildView("note")->setVisible(!new_preset);
  76. // Switch between the water presets combobox and preset name input field.
  77. mWaterPresetCombo->setVisible(!new_preset);
  78. mWaterPresetNameEditor->setVisible(new_preset);
  79. reset();
  80. }
  81. // virtual
  82. void LLFloaterEditWater::onClose(bool app_quitting)
  83. {
  84. if (!app_quitting) // there's no point to change environment if we're quitting
  85. {
  86. LLEnvManagerNew::instance().usePrefs(); // revert changes made to current environment
  87. }
  88. }
  89. // virtual
  90. void LLFloaterEditWater::draw()
  91. {
  92. syncControls();
  93. LLFloater::draw();
  94. }
  95. void LLFloaterEditWater::initCallbacks(void)
  96. {
  97. mWaterPresetNameEditor->setKeystrokeCallback(boost::bind(&LLFloaterEditWater::onWaterPresetNameEdited, this), NULL);
  98. mWaterPresetCombo->setCommitCallback(boost::bind(&LLFloaterEditWater::onWaterPresetSelected, this));
  99. mWaterPresetCombo->setTextEntryCallback(boost::bind(&LLFloaterEditWater::onWaterPresetNameEdited, this));
  100. mSaveButton->setCommitCallback(boost::bind(&LLFloaterEditWater::onBtnSave, this));
  101. getChild<LLButton>("cancel")->setCommitCallback(boost::bind(&LLFloaterEditWater::onBtnCancel, this));
  102. LLEnvManagerNew::instance().setRegionSettingsChangeCallback(boost::bind(&LLFloaterEditWater::onRegionSettingsChange, this));
  103. LLWaterParamManager::instance().setPresetListChangeCallback(boost::bind(&LLFloaterEditWater::onWaterPresetListChange, this));
  104. // Connect to region info updates.
  105. LLRegionInfoModel::instance().setUpdateCallback(boost::bind(&LLFloaterEditWater::onRegionInfoUpdate, this));
  106. //-------------------------------------------------------------------------
  107. LLWaterParamManager& water_mgr = LLWaterParamManager::instance();
  108. getChild<LLUICtrl>("WaterFogColor")->setCommitCallback(boost::bind(&LLFloaterEditWater::onWaterFogColorMoved, this, _1, &water_mgr.mFogColor));
  109. //getChild<LLUICtrl>("WaterGlow")->setCommitCallback(boost::bind(&LLFloaterEditWater::onColorControlAMoved, this, _1, &water_mgr.mFogColor));
  110. // fog density
  111. getChild<LLUICtrl>("WaterFogDensity")->setCommitCallback(boost::bind(&LLFloaterEditWater::onExpFloatControlMoved, this, _1, &water_mgr.mFogDensity));
  112. getChild<LLUICtrl>("WaterUnderWaterFogMod")->setCommitCallback(boost::bind(&LLFloaterEditWater::onFloatControlMoved, this, _1, &water_mgr.mUnderWaterFogMod));
  113. // blue density
  114. getChild<LLUICtrl>("WaterNormalScaleX")->setCommitCallback(boost::bind(&LLFloaterEditWater::onVector3ControlXMoved, this, _1, &water_mgr.mNormalScale));
  115. getChild<LLUICtrl>("WaterNormalScaleY")->setCommitCallback(boost::bind(&LLFloaterEditWater::onVector3ControlYMoved, this, _1, &water_mgr.mNormalScale));
  116. getChild<LLUICtrl>("WaterNormalScaleZ")->setCommitCallback(boost::bind(&LLFloaterEditWater::onVector3ControlZMoved, this, _1, &water_mgr.mNormalScale));
  117. // fresnel
  118. getChild<LLUICtrl>("WaterFresnelScale")->setCommitCallback(boost::bind(&LLFloaterEditWater::onFloatControlMoved, this, _1, &water_mgr.mFresnelScale));
  119. getChild<LLUICtrl>("WaterFresnelOffset")->setCommitCallback(boost::bind(&LLFloaterEditWater::onFloatControlMoved, this, _1, &water_mgr.mFresnelOffset));
  120. // scale above/below
  121. getChild<LLUICtrl>("WaterScaleAbove")->setCommitCallback(boost::bind(&LLFloaterEditWater::onFloatControlMoved, this, _1, &water_mgr.mScaleAbove));
  122. getChild<LLUICtrl>("WaterScaleBelow")->setCommitCallback(boost::bind(&LLFloaterEditWater::onFloatControlMoved, this, _1, &water_mgr.mScaleBelow));
  123. // blur mult
  124. getChild<LLUICtrl>("WaterBlurMult")->setCommitCallback(boost::bind(&LLFloaterEditWater::onFloatControlMoved, this, _1, &water_mgr.mBlurMultiplier));
  125. // wave direction
  126. getChild<LLUICtrl>("WaterWave1DirX")->setCommitCallback(boost::bind(&LLFloaterEditWater::onVector2ControlXMoved, this, _1, &water_mgr.mWave1Dir));
  127. getChild<LLUICtrl>("WaterWave1DirY")->setCommitCallback(boost::bind(&LLFloaterEditWater::onVector2ControlYMoved, this, _1, &water_mgr.mWave1Dir));
  128. getChild<LLUICtrl>("WaterWave2DirX")->setCommitCallback(boost::bind(&LLFloaterEditWater::onVector2ControlXMoved, this, _1, &water_mgr.mWave2Dir));
  129. getChild<LLUICtrl>("WaterWave2DirY")->setCommitCallback(boost::bind(&LLFloaterEditWater::onVector2ControlYMoved, this, _1, &water_mgr.mWave2Dir));
  130. LLTextureCtrl* texture_ctrl = getChild<LLTextureCtrl>("WaterNormalMap");
  131. texture_ctrl->setDefaultImageAssetID(DEFAULT_WATER_NORMAL);
  132. texture_ctrl->setCommitCallback(boost::bind(&LLFloaterEditWater::onNormalMapPicked, this, _1));
  133. }
  134. //=============================================================================
  135. void LLFloaterEditWater::syncControls()
  136. {
  137. // *TODO: Eliminate slow getChild() calls.
  138. bool err;
  139. LLWaterParamManager& water_mgr = LLWaterParamManager::instance();
  140. LLWaterParamSet& current_params = water_mgr.mCurParams;
  141. // blue horizon
  142. water_mgr.mFogColor = current_params.getVector4(water_mgr.mFogColor.mName, err);
  143. LLColor4 col = water_mgr.getFogColor();
  144. //getChild<LLUICtrl>("WaterGlow")->setValue(col.mV[3]);
  145. col.mV[3] = 1.0f;
  146. getChild<LLColorSwatchCtrl>("WaterFogColor")->set(col);
  147. // fog and wavelets
  148. water_mgr.mFogDensity.mExp =
  149. log(current_params.getFloat(water_mgr.mFogDensity.mName, err)) /
  150. log(water_mgr.mFogDensity.mBase);
  151. water_mgr.setDensitySliderValue(water_mgr.mFogDensity.mExp);
  152. getChild<LLUICtrl>("WaterFogDensity")->setValue(water_mgr.mFogDensity.mExp);
  153. water_mgr.mUnderWaterFogMod.mX =
  154. current_params.getFloat(water_mgr.mUnderWaterFogMod.mName, err);
  155. getChild<LLUICtrl>("WaterUnderWaterFogMod")->setValue(water_mgr.mUnderWaterFogMod.mX);
  156. water_mgr.mNormalScale = current_params.getVector3(water_mgr.mNormalScale.mName, err);
  157. getChild<LLUICtrl>("WaterNormalScaleX")->setValue(water_mgr.mNormalScale.mX);
  158. getChild<LLUICtrl>("WaterNormalScaleY")->setValue(water_mgr.mNormalScale.mY);
  159. getChild<LLUICtrl>("WaterNormalScaleZ")->setValue(water_mgr.mNormalScale.mZ);
  160. // Fresnel
  161. water_mgr.mFresnelScale.mX = current_params.getFloat(water_mgr.mFresnelScale.mName, err);
  162. getChild<LLUICtrl>("WaterFresnelScale")->setValue(water_mgr.mFresnelScale.mX);
  163. water_mgr.mFresnelOffset.mX = current_params.getFloat(water_mgr.mFresnelOffset.mName, err);
  164. getChild<LLUICtrl>("WaterFresnelOffset")->setValue(water_mgr.mFresnelOffset.mX);
  165. // Scale Above/Below
  166. water_mgr.mScaleAbove.mX = current_params.getFloat(water_mgr.mScaleAbove.mName, err);
  167. getChild<LLUICtrl>("WaterScaleAbove")->setValue(water_mgr.mScaleAbove.mX);
  168. water_mgr.mScaleBelow.mX = current_params.getFloat(water_mgr.mScaleBelow.mName, err);
  169. getChild<LLUICtrl>("WaterScaleBelow")->setValue(water_mgr.mScaleBelow.mX);
  170. // blur mult
  171. water_mgr.mBlurMultiplier.mX = current_params.getFloat(water_mgr.mBlurMultiplier.mName, err);
  172. getChild<LLUICtrl>("WaterBlurMult")->setValue(water_mgr.mBlurMultiplier.mX);
  173. // wave directions
  174. water_mgr.mWave1Dir = current_params.getVector2(water_mgr.mWave1Dir.mName, err);
  175. getChild<LLUICtrl>("WaterWave1DirX")->setValue(water_mgr.mWave1Dir.mX);
  176. getChild<LLUICtrl>("WaterWave1DirY")->setValue(water_mgr.mWave1Dir.mY);
  177. water_mgr.mWave2Dir = current_params.getVector2(water_mgr.mWave2Dir.mName, err);
  178. getChild<LLUICtrl>("WaterWave2DirX")->setValue(water_mgr.mWave2Dir.mX);
  179. getChild<LLUICtrl>("WaterWave2DirY")->setValue(water_mgr.mWave2Dir.mY);
  180. LLTextureCtrl* textCtrl = getChild<LLTextureCtrl>("WaterNormalMap");
  181. textCtrl->setImageAssetID(water_mgr.getNormalMapID());
  182. }
  183. // color control callbacks
  184. void LLFloaterEditWater::onColorControlRMoved(LLUICtrl* ctrl, WaterColorControl* color_ctrl)
  185. {
  186. LLSliderCtrl* sldr_ctrl = static_cast<LLSliderCtrl*>(ctrl);
  187. color_ctrl->mR = sldr_ctrl->getValueF32();
  188. // move i if it's the max
  189. if (color_ctrl->mR >= color_ctrl->mG
  190. && color_ctrl->mR >= color_ctrl->mB
  191. && color_ctrl->mHasSliderName)
  192. {
  193. color_ctrl->mI = color_ctrl->mR;
  194. std::string name = color_ctrl->mSliderName;
  195. name.append("I");
  196. getChild<LLUICtrl>(name)->setValue(color_ctrl->mR);
  197. }
  198. color_ctrl->update(LLWaterParamManager::getInstance()->mCurParams);
  199. LLWaterParamManager::getInstance()->propagateParameters();
  200. }
  201. void LLFloaterEditWater::onColorControlGMoved(LLUICtrl* ctrl, WaterColorControl* color_ctrl)
  202. {
  203. LLSliderCtrl* sldr_ctrl = static_cast<LLSliderCtrl*>(ctrl);
  204. color_ctrl->mG = sldr_ctrl->getValueF32();
  205. // move i if it's the max
  206. if (color_ctrl->mG >= color_ctrl->mR
  207. && color_ctrl->mG >= color_ctrl->mB
  208. && color_ctrl->mHasSliderName)
  209. {
  210. color_ctrl->mI = color_ctrl->mG;
  211. std::string name = color_ctrl->mSliderName;
  212. name.append("I");
  213. getChild<LLUICtrl>(name)->setValue(color_ctrl->mG);
  214. }
  215. color_ctrl->update(LLWaterParamManager::getInstance()->mCurParams);
  216. LLWaterParamManager::getInstance()->propagateParameters();
  217. }
  218. void LLFloaterEditWater::onColorControlBMoved(LLUICtrl* ctrl, WaterColorControl* color_ctrl)
  219. {
  220. LLSliderCtrl* sldr_ctrl = static_cast<LLSliderCtrl*>(ctrl);
  221. color_ctrl->mB = sldr_ctrl->getValueF32();
  222. // move i if it's the max
  223. if (color_ctrl->mB >= color_ctrl->mR
  224. && color_ctrl->mB >= color_ctrl->mG
  225. && color_ctrl->mHasSliderName)
  226. {
  227. color_ctrl->mI = color_ctrl->mB;
  228. std::string name = color_ctrl->mSliderName;
  229. name.append("I");
  230. getChild<LLUICtrl>(name)->setValue(color_ctrl->mB);
  231. }
  232. color_ctrl->update(LLWaterParamManager::getInstance()->mCurParams);
  233. LLWaterParamManager::getInstance()->propagateParameters();
  234. }
  235. void LLFloaterEditWater::onColorControlAMoved(LLUICtrl* ctrl, WaterColorControl* color_ctrl)
  236. {
  237. LLSliderCtrl* sldr_ctrl = static_cast<LLSliderCtrl*>(ctrl);
  238. color_ctrl->mA = sldr_ctrl->getValueF32();
  239. color_ctrl->update(LLWaterParamManager::getInstance()->mCurParams);
  240. LLWaterParamManager::getInstance()->propagateParameters();
  241. }
  242. void LLFloaterEditWater::onColorControlIMoved(LLUICtrl* ctrl, WaterColorControl* color_ctrl)
  243. {
  244. LLSliderCtrl* sldr_ctrl = static_cast<LLSliderCtrl*>(ctrl);
  245. color_ctrl->mI = sldr_ctrl->getValueF32();
  246. // only for sliders where we pass a name
  247. if (color_ctrl->mHasSliderName)
  248. {
  249. // set it to the top
  250. F32 maxVal = std::max(std::max(color_ctrl->mR, color_ctrl->mG), color_ctrl->mB);
  251. F32 iVal;
  252. iVal = color_ctrl->mI;
  253. // get the names of the other sliders
  254. std::string rName = color_ctrl->mSliderName;
  255. rName.append("R");
  256. std::string gName = color_ctrl->mSliderName;
  257. gName.append("G");
  258. std::string bName = color_ctrl->mSliderName;
  259. bName.append("B");
  260. // handle if at 0
  261. if (iVal == 0)
  262. {
  263. color_ctrl->mR = 0;
  264. color_ctrl->mG = 0;
  265. color_ctrl->mB = 0;
  266. // if all at the start
  267. // set them all to the intensity
  268. }
  269. else if (maxVal == 0)
  270. {
  271. color_ctrl->mR = iVal;
  272. color_ctrl->mG = iVal;
  273. color_ctrl->mB = iVal;
  274. }
  275. else
  276. {
  277. // add delta amounts to each
  278. F32 delta = (iVal - maxVal) / maxVal;
  279. color_ctrl->mR *= (1.0f + delta);
  280. color_ctrl->mG *= (1.0f + delta);
  281. color_ctrl->mB *= (1.0f + delta);
  282. }
  283. // set the sliders to the new vals
  284. getChild<LLUICtrl>(rName)->setValue(color_ctrl->mR);
  285. getChild<LLUICtrl>(gName)->setValue(color_ctrl->mG);
  286. getChild<LLUICtrl>(bName)->setValue(color_ctrl->mB);
  287. }
  288. // now update the current parameters and send them to shaders
  289. color_ctrl->update(LLWaterParamManager::getInstance()->mCurParams);
  290. LLWaterParamManager::getInstance()->propagateParameters();
  291. }
  292. // vector control callbacks
  293. void LLFloaterEditWater::onVector3ControlXMoved(LLUICtrl* ctrl, WaterVector3Control* vector_ctrl)
  294. {
  295. LLSliderCtrl* sldr_ctrl = static_cast<LLSliderCtrl*>(ctrl);
  296. vector_ctrl->mX = sldr_ctrl->getValueF32();
  297. vector_ctrl->update(LLWaterParamManager::getInstance()->mCurParams);
  298. LLWaterParamManager::getInstance()->propagateParameters();
  299. }
  300. // vector control callbacks
  301. void LLFloaterEditWater::onVector3ControlYMoved(LLUICtrl* ctrl, WaterVector3Control* vector_ctrl)
  302. {
  303. LLSliderCtrl* sldr_ctrl = static_cast<LLSliderCtrl*>(ctrl);
  304. vector_ctrl->mY = sldr_ctrl->getValueF32();
  305. vector_ctrl->update(LLWaterParamManager::getInstance()->mCurParams);
  306. LLWaterParamManager::getInstance()->propagateParameters();
  307. }
  308. // vector control callbacks
  309. void LLFloaterEditWater::onVector3ControlZMoved(LLUICtrl* ctrl, WaterVector3Control* vector_ctrl)
  310. {
  311. LLSliderCtrl* sldr_ctrl = static_cast<LLSliderCtrl*>(ctrl);
  312. vector_ctrl->mZ = sldr_ctrl->getValueF32();
  313. vector_ctrl->update(LLWaterParamManager::getInstance()->mCurParams);
  314. LLWaterParamManager::getInstance()->propagateParameters();
  315. }
  316. // vector control callbacks
  317. void LLFloaterEditWater::onVector2ControlXMoved(LLUICtrl* ctrl, WaterVector2Control* vector_ctrl)
  318. {
  319. LLSliderCtrl* sldr_ctrl = static_cast<LLSliderCtrl*>(ctrl);
  320. vector_ctrl->mX = sldr_ctrl->getValueF32();
  321. vector_ctrl->update(LLWaterParamManager::getInstance()->mCurParams);
  322. LLWaterParamManager::getInstance()->propagateParameters();
  323. }
  324. // vector control callbacks
  325. void LLFloaterEditWater::onVector2ControlYMoved(LLUICtrl* ctrl, WaterVector2Control* vector_ctrl)
  326. {
  327. LLSliderCtrl* sldr_ctrl = static_cast<LLSliderCtrl*>(ctrl);
  328. vector_ctrl->mY = sldr_ctrl->getValueF32();
  329. vector_ctrl->update(LLWaterParamManager::getInstance()->mCurParams);
  330. LLWaterParamManager::getInstance()->propagateParameters();
  331. }
  332. void LLFloaterEditWater::onFloatControlMoved(LLUICtrl* ctrl, WaterFloatControl* floatControl)
  333. {
  334. LLSliderCtrl* sldr_ctrl = static_cast<LLSliderCtrl*>(ctrl);
  335. floatControl->mX = sldr_ctrl->getValueF32() / floatControl->mMult;
  336. floatControl->update(LLWaterParamManager::getInstance()->mCurParams);
  337. LLWaterParamManager::getInstance()->propagateParameters();
  338. }
  339. void LLFloaterEditWater::onExpFloatControlMoved(LLUICtrl* ctrl, WaterExpFloatControl* expFloatControl)
  340. {
  341. LLSliderCtrl* sldr_ctrl = static_cast<LLSliderCtrl*>(ctrl);
  342. F32 val = sldr_ctrl->getValueF32();
  343. expFloatControl->mExp = val;
  344. LLWaterParamManager::getInstance()->setDensitySliderValue(val);
  345. expFloatControl->update(LLWaterParamManager::getInstance()->mCurParams);
  346. LLWaterParamManager::getInstance()->propagateParameters();
  347. }
  348. void LLFloaterEditWater::onWaterFogColorMoved(LLUICtrl* ctrl, WaterColorControl* color_ctrl)
  349. {
  350. LLColorSwatchCtrl* swatch = static_cast<LLColorSwatchCtrl*>(ctrl);
  351. *color_ctrl = swatch->get();
  352. color_ctrl->update(LLWaterParamManager::getInstance()->mCurParams);
  353. LLWaterParamManager::getInstance()->propagateParameters();
  354. }
  355. void LLFloaterEditWater::onNormalMapPicked(LLUICtrl* ctrl)
  356. {
  357. LLTextureCtrl* textCtrl = static_cast<LLTextureCtrl*>(ctrl);
  358. LLUUID textID = textCtrl->getImageAssetID();
  359. LLWaterParamManager::getInstance()->setNormalMapID(textID);
  360. }
  361. //=============================================================================
  362. void LLFloaterEditWater::reset()
  363. {
  364. if (isNewPreset())
  365. {
  366. mWaterPresetNameEditor->setValue(LLSD());
  367. mSaveButton->setEnabled(FALSE); // will be enabled as soon as users enters a name
  368. }
  369. else
  370. {
  371. refreshWaterPresetsList();
  372. // Disable controls until a water preset to edit is selected.
  373. enableEditing(false);
  374. }
  375. }
  376. bool LLFloaterEditWater::isNewPreset() const
  377. {
  378. return mKey.asString() == "new";
  379. }
  380. void LLFloaterEditWater::refreshWaterPresetsList()
  381. {
  382. mWaterPresetCombo->removeall();
  383. #if 0 // *TODO: enable when we have a clear workflow to edit existing region environment
  384. // If the region already has water params, add them to the list.
  385. const LLEnvironmentSettings& region_settings = LLEnvManagerNew::instance().getRegionSettings();
  386. if (region_settings.getWaterParams().size() != 0)
  387. {
  388. const std::string& region_name = gAgent.getRegion()->getName();
  389. mWaterPresetCombo->add(region_name, LLSD().with(0, region_name).with(1, LLEnvKey::SCOPE_REGION));
  390. mWaterPresetCombo->addSeparator();
  391. }
  392. #endif
  393. std::list<std::string> user_presets, system_presets;
  394. LLWaterParamManager::instance().getPresetNames(user_presets, system_presets);
  395. // Add local user presets first.
  396. for (std::list<std::string>::const_iterator it = user_presets.begin(); it != user_presets.end(); ++it)
  397. {
  398. const std::string& name = *it;
  399. mWaterPresetCombo->add(name, LLSD().with(0, name).with(1, LLEnvKey::SCOPE_LOCAL)); // [<name>, <scope>]
  400. }
  401. if (user_presets.size() > 0)
  402. {
  403. mWaterPresetCombo->addSeparator();
  404. }
  405. // Add local system presets.
  406. for (std::list<std::string>::const_iterator it = system_presets.begin(); it != system_presets.end(); ++it)
  407. {
  408. const std::string& name = *it;
  409. mWaterPresetCombo->add(name, LLSD().with(0, name).with(1, LLEnvKey::SCOPE_LOCAL)); // [<name>, <scope>]
  410. }
  411. mWaterPresetCombo->setLabel(getString("combo_label"));
  412. }
  413. void LLFloaterEditWater::enableEditing(bool enable)
  414. {
  415. // Enable/disable water controls.
  416. getChild<LLPanel>("panel_water_preset")->setCtrlsEnabled(enable);
  417. // Enable/disable saving.
  418. mSaveButton->setEnabled(enable);
  419. mMakeDefaultCheckBox->setEnabled(enable);
  420. }
  421. void LLFloaterEditWater::saveRegionWater()
  422. {
  423. llassert(getCurrentScope() == LLEnvKey::SCOPE_REGION); // make sure we're editing region water
  424. LL_DEBUGS("Windlight") << "Saving region water preset" << llendl;
  425. //LLWaterParamSet region_water = water_mgr.mCurParams;
  426. // *TODO: save to cached region settings.
  427. LL_WARNS("Windlight") << "Saving region water is not fully implemented yet" << LL_ENDL;
  428. }
  429. std::string LLFloaterEditWater::getCurrentPresetName() const
  430. {
  431. std::string name;
  432. LLEnvKey::EScope scope;
  433. getSelectedPreset(name, scope);
  434. return name;
  435. }
  436. LLEnvKey::EScope LLFloaterEditWater::getCurrentScope() const
  437. {
  438. std::string name;
  439. LLEnvKey::EScope scope;
  440. getSelectedPreset(name, scope);
  441. return scope;
  442. }
  443. void LLFloaterEditWater::getSelectedPreset(std::string& name, LLEnvKey::EScope& scope) const
  444. {
  445. if (mWaterPresetNameEditor->getVisible())
  446. {
  447. name = mWaterPresetNameEditor->getText();
  448. scope = LLEnvKey::SCOPE_LOCAL;
  449. }
  450. else
  451. {
  452. LLSD combo_val = mWaterPresetCombo->getValue();
  453. if (!combo_val.isArray()) // manually typed text
  454. {
  455. name = combo_val.asString();
  456. scope = LLEnvKey::SCOPE_LOCAL;
  457. }
  458. else
  459. {
  460. name = combo_val[0].asString();
  461. scope = (LLEnvKey::EScope) combo_val[1].asInteger();
  462. }
  463. }
  464. }
  465. void LLFloaterEditWater::onWaterPresetNameEdited()
  466. {
  467. // Disable saving a water preset having empty name.
  468. mSaveButton->setEnabled(!getCurrentPresetName().empty());
  469. }
  470. void LLFloaterEditWater::onWaterPresetSelected()
  471. {
  472. LLWaterParamSet water_params;
  473. std::string name;
  474. LLEnvKey::EScope scope;
  475. getSelectedPreset(name, scope);
  476. // Display selected preset.
  477. if (scope == LLEnvKey::SCOPE_REGION)
  478. {
  479. water_params.setAll(LLEnvManagerNew::instance().getRegionSettings().getWaterParams());
  480. }
  481. else // local preset selected
  482. {
  483. if (!LLWaterParamManager::instance().getParamSet(name, water_params))
  484. {
  485. // Manually entered string?
  486. LL_WARNS("Windlight") << "No water preset named " << name << LL_ENDL;
  487. return;
  488. }
  489. }
  490. LLEnvManagerNew::instance().useWaterParams(water_params.getAll());
  491. bool can_edit = (scope == LLEnvKey::SCOPE_LOCAL || LLEnvManagerNew::canEditRegionSettings());
  492. enableEditing(can_edit);
  493. mMakeDefaultCheckBox->setEnabled(scope == LLEnvKey::SCOPE_LOCAL);
  494. }
  495. bool LLFloaterEditWater::onSaveAnswer(const LLSD& notification, const LLSD& response)
  496. {
  497. S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
  498. // If they choose save, do it. Otherwise, don't do anything
  499. if (option == 0)
  500. {
  501. onSaveConfirmed();
  502. }
  503. return false;
  504. }
  505. void LLFloaterEditWater::onSaveConfirmed()
  506. {
  507. // Save currently displayed water params to the selected preset.
  508. std::string name = getCurrentPresetName();
  509. LL_DEBUGS("Windlight") << "Saving sky preset " << name << LL_ENDL;
  510. LLWaterParamManager& water_mgr = LLWaterParamManager::instance();
  511. if (water_mgr.hasParamSet(name))
  512. {
  513. water_mgr.setParamSet(name, water_mgr.mCurParams);
  514. }
  515. else
  516. {
  517. water_mgr.addParamSet(name, water_mgr.mCurParams);
  518. }
  519. water_mgr.savePreset(name);
  520. // Change preference if requested.
  521. if (mMakeDefaultCheckBox->getEnabled() && mMakeDefaultCheckBox->getValue())
  522. {
  523. LL_DEBUGS("Windlight") << name << " is now the new preferred water preset" << llendl;
  524. LLEnvManagerNew::instance().setUseWaterPreset(name);
  525. }
  526. closeFloater();
  527. }
  528. void LLFloaterEditWater::onBtnSave()
  529. {
  530. LLEnvKey::EScope scope;
  531. std::string name;
  532. getSelectedPreset(name, scope);
  533. if (scope == LLEnvKey::SCOPE_REGION)
  534. {
  535. saveRegionWater();
  536. closeFloater();
  537. return;
  538. }
  539. if (name.empty())
  540. {
  541. // *TODO: show an alert
  542. llwarns << "Empty water preset name" << llendl;
  543. return;
  544. }
  545. // Don't allow overwriting system presets.
  546. LLWaterParamManager& water_mgr = LLWaterParamManager::instance();
  547. if (water_mgr.isSystemPreset(name))
  548. {
  549. LLNotificationsUtil::add("WLNoEditDefault");
  550. return;
  551. }
  552. // Save, ask for confirmation for overwriting an existing preset.
  553. if (water_mgr.hasParamSet(name))
  554. {
  555. LLNotificationsUtil::add("WLSavePresetAlert", LLSD(), LLSD(), boost::bind(&LLFloaterEditWater::onSaveAnswer, this, _1, _2));
  556. }
  557. else
  558. {
  559. // new preset, hence no confirmation needed
  560. onSaveConfirmed();
  561. }
  562. }
  563. void LLFloaterEditWater::onBtnCancel()
  564. {
  565. closeFloater();
  566. }
  567. void LLFloaterEditWater::onWaterPresetListChange()
  568. {
  569. std::string name;
  570. LLEnvKey::EScope scope;
  571. getSelectedPreset(name, scope); // preset being edited
  572. if (scope == LLEnvKey::SCOPE_LOCAL && !LLWaterParamManager::instance().hasParamSet(name))
  573. {
  574. // Preset we've been editing doesn't exist anymore. Close the floater.
  575. closeFloater(false);
  576. }
  577. else
  578. {
  579. // A new preset has been added.
  580. // Refresh the presets list, though it may not make sense as the floater is about to be closed.
  581. refreshWaterPresetsList();
  582. }
  583. }
  584. void LLFloaterEditWater::onRegionSettingsChange()
  585. {
  586. // If creating a new preset, don't bother.
  587. if (isNewPreset())
  588. {
  589. return;
  590. }
  591. if (getCurrentScope() == LLEnvKey::SCOPE_REGION) // if editing region water
  592. {
  593. // reset the floater to its initial state
  594. reset();
  595. // *TODO: Notify user?
  596. }
  597. else // editing a local preset
  598. {
  599. refreshWaterPresetsList();
  600. }
  601. }
  602. void LLFloaterEditWater::onRegionInfoUpdate()
  603. {
  604. bool can_edit = true;
  605. // If we've selected the region water for editing.
  606. if (getCurrentScope() == LLEnvKey::SCOPE_REGION)
  607. {
  608. // check whether we have the access
  609. can_edit = LLEnvManagerNew::canEditRegionSettings();
  610. }
  611. enableEditing(can_edit);
  612. }