forked from siana/SingularityViewer
/
llfloateravatarlist.cpp
1616 lines (1454 loc) · 50.9 KB
/
llfloateravatarlist.cpp
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
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @file llfloateravatarlist.cpp
* @brief Avatar list/radar floater
*
* @author Dale Glass <dale@daleglass.net>, (C) 2007
*/
/**
* Rewritten by jcool410
* Removed usage of globals
* Removed TrustNET
* Added utilization of "minimap" data
* Heavily modified by Henri Beauchamp (the laggy spying tool becomes a true,
* low lag radar)
*/
#include "llviewerprecompiledheaders.h"
#include "llfloateravatarlist.h"
#include "llaudioengine.h"
#include "llavatarconstants.h"
#include "llavatarnamecache.h"
#include "llnotificationsutil.h"
#include "llradiogroup.h"
#include "llscrolllistcolumn.h"
#include "llscrolllistctrl.h"
#include "llscrolllistitem.h"
#include "llsdutil.h"
#include "lltrans.h"
#include "lluictrlfactory.h"
#include "llwindow.h"
#include "hippogridmanager.h"
#include "lfsimfeaturehandler.h"
#include "llagent.h"
#include "llagentcamera.h"
#include "llavataractions.h"
#include "llfloaterchat.h"
#include "llfloaterregioninfo.h"
#include "llfloaterreporter.h"
#include "llmutelist.h"
#include "llspeakers.h"
#include "lltracker.h"
#include "llviewermenu.h"
#include "llviewermessage.h"
#include "llviewerobjectlist.h"
#include "llviewerregion.h"
#include "llviewerwindow.h"
#include "llvoavatar.h"
#include "llvoiceclient.h"
#include "llworld.h"
#include <boost/date_time.hpp>
#include <boost/lexical_cast.hpp>
// [RLVa:KB]
#include "rlvhandler.h"
// [/RLVa:KB]
LLVector3d unpackLocalToGlobalPosition(U32 compact_local, const LLVector3d& origin);
extern U32 gFrameCount;
const S32& radar_namesystem()
{
static const LLCachedControl<S32> namesystem("RadarNameSystem");
return namesystem;
}
namespace
{
void chat_avatar_status(const std::string& name, const LLUUID& key, ERadarStatType type, bool entering, const F32& dist, bool flood = false)
{
static LLCachedControl<bool> radar_chat_alerts(gSavedSettings, "RadarChatAlerts");
if (!radar_chat_alerts) return;
// <Alchemy>
// If we're teleporting, we don't want to see the radar's alerts about EVERY agent leaving.
if (!entering && gAgent.getTeleportState() != LLAgent::TELEPORT_NONE)
{
return;
}
// </Alchemy>
if (gRlvHandler.hasBehaviour(RLV_BHVR_SHOWNAMETAGS)) return; // RLVa:LF Don't announce people are around when blind, that cheats the system.
static LLCachedControl<bool> radar_alert_flood(gSavedSettings, "RadarAlertFlood");
if (flood && !radar_alert_flood) return;
static LLCachedControl<bool> radar_alert_sim(gSavedSettings, "RadarAlertSim");
static LLCachedControl<bool> radar_alert_draw(gSavedSettings, "RadarAlertDraw");
static LLCachedControl<bool> radar_alert_shout_range(gSavedSettings, "RadarAlertShoutRange");
static LLCachedControl<bool> radar_alert_chat_range(gSavedSettings, "RadarAlertChatRange");
static LLCachedControl<bool> radar_alert_age(gSavedSettings, "RadarAlertAge");
LLStringUtil::format_map_t args;
LLChat chat;
switch(type)
{
case STAT_TYPE_SIM: if (radar_alert_sim) args["[RANGE]"] = LLTrans::getString("the_sim"); break;
case STAT_TYPE_DRAW: if (radar_alert_draw) args["[RANGE]"] = LLTrans::getString("draw_distance"); break;
case STAT_TYPE_SHOUTRANGE: if (radar_alert_shout_range) args["[RANGE]"] = LLTrans::getString("shout_range"); break;
case STAT_TYPE_CHATRANGE: if (radar_alert_chat_range) args["[RANGE]"] = LLTrans::getString("chat_range"); break;
case STAT_TYPE_AGE: if (radar_alert_age) chat.mText = name + ' ' + LLTrans::getString("has_triggered_your_avatar_age_alert") + '.'; break;
default: llassert(type); break;
}
args["[NAME]"] = name;
args["[ACTION]"] = LLTrans::getString((entering ? "has_entered" : "has_left") + (flood ? "_flood" : LLStringUtil::null));
if (args.find("[RANGE]") != args.end())
chat.mText = LLTrans::getString("radar_alert_template", args);
else if (chat.mText.empty()) return;
if (entering) // Note: If we decide to make this for leaving as well, change this check to dist != F32_MIN
{
static const LLCachedControl<bool> radar_show_dist("RadarAlertShowDist");
if (radar_show_dist) chat.mText += llformat(" (%.2fm)", dist);
}
chat.mFromName = name;
chat.mFromID = key;
if (!gRlvHandler.hasBehaviour(RLV_BHVR_SHOWNAMES)) // RLVa:LF - No way!
chat.mURL = LLAvatarActions::getSLURL(key);
chat.mSourceType = CHAT_SOURCE_SYSTEM;
LLFloaterChat::addChat(chat);
}
void send_keys_message(const int transact_num, const int num_ids, const std::string& ids)
{
gMessageSystem->newMessage("ScriptDialogReply");
gMessageSystem->nextBlock("AgentData");
gMessageSystem->addUUID("AgentID", gAgentID);
gMessageSystem->addUUID("SessionID", gAgentSessionID);
gMessageSystem->nextBlock("Data");
gMessageSystem->addUUID("ObjectID", gAgentID);
gMessageSystem->addS32("ChatChannel", -777777777);
gMessageSystem->addS32("ButtonIndex", 1);
gMessageSystem->addString("ButtonLabel", llformat("%d,%d", transact_num, num_ids) + ids);
gAgent.sendReliableMessage();
}
} //namespace
LLAvatarListEntry::LLAvatarListEntry(const LLUUID& id, const std::string& name, const LLVector3d& position) :
mID(id), mName(name), mPosition(position), mMarked(false), mFocused(false),
mStats(),
mActivityType(ACTIVITY_NEW), mActivityTimer(),
mIsInList(false), mAge(-1), mTime(time(NULL))
{
LLAvatarPropertiesProcessor& inst(LLAvatarPropertiesProcessor::instance());
inst.addObserver(mID, this);
inst.sendAvatarPropertiesRequest(mID);
inst.sendAvatarNotesRequest(mID);
}
LLAvatarListEntry::~LLAvatarListEntry()
{
static LLCachedControl<bool> radar_alert_flood_leaving(gSavedSettings, "RadarAlertFloodLeaving");
bool cleanup = LLFloaterAvatarList::isCleanup();
if (radar_alert_flood_leaving || !cleanup)
{
setPosition(mPosition, F32_MIN, false, cleanup); // Dead and gone
}
LLAvatarPropertiesProcessor::instance().removeObserver(mID, this);
}
// virtual
void LLAvatarListEntry::processProperties(void* data, EAvatarProcessorType type)
{
// If one wanted more information that gets displayed on profiles to be displayed, here would be the place to do it.
switch(type)
{
case APT_PROPERTIES:
if (mAge == -1)
{
LLAvatarPropertiesProcessor& inst(LLAvatarPropertiesProcessor::instance());
const LLAvatarData* pAvatarData = static_cast<const LLAvatarData*>(data);
if (pAvatarData && (pAvatarData->avatar_id.notNull()))
{
using namespace boost::gregorian;
int year, month, day;
const auto born = pAvatarData->born_on;
if (!born.empty() && sscanf(born.c_str(),"%d/%d/%d",&month,&day,&year) == 3)
try
{
mAge = (day_clock::local_day() - date(year, month, day)).days();
}
catch(const std::out_of_range&) {} // date throws this, so we didn't assign
if (mAge >= 0)
{
static const LLCachedControl<U32> sAvatarAgeAlertDays(gSavedSettings, "AvatarAgeAlertDays");
if (!mStats[STAT_TYPE_AGE] && (U32)mAge < sAvatarAgeAlertDays) //Only announce age once per entry.
chat_avatar_status(mName, mID, STAT_TYPE_AGE, mStats[STAT_TYPE_AGE] = true, (mPosition - gAgent.getPositionGlobal()).magVec());
}
else // Something failed, resend request
{
LL_WARNS() << "Failed to extract age from APT_PROPERTIES for " << mID << ", received \"" << born << "\". Requesting properties again." << LL_ENDL;
inst.sendAvatarPropertiesRequest(mID);
}
}
}
break;
case APT_NOTES:
if (const LLAvatarNotes* pAvatarNotes = static_cast<const LLAvatarNotes*>(data))
mNotes = !pAvatarNotes->notes.empty();
break;
default: break;
}
}
void LLAvatarListEntry::setPosition(const LLVector3d& position, const F32& dist, bool drawn, bool flood)
{
mPosition = position;
bool here(dist != F32_MIN); // F32_MIN only if dead
bool this_sim(here && (gAgent.getRegion()->pointInRegionGlobal(position) || !(LLWorld::getInstance()->positionRegionValidGlobal(position))));
if (this_sim != mStats[STAT_TYPE_SIM]) chat_avatar_status(mName, mID, STAT_TYPE_SIM, mStats[STAT_TYPE_SIM] = this_sim, dist, flood);
if (drawn != mStats[STAT_TYPE_DRAW]) chat_avatar_status(mName, mID, STAT_TYPE_DRAW, mStats[STAT_TYPE_DRAW] = drawn, dist, flood);
bool shoutrange(here && dist < LFSimFeatureHandler::getInstance()->shoutRange());
if (shoutrange != mStats[STAT_TYPE_SHOUTRANGE]) chat_avatar_status(mName, mID, STAT_TYPE_SHOUTRANGE, mStats[STAT_TYPE_SHOUTRANGE] = shoutrange, dist, flood);
bool chatrange(here && dist < LFSimFeatureHandler::getInstance()->sayRange());
if (chatrange != mStats[STAT_TYPE_CHATRANGE]) chat_avatar_status(mName, mID, STAT_TYPE_CHATRANGE, mStats[STAT_TYPE_CHATRANGE] = chatrange, dist, flood);
}
void LLAvatarListEntry::resetName(const bool& hide_tags, const bool& anon_names, const std::string& hidden)
{
if (hide_tags)
mName = hidden;
else
{
LLAvatarNameCache::getNSName(mID, mName, radar_namesystem()); // We wouldn't be alive if this were to fail now.
if (anon_names) mName = RlvStrings::getAnonym(mName);
}
}
const F32 ACTIVITY_TIMEOUT = 1.0f;
void LLAvatarListEntry::setActivity(ACTIVITY_TYPE activity)
{
if (activity >= mActivityType || mActivityTimer.getElapsedTimeF32() > ACTIVITY_TIMEOUT)
{
mActivityType = activity;
mActivityTimer.start();
}
}
const LLAvatarListEntry::ACTIVITY_TYPE LLAvatarListEntry::getActivity()
{
if (mActivityTimer.getElapsedTimeF32() > ACTIVITY_TIMEOUT)
{
mActivityType = ACTIVITY_NONE;
}
return mActivityType;
}
LLFloaterAvatarList::LLFloaterAvatarList() : LLFloater(std::string("radar")),
mTracking(false),
mUpdate("RadarUpdateEnabled"),
mDirtyAvatarSorting(false),
mAvatarList(NULL)
{
LLUICtrlFactory::getInstance()->buildFloater(this, "floater_radar.xml");
}
LLFloaterAvatarList::~LLFloaterAvatarList()
{
mCleanup = true;
LLSD sort;
for (const auto& col : mAvatarList->getSortOrder())
{
sort.append(mAvatarList->getColumn(col.first)->mName);
sort.append(col.second);
}
gSavedSettings.setLLSD("RadarSortOrder", sort);
mAvatars.clear();
}
//static
void LLFloaterAvatarList::toggleInstance(const LLSD&)
{
if (!instanceVisible())
{
showInstance();
}
else
{
getInstance()->close();
}
}
//static
void LLFloaterAvatarList::showInstance()
{
getInstance()->open();
}
void LLFloaterAvatarList::draw()
{
LLFloater::draw();
}
void LLFloaterAvatarList::onOpen()
{
refreshAvatarList();
}
void LLFloaterAvatarList::onClose(bool app_quitting)
{
if (app_quitting || !gSavedSettings.getBOOL("RadarKeepOpen"))
destroy();
else
setVisible(false);
}
BOOL LLFloaterAvatarList::handleRightMouseDown(S32 x, S32 y, MASK mask)
{
if (gRlvHandler.hasBehaviour(RLV_BHVR_SHOWNAMETAGS) || gRlvHandler.hasBehaviour(RLV_BHVR_SHOWNAMES)) return TRUE; // RLVa:LF - No menu, menus share listeners with others that we may want to work; plus the user has no idea who these people are!!
return LLFloater::handleRightMouseDown(x, y, mask);
}
bool is_nearby(const LLUUID& id)
{
if (id.isNull()) return false;
if (const auto inst = LLFloaterAvatarList::getIfExists())
return inst->getAvatarEntry(id);
uuid_vec_t avatars;
LLWorld::instance().getAvatars(&avatars);
return std::find(avatars.begin(), avatars.end(), id) != avatars.end();
}
void track_av(const LLUUID& id)
{
if (auto inst = LLFloaterAvatarList::getIfExists())
if (inst->getAvatarEntry(id))
{
inst->trackAvatar(id);
return;
}
LLWorld::pos_map_t avatars;
LLWorld::instance().getAvatars(&avatars);
LLTracker::trackLocation(avatars[id], LLStringUtil::null, LLStringUtil::null);
}
void teleport_to(const LLUUID& id)
{
if (auto entry = LLFloaterAvatarList::instanceExists() ? LLFloaterAvatarList::instance().getAvatarEntry(id) : nullptr)
gAgent.teleportViaLocation(entry->getPosition());
else
{
LLWorld::pos_map_t avatars;
LLWorld::instance().getAvatars(&avatars);
gAgent.teleportViaLocation(avatars[id]);
}
}
static void cmd_profile(const LLAvatarListEntry* entry);
static void cmd_toggle_mark(LLAvatarListEntry* entry);
static void cmd_ar(const LLAvatarListEntry* entry);
static void cmd_teleport(const LLAvatarListEntry* entry);
namespace
{
typedef LLMemberListener<LLView> view_listener_t;
class RadarTrack : public view_listener_t
{
bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata)
{
LLFloaterAvatarList::instance().onClickTrack();
return true;
}
};
class RadarMark : public view_listener_t
{
bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata)
{
LLFloaterAvatarList::instance().doCommand(cmd_toggle_mark);
return true;
}
};
class RadarFocus : public view_listener_t
{
bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata)
{
LLFloaterAvatarList::setFocusAvatar(LFIDBearer::getActiveSelectedID());
return true;
}
};
class RadarFocusPrev : public view_listener_t
{
bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata)
{
LLFloaterAvatarList::instance().focusOnPrev(userdata.asInteger());
return true;
}
};
class RadarFocusNext : public view_listener_t
{
bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata)
{
LLFloaterAvatarList::instance().focusOnNext(userdata.asInteger());
return true;
}
};
class RadarTeleportTo : public view_listener_t
{
bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata)
{
teleport_to(LFIDBearer::getActiveSelectedID());
return true;
}
};
class RadarAnnounceKeys : public view_listener_t
{
bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata)
{
LLFloaterAvatarList::instance().sendKeys();
return true;
}
};
}
void addMenu(view_listener_t* menu, const std::string& name);
void add_radar_listeners()
{
addMenu(new RadarTrack, "Radar.Track");
addMenu(new RadarMark, "Radar.Mark");
addMenu(new RadarFocus, "Radar.Focus");
addMenu(new RadarFocusPrev, "Radar.FocusPrev");
addMenu(new RadarFocusNext, "Radar.FocusNext");
addMenu(new RadarTeleportTo, "Radar.TeleportTo");
addMenu(new RadarAnnounceKeys, "Radar.AnnounceKeys");
}
BOOL LLFloaterAvatarList::postBuild()
{
// Set callbacks
childSetAction("profile_btn", boost::bind(&LLFloaterAvatarList::doCommand, this, &cmd_profile, false));
childSetAction("im_btn", boost::bind(&LLFloaterAvatarList::onClickIM, this));
childSetAction("offer_btn", boost::bind(&LLFloaterAvatarList::onClickTeleportOffer, this));
childSetAction("track_btn", boost::bind(&LLFloaterAvatarList::onClickTrack, this));
childSetAction("mark_btn", boost::bind(&LLFloaterAvatarList::doCommand, this, &cmd_toggle_mark, false));
childSetAction("focus_btn", boost::bind(&LLFloaterAvatarList::onClickFocus, this));
childSetAction("prev_in_list_btn", boost::bind(&LLFloaterAvatarList::focusOnPrev, this, false));
childSetAction("next_in_list_btn", boost::bind(&LLFloaterAvatarList::focusOnNext, this, false));
childSetAction("prev_marked_btn", boost::bind(&LLFloaterAvatarList::focusOnPrev, this, true));
childSetAction("next_marked_btn", boost::bind(&LLFloaterAvatarList::focusOnNext, this, true));
childSetAction("get_key_btn", boost::bind(&LLFloaterAvatarList::onClickGetKey, this));
childSetAction("freeze_btn", boost::bind(&LLFloaterAvatarList::onClickFreeze, this));
childSetAction("eject_btn", boost::bind(&LLFloaterAvatarList::onClickEject, this));
childSetAction("mute_btn", boost::bind(&LLFloaterAvatarList::onClickMute, this));
childSetAction("ar_btn", boost::bind(&LLFloaterAvatarList::doCommand, this, &cmd_ar, true));
childSetAction("teleport_btn", boost::bind(&LLFloaterAvatarList::doCommand, this, &cmd_teleport, true));
childSetAction("estate_eject_btn", boost::bind(&LLFloaterAvatarList::onClickEjectFromEstate, this));
childSetAction("estate_ban_btn",boost::bind(&LLFloaterAvatarList:: onClickBanFromEstate, this));
childSetAction("send_keys_btn", boost::bind(&LLFloaterAvatarList::sendKeys, this));
gSavedSettings.getControl("RadarColumnMarkHidden")->getSignal()->connect(boost::bind(&LLFloaterAvatarList::assessColumns, this));
gSavedSettings.getControl("RadarColumnPositionHidden")->getSignal()->connect(boost::bind(&LLFloaterAvatarList::assessColumns, this));
gSavedSettings.getControl("RadarColumnAltitudeHidden")->getSignal()->connect(boost::bind(&LLFloaterAvatarList::assessColumns, this));
gSavedSettings.getControl("RadarColumnActivityHidden")->getSignal()->connect(boost::bind(&LLFloaterAvatarList::assessColumns, this));
gSavedSettings.getControl("RadarColumnVoiceHidden")->getSignal()->connect(boost::bind(&LLFloaterAvatarList::assessColumns, this));
gSavedSettings.getControl("RadarColumnNotesHidden")->getSignal()->connect(boost::bind(&LLFloaterAvatarList::assessColumns, this));
gSavedSettings.getControl("RadarColumnAgeHidden")->getSignal()->connect(boost::bind(&LLFloaterAvatarList::assessColumns, this));
gSavedSettings.getControl("RadarColumnTimeHidden")->getSignal()->connect(boost::bind(&LLFloaterAvatarList::assessColumns, this));
// Get a pointer to the scroll list from the interface
mAvatarList = getChild<LLScrollListCtrl>("avatar_list");
const LLSD sort = gSavedSettings.getLLSD("RadarSortOrder");
for (auto it = sort.beginArray(), end = sort.endArray(); it < end; ++it)
{
const auto& column_name = (*it);
const auto& ascending = (*++it);
mAvatarList->sortByColumn(column_name.asStringRef(), ascending.asBoolean());
}
mAvatarList->setCommitOnSelectionChange(true);
mAvatarList->setCommitCallback(boost::bind(&LLFloaterAvatarList::onSelectName,this));
mAvatarList->setDoubleClickCallback(boost::bind(&LLFloaterAvatarList::onClickFocus,this));
mAvatarList->setSortChangedCallback(boost::bind(&LLFloaterAvatarList::onAvatarSortingChanged,this));
for (LLViewerRegion* region : LLWorld::instance().getRegionList())
{
updateAvatarList(region, true);
}
assessColumns();
if(gHippoGridManager->getConnectedGrid()->isSecondLife())
childSetVisible("hide_client", false);
else
gSavedSettings.getControl("RadarColumnClientHidden")->getSignal()->connect(boost::bind(&LLFloaterAvatarList::assessColumns, this));
return true;
}
void col_helper(const bool hide, LLCachedControl<S32> &setting, LLScrollListColumn* col)
{
// Brief Explanation:
// Check if we want the column hidden, and if it's still showing. If so, hide it, but save its width.
// Otherwise, if we don't want it hidden, but it is, unhide it to the saved width.
// We only store width of columns when hiding here for the purpose of hiding and unhiding.
const int width = col->getWidth();
if (hide && width)
{
setting = width;
col->setWidth(0);
}
else if(!hide && !width)
{
col->setWidth(setting);
}
}
enum AVATARS_COLUMN_ORDER
{
LIST_MARK,
LIST_AVATAR_NAME,
LIST_DISTANCE,
LIST_POSITION,
LIST_ALTITUDE,
LIST_ACTIVITY,
LIST_VOICE,
LIST_NOTES,
LIST_AGE,
LIST_TIME,
LIST_CLIENT,
};
//Macro to reduce redundant lines. Preprocessor concatenation and stringizing avoids bloat that
//wrapping in a class would create.
#define BIND_COLUMN_TO_SETTINGS(col, name)\
static const LLCachedControl<bool> hide_##name(gSavedSettings, "RadarColumn"#name"Hidden");\
static LLCachedControl<S32> width_##name(gSavedSettings, "RadarColumn"#name"Width");\
col_helper(hide_##name, width_##name, mAvatarList->getColumn(col));
void LLFloaterAvatarList::assessColumns()
{
BIND_COLUMN_TO_SETTINGS(LIST_MARK,Mark);
BIND_COLUMN_TO_SETTINGS(LIST_POSITION,Position);
BIND_COLUMN_TO_SETTINGS(LIST_ALTITUDE,Altitude);
BIND_COLUMN_TO_SETTINGS(LIST_ACTIVITY,Activity);
BIND_COLUMN_TO_SETTINGS(LIST_VOICE,Voice);
BIND_COLUMN_TO_SETTINGS(LIST_NOTES,Notes);
BIND_COLUMN_TO_SETTINGS(LIST_AGE,Age);
BIND_COLUMN_TO_SETTINGS(LIST_TIME,Time);
static const LLCachedControl<bool> hide_client(gSavedSettings, "RadarColumnClientHidden");
static LLCachedControl<S32> width_name(gSavedSettings, "RadarColumnNameWidth");
bool client_hidden = hide_client || gHippoGridManager->getConnectedGrid()->isSecondLife();
LLScrollListColumn* name_col = mAvatarList->getColumn(LIST_AVATAR_NAME);
LLScrollListColumn* client_col = mAvatarList->getColumn(LIST_CLIENT);
if (client_hidden != !!name_col->mDynamicWidth)
{
//Don't save if its being hidden because of detected grid. Not that it really matters, as this setting(along with the other RadarColumn*Width settings)
//isn't handled in a way that allows it to carry across sessions, but I assume that may want to be fixed in the future..
if(client_hidden && !gHippoGridManager->getConnectedGrid()->isSecondLife() && name_col->getWidth() > 0)
width_name = name_col->getWidth();
//MUST call setWidth(0) first to clear out mTotalStaticColumnWidth accumulation in parent before changing the mDynamicWidth value
client_col->setWidth(0);
name_col->setWidth(0);
client_col->mDynamicWidth = !client_hidden;
name_col->mDynamicWidth = client_hidden;
mAvatarList->setNumDynamicColumns(1); // Dynamic width is set on only one column, be sure to let the list know, otherwise we may divide by zero
if(!client_hidden)
{
name_col->setWidth(llmax(width_name.get(),10));
}
}
mAvatarList->updateLayout();
}
void updateParticleActivity(LLDrawable *drawablep)
{
if (LLFloaterAvatarList::instanceExists())
{
LLViewerObject *vobj = drawablep->getVObj();
if (vobj && vobj->isParticleSource())
{
LLUUID id = vobj->mPartSourcep->getOwnerUUID();
LLAvatarListEntry *ent = LLFloaterAvatarList::getInstance()->getAvatarEntry(id);
if ( NULL != ent )
{
ent->setActivity(LLAvatarListEntry::ACTIVITY_PARTICLES);
}
}
}
}
const F32& radar_range_radius()
{
static const LLCachedControl<F32> radius("RadarRangeRadius", 0);
return radius;
}
void LLFloaterAvatarList::updateAvatarList(const LLViewerRegion* region, bool first)
{
// Check whether updates are enabled
if (!mUpdate)
{
refreshTracker();
return;
}
{
const std::vector<U32>& map_avs(region->mMapAvatars);
const uuid_vec_t& map_avids(region->mMapAvatarIDs);
const LLVector3d& mypos(gAgent.getPositionGlobal());
const LLVector3d& origin(region->getOriginGlobal());
const F32 max_range(radar_range_radius() * radar_range_radius());
static LLCachedControl<bool> announce(gSavedSettings, "RadarChatKeys");
std::queue<LLUUID> announce_keys;
bool no_names(gRlvHandler.hasBehaviour(RLV_BHVR_SHOWNAMETAGS));
bool anon_names(!no_names && gRlvHandler.hasBehaviour(RLV_BHVR_SHOWNAMES));
const std::string& rlv_hidden(RlvStrings::getString(RLV_STRING_HIDDEN));
for (size_t i = 0, size = map_avs.size(); i < size; ++i)
{
const LLUUID& avid = map_avids[i];
LLVector3d position(unpackLocalToGlobalPosition(map_avs[i], origin));
LLVOAvatar* avatarp = gObjectList.findAvatar(avid);
if (avatarp) position = gAgent.getPosGlobalFromAgent(avatarp->getCharacterPosition());
if (max_range && dist_vec_squared(position, mypos) > max_range) continue; // Out of desired range
std::string name;
if (no_names) name = rlv_hidden;
else if (!LLAvatarNameCache::getNSName(avid, name, radar_namesystem())) continue; //prevent (Loading...)
else if (anon_names) name = RlvStrings::getAnonym(name);
LLAvatarListEntry* entry = getAvatarEntry(avid);
if (!entry)
{
// Avatar not there yet, add it
if (announce && gAgent.getRegion()->pointInRegionGlobal(position)) announce_keys.push(avid);
mAvatars.push_back(LLAvatarListEntryPtr(entry = new LLAvatarListEntry(avid, name, position)));
}
// Announce position
entry->setPosition(position, (position - mypos).magVec(), avatarp, first);
// Mark as typing if they are typing
if (avatarp && avatarp->isTyping()) entry->setActivity(LLAvatarListEntry::ACTIVITY_TYPING);
}
// Set activity for anyone making sounds
if (gAudiop)
for (LLAudioEngine::source_map::iterator i = gAudiop->mAllSources.begin(); i != gAudiop->mAllSources.end(); ++i)
if (LLAvatarListEntry* entry = getAvatarEntry((i->second)->getOwnerID()))
entry->setActivity(LLAvatarListEntry::ACTIVITY_SOUND);
//let us send the keys in a more timely fashion
if (announce && !announce_keys.empty())
{
// NOTE: This fragment is repeated in sendKey
std::ostringstream ids;
U32 transact_num = gFrameCount;
U32 num_ids = 0;
while(!announce_keys.empty())
{
ids << ',' << announce_keys.front().asString();
++num_ids;
if (ids.tellp() > 200)
{
send_keys_message(transact_num, num_ids, ids.str());
ids.seekp(num_ids = 0);
ids.str(LLStringUtil::null);
}
announce_keys.pop();
}
if (num_ids) send_keys_message(transact_num, num_ids, ids.str());
}
}
}
void LLFloaterAvatarList::expireAvatarList(const std::list<LLUUID>& ids)
{
if (!ids.empty())
{
uuid_vec_t existing_avs;
std::vector<LLViewerRegion*> neighbors;
gAgent.getRegion()->getNeighboringRegions(neighbors);
for (const LLViewerRegion* region : neighbors)
existing_avs.insert(existing_avs.end(), region->mMapAvatarIDs.begin(), region->mMapAvatarIDs.end());
for (const LLUUID& id : ids)
{
if (std::find(existing_avs.begin(), existing_avs.end(), id) != existing_avs.end()) continue; // Now in another region we know.
av_list_t::iterator it(std::find_if(mAvatars.begin(), mAvatars.end(), LLAvatarListEntry::uuidMatch(id)));
if (it != mAvatars.end())
mAvatars.erase(it);
}
}
refreshAvatarList();
refreshTracker();
}
void LLFloaterAvatarList::updateAvatarSorting()
{
if (mDirtyAvatarSorting)
{
mDirtyAvatarSorting = false;
if (mAvatars.size() <= 1) return; // Nothing to sort.
const std::vector<LLScrollListItem*> list = mAvatarList->getAllData();
av_list_t::iterator insert_it = mAvatars.begin();
for(std::vector<LLScrollListItem*>::const_iterator it = list.begin(); it != list.end(); ++it)
{
av_list_t::iterator av_it = std::find_if(mAvatars.begin(),mAvatars.end(),LLAvatarListEntry::uuidMatch((*it)->getUUID()));
if (av_it == mAvatars.end()) continue;
std::iter_swap(insert_it++, av_it);
if (insert_it+1 == mAvatars.end()) return; // We've run out of elements to sort
}
}
}
bool getCustomColorRLV(const LLUUID& id, LLColor4& color, LLViewerRegion* parent_estate, bool name_restricted);
/**
* Redraws the avatar list
* Only does anything if the avatar list is visible.
* @author Dale Glass
*/
void LLFloaterAvatarList::refreshAvatarList()
{
// Don't update when interface is hidden
if (!getVisible()) return;
// We rebuild the list fully each time it's refreshed
// The assumption is that it's faster to refill it and sort than
// to rebuild the whole list.
uuid_vec_t selected = mAvatarList->getSelectedIDs();
S32 scrollpos = mAvatarList->getScrollPos();
mAvatarList->deleteAllItems();
LLVector3d mypos = gAgent.getPositionGlobal();
LLVector3d posagent;
posagent.setVec(gAgent.getPositionAgent());
LLVector3d simpos = mypos - posagent;
const S32 width(gAgent.getRegion() ? gAgent.getRegion()->getWidth() : 256);
LLSpeakerMgr& speakermgr = LLActiveSpeakerMgr::instance();
LLRect screen_rect;
localRectToScreen(getLocalRect(), &screen_rect);
speakermgr.update(!(screen_rect.pointInRect(gViewerWindow->getCurrentMouseX(), gViewerWindow->getCurrentMouseY()) && gMouseIdleTimer.getElapsedTimeF32() < 5.f));
av_list_t dead_entries;
bool name_restricted(gRlvHandler.hasBehaviour(RLV_BHVR_SHOWNAMETAGS) || gRlvHandler.hasBehaviour(RLV_BHVR_SHOWNAMES));
for (auto& entry : mAvatars)
{
LLVector3d position = entry->getPosition();
LLVector3d delta = position - mypos;
bool UnknownAltitude = position.mdV[VZ] == (gHippoGridManager->getConnectedGrid()->isSecondLife() ? 1020.f : 0.f);
F32 distance = UnknownAltitude ? 9000.0f : (F32)delta.magVec();
delta.mdV[2] = 0.0f;
// HACK: Workaround for an apparent bug:
// sometimes avatar entries get stuck, and are registered
// by the client as perpetually moving in the same direction.
// this makes sure they get removed from the visible list eventually
//jcool410 -- this fucks up seeing dueds thru minimap data > 1024m away, so, lets just say > 2048m to the side is bad
//aka 8 sims
if (delta.magVec() > 2048.0)
{
dead_entries.push_back(entry);
continue;
}
entry->setInList();
const LLUUID& av_id = entry->getID();
LLScrollListItem::Params element;
element.value = av_id;
static const LLCachedControl<bool> hide_mark("RadarColumnMarkHidden");
if (!hide_mark)
{
LLScrollListCell::Params mark;
mark.column = "marked";
mark.type = "text";
if (entry->isMarked())
{
mark.value = "X";
mark.color = LLColor4::blue;
mark.font_style = "BOLD";
}
element.columns.add(mark);
}
static const LLCachedControl<LLColor4> unselected_color(gColors, "ScrollUnselectedColor", LLColor4(0.f, 0.f, 0.f, 0.8f));
static const LLCachedControl<LLColor4> sDefaultListText(gColors, "DefaultListText");
static const LLCachedControl<LLColor4> ascent_muted_color("AscentMutedColor", LLColor4(0.7f,0.7f,0.7f,1.f));
LLColor4 color = sDefaultListText;
// Name never hidden
{
LLScrollListCell::Params name;
name.column = "avatar_name";
name.type = "text";
name.value = entry->getName();
if (entry->isFocused())
{
name.font_style = "BOLD";
}
//<edit> custom colors for certain types of avatars!
getCustomColorRLV(av_id, color, LLWorld::getInstance()->getRegionFromPosGlobal(entry->getPosition()), name_restricted);
name.color = color*0.5f + unselected_color*0.5f;
element.columns.add(name);
}
char temp[32];
// Distance never hidden
{
color = sDefaultListText;
LLScrollListCell::Params dist;
dist.column = "distance";
dist.type = "text";
static const LLCachedControl<LLColor4> sRadarTextDrawDist(gColors, "RadarTextDrawDist");
if (UnknownAltitude)
{
strcpy(temp, "?");
if (entry->mStats[STAT_TYPE_DRAW])
{
color = sRadarTextDrawDist;
}
}
else
{
if (distance <= LFSimFeatureHandler::getInstance()->shoutRange())
{
static const LLCachedControl<LLColor4> sRadarTextChatRange(gColors, "RadarTextChatRange");
static const LLCachedControl<LLColor4> sRadarTextShoutRange(gColors, "RadarTextShoutRange");
snprintf(temp, sizeof(temp), "%.1f", distance);
color = (distance > LFSimFeatureHandler::getInstance()->sayRange()) ? sRadarTextShoutRange : sRadarTextChatRange;
}
else
{
if (entry->mStats[STAT_TYPE_DRAW]) color = sRadarTextDrawDist;
snprintf(temp, sizeof(temp), "%d", (S32)distance);
}
}
dist.value = temp;
dist.color = color * 0.7f + unselected_color * 0.3f; // Liru: Blend testing!
//dist.color = color;
element.columns.add(dist);
}
static const LLCachedControl<bool> hide_pos("RadarColumnPositionHidden");
if (!hide_pos)
{
LLScrollListCell::Params pos;
position -= simpos;
S32 x(position.mdV[VX]);
S32 y(position.mdV[VY]);
if (x >= 0 && x <= width && y >= 0 && y <= width)
{
snprintf(temp, sizeof(temp), "%d, %d", x, y);
}
else
{
temp[0] = '\0';
if (y < 0)
{
strcat(temp, "S");
}
else if (y > width)
{
strcat(temp, "N");
}
if (x < 0)
{
strcat(temp, "W");
}
else if (x > width)
{
strcat(temp, "E");
}
}
pos.column = "position";
pos.type = "text";
pos.value = temp;
element.columns.add(pos);
}
static const LLCachedControl<bool> hide_alt("RadarColumnAltitudeHidden");
if (!hide_alt)
{
LLScrollListCell::Params alt;
alt.column = "altitude";
alt.type = "text";
if (UnknownAltitude)
{
strcpy(temp, "?");
}
else
{
snprintf(temp, sizeof(temp), "%d", (S32)position.mdV[VZ]);
}
alt.value = temp;
element.columns.add(alt);
}
static const LLCachedControl<bool> hide_act("RadarColumnActivityHidden");
if (!hide_act)
{
LLScrollListCell::Params act;
act.column = "activity";
act.type = "icon";
switch(entry->getActivity())
{
case LLAvatarListEntry::ACTIVITY_MOVING:
act.value = "inv_item_animation.tga";
act.tool_tip = getString("Moving");
break;
case LLAvatarListEntry::ACTIVITY_GESTURING:
act.value = "inv_item_gesture.tga";
act.tool_tip = getString("Playing a gesture");
break;
case LLAvatarListEntry::ACTIVITY_SOUND:
act.value = "inv_item_sound.tga";
act.tool_tip = getString("Playing a sound");
break;
case LLAvatarListEntry::ACTIVITY_REZZING:
act.value = "ff_edit_theirs.tga";
act.tool_tip = getString("Rezzing objects");
break;
case LLAvatarListEntry::ACTIVITY_PARTICLES:
act.value = "particles_scan.tga";
act.tool_tip = getString("Creating particles");
break;
case LLAvatarListEntry::ACTIVITY_NEW:
act.value = "avatar_new.tga";
act.tool_tip = getString("Just arrived");
break;
case LLAvatarListEntry::ACTIVITY_TYPING:
act.value = "avatar_typing.tga";
act.tool_tip = getString("Typing");
break;
default:
break;
}
element.columns.add(act);
}
static const LLCachedControl<bool> hide_voice("RadarColumnVoiceHidden");
if (!hide_voice)
{
LLScrollListCell::Params voice;
voice.column("voice");
voice.type("icon");
// transplant from llparticipantlist.cpp, update accordingly.
if (LLPointer<LLSpeaker> speakerp = speakermgr.findSpeaker(av_id))
{
if (speakerp->mStatus == LLSpeaker::STATUS_MUTED)
{
voice.value("mute_icon.tga");
voice.color(speakerp->mModeratorMutedVoice ? ascent_muted_color : LLColor4(1.f, 71.f / 255.f, 71.f / 255.f, 1.f));
}
else
{
switch(llmin(2, llfloor((speakerp->mSpeechVolume / LLVoiceClient::OVERDRIVEN_POWER_LEVEL) * 3.f)))
{
case 0:
voice.value("icn_active-speakers-dot-lvl0.tga");
break;
case 1:
voice.value("icn_active-speakers-dot-lvl1.tga");
break;
case 2:
voice.value("icn_active-speakers-dot-lvl2.tga");
break;
}
// non voice speakers have hidden icons, render as transparent
voice.color(speakerp->mStatus > LLSpeaker::STATUS_VOICE_ACTIVE ? LLColor4::transparent : speakerp->mDotColor);
}
}
element.columns.add(voice);
}
static const LLCachedControl<bool> hide_notes("RadarColumnNotesHidden");
if (!hide_notes)
{
element.columns.add(LLScrollListCell::Params().column("notes").type("checkbox").enabled(false).value(entry->mNotes));
}
static const LLCachedControl<bool> hide_age("RadarColumnAgeHidden");
if (!hide_age)
{