PageRenderTime 93ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llfloaterlandholdings.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 332 lines | 234 code | 58 blank | 40 comment | 17 complexity | 708b8bc99f4fe0d7d2d172c5985c9ddf MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llfloaterlandholdings.cpp
  3. * @brief "My Land" floater showing all your land parcels.
  4. *
  5. * $LicenseInfo:firstyear=2003&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #include "llviewerprecompiledheaders.h"
  27. #include "llfloaterlandholdings.h"
  28. #include "indra_constants.h"
  29. #include "llfontgl.h"
  30. #include "llqueryflags.h"
  31. #include "llparcel.h"
  32. #include "message.h"
  33. #include "llagent.h"
  34. #include "llfloaterreg.h"
  35. #include "llfloaterworldmap.h"
  36. #include "llproductinforequest.h"
  37. #include "llscrolllistctrl.h"
  38. #include "llstatusbar.h"
  39. #include "lltextbox.h"
  40. #include "llscrolllistctrl.h"
  41. #include "llscrolllistitem.h"
  42. #include "llscrolllistcell.h"
  43. #include "lltrans.h"
  44. #include "lluiconstants.h"
  45. #include "llviewermessage.h"
  46. #include "lluictrlfactory.h"
  47. #include "llgroupactions.h"
  48. // protected
  49. LLFloaterLandHoldings::LLFloaterLandHoldings(const LLSD& key)
  50. : LLFloater(key),
  51. mActualArea(0),
  52. mBillableArea(0),
  53. mFirstPacketReceived(FALSE),
  54. mSortColumn(""),
  55. mSortAscending(TRUE)
  56. {
  57. }
  58. BOOL LLFloaterLandHoldings::postBuild()
  59. {
  60. childSetAction("Teleport", onClickTeleport, this);
  61. childSetAction("Show on Map", onClickMap, this);
  62. // Grant list
  63. LLScrollListCtrl* grant_list = getChild<LLScrollListCtrl>("grant list");
  64. grant_list->sortByColumnIndex(0, TRUE);
  65. grant_list->setDoubleClickCallback(onGrantList, this);
  66. S32 count = gAgent.mGroups.count();
  67. for(S32 i = 0; i < count; ++i)
  68. {
  69. LLUUID id(gAgent.mGroups.get(i).mID);
  70. LLSD element;
  71. element["id"] = id;
  72. element["columns"][0]["column"] = "group";
  73. element["columns"][0]["value"] = gAgent.mGroups.get(i).mName;
  74. element["columns"][0]["font"] = "SANSSERIF";
  75. LLUIString areastr = getString("area_string");
  76. areastr.setArg("[AREA]", llformat("%d", gAgent.mGroups.get(i).mContribution));
  77. element["columns"][1]["column"] = "area";
  78. element["columns"][1]["value"] = areastr;
  79. element["columns"][1]["font"] = "SANSSERIF";
  80. grant_list->addElement(element);
  81. }
  82. center();
  83. return TRUE;
  84. }
  85. // protected
  86. LLFloaterLandHoldings::~LLFloaterLandHoldings()
  87. {
  88. }
  89. void LLFloaterLandHoldings::onOpen(const LLSD& key)
  90. {
  91. // query_id null is known to be us
  92. const LLUUID& query_id = LLUUID::null;
  93. // look only for parcels we own
  94. U32 query_flags = DFQ_AGENT_OWNED;
  95. send_places_query(query_id,
  96. LLUUID::null,
  97. "",
  98. query_flags,
  99. LLParcel::C_ANY,
  100. "");
  101. }
  102. void LLFloaterLandHoldings::draw()
  103. {
  104. refresh();
  105. LLFloater::draw();
  106. }
  107. // public
  108. void LLFloaterLandHoldings::refresh()
  109. {
  110. LLCtrlSelectionInterface *list = childGetSelectionInterface("parcel list");
  111. BOOL enable_btns = FALSE;
  112. if (list && list->getFirstSelectedIndex()> -1)
  113. {
  114. enable_btns = TRUE;
  115. }
  116. getChildView("Teleport")->setEnabled(enable_btns);
  117. getChildView("Show on Map")->setEnabled(enable_btns);
  118. refreshAggregates();
  119. }
  120. // static
  121. void LLFloaterLandHoldings::processPlacesReply(LLMessageSystem* msg, void**)
  122. {
  123. LLFloaterLandHoldings* self = LLFloaterReg::findTypedInstance<LLFloaterLandHoldings>("land_holdings");
  124. // Is this packet from an old, closed window?
  125. if (!self)
  126. {
  127. return;
  128. }
  129. LLCtrlListInterface *list = self->childGetListInterface("parcel list");
  130. if (!list) return;
  131. // If this is the first packet, clear out the "loading..." indicator
  132. if (!self->mFirstPacketReceived)
  133. {
  134. self->mFirstPacketReceived = TRUE;
  135. list->operateOnAll(LLCtrlSelectionInterface::OP_DELETE);
  136. }
  137. LLUUID owner_id;
  138. std::string name;
  139. std::string desc;
  140. S32 actual_area;
  141. S32 billable_area;
  142. U8 flags;
  143. F32 global_x;
  144. F32 global_y;
  145. std::string sim_name;
  146. std::string land_sku;
  147. std::string land_type;
  148. S32 i;
  149. S32 count = msg->getNumberOfBlocks("QueryData");
  150. for (i = 0; i < count; i++)
  151. {
  152. msg->getUUID("QueryData", "OwnerID", owner_id, i);
  153. msg->getString("QueryData", "Name", name, i);
  154. msg->getString("QueryData", "Desc", desc, i);
  155. msg->getS32("QueryData", "ActualArea", actual_area, i);
  156. msg->getS32("QueryData", "BillableArea", billable_area, i);
  157. msg->getU8("QueryData", "Flags", flags, i);
  158. msg->getF32("QueryData", "GlobalX", global_x, i);
  159. msg->getF32("QueryData", "GlobalY", global_y, i);
  160. msg->getString("QueryData", "SimName", sim_name, i);
  161. if ( msg->getSizeFast(_PREHASH_QueryData, i, _PREHASH_ProductSKU) > 0 )
  162. {
  163. msg->getStringFast( _PREHASH_QueryData, _PREHASH_ProductSKU, land_sku, i);
  164. llinfos << "Land sku: " << land_sku << llendl;
  165. land_type = LLProductInfoRequestManager::instance().getDescriptionForSku(land_sku);
  166. }
  167. else
  168. {
  169. land_sku.clear();
  170. land_type = LLTrans::getString("land_type_unknown");
  171. }
  172. if(owner_id.notNull())
  173. {
  174. self->mActualArea += actual_area;
  175. self->mBillableArea += billable_area;
  176. S32 region_x = llround(global_x) % REGION_WIDTH_UNITS;
  177. S32 region_y = llround(global_y) % REGION_WIDTH_UNITS;
  178. std::string location;
  179. location = llformat("%s (%d, %d)", sim_name.c_str(), region_x, region_y);
  180. std::string area;
  181. if(billable_area == actual_area)
  182. {
  183. area = llformat("%d", billable_area);
  184. }
  185. else
  186. {
  187. area = llformat("%d / %d", billable_area, actual_area);
  188. }
  189. std::string hidden;
  190. hidden = llformat("%f %f", global_x, global_y);
  191. LLSD element;
  192. element["columns"][0]["column"] = "name";
  193. element["columns"][0]["value"] = name;
  194. element["columns"][0]["font"] = "SANSSERIF";
  195. element["columns"][1]["column"] = "location";
  196. element["columns"][1]["value"] = location;
  197. element["columns"][1]["font"] = "SANSSERIF";
  198. element["columns"][2]["column"] = "area";
  199. element["columns"][2]["value"] = area;
  200. element["columns"][2]["font"] = "SANSSERIF";
  201. element["columns"][3]["column"] = "type";
  202. element["columns"][3]["value"] = land_type;
  203. element["columns"][3]["font"] = "SANSSERIF";
  204. // hidden is always last column
  205. element["columns"][4]["column"] = "hidden";
  206. element["columns"][4]["value"] = hidden;
  207. list->addElement(element);
  208. }
  209. }
  210. self->refreshAggregates();
  211. }
  212. void LLFloaterLandHoldings::buttonCore(S32 which)
  213. {
  214. LLScrollListCtrl *list = getChild<LLScrollListCtrl>("parcel list");
  215. if (!list) return;
  216. S32 index = list->getFirstSelectedIndex();
  217. if (index < 0) return;
  218. // hidden is always last column
  219. std::string location = list->getSelectedItemLabel(list->getNumColumns()-1);
  220. F32 global_x = 0.f;
  221. F32 global_y = 0.f;
  222. sscanf(location.c_str(), "%f %f", &global_x, &global_y);
  223. // Hack: Use the agent's z-height
  224. F64 global_z = gAgent.getPositionGlobal().mdV[VZ];
  225. LLVector3d pos_global(global_x, global_y, global_z);
  226. LLFloaterWorldMap* floater_world_map = LLFloaterWorldMap::getInstance();
  227. switch(which)
  228. {
  229. case 0:
  230. gAgent.teleportViaLocation(pos_global);
  231. if(floater_world_map) floater_world_map->trackLocation(pos_global);
  232. break;
  233. case 1:
  234. if(floater_world_map) floater_world_map->trackLocation(pos_global);
  235. LLFloaterReg::showInstance("world_map", "center");
  236. break;
  237. default:
  238. break;
  239. }
  240. }
  241. // static
  242. void LLFloaterLandHoldings::onClickTeleport(void* data)
  243. {
  244. LLFloaterLandHoldings* self = (LLFloaterLandHoldings*)data;
  245. self->buttonCore(0);
  246. self->closeFloater();
  247. }
  248. // static
  249. void LLFloaterLandHoldings::onClickMap(void* data)
  250. {
  251. LLFloaterLandHoldings* self = (LLFloaterLandHoldings*)data;
  252. self->buttonCore(1);
  253. }
  254. // static
  255. void LLFloaterLandHoldings::onGrantList(void* data)
  256. {
  257. LLFloaterLandHoldings* self = (LLFloaterLandHoldings*)data;
  258. LLCtrlSelectionInterface *list = self->childGetSelectionInterface("grant list");
  259. if (!list) return;
  260. LLUUID group_id = list->getCurrentID();
  261. if (group_id.notNull())
  262. {
  263. LLGroupActions::show(group_id);
  264. }
  265. }
  266. void LLFloaterLandHoldings::refreshAggregates()
  267. {
  268. S32 allowed_area = gStatusBar->getSquareMetersCredit();
  269. S32 current_area = gStatusBar->getSquareMetersCommitted();
  270. S32 available_area = gStatusBar->getSquareMetersLeft();
  271. getChild<LLUICtrl>("allowed_text")->setTextArg("[AREA]", llformat("%d",allowed_area));
  272. getChild<LLUICtrl>("current_text")->setTextArg("[AREA]", llformat("%d",current_area));
  273. getChild<LLUICtrl>("available_text")->setTextArg("[AREA]", llformat("%d",available_area));
  274. }