summaryrefslogtreecommitdiff
path: root/indra/newview/llfloatereditextdaycycle.cpp
blob: 74cde2b0f7ac170f7961874b353caecf7c2b2610 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
/** 
 * @file llfloatereditextdaycycle.cpp
 * @brief Floater to create or edit a day cycle
 *
 * $LicenseInfo:firstyear=2011&license=viewerlgpl$
 * Second Life Viewer Source Code
 * Copyright (C) 2011, Linden Research, Inc.
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation;
 * version 2.1 of the License only.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 * 
 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 * $/LicenseInfo$
 */

#include "llviewerprecompiledheaders.h"

#include "llfloatereditextdaycycle.h"

// libs
#include "llbutton.h"
#include "llcheckboxctrl.h"
#include "llcombobox.h"
#include "llloadingindicator.h"
#include "llmultisliderctrl.h"
#include "llnotifications.h"
#include "llnotificationsutil.h"
#include "llspinctrl.h"
#include "lltimectrl.h"

#include "llsettingsvo.h"
#include "llinventorymodel.h"

// newview
#include "llagent.h"
//#include "llflyoutcombobtnctrl.h" //Todo: get rid of this and LLSaveOutfitComboBtn, make a proper UI element/button/pannel instead
#include "llregioninfomodel.h"
#include "llviewerregion.h"
#include "llpaneleditwater.h"
#include "llpaneleditsky.h"
//#include "llsettingsvo.h"
//#include "llinventorymodel.h"

#include "llenvironment.h"
#include "lltrans.h"

static const std::string track_tabs[] = {
    "water_track",
    "sky1_track",
    "sky2_track",
    "sky3_track",
    "sky4_track",
};

// For flyout
/*const std::string ACTION_SAVE("save_settings");
const std::string ACTION_SAVEAS("save_as_new_settings");
const std::string ACTION_APPLY_LOCAL("apply_local");
const std::string ACTION_APPLY_PARCEL("apply_parcel");
const std::string ACTION_APPLY_REGION("apply_region");

const std::string XML_FLYOUTMENU_FILE("menu_save_settings.xml");*/

//=========================================================================
// **RIDER**

const std::string LLFloaterFixedEnvironment::KEY_INVENTORY_ID("inventory_id");
const std::string LLFloaterFixedEnvironment::KEY_LIVE_ENVIRONMENT("live_environment");
const std::string LLFloaterFixedEnvironment::KEY_DAY_LENGTH("day_length");
const std::string LLFloaterFixedEnvironment::KEY_DAY_OFFSET("day_offset");

// **RIDER**

LLFloaterEditExtDayCycle::LLFloaterEditExtDayCycle(const LLSD &key):
    LLFloater(key),
    mSaveButton(NULL),
    mCancelButton(NULL),
    mUploadButton(NULL),
    mDayLength(0),
    mDayOffset(0),
    mCurrentTrack(4),
    mTimeSlider(NULL),
    mFramesSlider(NULL),
    //mFlyoutControl(NULL),
    mCurrentTimeLabel(NULL),
    // **RIDER**
    mInventoryId(),
    mInventoryItem(nullptr)
    // **RIDER**
{
    mCommitCallbackRegistrar.add("DayCycle.Track", boost::bind(&LLFloaterEditExtDayCycle::onTrackSelectionCallback, this, _2));
}

LLFloaterEditExtDayCycle::~LLFloaterEditExtDayCycle()
{
    // Todo: consider remaking mFlyoutControl into class that initializes intself with floater,
    // completes at postbuild, e t c...
    // (make it into actual button?, In such case XML_FLYOUTMENU_FILE will be specified in xml)
    //delete mFlyoutControl;
}

void LLFloaterEditExtDayCycle::openFloater(LLSettingsDay::ptr_t settings, S64Seconds daylength, S64Seconds dayoffset)
{
        mSavedDay = settings;
        mEditDay = settings->buildClone();
        mDayLength = daylength;
        mDayOffset = dayoffset;
        LLFloater::openFloater();
}

