PageRenderTime 296ms CodeModel.GetById 111ms app.highlight 85ms RepoModel.GetById 96ms app.codeStats 0ms

/indra/newview/llpanelland.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 259 lines | 172 code | 40 blank | 47 comment | 31 complexity | b6f34352ba056eaf001520d43f5ecf18 MD5 | raw file
  1/** 
  2 * @file llpanelland.cpp
  3 * @brief Land information in the tool floater, NOT the "About Land" floater
  4 *
  5 * $LicenseInfo:firstyear=2002&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 "llpanelland.h"
 30
 31#include "llparcel.h"
 32
 33#include "llagent.h"
 34#include "llbutton.h"
 35#include "llcheckboxctrl.h"
 36#include "llfloaterland.h"
 37#include "llfloaterreg.h"
 38#include "lltextbox.h"
 39#include "llviewercontrol.h"
 40#include "llviewerparcelmgr.h"
 41#include "llviewerregion.h"
 42#include "llviewerwindow.h"
 43#include "roles_constants.h"
 44
 45#include "lluictrlfactory.h"
 46
 47LLPanelLandSelectObserver* LLPanelLandInfo::sObserver = NULL;
 48LLPanelLandInfo* LLPanelLandInfo::sInstance = NULL;
 49
 50class LLPanelLandSelectObserver : public LLParcelObserver
 51{
 52public:
 53	LLPanelLandSelectObserver() {}
 54	virtual ~LLPanelLandSelectObserver() {}
 55	virtual void changed() { LLPanelLandInfo::refreshAll(); }
 56};
 57
 58
 59BOOL	LLPanelLandInfo::postBuild()
 60{
 61	childSetAction("button buy land",boost::bind(onClickClaim));
 62	childSetAction("button abandon land", boost::bind(onClickRelease));
 63	childSetAction("button subdivide land", boost::bind(onClickDivide));
 64	childSetAction("button join land", boost::bind(onClickJoin));
 65	childSetAction("button about land", boost::bind(onClickAbout));
 66
 67	mCheckShowOwners = getChild<LLCheckBoxCtrl>("checkbox show owners");
 68	getChild<LLUICtrl>("checkbox show owners")->setValue(gSavedSettings.getBOOL("ShowParcelOwners"));
 69
 70	return TRUE;
 71}
 72//
 73// Methods
 74//
 75LLPanelLandInfo::LLPanelLandInfo()
 76:	LLPanel(),
 77	mCheckShowOwners(NULL)
 78{
 79	if (!sInstance)
 80	{
 81		sInstance = this;
 82	}
 83	if (!sObserver)
 84	{
 85		sObserver = new LLPanelLandSelectObserver();
 86		LLViewerParcelMgr::getInstance()->addObserver( sObserver );
 87	}
 88
 89}
 90
 91
 92// virtual
 93LLPanelLandInfo::~LLPanelLandInfo()
 94{
 95	LLViewerParcelMgr::getInstance()->removeObserver( sObserver );
 96	delete sObserver;
 97	sObserver = NULL;
 98
 99	sInstance = NULL;
100}
101
102
103// static
104void LLPanelLandInfo::refreshAll()
105{
106	if (sInstance)
107	{
108		sInstance->refresh();
109	}
110}
111
112
113// public
114void LLPanelLandInfo::refresh()
115{
116	LLParcel *parcel = LLViewerParcelMgr::getInstance()->getParcelSelection()->getParcel();
117	LLViewerRegion *regionp = LLViewerParcelMgr::getInstance()->getSelectionRegion();
118
119	if (!parcel || !regionp)
120	{
121		// nothing selected, disable panel
122		getChildView("label_area_price")->setVisible(false);
123		getChildView("label_area")->setVisible(false);
124
125		//mTextPrice->setText(LLStringUtil::null);
126		getChild<LLUICtrl>("textbox price")->setValue(LLStringUtil::null);
127
128		getChildView("button buy land")->setEnabled(FALSE);
129		getChildView("button abandon land")->setEnabled(FALSE);
130		getChildView("button subdivide land")->setEnabled(FALSE);
131		getChildView("button join land")->setEnabled(FALSE);
132		getChildView("button about land")->setEnabled(FALSE);
133	}
134	else
135	{
136		// something selected, hooray!
137		const LLUUID& owner_id = parcel->getOwnerID();
138		const LLUUID& auth_buyer_id = parcel->getAuthorizedBuyerID();
139
140		BOOL is_public = parcel->isPublic();
141		BOOL is_for_sale = parcel->getForSale()
142			&& ((parcel->getSalePrice() > 0) || (auth_buyer_id.notNull()));
143		BOOL can_buy = (is_for_sale
144						&& (owner_id != gAgent.getID())
145						&& ((gAgent.getID() == auth_buyer_id)
146							|| (auth_buyer_id.isNull())));
147			
148		if (is_public)
149		{
150			getChildView("button buy land")->setEnabled(TRUE);
151		}
152		else
153		{
154			getChildView("button buy land")->setEnabled(can_buy);
155		}
156
157		BOOL owner_release = LLViewerParcelMgr::isParcelOwnedByAgent(parcel, GP_LAND_RELEASE);
158		BOOL owner_divide =  LLViewerParcelMgr::isParcelOwnedByAgent(parcel, GP_LAND_DIVIDE_JOIN);
159
160		BOOL manager_releaseable = ( gAgent.canManageEstate()
161								  && (parcel->getOwnerID() == regionp->getOwner()) );
162		
163		BOOL manager_divideable = ( gAgent.canManageEstate()
164								&& ((parcel->getOwnerID() == regionp->getOwner()) || owner_divide) );
165
166		getChildView("button abandon land")->setEnabled(owner_release || manager_releaseable || gAgent.isGodlike());
167
168		// only mainland sims are subdividable by owner
169		if (regionp->getRegionFlags() && REGION_FLAGS_ALLOW_PARCEL_CHANGES)
170		{
171			getChildView("button subdivide land")->setEnabled(owner_divide || manager_divideable || gAgent.isGodlike());
172		}
173		else
174		{
175			getChildView("button subdivide land")->setEnabled(manager_divideable || gAgent.isGodlike());
176		}
177		
178		// To join land, must have something selected,
179		// not just a single unit of land,
180		// you must own part of it,
181		// and it must not be a whole parcel.
182		if (LLViewerParcelMgr::getInstance()->getSelectedArea() > PARCEL_UNIT_AREA
183			//&& LLViewerParcelMgr::getInstance()->getSelfCount() > 1
184			&& !LLViewerParcelMgr::getInstance()->getParcelSelection()->getWholeParcelSelected())
185		{
186			getChildView("button join land")->setEnabled(TRUE);
187		}
188		else
189		{
190			lldebugs << "Invalid selection for joining land" << llendl;
191			getChildView("button join land")->setEnabled(FALSE);
192		}
193
194		getChildView("button about land")->setEnabled(TRUE);
195
196		// show pricing information
197		S32 area;
198		S32 claim_price;
199		S32 rent_price;
200		BOOL for_sale;
201		F32 dwell;
202		LLViewerParcelMgr::getInstance()->getDisplayInfo(&area,
203								   &claim_price,
204								   &rent_price,
205								   &for_sale,
206								   &dwell);
207		if(is_public || (is_for_sale && LLViewerParcelMgr::getInstance()->getParcelSelection()->getWholeParcelSelected()))
208		{
209			getChild<LLUICtrl>("label_area_price")->setTextArg("[PRICE]", llformat("%d",claim_price));
210			getChild<LLUICtrl>("label_area_price")->setTextArg("[AREA]", llformat("%d",area));
211			getChildView("label_area_price")->setVisible(true);
212			getChildView("label_area")->setVisible(false);
213		}
214		else
215		{
216			getChildView("label_area_price")->setVisible(false);
217			getChild<LLUICtrl>("label_area")->setTextArg("[AREA]", llformat("%d",area));
218			getChildView("label_area")->setVisible(true);
219		}
220	}
221}
222
223
224//static
225void LLPanelLandInfo::onClickClaim()
226{
227	LLViewerParcelMgr::getInstance()->startBuyLand();
228}
229
230
231//static
232void LLPanelLandInfo::onClickRelease()
233{
234	LLViewerParcelMgr::getInstance()->startReleaseLand();
235}
236
237// static
238void LLPanelLandInfo::onClickDivide()
239{
240	LLViewerParcelMgr::getInstance()->startDivideLand();
241}
242
243// static
244void LLPanelLandInfo::onClickJoin()
245{
246	LLViewerParcelMgr::getInstance()->startJoinLand();
247}
248
249//static
250void LLPanelLandInfo::onClickAbout()
251{
252	// Promote the rectangle selection to a parcel selection
253	if (!LLViewerParcelMgr::getInstance()->getParcelSelection()->getWholeParcelSelected())
254	{
255		LLViewerParcelMgr::getInstance()->selectParcelInRectangle();
256	}
257
258	LLFloaterReg::showInstance("about_land");
259}