llpanelpick.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. /**
  2. * @file llpanelpick.cpp
  3. * @brief LLPanelPick class implementation
  4. *
  5. * $LicenseInfo:firstyear=2004&license=viewergpl$
  6. *
  7. * Copyright (c) 2004-2009, 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. // Display of a "Top Pick" used both for the global top picks in the
  33. // Find directory, and also for each individual user's picks in their
  34. // profile.
  35. #include "llviewerprecompiledheaders.h"
  36. #include "llpanelpick.h"
  37. #include "llbutton.h"
  38. #include "llcheckboxctrl.h"
  39. #include "lllineeditor.h"
  40. #include "llparcel.h"
  41. #include "lltabcontainer.h"
  42. #include "lltextbox.h"
  43. #include "lluictrlfactory.h"
  44. #include "llagent.h"
  45. #include "lltexturectrl.h"
  46. #include "llfloaterworldmap.h"
  47. //MK
  48. #include "mkrlinterface.h"
  49. //mk
  50. #include "llviewercontrol.h"
  51. #include "llviewerparcelmgr.h"
  52. #include "llviewerregion.h"
  53. #include "llviewertexteditor.h"
  54. #include "llworldmap.h"
  55. LLPanelPick::LLPanelPick(bool top_pick)
  56. : LLPanel(top_pick ? "Top picks panel" : "Picks panel"),
  57. LLAvatarPropertiesObserver(LLUUID::null, APT_PICK_INFO),
  58. mTopPick(top_pick),
  59. mDataRequested(false),
  60. mDataReceived(false)
  61. {
  62. std::string xml_file = top_pick ? "panel_top_pick.xml"
  63. : "panel_avatar_pick.xml";
  64. LLUICtrlFactory::getInstance()->buildPanel(this, xml_file);
  65. LLAvatarProperties::addObserver(this);
  66. }
  67. LLPanelPick::~LLPanelPick()
  68. {
  69. LLAvatarProperties::removeObserver(this);
  70. }
  71. void LLPanelPick::reset()
  72. {
  73. mPickID.setNull();
  74. mCreatorID.setNull();
  75. mParcelID.setNull();
  76. // Do not request data, this is not valid
  77. mDataRequested = true;
  78. mDataReceived = false;
  79. mPosGlobal.clear();
  80. clearCtrls();
  81. }
  82. //virtual
  83. bool LLPanelPick::postBuild()
  84. {
  85. mSnapshotCtrl = getChild<LLTextureCtrl>("snapshot_ctrl");
  86. mSnapshotCtrl->setCommitCallback(onCommitAny);
  87. mSnapshotCtrl->setCallbackUserData(this);
  88. mNameEditor = getChild<LLLineEditor>("given_name_editor");
  89. mNameEditor->setCommitOnFocusLost(true);
  90. mNameEditor->setCommitCallback(onCommitAny);
  91. mNameEditor->setCallbackUserData(this);
  92. mDescEditor = getChild<LLTextEditor>("desc_editor");
  93. mDescEditor->setCommitOnFocusLost(true);
  94. mDescEditor->setCommitCallback(onCommitAny);
  95. mDescEditor->setCallbackUserData(this);
  96. mDescEditor->setTabsToNextField(true);
  97. mLocationEditor = getChild<LLLineEditor>("location_editor");
  98. mSetBtn = getChild<LLButton>( "set_location_btn");
  99. mSetBtn->setClickedCallback(onClickSetLocation);
  100. mSetBtn->setCallbackUserData(this);
  101. mTeleportBtn = getChild<LLButton>( "pick_teleport_btn");
  102. mTeleportBtn->setClickedCallback(onClickTeleport);
  103. mTeleportBtn->setCallbackUserData(this);
  104. mMapBtn = getChild<LLButton>( "pick_map_btn");
  105. mMapBtn->setClickedCallback(onClickMap);
  106. mMapBtn->setCallbackUserData(this);
  107. mSortOrderText = getChild<LLTextBox>("sort_order_text");
  108. mSortOrderEditor = getChild<LLLineEditor>("sort_order_editor");
  109. mSortOrderEditor->setPrevalidate(LLLineEditor::prevalidateInt);
  110. mSortOrderEditor->setCommitOnFocusLost(true);
  111. mSortOrderEditor->setCommitCallback(onCommitAny);
  112. mSortOrderEditor->setCallbackUserData(this);
  113. mEnabledCheck = getChild<LLCheckBoxCtrl>( "enabled_check");
  114. mEnabledCheck->setCommitCallback(onCommitAny);
  115. mEnabledCheck->setCallbackUserData(this);
  116. return true;
  117. }
  118. // Fill in some reasonable defaults for a new pick.
  119. void LLPanelPick::initNewPick()
  120. {
  121. //MK
  122. if (gRLenabled && gRLInterface.mContainsShowloc)
  123. {
  124. return;
  125. }
  126. //mk
  127. mPickID.generate();
  128. mCreatorID = gAgentID;
  129. mPosGlobal = gAgent.getPositionGlobal();
  130. // Try to fill in the current parcel
  131. LLParcel* parcel = gViewerParcelMgr.getAgentParcel();
  132. if (parcel)
  133. {
  134. mNameEditor->setText(parcel->getName());
  135. mDescEditor->setText(parcel->getDesc());
  136. mSnapshotCtrl->setImageAssetID(parcel->getSnapshotID());
  137. }
  138. // Commit to the database, since we have got "new" values.
  139. sendPickInfoUpdate();
  140. }
  141. void LLPanelPick::setPickID(const LLUUID& pick_id, const LLUUID& creator_id)
  142. {
  143. mPickID = pick_id;
  144. mCreatorID = creator_id;
  145. }
  146. // Schedules the panel to request data from the server next time it is drawn
  147. void LLPanelPick::markForServerRequest()
  148. {
  149. mDataRequested = false;
  150. mDataReceived = false;
  151. }
  152. std::string LLPanelPick::getPickName()
  153. {
  154. return mNameEditor->getText();
  155. }
  156. void LLPanelPick::sendPickInfoRequest()
  157. {
  158. LLAvatarProperties::sendPickInfoRequest(mCreatorID, mPickID);
  159. mDataRequested = true;
  160. }
  161. void LLPanelPick::sendPickInfoUpdate()
  162. {
  163. // If we do not have a pick Id yet, we will need to generate one,
  164. // otherwise we will keep overwriting pick_id 00000 in the database.
  165. if (mPickID.isNull())
  166. {
  167. mPickID.generate();
  168. }
  169. LLAvatarPickInfo data;
  170. data.mAvatarId = mCreatorID;
  171. data.mPickId = mPickID;
  172. data.mSnapshotId = mSnapshotCtrl->getImageAssetID();
  173. data.mParcelId = mParcelID;
  174. data.mName = mNameEditor->getText();
  175. data.mDesc = mDescEditor->getText();
  176. data.mPosGlobal = mPosGlobal;
  177. // Only top picks have a sort order
  178. data.mSortOrder = mTopPick ? atoi(mSortOrderEditor->getText().c_str()) : 0;
  179. data.mEnabled = mEnabledCheck->get();
  180. LLAvatarProperties::sendPickInfoUpdate(data);
  181. }
  182. // Returns a location text made up from the owner name, the parcel name, the
  183. // sim name and the coordinates in that sim.
  184. //static
  185. std::string LLPanelPick::createLocationText(const std::string& owner_name,
  186. std::string parcel_name,
  187. const std::string& sim_name,
  188. const LLVector3d& pos_global)
  189. {
  190. std::string location_text = owner_name;
  191. // strip leading spaces in parcel name
  192. while (!parcel_name.empty() && parcel_name[0] == ' ')
  193. {
  194. parcel_name = parcel_name.substr(1);
  195. }
  196. if (!parcel_name.empty())
  197. {
  198. if (location_text.empty())
  199. {
  200. location_text = parcel_name;
  201. }
  202. else
  203. {
  204. location_text += ", " + parcel_name;
  205. }
  206. }
  207. if (!sim_name.empty())
  208. {
  209. if (location_text.empty())
  210. {
  211. location_text = sim_name;
  212. }
  213. else
  214. {
  215. location_text += ", " + sim_name;
  216. }
  217. }
  218. if (!pos_global.isNull())
  219. {
  220. if (!location_text.empty())
  221. {
  222. location_text += " ";
  223. }
  224. S32 x = ll_roundp((F32)pos_global.mdV[VX]) % REGION_WIDTH_UNITS;
  225. S32 y = ll_roundp((F32)pos_global.mdV[VY]) % REGION_WIDTH_UNITS;
  226. S32 z = ll_roundp((F32)pos_global.mdV[VZ]);
  227. location_text += llformat("(%d, %d, %d)", x, y, z);
  228. }
  229. return location_text;
  230. }
  231. //virtual
  232. void LLPanelPick::processProperties(S32 type, void* data)
  233. {
  234. if (type != APT_PICK_INFO || mPickID.isNull())
  235. {
  236. return; // Bad info, or we have not yet been assigned a pick.
  237. }
  238. LLAvatarPickInfo* info = (LLAvatarPickInfo*)data;
  239. if (info->mPickId != mPickID)
  240. {
  241. return; // Not for us.
  242. }
  243. mDataReceived = true;
  244. mCreatorID = info->mAvatarId;
  245. mParcelID = info->mParcelId;
  246. mSimName = info->mSimName;
  247. mPosGlobal = info->mPosGlobal;
  248. std::string location_text = createLocationText(info->mUserName,
  249. info->mParcelName,
  250. mSimName,
  251. mPosGlobal);
  252. mNameEditor->setText(info->mName);
  253. mDescEditor->clear();
  254. mDescEditor->setParseHTML(true);
  255. if (mCreatorID == gAgentID)
  256. {
  257. mDescEditor->setText(info->mDesc);
  258. }
  259. else
  260. {
  261. mDescEditor->appendColoredText(info->mDesc, false, false,
  262. mDescEditor->getReadOnlyFgColor());
  263. }
  264. mSnapshotCtrl->setImageAssetID(info->mSnapshotId);
  265. mLocationEditor->setText(location_text);
  266. mEnabledCheck->set(info->mEnabled);
  267. mSortOrderEditor->setText(llformat("%d", info->mSortOrder));
  268. }
  269. void LLPanelPick::draw()
  270. {
  271. refresh();
  272. LLPanel::draw();
  273. }
  274. void LLPanelPick::refresh()
  275. {
  276. if (!mDataRequested)
  277. {
  278. sendPickInfoRequest();
  279. }
  280. // Check for god mode
  281. bool godlike = gAgent.isGodlike();
  282. bool is_self = gAgentID == mCreatorID;
  283. // Set button visibility/enablement appropriately
  284. if (mTopPick)
  285. {
  286. mSnapshotCtrl->setEnabled(godlike);
  287. mNameEditor->setEnabled(godlike);
  288. mDescEditor->setEnabled(godlike);
  289. mSortOrderText->setVisible(godlike);
  290. mSortOrderEditor->setVisible(godlike);
  291. mSortOrderEditor->setEnabled(godlike);
  292. mEnabledCheck->setVisible(godlike);
  293. mEnabledCheck->setEnabled(godlike);
  294. mSetBtn->setVisible(godlike);
  295. mSetBtn->setEnabled(godlike);
  296. }
  297. else
  298. {
  299. mSnapshotCtrl->setEnabled(is_self);
  300. mNameEditor->setEnabled(is_self);
  301. mDescEditor->setEnabled(is_self);
  302. mSortOrderText->setVisible(false);
  303. mSortOrderEditor->setVisible(false);
  304. mSortOrderEditor->setEnabled(false);
  305. mEnabledCheck->setVisible(false);
  306. mEnabledCheck->setEnabled(false);
  307. mSetBtn->setVisible(is_self);
  308. mSetBtn->setEnabled(is_self);
  309. }
  310. }
  311. //static
  312. void LLPanelPick::onClickTeleport(void* data)
  313. {
  314. LLPanelPick* self = (LLPanelPick*)data;
  315. if (self && !self->mPosGlobal.isExactlyZero())
  316. {
  317. gAgent.teleportViaLocation(self->mPosGlobal);
  318. if (gFloaterWorldMapp)
  319. {
  320. gFloaterWorldMapp->trackLocation(self->mPosGlobal);
  321. }
  322. }
  323. }
  324. //static
  325. void LLPanelPick::onClickMap(void* data)
  326. {
  327. LLPanelPick* self = (LLPanelPick*)data;
  328. if (self && gFloaterWorldMapp)
  329. {
  330. gFloaterWorldMapp->trackLocation(self->mPosGlobal);
  331. LLFloaterWorldMap::show(NULL, true);
  332. }
  333. }
  334. //static
  335. void LLPanelPick::onClickSetLocation(void* data)
  336. {
  337. //MK
  338. if (gRLenabled && gRLInterface.mContainsShowloc)
  339. {
  340. // Do not allow to set the location while under @showloc
  341. return;
  342. }
  343. //mk
  344. LLPanelPick* self = (LLPanelPick*)data;
  345. if (!self) return;
  346. LLViewerRegion* regionp = gAgent.getRegion();
  347. if (!regionp) return;
  348. self->mSimName = regionp->getName();
  349. self->mPosGlobal = gAgent.getPositionGlobal();
  350. std::string parcel_name;
  351. LLParcel* parcel = gViewerParcelMgr.getAgentParcel();
  352. if (parcel)
  353. {
  354. self->mParcelID = parcel->getID();
  355. parcel_name = parcel->getName();
  356. }
  357. self->mLocationEditor->setText(createLocationText("", parcel_name,
  358. self->mSimName,
  359. self->mPosGlobal));
  360. onCommitAny(NULL, data);
  361. }
  362. //static
  363. void LLPanelPick::onCommitAny(LLUICtrl* ctrl, void* data)
  364. {
  365. LLPanelPick* self = (LLPanelPick*)data;
  366. // Have we received up to date data for this pick ?
  367. if (self && self->mDataReceived)
  368. {
  369. self->sendPickInfoUpdate();
  370. LLTabContainer* tab = (LLTabContainer*)self->getParent();
  371. if (tab)
  372. {
  373. tab->setCurrentTabName(self->mNameEditor->getText());
  374. }
  375. }
  376. }