From 552f288a0caea45e30a231478a19f4243d69689c Mon Sep 17 00:00:00 2001 From: Merov Linden Date: Fri, 21 Sep 2012 20:13:50 -0700 Subject: CHUI-340 : Implement distance computation and update --- indra/newview/llimfloatercontainer.cpp | 40 ++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'indra/newview/llimfloatercontainer.cpp') diff --git a/indra/newview/llimfloatercontainer.cpp b/indra/newview/llimfloatercontainer.cpp index 3c21794d28..cd56ea6081 100755 --- a/indra/newview/llimfloatercontainer.cpp +++ b/indra/newview/llimfloatercontainer.cpp @@ -47,6 +47,7 @@ #include "llviewercontrol.h" #include "llconversationview.h" #include "llcallbacklist.h" +#include "llworld.h" // // LLIMFloaterContainer @@ -333,6 +334,14 @@ void LLIMFloaterContainer::setMinimized(BOOL b) void LLIMFloaterContainer::idle(void* user_data) { LLIMFloaterContainer* self = static_cast(user_data); + + // Update the distance to agent in the nearby chat session if required + // Note: it makes no sense of course to update the distance in other session + if (self->mConversationViewModel.getSorter().getSortOrderParticipants() == LLConversationFilter::SO_DISTANCE) + { + self->setNearbyDistances(); + } + self->mConversationsRoot->update(); } @@ -725,6 +734,37 @@ void LLIMFloaterContainer::setTimeNow(const LLUUID& session_id, const LLUUID& pa } } +void LLIMFloaterContainer::setNearbyDistances() +{ + // Get the nearby chat session: that's the one with uuid nul in mConversationsItems + conversations_items_map::iterator item_it = mConversationsItems.find(LLUUID()); + if (item_it != mConversationsItems.end()) + { + LLConversationItemSession* item = dynamic_cast(item_it->second); + if (item) + { + // Get the positions of the nearby avatars and their ids + std::vector positions; + uuid_vec_t avatar_ids; + LLWorld::getInstance()->getAvatars(&avatar_ids, &positions, gAgent.getPositionGlobal(), gSavedSettings.getF32("NearMeRange")); + // Get the position of the agent + const LLVector3d& me_pos = gAgent.getPositionGlobal(); + // For each nearby avatar, compute and update the distance + int avatar_count = positions.size(); + for (int i = 0; i < avatar_count; i++) + { + F64 dist = dist_vec_squared(positions[i], me_pos); + item->setDistance(avatar_ids[i],dist); + } + // Also does it for the agent itself + item->setDistance(gAgent.getID(),0.0f); + // Request resort + mConversationViewModel.requestSortAll(); + mConversationsRoot->arrangeAll(); + } + } +} + void LLIMFloaterContainer::addConversationListItem(const LLUUID& uuid) { bool is_nearby_chat = uuid.isNull(); -- cgit v1.2.3