aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llfloaterdaycycle.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/llfloaterdaycycle.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/llfloaterdaycycle.cpp612
1 files changed, 612 insertions, 0 deletions
diff --git a/linden/indra/newview/llfloaterdaycycle.cpp b/linden/indra/newview/llfloaterdaycycle.cpp
new file mode 100644
index 0000000..29e4c37
--- /dev/null
+++ b/linden/indra/newview/llfloaterdaycycle.cpp
@@ -0,0 +1,612 @@
1/**
2 * @file llfloaterdaycycle.cpp
3 * @brief LLFloaterDayCycle 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 "llfloaterdaycycle.h"
35
36#include "pipeline.h"
37#include "llsky.h"
38
39#include "llsliderctrl.h"
40#include "llmultislider.h"
41#include "llmultisliderctrl.h"
42#include "llspinctrl.h"
43#include "llcheckboxctrl.h"
44#include "llvieweruictrlfactory.h"
45#include "llviewercamera.h"
46#include "llcombobox.h"
47#include "lllineeditor.h"
48#include "llwlanimator.h"
49
50#include "v4math.h"
51#include "llviewerdisplay.h"
52#include "llviewercontrol.h"
53#include "llviewerwindow.h"
54
55#include "llwlparamset.h"
56#include "llwlparammanager.h"
57#include "llpostprocess.h"
58#include "llfloaterwindlight.h"
59
60
61LLFloaterDayCycle* LLFloaterDayCycle::sDayCycle = NULL;
62std::map<LLString, LLWLSkyKey> LLFloaterDayCycle::sSliderToKey;
63const F32 LLFloaterDayCycle::sHoursPerDay = 24.0f;
64
65LLFloaterDayCycle::LLFloaterDayCycle() : LLFloater("Day Cycle Floater")
66{
67 gUICtrlFactory->buildFloater(this, "floater_day_cycle_options.xml");
68
69 // add the combo boxes
70 LLComboBox* keyCombo = LLUICtrlFactory::getComboBoxByName(this, "WLKeyPresets");
71
72 if(keyCombo != NULL)
73 {
74 std::map<std::string, LLWLParamSet>::iterator mIt =
75 LLWLParamManager::instance()->mParamList.begin();
76 for(; mIt != LLWLParamManager::instance()->mParamList.end(); mIt++)
77 {
78 keyCombo->add(LLString(mIt->first));
79 }
80
81 // set defaults on combo boxes
82 keyCombo->selectFirstItem();
83 }
84
85 // add the time slider
86 LLMultiSliderCtrl* sldr = LLUICtrlFactory::getMultiSliderByName(this,
87 "WLTimeSlider");
88
89 sldr->addSlider();
90
91 // load it up
92 initCallbacks();
93}
94
95LLFloaterDayCycle::~LLFloaterDayCycle()
96{
97}
98
99void LLFloaterDayCycle::onClickHelp(void* data)
100{
101
102 LLFloaterDayCycle* self = LLFloaterDayCycle::instance();
103
104 const char* xml_alert = (const char*) data;
105 LLAlertDialog* dialogp = gViewerWindow->alertXml(xml_alert);
106 if (dialogp)
107 {
108 LLFloater* root_floater = gFloaterView->getParentFloater(self);
109 if (root_floater)
110 {
111 root_floater->addDependentFloater(dialogp);
112 }
113 }
114}
115
116void LLFloaterDayCycle::initHelpBtn(const char* name, const char* xml_alert)
117{
118 childSetAction(name, onClickHelp, (void*)xml_alert);
119}
120
121void LLFloaterDayCycle::initCallbacks(void)
122{
123 initHelpBtn("WLDayCycleHelp", "HelpDayCycle");
124
125 // WL Day Cycle
126 childSetCommitCallback("WLTimeSlider", onTimeSliderMoved, NULL);
127 childSetCommitCallback("WLDayCycleKeys", onKeyTimeMoved, NULL);
128 childSetCommitCallback("WLCurKeyHour", onKeyTimeChanged, NULL);
129 childSetCommitCallback("WLCurKeyMin", onKeyTimeChanged, NULL);
130 childSetCommitCallback("WLKeyPresets", onKeyPresetChanged, NULL);
131
132 childSetCommitCallback("WLLengthOfDayHour", onTimeRateChanged, NULL);
133 childSetCommitCallback("WLLengthOfDayMin", onTimeRateChanged, NULL);
134 childSetCommitCallback("WLLengthOfDaySec", onTimeRateChanged, NULL);
135 childSetAction("WLUseLindenTime", onUseLindenTime, NULL);
136 childSetAction("WLAnimSky", onRunAnimSky, NULL);
137 childSetAction("WLStopAnimSky", onStopAnimSky, NULL);
138
139 childSetAction("WLLoadDayCycle", onLoadDayCycle, NULL);
140 childSetAction("WLSaveDayCycle", onSaveDayCycle, NULL);
141
142 childSetAction("WLAddKey", onAddKey, NULL);
143 childSetAction("WLDeleteKey", onDeleteKey, NULL);
144}
145
146void LLFloaterDayCycle::syncMenu()
147{
148// std::map<std::string, LLVector4> & currentParams = LLWLParamManager::instance()->mCurParams.mParamValues;
149
150 // set time
151 LLMultiSliderCtrl* sldr = LLUICtrlFactory::getMultiSliderByName(LLFloaterDayCycle::sDayCycle,
152 "WLTimeSlider");
153 sldr->setCurSliderValue((F32)LLWLParamManager::instance()->mAnimator.getDayTime() * sHoursPerDay);
154
155 LLSpinCtrl* secSpin = LLUICtrlFactory::getSpinnerByName(sDayCycle,
156 "WLLengthOfDaySec");
157 LLSpinCtrl* minSpin = LLUICtrlFactory::getSpinnerByName(sDayCycle,
158 "WLLengthOfDayMin");
159 LLSpinCtrl* hourSpin = LLUICtrlFactory::getSpinnerByName(sDayCycle,
160 "WLLengthOfDayHour");
161
162 F32 curRate;
163 F32 hours, min, sec;
164
165 // get the current rate
166 curRate = LLWLParamManager::instance()->mDay.mDayRate;
167 hours = (F32)((int)(curRate / 60 / 60));
168 curRate -= (hours * 60 * 60);
169 min = (F32)((int)(curRate / 60));
170 curRate -= (min * 60);
171 sec = curRate;
172
173 hourSpin->setValue(hours);
174 minSpin->setValue(min);
175 secSpin->setValue(sec);
176
177 // turn off Use Estate Time button if it's already being used
178 if( LLWLParamManager::instance()->mAnimator.mUseLindenTime == true)
179 {
180 LLFloaterDayCycle::sDayCycle->childDisable("WLUseLindenTime");
181 }
182 else
183 {
184 LLFloaterDayCycle::sDayCycle->childEnable("WLUseLindenTime");
185 }
186}
187
188void LLFloaterDayCycle::syncSliderTrack()
189{
190 // clear the slider
191 LLMultiSliderCtrl* kSldr = LLUICtrlFactory::getMultiSliderByName(sDayCycle,
192 "WLDayCycleKeys");
193
194 kSldr->clear();
195 sSliderToKey.clear();
196
197 // add sliders
198 std::map<F32, std::string>::iterator mIt =
199 LLWLParamManager::instance()->mDay.mTimeMap.begin();
200 for(; mIt != LLWLParamManager::instance()->mDay.mTimeMap.end(); mIt++)
201 {
202 addSliderKey(mIt->first * sHoursPerDay, mIt->second.c_str());
203 }
204}
205
206void LLFloaterDayCycle::syncTrack()
207{
208 // if no keys, do nothing
209 if(sSliderToKey.size() == 0)
210 {
211 return;
212 }
213
214 LLMultiSliderCtrl* sldr;
215 sldr = LLUICtrlFactory::getMultiSliderByName(sDayCycle,
216 "WLDayCycleKeys");
217 llassert_always(sSliderToKey.size() == sldr->getValue().size());
218
219 LLMultiSliderCtrl* tSldr;
220 tSldr = LLUICtrlFactory::getMultiSliderByName(sDayCycle,
221 "WLTimeSlider");
222
223 // create a new animation track
224 LLWLParamManager::instance()->mDay.clearKeys();
225
226 // add the keys one by one
227 std::map<LLString, LLWLSkyKey>::iterator mIt = sSliderToKey.begin();
228 for(; mIt != sSliderToKey.end(); mIt++)
229 {
230 LLWLParamManager::instance()->mDay.addKey(mIt->second.time / sHoursPerDay,
231 mIt->second.presetName);
232 }
233
234 // set the param manager's track to the new one
235 LLWLParamManager::instance()->resetAnimator(
236 tSldr->getCurSliderValue() / sHoursPerDay, false);
237
238 LLWLParamManager::instance()->mAnimator.update(
239 LLWLParamManager::instance()->mCurParams);
240}
241
242// static
243LLFloaterDayCycle* LLFloaterDayCycle::instance()
244{
245 if (!sDayCycle)
246 {
247 sDayCycle = new LLFloaterDayCycle();
248 sDayCycle->open();
249 sDayCycle->setFocus(TRUE);
250 }
251 return sDayCycle;
252}
253
254bool LLFloaterDayCycle::isOpen()
255{
256 if (sDayCycle != NULL)
257 {
258 return true;
259 }
260 return false;
261}
262
263void LLFloaterDayCycle::show()
264{
265 LLFloaterDayCycle* dayCycle = instance();
266 dayCycle->syncMenu();
267 syncSliderTrack();
268
269 // comment in if you want the menu to rebuild each time
270 //gUICtrlFactory->buildFloater(dayCycle, "floater_day_cycle_options.xml");
271 //dayCycle->initCallbacks();
272
273 dayCycle->open();
274}
275
276// virtual
277void LLFloaterDayCycle::onClose(bool app_quitting)
278{
279 if (sDayCycle)
280 {
281 sDayCycle->setVisible(FALSE);
282 }
283}
284
285void LLFloaterDayCycle::onRunAnimSky(void* userData)
286{
287 // if no keys, do nothing
288 if(sSliderToKey.size() == 0)
289 {
290 return;
291 }
292
293 LLMultiSliderCtrl* sldr;
294 sldr = LLUICtrlFactory::getMultiSliderByName(sDayCycle,
295 "WLDayCycleKeys");
296 llassert_always(sSliderToKey.size() == sldr->getValue().size());
297
298 LLMultiSliderCtrl* tSldr;
299 tSldr = LLUICtrlFactory::getMultiSliderByName(sDayCycle,
300 "WLTimeSlider");
301
302 // turn off linden time
303 LLWLParamManager::instance()->mAnimator.mUseLindenTime = false;
304
305 // set the param manager's track to the new one
306 LLWLParamManager::instance()->resetAnimator(
307 tSldr->getCurSliderValue() / sHoursPerDay, true);
308
309 llassert_always(LLWLParamManager::instance()->mAnimator.mTimeTrack.size() == sldr->getValue().size());
310}
311
312void LLFloaterDayCycle::onStopAnimSky(void* userData)
313{
314 // if no keys, do nothing
315 if(sSliderToKey.size() == 0) {
316 return;
317 }
318
319 // turn off animation and using linden time
320 LLWLParamManager::instance()->mAnimator.mIsRunning = false;
321 LLWLParamManager::instance()->mAnimator.mUseLindenTime = false;
322}
323
324void LLFloaterDayCycle::onUseLindenTime(void* userData)
325{
326 LLFloaterWindLight* wl = LLFloaterWindLight::instance();
327 LLComboBox* box = LLUICtrlFactory::getComboBoxByName(wl, "WLPresetsCombo");
328 box->selectByValue("");
329
330 LLWLParamManager::instance()->mAnimator.mIsRunning = true;
331 LLWLParamManager::instance()->mAnimator.mUseLindenTime = true;
332}
333
334void LLFloaterDayCycle::onLoadDayCycle(void* userData)
335{
336 LLWLParamManager::instance()->mDay.loadDayCycle("Default.xml");
337
338 // sync it all up
339 syncSliderTrack();
340 syncMenu();
341
342 // set the param manager's track to the new one
343 LLMultiSliderCtrl* tSldr;
344 tSldr = LLUICtrlFactory::getMultiSliderByName(sDayCycle,
345 "WLTimeSlider");
346 LLWLParamManager::instance()->resetAnimator(
347 tSldr->getCurSliderValue() / sHoursPerDay, false);
348
349 // and draw it
350 LLWLParamManager::instance()->mAnimator.update(
351 LLWLParamManager::instance()->mCurParams);
352}
353
354void LLFloaterDayCycle::onSaveDayCycle(void* userData)
355{
356 LLWLParamManager::instance()->mDay.saveDayCycle("Default.xml");
357}
358
359
360void LLFloaterDayCycle::onTimeSliderMoved(LLUICtrl* ctrl, void* userData)
361{
362 LLMultiSliderCtrl* sldr = LLUICtrlFactory::getMultiSliderByName(sDayCycle,
363 "WLTimeSlider");
364
365 /// get the slider value
366 F32 val = sldr->getCurSliderValue() / sHoursPerDay;
367
368 // set the value, turn off animation
369 LLWLParamManager::instance()->mAnimator.setDayTime((F64)val);
370 LLWLParamManager::instance()->mAnimator.mIsRunning = false;
371 LLWLParamManager::instance()->mAnimator.mUseLindenTime = false;
372
373 // then call update once
374 LLWLParamManager::instance()->mAnimator.update(
375 LLWLParamManager::instance()->mCurParams);
376}
377
378void LLFloaterDayCycle::onKeyTimeMoved(LLUICtrl* ctrl, void* userData)
379{
380 LLComboBox* comboBox = LLUICtrlFactory::getComboBoxByName(sDayCycle,
381 "WLKeyPresets");
382 LLMultiSliderCtrl* sldr = LLUICtrlFactory::getMultiSliderByName(sDayCycle,
383 "WLDayCycleKeys");
384 LLSpinCtrl* hourSpin = LLUICtrlFactory::getSpinnerByName(sDayCycle,
385 "WLCurKeyHour");
386 LLSpinCtrl* minSpin = LLUICtrlFactory::getSpinnerByName(sDayCycle,
387 "WLCurKeyMin");
388
389 if(sldr->getValue().size() == 0) {
390 return;
391 }
392
393 // make sure we have a slider
394 const LLString& curSldr = sldr->getCurSlider();
395 if(curSldr == "") {
396 return;
397 }
398
399 F32 time = sldr->getCurSliderValue();
400
401 // check to see if a key exists
402 LLString presetName = sSliderToKey[curSldr].presetName;
403 sSliderToKey[curSldr].time = time;
404
405 // if it exists, turn on check box
406 comboBox->selectByValue(presetName);
407
408 // now set the spinners
409 F32 hour = (F32)((S32)time);
410 F32 min = (time - hour) * 60;
411
412 // handle imprecision
413 if(min >= 59) {
414 min = 0;
415 hour += 1;
416 }
417
418 hourSpin->set(hour);
419 minSpin->set(min);
420
421 syncTrack();
422
423}
424
425void LLFloaterDayCycle::onKeyTimeChanged(LLUICtrl* ctrl, void* userData)
426{
427 // if no keys, skipped
428 if(sSliderToKey.size() == 0) {
429 return;
430 }
431
432 LLMultiSliderCtrl* sldr = LLUICtrlFactory::getMultiSliderByName(sDayCycle,
433 "WLDayCycleKeys");
434 LLSpinCtrl* hourSpin = LLUICtrlFactory::getSpinnerByName(sDayCycle,
435 "WLCurKeyHour");
436 LLSpinCtrl* minSpin = LLUICtrlFactory::getSpinnerByName(sDayCycle,
437 "WLCurKeyMin");
438
439 F32 hour = hourSpin->get();
440 F32 min = minSpin->get();
441 F32 val = hour + min / 60.0f;
442
443 const LLString& curSldr = sldr->getCurSlider();
444 sldr->setCurSliderValue(val, TRUE);
445 F32 time = sldr->getCurSliderValue() / sHoursPerDay;
446
447 // now set the key's time in the sliderToKey map
448 LLString presetName = sSliderToKey[curSldr].presetName;
449 sSliderToKey[curSldr].time = time;
450
451 syncTrack();
452}
453
454void LLFloaterDayCycle::onKeyPresetChanged(LLUICtrl* ctrl, void* userData)
455{
456 // get the time
457 LLComboBox* comboBox = LLUICtrlFactory::getComboBoxByName(sDayCycle,
458 "WLKeyPresets");
459 LLMultiSliderCtrl* sldr = LLUICtrlFactory::getMultiSliderByName(sDayCycle,
460 "WLDayCycleKeys");
461
462 // do nothing if no sliders
463 if(sldr->getValue().size() == 0) {
464 return;
465 }
466
467 // change the map
468 LLString newPreset(comboBox->getSelectedValue().asString());
469 const LLString& curSldr = sldr->getCurSlider();
470
471 // if null, don't use
472 if(curSldr == "") {
473 return;
474 }
475
476 sSliderToKey[curSldr].presetName = newPreset;
477
478 syncTrack();
479}
480
481void LLFloaterDayCycle::onTimeRateChanged(LLUICtrl* ctrl, void* userData)
482{
483 // get the time
484 LLSpinCtrl* secSpin = LLUICtrlFactory::getSpinnerByName(sDayCycle,
485 "WLLengthOfDaySec");
486
487 LLSpinCtrl* minSpin = LLUICtrlFactory::getSpinnerByName(sDayCycle,
488 "WLLengthOfDayMin");
489
490 LLSpinCtrl* hourSpin = LLUICtrlFactory::getSpinnerByName(sDayCycle,
491 "WLLengthOfDayHour");
492
493 F32 hour;
494 hour = (F32)hourSpin->getValue().asReal();
495 F32 min;
496 min = (F32)minSpin->getValue().asReal();
497 F32 sec;
498 sec = (F32)secSpin->getValue().asReal();
499
500 F32 time = 60.0f * 60.0f * hour + 60.0f * min + sec;
501 if(time <= 0) {
502 time = 1;
503 }
504 LLWLParamManager::instance()->mDay.mDayRate = time;
505
506 syncTrack();
507}
508
509void LLFloaterDayCycle::onAddKey(void* userData)
510{
511 LLComboBox* comboBox = LLUICtrlFactory::getComboBoxByName(sDayCycle,
512 "WLKeyPresets");
513 LLMultiSliderCtrl* kSldr = LLUICtrlFactory::getMultiSliderByName(sDayCycle,
514 "WLDayCycleKeys");
515 LLMultiSliderCtrl* tSldr = LLUICtrlFactory::getMultiSliderByName(sDayCycle,
516 "WLTimeSlider");
517
518 llassert_always(sSliderToKey.size() == kSldr->getValue().size());
519
520 // get the values
521 LLString newPreset(comboBox->getSelectedValue().asString());
522
523 // add the slider key
524 addSliderKey(tSldr->getCurSliderValue(), newPreset);
525
526 syncTrack();
527}
528
529void LLFloaterDayCycle::addSliderKey(F32 time, const LLString & presetName)
530{
531 LLMultiSliderCtrl* kSldr = LLUICtrlFactory::getMultiSliderByName(sDayCycle,
532 "WLDayCycleKeys");
533
534 // make a slider
535 const LLString& sldrName = kSldr->addSlider(time);
536 if(sldrName == "") {
537 return;
538 }
539
540 // set the key
541 LLWLSkyKey newKey;
542 newKey.presetName = presetName;
543 newKey.time = kSldr->getCurSliderValue();
544
545 llassert_always(sldrName != LLString::null);
546
547 // add to map
548 sSliderToKey.insert(std::pair<LLString, LLWLSkyKey>(sldrName, newKey));
549
550 llassert_always(sSliderToKey.size() == kSldr->getValue().size());
551
552}
553
554void LLFloaterDayCycle::deletePreset(LLString& presetName)
555{
556 LLMultiSliderCtrl* sldr = LLUICtrlFactory::getMultiSliderByName(
557 sDayCycle, "WLDayCycleKeys");
558
559 /// delete any reference
560 std::map<LLString, LLWLSkyKey>::iterator curr_preset, next_preset;
561 for(curr_preset = sSliderToKey.begin(); curr_preset != sSliderToKey.end(); curr_preset = next_preset)
562 {
563 next_preset = curr_preset;
564 ++next_preset;
565 if (curr_preset->second.presetName == presetName)
566 {
567 sldr->deleteSlider(curr_preset->first);
568 sSliderToKey.erase(curr_preset);
569 }
570 }
571}
572
573void LLFloaterDayCycle::onDeleteKey(void* userData)
574{
575 if(sSliderToKey.size() == 0) {
576 return;
577 }
578
579 LLComboBox* comboBox = LLUICtrlFactory::getComboBoxByName(sDayCycle,
580 "WLKeyPresets");
581 LLMultiSliderCtrl* sldr = LLUICtrlFactory::getMultiSliderByName(
582 sDayCycle, "WLDayCycleKeys");
583
584 // delete from map
585 const LLString& sldrName = sldr->getCurSlider();
586 std::map<LLString, LLWLSkyKey>::iterator mIt = sSliderToKey.find(sldrName);
587 sSliderToKey.erase(mIt);
588
589 sldr->deleteCurSlider();
590
591 if(sSliderToKey.size() == 0) {
592 return;
593 }
594
595 const LLString& name = sldr->getCurSlider();
596 comboBox->selectByValue(sSliderToKey[name].presetName);
597 F32 time = sSliderToKey[name].time;
598
599 LLSpinCtrl* hourSpin = LLUICtrlFactory::getSpinnerByName(sDayCycle,
600 "WLCurKeyHour");
601 LLSpinCtrl* minSpin = LLUICtrlFactory::getSpinnerByName(sDayCycle,
602 "WLCurKeyMin");
603
604 // now set the spinners
605 F32 hour = (F32)((S32)time);
606 F32 min = (time - hour) / 60;
607 hourSpin->set(hour);
608 minSpin->set(min);
609
610 syncTrack();
611
612}