// virtual
BOOL LLFloaterEditExtDayCycle::postBuild()
{
    getChild<LLLineEditor>("day_cycle_name")->setKeystrokeCallback(boost::bind(&LLFloaterEditExtDayCycle::onCommitName, this, _1, _2), NULL);

    mSaveButton = getChild<LLButton>("save_btn", true);
    mCancelButton = getChild<LLButton>("cancel_btn", true);
    mUploadButton = getChild<LLButton>("upload_btn", true);
    mAddFrameButton = getChild<LLButton>("add_frame", true);
    mDeleteFrameButton = getChild<LLButton>("delete_frame", true);
    mTimeSlider = getChild<LLMultiSliderCtrl>("WLTimeSlider");
    mFramesSlider = getChild<LLMultiSliderCtrl>("WLDayCycleFrames");
    mSkyTabLayoutContainer = getChild<LLView>("frame_settings_sky", true);
    mWaterTabLayoutContainer = getChild<LLView>("frame_settings_water", true);
    mCurrentTimeLabel = getChild<LLTextBox>("current_time", true);

    //mFlyoutControl = new LLFlyoutComboBtnCtrl(this, "save_btn", "btn_flyout", XML_FLYOUTMENU_FILE);
    //mFlyoutControl->setAction([this](LLUICtrl *ctrl, const LLSD &data) { onButtonApply(ctrl, data); });

    mUploadButton->setCommitCallback(boost::bind(&LLFloaterEditExtDayCycle::onBtnSave, this));
    mCancelButton->setCommitCallback(boost::bind(&LLFloaterEditExtDayCycle::onBtnCancel, this));
    mUploadButton->setCommitCallback(boost::bind(&LLFloaterEditExtDayCycle::onBtnUpload, this));
    mTimeSlider->setCommitCallback(boost::bind(&LLFloaterEditExtDayCycle::onTimeSliderMoved, this));
    mFramesSlider->setCommitCallback(boost::bind(&LLFloaterEditExtDayCycle::onFrameSliderCallback, this));
    mAddFrameButton->setCommitCallback(boost::bind(&LLFloaterEditExtDayCycle::onAddTrack, this));
    mDeleteFrameButton->setCommitCallback(boost::bind(&LLFloaterEditExtDayCycle::onRemoveTrack, this));

    mTimeSlider->addSlider(0);


    getChild<LLButton>("sky4_track", true)->setToggleState(true);

	return TRUE;
}

