llfloaterlandholdings.cpp 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. /**
  2. * @file llfloaterlandholdings.cpp
  3. * @brief "My Land" floater showing all your land parcels.
  4. *
  5. * $LicenseInfo:firstyear=2003&license=viewergpl$
  6. *
  7. * Copyright (c) 2003-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. #include "llviewerprecompiledheaders.h"
  33. #include "llfloaterlandholdings.h"
  34. #include "llparcel.h"
  35. #include "llqueryflags.h"
  36. #include "llscrolllistctrl.h"
  37. #include "lltrans.h"
  38. #include "lluictrlfactory.h"
  39. #include "llagent.h"
  40. #include "llfloatergroupinfo.h"
  41. #include "llfloaterworldmap.h"
  42. #include "llproductinforequest.h"
  43. #include "llstatusbar.h"
  44. #include "llviewermessage.h" // send_places_query()
  45. // protected
  46. LLFloaterLandHoldings::LLFloaterLandHoldings(const LLSD&)
  47. : mActualArea(0),
  48. mBillableArea(0),
  49. mIsDirty(true),
  50. mFirstPacketReceived(false)
  51. {
  52. LLUICtrlFactory::getInstance()->buildFloater(this,
  53. "floater_land_holdings.xml");
  54. }
  55. //virtual
  56. bool LLFloaterLandHoldings::postBuild()
  57. {
  58. // Parcels list
  59. mParcelsList = getChild<LLScrollListCtrl>("parcel list");
  60. mParcelsList->setCommitCallback(onSelectParcel);
  61. mParcelsList->setCallbackUserData(this);
  62. // Grant list
  63. mGrantList = getChild<LLScrollListCtrl>("grant list");
  64. mGrantList->setDoubleClickCallback(onGrantList);
  65. mGrantList->setCallbackUserData(this);
  66. childSetAction("Teleport", onClickTeleport, this);
  67. childSetAction("Show on Map", onClickMap, this);
  68. for (S32 i = 0, count = gAgent.mGroups.size(); i < count; ++i)
  69. {
  70. LLUUID id(gAgent.mGroups[i].mID);
  71. LLSD element;
  72. element["id"] = id;
  73. element["columns"][0]["column"] = "group";
  74. element["columns"][0]["value"] = gAgent.mGroups[i].mName;
  75. element["columns"][0]["font"] = "SANSSERIF";
  76. LLUIString areastr = getString("area_string");
  77. areastr.setArg("[AREA]", llformat("%d",
  78. gAgent.mGroups[i].mContribution));
  79. element["columns"][1]["column"] = "area";
  80. element["columns"][1]["value"] = areastr.getString();
  81. element["columns"][1]["font"] = "SANSSERIF";
  82. mGrantList->addElement(element, ADD_SORTED);
  83. }
  84. // Look only for parcels we own:
  85. send_places_query(LLUUID::null, LLUUID::null, "", DFQ_AGENT_OWNED,
  86. LLParcel::C_ANY, "");
  87. return true;
  88. }
  89. //virtual
  90. void LLFloaterLandHoldings::draw()
  91. {
  92. if (mIsDirty)
  93. {
  94. refresh();
  95. }
  96. LLFloater::draw();
  97. }
  98. //virtual
  99. void LLFloaterLandHoldings::refresh()
  100. {
  101. bool enable = mParcelsList->getFirstSelectedIndex() > -1;
  102. childSetEnabled("Teleport", enable);
  103. childSetEnabled("Show on Map", enable);
  104. S32 allowed_area = gStatusBarp->getSquareMetersCredit();
  105. S32 current_area = gStatusBarp->getSquareMetersCommitted();
  106. S32 available_area = gStatusBarp->getSquareMetersLeft();
  107. childSetTextArg("allowed_text", "[AREA]",
  108. llformat("%d", allowed_area));
  109. childSetTextArg("current_text", "[AREA]",
  110. llformat("%d", current_area));
  111. childSetTextArg("available_text", "[AREA]",
  112. llformat("%d", available_area));
  113. mIsDirty = false;
  114. }
  115. void LLFloaterLandHoldings::buttonCore(S32 which)
  116. {
  117. S32 index = mParcelsList->getFirstSelectedIndex();
  118. if (index < 0) return;
  119. // 'hidden' is always last column
  120. std::string location =
  121. mParcelsList->getSelectedItemLabel(mParcelsList->getNumColumns() - 1);
  122. F32 global_x = 0.f;
  123. F32 global_y = 0.f;
  124. sscanf(location.c_str(), "%f %f", &global_x, &global_y);
  125. // Hack: Use the agent's z-height
  126. F64 global_z = gAgent.getPositionGlobal().mdV[VZ];
  127. LLVector3d pos_global(global_x, global_y, global_z);
  128. switch (which)
  129. {
  130. case 0:
  131. gAgent.teleportViaLocation(pos_global);
  132. if (gFloaterWorldMapp)
  133. {
  134. gFloaterWorldMapp->trackLocation(pos_global);
  135. }
  136. break;
  137. case 1:
  138. if (gFloaterWorldMapp)
  139. {
  140. gFloaterWorldMapp->trackLocation(pos_global);
  141. LLFloaterWorldMap::show(NULL, true);
  142. }
  143. break;
  144. default:
  145. break;
  146. }
  147. }
  148. //static
  149. void LLFloaterLandHoldings::onSelectParcel(LLUICtrl*, void* data)
  150. {
  151. LLFloaterLandHoldings* self = (LLFloaterLandHoldings*)data;
  152. if (self)
  153. {
  154. self->mIsDirty = true;
  155. }
  156. }
  157. // static
  158. void LLFloaterLandHoldings::processPlacesReply(LLMessageSystem* msg, void**)
  159. {
  160. LLFloaterLandHoldings* self = findInstance();
  161. if (!self || !msg) return;
  162. // If this is the first packet, clear out the "loading..." indicator
  163. if (!self->mFirstPacketReceived)
  164. {
  165. self->mFirstPacketReceived = true;
  166. self->mParcelsList->deleteAllItems();
  167. }
  168. #if 0 // Not used
  169. LLUUID owner_id;
  170. std::string desc;
  171. #endif
  172. std::string name, sim_name, land_sku, land_type;
  173. LLProductInfoRequestManager* mgrp =
  174. LLProductInfoRequestManager::getInstance();
  175. for (S32 i = 0, count = msg->getNumberOfBlocks(_PREHASH_QueryData);
  176. i < count; ++i)
  177. {
  178. #if 0 // Not used
  179. msg->getUUID(_PREHASH_QueryData, _PREHASH_OwnerID, owner_id, i);
  180. msg->getString(_PREHASH_QueryData, _PREHASH_Desc, desc, i);
  181. U8 flags;
  182. msg->getU8(_PREHASH_QueryData, _PREHASH_Flags, flags, i);
  183. #endif
  184. msg->getString(_PREHASH_QueryData, _PREHASH_Name, name, i);
  185. S32 actual_area;
  186. msg->getS32(_PREHASH_QueryData, _PREHASH_ActualArea, actual_area, i);
  187. self->mActualArea += actual_area;
  188. S32 billable;
  189. msg->getS32(_PREHASH_QueryData, _PREHASH_BillableArea, billable, i);
  190. self->mBillableArea += billable;
  191. F32 global_x;
  192. msg->getF32(_PREHASH_QueryData, _PREHASH_GlobalX, global_x, i);
  193. F32 global_y;
  194. msg->getF32(_PREHASH_QueryData, _PREHASH_GlobalY, global_y, i);
  195. msg->getString(_PREHASH_QueryData, _PREHASH_SimName, sim_name, i);
  196. if (msg->getSizeFast(_PREHASH_QueryData, i, _PREHASH_ProductSKU) > 0)
  197. {
  198. msg->getStringFast( _PREHASH_QueryData, _PREHASH_ProductSKU,
  199. land_sku, i);
  200. LL_DEBUGS("Land SKU") << "Land sku: " << land_sku << LL_ENDL;
  201. land_type = mgrp->getDescriptionForSku(land_sku);
  202. }
  203. else
  204. {
  205. land_sku.clear();
  206. land_type = LLTrans::getString("unknown");
  207. }
  208. LLSD element;
  209. element["columns"][0]["column"] = "name";
  210. element["columns"][0]["value"] = name;
  211. element["columns"][0]["font"] = "SANSSERIF";
  212. S32 region_x = ll_roundp(global_x) % REGION_WIDTH_UNITS;
  213. S32 region_y = ll_roundp(global_y) % REGION_WIDTH_UNITS;
  214. element["columns"][1]["column"] = "location";
  215. element["columns"][1]["value"] =
  216. llformat("%s (%d, %d)", sim_name.c_str(), region_x, region_y);
  217. element["columns"][1]["font"] = "SANSSERIF";
  218. element["columns"][2]["column"] = "area";
  219. if (billable == actual_area)
  220. {
  221. element["columns"][2]["value"] = llformat("%d", billable);
  222. }
  223. else
  224. {
  225. element["columns"][2]["value"] = llformat("%d / %d", billable,
  226. actual_area);
  227. }
  228. element["columns"][2]["font"] = "SANSSERIF";
  229. element["columns"][3]["column"] = "type";
  230. element["columns"][3]["value"] = land_type;
  231. element["columns"][3]["font"] = "SANSSERIF";
  232. // 'hidden' is always last column
  233. element["columns"][4]["column"] = "hidden";
  234. element["columns"][4]["value"] = llformat("%f %f", global_x, global_y);
  235. self->mParcelsList->addElement(element);
  236. }
  237. self->mIsDirty = true;
  238. }
  239. // static
  240. void LLFloaterLandHoldings::onClickTeleport(void* data)
  241. {
  242. LLFloaterLandHoldings* self = (LLFloaterLandHoldings*)data;
  243. if (self)
  244. {
  245. self->buttonCore(0);
  246. self->close();
  247. }
  248. }
  249. // static
  250. void LLFloaterLandHoldings::onClickMap(void* data)
  251. {
  252. LLFloaterLandHoldings* self = (LLFloaterLandHoldings*)data;
  253. if (self)
  254. {
  255. self->buttonCore(1);
  256. }
  257. }
  258. // static
  259. void LLFloaterLandHoldings::onGrantList(void* data)
  260. {
  261. LLFloaterLandHoldings* self = (LLFloaterLandHoldings*)data;
  262. if (self)
  263. {
  264. LLUUID group_id = self->mGrantList->getCurrentID();
  265. if (group_id.notNull())
  266. {
  267. LLFloaterGroupInfo::showFromUUID(group_id);
  268. }
  269. }
  270. }