00001
00032 #include "llviewerprecompiledheaders.h"
00033
00034 #include "llpanelplace.h"
00035
00036 #include "llviewercontrol.h"
00037 #include "llqueryflags.h"
00038 #include "message.h"
00039 #include "llui.h"
00040 #include "llsecondlifeurls.h"
00041 #include "llremoteparcelrequest.h"
00042 #include "llfloater.h"
00043
00044 #include "llagent.h"
00045 #include "llviewerwindow.h"
00046 #include "llbutton.h"
00047 #include "llfloaterworldmap.h"
00048 #include "lllineeditor.h"
00049 #include "lluiconstants.h"
00050 #include "lltextbox.h"
00051 #include "llviewertexteditor.h"
00052 #include "lltexturectrl.h"
00053 #include "llworldmap.h"
00054 #include "llviewerregion.h"
00055 #include "llvieweruictrlfactory.h"
00056
00057 #include "llweb.h"
00058 #include "llsdutil.h"
00059
00060
00061 std::list<LLPanelPlace*> LLPanelPlace::sAllPanels;
00062
00063 LLPanelPlace::LLPanelPlace()
00064 : LLPanel("Places Panel"),
00065 mParcelID(),
00066 mRequestedID(),
00067 mRegionID(),
00068 mPosGlobal(),
00069 mPosRegion(),
00070 mAuctionID(0),
00071 mLandmarkAssetID()
00072 {
00073 sAllPanels.push_back(this);
00074 }
00075
00076
00077 LLPanelPlace::~LLPanelPlace()
00078 {
00079 sAllPanels.remove(this);
00080 }
00081
00082
00083 BOOL LLPanelPlace::postBuild()
00084 {
00085
00086
00087
00088 mSnapshotCtrl = LLViewerUICtrlFactory::getTexturePickerByName(this, "snapshot_ctrl");
00089 mSnapshotCtrl->setEnabled(FALSE);
00090
00091 mNameEditor = LLViewerUICtrlFactory::getTextBoxByName(this, "name_editor");
00092
00093
00094 mNameEditor->setText( LLString::null );
00095
00096 mDescEditor = LLUICtrlFactory::getTextEditorByName(this, "desc_editor");
00097
00098 mInfoEditor = LLViewerUICtrlFactory::getTextBoxByName(this, "info_editor");
00099
00100 mLocationEditor = LLViewerUICtrlFactory::getTextBoxByName(this, "location_editor");
00101
00102 mTeleportBtn = LLViewerUICtrlFactory::getButtonByName(this, "teleport_btn");
00103 mTeleportBtn->setClickedCallback(onClickTeleport);
00104 mTeleportBtn->setCallbackUserData(this);
00105
00106 mMapBtn = LLViewerUICtrlFactory::getButtonByName(this, "map_btn");
00107 mMapBtn->setClickedCallback(onClickMap);
00108 mMapBtn->setCallbackUserData(this);
00109
00110
00111
00112
00113
00114 mAuctionBtn = LLViewerUICtrlFactory::getButtonByName(this, "auction_btn");
00115 mAuctionBtn->setClickedCallback(onClickAuction);
00116 mAuctionBtn->setCallbackUserData(this);
00117
00118
00119 mAuctionBtn->setVisible(FALSE);
00120
00121
00122
00123
00124 return TRUE;
00125 }
00126
00127 void LLPanelPlace::displayItemInfo(const LLInventoryItem* pItem)
00128 {
00129 mNameEditor->setText(pItem->getName());
00130 mDescEditor->setText(pItem->getDescription());
00131 }
00132
00133
00134
00135
00136
00137
00138 void LLPanelPlace::resetLocation()
00139 {
00140 mParcelID.setNull();
00141 mRequestedID.setNull();
00142 mRegionID.setNull();
00143 mLandmarkAssetID.setNull();
00144 mPosGlobal.clearVec();
00145 mPosRegion.clearVec();
00146 mAuctionID = 0;
00147 mNameEditor->setText( LLString::null );
00148 mDescEditor->setText( LLString::null );
00149 mInfoEditor->setText( LLString::null );
00150 mLocationEditor->setText( LLString::null );
00151 }
00152
00153 void LLPanelPlace::setParcelID(const LLUUID& parcel_id)
00154 {
00155 mParcelID = parcel_id;
00156 sendParcelInfoRequest();
00157 }
00158
00159 void LLPanelPlace::setSnapshot(const LLUUID& snapshot_id)
00160 {
00161 mSnapshotCtrl->setImageAssetID(snapshot_id);
00162 }
00163
00164
00165 void LLPanelPlace::setLocationString(const std::string& location)
00166 {
00167 mLocationEditor->setText(location);
00168 }
00169
00170 void LLPanelPlace::sendParcelInfoRequest()
00171 {
00172 LLMessageSystem *msg = gMessageSystem;
00173
00174 if (mParcelID != mRequestedID)
00175 {
00176 msg->newMessage("ParcelInfoRequest");
00177 msg->nextBlockFast(_PREHASH_AgentData);
00178 msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
00179 msg->addUUID("SessionID", gAgent.getSessionID());
00180 msg->nextBlock("Data");
00181 msg->addUUID("ParcelID", mParcelID);
00182 gAgent.sendReliableMessage();
00183 mRequestedID = mParcelID;
00184 }
00185 }
00186
00187 void LLPanelPlace::setErrorStatus(U32 status, const std::string& reason)
00188 {
00189
00190 LLString error_text;
00191 if(status == 404)
00192 {
00193 error_text = childGetText("server_error_text");
00194 }
00195 else if(status == 499)
00196 {
00197 error_text = childGetText("server_forbidden_text");
00198 }
00199 mDescEditor->setText(error_text);
00200 }
00201
00202
00203 void LLPanelPlace::processParcelInfoReply(LLMessageSystem *msg, void **)
00204 {
00205 LLUUID agent_id;
00206 LLUUID parcel_id;
00207 LLUUID owner_id;
00208 char name[MAX_STRING];
00209 char desc[MAX_STRING];
00210 S32 actual_area;
00211 S32 billable_area;
00212 U8 flags;
00213 F32 global_x;
00214 F32 global_y;
00215 F32 global_z;
00216 char sim_name[MAX_STRING];
00217 LLUUID snapshot_id;
00218 F32 dwell;
00219 S32 sale_price;
00220 S32 auction_id;
00221
00222 msg->getUUID("AgentData", "AgentID", agent_id );
00223 msg->getUUID("Data", "ParcelID", parcel_id);
00224
00225
00226 for (panel_list_t::iterator iter = sAllPanels.begin(); iter != sAllPanels.end(); ++iter)
00227 {
00228 LLPanelPlace* self = *iter;
00229 if (self->mParcelID != parcel_id)
00230 {
00231 continue;
00232 }
00233
00234 msg->getUUID ("Data", "OwnerID", owner_id);
00235 msg->getString ("Data", "Name", MAX_STRING, name);
00236 msg->getString ("Data", "Desc", MAX_STRING, desc);
00237 msg->getS32 ("Data", "ActualArea", actual_area);
00238 msg->getS32 ("Data", "BillableArea", billable_area);
00239 msg->getU8 ("Data", "Flags", flags);
00240 msg->getF32 ("Data", "GlobalX", global_x);
00241 msg->getF32 ("Data", "GlobalY", global_y);
00242 msg->getF32 ("Data", "GlobalZ", global_z);
00243 msg->getString ("Data", "SimName", MAX_STRING, sim_name);
00244 msg->getUUID ("Data", "SnapshotID", snapshot_id);
00245 msg->getF32 ("Data", "Dwell", dwell);
00246 msg->getS32 ("Data", "SalePrice", sale_price);
00247 msg->getS32 ("Data", "AuctionID", auction_id);
00248
00249
00250 self->mAuctionID = auction_id;
00251
00252 if(snapshot_id.notNull())
00253 {
00254 self->mSnapshotCtrl->setImageAssetID(snapshot_id);
00255 }
00256
00257
00258
00259 std::string name_str(name);
00260 std::string desc_str(desc);
00261
00262 if( !name_str.empty()
00263 && self->mNameEditor->getText().empty())
00264 {
00265 self->mNameEditor->setText(name_str);
00266 }
00267
00268 if( !desc_str.empty()
00269 && self->mDescEditor->getText().empty())
00270 {
00271 self->mDescEditor->setText(desc_str);
00272 }
00273
00274 LLString info_text;
00275 LLUIString traffic = self->getUIString("traffic_text");
00276 traffic.setArg("[TRAFFIC]", llformat("%d ", (int)dwell));
00277 info_text = traffic;
00278 LLUIString area = self->getUIString("area_text");
00279 area.setArg("[AREA]", llformat("%d", actual_area));
00280 info_text += area;
00281 if (flags & DFQ_FOR_SALE)
00282 {
00283 LLUIString forsale = self->getUIString("forsale_text");
00284 forsale.setArg("[PRICE]", llformat("%d", sale_price));
00285 info_text += forsale;
00286 }
00287 if (auction_id != 0)
00288 {
00289 LLUIString auction = self->getUIString("auction_text");
00290 auction.setArg("[ID]", llformat("%010d ", auction_id));
00291 info_text += auction;
00292 }
00293 self->mInfoEditor->setText(info_text);
00294
00295
00296
00297 const char* rating = LLViewerRegion::accessToString(SIM_ACCESS_PG);
00298 if (flags & 0x1)
00299 {
00300 rating = LLViewerRegion::accessToString(SIM_ACCESS_MATURE);
00301 }
00302
00303
00304 S32 region_x = llround(self->mPosRegion.mV[0]);
00305 S32 region_y = llround(self->mPosRegion.mV[1]);
00306 S32 region_z = llround(self->mPosRegion.mV[2]);
00307
00308
00309 if(self->mPosRegion.isExactlyZero())
00310 {
00311 region_x = llround(global_x) % REGION_WIDTH_UNITS;
00312 region_y = llround(global_y) % REGION_WIDTH_UNITS;
00313 region_z = llround(global_z);
00314 }
00315
00316 if(self->mPosGlobal.isExactlyZero())
00317 {
00318 self->mPosGlobal.setVec(global_x, global_y, global_z);
00319 }
00320
00321 LLString location = llformat("%s %d, %d, %d (%s)",
00322 sim_name, region_x, region_y, region_z, rating);
00323 self->mLocationEditor->setText(location);
00324
00325 BOOL show_auction = (auction_id > 0);
00326 self->mAuctionBtn->setVisible(show_auction);
00327 }
00328 }
00329
00330
00331 void LLPanelPlace::displayParcelInfo(const LLVector3& pos_region,
00332 const LLUUID& landmark_asset_id,
00333 const LLUUID& region_id,
00334 const LLVector3d& pos_global)
00335 {
00336 LLSD body;
00337 mPosRegion = pos_region;
00338 mPosGlobal = pos_global;
00339 mLandmarkAssetID = landmark_asset_id;
00340 std::string url = gAgent.getRegion()->getCapability("RemoteParcelRequest");
00341 if (!url.empty())
00342 {
00343 body["location"] = ll_sd_from_vector3(pos_region);
00344 if (!region_id.isNull())
00345 {
00346 body["region_id"] = region_id;
00347 }
00348 if (!pos_global.isExactlyZero())
00349 {
00350 U64 region_handle = to_region_handle(pos_global);
00351 body["region_handle"] = ll_sd_from_U64(region_handle);
00352 }
00353 LLHTTPClient::post(url, body, new LLRemoteParcelRequestResponder(this->getHandle()));
00354 }
00355 else
00356 {
00357 mDescEditor->setText(childGetText("server_update_text"));
00358 }
00359 mSnapshotCtrl->setImageAssetID(LLUUID::null);
00360 }
00361
00362
00363
00364 void LLPanelPlace::onClickTeleport(void* data)
00365 {
00366 LLPanelPlace* self = (LLPanelPlace*)data;
00367
00368 LLView* parent_viewp = self->getParent();
00369 if (parent_viewp->getWidgetType() == WIDGET_TYPE_FLOATER)
00370 {
00371 LLFloater* parent_floaterp = (LLFloater*)parent_viewp;
00372 parent_floaterp->close();
00373 }
00374
00375 parent_viewp->setVisible(false);
00376 if(self->mLandmarkAssetID.notNull())
00377 {
00378 gAgent.teleportViaLandmark(self->mLandmarkAssetID);
00379 gFloaterWorldMap->trackLandmark(self->mLandmarkAssetID);
00380
00381 }
00382 else if (!self->mPosGlobal.isExactlyZero())
00383 {
00384 gAgent.teleportViaLocation(self->mPosGlobal);
00385 gFloaterWorldMap->trackLocation(self->mPosGlobal);
00386 }
00387 }
00388
00389
00390 void LLPanelPlace::onClickMap(void* data)
00391 {
00392 LLPanelPlace* self = (LLPanelPlace*)data;
00393 if (!self->mPosGlobal.isExactlyZero())
00394 {
00395 gFloaterWorldMap->trackLocation(self->mPosGlobal);
00396 LLFloaterWorldMap::show(NULL, TRUE);
00397 }
00398 }
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412 void LLPanelPlace::onClickAuction(void* data)
00413 {
00414 LLPanelPlace* self = (LLPanelPlace*)data;
00415
00416 gViewerWindow->alertXml("GoToAuctionPage",
00417 callbackAuctionWebPage,
00418 self);
00419 }
00420
00421
00422 void LLPanelPlace::callbackAuctionWebPage(S32 option, void* data)
00423 {
00424 LLPanelPlace* self = (LLPanelPlace*)data;
00425
00426 if (0 == option)
00427 {
00428 char url[256];
00429 snprintf(url, sizeof(url), "%s%010d", AUCTION_URL, self->mAuctionID);
00430
00431 llinfos << "Loading auction page " << url << llendl;
00432
00433 LLWeb::loadURL(url);
00434 }
00435 }