void LLFloaterEditExtDayCycle::onOpen(const LLSD& key)
{
    LLEnvironment::instance().setSelectedEnvironment(LLEnvironment::ENV_EDIT);
    LLEnvironment::instance().updateEnvironment();

    // **RIDER**

    mEditingEnv = LLEnvironment::ENV_NONE;
    mEditDay.reset();
    if (key.has(KEY_INVENTORY_ID))
    {
        loadInventoryItem(key[KEY_INVENTORY_ID].asUUID());
    }
    else if (key.has(KEY_LIVE_ENVIRONMENT))
    {
        LLEnvironment::EnvSelection_t env = static_cast<LLEnvironment::EnvSelection_t>(key[KEY_LIVE_ENVIRONMENT].asInteger());

        loadLiveEnvironment(env);
    }

    mDayLength.value(0);
    mDayOffset.value(0);
    if (key.has(KEY_DAY_LENGTH))
    {
        mDayLength.value(key[KEY_DAY_LENGTH].asReal());
        mDayOffset.value(key[KEY_DAY_OFFSET].asReal());
    }

    // **RIDER**

    LLLineEditor* name_field = getChild<LLLineEditor>("day_cycle_name");
    name_field->setText(mEditDay->getName());

    selectTrack(mCurrentTrack);

    // time labels
    mCurrentTimeLabel->setTextArg("[PRCNT]", std::string("0"));
    const S32 max_elm = 5;
    if (mDayLength.value() != 0)
    {
        S32Hours hrs;
        S32Minutes minutes;
        S64Seconds total;
        //LLDate date;
        LLUIString formatted_label = getString("time_label");
        for (int i = 0; i < max_elm; i++)
        {
            total = ((mDayLength / (max_elm - 1)) * i) + mDayOffset;
            hrs = total;
            minutes = total - hrs;

            //date = LLDate(((mDayLength / (max_elm - 1)) * i) + mDayOffset);
            //formatted_label.setArg("[TIME]", date.toHTTPDateString(std::string("%H:%M")));
            //formatted_label.setArg("[TIME]", llformat("%.1f", hrs.value()));

            formatted_label.setArg("[HH]", llformat("%d", hrs.value()));
            formatted_label.setArg("[MM]", llformat("%d", abs(minutes.value())));
            getChild<LLTextBox>("p" + llformat("%d", i), true)->setTextArg("[DSC]", formatted_label.getString());
        }
        hrs = mDayOffset;
        minutes = mDayOffset - hrs;
        //formatted_label.setArg("[TIME]", llformat("%.1f", hrs.value()));
        //date = LLDate(mDayOffset);
        //formatted_label.setArg("[TIME]", date.toHTTPDateString(std::string("%H:%M")));
        formatted_label.setArg("[HH]", llformat("%d", hrs.value()));
        formatted_label.setArg("[MM]", llformat("%d", abs(minutes.value())));
        mCurrentTimeLabel->setTextArg("[DSC]", formatted_label.getString());
    }
    else
    {
        for (int i = 0; i < max_elm; i++)
        {
            getChild<LLTextBox>("p" + llformat("%d", i), true)->setTextArg("[DSC]", std::string());
        }
        mCurrentTimeLabel->setTextArg("[DSC]", std::string());
    }
}

void LLFloaterEditExtDayCycle::onClose(bool app_quitting)
{
	if (!app_quitting) // there's no point to change environment if we're quitting
	{
        /* TODO: don't restore this environment.  We may have gotten here from land or region. */
        LLEnvironment::instance().clearEnvironment(LLEnvironment::ENV_EDIT);
        LLEnvironment::instance().updateEnvironment();
	}
}

void LLFloaterEditExtDayCycle::onVisibilityChange(BOOL new_visibility)
{
    if (new_visibility)
    {
        LLEnvironment::instance().setEnvironment(LLEnvironment::ENV_EDIT, mEditDay, LLSettingsDay::DEFAULT_DAYLENGTH, LLSettingsDay::DEFAULT_DAYOFFSET);
        LLEnvironment::instance().setSelectedEnvironment(LLEnvironment::ENV_EDIT);
    }
    else
    {
        /* TODO: don't restore this environment.  We may have gotten here from land or region. */
        LLEnvironment::instance().setSelectedEnvironment(LLEnvironment::ENV_LOCAL);
    }
}

/*void LLFloaterEditExtDayCycle::onButtonApply(LLUICtrl *ctrl, const LLSD &data)
{
    std::string ctrl_action = ctrl->getName();

    if (ctrl_action == ACTION_SAVE)
    {
        mSavedDay = mEditDay;
        //doApplyUpdateInventory();
    }
    else if (ctrl_action == ACTION_SAVEAS)
    {
        //doApplyCreateNewInventory();
        LLSettingsVOBase::createInventoryItem(mEditDay, NULL);
    }
    else if ((ctrl_action == ACTION_APPLY_LOCAL) ||
        (ctrl_action == ACTION_APPLY_PARCEL) ||
        (ctrl_action == ACTION_APPLY_REGION))
    {
        //doApplyEnvironment(ctrl_action);
        // Shouldn't be supported?
    }
    else
    {
        LL_WARNS("ENVIRONMENT") << "Unknown settings action '" << ctrl_action << "'" << LL_ENDL;
    }

    if (!mCommitSignal.empty())
        mCommitSignal(mEditDay);
    closeFloater();
    }*/

