From b98cbe00fe885cebebe1ec5fd123c969b5d2c29f Mon Sep 17 00:00:00 2001
From: Todd Stinson <stinson@lindenlab.com>
Date: Tue, 19 Jun 2012 19:06:25 -0700
Subject: [PATCH] PATH-702: Refining the behavior of the rebuild navmesh button
 after it is pushed, and removing unused code.

---
 indra/newview/llpanelnavmeshrebake.cpp        | 14 ++-
 indra/newview/llpanelnavmeshrebake.h          |  1 +
 indra/newview/llpathfindingmanager.cpp        | 90 +++++++------------
 indra/newview/llpathfindingmanager.h          | 13 +--
 .../default/xui/en/panel_navmesh_rebake.xml   | 56 ++++++------
 5 files changed, 76 insertions(+), 98 deletions(-)

diff --git a/indra/newview/llpanelnavmeshrebake.cpp b/indra/newview/llpanelnavmeshrebake.cpp
index 608bfbf776a..0cc0d6c50a8 100644
--- a/indra/newview/llpanelnavmeshrebake.cpp
+++ b/indra/newview/llpanelnavmeshrebake.cpp
@@ -57,12 +57,14 @@ LLPanelNavMeshRebake* LLPanelNavMeshRebake::getInstance()
 BOOL LLPanelNavMeshRebake::postBuild()
 {
 	//Rebake initiated
-	mNavMeshRebakeButton = getChild<LLButton>("navmesh_btn");
+	mNavMeshRebakeButton = findChild<LLButton>("navmesh_btn");
+	llassert(mNavMeshRebakeButton != NULL);
 	mNavMeshRebakeButton->setCommitCallback(boost::bind(&LLPanelNavMeshRebake::onNavMeshRebakeClick, this));
 	LLHints::registerHintTarget("navmesh_btn", mNavMeshRebakeButton->getHandle());
 	
 	//Baking...
-	mNavMeshBakingButton = getChild<LLButton>("navmesh_btn_baking");
+	mNavMeshBakingButton = findChild<LLButton>("navmesh_btn_baking");
+	llassert(mNavMeshBakingButton != NULL);
 	LLHints::registerHintTarget("navmesh_btn_baking", mNavMeshBakingButton->getHandle());
 
 	setMode(kRebakeNavMesh_Default);
@@ -133,7 +135,13 @@ void LLPanelNavMeshRebake::onNavMeshRebakeClick()
 	mNavMeshBakingButton->setVisible( TRUE ); 
 	mNavMeshBakingButton->setForcePressedState( TRUE );
 #endif
-	LLPathfindingManager::getInstance()->triggerNavMeshRebuild();
+	setMode(kRebakeNavMesh_RequestSent);
+	LLPathfindingManager::getInstance()->requestRebakeNavMesh(boost::bind(&LLPanelNavMeshRebake::handleRebakeNavMeshResponse, this, _1));
+}
+
+void LLPanelNavMeshRebake::handleRebakeNavMeshResponse(bool pResponseStatus)
+{
+	setMode(pResponseStatus ? kRebakeNavMesh_NotAvailable : kRebakeNavMesh_Available);
 }
 
 void LLPanelNavMeshRebake::handleNavMeshStatus(const LLPathfindingNavMeshStatus &pNavMeshStatus)
diff --git a/indra/newview/llpanelnavmeshrebake.h b/indra/newview/llpanelnavmeshrebake.h
index 39af298aa82..2c573f4c04b 100644
--- a/indra/newview/llpanelnavmeshrebake.h
+++ b/indra/newview/llpanelnavmeshrebake.h
@@ -72,6 +72,7 @@ class LLPanelNavMeshRebake : public LLPanel
 	
 	void onNavMeshRebakeClick();
 
+	void handleRebakeNavMeshResponse(bool pResponseStatus);
 	void handleNavMeshStatus(const LLPathfindingNavMeshStatus &pNavMeshStatus);
 	void handleRegionBoundaryCrossed();
 
