llfloaterlandholdings.cpp

Go to the documentation of this file.
00001 
00032 #include "llviewerprecompiledheaders.h"
00033 
00034 #include "llfloaterlandholdings.h"
00035 
00036 #include "indra_constants.h"
00037 #include "llfontgl.h"
00038 #include "llqueryflags.h"
00039 #include "llparcel.h"
00040 #include "message.h"
00041 
00042 #include "llagent.h"
00043 #include "llfloatergroupinfo.h"
00044 #include "llfloaterworldmap.h"
00045 //#include "llinventoryview.h"  // for mOpenNextNewItem
00046 #include "llstatusbar.h"
00047 #include "lltextbox.h"
00048 #include "llscrolllistctrl.h"
00049 #include "llbutton.h"
00050 #include "lluiconstants.h"
00051 #include "llviewermessage.h"
00052 #include "llvieweruictrlfactory.h"
00053 
00054 // statics
00055 LLFloaterLandHoldings* LLFloaterLandHoldings::sInstance = NULL;
00056 
00057 
00058 // static
00059 void LLFloaterLandHoldings::show(void*)
00060 {
00061         LLFloaterLandHoldings* floater = new LLFloaterLandHoldings();
00062         gUICtrlFactory->buildFloater(floater, "floater_land_holdings.xml");
00063         floater->center();
00064 
00065         // query_id null is known to be us
00066         const LLUUID& query_id = LLUUID::null;
00067 
00068         // look only for parcels we own
00069         U32 query_flags = DFQ_AGENT_OWNED;
00070 
00071         send_places_query(query_id,
00072                                           LLUUID::null,
00073                                           "",
00074                                           query_flags,
00075                                           LLParcel::C_ANY,
00076                                           "");
00077 
00078         // TODO: request updated L$ balance?
00079         floater->open();                /* Flawfinder: ignore */
00080 }
00081 
00082 
00083 // protected
00084 LLFloaterLandHoldings::LLFloaterLandHoldings()
00085 :       LLFloater("land holdings floater"),
00086         mActualArea(0),
00087         mBillableArea(0),
00088         mFirstPacketReceived(FALSE),
00089         mSortColumn(""),
00090         mSortAscending(TRUE)
00091 {
00092         // Instance management.
00093         sInstance = this;
00094 }
00095 
00096 BOOL LLFloaterLandHoldings::postBuild()
00097 {
00098         childSetAction("Teleport", onClickTeleport, this);
00099         childSetAction("Show on Map", onClickMap, this);
00100 
00101         // Grant list
00102         childSetDoubleClickCallback("grant list", onGrantList);
00103         childSetUserData("grant list", this);
00104 
00105         LLCtrlListInterface *list = childGetListInterface("grant list");
00106         if (!list) return TRUE;
00107 
00108         S32 count = gAgent.mGroups.count();
00109         for(S32 i = 0; i < count; ++i)
00110         {
00111                 LLUUID id(gAgent.mGroups.get(i).mID);
00112 
00113                 LLSD element;
00114                 element["id"] = id;
00115                 element["columns"][0]["column"] = "group";
00116                 element["columns"][0]["value"] = gAgent.mGroups.get(i).mName;
00117                 element["columns"][0]["font"] = "SANSSERIF";
00118 
00119                 LLUIString areastr = getUIString("area_string");
00120                 areastr.setArg("[AREA]", llformat("%d", gAgent.mGroups.get(i).mContribution));
00121                 element["columns"][1]["column"] = "area";
00122                 element["columns"][1]["value"] = areastr;
00123                 element["columns"][1]["font"] = "SANSSERIF";
00124 
00125                 list->addElement(element, ADD_SORTED);
00126         }
00127 
00128         return TRUE;
00129 }
00130 
00131 
00132 // protected
00133 LLFloaterLandHoldings::~LLFloaterLandHoldings()
00134 {
00135         sInstance = NULL;
00136 }
00137 
00138 
00139 void LLFloaterLandHoldings::draw()
00140 {
00141         refresh();
00142 
00143         LLFloater::draw();
00144 }
00145 
00146 
00147 // public
00148 void LLFloaterLandHoldings::refresh()
00149 {
00150         LLCtrlSelectionInterface *list = childGetSelectionInterface("parcel list");
00151         BOOL enable_btns = FALSE;
00152         if (list && list->getFirstSelectedIndex()> -1)
00153         {
00154                 enable_btns = TRUE;
00155         }
00156 
00157         childSetEnabled("Teleport", enable_btns);
00158         childSetEnabled("Show on Map", enable_btns);
00159 
00160         refreshAggregates();
00161 }
00162 
00163 
00164 // static
00165 void LLFloaterLandHoldings::processPlacesReply(LLMessageSystem* msg, void**)
00166 {
00167         LLFloaterLandHoldings* self = sInstance;
00168 
00169         // Is this packet from an old, closed window?
00170         if (!self)
00171         {
00172                 return;
00173         }
00174 
00175         LLCtrlListInterface *list = self->childGetListInterface("parcel list");
00176         if (!list) return;
00177 
00178         // If this is the first packet, clear out the "loading..." indicator
00179         if (!self->mFirstPacketReceived)
00180         {
00181                 self->mFirstPacketReceived = TRUE;
00182                 list->operateOnAll(LLCtrlSelectionInterface::OP_DELETE);
00183         }
00184 
00185         LLUUID  owner_id;
00186         char    name[MAX_STRING];               /* Flawfinder: ignore */
00187         char    desc[MAX_STRING];               /* Flawfinder: ignore */
00188         S32             actual_area;
00189         S32             billable_area;
00190         U8              flags;
00191         F32             global_x;
00192         F32             global_y;
00193         char    sim_name[MAX_STRING];           /* Flawfinder: ignore */
00194 
00195         S32 i;
00196         S32 count = msg->getNumberOfBlocks("QueryData");
00197         for (i = 0; i < count; i++)
00198         {
00199                 msg->getUUID("QueryData", "OwnerID", owner_id, i);
00200                 msg->getString("QueryData", "Name", MAX_STRING, name, i);
00201                 msg->getString("QueryData", "Desc", MAX_STRING, desc, i);
00202                 msg->getS32("QueryData", "ActualArea", actual_area, i);
00203                 msg->getS32("QueryData", "BillableArea", billable_area, i);
00204                 msg->getU8("QueryData", "Flags", flags, i);
00205                 msg->getF32("QueryData", "GlobalX", global_x, i);
00206                 msg->getF32("QueryData", "GlobalY", global_y, i);
00207                 msg->getString("QueryData", "SimName", MAX_STRING, sim_name, i);
00208                 
00209                 self->mActualArea += actual_area;
00210                 self->mBillableArea += billable_area;
00211 
00212                 S32 region_x = llround(global_x) % REGION_WIDTH_UNITS;
00213                 S32 region_y = llround(global_y) % REGION_WIDTH_UNITS;
00214 
00215                 char location[MAX_STRING];              /* Flawfinder: ignore */
00216                 snprintf(location, MAX_STRING, "%s (%d, %d)", sim_name, region_x, region_y);                    /* Flawfinder: ignore */
00217 
00218                 char area[MAX_STRING];          /* Flawfinder: ignore */
00219                 if(billable_area == actual_area)
00220                 {
00221                         snprintf(area, MAX_STRING, "%d", billable_area);                        /* Flawfinder: ignore */
00222                 }
00223                 else
00224                 {
00225                         snprintf(area, MAX_STRING, "%d / %d", billable_area, actual_area);                      /* Flawfinder: ignore */
00226                 }
00227 
00228                 char hidden[MAX_STRING];                /* Flawfinder: ignore */
00229                 snprintf(hidden, MAX_STRING, "%f %f", global_x, global_y);                      /* Flawfinder: ignore */
00230 
00231                 LLSD element;
00232                 element["columns"][0]["column"] = "name";
00233                 element["columns"][0]["value"] = name;
00234                 element["columns"][0]["font"] = "SANSSERIF";
00235                 element["columns"][1]["column"] = "location";
00236                 element["columns"][1]["value"] = location;
00237                 element["columns"][1]["font"] = "SANSSERIF";
00238                 element["columns"][2]["column"] = "area";
00239                 element["columns"][2]["value"] = area;
00240                 element["columns"][2]["font"] = "SANSSERIF";
00241                 element["columns"][3]["column"] = "hidden";
00242                 element["columns"][3]["value"] = hidden;
00243                 element["columns"][3]["font"] = "SANSSERIF";
00244 
00245                 list->addElement(element);
00246         }
00247 
00248         self->refreshAggregates();
00249 }
00250 
00251 void LLFloaterLandHoldings::buttonCore(S32 which)
00252 {
00253         LLScrollListCtrl *list = LLUICtrlFactory::getScrollListByName(this, "parcel list");
00254         if (!list) return;
00255 
00256         S32 index = list->getFirstSelectedIndex();
00257         if (index < 0) return;
00258 
00259         LLString location = list->getSimpleSelectedItem(3);
00260 
00261         F32 global_x = 0.f;
00262         F32 global_y = 0.f;
00263         sscanf(location.c_str(), "%f %f", &global_x, &global_y);
00264 
00265         // Hack: Use the agent's z-height
00266         F64 global_z = gAgent.getPositionGlobal().mdV[VZ];
00267 
00268         LLVector3d pos_global(global_x, global_y, global_z);
00269 
00270         switch(which)
00271         {
00272         case 0:
00273                 gAgent.teleportViaLocation(pos_global);
00274                 gFloaterWorldMap->trackLocation(pos_global);
00275                 break;
00276         case 1:
00277                 gFloaterWorldMap->trackLocation(pos_global);
00278                 LLFloaterWorldMap::show(NULL, TRUE);
00279                 break;
00280         default:
00281                 break;
00282         }
00283 }
00284 
00285 // static
00286 void LLFloaterLandHoldings::onClickTeleport(void* data)
00287 {
00288         LLFloaterLandHoldings* self = (LLFloaterLandHoldings*)data;
00289         self->buttonCore(0);
00290         self->close();
00291 }
00292 
00293 
00294 // static
00295 void LLFloaterLandHoldings::onClickMap(void* data)
00296 {
00297         LLFloaterLandHoldings* self = (LLFloaterLandHoldings*)data;
00298         self->buttonCore(1);
00299 }
00300 
00301 // static
00302 void LLFloaterLandHoldings::onGrantList(void* data)
00303 {
00304         LLFloaterLandHoldings* self = (LLFloaterLandHoldings*)data;
00305         LLCtrlSelectionInterface *list = self->childGetSelectionInterface("grant list");
00306         if (!list) return;
00307         LLUUID group_id = list->getCurrentID();
00308         if (group_id.notNull())
00309         {
00310                 LLFloaterGroupInfo::showFromUUID(group_id);
00311         }
00312 }
00313 
00314 void LLFloaterLandHoldings::refreshAggregates()
00315 {
00316         S32 allowed_area = gStatusBar->getSquareMetersCredit();
00317         S32 current_area = gStatusBar->getSquareMetersCommitted();
00318         S32 available_area = gStatusBar->getSquareMetersLeft();
00319 
00320         childSetTextArg("allowed_text", "[AREA]", llformat("%d",allowed_area));
00321         childSetTextArg("current_text", "[AREA]", llformat("%d",current_area));
00322         childSetTextArg("available_text", "[AREA]", llformat("%d",available_area));
00323 }

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