void LLFloaterEditExtDayCycle::onBtnSave()
{
    mSavedDay = mEditDay;

    //no longer needed?
    if (!mCommitSignal.empty())
        mCommitSignal(mEditDay);

    closeFloater();
}

void LLFloaterEditExtDayCycle::onBtnCancel()
{
    closeFloater();
}

void LLFloaterEditExtDayCycle::onBtnUpload()
{
    LLSettingsVOBase::createInventoryItem(mEditDay);
    //closeFloater();
}

void LLFloaterEditExtDayCycle::onAddTrack()
{
    // todo: 2.5% safety zone
    std::string sldr_key = mFramesSlider->getCurSlider();
    F32 frame = mTimeSlider->getCurSliderValue();
    LLSettingsBase::ptr_t setting;
    if (mEditDay->getSettingsAtKeyframe(frame, mCurrentTrack).get() != NULL)
    {
        return;
    }

    if (mCurrentTrack == LLSettingsDay::TRACK_WATER)
    {
        if (mSliderKeyMap.empty())
        {
            // No existing points, use defaults
            setting = LLSettingsVOWater::buildDefaultWater();
        }
        else
        {
            // clone existing element, since we are intentionally dropping slider on time selection, copy from tab panels
            LLView* tab_container = mWaterTabLayoutContainer->getChild<LLView>("water_tabs"); //can't extract panels directly, since it is in 'tuple'
            LLPanelSettingsWaterMainTab* panel = dynamic_cast<LLPanelSettingsWaterMainTab*>(tab_container->getChildView("water_panel"));
            if (panel)
            {
                setting = panel->getWater()->buildClone();
            }
        }
        mEditDay->setWaterAtKeyframe(std::dynamic_pointer_cast<LLSettingsWater>(setting), frame);
    }
    else
    {
        if (mSliderKeyMap.empty())
        {
            // No existing points, use defaults
            setting = LLSettingsVOSky::buildDefaultSky();
        }
        else
        {
            // clone existing element, since we are intentionally dropping slider on time selection, copy from tab panels
            LLView* tab_container = mSkyTabLayoutContainer->getChild<LLView>("sky_tabs"); //can't extract panels directly, since they are in 'tuple'

            LLPanelSettingsSky* panel = dynamic_cast<LLPanelSettingsSky*>(tab_container->getChildView("atmosphere_panel"));
            if (panel)
            {
                setting = panel->getSky()->buildClone();
            }
        }
        mEditDay->setSkyAtKeyframe(std::dynamic_pointer_cast<LLSettingsSky>(setting), frame, mCurrentTrack);
    }

    addSliderFrame(frame, setting);
    updateTabs();
}

void LLFloaterEditExtDayCycle::onRemoveTrack()
{
    std::string sldr_key = mFramesSlider->getCurSlider();
    if (!sldr_key.empty())
    {
        return;
    }
    removeCurrentSliderFrame();
    updateButtons();
}

void LLFloaterEditExtDayCycle::onCommitName(class LLLineEditor* caller, void* user_data)
{
    mEditDay->setName(caller->getText());
}

void LLFloaterEditExtDayCycle::onTrackSelectionCallback(const LLSD& user_data)
{
    U32 track_index = user_data.asInteger(); // 1-5
    selectTrack(track_index);
}

