From 2bb9751d0aee01b8911f57150fb1e5ea258d7bb4 Mon Sep 17 00:00:00 2001
From: Denis Serdjuk <dserduk@productengine.com>
Date: Wed, 28 Oct 2009 13:56:02 +0200
Subject: [PATCH] EXT-1232  Implement \"You are Here\" banner for Place Profile
 - Parcel Characteristics Note: \"YouAreHereDistance\" setting has been added
 to setting.xml

--HG--
branch : product-engine
---
 indra/newview/app_settings/settings.xml | 11 ++++++++++
 indra/newview/llagentui.cpp             |  5 +++++
 indra/newview/llagentui.h               |  5 +++++
 indra/newview/llpanelplaceinfo.cpp      | 27 ++++++++++++++++---------
 indra/newview/llpanelplaceinfo.h        |  2 +-
 5 files changed, 40 insertions(+), 10 deletions(-)

diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml
index b113a35ea1f..858da77418b 100644
--- a/indra/newview/app_settings/settings.xml
+++ b/indra/newview/app_settings/settings.xml
@@ -10482,6 +10482,17 @@
       <key>Value</key>
       <real>90.0</real>
     </map>
+    <key>YouAreHereDistance</key>
+    <map>
+      <key>Comment</key>
+      <string>Radius of distance for banner that indicates if the resident is "on" the Place.(meters from avatar to requested place)</string>
+      <key>Persist</key>
+      <integer>1</integer>
+      <key>Type</key>
+      <string>F32</string>
+      <key>Value</key>
+      <real>10.0</real>
+    </map>
     <key>YieldTime</key>
     <map>
       <key>Comment</key>
diff --git a/indra/newview/llagentui.cpp b/indra/newview/llagentui.cpp
index 1a69f1d975e..09f7c49f23d 100644
--- a/indra/newview/llagentui.cpp
+++ b/indra/newview/llagentui.cpp
@@ -89,6 +89,11 @@ std::string LLAgentUI::buildSLURL(const bool escaped /*= true*/)
 	return slurl;
 }
 
+//static
+BOOL LLAgentUI::checkAgentDistance(const LLVector3& pole, F32 radius)
+{
+	return  (gAgent.getPositionAgent() - pole).length() < radius;
+}
 BOOL LLAgentUI::buildLocationString(std::string& str, ELocationFormat fmt,const LLVector3& agent_pos_region)
 {
 	LLViewerRegion* region = gAgent.getRegion();
diff --git a/indra/newview/llagentui.h b/indra/newview/llagentui.h
index 47ecb04547a..c7aafb71e7b 100644
--- a/indra/newview/llagentui.h
+++ b/indra/newview/llagentui.h
@@ -52,6 +52,11 @@ class LLAgentUI
 	static BOOL buildLocationString(std::string& str, ELocationFormat fmt = LOCATION_FORMAT_LANDMARK);
 	//build location string using a region position of the avatar. 
 	static BOOL buildLocationString(std::string& str, ELocationFormat fmt,const LLVector3& agent_pos_region);
+	/**
+	 * @brief Check whether  the agent is in neighborhood of the pole  Within same region
+	 * @return true if the agent is in neighborhood.
+	 */
+	static BOOL checkAgentDistance(const LLVector3& local_pole, F32 radius);
 };
 
 #endif //LLAGENTUI_H
diff --git a/indra/newview/llpanelplaceinfo.cpp b/indra/newview/llpanelplaceinfo.cpp
index 2edb2bba06d..15c420d4962 100644
--- a/indra/newview/llpanelplaceinfo.cpp
+++ b/indra/newview/llpanelplaceinfo.cpp
@@ -55,6 +55,7 @@
 #include "llagent.h"
 #include "llagentui.h"
 #include "llavatarpropertiesprocessor.h"
+#include "llcallbacklist.h"
 #include "llfloaterworldmap.h"
 #include "llfloaterbuycurrency.h"
 #include "llinventorymodel.h"
