diff --git a/indra/newview/CMakeLists.txt b/indra/newview/CMakeLists.txt index 7a5c71729..342c19552 100644 --- a/indra/newview/CMakeLists.txt +++ b/indra/newview/CMakeLists.txt @@ -106,6 +106,7 @@ set(viewer_SOURCE_FILES llagentdata.cpp llagentlanguage.cpp llagentpilot.cpp + llagentui.cpp llagentwearables.cpp llanimstatelabels.cpp llappviewer.cpp @@ -584,6 +585,7 @@ set(viewer_HEADER_FILES llagentdata.h llagentlanguage.h llagentpilot.h + llagentui.h llagentwearables.h llanimstatelabels.h llappearance.h diff --git a/indra/newview/llagent.cpp b/indra/newview/llagent.cpp index 1b8192b36..c41d70ca6 100644 --- a/indra/newview/llagent.cpp +++ b/indra/newview/llagent.cpp @@ -39,6 +39,7 @@ #include "llagentaccess.h" #include "llagentcamera.h" #include "llagentwearables.h" +#include "llagentui.h" #include "llanimationstates.h" #include "llcallingcard.h" #include "llconsole.h" @@ -2518,61 +2519,6 @@ BOOL LLAgent::setUserGroupFlags(const LLUUID& group_id, BOOL accept_notices, BOO return FALSE; } -// utility to build a location string -void LLAgent::buildLocationString(std::string& str) -{ -// [RLVa:KB] - Checked: 2009-07-04 (RLVa-1.0.0a) - if (gRlvHandler.hasBehaviour(RLV_BHVR_SHOWLOC)) - { - str = RlvStrings::getString(RLV_STRING_HIDDEN); - return; - } -// [/RLVa:KB] - - const LLVector3& agent_pos_region = getPositionAgent(); - S32 pos_x = S32(agent_pos_region.mV[VX]); - S32 pos_y = S32(agent_pos_region.mV[VY]); - S32 pos_z = S32(agent_pos_region.mV[VZ]); - - // Round the numbers based on the velocity - LLVector3 agent_velocity = getVelocity(); - F32 velocity_mag_sq = agent_velocity.magVecSquared(); - - const F32 FLY_CUTOFF = 6.f; // meters/sec - const F32 FLY_CUTOFF_SQ = FLY_CUTOFF * FLY_CUTOFF; - const F32 WALK_CUTOFF = 1.5f; // meters/sec - const F32 WALK_CUTOFF_SQ = WALK_CUTOFF * WALK_CUTOFF; - - if (velocity_mag_sq > FLY_CUTOFF_SQ) - { - pos_x -= pos_x % 4; - pos_y -= pos_y % 4; - } - else if (velocity_mag_sq > WALK_CUTOFF_SQ) - { - pos_x -= pos_x % 2; - pos_y -= pos_y % 2; - } - - // create a defult name and description for the landmark - std::string buffer; - if( LLViewerParcelMgr::getInstance()->getAgentParcelName().empty() ) - { - // the parcel doesn't have a name - buffer = llformat("%.32s (%d, %d, %d)", - getRegion()->getName().c_str(), - pos_x, pos_y, pos_z); - } - else - { - // the parcel has a name, so include it in the landmark name - buffer = llformat("%.32s, %.32s (%d, %d, %d)", - LLViewerParcelMgr::getInstance()->getAgentParcelName().c_str(), - getRegion()->getName().c_str(), - pos_x, pos_y, pos_z); - } - str = buffer; -} LLQuaternion LLAgent::getHeadRotation() { diff --git a/indra/newview/llagent.h b/indra/newview/llagent.h index ff109d2ea..2c593f027 100644 --- a/indra/newview/llagent.h +++ b/indra/newview/llagent.h @@ -253,7 +253,6 @@ public: const LLHost& getRegionHost() const; BOOL inPrelude(); std::string getSLURL() const; //Return uri for current region - void buildLocationString(std::string& str); //Build a description string for current location // struct SHLureRequest diff --git a/indra/newview/llagentui.cpp b/indra/newview/llagentui.cpp new file mode 100644 index 000000000..7f6875385 --- /dev/null +++ b/indra/newview/llagentui.cpp @@ -0,0 +1,184 @@ +/** + * @file llagentui.cpp + * @brief Utility methods to process agent's data as slurl's etc. before displaying + * + * $LicenseInfo:firstyear=2009&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 "llagentui.h" + +// Library includes +#include "llparcel.h" + +// Viewer includes +#include "llagent.h" +#include "llviewercontrol.h" +#include "llviewerregion.h" +#include "llviewerparcelmgr.h" +// [RLVa:KB] - Checked: 2010-09-27 (RLVa-1.1.3b) +#include "rlvhandler.h" +// [/RLVa:KB] + +//static +void LLAgentUI::buildFullname(std::string& name) +{ + if (isAgentAvatarValid()) + name = gAgent.getAvatarObject()->getFullname(); +} + +/* +//static +void LLAgentUI::buildSLURL(LLSLURL& slurl, const bool escaped /*= true*//*) +{ + LLSLURL return_slurl; + LLViewerRegion *regionp = gAgent.getRegion(); + if (regionp) + { + return_slurl = LLSLURL(regionp->getName(), gAgent.getPositionGlobal()); + } + slurl = return_slurl; +}*/ + +//static +BOOL LLAgentUI::checkAgentDistance(const LLVector3& pole, F32 radius) +{ + F32 delta_x = gAgent.getPositionAgent().mV[VX] - pole.mV[VX]; + F32 delta_y = gAgent.getPositionAgent().mV[VY] - pole.mV[VY]; + + return sqrt( delta_x* delta_x + delta_y* delta_y ) < radius; +} +BOOL LLAgentUI::buildLocationString(std::string& str, ELocationFormat fmt,const LLVector3& agent_pos_region) +{ +// [RLVa:KB] - Checked: 2009-07-04 (RLVa-1.0.0a) + if (gRlvHandler.hasBehaviour(RLV_BHVR_SHOWLOC)) + { + str = RlvStrings::getString(RLV_STRING_HIDDEN); + return TRUE; + } +// [/RLVa:KB] + LLViewerRegion* region = gAgent.getRegion(); + LLParcel* parcel = LLViewerParcelMgr::getInstance()->getAgentParcel(); + + if (!region || !parcel) return FALSE; + + S32 pos_x = S32(agent_pos_region.mV[VX]); + S32 pos_y = S32(agent_pos_region.mV[VY]); + S32 pos_z = S32(agent_pos_region.mV[VZ]); + + // Round the numbers based on the velocity + F32 velocity_mag_sq = gAgent.getVelocity().magVecSquared(); + + const F32 FLY_CUTOFF = 6.f; // meters/sec + const F32 FLY_CUTOFF_SQ = FLY_CUTOFF * FLY_CUTOFF; + const F32 WALK_CUTOFF = 1.5f; // meters/sec + const F32 WALK_CUTOFF_SQ = WALK_CUTOFF * WALK_CUTOFF; + + if (velocity_mag_sq > FLY_CUTOFF_SQ) + { + pos_x -= pos_x % 4; + pos_y -= pos_y % 4; + } + else if (velocity_mag_sq > WALK_CUTOFF_SQ) + { + pos_x -= pos_x % 2; + pos_y -= pos_y % 2; + } + + // create a default name and description for the landmark + std::string parcel_name = LLViewerParcelMgr::getInstance()->getAgentParcelName(); + std::string region_name = region->getName(); + std::string sim_access_string = region->getSimAccessString(); + std::string buffer; + if( parcel_name.empty() ) + { + // the parcel doesn't have a name + switch (fmt) + { + case LOCATION_FORMAT_LANDMARK: + buffer = llformat("%.100s", region_name.c_str()); + break; + case LOCATION_FORMAT_NORMAL: + buffer = llformat("%s", region_name.c_str()); + break; + case LOCATION_FORMAT_NO_COORDS: + buffer = llformat("%s%s%s", + region_name.c_str(), + sim_access_string.empty() ? "" : " - ", + sim_access_string.c_str()); + break; + case LOCATION_FORMAT_NO_MATURITY: + buffer = llformat("%s (%d, %d, %d)", + region_name.c_str(), + pos_x, pos_y, pos_z); + break; + case LOCATION_FORMAT_FULL: + buffer = llformat("%s (%d, %d, %d)%s%s", + region_name.c_str(), + pos_x, pos_y, pos_z, + sim_access_string.empty() ? "" : " - ", + sim_access_string.c_str()); + break; + } + } + else + { + // the parcel has a name, so include it in the landmark name + switch (fmt) + { + case LOCATION_FORMAT_LANDMARK: + buffer = llformat("%.100s", parcel_name.c_str()); + break; + case LOCATION_FORMAT_NORMAL: + buffer = llformat("%s, %s", parcel_name.c_str(), region_name.c_str()); + break; + case LOCATION_FORMAT_NO_MATURITY: + buffer = llformat("%s, %s (%d, %d, %d)", + parcel_name.c_str(), + region_name.c_str(), + pos_x, pos_y, pos_z); + break; + case LOCATION_FORMAT_NO_COORDS: + buffer = llformat("%s, %s%s%s", + parcel_name.c_str(), + region_name.c_str(), + sim_access_string.empty() ? "" : " - ", + sim_access_string.c_str()); + break; + case LOCATION_FORMAT_FULL: + buffer = llformat("%s, %s (%d, %d, %d)%s%s", + parcel_name.c_str(), + region_name.c_str(), + pos_x, pos_y, pos_z, + sim_access_string.empty() ? "" : " - ", + sim_access_string.c_str()); + break; + } + } + str = buffer; + return TRUE; +} +BOOL LLAgentUI::buildLocationString(std::string& str, ELocationFormat fmt) +{ + return buildLocationString(str,fmt, gAgent.getPositionAgent()); +} diff --git a/indra/newview/llagentui.h b/indra/newview/llagentui.h new file mode 100644 index 000000000..dda5dc1fd --- /dev/null +++ b/indra/newview/llagentui.h @@ -0,0 +1,58 @@ +/** + * @file llagentui.h + * @brief Utility methods to process agent's data as slurl's etc. before displaying + * + * $LicenseInfo:firstyear=2009&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 LLAGENTUI_H +#define LLAGENTUI_H + +class LLSLURL; + +class LLAgentUI +{ +public: + enum ELocationFormat + { + LOCATION_FORMAT_NORMAL, // Parcel + LOCATION_FORMAT_LANDMARK, // Parcel, Region + LOCATION_FORMAT_NO_MATURITY, // Parcel, Region (x, y, z) + LOCATION_FORMAT_NO_COORDS, // Parcel, Region - Maturity + LOCATION_FORMAT_FULL, // Parcel, Region (x, y, z) - Maturity + }; + + static void buildFullname(std::string &name); + + static void buildSLURL(LLSLURL& slurl, const bool escaped = true); + //build location string using the current position of gAgent. + 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/llfloaterlandmark.cpp b/indra/newview/llfloaterlandmark.cpp index 25b955526..6f0940c9b 100644 --- a/indra/newview/llfloaterlandmark.cpp +++ b/indra/newview/llfloaterlandmark.cpp @@ -35,6 +35,7 @@ #include "llfloaterlandmark.h" #include "llagent.h" +#include "llagentui.h" #include "llcheckboxctrl.h" #include "llviewerparcelmgr.h" #include "llfolderview.h" @@ -299,14 +300,15 @@ void LLFloaterLandmark::onBtnNew(void* userdata) return; } - LLUUID folder_id; - folder_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_LANDMARK); - std::string pos_string; - gAgent.buildLocationString(pos_string); + std::string landmark_name, landmark_desc; + + LLAgentUI::buildLocationString(landmark_name, LLAgentUI::LOCATION_FORMAT_LANDMARK); + LLAgentUI::buildLocationString(landmark_desc, LLAgentUI::LOCATION_FORMAT_FULL); + const LLUUID folder_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_LANDMARK); create_inventory_item(gAgent.getID(), gAgent.getSessionID(), folder_id, LLTransactionID::tnull, - pos_string, pos_string, // name, desc + landmark_name, landmark_desc, // name, desc LLAssetType::AT_LANDMARK, LLInventoryType::IT_LANDMARK, NOT_WEARABLE, PERM_ALL, diff --git a/indra/newview/llfloatersnapshot.cpp b/indra/newview/llfloatersnapshot.cpp index 9289ff7b0..ed7415132 100644 --- a/indra/newview/llfloatersnapshot.cpp +++ b/indra/newview/llfloatersnapshot.cpp @@ -68,6 +68,7 @@ #include "lltoolfocus.h" #include "lltoolmgr.h" #include "llworld.h" +#include "llagentui.h" #include "llgl.h" #include "llglheaders.h" @@ -975,9 +976,9 @@ void LLSnapshotLivePreview::saveTexture() { LLVFile::writeFile(formatted->getData(), formatted->getDataSize(), gVFS, new_asset_id, LLAssetType::AT_TEXTURE); std::string pos_string; - gAgent.buildLocationString(pos_string); + LLAgentUI::buildLocationString(pos_string, LLAgentUI::LOCATION_FORMAT_FULL); std::string who_took_it; - gAgent.buildFullname(who_took_it); + LLAgentUI::buildFullname(who_took_it); LLAssetStorage::LLStoreAssetCallback callback = NULL; S32 expected_upload_cost = LLGlobalEconomy::Singleton::getInstance()->getPriceUpload(); void *userdata = NULL; diff --git a/indra/newview/llstatusbar.cpp b/indra/newview/llstatusbar.cpp index bcfd312ae..036d4f76f 100644 --- a/indra/newview/llstatusbar.cpp +++ b/indra/newview/llstatusbar.cpp @@ -69,6 +69,7 @@ #include "llviewerthrottle.h" #include "lluictrlfactory.h" #include "llvoiceclient.h" // for gVoiceClient +#include "llagentui.h" #include "lltoolmgr.h" #include "llfocusmgr.h" @@ -495,11 +496,10 @@ void LLStatusBar::refresh() mRegionDetails.mPing = region->getNetDetailsForLCD(); if (parcel) { - location_name = region->getName() - + llformat(" %d, %d, %d (%s) - %s", - pos_x, pos_y, pos_z, - region->getSimAccessString().c_str(), - parcel->getName().c_str()); + if (!LLAgentUI::buildLocationString(location_name, LLAgentUI::LOCATION_FORMAT_FULL)) + { + location_name = "???"; + } // keep these around for the LCD to use mRegionDetails.mRegionName = region->getName(); diff --git a/indra/newview/llviewermenu.cpp b/indra/newview/llviewermenu.cpp index a0c263cf2..2be3d924c 100644 --- a/indra/newview/llviewermenu.cpp +++ b/indra/newview/llviewermenu.cpp @@ -252,6 +252,7 @@ #include "floaterao.h" #include "slfloatermediafilter.h" #include "llviewerobjectbackup.h" +#include "llagentui.h" #include "hippogridmanager.h" @@ -6027,7 +6028,7 @@ class LLWorldCreateLandmark : public view_listener_t LLUUID folder_id; folder_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_LANDMARK); std::string pos_string; - gAgent.buildLocationString(pos_string); + LLAgentUI::buildLocationString(pos_string); create_inventory_item(gAgent.getID(), gAgent.getSessionID(), folder_id, LLTransactionID::tnull,