void LLFloaterEditExtDayCycle::onFrameSliderCallback()
{
    if (mSliderKeyMap.size() == 0)
    {
        mLastFrameSlider.clear();
        return;
    }
    // make sure we have a slider
    const std::string& cur_sldr = mFramesSlider->getCurSlider();
    if (cur_sldr.empty())
    {
        mLastFrameSlider.clear();
        return;
    }

    F32 new_frame = mFramesSlider->getCurSliderValue();
    // todo: add safety checks, user shouldn't be capable of moving one frame over another or move missing frame
    keymap_t::iterator iter = mSliderKeyMap.find(cur_sldr);
    if (iter != mSliderKeyMap.end() && mEditDay->getSettingsAtKeyframe(new_frame, mCurrentTrack).get() == NULL)
    {
        LL_DEBUGS() << "Moving frame from " << iter->second.first << " to " << new_frame << LL_ENDL;
        if (mEditDay->moveTrackKeyframe(mCurrentTrack, iter->second.first, new_frame))
        {
            iter->second.first = new_frame;
        }
    }

    mTimeSlider->setCurSliderValue(new_frame);

    if (mLastFrameSlider != cur_sldr)
    {
        // technically should not be possible for both frame and slider to change
        // but for safety, assume that they can change independently and both
        mLastFrameSlider = cur_sldr;
        updateTabs();
    }
    else
    {
        updateButtons();
        updateTimeAndLabel();
    }
}

void LLFloaterEditExtDayCycle::onTimeSliderMoved()
{
    mFramesSlider->resetCurSlider();

    keymap_t::iterator iter = mSliderKeyMap.begin();
    keymap_t::iterator end_iter = mSliderKeyMap.end();
    F32 frame = mTimeSlider->getCurSliderValue();
    while (iter != end_iter)
    {
        if (iter->second.first == frame)
        {
            mFramesSlider->setCurSlider(iter->first);
            break;
        }
        iter++;
    }

    // Todo: safety checks
    updateTabs();
    //Todo: update something related to time/play/blending?
}

void LLFloaterEditExtDayCycle::selectTrack(U32 track_index)
{
    // todo: safety checks
    mCurrentTrack = track_index;
    LLButton* button = getChild<LLButton>(track_tabs[track_index], true);
    if (button->getToggleState())
    {
        return;
    }

    for (int i = 0; i < LLSettingsDay::TRACK_MAX; i++) // use max value
    {
        getChild<LLButton>(track_tabs[i], true)->setToggleState(false);
    }

    button->setToggleState(true);

    bool show_water = mCurrentTrack == LLSettingsDay::TRACK_WATER;
    mSkyTabLayoutContainer->setVisible(!show_water);
    mWaterTabLayoutContainer->setVisible(show_water);
    updateSlider();
}

void LLFloaterEditExtDayCycle::clearTabs()
{
    // todo: instead init with defaults?
    if (mCurrentTrack == LLSettingsDay::TRACK_WATER)
    {
        const LLSettingsWaterPtr_t p_water = LLSettingsWaterPtr_t(NULL);
        updateWaterTabs(p_water);
    }
    else
    {
        const LLSettingsSkyPtr_t p_sky = LLSettingsSkyPtr_t(NULL);
        updateSkyTabs(p_sky);
    }
    updateButtons();
    updateTimeAndLabel();
}

void LLFloaterEditExtDayCycle::updateTabs()
{
    // TODO: either prevent user from editing existing settings or clone them to not affect saved frames
    std::string sldr = mFramesSlider->getCurSlider();
    if (sldr.empty())
    {
        // keep old settings for duplicating if there are any
        // TODO: disable tabs to prevent editing without nulling settings
    }
    else if (mCurrentTrack == LLSettingsDay::TRACK_WATER)
    {
        const LLSettingsWaterPtr_t p_water = sldr.empty() ? LLSettingsWaterPtr_t(NULL) : mEditDay->getWaterAtKeyframe(mFramesSlider->getCurSliderValue());
        updateWaterTabs(p_water);
    }
    else
    {
        const LLSettingsSkyPtr_t p_sky = sldr.empty() ? LLSettingsSkyPtr_t(NULL) : mEditDay->getSkyAtKeyframe(mFramesSlider->getCurSliderValue(), mCurrentTrack);
        updateSkyTabs(p_sky);
    }
    updateButtons();
    updateTimeAndLabel();
}

