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

游戏引擎

开发平台:

C++ Builder

  1. /**
  2.  * @file llpanelplaceprofile.cpp
  3.  * @brief Displays place profile 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 "llpanelplaceprofile.h"
  34. #include "llparcel.h"
  35. #include "message.h"
  36. #include "lliconctrl.h"
  37. #include "lllineeditor.h"
  38. #include "lltextbox.h"
  39. #include "lltexteditor.h"
  40. #include "lltrans.h"
  41. #include "llaccordionctrl.h"
  42. #include "llaccordionctrltab.h"
  43. #include "llagent.h"
  44. #include "llagentui.h"
  45. #include "llappviewer.h"
  46. #include "llcallbacklist.h"
  47. #include "llfloaterbuycurrency.h"
  48. #include "llstatusbar.h"
  49. #include "llviewercontrol.h"
  50. #include "llviewerparcelmgr.h"
  51. #include "llviewerregion.h"
  52. static LLRegisterPanelClassWrapper<LLPanelPlaceProfile> t_place_profile("panel_place_profile");
  53. // Statics for textures filenames
  54. static std::string icon_pg;
  55. static std::string icon_m;
  56. static std::string icon_r;
  57. static std::string icon_voice;
  58. static std::string icon_voice_no;
  59. static std::string icon_fly;
  60. static std::string icon_fly_no;
  61. static std::string icon_push;
  62. static std::string icon_push_no;
  63. static std::string icon_build;
  64. static std::string icon_build_no;
  65. static std::string icon_scripts;
  66. static std::string icon_scripts_no;
  67. static std::string icon_damage;
  68. static std::string icon_damage_no;
  69. LLPanelPlaceProfile::LLPanelPlaceProfile()
  70. : LLPanelPlaceInfo(),
  71. mForSalePanel(NULL),
  72. mYouAreHerePanel(NULL),
  73. mSelectedParcelID(-1)
  74. {}
  75. // virtual
  76. LLPanelPlaceProfile::~LLPanelPlaceProfile()
  77. {}
  78. // virtual
  79. BOOL LLPanelPlaceProfile::postBuild()
  80. {
  81. LLPanelPlaceInfo::postBuild();
  82. mForSalePanel = getChild<LLPanel>("for_sale_panel");
  83. mYouAreHerePanel = getChild<LLPanel>("here_panel");
  84. gIdleCallbacks.addFunction(&LLPanelPlaceProfile::updateYouAreHereBanner, this);
  85. //Icon value should contain sale price of last selected parcel.
  86. mForSalePanel->getChild<LLIconCtrl>("icon_for_sale")->
  87. setMouseDownCallback(boost::bind(&LLPanelPlaceProfile::onForSaleBannerClick, this));
  88. mParcelOwner = getChild<LLTextBox>("owner_value");
  89. mParcelRatingIcon = getChild<LLIconCtrl>("rating_icon");
  90. mParcelRatingText = getChild<LLTextBox>("rating_value");
  91. mVoiceIcon = getChild<LLIconCtrl>("voice_icon");
  92. mVoiceText = getChild<LLTextBox>("voice_value");
  93. mFlyIcon = getChild<LLIconCtrl>("fly_icon");
  94. mFlyText = getChild<LLTextBox>("fly_value");
  95. mPushIcon = getChild<LLIconCtrl>("push_icon");
  96. mPushText = getChild<LLTextBox>("push_value");
  97. mBuildIcon = getChild<LLIconCtrl>("build_icon");
  98. mBuildText = getChild<LLTextBox>("build_value");
  99. mScriptsIcon = getChild<LLIconCtrl>("scripts_icon");
  100. mScriptsText = getChild<LLTextBox>("scripts_value");
  101. mDamageIcon = getChild<LLIconCtrl>("damage_icon");
  102. mDamageText = getChild<LLTextBox>("damage_value");
  103. mRegionNameText = getChild<LLTextBox>("region_name");
  104. mRegionTypeText = getChild<LLTextBox>("region_type");
  105. mRegionRatingIcon = getChild<LLIconCtrl>("region_rating_icon");
  106. mRegionRatingText = getChild<LLTextBox>("region_rating");
  107. mRegionOwnerText = getChild<LLTextBox>("region_owner");
  108. mRegionGroupText = getChild<LLTextBox>("region_group");
  109. mEstateNameText = getChild<LLTextBox>("estate_name");
  110. mEstateRatingText = getChild<LLTextBox>("estate_rating");
  111. mEstateOwnerText = getChild<LLTextBox>("estate_owner");
  112. mCovenantText = getChild<LLTextEditor>("covenant");
  113. mSalesPriceText = getChild<LLTextBox>("sales_price");
  114. mAreaText = getChild<LLTextBox>("area");
  115. mTrafficText = getChild<LLTextBox>("traffic");
  116. mPrimitivesText = getChild<LLTextBox>("primitives");
  117. mParcelScriptsText = getChild<LLTextBox>("parcel_scripts");
  118. mTerraformLimitsText = getChild<LLTextBox>("terraform_limits");
  119. mSubdivideText = getChild<LLTextEditor>("subdivide");
  120. mResaleText = getChild<LLTextEditor>("resale");
  121. mSaleToText = getChild<LLTextBox>("sale_to");
  122. icon_pg = getString("icon_PG");
  123. icon_m = getString("icon_M");
  124. icon_r = getString("icon_R");
  125. icon_voice = getString("icon_Voice");
  126. icon_voice_no = getString("icon_VoiceNo");
  127. icon_fly = getString("icon_Fly");
  128. icon_fly_no = getString("icon_FlyNo");
  129. icon_push = getString("icon_Push");
  130. icon_push_no = getString("icon_PushNo");
  131. icon_build = getString("icon_Build");
  132. icon_build_no = getString("icon_BuildNo");
  133. icon_scripts = getString("icon_Scripts");
  134. icon_scripts_no = getString("icon_ScriptsNo");
  135. icon_damage = getString("icon_Damage");
  136. icon_damage_no = getString("icon_DamageNo");
  137. return TRUE;
  138. }
  139. // virtual
  140. void LLPanelPlaceProfile::resetLocation()
  141. {
  142. LLPanelPlaceInfo::resetLocation();
  143. mForSalePanel->setVisible(FALSE);
  144. mYouAreHerePanel->setVisible(FALSE);
  145. std::string loading = LLTrans::getString("LoadingData");
  146. mParcelOwner->setValue(loading);
  147. mParcelRatingIcon->setValue(loading);
  148. mParcelRatingText->setText(loading);
  149. mVoiceIcon->setValue(loading);
  150. mVoiceText->setText(loading);
  151. mFlyIcon->setValue(loading);
  152. mFlyText->setText(loading);
  153. mPushIcon->setValue(loading);
  154. mPushText->setText(loading);
  155. mBuildIcon->setValue(loading);
  156. mBuildText->setText(loading);
  157. mScriptsIcon->setValue(loading);
  158. mScriptsText->setText(loading);
  159. mDamageIcon->setValue(loading);
  160. mDamageText->setText(loading);
  161. mRegionNameText->setValue(loading);
  162. mRegionTypeText->setValue(loading);
  163. mRegionRatingIcon->setValue(loading);
  164. mRegionRatingText->setValue(loading);
  165. mRegionOwnerText->setValue(loading);
  166. mRegionGroupText->setValue(loading);
  167. mEstateNameText->setValue(loading);
  168. mEstateRatingText->setValue(loading);
  169. mEstateOwnerText->setValue(loading);
  170. mCovenantText->setValue(loading);
  171. mSalesPriceText->setValue(loading);
  172. mAreaText->setValue(loading);
  173. mTrafficText->setValue(loading);
  174. mPrimitivesText->setValue(loading);
  175. mParcelScriptsText->setValue(loading);
  176. mTerraformLimitsText->setValue(loading);
  177. mSubdivideText->setValue(loading);
  178. mResaleText->setValue(loading);
  179. mSaleToText->setValue(loading);
  180. }
  181. // virtual
  182. void LLPanelPlaceProfile::setInfoType(EInfoType type)
  183. {
  184. bool is_info_type_agent = type == AGENT;
  185. mMaturityRatingIcon->setVisible(!is_info_type_agent);
  186. mMaturityRatingText->setVisible(!is_info_type_agent);
  187. getChild<LLTextBox>("owner_label")->setVisible(is_info_type_agent);
  188. mParcelOwner->setVisible(is_info_type_agent);
  189. getChild<LLAccordionCtrl>("advanced_info_accordion")->setVisible(is_info_type_agent);
  190. switch(type)
  191. {
  192. case AGENT:
  193. case PLACE:
  194. default:
  195. mCurrentTitle = getString("title_place");
  196. break;
  197. case TELEPORT_HISTORY:
  198. mCurrentTitle = getString("title_teleport_history");
  199. break;
  200. }
  201. LLPanelPlaceInfo::setInfoType(type);
  202. }
  203. // virtual
  204. void LLPanelPlaceProfile::processParcelInfo(const LLParcelData& parcel_data)
  205. {
  206. LLPanelPlaceInfo::processParcelInfo(parcel_data);
  207. // HACK: Flag 0x2 == adult region,
  208. // Flag 0x1 == mature region, otherwise assume PG
  209. if (parcel_data.flags & 0x2)
  210. {
  211. mMaturityRatingIcon->setValue(icon_r);
  212. mMaturityRatingText->setText(LLViewerRegion::accessToString(SIM_ACCESS_ADULT));
  213. }
  214. else if (parcel_data.flags & 0x1)
  215. {
  216. mMaturityRatingIcon->setValue(icon_m);
  217. mMaturityRatingText->setText(LLViewerRegion::accessToString(SIM_ACCESS_MATURE));
  218. }
  219. else
  220. {
  221. mMaturityRatingIcon->setValue(icon_pg);
  222. mMaturityRatingText->setText(LLViewerRegion::accessToString(SIM_ACCESS_PG));
  223. }
  224. }
  225. // virtual
  226. void LLPanelPlaceProfile::handleVisibilityChange(BOOL new_visibility)
  227. {
  228. LLPanel::handleVisibilityChange(new_visibility);
  229. LLViewerParcelMgr* parcel_mgr = LLViewerParcelMgr::getInstance();
  230. if (!parcel_mgr)
  231. return;
  232. // Remove land selection when panel hides.
  233. if (!new_visibility)
  234. {
  235. if (!parcel_mgr->selectionEmpty())
  236. {
  237. parcel_mgr->deselectUnused();
  238. }
  239. }
  240. }
  241. void LLPanelPlaceProfile::displaySelectedParcelInfo(LLParcel* parcel,
  242. LLViewerRegion* region,
  243. const LLVector3d& pos_global,
  244. bool is_current_parcel)
  245. {
  246. if (!region || !parcel)
  247. return;
  248. // send EstateCovenantInfo message
  249. LLMessageSystem *msg = gMessageSystem;
  250. msg->newMessage("EstateCovenantRequest");
  251. msg->nextBlockFast(_PREHASH_AgentData);
  252. msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
  253. msg->addUUIDFast(_PREHASH_SessionID,gAgent.getSessionID());
  254. msg->sendReliable(region->getHost());
  255. LLParcelData parcel_data;
  256. // HACK: Converting sim access flags to the format
  257. // returned by remote parcel response.
  258. U8 sim_access = region->getSimAccess();
  259. switch(sim_access)
  260. {
  261. case SIM_ACCESS_MATURE:
  262. parcel_data.flags = 0x1;
  263. mParcelRatingIcon->setValue(icon_m);
  264. mRegionRatingIcon->setValue(icon_m);
  265. break;
  266. case SIM_ACCESS_ADULT:
  267. parcel_data.flags = 0x2;
  268. mParcelRatingIcon->setValue(icon_r);
  269. mRegionRatingIcon->setValue(icon_r);
  270. break;
  271. default:
  272. parcel_data.flags = 0;
  273. mParcelRatingIcon->setValue(icon_pg);
  274. mRegionRatingIcon->setValue(icon_pg);
  275. }
  276. std::string rating = LLViewerRegion::accessToString(sim_access);
  277. mParcelRatingText->setText(rating);
  278. mRegionRatingText->setText(rating);
  279. parcel_data.desc = parcel->getDesc();
  280. parcel_data.name = parcel->getName();
  281. parcel_data.sim_name = region->getName();
  282. parcel_data.snapshot_id = parcel->getSnapshotID();
  283. mPosRegion.setVec((F32)fmod(pos_global.mdV[VX], (F64)REGION_WIDTH_METERS),
  284.   (F32)fmod(pos_global.mdV[VY], (F64)REGION_WIDTH_METERS),
  285.   (F32)pos_global.mdV[VZ]);
  286. parcel_data.global_x = pos_global.mdV[VX];
  287. parcel_data.global_y = pos_global.mdV[VY];
  288. parcel_data.global_z = pos_global.mdV[VZ];
  289. std::string on = getString("on");
  290. std::string off = getString("off");
  291. LLViewerParcelMgr* vpm = LLViewerParcelMgr::getInstance();
  292. // Processing parcel characteristics
  293. if (vpm->allowAgentVoice(region, parcel))
  294. {
  295. mVoiceIcon->setValue(icon_voice);
  296. mVoiceText->setText(on);
  297. }
  298. else
  299. {
  300. mVoiceIcon->setValue(icon_voice_no);
  301. mVoiceText->setText(off);
  302. }
  303. if (vpm->allowAgentFly(region, parcel))
  304. {
  305. mFlyIcon->setValue(icon_fly);
  306. mFlyText->setText(on);
  307. }
  308. else
  309. {
  310. mFlyIcon->setValue(icon_fly_no);
  311. mFlyText->setText(off);
  312. }
  313. if (vpm->allowAgentPush(region, parcel))
  314. {
  315. mPushIcon->setValue(icon_push);
  316. mPushText->setText(on);
  317. }
  318. else
  319. {
  320. mPushIcon->setValue(icon_push_no);
  321. mPushText->setText(off);
  322. }
  323. if (vpm->allowAgentBuild(parcel))
  324. {
  325. mBuildIcon->setValue(icon_build);
  326. mBuildText->setText(on);
  327. }
  328. else
  329. {
  330. mBuildIcon->setValue(icon_build_no);
  331. mBuildText->setText(off);
  332. }
  333. if (vpm->allowAgentScripts(region, parcel))
  334. {
  335. mScriptsIcon->setValue(icon_scripts);
  336. mScriptsText->setText(on);
  337. }
  338. else
  339. {
  340. mScriptsIcon->setValue(icon_scripts_no);
  341. mScriptsText->setText(off);
  342. }
  343. if (vpm->allowAgentDamage(region, parcel))
  344. {
  345. mDamageIcon->setValue(icon_damage);
  346. mDamageText->setText(on);
  347. }
  348. else
  349. {
  350. mDamageIcon->setValue(icon_damage_no);
  351. mDamageText->setText(off);
  352. }
  353. mRegionNameText->setText(region->getName());
  354. mRegionTypeText->setText(region->getSimProductName());
  355. // Determine parcel owner
  356. if (parcel->isPublic())
  357. {
  358. mParcelOwner->setText(getString("public"));
  359. mRegionOwnerText->setText(getString("public"));
  360. }
  361. else
  362. {
  363. if (parcel->getIsGroupOwned())
  364. {
  365. mRegionOwnerText->setText(getString("group_owned_text"));
  366. if(!parcel->getGroupID().isNull())
  367. {
  368. // FIXME: Using parcel group as region group.
  369. gCacheName->get(parcel->getGroupID(), TRUE,
  370. boost::bind(&LLPanelPlaceInfo::nameUpdatedCallback, mRegionGroupText, _2, _3));
  371. gCacheName->get(parcel->getGroupID(), TRUE,
  372. boost::bind(&LLPanelPlaceInfo::nameUpdatedCallback, mParcelOwner, _2, _3));
  373. }
  374. else
  375. {
  376. std::string owner = getString("none_text");
  377. mRegionGroupText->setText(owner);
  378. mParcelOwner->setText(owner);
  379. }
  380. }
  381. else
  382. {
  383. // Figure out the owner's name
  384. gCacheName->get(parcel->getOwnerID(), FALSE,
  385. boost::bind(&LLPanelPlaceInfo::nameUpdatedCallback, mParcelOwner, _2, _3));
  386. gCacheName->get(region->getOwner(), FALSE,
  387. boost::bind(&LLPanelPlaceInfo::nameUpdatedCallback, mRegionOwnerText, _2, _3));
  388. }
  389. if(LLParcel::OS_LEASE_PENDING == parcel->getOwnershipStatus())
  390. {
  391. mRegionOwnerText->setText(mRegionOwnerText->getText() + getString("sale_pending_text"));
  392. }
  393. }
  394. mEstateRatingText->setText(region->getSimAccessString());
  395. S32 area;
  396. S32 claim_price;
  397. S32 rent_price;
  398. F32 dwell;
  399. BOOL for_sale;
  400. vpm->getDisplayInfo(&area, &claim_price, &rent_price, &for_sale, &dwell);
  401. if (for_sale)
  402. {
  403. const LLUUID& auth_buyer_id = parcel->getAuthorizedBuyerID();
  404. if(auth_buyer_id.notNull())
  405. {
  406. gCacheName->get(auth_buyer_id, TRUE,
  407. boost::bind(&LLPanelPlaceInfo::nameUpdatedCallback, mSaleToText, _2, _3));
  408. // Show sales info to a specific person or a group he belongs to.
  409. if (auth_buyer_id != gAgent.getID() && !gAgent.isInGroup(auth_buyer_id))
  410. {
  411. for_sale = FALSE;
  412. }
  413. }
  414. else
  415. {
  416. mSaleToText->setText(getString("anyone"));
  417. }
  418. mForSalePanel->setVisible(for_sale);
  419. const U8* sign = (U8*)getString("price_text").c_str();
  420. const U8* sqm = (U8*)getString("area_text").c_str();
  421. mSalesPriceText->setText(llformat("%s%d ", sign, parcel->getSalePrice()));
  422. mAreaText->setText(llformat("%d %s", area, sqm));
  423. mTrafficText->setText(llformat("%.0f", dwell));
  424. // Can't have more than region max tasks, regardless of parcel
  425. // object bonus factor.
  426. S32 primitives = llmin(llround(parcel->getMaxPrimCapacity() * parcel->getParcelPrimBonus()),
  427.    (S32)region->getMaxTasks());
  428. const U8* available = (U8*)getString("available").c_str();
  429. const U8* allocated = (U8*)getString("allocated").c_str();
  430. mPrimitivesText->setText(llformat("%d %s, %d %s", primitives, available, parcel->getPrimCount(), allocated));
  431. if (parcel->getAllowOtherScripts())
  432. {
  433. mParcelScriptsText->setText(getString("all_residents_text"));
  434. }
  435. else if (parcel->getAllowGroupScripts())
  436. {
  437. mParcelScriptsText->setText(getString("group_text"));
  438. }
  439. else
  440. {
  441. mParcelScriptsText->setText(off);
  442. }
  443. mTerraformLimitsText->setText(parcel->getAllowTerraform() ? on : off);
  444. if (region->getRegionFlags() & REGION_FLAGS_ALLOW_PARCEL_CHANGES)
  445. {
  446. mSubdivideText->setText(getString("can_change"));
  447. }
  448. else
  449. {
  450. mSubdivideText->setText(getString("can_not_change"));
  451. }
  452. if (region->getRegionFlags() & REGION_FLAGS_BLOCK_LAND_RESELL)
  453. {
  454. mResaleText->setText(getString("can_not_resell"));
  455. }
  456. else
  457. {
  458. mResaleText->setText(getString("can_resell"));
  459. }
  460. }
  461. mSelectedParcelID = parcel->getLocalID();
  462. mLastSelectedRegionID = region->getRegionID();
  463. LLPanelPlaceInfo::processParcelInfo(parcel_data);
  464. mYouAreHerePanel->setVisible(is_current_parcel);
  465. getChild<LLAccordionCtrlTab>("sales_tab")->setVisible(for_sale);
  466. }
  467. void LLPanelPlaceProfile::updateEstateName(const std::string& name)
  468. {
  469. mEstateNameText->setText(name);
  470. }
  471. void LLPanelPlaceProfile::updateEstateOwnerName(const std::string& name)
  472. {
  473. mEstateOwnerText->setText(name);
  474. }
  475. void LLPanelPlaceProfile::updateCovenantText(const std::string &text)
  476. {
  477. mCovenantText->setText(text);
  478. }
  479. void LLPanelPlaceProfile::onForSaleBannerClick()
  480. {
  481. LLViewerParcelMgr* mgr = LLViewerParcelMgr::getInstance();
  482. LLParcel* parcel = mgr->getFloatingParcelSelection()->getParcel();
  483. LLViewerRegion* selected_region =  mgr->getSelectionRegion();
  484. if(parcel && selected_region)
  485. {
  486. if(parcel->getLocalID() == mSelectedParcelID &&
  487. mLastSelectedRegionID ==selected_region->getRegionID())
  488. {
  489. if(parcel->getSalePrice() - gStatusBar->getBalance() > 0)
  490. {
  491. LLFloaterBuyCurrency::buyCurrency("Buying selected land ", parcel->getSalePrice());
  492. }
  493. else
  494. {
  495. LLViewerParcelMgr::getInstance()->startBuyLand();
  496. }
  497. }
  498. else
  499. {
  500. LL_WARNS("Places") << "User  is trying  to buy remote parcel.Operation is not supported"<< LL_ENDL;
  501. }
  502. }
  503. }
  504. // static
  505. void LLPanelPlaceProfile::updateYouAreHereBanner(void* userdata)
  506. {
  507. //YouAreHere Banner should be displayed only for selected places,
  508. // If you want to display it for landmark or teleport history item, you should check by mParcelId
  509. LLPanelPlaceProfile* self = static_cast<LLPanelPlaceProfile*>(userdata);
  510. if(!self->getVisible())
  511. return;
  512. if(!gDisconnected && gAgent.getRegion())
  513. {
  514. static F32 radius = gSavedSettings.getF32("YouAreHereDistance");
  515. BOOL display_banner = gAgent.getRegion()->getRegionID() == self->mLastSelectedRegionID &&
  516. LLAgentUI::checkAgentDistance(self->mPosRegion, radius);
  517. self->mYouAreHerePanel->setVisible(display_banner);
  518. }
  519. }