llpanelland.cpp

Go to the documentation of this file.
00001 
00032 #include "llviewerprecompiledheaders.h"
00033 
00034 #include "llpanelland.h"
00035 
00036 #include "llparcel.h"
00037 
00038 #include "llagent.h"
00039 #include "llbutton.h"
00040 #include "llfloaterland.h"
00041 #include "lltextbox.h"
00042 #include "llviewerparcelmgr.h"
00043 #include "llviewerregion.h"
00044 #include "roles_constants.h"
00045 
00046 #include "llvieweruictrlfactory.h"
00047 
00048 LLPanelLandSelectObserver* LLPanelLandInfo::sObserver = NULL;
00049 LLPanelLandInfo* LLPanelLandInfo::sInstance = NULL;
00050 
00051 class LLPanelLandSelectObserver : public LLParcelObserver
00052 {
00053 public:
00054         LLPanelLandSelectObserver() {}
00055         virtual ~LLPanelLandSelectObserver() {}
00056         virtual void changed() { LLPanelLandInfo::refreshAll(); }
00057 };
00058 
00059 
00060 BOOL    LLPanelLandInfo::postBuild()
00061 {
00062 
00063         childSetAction("button buy land",onClickClaim,this);
00064         childSetAction("button abandon land",onClickRelease,this);
00065         childSetAction("button subdivide land",onClickDivide,this);
00066         childSetAction("button join land",onClickJoin,this);
00067         childSetAction("button about land",onClickAbout,this);
00068 
00069         return TRUE;
00070 }
00071 //
00072 // Methods
00073 //
00074 LLPanelLandInfo::LLPanelLandInfo(const std::string& name)
00075 :       LLPanel(name)
00076 {
00077         if (!sInstance)
00078         {
00079                 sInstance = this;
00080         }
00081         if (!sObserver)
00082         {
00083                 sObserver = new LLPanelLandSelectObserver();
00084                 gParcelMgr->addObserver( sObserver );
00085         }
00086 
00087 }
00088 
00089 
00090 // virtual
00091 LLPanelLandInfo::~LLPanelLandInfo()
00092 {
00093         gParcelMgr->removeObserver( sObserver );
00094         delete sObserver;
00095         sObserver = NULL;
00096 
00097         sInstance = NULL;
00098 }
00099 
00100 
00101 // static
00102 void LLPanelLandInfo::refreshAll()
00103 {
00104         if (sInstance)
00105         {
00106                 sInstance->refresh();
00107         }
00108 }
00109 
00110 
00111 // public
00112 void LLPanelLandInfo::refresh()
00113 {
00114         LLParcel *parcel = gParcelMgr->getParcelSelection()->getParcel();
00115         LLViewerRegion *regionp = gParcelMgr->getSelectionRegion();
00116 
00117         if (!parcel || !regionp)
00118         {
00119                 // nothing selected, disable panel
00120                 childSetVisible("label_area_price",false);
00121                 childSetVisible("label_area",false);
00122 
00123                 //mTextPrice->setText(LLString::null);
00124                 childSetText("textbox price",LLString::null);
00125 
00126                 childSetEnabled("button buy land",FALSE);
00127                 childSetEnabled("button abandon land",FALSE);
00128                 childSetEnabled("button subdivide land",FALSE);
00129                 childSetEnabled("button join land",FALSE);
00130                 childSetEnabled("button about land",FALSE);
00131         }
00132         else
00133         {
00134                 // something selected, hooray!
00135                 const LLUUID& owner_id = parcel->getOwnerID();
00136                 const LLUUID& auth_buyer_id = parcel->getAuthorizedBuyerID();
00137 
00138                 BOOL is_public = parcel->isPublic();
00139                 BOOL is_for_sale = parcel->getForSale()
00140                         && ((parcel->getSalePrice() > 0) || (auth_buyer_id.notNull()));
00141                 BOOL can_buy = (is_for_sale
00142                                                 && (owner_id != gAgent.getID())
00143                                                 && ((gAgent.getID() == auth_buyer_id)
00144                                                         || (auth_buyer_id.isNull())));
00145                         
00146                 if (is_public)
00147                 {
00148                         childSetEnabled("button buy land",TRUE);
00149                 }
00150                 else
00151                 {
00152                         childSetEnabled("button buy land",can_buy);
00153                 }
00154 
00155                 BOOL owner_release = LLViewerParcelMgr::isParcelOwnedByAgent(parcel, GP_LAND_RELEASE);
00156                 BOOL owner_divide =  LLViewerParcelMgr::isParcelOwnedByAgent(parcel, GP_LAND_DIVIDE_JOIN);
00157 
00158                 BOOL manager_releaseable = ( gAgent.canManageEstate()
00159                                                                   && (parcel->getOwnerID() == regionp->getOwner()) );
00160                 
00161                 BOOL manager_divideable = ( gAgent.canManageEstate()
00162                                                                 && ((parcel->getOwnerID() == regionp->getOwner()) || owner_divide) );
00163 
00164                 childSetEnabled("button abandon land",owner_release || manager_releaseable || gAgent.isGodlike());
00165 
00166                 // only mainland sims are subdividable by owner
00167                 if (regionp->getRegionFlags() && REGION_FLAGS_ALLOW_PARCEL_CHANGES)
00168                 {
00169                         childSetEnabled("button subdivide land",owner_divide || manager_divideable || gAgent.isGodlike());
00170                 }
00171                 else
00172                 {
00173                         childSetEnabled("button subdivide land",manager_divideable || gAgent.isGodlike());
00174                 }
00175                 
00176                 // To join land, must have something selected,
00177                 // not just a single unit of land,
00178                 // you must own part of it,
00179                 // and it must not be a whole parcel.
00180                 if (gParcelMgr->getSelectedArea() > PARCEL_UNIT_AREA
00181                         //&& gParcelMgr->getSelfCount() > 1
00182                         && !gParcelMgr->getParcelSelection()->getWholeParcelSelected())
00183                 {
00184                         childSetEnabled("button join land",TRUE);
00185                 }
00186                 else
00187                 {
00188                         lldebugs << "Invalid selection for joining land" << llendl;
00189                         childSetEnabled("button join land",FALSE);
00190                 }
00191 
00192                 childSetEnabled("button about land",TRUE);
00193 
00194                 // show pricing information
00195                 S32 area;
00196                 S32 claim_price;
00197                 S32 rent_price;
00198                 BOOL for_sale;
00199                 F32 dwell;
00200                 gParcelMgr->getDisplayInfo(&area,
00201                                                                    &claim_price,
00202                                                                    &rent_price,
00203                                                                    &for_sale,
00204                                                                    &dwell);
00205                 if(is_public || (is_for_sale && gParcelMgr->getParcelSelection()->getWholeParcelSelected()))
00206                 {
00207                         childSetTextArg("label_area_price","[PRICE]", llformat("%d",claim_price));
00208                         childSetTextArg("label_area_price","[AREA]", llformat("%d",area));
00209                         childSetVisible("label_area_price",true);
00210                         childSetVisible("label_area",false);
00211                 }
00212                 else
00213                 {
00214                         childSetVisible("label_area_price",false);
00215                         childSetTextArg("label_area","[AREA]", llformat("%d",area));
00216                         childSetVisible("label_area",true);
00217                 }
00218         }
00219 }
00220 
00221 
00222 //static
00223 void LLPanelLandInfo::onClickClaim(void*)
00224 {
00225         gParcelMgr->startBuyLand();
00226 }
00227 
00228 
00229 //static
00230 void LLPanelLandInfo::onClickRelease(void*)
00231 {
00232         gParcelMgr->startReleaseLand();
00233 }
00234 
00235 // static
00236 void LLPanelLandInfo::onClickDivide(void*)
00237 {
00238         gParcelMgr->startDivideLand();
00239 }
00240 
00241 // static
00242 void LLPanelLandInfo::onClickJoin(void*)
00243 {
00244         gParcelMgr->startJoinLand();
00245 }
00246 
00247 //static
00248 void LLPanelLandInfo::onClickAbout(void*)
00249 {
00250         // Promote the rectangle selection to a parcel selection
00251         if (!gParcelMgr->getParcelSelection()->getWholeParcelSelected())
00252         {
00253                 gParcelMgr->selectParcelInRectangle();
00254         }
00255 
00256         LLFloaterLand::show();
00257 }

Generated on Thu Jul 1 06:08:58 2010 for Second Life Viewer by  doxygen 1.4.7