void LLFloaterEditExtDayCycle::updateWaterTabs(const LLSettingsWaterPtr_t &p_water)
{
    LLView* tab_container = mWaterTabLayoutContainer->getChild<LLView>("water_tabs"); //can't extract panels directly, since it is in 'tuple'
    LLPanelSettingsWaterMainTab* panel = dynamic_cast<LLPanelSettingsWaterMainTab*>(tab_container->getChildView("water_panel"));
    if (panel)
    {
        panel->setWater(p_water);
    }
}

void LLFloaterEditExtDayCycle::updateSkyTabs(const LLSettingsSkyPtr_t &p_sky)
{
    LLView* tab_container = mSkyTabLayoutContainer->getChild<LLView>("sky_tabs"); //can't extract panels directly, since they are in 'tuple'

    LLPanelSettingsSky* panel;
    panel = dynamic_cast<LLPanelSettingsSky*>(tab_container->getChildView("atmosphere_panel"));
    if (panel)
    {
        panel->setSky(p_sky);
    }
    panel = dynamic_cast<LLPanelSettingsSky*>(tab_container->getChildView("clouds_panel"));
    if (panel)
    {
        panel->setSky(p_sky);
    }
    panel = dynamic_cast<LLPanelSettingsSky*>(tab_container->getChildView("moon_panel"));
    if (panel)
    {
        panel->setSky(p_sky);
    }
}

void LLFloaterEditExtDayCycle::updateButtons()
{
    F32 frame = mTimeSlider->getCurSliderValue();
    LLSettingsBase::ptr_t settings = mEditDay->getSettingsAtKeyframe(frame, mCurrentTrack);
    mAddFrameButton->setEnabled(settings.get() == NULL ? TRUE : FALSE);
    mDeleteFrameButton->setEnabled(mSliderKeyMap.size() > 0 ? TRUE : FALSE);
}

void LLFloaterEditExtDayCycle::updateSlider()
{
    mFramesSlider->clear();
    mSliderKeyMap.clear();

    std::string new_slider;
    F32 frame = 0;
    LLSettingsDay::CycleTrack_t track = mEditDay->getCycleTrack(mCurrentTrack);
    for (auto &track_frame : track)
    {
        // multi slider distinguishes elements by key/name in string format
        // store names to map to be able to recall dependencies
        frame = track_frame.first;
        new_slider = mFramesSlider->addSlider(frame);
        mSliderKeyMap[new_slider] = framedata_t(frame, track_frame.second);
    }

    mLastFrameSlider = new_slider;

    if (mSliderKeyMap.size() > 0)
    {
        mTimeSlider->setCurSliderValue(frame);
        updateTabs();
    }
    else
    {
        // disable panels
        clearTabs();
    }
}

void LLFloaterEditExtDayCycle::updateTimeAndLabel()
{
    F32 time = mTimeSlider->getCurSliderValue();
    mCurrentTimeLabel->setTextArg("[PRCNT]", llformat("%.0f", time * 100));
    if (mDayLength.value() != 0)
    {
        LLUIString formatted_label = getString("time_label");

        //F32Hours hrs = (mDayLength  * time) + mDayOffset;
        //LLDate date((mDayLength  * time) + mDayOffset);
        //formatted_label.setArg("[TIME]", llformat("%.1f", hrs.value()));
        //formatted_label.setArg("[TIME]", date.toHTTPDateString(std::string("%H:%M")));

        S64Seconds total = (mDayLength  * time) + mDayOffset;
        S32Hours hrs = total;
        S32Minutes minutes = total - hrs;

        formatted_label.setArg("[HH]", llformat("%d", hrs.value()));
        formatted_label.setArg("[MM]", llformat("%d", abs(minutes.value())));
        mCurrentTimeLabel->setTextArg("[DSC]", formatted_label.getString());
    }
    else
    {
        mCurrentTimeLabel->setTextArg("[DSC]", std::string());
    }

    // Update blender here:
}

