PageRenderTime 47ms CodeModel.GetById 19ms app.highlight 24ms RepoModel.GetById 1ms 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
  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
 27#include "llviewerprecompiledheaders.h"
 28
 29#include "llfloaterlandholdings.h"
 30
 31#include "indra_constants.h"
 32#include "llfontgl.h"
 33#include "llqueryflags.h"
 34#include "llparcel.h"
 35#include "message.h"
 36
 37#include "llagent.h"
 38#include "llfloaterreg.h"
 39#include "llfloaterworldmap.h"
 40#include "llproductinforequest.h"
 41#include "llscrolllistctrl.h"
 42#include "llstatusbar.h"
 43#include "lltextbox.h"
 44#include "llscrolllistctrl.h"
 45#include "llscrolllistitem.h"
 46#include "llscrolllistcell.h"
 47#include "lltrans.h"
 48#include "lluiconstants.h"
 49#include "llviewermessage.h"
 50#include "lluictrlfactory.h"
 51
 52#include "llgroupactions.h"
 53
 54// protected
 55LLFloaterLandHoldings::LLFloaterLandHoldings(const LLSD& key)
 56:	LLFloater(key),
 57	mActualArea(0),
 58	mBillableArea(0),
 59	mFirstPacketReceived(FALSE),
 60	mSortColumn(""),
 61	mSortAscending(TRUE)
 62{
 63}
 64
 65BOOL LLFloaterLandHoldings::postBuild()
 66{
 67	childSetAction("Teleport", onClickTeleport, this);
 68	childSetAction("Show on Map", onClickMap, this);
 69
 70	// Grant list
 71	LLScrollListCtrl* grant_list = getChild<LLScrollListCtrl>("grant list");
 72	grant_list->sortByColumnIndex(0, TRUE);
 73	grant_list->setDoubleClickCallback(onGrantList, this);
 74
 75	S32 count = gAgent.mGroups.count();
 76	for(S32 i = 0; i < count; ++i)
 77	{
 78		LLUUID id(gAgent.mGroups.get(i).mID);
 79
 80		LLSD element;
 81		element["id"] = id;
 82		element["columns"][0]["column"] = "group";
 83		element["columns"][0]["value"] = gAgent.mGroups.get(i).mName;
 84		element["columns"][0]["font"] = "SANSSERIF";
 85
 86		LLUIString areastr = getString("area_string");
 87		areastr.setArg("[AREA]", llformat("%d", gAgent.mGroups.get(i).mContribution));
 88		element["columns"][1]["column"] = "area";
 89		element["columns"][1]["value"] = areastr;
 90		element["columns"][1]["font"] = "SANSSERIF";
 91
 92		grant_list->addElement(element);
 93	}
 94	
 95	center();
 96	
 97	return TRUE;
 98}
 99
