00001
00033 #include "llviewerprecompiledheaders.h"
00034 #include "llfloaterauction.h"
00035
00036 #include "lldir.h"
00037 #include "llgl.h"
00038 #include "llimagej2c.h"
00039 #include "llimagetga.h"
00040 #include "llparcel.h"
00041 #include "llvfile.h"
00042 #include "llvfs.h"
00043
00044 #include "llagent.h"
00045 #include "llcombobox.h"
00046 #include "llnotify.h"
00047 #include "llsavedsettingsglue.h"
00048 #include "llviewerimagelist.h"
00049 #include "llviewerparcelmgr.h"
00050 #include "llviewerregion.h"
00051 #include "llvieweruictrlfactory.h"
00052 #include "llviewerwindow.h"
00053 #include "viewer.h"
00054 #include "llui.h"
00055
00059
00060 void auction_j2c_upload_done(const LLUUID& asset_id,
00061 void* user_data, S32 status, LLExtStat ext_status);
00062 void auction_tga_upload_done(const LLUUID& asset_id,
00063 void* user_data, S32 status, LLExtStat ext_status);
00064
00068
00069 LLFloaterAuction* LLFloaterAuction::sInstance = NULL;
00070
00071
00072 LLFloaterAuction::LLFloaterAuction() :
00073 LLFloater("floater_auction"),
00074 mParcelID(-1)
00075 {
00076 gUICtrlFactory->buildFloater(this, "floater_auction.xml");
00077
00078 childSetValue("fence_check",
00079 LLSD( gSavedSettings.getBOOL("AuctionShowFence") ) );
00080 childSetCommitCallback("fence_check",
00081 LLSavedSettingsGlue::setBOOL, (void*)"AuctionShowFence");
00082
00083 childSetAction("snapshot_btn", onClickSnapshot, this);
00084 childSetAction("ok_btn", onClickOK, this);
00085 }
00086
00087
00088 LLFloaterAuction::~LLFloaterAuction()
00089 {
00090 sInstance = NULL;
00091 }
00092
00093
00094 void LLFloaterAuction::show()
00095 {
00096 if(!sInstance)
00097 {
00098 sInstance = new LLFloaterAuction();
00099 sInstance->center();
00100 sInstance->setFocus(TRUE);
00101 }
00102 sInstance->initialize();
00103 sInstance->open();
00104 }
00105
00106 void LLFloaterAuction::initialize()
00107 {
00108 mParcelp = gParcelMgr->getParcelSelection();
00109 LLViewerRegion* region = gParcelMgr->getSelectionRegion();
00110 LLParcel* parcelp = mParcelp->getParcel();
00111 if(parcelp && region && !parcelp->getForSale())
00112 {
00113 mParcelHost = region->getHost();
00114 mParcelID = parcelp->getLocalID();
00115
00116 childSetText("parcel_text", parcelp->getName());
00117 childEnable("snapshot_btn");
00118 childEnable("ok_btn");
00119 }
00120 else
00121 {
00122 mParcelHost.invalidate();
00123 if(parcelp && parcelp->getForSale())
00124 {
00125 childSetText("parcel_text", childGetText("already for sale"));
00126 }
00127 else
00128 {
00129 childSetText("parcel_text", LLString::null);
00130 }
00131 mParcelID = -1;
00132 childSetEnabled("snapshot_btn", false);
00133 childSetEnabled("ok_btn", false);
00134 }
00135 mImageID.setNull();
00136 mImage = NULL;
00137 }
00138
00139 void LLFloaterAuction::draw()
00140 {
00141 LLFloater::draw();
00142
00143 if(getVisible() && !isMinimized() && mImage.notNull())
00144 {
00145 LLRect rect;
00146 if (childGetRect("snapshot_icon", rect))
00147 {
00148 {
00149 LLGLSNoTexture gls_no_texture;
00150 gl_rect_2d(rect, LLColor4(0.f, 0.f, 0.f, 1.f));
00151 rect.stretch(-1);
00152 }
00153 {
00154 LLGLSUIDefault gls_ui;
00155 glColor3f(1.f, 1.f, 1.f);
00156 gl_draw_scaled_image(rect.mLeft,
00157 rect.mBottom,
00158 rect.getWidth(),
00159 rect.getHeight(),
00160 mImage);
00161 }
00162 }
00163 }
00164 }
00165
00166
00167
00168 void LLFloaterAuction::onClickSnapshot(void* data)
00169 {
00170 LLFloaterAuction* self = (LLFloaterAuction*)(data);
00171
00172 LLPointer<LLImageRaw> raw = new LLImageRaw;
00173
00174 gForceRenderLandFence = self->childGetValue("fence_check").asBoolean();
00175 BOOL success = gViewerWindow->rawSnapshot(raw,
00176 gViewerWindow->getWindowWidth(),
00177 gViewerWindow->getWindowHeight(),
00178 TRUE,
00179 FALSE, FALSE);
00180 gForceRenderLandFence = FALSE;
00181
00182 if (success)
00183 {
00184 self->mTransactionID.generate();
00185 self->mImageID = self->mTransactionID.makeAssetID(gAgent.getSecureSessionID());
00186
00187 gViewerWindow->playSnapshotAnimAndSound();
00188 llinfos << "Writing TGA..." << llendl;
00189
00190 LLPointer<LLImageTGA> tga = new LLImageTGA;
00191 tga->encode(raw);
00192 LLVFile::writeFile(tga->getData(), tga->getDataSize(), gVFS, self->mImageID, LLAssetType::AT_IMAGE_TGA);
00193
00194 raw->biasedScaleToPowerOfTwo(LLViewerImage::MAX_IMAGE_SIZE_DEFAULT);
00195
00196 llinfos << "Writing J2C..." << llendl;
00197
00198 LLPointer<LLImageJ2C> j2c = new LLImageJ2C;
00199 j2c->encode(raw);
00200 LLVFile::writeFile(j2c->getData(), j2c->getDataSize(), gVFS, self->mImageID, LLAssetType::AT_TEXTURE);
00201
00202 self->mImage = new LLImageGL((LLImageRaw*)raw, FALSE);
00203 self->mImage->bind();
00204 self->mImage->setClamp(TRUE, TRUE);
00205 }
00206 else
00207 {
00208 llwarns << "Unable to take snapshot" << llendl;
00209 }
00210 }
00211
00212
00213 void LLFloaterAuction::onClickOK(void* data)
00214 {
00215 LLFloaterAuction* self = (LLFloaterAuction*)(data);
00216
00217 if(self->mImageID.notNull())
00218 {
00219 LLSD parcel_name = self->childGetValue("parcel_text");
00220
00221
00222 LLString* name = new LLString(parcel_name.asString());
00223 gAssetStorage->storeAssetData(self->mTransactionID, LLAssetType::AT_IMAGE_TGA,
00224 &auction_tga_upload_done,
00225 (void*)name,
00226 FALSE);
00227 self->getWindow()->incBusyCount();
00228
00229 LLString* j2c_name = new LLString(parcel_name.asString());
00230 gAssetStorage->storeAssetData(self->mTransactionID, LLAssetType::AT_TEXTURE,
00231 &auction_j2c_upload_done,
00232 (void*)j2c_name,
00233 FALSE);
00234 self->getWindow()->incBusyCount();
00235
00236 LLNotifyBox::showXml("UploadingAuctionSnapshot");
00237
00238 }
00239 LLMessageSystem* msg = gMessageSystem;
00240
00241 msg->newMessage("ViewerStartAuction");
00242
00243 msg->nextBlock("AgentData");
00244 msg->addUUID("AgentID", gAgent.getID());
00245 msg->addUUID("SessionID", gAgent.getSessionID());
00246 msg->nextBlock("ParcelData");
00247 msg->addS32("LocalID", self->mParcelID);
00248 msg->addUUID("SnapshotID", self->mImageID);
00249 msg->sendReliable(self->mParcelHost);
00250
00251
00252 self->mImageID.setNull();
00253 self->mImage = NULL;
00254 self->mParcelID = -1;
00255 self->mParcelHost.invalidate();
00256 self->close();
00257 }
00258
00259
00263
00264 void auction_tga_upload_done(const LLUUID& asset_id, void* user_data, S32 status, LLExtStat ext_status)
00265 {
00266 LLString* name = (LLString*)(user_data);
00267 llinfos << "Upload of asset '" << *name << "' " << asset_id
00268 << " returned " << status << llendl;
00269 delete name;
00270
00271 gViewerWindow->getWindow()->decBusyCount();
00272
00273 if (0 == status)
00274 {
00275 LLNotifyBox::showXml("UploadWebSnapshotDone");
00276 }
00277 else
00278 {
00279 LLStringBase<char>::format_map_t args;
00280 args["[REASON]"] = std::string(LLAssetStorage::getErrorString(status));
00281 gViewerWindow->alertXml("UploadAuctionSnapshotFail", args);
00282 }
00283 }
00284
00285 void auction_j2c_upload_done(const LLUUID& asset_id, void* user_data, S32 status, LLExtStat ext_status)
00286 {
00287 LLString* name = (LLString*)(user_data);
00288 llinfos << "Upload of asset '" << *name << "' " << asset_id
00289 << " returned " << status << llendl;
00290 delete name;
00291
00292 gViewerWindow->getWindow()->decBusyCount();
00293
00294 if (0 == status)
00295 {
00296 LLNotifyBox::showXml("UploadSnapshotDone");
00297 }
00298 else
00299 {
00300 LLStringBase<char>::format_map_t args;
00301 args["[REASON]"] = std::string(LLAssetStorage::getErrorString(status));
00302 gViewerWindow->alertXml("UploadAuctionSnapshotFail", args);
00303 }
00304 }