llpanelplace.cpp

Go to the documentation of this file.
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 "lluictrlfactory.h"
00056 //#include "llviewermenu.h"     // create_landmark()
00057 #include "llweb.h"
00058 #include "llsdutil.h"
00059 
00060 //static
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         // Since this is only used in the directory browser, always
00086         // disable the snapshot control. Otherwise clicking on it will
00087         // open a texture picker.
00088         mSnapshotCtrl = getChild<LLTextureCtrl>("snapshot_ctrl");
00089         mSnapshotCtrl->setEnabled(FALSE);
00090 
00091     mNameEditor = getChild<LLTextBox>("name_editor");
00092         // Text boxes appear to have a " " in them by default.  This breaks the
00093         // emptiness test for filling in data from the network.  Slam to empty.
00094         mNameEditor->setText( LLString::null );
00095 
00096     mDescEditor = getChild<LLTextEditor>("desc_editor");
00097 
00098         mInfoEditor = getChild<LLTextBox>("info_editor");
00099 
00100     mLocationEditor = getChild<LLTextBox>("location_editor");
00101 
00102         mTeleportBtn = getChild<LLButton>( "teleport_btn");
00103         mTeleportBtn->setClickedCallback(onClickTeleport);
00104         mTeleportBtn->setCallbackUserData(this);
00105 
00106         mMapBtn = getChild<LLButton>( "map_btn");
00107         mMapBtn->setClickedCallback(onClickMap);
00108         mMapBtn->setCallbackUserData(this);
00109 
00110         //mLandmarkBtn = getChild<LLButton>( "landmark_btn");
00111         //mLandmarkBtn->setClickedCallback(onClickLandmark);
00112         //mLandmarkBtn->setCallbackUserData(this);
00113 
00114         mAuctionBtn = getChild<LLButton>( "auction_btn");
00115         mAuctionBtn->setClickedCallback(onClickAuction);
00116         mAuctionBtn->setCallbackUserData(this);
00117 
00118         // Default to no auction button.  We'll show it if we get an auction id
00119         mAuctionBtn->setVisible(FALSE);
00120 
00121         // Temporary text to explain why the description panel is blank.
00122         // mDescEditor->setText("Parcel information not available without server update");
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 // Use this for search directory clicks, because we are totally
00134 // recycling the panel and don't need to use what's there.
00135 //
00136 // For SLURL clicks, don't call this, because we need to cache
00137 // the location info from the user.
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         // We only really handle 404 and 499 errors
00190         LLString error_text;
00191         if(status == 404)
00192         {       
00193                 error_text = getString("server_error_text");
00194         }
00195         else if(status == 499)
00196         {
00197                 error_text = getString("server_forbidden_text");
00198         }
00199         mDescEditor->setText(error_text);
00200 }
00201 
00202 //static 
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];               /*Flawfinder: ignore*/
00209         char    desc[MAX_STRING];               /*Flawfinder: ignore*/
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];           /*Flawfinder: ignore*/
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         // look up all panels which have this avatar
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                 // Only assign the name and description if they are not empty and there is not a 
00258                 // value present (passed in from a landmark, e.g.)
00259                 std::string name_str(name);
00260                 std::string desc_str(desc);
00261 
00262                 if( !name_str.empty()
00263                    && self->mNameEditor && self->mNameEditor->getText().empty())
00264                 {
00265                         self->mNameEditor->setText(name_str);
00266                 }
00267 
00268                 if( !desc_str.empty()
00269                         && self->mDescEditor && 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                 if (self->mInfoEditor)
00294                 {
00295                         self->mInfoEditor->setText(info_text);
00296                 }
00297 
00298                 // HACK: Flag 0x1 == mature region, otherwise assume PG
00299                 const char* rating = LLViewerRegion::accessToString(SIM_ACCESS_PG);
00300                 if (flags & 0x1)
00301                 {
00302                         rating = LLViewerRegion::accessToString(SIM_ACCESS_MATURE);
00303                 }
00304 
00305                 // Just use given region position for display
00306                 S32 region_x = llround(self->mPosRegion.mV[0]);
00307                 S32 region_y = llround(self->mPosRegion.mV[1]);
00308                 S32 region_z = llround(self->mPosRegion.mV[2]);
00309 
00310                 // If the region position is zero, grab position from the global
00311                 if(self->mPosRegion.isExactlyZero())
00312                 {
00313                         region_x = llround(global_x) % REGION_WIDTH_UNITS;
00314                         region_y = llround(global_y) % REGION_WIDTH_UNITS;
00315                         region_z = llround(global_z);
00316                 }
00317 
00318                 if(self->mPosGlobal.isExactlyZero())
00319                 {
00320                         self->mPosGlobal.setVec(global_x, global_y, global_z);
00321                 }
00322 
00323                 LLString location = llformat("%s %d, %d, %d (%s)",
00324                         sim_name, region_x, region_y, region_z, rating);
00325                 if (self->mLocationEditor)
00326                 {
00327                         self->mLocationEditor->setText(location);
00328                 }
00329 
00330                 BOOL show_auction = (auction_id > 0);
00331                 self->mAuctionBtn->setVisible(show_auction);
00332         }
00333 }
00334 
00335 
00336 void LLPanelPlace::displayParcelInfo(const LLVector3& pos_region,
00337                                                                          const LLUUID& landmark_asset_id,
00338                                                                          const LLUUID& region_id,
00339                                                                          const LLVector3d& pos_global)
00340 {
00341         LLSD body;
00342         mPosRegion = pos_region;
00343         mPosGlobal = pos_global;
00344         mLandmarkAssetID = landmark_asset_id;
00345         std::string url = gAgent.getRegion()->getCapability("RemoteParcelRequest");
00346         if (!url.empty())
00347         {
00348                 body["location"] = ll_sd_from_vector3(pos_region);
00349                 if (!region_id.isNull())
00350                 {
00351                         body["region_id"] = region_id;
00352                 }
00353                 if (!pos_global.isExactlyZero())
00354                 {
00355                         U64 region_handle = to_region_handle(pos_global);
00356                         body["region_handle"] = ll_sd_from_U64(region_handle);
00357                 }
00358                 LLHTTPClient::post(url, body, new LLRemoteParcelRequestResponder(this->getHandle()));
00359         }
00360         else
00361         {
00362                 mDescEditor->setText(getString("server_update_text"));
00363         }
00364         mSnapshotCtrl->setImageAssetID(LLUUID::null);
00365 }
00366 
00367 
00368 // static
00369 void LLPanelPlace::onClickTeleport(void* data)
00370 {
00371         LLPanelPlace* self = (LLPanelPlace*)data;
00372 
00373         LLView* parent_viewp = self->getParent();
00374         LLFloater* parent_floaterp = dynamic_cast<LLFloater*>(parent_viewp);
00375         if (parent_floaterp)
00376         {
00377                 parent_floaterp->close();
00378         }
00379         // LLFloater* parent_floaterp = (LLFloater*)self->getParent();
00380         parent_viewp->setVisible(false);
00381         if(self->mLandmarkAssetID.notNull())
00382         {
00383                 gAgent.teleportViaLandmark(self->mLandmarkAssetID);
00384                 gFloaterWorldMap->trackLandmark(self->mLandmarkAssetID);
00385 
00386         }
00387         else if (!self->mPosGlobal.isExactlyZero())
00388         {
00389                 gAgent.teleportViaLocation(self->mPosGlobal);
00390                 gFloaterWorldMap->trackLocation(self->mPosGlobal);
00391         }
00392 }
00393 
00394 // static
00395 void LLPanelPlace::onClickMap(void* data)
00396 {
00397         LLPanelPlace* self = (LLPanelPlace*)data;
00398         if (!self->mPosGlobal.isExactlyZero())
00399         {
00400                 gFloaterWorldMap->trackLocation(self->mPosGlobal);
00401                 LLFloaterWorldMap::show(NULL, TRUE);
00402         }
00403 }
00404 
00405 // static
00406 /*
00407 void LLPanelPlace::onClickLandmark(void* data)
00408 {
00409         LLPanelPlace* self = (LLPanelPlace*)data;
00410 
00411         create_landmark(self->mNameEditor->getText(), "", self->mPosGlobal);
00412 }
00413 */
00414 
00415 
00416 // static
00417 void LLPanelPlace::onClickAuction(void* data)
00418 {
00419         LLPanelPlace* self = (LLPanelPlace*)data;
00420 
00421         gViewerWindow->alertXml("GoToAuctionPage",
00422                 callbackAuctionWebPage, 
00423                 self);
00424 }
00425 
00426 // static
00427 void LLPanelPlace::callbackAuctionWebPage(S32 option, void* data)
00428 {
00429         LLPanelPlace* self = (LLPanelPlace*)data;
00430 
00431         if (0 == option)
00432         {
00433                 char url[256];          /*Flawfinder: ignore*/
00434                 snprintf(url, sizeof(url), "%s%010d", AUCTION_URL, self->mAuctionID);                   /* Flawfinder: ignore */
00435 
00436                 llinfos << "Loading auction page " << url << llendl;
00437 
00438                 LLWeb::loadURL(url);
00439         }
00440 }

Generated on Fri May 16 08:33:55 2008 for SecondLife by  doxygen 1.5.5