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
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
|
/**
* @file llpanelenvironment.cpp
* @brief LLPanelExperiences class implementation
*
* $LicenseInfo:firstyear=2013&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2013, 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 "llpanelprofile.h"
#include "lluictrlfactory.h"
#include "llexperiencecache.h"
#include "llagent.h"
#include "llparcel.h"
#include "llviewerregion.h"
#include "llpanelenvironment.h"
#include "llslurl.h"
#include "lllayoutstack.h"
#include "llfloater.h"
#include "llfloaterreg.h"
#include "llfloatereditextdaycycle.h"
#include "llmultisliderctrl.h"
#include "llsettingsvo.h"
#include "llappviewer.h"
#include "llcallbacklist.h"
#include "llviewerparcelmgr.h"
#include "llinventorymodel.h"
//=========================================================================
namespace
{
const std::string FLOATER_DAY_CYCLE_EDIT("env_edit_extdaycycle");
inline bool ends_with(std::string const & value, std::string const & ending)
{
if (ending.size() > value.size())
return false;
return std::equal(ending.rbegin(), ending.rend(), value.rbegin());
}
}
//=========================================================================
const std::string LLPanelEnvironmentInfo::BTN_SELECTINV("btn_select_inventory");
const std::string LLPanelEnvironmentInfo::BTN_EDIT("btn_edit");
const std::string LLPanelEnvironmentInfo::BTN_USEDEFAULT("btn_usedefault");
const std::string LLPanelEnvironmentInfo::SLD_DAYLENGTH("sld_day_length");
const std::string LLPanelEnvironmentInfo::SLD_DAYOFFSET("sld_day_offset");
const std::string LLPanelEnvironmentInfo::SLD_ALTITUDES("sld_altitudes");
const std::string LLPanelEnvironmentInfo::ICN_GROUND("icon_ground");
const std::string LLPanelEnvironmentInfo::CHK_ALLOWOVERRIDE("chk_allow_override");
const std::string LLPanelEnvironmentInfo::LBL_TIMEOFDAY("lbl_apparent_time");
const std::string LLPanelEnvironmentInfo::PNL_SETTINGS("pnl_environment_config");
const std::string LLPanelEnvironmentInfo::PNL_ENVIRONMENT_ALTITUDES("pnl_environment_altitudes");
const std::string LLPanelEnvironmentInfo::PNL_BUTTONS("pnl_environment_buttons");
const std::string LLPanelEnvironmentInfo::PNL_DISABLED("pnl_environment_disabled");
const std::string LLPanelEnvironmentInfo::TXT_DISABLED("txt_environment_disabled");
const std::string LLPanelEnvironmentInfo::SDT_DROP_TARGET("sdt_drop_target");
const std::string LLPanelEnvironmentInfo::STR_LABEL_USEDEFAULT("str_label_use_default");
const std::string LLPanelEnvironmentInfo::STR_LABEL_USEREGION("str_label_use_region");
const std::string LLPanelEnvironmentInfo::STR_LABEL_UNKNOWNINV("str_unknow_inventory");
const std::string LLPanelEnvironmentInfo::STR_ALTITUDE_DESCRIPTION("str_altitude_desription");
const std::string LLPanelEnvironmentInfo::STR_NO_PARCEL("str_no_parcel");
const std::string LLPanelEnvironmentInfo::STR_CROSS_REGION("str_cross_region");
const std::string LLPanelEnvironmentInfo::STR_LEGACY("str_legacy");
const std::string LLPanelEnvironmentInfo::STR_DISALLOWED("str_disallowed");
const std::string LLPanelEnvironmentInfo::STR_TOO_SMALL("str_too_small");
const S32 LLPanelEnvironmentInfo::MINIMUM_PARCEL_SIZE(128);
const U32 LLPanelEnvironmentInfo::DIRTY_FLAG_DAYCYCLE(0x01 << 0);
const U32 LLPanelEnvironmentInfo::DIRTY_FLAG_DAYLENGTH(0x01 << 1);
const U32 LLPanelEnvironmentInfo::DIRTY_FLAG_DAYOFFSET(0x01 << 2);
const U32 LLPanelEnvironmentInfo::DIRTY_FLAG_ALTITUDES(0x01 << 3);
const U32 LLPanelEnvironmentInfo::DIRTY_FLAG_MASK(
LLPanelEnvironmentInfo::DIRTY_FLAG_DAYCYCLE |
LLPanelEnvironmentInfo::DIRTY_FLAG_DAYLENGTH |
LLPanelEnvironmentInfo::DIRTY_FLAG_DAYOFFSET |
LLPanelEnvironmentInfo::DIRTY_FLAG_ALTITUDES);
const U32 ALTITUDE_SLIDER_COUNT = 3;
const std::string alt_sliders[] = {
"sld1",
"sld2",
"sld3",
};
const std::string alt_prefixes[] = {
"alt1",
"alt2",
"alt3",
"ground",
"water",
};
const std::string alt_panels[] = {
"pnl_alt1",
"pnl_alt2",
"pnl_alt3",
"pnl_ground",
"pnl_water",
};
static LLDefaultChildRegistry::Register<LLSettingsDropTarget> r("settings_drop_target");
//=========================================================================
LLPanelEnvironmentInfo::LLPanelEnvironmentInfo():
mCurrentEnvironment(),
mDirtyFlag(0),
mEditorLastParcelId(INVALID_PARCEL_ID),
mCrossRegion(false),
mNoSelection(false),
mNoEnvironment(false),
mCurEnvVersion(INVALID_PARCEL_ENVIRONMENT_VERSION),
mSettingsFloater(),
mEditFloater(),
mAllowOverride(true)
{
}
LLPanelEnvironmentInfo::~LLPanelEnvironmentInfo()
{
if (mChangeMonitor.connected())
mChangeMonitor.disconnect();
if (mCommitConnection.connected())
mCommitConnection.disconnect();
if (mUpdateConnection.connected())
mUpdateConnection.disconnect();
}
BOOL LLPanelEnvironmentInfo::postBuild()
{
getChild<LLUICtrl>(BTN_USEDEFAULT)->setCommitCallback([this](LLUICtrl *, const LLSD &){ onBtnDefault(); });
getChild<LLUICtrl>(BTN_SELECTINV)->setCommitCallback([this](LLUICtrl *, const LLSD &){ onBtnSelect(); });
getChild<LLUICtrl>(BTN_EDIT)->setCommitCallback([this](LLUICtrl *, const LLSD &){ onBtnEdit(); });
getChild<LLUICtrl>(SLD_DAYLENGTH)->setCommitCallback([this](LLUICtrl *, const LLSD &value) { onSldDayLengthChanged(value.asReal()); });
getChild<LLSliderCtrl>(SLD_DAYLENGTH)->setSliderMouseUpCallback([this](LLUICtrl *, const LLSD &) { onDayLenOffsetMouseUp(); });
getChild<LLUICtrl>(SLD_DAYOFFSET)->setCommitCallback([this](LLUICtrl *, const LLSD &value) { onSldDayOffsetChanged(value.asReal()); });
getChild<LLSliderCtrl>(SLD_DAYOFFSET)->setSliderMouseUpCallback([this](LLUICtrl *, const LLSD &) { onDayLenOffsetMouseUp(); });
getChild<LLMultiSliderCtrl>(SLD_ALTITUDES)->setCommitCallback([this](LLUICtrl *cntrl, const LLSD &value) { onAltSliderCallback(cntrl, value); });
getChild<LLMultiSliderCtrl>(SLD_ALTITUDES)->setSliderMouseUpCallback([this](LLUICtrl *, const LLSD &) { onAltSliderMouseUp(); });
mChangeMonitor = LLEnvironment::instance().setEnvironmentChanged([this](LLEnvironment::EnvSelection_t env, S32 version) { onEnvironmentChanged(env, version); });
getChild<LLSettingsDropTarget>(SDT_DROP_TARGET)->setPanel(this);
return TRUE;
}
// virtual
void LLPanelEnvironmentInfo::onOpen(const LLSD& key)
{
refreshFromSource();
}
// virtual
void LLPanelEnvironmentInfo::onVisibilityChange(BOOL new_visibility)
{
if (new_visibility)
{
gIdleCallbacks.addFunction(onIdlePlay, this);
}
else
{
LLFloaterSettingsPicker *picker = getSettingsPicker(false);
if (picker)
{
picker->closeFloater();
}
gIdleCallbacks.deleteFunction(onIdlePlay, this);
LLFloaterEditExtDayCycle *dayeditor = getEditFloater(false);
if (mCommitConnection.connected())
mCommitConnection.disconnect();
if (dayeditor)
{
if (dayeditor->isDirty())
dayeditor->refresh();
else
{
dayeditor->closeFloater();
mEditFloater.markDead();
}
}
}
}
void LLPanelEnvironmentInfo::refresh()
{
if (gDisconnected)
return;
if (!setControlsEnabled(canEdit()))
return;
if (!mCurrentEnvironment)
{
return;
}
F32Hours daylength(mCurrentEnvironment->mDayLength);
F32Hours dayoffset(mCurrentEnvironment->mDayOffset);
if (dayoffset.value() > 12.0f)
dayoffset -= F32Hours(24.0);
getChild<LLSliderCtrl>(SLD_DAYLENGTH)->setValue(daylength.value());
getChild<LLSliderCtrl>(SLD_DAYOFFSET)->setValue(dayoffset.value());
udpateApparentTimeOfDay();
updateEditFloater(mCurrentEnvironment, canEdit());
LLEnvironment::altitude_list_t altitudes = LLEnvironment::instance().getRegionAltitudes();
if (altitudes.size() > 0)
{
LLMultiSliderCtrl *sld = getChild<LLMultiSliderCtrl>(SLD_ALTITUDES);
sld->clear();
for (S32 idx = 0; idx < ALTITUDE_SLIDER_COUNT; ++idx)
{
sld->addSlider(altitudes[idx + 1], alt_sliders[idx]);
updateAltLabel(alt_prefixes[idx], idx + 2, altitudes[idx + 1]);
mAltitudes[alt_sliders[idx]] = AltitudeData(idx+1, idx, altitudes[idx+1]);
}
if (sld->getCurNumSliders() != ALTITUDE_SLIDER_COUNT)
{
LL_WARNS("ENVPANEL") << "Failed to add altitude sliders!" << LL_ENDL;
}
readjustAltLabels();
}
updateAltLabel(alt_prefixes[3], 1, 0); // ground
updateAltLabel(alt_prefixes[4], 0, 0); // water
}
void LLPanelEnvironmentInfo::refreshFromEstate()
{
LLViewerRegion *pRegion = gAgent.getRegion();
bool oldAO = mAllowOverride;
mAllowOverride = (isRegion() && LLEstateInfoModel::instance().getAllowEnvironmentOverride()) || pRegion->getAllowEnvironmentOverride();
if (oldAO != mAllowOverride)
refresh();
}
std::string LLPanelEnvironmentInfo::getInventoryNameForAssetId(LLUUID asset_id)
{
std::string name(LLFloaterSettingsPicker::findItemName(asset_id, false, false));
if (name.empty())
return getString(STR_LABEL_UNKNOWNINV);
return name;
}
std::string LLPanelEnvironmentInfo::getNameForTrackIndex(S32 index)
{
std::string invname;
LL_WARNS("LAPRAS") << "mDayCycleName='" << mCurrentEnvironment->mDayCycleName << "'" << LL_ENDL;
if (mCurrentEnvironment->mDayCycleName.empty())
{
invname = mCurrentEnvironment->mNameList[index];
}
else if (!mCurrentEnvironment->mDayCycle->isTrackEmpty(index))
{
invname = mCurrentEnvironment->mDayCycleName;
}
if (invname.empty())
invname = getString("str_empty");
return invname;
}
LLFloaterSettingsPicker * LLPanelEnvironmentInfo::getSettingsPicker(bool create)
{
LLFloaterSettingsPicker *picker = static_cast<LLFloaterSettingsPicker *>(mSettingsFloater.get());
// Show the dialog
if (!picker && create)
{
picker = new LLFloaterSettingsPicker(this,
LLUUID::null, "SELECT SETTINGS");
mSettingsFloater = picker->getHandle();
picker->setCommitCallback([this](LLUICtrl *, const LLSD &data){ onPickerCommitted(data.asUUID()); });
}
return picker;
}
LLFloaterEditExtDayCycle * LLPanelEnvironmentInfo::getEditFloater(bool create)
{
static const S32 FOURHOURS(4 * 60 * 60);
LLFloaterEditExtDayCycle *editor = static_cast<LLFloaterEditExtDayCycle *>(mEditFloater.get());
// Show the dialog
if (!editor && create)
{
LLSD params(LLSDMap(LLFloaterEditExtDayCycle::KEY_EDIT_CONTEXT, isRegion() ? LLFloaterEditExtDayCycle::CONTEXT_REGION : LLFloaterEditExtDayCycle::CONTEXT_PARCEL)
(LLFloaterEditExtDayCycle::KEY_DAY_LENGTH, mCurrentEnvironment ? (S32)(mCurrentEnvironment->mDayLength.value()) : FOURHOURS));
editor = (LLFloaterEditExtDayCycle *)LLFloaterReg::getInstance(FLOATER_DAY_CYCLE_EDIT, params);
if (!editor)
return nullptr;
mEditFloater = editor->getHandle();
}
if (editor && !mCommitConnection.connected())
mCommitConnection = editor->setEditCommitSignal([this](LLSettingsDay::ptr_t pday) { onEditCommitted(pday); });
return editor;
}
void LLPanelEnvironmentInfo::updateEditFloater(const LLEnvironment::EnvironmentInfo::ptr_t &nextenv, bool enable)
{
LLFloaterEditExtDayCycle *dayeditor(getEditFloater(false));
if (!dayeditor)
return;
if (!nextenv || !nextenv->mDayCycle || !enable)
{
if (mCommitConnection.connected())
mCommitConnection.disconnect();
if (dayeditor->isDirty())
dayeditor->refresh();
else
dayeditor->closeFloater();
}
else if (dayeditor->getEditingAssetId() != nextenv->mDayCycle->getAssetId()
|| mEditorLastParcelId != nextenv->mParcelId
|| mEditorLastRegionId != nextenv->mRegionId)
{
// Ignore dirty
// If parcel selection changed whatever we do except saving to inventory with
// old settings will be invalid.
mEditorLastParcelId = nextenv->mParcelId;
mEditorLastRegionId = nextenv->mRegionId;
dayeditor->setEditDayCycle(nextenv->mDayCycle);
}
}
bool LLPanelEnvironmentInfo::setControlsEnabled(bool enabled)
{
bool is_unavailable(false);
bool is_legacy = (mCurrentEnvironment) ? mCurrentEnvironment->mIsLegacy : true;
bool is_bigenough = isLargeEnough();
if (mNoEnvironment || (!LLEnvironment::instance().isExtendedEnvironmentEnabled() && !isRegion()))
{
is_unavailable = true;
getChild<LLTextBox>(TXT_DISABLED)->setText(getString(STR_LEGACY));
}
else if (mNoSelection)
{
is_unavailable = true;
getChild<LLTextBox>(TXT_DISABLED)->setText(getString(STR_NO_PARCEL));
}
else if (mCrossRegion)
{
is_unavailable = true;
getChild<LLTextBox>(TXT_DISABLED)->setText(getString(STR_CROSS_REGION));
}
else if (!isRegion() && !mAllowOverride)
{
is_unavailable = true;
getChild<LLTextBox>(TXT_DISABLED)->setText(getString(STR_DISALLOWED));
}
else if (!is_bigenough)
{
is_unavailable = true;
getChild<LLTextBox>(TXT_DISABLED)->setText(getString(STR_TOO_SMALL));
}
if (is_unavailable)
{
getChild<LLUICtrl>(PNL_SETTINGS)->setVisible(false);
getChild<LLUICtrl>(PNL_BUTTONS)->setVisible(false);
getChild<LLUICtrl>(PNL_DISABLED)->setVisible(true);
getChild<LLUICtrl>(PNL_ENVIRONMENT_ALTITUDES)->setVisible(false);
updateEditFloater(mCurrentEnvironment, false);
return false;
}
getChild<LLUICtrl>(PNL_SETTINGS)->setVisible(true);
getChild<LLUICtrl>(PNL_BUTTONS)->setVisible(true);
getChild<LLUICtrl>(PNL_DISABLED)->setVisible(false);
getChild<LLUICtrl>(PNL_ENVIRONMENT_ALTITUDES)->setVisible(LLEnvironment::instance().isExtendedEnvironmentEnabled());
bool can_enable = enabled && mCurrentEnvironment && (mCurEnvVersion != INVALID_PARCEL_ENVIRONMENT_VERSION);
getChild<LLUICtrl>(BTN_SELECTINV)->setEnabled(can_enable && !is_legacy);
getChild<LLUICtrl>(BTN_USEDEFAULT)->setEnabled(can_enable && !is_legacy);
getChild<LLUICtrl>(BTN_EDIT)->setEnabled(can_enable);
getChild<LLUICtrl>(SLD_DAYLENGTH)->setEnabled(can_enable && !is_legacy);
getChild<LLUICtrl>(SLD_DAYOFFSET)->setEnabled(can_enable && !is_legacy);
getChild<LLUICtrl>(SLD_ALTITUDES)->setEnabled(can_enable && isRegion() && !is_legacy);
getChild<LLUICtrl>(ICN_GROUND)->setColor((can_enable && isRegion() && !is_legacy) ? LLColor4::white : LLColor4::grey % 0.8f);
getChild<LLUICtrl>(PNL_ENVIRONMENT_ALTITUDES)->setEnabled(can_enable && isRegion() && !is_legacy);
getChild<LLUICtrl>(CHK_ALLOWOVERRIDE)->setEnabled(can_enable && isRegion() && !is_legacy);
getChild<LLSettingsDropTarget>(SDT_DROP_TARGET)->setDndEnabled(enabled && !is_legacy);
return true;
}
void LLPanelEnvironmentInfo::setDirtyFlag(U32 flag)
{
mDirtyFlag |= flag;
}
void LLPanelEnvironmentInfo::clearDirtyFlag(U32 flag)
{
mDirtyFlag &= ~flag;
}
void LLPanelEnvironmentInfo::updateAltLabel(const std::string &alt_prefix, U32 sky_index, F32 alt_value)
{
LLMultiSliderCtrl *sld = findChild<LLMultiSliderCtrl>(SLD_ALTITUDES);
if (!sld)
{
LL_WARNS() << "Failed to find slider " << SLD_ALTITUDES << LL_ENDL;
return;
}
LLRect sld_rect = sld->getRect();
S32 sld_range = sld_rect.getHeight();
S32 sld_bottom = sld_rect.mBottom;
S32 sld_offset = sld_rect.getWidth(); // Roughly identical to thumb's width in slider.
S32 pos = (sld_range - sld_offset) * ((alt_value - 100) / (4000 - 100));
// get related views
LLTextBox* text = findChild<LLTextBox>("txt_" + alt_prefix);
LLLineEditor *field = findChild<LLLineEditor>("edt_invname_" + alt_prefix);
LLView *alt_panel = findChild<LLView>("pnl_" + alt_prefix);
if (text && (sky_index > 1))
{
// update text
std::ostringstream convert;
convert << alt_value;
text->setTextArg("[ALTITUDE]", convert.str());
convert.str("");
convert.clear();
convert << sky_index;
text->setTextArg("[INDEX]", convert.str());
}
if (field)
{
field->setText(getNameForTrackIndex(sky_index));
}
if (alt_panel && (sky_index > 1))
{
// move containing panel
LLRect rect = alt_panel->getRect();
S32 height = rect.getHeight();
rect.mBottom = sld_bottom + (sld_offset / 2 + 1) + pos - (height / 2);
rect.mTop = rect.mBottom + height;
alt_panel->setRect(rect);
}
}
void LLPanelEnvironmentInfo::readjustAltLabels()
{
// Re-adjust all labels
// Very simple "adjust after the fact" method
// Note: labels can be in any ordered
for (U32 i = 0; i < ALTITUDE_SLIDER_COUNT - 1; i++)
{
LLView* view_cmp = findChild<LLView>(alt_panels[i]);
for (U32 j = i + 1; j < ALTITUDE_SLIDER_COUNT; j++)
{
LLView* view_intr = findChild<LLView>(alt_panels[j]);
if (view_cmp && view_intr)
{
LLRect cmp_rect = view_cmp->getRect();
LLRect intr_rect = view_intr->getRect();
S32 shift = 0;
if (cmp_rect.mBottom <= intr_rect.mTop && cmp_rect.mBottom >= intr_rect.mBottom)
{
// Approximate shift
// We probably will need more cycle runs over all labels to get accurate one
// At the moment single cycle should do since we have too little elements to do something complicated
shift = (cmp_rect.mBottom - intr_rect.mTop) / 2;
}
else if (cmp_rect.mTop >= intr_rect.mBottom && cmp_rect.mTop <= intr_rect.mTop)
{
// Approximate shift
shift = (cmp_rect.mTop - intr_rect.mBottom) / 2;
}
if (shift != 0)
{
cmp_rect.translate(0, -shift);
view_cmp->setRect(cmp_rect);
intr_rect.translate(0, shift);
view_intr->setRect(intr_rect);
}
}
}
}
}
void LLPanelEnvironmentInfo::onSldDayLengthChanged(F32 value)
{
F32Hours daylength(value);
mCurrentEnvironment->mDayLength = daylength;
setDirtyFlag(DIRTY_FLAG_DAYLENGTH);
udpateApparentTimeOfDay();
}
void LLPanelEnvironmentInfo::onSldDayOffsetChanged(F32 value)
{
F32Hours dayoffset(value);
if (dayoffset.value() <= 0.0f)
dayoffset += F32Hours(24.0);
mCurrentEnvironment->mDayOffset = dayoffset;
setDirtyFlag(DIRTY_FLAG_DAYOFFSET);
udpateApparentTimeOfDay();
}
void LLPanelEnvironmentInfo::onDayLenOffsetMouseUp()
{
if (getDirtyFlag() & (DIRTY_FLAG_DAYLENGTH | DIRTY_FLAG_DAYOFFSET))
{
clearDirtyFlag(DIRTY_FLAG_DAYOFFSET);
clearDirtyFlag(DIRTY_FLAG_DAYLENGTH);
LLHandle<LLPanel> that_h = getHandle();
LLEnvironment::instance().updateParcel(getParcelId(), LLSettingsDay::ptr_t(),
mCurrentEnvironment->mDayLength.value(), mCurrentEnvironment->mDayOffset.value(), LLEnvironment::altitudes_vect_t(),
[that_h](S32 parcel_id, LLEnvironment::EnvironmentInfo::ptr_t envifo) { _onEnvironmentReceived(that_h, parcel_id, envifo); });
}
}
void LLPanelEnvironmentInfo::onAltSliderCallback(LLUICtrl *cntrl, const LLSD &data)
{
LLMultiSliderCtrl *sld = (LLMultiSliderCtrl *)cntrl;
std::string sld_name = sld->getCurSlider();
F32 sld_value = sld->getCurSliderValue();
mAltitudes[sld_name].mAltitude = sld_value;
// update all labels since we could have jumped multiple and we will need to readjust
// (or sort by altitude, too little elements, so I didn't bother with efficiency)
altitudes_data_t::iterator end = mAltitudes.end();
altitudes_data_t::iterator iter = mAltitudes.begin();
altitudes_data_t::iterator iter2;
U32 new_index;
while (iter != end)
{
iter2 = mAltitudes.begin();
new_index = 1;
while (iter2 != end)
{
if (iter->second.mAltitude > iter2->second.mAltitude)
{
new_index++;
}
iter2++;
}
iter->second.mAltitudeIndex = new_index;
updateAltLabel(alt_prefixes[iter->second.mLabelIndex], iter->second.mAltitudeIndex + 1, iter->second.mAltitude);
iter++;
}
readjustAltLabels();
setDirtyFlag(DIRTY_FLAG_ALTITUDES);
}
void LLPanelEnvironmentInfo::onAltSliderMouseUp()
{
if (isRegion() && (getDirtyFlag() & DIRTY_FLAG_ALTITUDES))
{
clearDirtyFlag(DIRTY_FLAG_ALTITUDES);
LLHandle<LLPanel> that_h = getHandle();
LLEnvironment::altitudes_vect_t alts;
for (auto alt : mAltitudes)
{
alts.push_back(alt.second.mAltitude);
}
LLEnvironment::instance().updateParcel(getParcelId(), LLSettingsDay::ptr_t(),
-1, -1, alts,
[that_h](S32 parcel_id, LLEnvironment::EnvironmentInfo::ptr_t envifo) { _onEnvironmentReceived(that_h, parcel_id, envifo); });
}
}
void LLPanelEnvironmentInfo::onBtnDefault()
{
LLHandle<LLPanel> that_h = getHandle();
LLEnvironment::instance().resetParcel(getParcelId(),
[that_h](S32 parcel_id, LLEnvironment::EnvironmentInfo::ptr_t envifo) { _onEnvironmentReceived(that_h, parcel_id, envifo); });
}
void LLPanelEnvironmentInfo::onBtnEdit()
{
static const S32 FOURHOURS(4 * 60 * 60);
LLFloaterEditExtDayCycle *dayeditor = getEditFloater();
LLSD params(LLSDMap(LLFloaterEditExtDayCycle::KEY_EDIT_CONTEXT, isRegion() ? LLFloaterEditExtDayCycle::VALUE_CONTEXT_REGION : LLFloaterEditExtDayCycle::VALUE_CONTEXT_PARCEL)
(LLFloaterEditExtDayCycle::KEY_DAY_LENGTH, mCurrentEnvironment ? (S32)(mCurrentEnvironment->mDayLength.value()) : FOURHOURS)
(LLFloaterEditExtDayCycle::KEY_CANMOD, LLSD::Boolean(true)));
dayeditor->openFloater(params);
if (mCurrentEnvironment && mCurrentEnvironment->mDayCycle)
{
dayeditor->setEditDayCycle(mCurrentEnvironment->mDayCycle);
if (!ends_with(mCurrentEnvironment->mDayCycle->getName(), "(customized)"))
{
dayeditor->setEditName(mCurrentEnvironment->mDayCycle->getName() + "(customized)");
}
}
else
dayeditor->setEditDefaultDayCycle();
}
void LLPanelEnvironmentInfo::onBtnSelect()
{
LLFloaterSettingsPicker *picker = getSettingsPicker();
if (picker)
{
LLUUID item_id;
if (mCurrentEnvironment && mCurrentEnvironment->mDayCycle)
{
item_id = LLFloaterSettingsPicker::findItemID(mCurrentEnvironment->mDayCycle->getAssetId(), false, false);
}
picker->setSettingsFilter(LLSettingsType::ST_NONE);
picker->setSettingsItemId(item_id);
picker->openFloater();
picker->setFocus(TRUE);
}
}
void LLPanelEnvironmentInfo::udpateApparentTimeOfDay()
{
static const F32 SECONDSINDAY(24.0 * 60.0 * 60.0);
if ((!mCurrentEnvironment) || (mCurrentEnvironment->mDayLength.value() < 1.0) || (mCurrentEnvironment->mDayOffset.value() < 1.0))
{
getChild<LLUICtrl>(LBL_TIMEOFDAY)->setVisible(false);
return;
}
getChild<LLUICtrl>(LBL_TIMEOFDAY)->setVisible(true);
S32Seconds now(LLDate::now().secondsSinceEpoch());
now += mCurrentEnvironment->mDayOffset;
F32 perc = (F32)(now.value() % mCurrentEnvironment->mDayLength.value()) / (F32)(mCurrentEnvironment->mDayLength.value());
S32Seconds secondofday((S32)(perc * SECONDSINDAY));
S32Hours hourofday(secondofday);
S32Seconds secondofhour(secondofday - hourofday);
S32Minutes minutesofhour(secondofhour);
bool am_pm(hourofday.value() >= 12);
if (hourofday.value() < 1)
hourofday = S32Hours(12);
if (hourofday.value() > 12)
hourofday -= S32Hours(12);
std::string lblminute(((minutesofhour.value() < 10) ? "0" : "") + LLSD(minutesofhour.value()).asString());
getChild<LLUICtrl>(LBL_TIMEOFDAY)->setTextArg("[HH]", LLSD(hourofday.value()).asString());
getChild<LLUICtrl>(LBL_TIMEOFDAY)->setTextArg("[MM]", lblminute);
getChild<LLUICtrl>(LBL_TIMEOFDAY)->setTextArg("[AP]", std::string(am_pm ? "PM" : "AM"));
getChild<LLUICtrl>(LBL_TIMEOFDAY)->setTextArg("[PRC]", LLSD((S32)(100 * perc)).asString());
}
void LLPanelEnvironmentInfo::onIdlePlay(void *data)
{
((LLPanelEnvironmentInfo *)data)->udpateApparentTimeOfDay();
}
void LLPanelEnvironmentInfo::onPickerCommitted(LLUUID item_id)
{
LLInventoryItem *itemp = gInventory.getItem(item_id);
if (itemp)
{
LLHandle<LLPanel> that_h = getHandle();
LLEnvironment::instance().updateParcel(getParcelId(), itemp->getAssetUUID(),
itemp->getName(),
-1, -1, LLEnvironment::altitudes_vect_t(),
[that_h](S32 parcel_id, LLEnvironment::EnvironmentInfo::ptr_t envifo) { _onEnvironmentReceived(that_h, parcel_id, envifo); });
}
}
void LLPanelEnvironmentInfo::onEditCommitted(LLSettingsDay::ptr_t newday)
{
LLEnvironment::instance().clearEnvironment(LLEnvironment::ENV_EDIT);
LLEnvironment::instance().updateEnvironment();
if (!newday)
{
LL_WARNS("ENVPANEL") << "Editor committed an empty day. Do nothing." << LL_ENDL;
return;
}
if (!mCurrentEnvironment)
{
// Attempting to save mid update?
LL_WARNS("ENVPANEL") << "Failed to apply changes from editor! Dirty state: " << mDirtyFlag << " env version: " << mCurEnvVersion << LL_ENDL;
return;
}
size_t newhash(newday->getHash());
size_t oldhash((mCurrentEnvironment->mDayCycle) ? mCurrentEnvironment->mDayCycle->getHash() : 0);
if (newhash != oldhash)
{
LLHandle<LLPanel> that_h = getHandle();
LLEnvironment::instance().updateParcel(getParcelId(), newday,
-1, -1, LLEnvironment::altitudes_vect_t(),
[that_h](S32 parcel_id, LLEnvironment::EnvironmentInfo::ptr_t envifo) { _onEnvironmentReceived(that_h, parcel_id, envifo); });
}
}
void LLPanelEnvironmentInfo::onEnvironmentChanged(LLEnvironment::EnvSelection_t env, S32 new_version)
{
if (new_version < INVALID_PARCEL_ENVIRONMENT_VERSION)
{
// cleanups and local changes, we are only interested in changes sent by server
return;
}
LL_DEBUGS("ENVPANEL") << "Received environment update " << mCurEnvVersion << " " << new_version << LL_ENDL;
// Environment comes from different sources, from environment update callbacks,
// from hovers (causes callbacks on version change) and from personal requests
// filter out duplicates and out of order packets by checking parcel environment version.
if (isRegion())
{
// Note: region uses same init versions as parcel
if (env == LLEnvironment::ENV_REGION
// version should be always growing, UNSET_PARCEL_ENVIRONMENT_VERSION is backup case
&& (mCurEnvVersion < new_version || mCurEnvVersion <= UNSET_PARCEL_ENVIRONMENT_VERSION))
{
if (new_version >= UNSET_PARCEL_ENVIRONMENT_VERSION)
{
// 'pending state' to prevent re-request on following onEnvironmentChanged if there will be any
mCurEnvVersion = new_version;
}
mCurrentEnvironment.reset();
refreshFromSource();
}
}
else if ((env == LLEnvironment::ENV_PARCEL)
&& (getParcelId() == LLViewerParcelMgr::instance().getAgentParcelId()))
{
LLParcel *parcel = getParcel();
if (parcel)
{
// first for parcel own settings, second is for case when parcel uses region settings
if (mCurEnvVersion < new_version
|| (mCurEnvVersion != new_version && new_version == UNSET_PARCEL_ENVIRONMENT_VERSION))
{
// 'pending state' to prevent re-request on following onEnvironmentChanged if there will be any
mCurEnvVersion = new_version;
mCurrentEnvironment.reset();
refreshFromSource();
}
else if (mCurrentEnvironment)
{
// update controls
refresh();
}
}
}
}
void LLPanelEnvironmentInfo::onPickerAssetDownloaded(LLSettingsBase::ptr_t settings)
{
LLSettingsVODay::buildFromOtherSetting(settings, [this](LLSettingsDay::ptr_t pday)
{
if (pday)
{
mCurrentEnvironment->mDayCycle = pday;
setDirtyFlag(DIRTY_FLAG_DAYCYCLE);
}
refresh();
});
}
void LLPanelEnvironmentInfo::onEnvironmentReceived(S32 parcel_id, LLEnvironment::EnvironmentInfo::ptr_t envifo)
{
if (parcel_id != getParcelId())
{
LL_WARNS("ENVPANEL") << "Have environment for parcel " << parcel_id << " expecting " << getParcelId() << ". Discarding." << LL_ENDL;
return;
}
mCurrentEnvironment = envifo;
clearDirtyFlag(DIRTY_FLAG_MASK);
if (mCurrentEnvironment->mEnvVersion > INVALID_PARCEL_ENVIRONMENT_VERSION)
{
// Server provided version, use it
mCurEnvVersion = mCurrentEnvironment->mEnvVersion;
LL_DEBUGS("ENVPANEL") << " Setting environment version: " << mCurEnvVersion << " for parcel id: " << parcel_id << LL_ENDL;
}
// Backup: Version was not provided for some reason
else
{
LL_WARNS("ENVPANEL") << " Environment version was not provided for " << parcel_id << ", old env version: " << mCurEnvVersion << LL_ENDL;
}
refreshFromEstate();
refresh();
// todo: we have envifo and parcel env version, should we just setEnvironment() and parcel's property to prevent dupplicate requests?
}
void LLPanelEnvironmentInfo::_onEnvironmentReceived(LLHandle<LLPanel> that_h, S32 parcel_id, LLEnvironment::EnvironmentInfo::ptr_t envifo)
{
LLPanelEnvironmentInfo *that = (LLPanelEnvironmentInfo *)that_h.get();
if (!that)
return;
that->onEnvironmentReceived(parcel_id, envifo);
}
LLSettingsDropTarget::LLSettingsDropTarget(const LLSettingsDropTarget::Params& p)
: LLView(p), mEnvironmentInfoPanel(NULL), mDndEnabled(false)
{}
BOOL LLSettingsDropTarget::handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop,
EDragAndDropType cargo_type,
void* cargo_data,
EAcceptance* accept,
std::string& tooltip_msg)
{
BOOL handled = FALSE;
if (getParent() && mDndEnabled)
{
handled = TRUE;
switch (cargo_type)
{
case DAD_SETTINGS:
{
LLViewerInventoryItem* inv_item = (LLViewerInventoryItem*)cargo_data;
if (inv_item && mEnvironmentInfoPanel)
{
LLUUID item_id = inv_item->getUUID();
if (gInventory.getItem(item_id))
{
*accept = ACCEPT_YES_COPY_SINGLE;
if (drop)
{
mEnvironmentInfoPanel->onPickerCommitted(item_id);
}
}
}
else
{
*accept = ACCEPT_NO;
}
break;
}
default:
*accept = ACCEPT_NO;
break;
}
}
return handled;
}
|