aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llfloaterwater.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:45:34 -0500
committerJacek Antonelli2008-08-15 23:45:34 -0500
commitcd17687f01420952712a500107e0f93e7ab8d5f8 (patch)
treece48c2b706f2c1176290e39fb555fbdf6648ce01 /linden/indra/newview/llfloaterwater.cpp
parentSecond Life viewer sources 1.19.0.5 (diff)
downloadmeta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.zip
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.gz
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.bz2
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.xz
Second Life viewer sources 1.19.1.0
Diffstat (limited to '')
-rw-r--r--linden/indra/newview/llfloaterwater.cpp735
1 files changed, 735 insertions, 0 deletions
diff --git a/linden/indra/newview/llfloaterwater.cpp b/linden/indra/newview/llfloaterwater.cpp
new file mode 100644
index 0000000..c842a87
--- /dev/null
+++ b/linden/indra/newview/llfloaterwater.cpp
@@ -0,0 +1,735 @@
1/**
2 * @file llfloaterwater.cpp
3 * @brief LLFloaterWater class definition
4 *
5 * $LicenseInfo:firstyear=2007&license=viewergpl$
6 *
7 * Copyright (c) 2007-2008, Linden Research, Inc.
8 *
9 * Second Life Viewer Source Code
10 * The source code in this file ("Source Code") is provided by Linden Lab
11 * to you under the terms of the GNU General Public License, version 2.0
12 * ("GPL"), unless you have obtained a separate licensing agreement
13 * ("Other License"), formally executed by you and Linden Lab. Terms of
14 * the GPL can be found in doc/GPL-license.txt in this distribution, or
15 * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
16 *
17 * There are special exceptions to the terms and conditions of the GPL as
18 * it is applied to this Source Code. View the full text of the exception
19 * in the file doc/FLOSS-exception.txt in this software distribution, or
20 * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception
21 *
22 * By copying, modifying or distributing this software, you acknowledge
23 * that you have read and understood your obligations described above,
24 * and agree to abide by those obligations.
25 *
26 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
27 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
28 * COMPLETENESS OR PERFORMANCE.
29 * $/LicenseInfo$
30 */
31
32#include "llviewerprecompiledheaders.h"
33
34#include "llfloaterwater.h"
35
36#include "pipeline.h"
37#include "llsky.h"
38
39#include "llsliderctrl.h"
40#include "llspinctrl.h"
41#include "llcolorswatch.h"
42#include "llcheckboxctrl.h"
43#include "lltexturectrl.h"
44#include "llvieweruictrlfactory.h"
45#include "llviewercamera.h"
46#include "llcombobox.h"
47#include "lllineeditor.h"
48#include "llfloaterdaycycle.h"
49#include "llboost.h"
50
51#include "v4math.h"
52#include "llviewerdisplay.h"
53#include "llviewercontrol.h"
54#include "llviewerwindow.h"
55#include "llsavedsettingsglue.h"
56
57#include "llwaterparamset.h"
58#include "llwaterparammanager.h"
59#include "llpostprocess.h"
60
61#undef max
62
63LLFloaterWater* LLFloaterWater::sWaterMenu = NULL;
64
65std::set<std::string> LLFloaterWater::sDefaultPresets;
66
67LLFloaterWater::LLFloaterWater() : LLFloater("water floater")
68{
69 gUICtrlFactory->buildFloater(this, "floater_water.xml");
70
71 // add the combo boxes
72 LLComboBox* comboBox = LLUICtrlFactory::getComboBoxByName(this, "WaterPresetsCombo");
73
74 if(comboBox != NULL) {
75
76 std::map<std::string, LLWaterParamSet>::iterator mIt =
77 LLWaterParamManager::instance()->mParamList.begin();
78 for(; mIt != LLWaterParamManager::instance()->mParamList.end(); mIt++)
79 {
80 comboBox->add(mIt->first);
81 }
82
83 // set defaults on combo boxes
84 comboBox->selectByValue(LLSD("Default"));
85 }
86
87 LLString def_water = getString("WLDefaultWaterNames");
88
89 // no editing or deleting of the blank string
90 sDefaultPresets.insert("");
91 boost_tokenizer tokens(def_water, boost::char_separator<char>(":"));
92 for (boost_tokenizer::iterator token_iter = tokens.begin(); token_iter != tokens.end(); ++token_iter)
93 {
94 LLString tok(*token_iter);
95 sDefaultPresets.insert(tok);
96 }
97
98 // load it up
99 initCallbacks();
100}
101
102LLFloaterWater::~LLFloaterWater()
103{
104}
105
106void LLFloaterWater::initCallbacks(void) {
107
108 // help buttons
109 initHelpBtn("WaterFogColorHelp", "HelpWaterFogColor");
110 initHelpBtn("WaterFogDensityHelp", "HelpWaterFogDensity");
111 initHelpBtn("WaterUnderWaterFogModHelp", "HelpUnderWaterFogMod");
112 initHelpBtn("WaterGlowHelp", "HelpWaterGlow");
113 initHelpBtn("WaterNormalScaleHelp", "HelpWaterNormalScale");
114 initHelpBtn("WaterFresnelScaleHelp", "HelpWaterFresnelScale");
115 initHelpBtn("WaterFresnelOffsetHelp", "HelpWaterFresnelOffset");
116
117 initHelpBtn("WaterBlurMultiplierHelp", "HelpWaterBlurMultiplier");
118 initHelpBtn("WaterScaleBelowHelp", "HelpWaterScaleBelow");
119 initHelpBtn("WaterScaleAboveHelp", "HelpWaterScaleAbove");
120
121 initHelpBtn("WaterNormalMapHelp", "HelpWaterNormalMap");
122 initHelpBtn("WaterWave1Help", "HelpWaterWave1");
123 initHelpBtn("WaterWave2Help", "HelpWaterWave2");
124
125 LLWaterParamManager * param_mgr = LLWaterParamManager::instance();
126
127 childSetCommitCallback("WaterFogColor", onWaterFogColorMoved, &param_mgr->mFogColor);
128
129 //
130 childSetCommitCallback("WaterGlow", onColorControlAMoved, &param_mgr->mFogColor);
131
132 // fog density
133 childSetCommitCallback("WaterFogDensity", onExpFloatControlMoved, &param_mgr->mFogDensity);
134 childSetCommitCallback("WaterUnderWaterFogMod", onFloatControlMoved, &param_mgr->mUnderWaterFogMod);
135
136 // blue density
137 childSetCommitCallback("WaterNormalScaleX", onVector3ControlXMoved, &param_mgr->mNormalScale);
138 childSetCommitCallback("WaterNormalScaleY", onVector3ControlYMoved, &param_mgr->mNormalScale);
139 childSetCommitCallback("WaterNormalScaleZ", onVector3ControlZMoved, &param_mgr->mNormalScale);
140
141 // fresnel
142 childSetCommitCallback("WaterFresnelScale", onFloatControlMoved, &param_mgr->mFresnelScale);
143 childSetCommitCallback("WaterFresnelOffset", onFloatControlMoved, &param_mgr->mFresnelOffset);
144
145 // scale above/below
146 childSetCommitCallback("WaterScaleAbove", onFloatControlMoved, &param_mgr->mScaleAbove);
147 childSetCommitCallback("WaterScaleBelow", onFloatControlMoved, &param_mgr->mScaleBelow);
148
149 // blur mult
150 childSetCommitCallback("WaterBlurMult", onFloatControlMoved, &param_mgr->mBlurMultiplier);
151
152 // Load/save
153 LLComboBox* comboBox = LLUICtrlFactory::getComboBoxByName(this, "WaterPresetsCombo");
154
155 //childSetAction("WaterLoadPreset", onLoadPreset, comboBox);
156 childSetAction("WaterNewPreset", onNewPreset, comboBox);
157 childSetAction("WaterSavePreset", onSavePreset, comboBox);
158 childSetAction("WaterDeletePreset", onDeletePreset, comboBox);
159
160 // wave direction
161 childSetCommitCallback("WaterWave1DirX", onVector2ControlXMoved, &param_mgr->mWave1Dir);
162 childSetCommitCallback("WaterWave1DirY", onVector2ControlYMoved, &param_mgr->mWave1Dir);
163 childSetCommitCallback("WaterWave2DirX", onVector2ControlXMoved, &param_mgr->mWave2Dir);
164 childSetCommitCallback("WaterWave2DirY", onVector2ControlYMoved, &param_mgr->mWave2Dir);
165
166 comboBox->setCommitCallback(onChangePresetName);
167
168 LLTextureCtrl* textCtrl = getChild<LLTextureCtrl>("WaterNormalMap");
169 textCtrl->setDefaultImageAssetID(LLUUID(gViewerArt.getString("water_normal.tga")));
170 childSetCommitCallback("WaterNormalMap", onNormalMapPicked, NULL);
171}
172
173void LLFloaterWater::onClickHelp(void* data)
174{
175 LLFloaterWater* self = LLFloaterWater::instance();
176
177 const char* xml_alert = (const char*) data;
178 LLAlertDialog* dialogp = gViewerWindow->alertXml(xml_alert);
179 if (dialogp)
180 {
181 LLFloater* root_floater = gFloaterView->getParentFloater(self);
182 if (root_floater)
183 {
184 root_floater->addDependentFloater(dialogp);
185 }
186 }
187}
188
189void LLFloaterWater::initHelpBtn(const char* name, const char* xml_alert)
190{
191 childSetAction(name, onClickHelp, (void*)xml_alert);
192}
193
194void LLFloaterWater::newPromptCallback(S32 option, const LLString& text, void* userData)
195{
196 if(text == "")
197 {
198 return;
199 }
200
201 if(option == 0) {
202 LLComboBox* comboBox = LLUICtrlFactory::getComboBoxByName(sWaterMenu,
203 "WaterPresetsCombo");
204
205 LLWaterParamManager * param_mgr = LLWaterParamManager::instance();
206
207 // add the current parameters to the list
208 // see if it's there first
209 std::map<std::string, LLWaterParamSet>::iterator mIt =
210 param_mgr->mParamList.find(text.c_str());
211
212 // if not there, add a new one
213 if(mIt == param_mgr->mParamList.end())
214 {
215 param_mgr->addParamSet(text.c_str(),
216 param_mgr->mCurParams);
217 comboBox->add(text);
218 comboBox->sortByName();
219
220 comboBox->setSelectedByValue(text, true);
221
222 param_mgr->savePreset(text);
223
224 // otherwise, send a message to the user
225 }
226 else
227 {
228 gViewerWindow->alertXml("ExistsWaterPresetAlert");
229 }
230 }
231}
232
233void LLFloaterWater::syncMenu()
234{
235 bool err;
236
237 LLWaterParamManager * param_mgr = LLWaterParamManager::instance();
238
239 LLWaterParamSet & current_params = param_mgr->mCurParams;
240
241 // blue horizon
242 param_mgr->mFogColor = current_params.getVector4(param_mgr->mFogColor.mName, err);
243
244 LLColor4 col = param_mgr->getFogColor();
245 childSetValue("WaterGlow", col.mV[3]);
246 col.mV[3] = 1.0f;
247 LLColorSwatchCtrl* colCtrl = sWaterMenu->getChild<LLColorSwatchCtrl>("WaterFogColor");
248
249 colCtrl->set(col);
250
251 // fog and wavelets
252 param_mgr->mFogDensity.mExp =
253 log(current_params.getFloat(param_mgr->mFogDensity.mName, err)) /
254 log(param_mgr->mFogDensity.mBase);
255 param_mgr->setDensitySliderValue(param_mgr->mFogDensity.mExp);
256 childSetValue("WaterFogDensity", param_mgr->mFogDensity.mExp);
257
258 param_mgr->mUnderWaterFogMod.mX =
259 current_params.getFloat(param_mgr->mUnderWaterFogMod.mName, err);
260 childSetValue("WaterUnderWaterFogMod", param_mgr->mUnderWaterFogMod.mX);
261
262 param_mgr->mNormalScale = current_params.getVector3(param_mgr->mNormalScale.mName, err);
263 childSetValue("WaterNormalScaleX", param_mgr->mNormalScale.mX);
264 childSetValue("WaterNormalScaleY", param_mgr->mNormalScale.mY);
265 childSetValue("WaterNormalScaleZ", param_mgr->mNormalScale.mZ);
266
267 // Fresnel
268 param_mgr->mFresnelScale.mX = current_params.getFloat(param_mgr->mFresnelScale.mName, err);
269 childSetValue("WaterFresnelScale", param_mgr->mFresnelScale.mX);
270 param_mgr->mFresnelOffset.mX = current_params.getFloat(param_mgr->mFresnelOffset.mName, err);
271 childSetValue("WaterFresnelOffset", param_mgr->mFresnelOffset.mX);
272
273 // Scale Above/Below
274 param_mgr->mScaleAbove.mX = current_params.getFloat(param_mgr->mScaleAbove.mName, err);
275 childSetValue("WaterScaleAbove", param_mgr->mScaleAbove.mX);
276 param_mgr->mScaleBelow.mX = current_params.getFloat(param_mgr->mScaleBelow.mName, err);
277 childSetValue("WaterScaleBelow", param_mgr->mScaleBelow.mX);
278
279 // blur mult
280 param_mgr->mBlurMultiplier.mX = current_params.getFloat(param_mgr->mBlurMultiplier.mName, err);
281 childSetValue("WaterBlurMult", param_mgr->mBlurMultiplier.mX);
282
283 // wave directions
284 param_mgr->mWave1Dir = current_params.getVector2(param_mgr->mWave1Dir.mName, err);
285 childSetValue("WaterWave1DirX", param_mgr->mWave1Dir.mX);
286 childSetValue("WaterWave1DirY", param_mgr->mWave1Dir.mY);
287
288 param_mgr->mWave2Dir = current_params.getVector2(param_mgr->mWave2Dir.mName, err);
289 childSetValue("WaterWave2DirX", param_mgr->mWave2Dir.mX);
290 childSetValue("WaterWave2DirY", param_mgr->mWave2Dir.mY);
291
292 LLTextureCtrl* textCtrl = sWaterMenu->getChild<LLTextureCtrl>("WaterNormalMap");
293 textCtrl->setImageAssetID(param_mgr->getNormalMapID());
294}
295
296
297// static
298LLFloaterWater* LLFloaterWater::instance()
299{
300 if (!sWaterMenu)
301 {
302 sWaterMenu = new LLFloaterWater();
303 sWaterMenu->open();
304 sWaterMenu->setFocus(TRUE);
305 }
306 return sWaterMenu;
307}
308void LLFloaterWater::show()
309{
310 LLFloaterWater* water = instance();
311 water->syncMenu();
312
313 // comment in if you want the menu to rebuild each time
314 //gUICtrlFactory->buildFloater(water, "floater_water.xml");
315 //water->initCallbacks();
316
317 water->open();
318}
319
320bool LLFloaterWater::isOpen()
321{
322 if (sWaterMenu != NULL) {
323 return true;
324 }
325 return false;
326}
327
328// virtual
329void LLFloaterWater::onClose(bool app_quitting)
330{
331 if (sWaterMenu)
332 {
333 sWaterMenu->setVisible(FALSE);
334 }
335}
336
337// vector control callbacks
338void LLFloaterWater::onVector3ControlXMoved(LLUICtrl* ctrl, void* userData)
339{
340 LLSliderCtrl* sldrCtrl = static_cast<LLSliderCtrl*>(ctrl);
341 WaterVector3Control * vectorControl = static_cast<WaterVector3Control *>(userData);
342
343 vectorControl->mX = sldrCtrl->getValueF32();
344
345 vectorControl->update(LLWaterParamManager::instance()->mCurParams);
346
347 LLWaterParamManager::instance()->propagateParameters();
348}
349
350// vector control callbacks
351void LLFloaterWater::onVector3ControlYMoved(LLUICtrl* ctrl, void* userData)
352{
353 LLSliderCtrl* sldrCtrl = static_cast<LLSliderCtrl*>(ctrl);
354 WaterVector3Control * vectorControl = static_cast<WaterVector3Control *>(userData);
355
356 vectorControl->mY = sldrCtrl->getValueF32();
357
358 vectorControl->update(LLWaterParamManager::instance()->mCurParams);
359
360 LLWaterParamManager::instance()->propagateParameters();
361}
362
363// vector control callbacks
364void LLFloaterWater::onVector3ControlZMoved(LLUICtrl* ctrl, void* userData)
365{
366 LLSliderCtrl* sldrCtrl = static_cast<LLSliderCtrl*>(ctrl);
367 WaterVector3Control * vectorControl = static_cast<WaterVector3Control *>(userData);
368
369 vectorControl->mZ = sldrCtrl->getValueF32();
370
371 vectorControl->update(LLWaterParamManager::instance()->mCurParams);
372
373 LLWaterParamManager::instance()->propagateParameters();
374}
375
376
377// vector control callbacks
378void LLFloaterWater::onVector2ControlXMoved(LLUICtrl* ctrl, void* userData)
379{
380 LLSliderCtrl* sldrCtrl = static_cast<LLSliderCtrl*>(ctrl);
381 WaterVector2Control * vectorControl = static_cast<WaterVector2Control *>(userData);
382
383 vectorControl->mX = sldrCtrl->getValueF32();
384
385 vectorControl->update(LLWaterParamManager::instance()->mCurParams);
386
387 LLWaterParamManager::instance()->propagateParameters();
388}
389
390// vector control callbacks
391void LLFloaterWater::onVector2ControlYMoved(LLUICtrl* ctrl, void* userData)
392{
393 LLSliderCtrl* sldrCtrl = static_cast<LLSliderCtrl*>(ctrl);
394 WaterVector2Control * vectorControl = static_cast<WaterVector2Control *>(userData);
395
396 vectorControl->mY = sldrCtrl->getValueF32();
397
398 vectorControl->update(LLWaterParamManager::instance()->mCurParams);
399
400 LLWaterParamManager::instance()->propagateParameters();
401}
402
403// color control callbacks
404void LLFloaterWater::onColorControlRMoved(LLUICtrl* ctrl, void* userData)
405{
406 LLSliderCtrl* sldrCtrl = static_cast<LLSliderCtrl*>(ctrl);
407 WaterColorControl * colorControl = static_cast<WaterColorControl *>(userData);
408
409 colorControl->mR = sldrCtrl->getValueF32();
410
411 // move i if it's the max
412 if(colorControl->mR >= colorControl->mG
413 && colorControl->mR >= colorControl->mB
414 && colorControl->mHasSliderName)
415 {
416 colorControl->mI = colorControl->mR;
417 std::string name = colorControl->mSliderName;
418 name.append("I");
419
420 sWaterMenu->childSetValue(name, colorControl->mR);
421 }
422
423 colorControl->update(LLWaterParamManager::instance()->mCurParams);
424
425 LLWaterParamManager::instance()->propagateParameters();
426}
427
428void LLFloaterWater::onColorControlGMoved(LLUICtrl* ctrl, void* userData)
429{
430 LLSliderCtrl* sldrCtrl = static_cast<LLSliderCtrl*>(ctrl);
431 WaterColorControl * colorControl = static_cast<WaterColorControl *>(userData);
432
433 colorControl->mG = sldrCtrl->getValueF32();
434
435 // move i if it's the max
436 if(colorControl->mG >= colorControl->mR
437 && colorControl->mG >= colorControl->mB
438 && colorControl->mHasSliderName)
439 {
440 colorControl->mI = colorControl->mG;
441 std::string name = colorControl->mSliderName;
442 name.append("I");
443
444 sWaterMenu->childSetValue(name, colorControl->mG);
445
446 }
447
448 colorControl->update(LLWaterParamManager::instance()->mCurParams);
449
450 LLWaterParamManager::instance()->propagateParameters();
451}
452
453void LLFloaterWater::onColorControlBMoved(LLUICtrl* ctrl, void* userData)
454{
455 LLSliderCtrl* sldrCtrl = static_cast<LLSliderCtrl*>(ctrl);
456 WaterColorControl * colorControl = static_cast<WaterColorControl *>(userData);
457
458 colorControl->mB = sldrCtrl->getValueF32();
459
460 // move i if it's the max
461 if(colorControl->mB >= colorControl->mR
462 && colorControl->mB >= colorControl->mG
463 && colorControl->mHasSliderName)
464 {
465 colorControl->mI = colorControl->mB;
466 std::string name = colorControl->mSliderName;
467 name.append("I");
468
469 sWaterMenu->childSetValue(name, colorControl->mB);
470 }
471
472 colorControl->update(LLWaterParamManager::instance()->mCurParams);
473
474 LLWaterParamManager::instance()->propagateParameters();
475}
476
477void LLFloaterWater::onColorControlAMoved(LLUICtrl* ctrl, void* userData)
478{
479 LLSliderCtrl* sldrCtrl = static_cast<LLSliderCtrl*>(ctrl);
480 WaterColorControl * colorControl = static_cast<WaterColorControl *>(userData);
481
482 colorControl->mA = sldrCtrl->getValueF32();
483
484 colorControl->update(LLWaterParamManager::instance()->mCurParams);
485
486 LLWaterParamManager::instance()->propagateParameters();
487}
488
489
490void LLFloaterWater::onColorControlIMoved(LLUICtrl* ctrl, void* userData)
491{
492 LLSliderCtrl* sldrCtrl = static_cast<LLSliderCtrl*>(ctrl);
493 WaterColorControl * colorControl = static_cast<WaterColorControl *>(userData);
494
495 colorControl->mI = sldrCtrl->getValueF32();
496
497 // only for sliders where we pass a name
498 if(colorControl->mHasSliderName)
499 {
500 // set it to the top
501 F32 maxVal = std::max(std::max(colorControl->mR, colorControl->mG), colorControl->mB);
502 F32 iVal;
503
504 iVal = colorControl->mI;
505
506 // get the names of the other sliders
507 std::string rName = colorControl->mSliderName;
508 rName.append("R");
509 std::string gName = colorControl->mSliderName;
510 gName.append("G");
511 std::string bName = colorControl->mSliderName;
512 bName.append("B");
513
514 // handle if at 0
515 if(iVal == 0)
516 {
517 colorControl->mR = 0;
518 colorControl->mG = 0;
519 colorControl->mB = 0;
520
521 // if all at the start
522 // set them all to the intensity
523 }
524 else if (maxVal == 0)
525 {
526 colorControl->mR = iVal;
527 colorControl->mG = iVal;
528 colorControl->mB = iVal;
529 }
530 else
531 {
532 // add delta amounts to each
533 F32 delta = (iVal - maxVal) / maxVal;
534 colorControl->mR *= (1.0f + delta);
535 colorControl->mG *= (1.0f + delta);
536 colorControl->mB *= (1.0f + delta);
537 }
538
539 // set the sliders to the new vals
540 sWaterMenu->childSetValue(rName.c_str(), colorControl->mR);
541 sWaterMenu->childSetValue(gName.c_str(), colorControl->mG);
542 sWaterMenu->childSetValue(bName.c_str(), colorControl->mB);
543 }
544
545 // now update the current parameters and send them to shaders
546 colorControl->update(LLWaterParamManager::instance()->mCurParams);
547 LLWaterParamManager::instance()->propagateParameters();
548}
549
550void LLFloaterWater::onExpFloatControlMoved(LLUICtrl* ctrl, void* userData)
551{
552 LLSliderCtrl* sldrCtrl = static_cast<LLSliderCtrl*>(ctrl);
553 WaterExpFloatControl * expFloatControl = static_cast<WaterExpFloatControl *>(userData);
554
555 F32 val = sldrCtrl->getValueF32();
556 expFloatControl->mExp = val;
557 LLWaterParamManager::instance()->setDensitySliderValue(val);
558
559 expFloatControl->update(LLWaterParamManager::instance()->mCurParams);
560 LLWaterParamManager::instance()->propagateParameters();
561}
562
563void LLFloaterWater::onFloatControlMoved(LLUICtrl* ctrl, void* userData)
564{
565 LLSliderCtrl* sldrCtrl = static_cast<LLSliderCtrl*>(ctrl);
566 WaterFloatControl * floatControl = static_cast<WaterFloatControl *>(userData);
567
568 floatControl->mX = sldrCtrl->getValueF32() / floatControl->mMult;
569
570 floatControl->update(LLWaterParamManager::instance()->mCurParams);
571 LLWaterParamManager::instance()->propagateParameters();
572}
573void LLFloaterWater::onWaterFogColorMoved(LLUICtrl* ctrl, void* userData)
574{
575 LLColorSwatchCtrl* swatch = static_cast<LLColorSwatchCtrl*>(ctrl);
576 WaterColorControl * colorControl = static_cast<WaterColorControl *>(userData);
577 *colorControl = swatch->get();
578
579 colorControl->update(LLWaterParamManager::instance()->mCurParams);
580 LLWaterParamManager::instance()->propagateParameters();
581}
582
583void LLFloaterWater::onBoolToggle(LLUICtrl* ctrl, void* userData)
584{
585 LLCheckBoxCtrl* cbCtrl = static_cast<LLCheckBoxCtrl*>(ctrl);
586
587 bool value = cbCtrl->get();
588 (*(static_cast<BOOL *>(userData))) = value;
589}
590
591void LLFloaterWater::onNormalMapPicked(LLUICtrl* ctrl, void* userData)
592{
593 LLTextureCtrl* textCtrl = static_cast<LLTextureCtrl*>(ctrl);
594 LLUUID textID = textCtrl->getImageAssetID();
595 LLWaterParamManager::instance()->setNormalMapID(textID);
596}
597
598void LLFloaterWater::onNewPreset(void* userData)
599{
600 gViewerWindow->alertXmlEditText("NewWaterPreset", LLString::format_map_t(),
601 NULL, NULL, newPromptCallback, NULL);
602}
603
604void LLFloaterWater::onSavePreset(void* userData)
605{
606 // get the name
607 LLComboBox* comboBox = LLUICtrlFactory::getComboBoxByName(sWaterMenu,
608 "WaterPresetsCombo");
609
610 // don't save the empty name
611 if(comboBox->getSelectedItemLabel() == "")
612 {
613 return;
614 }
615
616 LLWaterParamManager::instance()->mCurParams.mName =
617 comboBox->getSelectedItemLabel();
618
619 // check to see if it's a default and shouldn't be overwritten
620 std::set<std::string>::iterator sIt = sDefaultPresets.find(
621 comboBox->getSelectedItemLabel().c_str());
622 if(sIt != sDefaultPresets.end() && !gSavedSettings.getBOOL("WaterEditPresets"))
623 {
624 gViewerWindow->alertXml("WLNoEditDefault");
625 return;
626 }
627
628 gViewerWindow->alertXml("WLSavePresetAlert", saveAlertCallback, sWaterMenu);
629}
630
631void LLFloaterWater::saveAlertCallback(S32 option, void* userdata)
632{
633 // if they choose save, do it. Otherwise, don't do anything
634 if(option == 0)
635 {
636 LLWaterParamManager * param_mgr = LLWaterParamManager::instance();
637
638 param_mgr->setParamSet(
639 param_mgr->mCurParams.mName,
640 param_mgr->mCurParams);
641
642 // comment this back in to save to file
643 param_mgr->savePreset(param_mgr->mCurParams.mName);
644 }
645
646}
647
648void LLFloaterWater::onDeletePreset(void* userData)
649{
650 LLComboBox* combo_box = LLUICtrlFactory::getComboBoxByName(sWaterMenu,
651 "WaterPresetsCombo");
652
653 if(combo_box->getSelectedValue().asString() == "")
654 {
655 return;
656 }
657
658 LLString::format_map_t args;
659 args["[SKY]"] = combo_box->getSelectedValue().asString();
660 gViewerWindow->alertXml("WLDeletePresetAlert", args, deleteAlertCallback, sWaterMenu);
661}
662
663void LLFloaterWater::deleteAlertCallback(S32 option, void* userdata)
664{
665 // if they choose delete, do it. Otherwise, don't do anything
666 if(option == 0)
667 {
668 LLComboBox* combo_box = LLUICtrlFactory::getComboBoxByName(sWaterMenu,
669 "WaterPresetsCombo");
670 LLFloaterDayCycle* day_cycle = NULL;
671 LLComboBox* key_combo = NULL;
672 LLMultiSliderCtrl* mult_sldr = NULL;
673
674 if(LLFloaterDayCycle::isOpen())
675 {
676 day_cycle = LLFloaterDayCycle::instance();
677 key_combo = LLUICtrlFactory::getComboBoxByName(day_cycle,
678 "WaterKeyPresets");
679 mult_sldr = LLUICtrlFactory::getMultiSliderByName(day_cycle,
680 "WaterDayCycleKeys");
681 }
682
683 LLString name = combo_box->getSelectedValue().asString();
684
685 // check to see if it's a default and shouldn't be deleted
686 std::set<std::string>::iterator sIt = sDefaultPresets.find(name.c_str());
687 if(sIt != sDefaultPresets.end())
688 {
689 gViewerWindow->alertXml("WaterNoEditDefault");
690 return;
691 }
692
693 LLWaterParamManager::instance()->removeParamSet(name, true);
694
695 // remove and choose another
696 S32 new_index = combo_box->getCurrentIndex();
697
698 combo_box->remove(name);
699
700 if(key_combo != NULL)
701 {
702 key_combo->remove(name);
703
704 // remove from slider, as well
705 day_cycle->deletePreset(name);
706 }
707
708 // pick the previously selected index after delete
709 if(new_index > 0)
710 {
711 new_index--;
712 }
713
714 if(combo_box->getItemCount() > 0)
715 {
716 combo_box->setCurrentByIndex(new_index);
717 }
718 }
719}
720
721
722void LLFloaterWater::onChangePresetName(LLUICtrl* ctrl, void * userData)
723{
724 LLComboBox * combo_box = static_cast<LLComboBox*>(ctrl);
725
726 if(combo_box->getSimple() == "")
727 {
728 return;
729 }
730
731 LLWaterParamManager::instance()->loadPreset(
732 combo_box->getSelectedValue().asString());
733 sWaterMenu->syncMenu();
734}
735