From 2115211328261d875dc0ccacdc2021f1c501a36d Mon Sep 17 00:00:00 2001 From: Todd Stinson Date: Mon, 9 Apr 2012 18:53:52 -0700 Subject: Re-implementing the path testing functionality as a proper LLTool. --- indra/llcommon/llcursortypes.cpp | 1 + indra/llcommon/llcursortypes.h | 1 + indra/llwindow/llwindowwin32.cpp | 1 + indra/newview/CMakeLists.txt | 3 + indra/newview/llfloaterpathfindingconsole.cpp | 361 ++++++++++----------- indra/newview/llfloaterpathfindingconsole.h | 50 ++- indra/newview/llpathfindingpathtool.cpp | 206 ++++++++++++ indra/newview/llpathfindingpathtool.h | 102 ++++++ indra/newview/lltoolmgr.cpp | 2 + indra/newview/lltoolmgr.h | 6 +- indra/newview/llviewerwindow.cpp | 21 +- indra/newview/pipeline.cpp | 3 +- indra/newview/res/lltoolpathfinding.cur | Bin 0 -> 326 bytes indra/newview/res/viewerRes.rc | 1 + .../default/xui/en/floater_pathfinding_console.xml | 4 + 15 files changed, 524 insertions(+), 238 deletions(-) create mode 100644 indra/newview/llpathfindingpathtool.cpp create mode 100644 indra/newview/llpathfindingpathtool.h create mode 100644 indra/newview/res/lltoolpathfinding.cur (limited to 'indra') diff --git a/indra/llcommon/llcursortypes.cpp b/indra/llcommon/llcursortypes.cpp index e987c397bd..dc308c30af 100644 --- a/indra/llcommon/llcursortypes.cpp +++ b/indra/llcommon/llcursortypes.cpp @@ -69,6 +69,7 @@ ECursorType getCursorFromString(const std::string& cursor_string) cursor_string_table["UI_CURSOR_TOOLSIT"] = UI_CURSOR_TOOLSIT; cursor_string_table["UI_CURSOR_TOOLBUY"] = UI_CURSOR_TOOLBUY; cursor_string_table["UI_CURSOR_TOOLOPEN"] = UI_CURSOR_TOOLOPEN; + cursor_string_table["UI_CURSOR_TOOLPATHFINDING"] = UI_CURSOR_TOOLPATHFINDING; } std::map::const_iterator iter = cursor_string_table.find(cursor_string); diff --git a/indra/llcommon/llcursortypes.h b/indra/llcommon/llcursortypes.h index bacb0a80ba..ea072ff4b4 100644 --- a/indra/llcommon/llcursortypes.h +++ b/indra/llcommon/llcursortypes.h @@ -65,6 +65,7 @@ enum ECursorType { UI_CURSOR_TOOLSIT, UI_CURSOR_TOOLBUY, UI_CURSOR_TOOLOPEN, + UI_CURSOR_TOOLPATHFINDING, UI_CURSOR_COUNT // Number of elements in this enum (NOT a cursor) }; diff --git a/indra/llwindow/llwindowwin32.cpp b/indra/llwindow/llwindowwin32.cpp index bc85acbf45..f6e4f9f6e1 100644 --- a/indra/llwindow/llwindowwin32.cpp +++ b/indra/llwindow/llwindowwin32.cpp @@ -1697,6 +1697,7 @@ void LLWindowWin32::initCursors() mCursor[ UI_CURSOR_TOOLSIT ] = LoadCursor(module, TEXT("TOOLSIT")); mCursor[ UI_CURSOR_TOOLBUY ] = LoadCursor(module, TEXT("TOOLBUY")); mCursor[ UI_CURSOR_TOOLOPEN ] = LoadCursor(module, TEXT("TOOLOPEN")); + mCursor[ UI_CURSOR_TOOLPATHFINDING ] = LoadCursor(module, TEXT("TOOLPATHFINDING")); // Color cursors mCursor[ UI_CURSOR_TOOLPLAY ] = loadColorCursor(TEXT("TOOLPLAY")); diff --git a/indra/newview/CMakeLists.txt b/indra/newview/CMakeLists.txt index f59bc457e2..d632220771 100644 --- a/indra/newview/CMakeLists.txt +++ b/indra/newview/CMakeLists.txt @@ -424,6 +424,7 @@ set(viewer_SOURCE_FILES llpathfindingnavmesh.cpp llpathfindingnavmeshstatus.cpp llpathfindingnavmeshzone.cpp + llpathfindingpathtool.cpp llphysicsmotion.cpp llphysicsshapebuilderutil.cpp llplacesinventorybridge.cpp @@ -980,6 +981,7 @@ set(viewer_HEADER_FILES llpathfindingnavmesh.h llpathfindingnavmeshstatus.h llpathfindingnavmeshzone.h + llpathfindingpathtool.h llphysicsmotion.h llphysicsshapebuilderutil.h llplacesinventorybridge.h @@ -1328,6 +1330,7 @@ if (WINDOWS) res/lltoolgrab.cur res/lltoolland.cur res/lltoolpan.cur + res/lltoolpathfinding.cur res/lltoolpipette.cur res/lltoolrotate.cur res/lltoolscale.cur diff --git a/indra/newview/llfloaterpathfindingconsole.cpp b/indra/newview/llfloaterpathfindingconsole.cpp index c59f960d3f..7941fd52af 100644 --- a/indra/newview/llfloaterpathfindingconsole.cpp +++ b/indra/newview/llfloaterpathfindingconsole.cpp @@ -32,7 +32,6 @@ #include "llsd.h" #include "llhandle.h" -#include "llagent.h" #include "llpanel.h" #include "llbutton.h" #include "llcheckboxctrl.h" @@ -42,13 +41,12 @@ #include "lltabcontainer.h" #include "llcombobox.h" #include "llfloaterreg.h" -#include "llviewerregion.h" -#include "llviewerwindow.h" -#include "llviewercamera.h" -#include "llviewercontrol.h" #include "llpathfindingnavmeshzone.h" #include "llpathfindingmanager.h" #include "llenvmanager.h" +#include "llpathfindingpathtool.h" +#include "lltoolmgr.h" +#include "lltoolfocus.h" #include "LLPathingLib.h" @@ -64,6 +62,7 @@ #define XUI_CHARACTER_TYPE_C 3 #define XUI_CHARACTER_TYPE_D 4 +#define XUI_EDIT_TAB_INDEX 0 #define XUI_TEST_TAB_INDEX 1 LLHandle LLFloaterPathfindingConsole::sInstanceHandle; @@ -105,6 +104,7 @@ BOOL LLFloaterPathfindingConsole::postBuild() mEditTestTabContainer = findChild("edit_test_tab_container"); llassert(mEditTestTabContainer != NULL); + mEditTestTabContainer->setCommitCallback(boost::bind(&LLFloaterPathfindingConsole::onTabSwitch, this)); mEditTab = findChild("edit_panel"); llassert(mEditTab != NULL); @@ -154,6 +154,11 @@ BOOL LLFloaterPathfindingConsole::postBuild() llassert(mClearPathButton != NULL); mClearPathButton->setCommitCallback(boost::bind(&LLFloaterPathfindingConsole::onClearPathClicked, this)); + mPathfindingToolset = new LLToolset(); + mPathfindingToolset->addTool(LLPathfindingPathTool::getInstance()); + mPathfindingToolset->addTool(LLToolCamera::getInstance()); + mPathfindingToolset->setShowFloaterTools(false); + return LLFloater::postBuild(); } @@ -192,13 +197,30 @@ void LLFloaterPathfindingConsole::onOpen(const LLSD& pKey) mRegionBoundarySlot = LLEnvManagerNew::instance().setRegionChangeCallback(boost::bind(&LLFloaterPathfindingConsole::onRegionBoundaryCross, this)); } + if (!mPathEventSlot.connected()) + { + mPathEventSlot = LLPathfindingPathTool::getInstance()->registerPathEventListener(boost::bind(&LLFloaterPathfindingConsole::onPathEvent, this)); + } + setAgentState(LLPathfindingManager::getInstance()->getAgentState()); setDefaultInputs(); updatePathTestStatus(); + + if (mEditTestTabContainer->getCurrentPanelIndex() == XUI_TEST_TAB_INDEX) + { + switchIntoTestPathMode(); + } } void LLFloaterPathfindingConsole::onClose(bool pIsAppQuitting) { + switchOutOfTestPathMode(); + + if (mPathEventSlot.connected()) + { + mPathEventSlot.disconnect(); + } + if (mRegionBoundarySlot.connected()) { mRegionBoundarySlot.disconnect(); @@ -225,46 +247,6 @@ void LLFloaterPathfindingConsole::onClose(bool pIsAppQuitting) LLFloater::onClose(pIsAppQuitting); } -BOOL LLFloaterPathfindingConsole::handleAnyMouseClick(S32 x, S32 y, MASK mask, EClickType clicktype, BOOL down) -{ - if (isGeneratePathMode(mask, clicktype, down)) - { - LLVector3 dv = gViewerWindow->mouseDirectionGlobal(x, y); - LLVector3 mousePos = LLViewerCamera::getInstance()->getOrigin(); - LLVector3 rayStart = mousePos; - LLVector3 rayEnd = mousePos + dv * 150; - - if (mask & MASK_CONTROL) - { - mPathData.mStartPointA = rayStart; - mPathData.mEndPointA = rayEnd; - mHasStartPoint = true; - } - else if (mask & MASK_SHIFT) - { - mPathData.mStartPointB = rayStart; - mPathData.mEndPointB = rayEnd; - mHasEndPoint = true; - } - generatePath(); - updatePathTestStatus(); - - return TRUE; - } - else - { - return LLFloater::handleAnyMouseClick(x, y, mask, clicktype, down); - } -} - -BOOL LLFloaterPathfindingConsole::isGeneratePathMode(MASK mask, EClickType clicktype, BOOL down) const -{ - return (isShown() && (mEditTestTabContainer->getCurrentPanelIndex() == XUI_TEST_TAB_INDEX) && - (clicktype == LLMouseHandler::CLICK_LEFT) && down && - (((mask & MASK_CONTROL) && !(mask & (~MASK_CONTROL))) || - ((mask & MASK_SHIFT) && !(mask & (~MASK_SHIFT))))); -} - LLHandle LLFloaterPathfindingConsole::getInstanceHandle() { if (sInstanceHandle.isDead()) @@ -279,11 +261,6 @@ LLHandle LLFloaterPathfindingConsole::getInstanceHa return sInstanceHandle; } -BOOL LLFloaterPathfindingConsole::isRenderPath() const -{ - return (mHasStartPoint && mHasEndPoint); -} - BOOL LLFloaterPathfindingConsole::isRenderNavMesh() const { return mShowNavMeshCheckBox->get(); @@ -444,76 +421,6 @@ void LLFloaterPathfindingConsole::setRenderHeatmapType(ERenderHeatmapType pRende return mShowNavMeshWalkabilityComboBox->setValue(comboBoxValue); } -F32 LLFloaterPathfindingConsole::getCharacterWidth() const -{ - return mCharacterWidthSlider->getValueF32(); -} - -void LLFloaterPathfindingConsole::setCharacterWidth(F32 pCharacterWidth) -{ - mCharacterWidthSlider->setValue(LLSD(pCharacterWidth)); -} - -LLFloaterPathfindingConsole::ECharacterType LLFloaterPathfindingConsole::getCharacterType() const -{ - ECharacterType characterType; - - switch (mCharacterTypeComboBox->getValue().asInteger()) - { - case XUI_CHARACTER_TYPE_NONE : - characterType = kCharacterTypeNone; - break; - case XUI_CHARACTER_TYPE_A : - characterType = kCharacterTypeA; - break; - case XUI_CHARACTER_TYPE_B : - characterType = kCharacterTypeB; - break; - case XUI_CHARACTER_TYPE_C : - characterType = kCharacterTypeC; - break; - case XUI_CHARACTER_TYPE_D : - characterType = kCharacterTypeD; - break; - default : - characterType = kCharacterTypeNone; - llassert(0); - break; - } - - return characterType; -} - -void LLFloaterPathfindingConsole::setCharacterType(ECharacterType pCharacterType) -{ - LLSD radioGroupValue; - - switch (pCharacterType) - { - case kCharacterTypeNone : - radioGroupValue = XUI_CHARACTER_TYPE_NONE; - break; - case kCharacterTypeA : - radioGroupValue = XUI_CHARACTER_TYPE_A; - break; - case kCharacterTypeB : - radioGroupValue = XUI_CHARACTER_TYPE_B; - break; - case kCharacterTypeC : - radioGroupValue = XUI_CHARACTER_TYPE_C; - break; - case kCharacterTypeD : - radioGroupValue = XUI_CHARACTER_TYPE_D; - break; - default : - radioGroupValue = XUI_CHARACTER_TYPE_NONE; - llassert(0); - break; - } - - mCharacterTypeComboBox->setValue(radioGroupValue); -} - LLFloaterPathfindingConsole::LLFloaterPathfindingConsole(const LLSD& pSeed) : LLFloater(pSeed), mSelfHandle(), @@ -546,11 +453,11 @@ LLFloaterPathfindingConsole::LLFloaterPathfindingConsole(const LLSD& pSeed) mIsNavMeshUpdating(false), mAgentStateSlot(), mRegionBoundarySlot(), + mPathEventSlot(), + mPathfindingToolset(NULL), + mSavedToolset(NULL), mConsoleState(kConsoleStateUnknown), - mPathData(), - mHasStartPoint(false), - mHasEndPoint(false), - mHasValidPath(false) + mShapeRenderFlags(0U) { mSelfHandle.bind(this); } @@ -594,21 +501,21 @@ void LLFloaterPathfindingConsole::onShowWalkabilitySet() } } -void LLFloaterPathfindingConsole::onCharacterWidthSet() -{ - generatePath(); - updatePathTestStatus(); -} - -void LLFloaterPathfindingConsole::onCharacterTypeSwitch() +void LLFloaterPathfindingConsole::onViewCharactersClicked() { - generatePath(); - updatePathTestStatus(); + LLFloaterPathfindingCharacters::openCharactersViewer(); } -void LLFloaterPathfindingConsole::onViewCharactersClicked() +void LLFloaterPathfindingConsole::onTabSwitch() { - LLFloaterPathfindingCharacters::openCharactersViewer(); + if (mEditTestTabContainer->getCurrentPanelIndex() == XUI_TEST_TAB_INDEX) + { + switchIntoTestPathMode(); + } + else + { + switchOutOfTestPathMode(); + } } void LLFloaterPathfindingConsole::onUnfreezeClicked() @@ -628,12 +535,19 @@ void LLFloaterPathfindingConsole::onViewEditLinksetClicked() LLFloaterPathfindingLinksets::openLinksetsEditor(); } +void LLFloaterPathfindingConsole::onCharacterWidthSet() +{ + updateCharacterWidth(); +} + +void LLFloaterPathfindingConsole::onCharacterTypeSwitch() +{ + updateCharacterType(); +} + void LLFloaterPathfindingConsole::onClearPathClicked() { - mHasStartPoint = false; - mHasEndPoint = false; - mHasValidPath = false; - updatePathTestStatus(); + clearPath(); } void LLFloaterPathfindingConsole::onNavMeshZoneCB(LLPathfindingNavMeshZone::ENavMeshZoneRequestStatus pNavMeshZoneRequestStatus) @@ -681,9 +595,43 @@ void LLFloaterPathfindingConsole::onRegionBoundaryCross() mShowWorldCheckBox->set(TRUE); } +void LLFloaterPathfindingConsole::onPathEvent() +{ + const LLPathfindingPathTool *pathToolInstance = LLPathfindingPathTool::getInstance(); + + mCharacterWidthSlider->setValue(LLSD(pathToolInstance->getCharacterWidth())); + + LLSD characterType; + switch (pathToolInstance->getCharacterType()) + { + case LLPathfindingPathTool::kCharacterTypeNone : + characterType = XUI_CHARACTER_TYPE_NONE; + break; + case LLPathfindingPathTool::kCharacterTypeA : + characterType = XUI_CHARACTER_TYPE_A; + break; + case LLPathfindingPathTool::kCharacterTypeB : + characterType = XUI_CHARACTER_TYPE_B; + break; + case LLPathfindingPathTool::kCharacterTypeC : + characterType = XUI_CHARACTER_TYPE_C; + break; + case LLPathfindingPathTool::kCharacterTypeD : + characterType = XUI_CHARACTER_TYPE_D; + break; + default : + characterType = XUI_CHARACTER_TYPE_NONE; + llassert(0); + break; + } + mCharacterTypeComboBox->setValue(characterType); + + updatePathTestStatus(); +} + void LLFloaterPathfindingConsole::setDefaultInputs() { - mEditTestTabContainer->selectTab(0); + mEditTestTabContainer->selectTab(XUI_EDIT_TAB_INDEX); mShowNavMeshCheckBox->set(FALSE); mShowWalkablesCheckBox->set(FALSE); mShowMaterialVolumesCheckBox->set(FALSE); @@ -721,9 +669,7 @@ void LLFloaterPathfindingConsole::updateControlsOnConsoleState() mCharacterWidthSlider->setEnabled(FALSE); mCharacterTypeComboBox->setEnabled(FALSE); mClearPathButton->setEnabled(FALSE); - mHasStartPoint = false; - mHasEndPoint = false; - mHasValidPath = false; + clearPath(); break; case kConsoleStateCheckingVersion : case kConsoleStateDownloading : @@ -742,9 +688,7 @@ void LLFloaterPathfindingConsole::updateControlsOnConsoleState() mCharacterWidthSlider->setEnabled(FALSE); mCharacterTypeComboBox->setEnabled(FALSE); mClearPathButton->setEnabled(FALSE); - mHasStartPoint = false; - mHasEndPoint = false; - mHasValidPath = false; + clearPath(); break; case kConsoleStateHasNavMesh : mShowNavMeshCheckBox->setEnabled(TRUE); @@ -943,36 +887,63 @@ void LLFloaterPathfindingConsole::setAgentState(LLPathfindingManager::EAgentStat break; } } - -void LLFloaterPathfindingConsole::generatePath() + +void LLFloaterPathfindingConsole::switchIntoTestPathMode() +{ + llassert(mPathfindingToolset != NULL); + llassert(mSavedToolset == NULL); + mSavedToolset = LLToolMgr::getInstance()->getCurrentToolset(); + LLToolMgr::getInstance()->setCurrentToolset(mPathfindingToolset); +} + +void LLFloaterPathfindingConsole::switchOutOfTestPathMode() { - if (mHasStartPoint && mHasEndPoint) + llassert(mPathfindingToolset != NULL); + if (mSavedToolset != NULL) { - mPathData.mCharacterWidth = getCharacterWidth(); - switch (getCharacterType()) - { - case kCharacterTypeNone : - mPathData.mCharacterType = LLPathingLib::LLPL_CHARACTER_TYPE_NONE; - break; - case kCharacterTypeA : - mPathData.mCharacterType = LLPathingLib::LLPL_CHARACTER_TYPE_A; - break; - case kCharacterTypeB : - mPathData.mCharacterType = LLPathingLib::LLPL_CHARACTER_TYPE_B; - break; - case kCharacterTypeC : - mPathData.mCharacterType = LLPathingLib::LLPL_CHARACTER_TYPE_C; - break; - case kCharacterTypeD : - mPathData.mCharacterType = LLPathingLib::LLPL_CHARACTER_TYPE_D; - break; - default : - mPathData.mCharacterType = LLPathingLib::LLPL_CHARACTER_TYPE_NONE; - break; - } - LLPathingLib::LLPLResult pathingResult = LLPathingLib::getInstance()->generatePath(mPathData); - mHasValidPath = (pathingResult == LLPathingLib::LLPL_PATH_GENERATED_OK); + LLToolMgr::getInstance()->setCurrentToolset(mSavedToolset); + mSavedToolset = NULL; + } +} + +void LLFloaterPathfindingConsole::updateCharacterWidth() +{ + LLPathfindingPathTool::getInstance()->setCharacterWidth(mCharacterWidthSlider->getValueF32()); +} + +void LLFloaterPathfindingConsole::updateCharacterType() +{ + LLPathfindingPathTool::ECharacterType characterType; + + switch (mCharacterTypeComboBox->getValue().asInteger()) + { + case XUI_CHARACTER_TYPE_NONE : + characterType = LLPathfindingPathTool::kCharacterTypeNone; + break; + case XUI_CHARACTER_TYPE_A : + characterType = LLPathfindingPathTool::kCharacterTypeA; + break; + case XUI_CHARACTER_TYPE_B : + characterType = LLPathfindingPathTool::kCharacterTypeB; + break; + case XUI_CHARACTER_TYPE_C : + characterType = LLPathfindingPathTool::kCharacterTypeC; + break; + case XUI_CHARACTER_TYPE_D : + characterType = LLPathfindingPathTool::kCharacterTypeD; + break; + default : + characterType = LLPathfindingPathTool::kCharacterTypeNone; + llassert(0); + break; } + + LLPathfindingPathTool::getInstance()->setCharacterType(characterType); +} + +void LLFloaterPathfindingConsole::clearPath() +{ + LLPathfindingPathTool::getInstance()->clearPath(); } void LLFloaterPathfindingConsole::updatePathTestStatus() @@ -983,29 +954,47 @@ void LLFloaterPathfindingConsole::updatePathTestStatus() std::string statusText(""); LLStyle::Params styleParams; - if (!mHasStartPoint && !mHasEndPoint) + switch (LLPathfindingPathTool::getInstance()->getPathStatus()) { + case LLPathfindingPathTool::kPathStatusUnknown : + statusText = getString("pathing_unknown"); + styleParams.color = errorColor; + break; + case LLPathfindingPathTool::kPathStatusChooseStartAndEndPoints : statusText = getString("pathing_choose_start_and_end_points"); styleParams.color = warningColor; - } - else if (!mHasStartPoint && mHasEndPoint) - { + break; + case LLPathfindingPathTool::kPathStatusChooseStartPoint : statusText = getString("pathing_choose_start_point"); styleParams.color = warningColor; - } - else if (mHasStartPoint && !mHasEndPoint) - { + break; + case LLPathfindingPathTool::kPathStatusChooseEndPoint : statusText = getString("pathing_choose_end_point"); styleParams.color = warningColor; - } - else if (mHasValidPath) - { + break; + case LLPathfindingPathTool::kPathStatusHasValidPath : statusText = getString("pathing_path_valid"); - } - else - { + break; + case LLPathfindingPathTool::kPathStatusHasInvalidPath : statusText = getString("pathing_path_invalid"); styleParams.color = errorColor; + break; + case LLPathfindingPathTool::kPathStatusNotEnabled : + statusText = getString("pathing_region_not_enabled"); + styleParams.color = errorColor; + break; + case LLPathfindingPathTool::kPathStatusNotImplemented : + statusText = getString("pathing_library_not_implemented"); + styleParams.color = errorColor; + break; + case LLPathfindingPathTool::kPathStatusError : + statusText = getString("pathing_error"); + styleParams.color = errorColor; + break; + default : + statusText = getString("pathing_unknown"); + styleParams.color = errorColor; + break; } mPathTestingStatus->setText((LLStringExplicit)statusText, styleParams); diff --git a/indra/newview/llfloaterpathfindingconsole.h b/indra/newview/llfloaterpathfindingconsole.h index 85df38b370..7e0f8a4eaa 100644 --- a/indra/newview/llfloaterpathfindingconsole.h +++ b/indra/newview/llfloaterpathfindingconsole.h @@ -33,6 +33,7 @@ #include "LLPathingLib.h" #include "llpathfindingmanager.h" #include "llpathfindingnavmeshzone.h" +#include "llpathfindingpathtool.h" #include @@ -45,6 +46,7 @@ class LLCheckBoxCtrl; class LLTabContainer; class LLComboBox; class LLButton; +class LLToolset; class LLFloaterPathfindingConsole : public LLFloater @@ -61,26 +63,12 @@ public: kRenderHeatmapD } ERenderHeatmapType; - typedef enum - { - kCharacterTypeNone, - kCharacterTypeA, - kCharacterTypeB, - kCharacterTypeC, - kCharacterTypeD - } ECharacterType; - virtual BOOL postBuild(); virtual void onOpen(const LLSD& pKey); virtual void onClose(bool pIsAppQuitting); - virtual BOOL handleAnyMouseClick(S32 x, S32 y, MASK mask, EClickType clicktype, BOOL down); - - BOOL isGeneratePathMode(MASK mask, EClickType clicktype, BOOL down) const; static LLHandle getInstanceHandle(); - BOOL isRenderPath() const; - BOOL isRenderNavMesh() const; void setRenderNavMesh(BOOL pIsRenderNavMesh); @@ -108,12 +96,6 @@ public: ERenderHeatmapType getRenderHeatmapType() const; void setRenderHeatmapType(ERenderHeatmapType pRenderHeatmapType); - F32 getCharacterWidth() const; - void setCharacterWidth(F32 pCharacterWidth); - - ECharacterType getCharacterType() const; - void setCharacterType(ECharacterType pCharacterType); - int getHeatMapType() const; protected: @@ -136,16 +118,18 @@ private: virtual ~LLFloaterPathfindingConsole(); void onShowWalkabilitySet(); - void onCharacterWidthSet(); - void onCharacterTypeSwitch(); void onViewCharactersClicked(); + void onTabSwitch(); void onUnfreezeClicked(); void onFreezeClicked(); void onViewEditLinksetClicked(); + void onCharacterWidthSet(); + void onCharacterTypeSwitch(); void onClearPathClicked(); void onNavMeshZoneCB(LLPathfindingNavMeshZone::ENavMeshZoneRequestStatus pNavMeshZoneRequestStatus); void onAgentStateCB(LLPathfindingManager::EAgentState pAgentState); void onRegionBoundaryCross(); + void onPathEvent(); void setDefaultInputs(); void setConsoleState(EConsoleState pConsoleState); @@ -158,8 +142,13 @@ private: void setAgentState(LLPathfindingManager::EAgentState pAgentState); - void generatePath(); + void switchIntoTestPathMode(); + void switchOutOfTestPathMode(); + void updateCharacterWidth(); + void updateCharacterType(); + void clearPath(); void updatePathTestStatus(); + void resetShapeRenderFlags() { mShapeRenderFlags = 0; } void setShapeRenderFlag( LLPathingLib::LLShapeType type ) { mShapeRenderFlags |= (1< sInstanceHandle; + static LLHandle sInstanceHandle; public: - LLPathingLib::NavMeshColors mNavMeshColors; + LLPathingLib::NavMeshColors mNavMeshColors; }; #endif // LL_LLFLOATERPATHFINDINGCONSOLE_H diff --git a/indra/newview/llpathfindingpathtool.cpp b/indra/newview/llpathfindingpathtool.cpp new file mode 100644 index 0000000000..f27c722264 --- /dev/null +++ b/indra/newview/llpathfindingpathtool.cpp @@ -0,0 +1,206 @@ +/** + * @file llpathfindingpathtool.cpp + * @author William Todd Stinson + * @brief XXX + * + * $LicenseInfo:firstyear=2002&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, 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 "llpathfindingpathtool.h" +#include "llsingleton.h" +#include "lltool.h" +#include "llviewerwindow.h" +#include "llviewercamera.h" +#include "llpathfindingmanager.h" +#include "llpathinglib.h" + +#include +#include + +#define PATH_TOOL_NAME "PathfindingPathTool" + +LLPathfindingPathTool::LLPathfindingPathTool() + : LLTool(PATH_TOOL_NAME), + LLSingleton(), + mPathData(), + mPathResult(LLPathingLib::LLPL_PATH_NOT_GENERATED), + mHasStartPoint(false), + mHasEndPoint(false), + mCharacterWidth(1.0f), + mCharacterType(kCharacterTypeNone), + mPathEventSignal() +{ + if (!LLPathingLib::getInstance()) + { + LLPathingLib::initSystem(); + } +} + +LLPathfindingPathTool::~LLPathfindingPathTool() +{ +} + +BOOL LLPathfindingPathTool::handleMouseDown(S32 pX, S32 pY, MASK pMask) +{ + if ((pMask & (MASK_CONTROL|MASK_SHIFT)) != 0) + { + LLVector3 dv = gViewerWindow->mouseDirectionGlobal(pX, pY); + LLVector3 mousePos = LLViewerCamera::getInstance()->getOrigin(); + LLVector3 rayStart = mousePos; + LLVector3 rayEnd = mousePos + dv * 150; + + if (pMask & MASK_CONTROL) + { + mPathData.mStartPointA = rayStart; + mPathData.mEndPointA = rayEnd; + mHasStartPoint = true; + } + else if (pMask & MASK_SHIFT) + { + mPathData.mStartPointB = rayStart; + mPathData.mEndPointB = rayEnd; + mHasEndPoint = true; + } + computePath(); + } + + return ((pMask & (MASK_CONTROL|MASK_SHIFT)) != 0); +} + +BOOL LLPathfindingPathTool::handleHover(S32 pX, S32 pY, MASK pMask) +{ + if ((pMask & (MASK_CONTROL|MASK_SHIFT)) != 0) + { + gViewerWindow->setCursor(UI_CURSOR_TOOLPATHFINDING); + } + + return ((pMask & (MASK_CONTROL|MASK_SHIFT)) != 0); +} + +LLPathfindingPathTool::EPathStatus LLPathfindingPathTool::getPathStatus() const +{ + EPathStatus status = kPathStatusUnknown; + + if (LLPathingLib::getInstance() == NULL) + { + status = kPathStatusNotImplemented; + } + else if (!LLPathfindingManager::getInstance()->isPathfindingEnabledForCurrentRegion()) + { + status = kPathStatusNotEnabled; + } + else if (!mHasStartPoint && !mHasEndPoint) + { + status = kPathStatusChooseStartAndEndPoints; + } + else if (!mHasStartPoint) + { + status = kPathStatusChooseStartPoint; + } + else if (!mHasEndPoint) + { + status = kPathStatusChooseEndPoint; + } + else if (mPathResult == LLPathingLib::LLPL_PATH_GENERATED_OK) + { + status = kPathStatusHasValidPath; + } + else if (mPathResult == LLPathingLib::LLPL_NO_PATH) + { + status = kPathStatusHasInvalidPath; + } + else + { + status = kPathStatusError; + } + + return status; +} + +F32 LLPathfindingPathTool::getCharacterWidth() const +{ + return mCharacterWidth; +} + +void LLPathfindingPathTool::setCharacterWidth(F32 pCharacterWidth) +{ + mCharacterWidth = pCharacterWidth; + mPathData.mCharacterWidth = pCharacterWidth; + computePath(); +} + +LLPathfindingPathTool::ECharacterType LLPathfindingPathTool::getCharacterType() const +{ + return mCharacterType; +} + +void LLPathfindingPathTool::setCharacterType(ECharacterType pCharacterType) +{ + mCharacterType = pCharacterType; + switch (pCharacterType) + { + case kCharacterTypeNone : + mPathData.mCharacterType = LLPathingLib::LLPL_CHARACTER_TYPE_NONE; + break; + case kCharacterTypeA : + mPathData.mCharacterType = LLPathingLib::LLPL_CHARACTER_TYPE_A; + break; + case kCharacterTypeB : + mPathData.mCharacterType = LLPathingLib::LLPL_CHARACTER_TYPE_B; + break; + case kCharacterTypeC : + mPathData.mCharacterType = LLPathingLib::LLPL_CHARACTER_TYPE_C; + break; + case kCharacterTypeD : + mPathData.mCharacterType = LLPathingLib::LLPL_CHARACTER_TYPE_D; + break; + default : + mPathData.mCharacterType = LLPathingLib::LLPL_CHARACTER_TYPE_NONE; + llassert(0); + break; + } + computePath(); +} + +bool LLPathfindingPathTool::isRenderPath() const +{ + return (mHasStartPoint && mHasEndPoint); +} + +void LLPathfindingPathTool::clearPath() +{ + mHasStartPoint = false; + mHasEndPoint = false; + computePath(); +} + +LLPathfindingPathTool::path_event_slot_t LLPathfindingPathTool::registerPathEventListener(path_event_callback_t pPathEventCallback) +{ + return mPathEventSignal.connect(pPathEventCallback); +} + +void LLPathfindingPathTool::computePath() +{ + mPathResult = LLPathingLib::getInstance()->generatePath(mPathData); + mPathEventSignal(); +} diff --git a/indra/newview/llpathfindingpathtool.h b/indra/newview/llpathfindingpathtool.h new file mode 100644 index 0000000000..80d3b4cceb --- /dev/null +++ b/indra/newview/llpathfindingpathtool.h @@ -0,0 +1,102 @@ +/** + * @file llpathfindingpathtool.h + * @author William Todd Stinson + * @brief XXX + * + * $LicenseInfo:firstyear=2002&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, 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$ + */ + +#ifndef LL_LLPATHFINDINGPATHTOOL_H +#define LL_LLPATHFINDINGPATHTOOL_H + +#include "llsingleton.h" +#include "lltool.h" +#include "llpathinglib.h" + +#include +#include + +class LLPathfindingPathTool : public LLTool, public LLSingleton +{ +public: + typedef enum + { + kPathStatusUnknown, + kPathStatusChooseStartAndEndPoints, + kPathStatusChooseStartPoint, + kPathStatusChooseEndPoint, + kPathStatusHasValidPath, + kPathStatusHasInvalidPath, + kPathStatusNotEnabled, + kPathStatusNotImplemented, + kPathStatusError + } EPathStatus; + + typedef enum + { + kCharacterTypeNone, + kCharacterTypeA, + kCharacterTypeB, + kCharacterTypeC, + kCharacterTypeD + } ECharacterType; + + typedef + + LLPathfindingPathTool(); + virtual ~LLPathfindingPathTool(); + + typedef boost::function path_event_callback_t; + typedef boost::signals2::signal path_event_signal_t; + typedef boost::signals2::connection path_event_slot_t; + + virtual BOOL handleMouseDown(S32 pX, S32 pY, MASK pMask); + virtual BOOL handleHover(S32 pX, S32 pY, MASK pMask); + + EPathStatus getPathStatus() const; + + F32 getCharacterWidth() const; + void setCharacterWidth(F32 pCharacterWidth); + + ECharacterType getCharacterType() const; + void setCharacterType(ECharacterType pCharacterType); + + bool isRenderPath() const; + void clearPath(); + + path_event_slot_t registerPathEventListener(path_event_callback_t pPathEventCallback); + +protected: + +private: + void computePath(); + + LLPathingLib::PathingPacket mPathData; + LLPathingLib::LLPLResult mPathResult; + bool mHasStartPoint; + bool mHasEndPoint; + F32 mCharacterWidth; + ECharacterType mCharacterType; + path_event_signal_t mPathEventSignal; +}; + +#endif // LL_LLPATHFINDINGPATHTOOL_H diff --git a/indra/newview/lltoolmgr.cpp b/indra/newview/lltoolmgr.cpp index ac01316462..a135ba70f5 100644 --- a/indra/newview/lltoolmgr.cpp +++ b/indra/newview/lltoolmgr.cpp @@ -91,6 +91,8 @@ LLToolMgr::LLToolMgr() // gLandToolset = new LLToolset(); gMouselookToolset = new LLToolset(); gFaceEditToolset = new LLToolset(); + gMouselookToolset->setShowFloaterTools(false); + gFaceEditToolset->setShowFloaterTools(false); } void LLToolMgr::initTools() diff --git a/indra/newview/lltoolmgr.h b/indra/newview/lltoolmgr.h index 12649cfba2..e7d1c56c83 100644 --- a/indra/newview/lltoolmgr.h +++ b/indra/newview/lltoolmgr.h @@ -89,7 +89,7 @@ protected: class LLToolset { public: - LLToolset() : mSelectedTool(NULL) {} + LLToolset() : mSelectedTool(NULL), mIsShowFloaterTools(true) {} LLTool* getSelectedTool() { return mSelectedTool; } @@ -105,10 +105,14 @@ public: BOOL isToolSelected( S32 index ); + void setShowFloaterTools(bool pShowFloaterTools) {mIsShowFloaterTools = pShowFloaterTools;}; + bool isShowFloaterTools() const {return mIsShowFloaterTools;}; + protected: LLTool* mSelectedTool; typedef std::vector tool_list_t; tool_list_t mToolList; + bool mIsShowFloaterTools; }; // Globals diff --git a/indra/newview/llviewerwindow.cpp b/indra/newview/llviewerwindow.cpp index c5f31907c6..ee2171fb07 100644 --- a/indra/newview/llviewerwindow.cpp +++ b/indra/newview/llviewerwindow.cpp @@ -199,8 +199,6 @@ #include "llwindowlistener.h" #include "llviewerwindowlistener.h" #include "llpaneltopinfobar.h" -#include "LLPathingLib.h" -#include "llfloaterpathfindingconsole.h" #if LL_WINDOWS #include // For Unicode conversion methods @@ -834,7 +832,6 @@ BOOL LLViewerWindow::handleAnyMouseClick(LLWindow *window, LLCoordGL pos, MASK x = llround((F32)x / mDisplayScale.mV[VX]); y = llround((F32)y / mDisplayScale.mV[VY]); - // only send mouse clicks to UI if UI is visible if(gPipeline.hasRenderDebugFeatureMask(LLPipeline::RENDER_DEBUG_FEATURE_UI)) { @@ -948,26 +945,13 @@ BOOL LLViewerWindow::handleAnyMouseClick(LLWindow *window, LLCoordGL pos, MASK } } - //Determine if we have a pathing system and subsequently provide any mouse input - if (LLPathingLib::getInstance() != NULL) - { - LLHandle pathfindingConsoleHandle = LLFloaterPathfindingConsole::getInstanceHandle(); - if (!pathfindingConsoleHandle.isDead()) - { - LLFloaterPathfindingConsole *pathfindingConsoleFloater = pathfindingConsoleHandle.get(); - if (pathfindingConsoleFloater->isGeneratePathMode(mask, clicktype, down)) - { - return pathfindingConsoleFloater->handleAnyMouseClick(x, y, mask, clicktype, down); - } - } - } - // Do not allow tool manager to handle mouseclicks if we have disconnected if(!gDisconnected && LLToolMgr::getInstance()->getCurrentTool()->handleAnyMouseClick( x, y, mask, clicktype, down ) ) { return TRUE; } + // If we got this far on a down-click, it wasn't handled. // Up-clicks, though, are always handled as far as the OS is concerned. BOOL default_rtn = !down; @@ -3180,8 +3164,7 @@ void LLViewerWindow::updateLayout() || (tool != LLToolPie::getInstance() // not default tool && tool != LLToolCompGun::getInstance() // not coming out of mouselook && !suppress_toolbox // not override in third person - && LLToolMgr::getInstance()->getCurrentToolset() != gFaceEditToolset // not special mode - && LLToolMgr::getInstance()->getCurrentToolset() != gMouselookToolset + && LLToolMgr::getInstance()->getCurrentToolset()->isShowFloaterTools() && (!captor || dynamic_cast(captor) != NULL))) // not dragging { // Force floater tools to be visible (unless minimized) diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index c2eb579bb9..526b4bb8d4 100644 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -106,6 +106,7 @@ #include "llnotifications.h" #include "LLPathingLib.h" #include "llfloaterpathfindingconsole.h" +#include "llpathfindingpathtool.h" #ifdef _DEBUG // Debug indices is disabled for now for debug performance - djs 4/24/02 @@ -4400,7 +4401,7 @@ void LLPipeline::renderDebug() gGL.flush(); } //User designated path - if ( pathfindingConsole->isRenderPath() ) + if ( LLPathfindingPathTool::getInstance()->isRenderPath() ) { LLGLEnable blend(GL_BLEND); if (LLGLSLShader::sNoFixedFunction) diff --git a/indra/newview/res/lltoolpathfinding.cur b/indra/newview/res/lltoolpathfinding.cur new file mode 100644 index 0000000000..2df80de0a6 Binary files /dev/null and b/indra/newview/res/lltoolpathfinding.cur differ diff --git a/indra/newview/res/viewerRes.rc b/indra/newview/res/viewerRes.rc index a53dece422..5b25714203 100644 --- a/indra/newview/res/viewerRes.rc +++ b/indra/newview/res/viewerRes.rc @@ -122,6 +122,7 @@ TOOLMEDIAOPEN CURSOR "toolmediaopen.cur" TOOLBUY CURSOR "toolbuy.cur" TOOLOPEN CURSOR "toolopen.cur" TOOLSIT CURSOR "toolsit.cur" +TOOLPATHFINDING CURSOR "lltoolpathfinding.cur" ///////////////////////////////////////////////////////////////////////////// // diff --git a/indra/newview/skins/default/xui/en/floater_pathfinding_console.xml b/indra/newview/skins/default/xui/en/floater_pathfinding_console.xml index e43fda01e0..28f0d9fa4a 100644 --- a/indra/newview/skins/default/xui/en/floater_pathfinding_console.xml +++ b/indra/newview/skins/default/xui/en/floater_pathfinding_console.xml @@ -27,11 +27,15 @@ Some navmesh regions are building. Some navmesh regions have pending changes and others are building. Navmesh is up-to-date. + + Cannot find pathing library implementation. + This region is not enabled for pathfinding. Please choose start and end points. Please choose start point. Please choose end point. Path is shown in orange. A path between the chosen points cannot be found. + An error occurred during path generation.