@@ -65,6 +66,7 @@
 #include "llviewerinventory.h"
 #include "llviewerparcelmgr.h"
 #include "llviewerregion.h"
+#include "llviewercontrol.h" 
 #include "llviewertexteditor.h"
 #include "llworldmap.h"
 #include "llsdutil_math.h"
@@ -110,7 +112,7 @@ BOOL LLPanelPlaceInfo::postBuild()
 
 	mForSalePanel = getChild<LLPanel>("for_sale_panel");
 	mYouAreHerePanel = getChild<LLPanel>("here_panel");
-	LLViewerParcelMgr::getInstance()->addAgentParcelChangedCallback(boost::bind(&LLPanelPlaceInfo::updateYouAreHereBanner,this));
+	gIdleCallbacks.addFunction(&LLPanelPlaceInfo::updateYouAreHereBanner, this);
 	
 	//Icon value should contain sale price of last selected parcel. 
 	mForSalePanel->getChild<LLIconCtrl>("icon_for_sale")->
@@ -609,6 +611,9 @@ void LLPanelPlaceInfo::displaySelectedParcelInfo(LLParcel* parcel,
 	parcel_data.name = parcel->getName();
 	parcel_data.sim_name = region->getName();
 	parcel_data.snapshot_id = parcel->getSnapshotID();
+	mPosRegion.setVec((F32)fmod(pos_global.mdV[VX], (F64)REGION_WIDTH_METERS),
+					  (F32)fmod(pos_global.mdV[VY], (F64)REGION_WIDTH_METERS),
+					  (F32)pos_global.mdV[VZ]);
 	parcel_data.global_x = pos_global.mdV[VX];
 	parcel_data.global_y = pos_global.mdV[VY];
 	parcel_data.global_z = pos_global.mdV[VZ];
@@ -985,18 +990,22 @@ void LLPanelPlaceInfo::populateFoldersList()
 		mFolderCombo->add(it->second, LLSD(it->first));
 }
 
-void LLPanelPlaceInfo::updateYouAreHereBanner()
+//static
+void LLPanelPlaceInfo::updateYouAreHereBanner(void* userdata)
 {
 	//YouAreHere Banner should be displayed only for selected places, 
 	// If you want to display it for landmark or teleport history item, you should check by mParcelId
 	
-	bool is_you_are_here = false;
-	if (mSelectedParcelID != S32(-1) && !mLastSelectedRegionID.isNull())
-	{
-		is_you_are_here = gAgent.getRegion()->getRegionID()== mLastSelectedRegionID &&
-		mSelectedParcelID == LLViewerParcelMgr::getInstance()->getAgentParcel()->getLocalID();
-	}
-	mYouAreHerePanel->setVisible(is_you_are_here);
+	LLPanelPlaceInfo* self  = static_cast<LLPanelPlaceInfo*>(userdata);
+	if(!self->getVisible())
+		return;
+
+	static F32 radius  = gSavedSettings.getF32("YouAreHereDistance");
+
+	BOOL display_banner = self->mLastSelectedRegionID == gAgent.getRegion()->getRegionID() && 
+			LLAgentUI::checkAgentDistance(self->mPosRegion, radius);
+
+	self->mYouAreHerePanel->setVisible(display_banner);
 }
 
 void LLPanelPlaceInfo::onForSaleBannerClick()
diff --git a/indra/newview/llpanelplaceinfo.h b/indra/newview/llpanelplaceinfo.h
index aa2485cbb49..4274baa66ec 100644
--- a/indra/newview/llpanelplaceinfo.h
+++ b/indra/newview/llpanelplaceinfo.h
@@ -138,7 +138,7 @@ class LLPanelPlaceInfo : public LLPanel, LLRemoteParcelInfoObserver
 private:
 
 	void populateFoldersList();
-	void updateYouAreHereBanner();
+	static void updateYouAreHereBanner(void*);// added to gIdleCallbacks
 	void onForSaleBannerClick();
 
 	/**
-- 
GitLab