100
101// protected
102LLFloaterLandHoldings::~LLFloaterLandHoldings()
103{
104}
105
106void LLFloaterLandHoldings::onOpen(const LLSD& key)
107{
108	// query_id null is known to be us
109	const LLUUID& query_id = LLUUID::null;
110
111	// look only for parcels we own
112	U32 query_flags = DFQ_AGENT_OWNED;
113
114	send_places_query(query_id,
115					  LLUUID::null,
116					  "",
117					  query_flags,
118					  LLParcel::C_ANY,
119					  "");
120}
121
122void LLFloaterLandHoldings::draw()
123{
124	refresh();
125
126	LLFloater::draw();
127}
128
129
130// public
131void LLFloaterLandHoldings::refresh()
132{
133	LLCtrlSelectionInterface *list = childGetSelectionInterface("parcel list");
134	BOOL enable_btns = FALSE;
135	if (list && list->getFirstSelectedIndex()> -1)
136	{
137		enable_btns = TRUE;
138	}
139
140	getChildView("Teleport")->setEnabled(enable_btns);
141	getChildView("Show on Map")->setEnabled(enable_btns);
142
143	refreshAggregates();
144}
145
146
147// static
148void LLFloaterLandHoldings::processPlacesReply(LLMessageSystem* msg, void**)
149{
150	LLFloaterLandHoldings* self = LLFloaterReg::findTypedInstance<LLFloaterLandHoldings>("land_holdings");
151
152	// Is this packet from an old, closed window?
153	if (!self)
154	{
155		return;
156	}
157
158	LLCtrlListInterface *list = self->childGetListInterface("parcel list");
159	if (!list) return;
160
161	// If this is the first packet, clear out the "loading..." indicator
162	if (!self->mFirstPacketReceived)
163	{
164		self->mFirstPacketReceived = TRUE;
165		list->operateOnAll(LLCtrlSelectionInterface::OP_DELETE);
166	}
167
168	LLUUID	owner_id;
169	std::string	name;
170	std::string	desc;
171	S32		actual_area;
172	S32		billable_area;
173	U8		flags;
174	F32		global_x;
175	F32		global_y;
176	std::string	sim_name;
177	std::string land_sku;
178	std::string land_type;
179	
180	S32 i;
181	S32 count = msg->getNumberOfBlocks("QueryData");
182	for (i = 0; i < count; i++)
183	{
184		msg->getUUID("QueryData", "OwnerID", owner_id, i);
185		msg->getString("QueryData", "Name", name, i);
186		msg->getString("QueryData", "Desc", desc, i);
187		msg->getS32("QueryData", "ActualArea", actual_area, i);
188		msg->getS32("QueryData", "BillableArea", billable_area, i);
189		msg->getU8("QueryData", "Flags", flags, i);
190		msg->getF32("QueryData", "GlobalX", global_x, i);
191		msg->getF32("QueryData", "GlobalY", global_y, i);
192		msg->getString("QueryData", "SimName", sim_name, i);
193
194		if ( msg->getSizeFast(_PREHASH_QueryData, i, _PREHASH_ProductSKU) > 0 )
195		{
196			msg->getStringFast(	_PREHASH_QueryData, _PREHASH_ProductSKU, land_sku, i);
197			llinfos << "Land sku: " << land_sku << llendl;
198			land_type = LLProductInfoRequestManager::instance().getDescriptionForSku(land_sku);
199		}
200		else
201		{
202			land_sku.clear();
203			land_type = LLTrans::getString("land_type_unknown");
204		}
205		
206		if(owner_id.notNull())
207		{
208			self->mActualArea += actual_area;
209			self->mBillableArea += billable_area;
210
211			S32 region_x = llround(global_x) % REGION_WIDTH_UNITS;
212			S32 region_y = llround(global_y) % REGION_WIDTH_UNITS;
213
214			std::string location;
215			location = llformat("%s (%d, %d)", sim_name.c_str(), region_x, region_y);
216
217			std::string area;
218			if(billable_area == actual_area)
219			{
220				area = llformat("%d", billable_area);
221			}
222			else
223			{
224				area = llformat("%d / %d", billable_area, actual_area);
225			}
226			
227			std::string hidden;
228			hidden = llformat("%f %f", global_x, global_y);
229
230			LLSD element;
231			element["columns"][0]["column"] = "name";
232			element["columns"][0]["value"] = name;
233			element["columns"][0]["font"] = "SANSSERIF";
234			
235			element["columns"][1]["column"] = "location";
236			element["columns"][1]["value"] = location;
237			element["columns"][1]["font"] = "SANSSERIF";
238			
239			element["columns"][2]["column"] = "area";
240			element["columns"][2]["value"] = area;
241			element["columns"][2]["font"] = "SANSSERIF";
242			
243			element["columns"][3]["column"] = "type";
244			element["columns"][3]["value"] = land_type;
245			element["columns"][3]["font"] = "SANSSERIF";
246			
247			// hidden is always last column
248			element["columns"][4]["column"] = "hidden";
249			element["columns"][4]["value"] = hidden;
250
251			list->addElement(element);
252		}
253	}
254	
255	self->refreshAggregates();
256}
257
258void LLFloaterLandHoldings::buttonCore(S32 which)
259{
260	LLScrollListCtrl *list = getChild<LLScrollListCtrl>("parcel list");
261	if (!list) return;
262
263	S32 index = list->getFirstSelectedIndex();
264	if (index < 0) return;
265
266	// hidden is always last column
267	std::string location = list->getSelectedItemLabel(list->getNumColumns()-1);
268
269	F32 global_x = 0.f;
270	F32 global_y = 0.f;
271	sscanf(location.c_str(), "%f %f", &global_x, &global_y);
272
273	// Hack: Use the agent's z-height
274	F64 global_z = gAgent.getPositionGlobal().mdV[VZ];
275
276	LLVector3d pos_global(global_x, global_y, global_z);
277	LLFloaterWorldMap* floater_world_map = LLFloaterWorldMap::getInstance();
278
279	switch(which)
280	{
281	case 0:
282		gAgent.teleportViaLocation(pos_global);
283		if(floater_world_map) floater_world_map->trackLocation(pos_global);
284		break;
285	case 1:
286		if(floater_world_map) floater_world_map->trackLocation(pos_global);
287		LLFloaterReg::showInstance("world_map", "center");
288		break;
289	default:
290		break;
291	}
292}
293
294// static
295void LLFloaterLandHoldings::onClickTeleport(void* data)
296{
297	LLFloaterLandHoldings* self = (LLFloaterLandHoldings*)data;
298	self->buttonCore(0);
299	self->closeFloater();
300}
301
302
303// static
304void LLFloaterLandHoldings::onClickMap(void* data)
305{
306	LLFloaterLandHoldings* self = (LLFloaterLandHoldings*)data;
307	self->buttonCore(1);
308}
309
310// static
311void LLFloaterLandHoldings::onGrantList(void* data)
312{
313	LLFloaterLandHoldings* self = (LLFloaterLandHoldings*)data;
314	LLCtrlSelectionInterface *list = self->childGetSelectionInterface("grant list");
315	if (!list) return;
316	LLUUID group_id = list->getCurrentID();
317	if (group_id.notNull())
318	{
319		LLGroupActions::show(group_id);
320	}
321}
322
323void LLFloaterLandHoldings::refreshAggregates()
324{
325	S32 allowed_area = gStatusBar->getSquareMetersCredit();
326	S32 current_area = gStatusBar->getSquareMetersCommitted();
327	S32 available_area = gStatusBar->getSquareMetersLeft();
328
329	getChild<LLUICtrl>("allowed_text")->setTextArg("[AREA]", llformat("%d",allowed_area));
330	getChild<LLUICtrl>("current_text")->setTextArg("[AREA]", llformat("%d",current_area));
331	getChild<LLUICtrl>("available_text")->setTextArg("[AREA]", llformat("%d",available_area));
332}