void LLFloaterEditExtDayCycle::addSliderFrame(const F32 frame, LLSettingsBase::ptr_t setting)
{
    // multi slider distinguishes elements by key/name in string format
    // store names to map to be able to recall dependencies
    std::string new_slider = mFramesSlider->addSlider(frame);
    mSliderKeyMap[new_slider] = framedata_t(frame, setting);
    mLastFrameSlider = new_slider;

    mTimeSlider->setCurSliderValue(frame);
    updateTabs();
}

void LLFloaterEditExtDayCycle::removeCurrentSliderFrame()
{
    std::string sldr = mFramesSlider->getCurSlider();
    if (sldr.empty())
    {
        return;
    }
    mFramesSlider->deleteCurSlider();
    keymap_t::iterator iter = mSliderKeyMap.find(sldr);
    if (iter != mSliderKeyMap.end())
    {
        LL_DEBUGS() << "Removing frame from " << iter->second.first << LL_ENDL;
        mSliderKeyMap.erase(iter);
        mEditDay->removeTrackKeyframe(mCurrentTrack, iter->second.first);
    }

    mLastFrameSlider = mFramesSlider->getCurSlider();
    mTimeSlider->setCurSliderValue(mFramesSlider->getCurSliderValue());
    updateTabs();
}

//-------------------------------------------------------------------------

LLFloaterEditExtDayCycle::connection_t LLFloaterEditExtDayCycle::setEditCommitSignal(LLFloaterEditExtDayCycle::edit_commit_signal_t::slot_type cb)
{
    return mCommitSignal.connect(cb);
}

// **RIDER**
void LLFloaterEditExtDayCycle::loadInventoryItem(const LLUUID  &inventoryId)
{
    if (inventoryId.isNull())
    {
        mInventoryItem = nullptr;
        mInventoryId.setNull();
        return;
    }

    mInventoryId = inventoryId;
    LL_INFOS("SETTINGS") << "Setting edit inventory item to " << mInventoryId << "." << LL_ENDL;
    mInventoryItem = gInventory.getItem(mInventoryId);

    if (!mInventoryItem)
    {
        LL_WARNS("SETTINGS") << "Could not find inventory item with Id = " << mInventoryId << LL_ENDL;
        mInventoryId.setNull();
        mInventoryItem = nullptr;
        return;
    }

    LLSettingsVOBase::getSettingsAsset(mInventoryItem->getAssetUUID(),
        [this](LLUUID asset_id, LLSettingsBase::ptr_t settins, S32 status, LLExtStat) { onAssetLoaded(asset_id, settins, status); });
}

void LLFloaterEditExtDayCycle::onAssetLoaded(LLUUID asset_id, LLSettingsBase::ptr_t settings, S32 status)
{
    mEditDay = settings;
    updateEditEnvironment();
    syncronizeTabs();
    refresh();
}

void LLFloaterEditExtDayCycle::loadLiveEnvironment(LLEnvironment::EnvSelection_t env)
{
    mEditingEnv = env;
    for (S32 idx = static_cast<S32>(env); idx <= LLEnvironment::ENV_DEFAULT; ++idx)
    {
        LLSettingsDay::ptr_t day = LLEnvironment::instance().getEnvironmentDay(static_cast<LLEnvironment::EnvSelection_t>(idx));

        if (day)
        {
            mEditDay = day;
            break;
        }
    }

    updateEditEnvironment();
    syncronizeTabs();
    refresh();
}

void LLFloaterEditExtDayCycle::updateEditEnvironment(void)
{
    LLEnvironment::instance().setEnvironment(LLEnvironment::ENV_EDIT, mEditDay);
}

void LLFloaterFixedEnvironment::syncronizeTabs()
{
    LLView* tab_container = mWaterTabLayoutContainer->getChild<LLView>("water_tabs"); //can't extract panels directly, since they are in 'tuple'

    S32 count = mTab->getTabCount();

    for (S32 idx = 0; idx < count; ++idx)
    {
        LLSettingsEditPanel *panel = static_cast<LLSettingsEditPanel *>(mTab->getPanelByIndex(idx));
        if (panel)
            panel->setSettings(mSettings);
    }
}

// **RIDER**