diff --git a/indra/newview/llpathfindingmanager.cpp b/indra/newview/llpathfindingmanager.cpp
index 912b264c411..7675d500da6 100644
--- a/indra/newview/llpathfindingmanager.cpp
+++ b/indra/newview/llpathfindingmanager.cpp
@@ -54,9 +54,6 @@
 #include "llweb.h"
 #include "llpanelnavmeshrebake.h"
 #include "llenvmanager.h"
-#if 0
-#include "llstartup.h"
-#endif
 
 #define CAP_SERVICE_RETRIEVE_NAVMESH      "RetrieveNavMeshSrc"
 
@@ -167,17 +164,19 @@ class AgentStateResponder : public LLHTTPClient::Responder
 class NavMeshRebakeResponder : public LLHTTPClient::Responder
 {
 public:
-	NavMeshRebakeResponder( const std::string &pCapabilityURL );
+	NavMeshRebakeResponder(const std::string &pCapabilityURL, LLPathfindingManager::rebake_navmesh_callback_t pRebakeNavMeshCallback);
 	virtual ~NavMeshRebakeResponder();
 
-	virtual void result( const LLSD &pContent );
-	virtual void error( U32 pStatus, const std::string& pReason );
+	virtual void result(const LLSD &pContent);
+	virtual void error(U32 pStatus, const std::string& pReason);
 
 protected:
 
 private:
-	std::string                       mCapabilityURL;
+	std::string                                     mCapabilityURL;
+	LLPathfindingManager::rebake_navmesh_callback_t mRebakeNavMeshCallback;
 };
+
 //---------------------------------------------------------------------------
 // LinksetsResponder
 //---------------------------------------------------------------------------
@@ -495,6 +494,19 @@ void LLPathfindingManager::requestGetCharacters(request_id_t pRequestId, object_
 	}
 }
 
