llpanellandmarkinfo.cpp
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:13k
源码类别:

游戏引擎

开发平台:

C++ Builder

  1. /**
  2.  * @file llpanellandmarkinfo.cpp
  3.  * @brief Displays landmark info in Side Tray.
  4.  *
  5.  * $LicenseInfo:firstyear=2009&license=viewergpl$
  6.  * 
  7.  * Copyright (c) 2009-2010, Linden Research, Inc.
  8.  * 
  9.  * Second Life Viewer Source Code
  10.  * The source code in this file ("Source Code") is provided by Linden Lab
  11.  * to you under the terms of the GNU General Public License, version 2.0
  12.  * ("GPL"), unless you have obtained a separate licensing agreement
  13.  * ("Other License"), formally executed by you and Linden Lab.  Terms of
  14.  * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15.  * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16.  * 
  17.  * There are special exceptions to the terms and conditions of the GPL as
  18.  * it is applied to this Source Code. View the full text of the exception
  19.  * in the file doc/FLOSS-exception.txt in this software distribution, or
  20.  * online at
  21.  * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22.  * 
  23.  * By copying, modifying or distributing this software, you acknowledge
  24.  * that you have read and understood your obligations described above,
  25.  * and agree to abide by those obligations.
  26.  * 
  27.  * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28.  * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29.  * COMPLETENESS OR PERFORMANCE.
  30.  * $/LicenseInfo$
  31.  */
  32. #include "llviewerprecompiledheaders.h"
  33. #include "llpanellandmarkinfo.h"
  34. #include "llcombobox.h"
  35. #include "lliconctrl.h"
  36. #include "lllineeditor.h"
  37. #include "lltextbox.h"
  38. #include "lltexteditor.h"
  39. #include "lltrans.h"
  40. #include "llagent.h"
  41. #include "llagentui.h"
  42. #include "lllandmarkactions.h"
  43. #include "llviewerinventory.h"
  44. #include "llviewerparcelmgr.h"
  45. #include "llviewerregion.h"
  46. //----------------------------------------------------------------------------
  47. // Aux types and methods
  48. //----------------------------------------------------------------------------
  49. typedef std::pair<LLUUID, std::string> folder_pair_t;
  50. static bool cmp_folders(const folder_pair_t& left, const folder_pair_t& right);
  51. static void collectLandmarkFolders(LLInventoryModel::cat_array_t& cats);
  52. static LLRegisterPanelClassWrapper<LLPanelLandmarkInfo> t_landmark_info("panel_landmark_info");
  53. // Statics for textures filenames
  54. static std::string icon_pg;
  55. static std::string icon_m;
  56. static std::string icon_r;
  57. LLPanelLandmarkInfo::LLPanelLandmarkInfo()
  58. : LLPanelPlaceInfo()
  59. {}
  60. // virtual
  61. LLPanelLandmarkInfo::~LLPanelLandmarkInfo()
  62. {}
  63. // virtual
  64. BOOL LLPanelLandmarkInfo::postBuild()
  65. {
  66. LLPanelPlaceInfo::postBuild();
  67. mOwner = getChild<LLTextBox>("owner");
  68. mCreator = getChild<LLTextBox>("creator");
  69. mCreated = getChild<LLTextBox>("created");
  70. mLandmarkTitle = getChild<LLTextBox>("title_value");
  71. mLandmarkTitleEditor = getChild<LLLineEditor>("title_editor");
  72. mNotesEditor = getChild<LLTextEditor>("notes_editor");
  73. mFolderCombo = getChild<LLComboBox>("folder_combo");
  74. icon_pg = getString("icon_PG");
  75. icon_m = getString("icon_M");
  76. icon_r = getString("icon_R");
  77. return TRUE;
  78. }
  79. // virtual
  80. void LLPanelLandmarkInfo::resetLocation()
  81. {
  82. LLPanelPlaceInfo::resetLocation();
  83. std::string loading = LLTrans::getString("LoadingData");
  84. mCreator->setText(loading);
  85. mOwner->setText(loading);
  86. mCreated->setText(loading);
  87. mLandmarkTitle->setText(LLStringUtil::null);
  88. mLandmarkTitleEditor->setText(LLStringUtil::null);
  89. mNotesEditor->setText(LLStringUtil::null);
  90. }
  91. // virtual
  92. void LLPanelLandmarkInfo::setInfoType(EInfoType type)
  93. {
  94. LLPanel* landmark_info_panel = getChild<LLPanel>("landmark_info_panel");
  95. bool is_info_type_create_landmark = type == CREATE_LANDMARK;
  96. landmark_info_panel->setVisible(type == LANDMARK);
  97. getChild<LLTextBox>("folder_label")->setVisible(is_info_type_create_landmark);
  98. mFolderCombo->setVisible(is_info_type_create_landmark);
  99. switch(type)
  100. {
  101. case CREATE_LANDMARK:
  102. mCurrentTitle = getString("title_create_landmark");
  103. mLandmarkTitle->setVisible(FALSE);
  104. mLandmarkTitleEditor->setVisible(TRUE);
  105. mNotesEditor->setEnabled(TRUE);
  106. break;
  107. case LANDMARK:
  108. default:
  109. mCurrentTitle = getString("title_landmark");
  110. mLandmarkTitle->setVisible(TRUE);
  111. mLandmarkTitleEditor->setVisible(FALSE);
  112. mNotesEditor->setEnabled(FALSE);
  113. break;
  114. }
  115. populateFoldersList();
  116. LLPanelPlaceInfo::setInfoType(type);
  117. }
  118. // virtual
  119. void LLPanelLandmarkInfo::processParcelInfo(const LLParcelData& parcel_data)
  120. {
  121. LLPanelPlaceInfo::processParcelInfo(parcel_data);
  122. // HACK: Flag 0x2 == adult region,
  123. // Flag 0x1 == mature region, otherwise assume PG
  124. if (parcel_data.flags & 0x2)
  125. {
  126. mMaturityRatingIcon->setValue(icon_r);
  127. mMaturityRatingText->setText(LLViewerRegion::accessToString(SIM_ACCESS_ADULT));
  128. }
  129. else if (parcel_data.flags & 0x1)
  130. {
  131. mMaturityRatingIcon->setValue(icon_m);
  132. mMaturityRatingText->setText(LLViewerRegion::accessToString(SIM_ACCESS_MATURE));
  133. }
  134. else
  135. {
  136. mMaturityRatingIcon->setValue(icon_pg);
  137. mMaturityRatingText->setText(LLViewerRegion::accessToString(SIM_ACCESS_PG));
  138. }
  139. S32 region_x;
  140. S32 region_y;
  141. S32 region_z;
  142. // If the region position is zero, grab position from the global
  143. if(mPosRegion.isExactlyZero())
  144. {
  145. region_x = llround(parcel_data.global_x) % REGION_WIDTH_UNITS;
  146. region_y = llround(parcel_data.global_y) % REGION_WIDTH_UNITS;
  147. region_z = llround(parcel_data.global_z);
  148. }
  149. else
  150. {
  151. region_x = llround(mPosRegion.mV[VX]);
  152. region_y = llround(mPosRegion.mV[VY]);
  153. region_z = llround(mPosRegion.mV[VZ]);
  154. }
  155. LLSD info;
  156. info["update_verbs"] = true;
  157. info["global_x"] = parcel_data.global_x;
  158. info["global_y"] = parcel_data.global_y;
  159. info["global_z"] = parcel_data.global_z;
  160. notifyParent(info);
  161. if (mInfoType == CREATE_LANDMARK)
  162. {
  163. if (parcel_data.name.empty())
  164. {
  165. mLandmarkTitleEditor->setText(llformat("%s (%d, %d, %d)",
  166.   parcel_data.sim_name.c_str(), region_x, region_y, region_z));
  167. }
  168. else
  169. {
  170. mLandmarkTitleEditor->setText(parcel_data.name);
  171. }
  172. std::string desc;
  173. LLAgentUI::buildLocationString(desc, LLAgentUI::LOCATION_FORMAT_FULL, gAgent.getPositionAgent());
  174. mNotesEditor->setText(desc);
  175. if (!LLLandmarkActions::landmarkAlreadyExists())
  176. {
  177. createLandmark(mFolderCombo->getValue().asUUID());
  178. }
  179. }
  180. }
  181. void LLPanelLandmarkInfo::displayItemInfo(const LLInventoryItem* pItem)
  182. {
  183. if (!pItem)
  184. return;
  185. if(!gCacheName)
  186. return;
  187. const LLPermissions& perm = pItem->getPermissions();
  188. //////////////////
  189. // CREATOR NAME //
  190. //////////////////
  191. if (pItem->getCreatorUUID().notNull())
  192. {
  193. std::string name;
  194. LLUUID creator_id = pItem->getCreatorUUID();
  195. if (!gCacheName->getFullName(creator_id, name))
  196. {
  197. gCacheName->get(creator_id, FALSE,
  198. boost::bind(&LLPanelPlaceInfo::nameUpdatedCallback, mCreator, _2, _3));
  199. }
  200. mCreator->setText(name);
  201. }
  202. else
  203. {
  204. mCreator->setText(getString("unknown"));
  205. }
  206. ////////////////
  207. // OWNER NAME //
  208. ////////////////
  209. if(perm.isOwned())
  210. {
  211. std::string name;
  212. if (perm.isGroupOwned())
  213. {
  214. LLUUID group_id = perm.getGroup();
  215. if (!gCacheName->getGroupName(group_id, name))
  216. {
  217. gCacheName->get(group_id, TRUE,
  218. boost::bind(&LLPanelPlaceInfo::nameUpdatedCallback, mOwner, _2, _3));
  219. }
  220. }
  221. else
  222. {
  223. LLUUID owner_id = perm.getOwner();
  224. if (!gCacheName->getFullName(owner_id, name))
  225. {
  226. gCacheName->get(owner_id, FALSE,
  227. boost::bind(&LLPanelPlaceInfo::nameUpdatedCallback, mOwner, _2, _3));
  228. }
  229. }
  230. mOwner->setText(name);
  231. }
  232. else
  233. {
  234. mOwner->setText(getString("public"));
  235. }
  236. //////////////////
  237. // ACQUIRE DATE //
  238. //////////////////
  239. time_t time_utc = pItem->getCreationDate();
  240. if (0 == time_utc)
  241. {
  242. mCreated->setText(getString("unknown"));
  243. }
  244. else
  245. {
  246. std::string timeStr = getString("acquired_date");
  247. LLSD substitution;
  248. substitution["datetime"] = (S32) time_utc;
  249. LLStringUtil::format (timeStr, substitution);
  250. mCreated->setText(timeStr);
  251. }
  252. mLandmarkTitle->setText(pItem->getName());
  253. mLandmarkTitleEditor->setText(pItem->getName());
  254. mNotesEditor->setText(pItem->getDescription());
  255. }
  256. void LLPanelLandmarkInfo::toggleLandmarkEditMode(BOOL enabled)
  257. {
  258. // If switching to edit mode while creating landmark
  259. // the "Create Landmark" title remains.
  260. if (enabled && mInfoType != CREATE_LANDMARK)
  261. {
  262. mTitle->setText(getString("title_edit_landmark"));
  263. }
  264. else
  265. {
  266. mTitle->setText(mCurrentTitle);
  267. mLandmarkTitle->setText(mLandmarkTitleEditor->getText());
  268. }
  269. if (mNotesEditor->getReadOnly() ==  (enabled == TRUE))
  270. {
  271. mLandmarkTitle->setVisible(!enabled);
  272. mLandmarkTitleEditor->setVisible(enabled);
  273. mNotesEditor->setReadOnly(!enabled);
  274. mFolderCombo->setVisible(enabled);
  275. getChild<LLTextBox>("folder_label")->setVisible(enabled);
  276. // HACK: To change the text color in a text editor
  277. // when it was enabled/disabled we set the text once again.
  278. mNotesEditor->setText(mNotesEditor->getText());
  279. }
  280. }
  281. const std::string& LLPanelLandmarkInfo::getLandmarkTitle() const
  282. {
  283. return mLandmarkTitleEditor->getText();
  284. }
  285. const std::string LLPanelLandmarkInfo::getLandmarkNotes() const
  286. {
  287. return mNotesEditor->getText();
  288. }
  289. const LLUUID LLPanelLandmarkInfo::getLandmarkFolder() const
  290. {
  291. return mFolderCombo->getValue().asUUID();
  292. }
  293. BOOL LLPanelLandmarkInfo::setLandmarkFolder(const LLUUID& id)
  294. {
  295. return mFolderCombo->setCurrentByID(id);
  296. }
  297. void LLPanelLandmarkInfo::createLandmark(const LLUUID& folder_id)
  298. {
  299. std::string name = mLandmarkTitleEditor->getText();
  300. std::string desc = mNotesEditor->getText();
  301. LLStringUtil::trim(name);
  302. LLStringUtil::trim(desc);
  303. // If typed name is empty use the parcel name instead.
  304. if (name.empty())
  305. {
  306. name = mParcelName->getText();
  307. // If no parcel exists use the region name instead.
  308. if (name.empty())
  309. {
  310. name = mRegionName->getText();
  311. }
  312. }
  313. LLStringUtil::replaceChar(desc, 'n', ' ');
  314. // If no folder chosen use the "Landmarks" folder.
  315. LLLandmarkActions::createLandmarkHere(name, desc,
  316. folder_id.notNull() ? folder_id : gInventory.findCategoryUUIDForType(LLFolderType::FT_LANDMARK));
  317. }
  318. // static
  319. std::string LLPanelLandmarkInfo::getFullFolderName(const LLViewerInventoryCategory* cat)
  320. {
  321. std::string name;
  322. LLUUID parent_id;
  323. llassert(cat);
  324. if (cat)
  325. {
  326. name = cat->getName();
  327. // translate category name, if it's right below the root
  328. // FIXME: it can throw notification about non existent string in strings.xml
  329. if (cat->getParentUUID().notNull() && cat->getParentUUID() == gInventory.getRootFolderID())
  330. {
  331. LLTrans::findString(name, "InvFolder " + name);
  332. }
  333. // we don't want "My Inventory" to appear in the name
  334. while ((parent_id = cat->getParentUUID()).notNull() && parent_id != gInventory.getRootFolderID())
  335. {
  336. cat = gInventory.getCategory(parent_id);
  337. llassert(cat);
  338. if (cat)
  339. {
  340. name = cat->getName() + "/" + name;
  341. }
  342. }
  343. }
  344. return name;
  345. }
  346. void LLPanelLandmarkInfo::populateFoldersList()
  347. {
  348. // Collect all folders that can contain landmarks.
  349. LLInventoryModel::cat_array_t cats;
  350. collectLandmarkFolders(cats);
  351. mFolderCombo->removeall();
  352. // Put the "Landmarks" folder first in list.
  353. LLUUID landmarks_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_LANDMARK);
  354. const LLViewerInventoryCategory* lmcat = gInventory.getCategory(landmarks_id);
  355. if (!lmcat)
  356. {
  357. llwarns << "Cannot find the landmarks folder" << llendl;
  358. }
  359. else
  360. {
  361. std::string cat_full_name = getFullFolderName(lmcat);
  362. mFolderCombo->add(cat_full_name, lmcat->getUUID());
  363. }
  364. typedef std::vector<folder_pair_t> folder_vec_t;
  365. folder_vec_t folders;
  366. // Sort the folders by their full name.
  367. for (S32 i = 0; i < cats.count(); i++)
  368. {
  369. const LLViewerInventoryCategory* cat = cats.get(i);
  370. std::string cat_full_name = getFullFolderName(cat);
  371. folders.push_back(folder_pair_t(cat->getUUID(), cat_full_name));
  372. }
  373. sort(folders.begin(), folders.end(), cmp_folders);
  374. // Finally, populate the combobox.
  375. for (folder_vec_t::const_iterator it = folders.begin(); it != folders.end(); it++)
  376. mFolderCombo->add(it->second, LLSD(it->first));
  377. }
  378. static bool cmp_folders(const folder_pair_t& left, const folder_pair_t& right)
  379. {
  380. return left.second < right.second;
  381. }
  382. static void collectLandmarkFolders(LLInventoryModel::cat_array_t& cats)
  383. {
  384. LLUUID landmarks_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_LANDMARK);
  385. // Add descendent folders of the "Landmarks" category.
  386. LLInventoryModel::item_array_t items; // unused
  387. LLIsType is_category(LLAssetType::AT_CATEGORY);
  388. gInventory.collectDescendentsIf(
  389. landmarks_id,
  390. cats,
  391. items,
  392. LLInventoryModel::EXCLUDE_TRASH,
  393. is_category);
  394. // Add the "My Favorites" category.
  395. LLUUID favorites_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_FAVORITE);
  396. LLViewerInventoryCategory* favorites_cat = gInventory.getCategory(favorites_id);
  397. if (!favorites_cat)
  398. {
  399. llwarns << "Cannot find the favorites folder" << llendl;
  400. }
  401. else
  402. {
  403. cats.put(favorites_cat);
  404. }
  405. }