+void LLPathfindingManager::requestRebakeNavMesh(rebake_navmesh_callback_t pRebakeNavMeshCallback)
+{
+	std::string navMeshStatusURL = getNavMeshStatusURLForCurrentRegion();
+	llassert(!navMeshStatusURL.empty())
+	if (!navMeshStatusURL.empty())
+	{
+		LLSD mPostData;			
+		mPostData["command"] = "rebuild";
+		LLHTTPClient::ResponderPtr responder = new NavMeshRebakeResponder(navMeshStatusURL, pRebakeNavMeshCallback);
+		LLHTTPClient::post(navMeshStatusURL, mPostData, responder);
+	}
+}
+
 void LLPathfindingManager::sendRequestGetNavMeshForRegion(LLPathfindingNavMeshPtr navMeshPtr, LLViewerRegion *pRegion, const LLPathfindingNavMeshStatus &pNavMeshStatus)
 {
 	if ((pRegion == NULL) || !pRegion->isAlive())
@@ -630,9 +642,6 @@ void LLPathfindingManager::requestGetAgentState()
 
 void LLPathfindingManager::handleAgentStateResult(const LLSD &pContent) 
 {	
-#if 0
-	displayNavMeshRebakePanel();
-#endif
 }
 
 void LLPathfindingManager::handleAgentStateError(U32 pStatus, const std::string &pReason, const std::string &pURL)
@@ -642,9 +651,13 @@ void LLPathfindingManager::handleAgentStateError(U32 pStatus, const std::string
 
 std::string LLPathfindingManager::getAgentStateURLForCurrentRegion(LLViewerRegion *pRegion) const
 {
-	return getCapabilityURLForRegion( pRegion, CAP_SERVICE_AGENT_STATE );
+	return getCapabilityURLForRegion(pRegion, CAP_SERVICE_AGENT_STATE);
 }
 
+std::string LLPathfindingManager::getNavMeshStatusURLForCurrentRegion() const
+{
+	return getNavMeshStatusURLForRegion(getCurrentRegion());
+}
 
 std::string LLPathfindingManager::getNavMeshStatusURLForRegion(LLViewerRegion *pRegion) const
 {
@@ -699,46 +712,6 @@ LLViewerRegion *LLPathfindingManager::getCurrentRegion() const
 	return gAgent.getRegion();
 }
 
-#if 0
-void LLPathfindingManager::displayNavMeshRebakePanel()
-{
-	LLPanelNavMeshRebake::getInstance()->setMode(LLPanelNavMeshRebake::kRebakeNavMesh_Available);
-}
-
-void LLPathfindingManager::hideNavMeshRebakePanel()
-{
-	LLPanelNavMeshRebake::getInstance()->setMode(LLPanelNavMeshRebake::kRebakeNavMesh_NotAvailable);
-}
-#endif
-
-void LLPathfindingManager::handleNavMeshRebakeError(U32 pStatus, const std::string &pReason, const std::string &pURL)
-{
-	llwarns << "error with request to URL '" << pURL << "' because " << pReason << " (statusCode:" << pStatus << ")" << llendl;
-}
-
-void LLPathfindingManager::handleNavMeshRebakeResult( const LLSD &pContent )
-{
-
-#if 0
-	hideNavMeshRebakePanel();
-#endif
-}
-
-void LLPathfindingManager::triggerNavMeshRebuild()
-{
-	std::string url = getNavMeshStatusURLForRegion( getCurrentRegion() );
-	if ( url.empty() )
-	{
-		llwarns << "Error with request due to nonexistent URL"<<llendl;
-	}
-	else
-	{
-		LLSD mPostData;			
-		mPostData["command"] = "rebuild";
-		LLHTTPClient::ResponderPtr responder = new NavMeshRebakeResponder( url );
-		LLHTTPClient::post( url, mPostData, responder );
-	}
-}
 //---------------------------------------------------------------------------
 // LLNavMeshSimStateChangeNode
 //---------------------------------------------------------------------------
@@ -766,9 +739,6 @@ void LLAgentStateChangeNode::post(ResponsePtr pResponse, const LLSD &pContext, c
 void LLPathfindingManager::handleAgentStateUpdate()
 {
 	//Don't trigger if we are still loading in
-#if 0
-	if ( LLStartUp::getStartupState() == STATE_STARTED) { displayNavMeshRebakePanel(); }
-#endif
 }
 
 //---------------------------------------------------------------------------
@@ -862,9 +832,10 @@ void AgentStateResponder::error(U32 pStatus, const std::string &pReason)
 //---------------------------------------------------------------------------
 // navmesh rebake responder
 //---------------------------------------------------------------------------
-NavMeshRebakeResponder::NavMeshRebakeResponder(const std::string &pCapabilityURL )
-: LLHTTPClient::Responder()
-, mCapabilityURL( pCapabilityURL )
+NavMeshRebakeResponder::NavMeshRebakeResponder(const std::string &pCapabilityURL, LLPathfindingManager::rebake_navmesh_callback_t pRebakeNavMeshCallback)
+	: LLHTTPClient::Responder(),
+	mCapabilityURL(pCapabilityURL),
+	mRebakeNavMeshCallback(pRebakeNavMeshCallback)
 {
 }
 
@@ -874,12 +845,13 @@ NavMeshRebakeResponder::~NavMeshRebakeResponder()
 
 void NavMeshRebakeResponder::result(const LLSD &pContent)
 {
-	LLPathfindingManager::getInstance()->handleNavMeshRebakeResult( pContent );
+	mRebakeNavMeshCallback(true);
 }
 
 void NavMeshRebakeResponder::error(U32 pStatus, const std::string &pReason)
 {
-	LLPathfindingManager::getInstance()->handleNavMeshRebakeError( pStatus, pReason, mCapabilityURL );
+	llwarns << "error with request to URL '" << mCapabilityURL << "' because " << pReason << " (statusCode:" << pStatus << ")" << llendl;
+	mRebakeNavMeshCallback(false);
 }
 
 //---------------------------------------------------------------------------
diff --git a/indra/newview/llpathfindingmanager.h b/indra/newview/llpathfindingmanager.h
index 2457c183097..f77877af086 100644
--- a/indra/newview/llpathfindingmanager.h
+++ b/indra/newview/llpathfindingmanager.h
@@ -91,12 +91,11 @@ class LLPathfindingManager : public LLSingleton<LLPathfindingManager>
 	typedef boost::signals2::connection				agent_state_slot_t;	
 
 	agent_state_slot_t registerAgentStateListener(agent_state_callback_t pAgentStateCallback);
-
-	void handleNavMeshRebakeResult( const LLSD &pContent );
-	void handleNavMeshRebakeError( U32 pStatus, const std::string &pReason, const std::string &pURL );
-	void triggerNavMeshRebuild();
 	void requestGetAgentState();	
 
+	typedef boost::function<void (bool)> rebake_navmesh_callback_t;
+	void requestRebakeNavMesh(rebake_navmesh_callback_t pRebakeNavMeshCallback);
+
 protected:
 
 private:
@@ -114,6 +113,7 @@ class LLPathfindingManager : public LLSingleton<LLPathfindingManager>
 	LLPathfindingNavMeshPtr getNavMeshForRegion(const LLUUID &pRegionUUID);
 	LLPathfindingNavMeshPtr getNavMeshForRegion(LLViewerRegion *pRegion);
 
+	std::string getNavMeshStatusURLForCurrentRegion() const;
 	std::string getNavMeshStatusURLForRegion(LLViewerRegion *pRegion) const;
 	std::string getRetrieveNavMeshURLForRegion(LLViewerRegion *pRegion) const;
 	std::string getObjectLinksetsURLForCurrentRegion() const;
@@ -124,10 +124,6 @@ class LLPathfindingManager : public LLSingleton<LLPathfindingManager>
 	std::string getCapabilityURLForRegion(LLViewerRegion *pRegion, const std::string &pCapabilityName) const;
 	LLViewerRegion *getCurrentRegion() const;
 
-#if 0
-	void displayNavMeshRebakePanel();
-	void hideNavMeshRebakePanel();	
-#endif
 	void handleAgentStateResult(const LLSD &pContent );
 	void handleAgentStateError(U32 pStatus, const std::string &pReason, const std::string &pURL);
 
@@ -135,5 +131,4 @@ class LLPathfindingManager : public LLSingleton<LLPathfindingManager>
 	agent_state_signal_t mAgentStateSignal;
 };
 
-
 #endif // LL_LLPATHFINDINGMANAGER_H
diff --git a/indra/newview/skins/default/xui/en/panel_navmesh_rebake.xml b/indra/newview/skins/default/xui/en/panel_navmesh_rebake.xml
index 35d07eea993..c7bf91efb47 100644
--- a/indra/newview/skins/default/xui/en/panel_navmesh_rebake.xml
+++ b/indra/newview/skins/default/xui/en/panel_navmesh_rebake.xml
@@ -1,32 +1,34 @@
 <?xml version="1.0" encoding="utf-8" standalone="yes" ?>
 <panel
- height="25"
- layout="topleft"
- name="panel_navmesh_rebake"
- mouse_opaque="false"
- visible="true"
- width="133">
-    <button
-     follows="left|bottom"
-     height="19"
-     label="Rebake navmesh"
-     layout="topleft"
-     left="10"
-     name="navmesh_btn"
-     tool_tip="Click here to rebake."
-     top="2"
-     visible="false"
-     width="113" />
+    height="25"
+    layout="topleft"
+    name="panel_navmesh_rebake"
+    mouse_opaque="false"
+    visible="true"
+    width="133">
   <button
-   follows="left|bottom"
-   height="19"
-   label="Navmesh baking..."
-   layout="topleft"
-   left="10"
-   name="navmesh_btn_baking"
-   tool_tip="Navmesh is baking."
-   top="2"
-   visible="false"
-   width="113" />
+      follows="left|bottom"
+      height="19"
+      label="Clean up region"
+      layout="topleft"
+      left="10"
+      name="navmesh_btn"
+      tool_tip="Click here to rebake the region&apos;s navmesh."
+      top="2"
+      visible="false"
+      enabled="true"
+      width="113" />
+  <button
+      follows="left|bottom"
+      height="19"
+      label="Region is cleaning"
+      layout="topleft"
+      left="10"
+      name="navmesh_btn_baking"
+      tool_tip="Region is cleaning up."
+      top="2"
+      visible="false"
+      enabled="false"
+      width="113" />
 </panel>
 
-- 
GitLab