diff options
author | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
commit | 38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch) | |
tree | adca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/newview/llfloatersellland.cpp | |
parent | README.txt (diff) | |
download | meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2 meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz |
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/newview/llfloatersellland.cpp')
-rwxr-xr-x | linden/indra/newview/llfloatersellland.cpp | 505 |
1 files changed, 505 insertions, 0 deletions
diff --git a/linden/indra/newview/llfloatersellland.cpp b/linden/indra/newview/llfloatersellland.cpp new file mode 100755 index 0000000..5fac819 --- /dev/null +++ b/linden/indra/newview/llfloatersellland.cpp | |||
@@ -0,0 +1,505 @@ | |||
1 | /** | ||
2 | * @file llfloatersellland.cpp | ||
3 | * | ||
4 | * Copyright (c) 2006-2007, Linden Research, Inc. | ||
5 | * | ||
6 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
7 | * to you under the terms of the GNU General Public License, version 2.0 | ||
8 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
9 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
10 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
11 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
12 | * | ||
13 | * There are special exceptions to the terms and conditions of the GPL as | ||
14 | * it is applied to this Source Code. View the full text of the exception | ||
15 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
16 | * online at http://secondlife.com/developers/opensource/flossexception | ||
17 | * | ||
18 | * By copying, modifying or distributing this software, you acknowledge | ||
19 | * that you have read and understood your obligations described above, | ||
20 | * and agree to abide by those obligations. | ||
21 | * | ||
22 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
23 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
24 | * COMPLETENESS OR PERFORMANCE. | ||
25 | */ | ||
26 | |||
27 | #include "llviewerprecompiledheaders.h" | ||
28 | |||
29 | #include "llfloatersellland.h" | ||
30 | |||
31 | #include "llfloateravatarpicker.h" | ||
32 | #include "llfloater.h" | ||
33 | #include "llfloaterland.h" | ||
34 | #include "lllineeditor.h" | ||
35 | #include "llnotify.h" | ||
36 | #include "llparcel.h" | ||
37 | #include "llselectmgr.h" | ||
38 | #include "lltexturectrl.h" | ||
39 | #include "llviewercontrol.h" | ||
40 | #include "llviewerparcelmgr.h" | ||
41 | #include "llvieweruictrlfactory.h" | ||
42 | #include "llviewerwindow.h" | ||
43 | |||
44 | // defined in llfloaterland.cpp | ||
45 | void send_parcel_select_objects(S32 parcel_local_id, S32 return_type, | ||
46 | uuid_list_t* return_ids = NULL); | ||
47 | |||
48 | enum Badge { BADGE_OK, BADGE_NOTE, BADGE_WARN, BADGE_ERROR }; | ||
49 | |||
50 | class LLFloaterSellLandUI | ||
51 | : public LLFloater | ||
52 | { | ||
53 | private: | ||
54 | LLFloaterSellLandUI(); | ||
55 | virtual ~LLFloaterSellLandUI(); | ||
56 | |||
57 | LLViewerRegion* mRegion; | ||
58 | LLParcel* mParcel; | ||
59 | bool mParcelIsForSale; | ||
60 | bool mSellToBuyer; | ||
61 | bool mChoseSellTo; | ||
62 | S32 mParcelPrice; | ||
63 | S32 mParcelActualArea; | ||
64 | LLUUID mParcelSnapshot; | ||
65 | LLUUID mAuthorizedBuyer; | ||
66 | bool mParcelSoldWithObjects; | ||
67 | |||
68 | void updateParcelInfo(); | ||
69 | void refreshUI(); | ||
70 | void setBadge(const char* id, Badge badge); | ||
71 | |||
72 | static LLFloaterSellLandUI* sInstance; | ||
73 | |||
74 | static void onChangeValue(LLUICtrl *ctrl, void *userdata); | ||
75 | static void doSelectAgent(void *userdata); | ||
76 | static void doCancel(void *userdata); | ||
77 | static void doSellLand(void *userdata); | ||
78 | static void onConfirmSale(S32 option, void *userdata); | ||
79 | static void doShowObjects(void *userdata); | ||
80 | static void callbackHighlightTransferable(S32 option, void* userdata); | ||
81 | |||
82 | static void callbackAvatarPick(const std::vector<std::string>& names, const std::vector<LLUUID>& ids, void* data); | ||
83 | |||
84 | public: | ||
85 | virtual BOOL postBuild(); | ||
86 | virtual void onClose(bool app_quitting); | ||
87 | |||
88 | static LLFloaterSellLandUI* soleInstance(bool createIfNeeded); | ||
89 | |||
90 | bool setParcel(LLViewerRegion* region, LLParcel* parcel); | ||
91 | }; | ||
92 | |||
93 | // static | ||
94 | void LLFloaterSellLand::sellLand( | ||
95 | LLViewerRegion* region, LLParcel* parcel) | ||
96 | { | ||
97 | LLFloaterSellLandUI* ui = LLFloaterSellLandUI::soleInstance(true); | ||
98 | if (ui->setParcel(region, parcel)) | ||
99 | { | ||
100 | ui->open(); | ||
101 | } | ||
102 | } | ||
103 | |||
104 | // static | ||
105 | LLFloaterSellLandUI* LLFloaterSellLandUI::sInstance = NULL; | ||
106 | |||
107 | // static | ||
108 | LLFloaterSellLandUI* LLFloaterSellLandUI::soleInstance(bool createIfNeeded) | ||
109 | { | ||
110 | if (!sInstance && createIfNeeded) | ||
111 | { | ||
112 | sInstance = new LLFloaterSellLandUI(); | ||
113 | |||
114 | gUICtrlFactory->buildFloater(sInstance, "floater_sell_land.xml"); | ||
115 | sInstance->center(); | ||
116 | } | ||
117 | |||
118 | return sInstance; | ||
119 | } | ||
120 | |||
121 | LLFloaterSellLandUI::LLFloaterSellLandUI() | ||
122 | : LLFloater("Sell Land"), | ||
123 | mRegion(0), mParcel(0) | ||
124 | { | ||
125 | } | ||
126 | |||
127 | LLFloaterSellLandUI::~LLFloaterSellLandUI() | ||
128 | { | ||
129 | if (sInstance == this) | ||
130 | { | ||
131 | sInstance = NULL; | ||
132 | } | ||
133 | } | ||
134 | |||
135 | |||
136 | void LLFloaterSellLandUI::onClose(bool app_quitting) | ||
137 | { | ||
138 | LLFloater::onClose(app_quitting); | ||
139 | delete this; | ||
140 | } | ||
141 | |||
142 | BOOL LLFloaterSellLandUI::postBuild() | ||
143 | { | ||
144 | childSetCommitCallback("sell_to", onChangeValue, this); | ||
145 | childSetCommitCallback("price", onChangeValue, this); | ||
146 | childSetPrevalidate("price", LLLineEditor::prevalidateNonNegativeS32); | ||
147 | childSetCommitCallback("sell_objects", onChangeValue, this); | ||
148 | childSetAction("sell_to_select_agent", doSelectAgent, this); | ||
149 | childSetAction("cancel_btn", doCancel, this); | ||
150 | childSetAction("sell_btn", doSellLand, this); | ||
151 | childSetAction("show_objects", doShowObjects, this); | ||
152 | return TRUE; | ||
153 | } | ||
154 | |||
155 | bool LLFloaterSellLandUI::setParcel(LLViewerRegion* region, LLParcel* parcel) | ||
156 | { | ||
157 | if (!parcel) // || !can_agent_modify_parcel(parcel)) // can_agent_modify_parcel was deprecated by GROUPS | ||
158 | { | ||
159 | return false; | ||
160 | } | ||
161 | |||
162 | mRegion = region; | ||
163 | mParcel = parcel; | ||
164 | mChoseSellTo = false; | ||
165 | |||
166 | updateParcelInfo(); | ||
167 | refreshUI(); | ||
168 | |||
169 | return true; | ||
170 | } | ||
171 | |||
172 | void LLFloaterSellLandUI::updateParcelInfo() | ||
173 | { | ||
174 | mParcelActualArea = mParcel->getArea(); | ||
175 | mParcelIsForSale = mParcel->getForSale(); | ||
176 | if (mParcelIsForSale) | ||
177 | { | ||
178 | mChoseSellTo = true; | ||
179 | } | ||
180 | mParcelPrice = mParcelIsForSale ? mParcel->getSalePrice() : 0; | ||
181 | mParcelSoldWithObjects = mParcel->getSellWithObjects(); | ||
182 | if (mParcelIsForSale) | ||
183 | { | ||
184 | childSetValue("price", mParcelPrice); | ||
185 | if (mParcelSoldWithObjects) | ||
186 | { | ||
187 | childSetValue("sell_objects", "yes"); | ||
188 | } | ||
189 | else | ||
190 | { | ||
191 | childSetValue("sell_objects", "no"); | ||
192 | } | ||
193 | } | ||
194 | else | ||
195 | { | ||
196 | childSetValue("price", ""); | ||
197 | childSetValue("sell_objects", "none"); | ||
198 | } | ||
199 | |||
200 | mParcelSnapshot = mParcel->getSnapshotID(); | ||
201 | |||
202 | mAuthorizedBuyer = mParcel->getAuthorizedBuyerID(); | ||
203 | mSellToBuyer = mAuthorizedBuyer.notNull(); | ||
204 | |||
205 | if(mSellToBuyer) | ||
206 | { | ||
207 | LLString name; | ||
208 | char firstname[MAX_STRING]; | ||
209 | char lastname[MAX_STRING]; | ||
210 | gCacheName->getName(mAuthorizedBuyer, firstname, lastname); | ||
211 | name.assign(firstname); | ||
212 | name.append(" "); | ||
213 | name.append(lastname); | ||
214 | |||
215 | childSetText("sell_to_agent", name); | ||
216 | } | ||
217 | } | ||
218 | |||
219 | void LLFloaterSellLandUI::setBadge(const char* id, Badge badge) | ||
220 | { | ||
221 | static LLUUID badgeOK(gViewerArt.getString("badge_ok.tga")); | ||
222 | static LLUUID badgeNote(gViewerArt.getString("badge_note.tga")); | ||
223 | static LLUUID badgeWarn(gViewerArt.getString("badge_warn.tga")); | ||
224 | static LLUUID badgeError(gViewerArt.getString("badge_error.tga")); | ||
225 | |||
226 | LLUUID badgeUUID; | ||
227 | switch (badge) | ||
228 | { | ||
229 | default: | ||
230 | case BADGE_OK: badgeUUID = badgeOK; break; | ||
231 | case BADGE_NOTE: badgeUUID = badgeNote; break; | ||
232 | case BADGE_WARN: badgeUUID = badgeWarn; break; | ||
233 | case BADGE_ERROR: badgeUUID = badgeError; break; | ||
234 | } | ||
235 | |||
236 | childSetValue(id, badgeUUID); | ||
237 | } | ||
238 | |||
239 | void LLFloaterSellLandUI::refreshUI() | ||
240 | { | ||
241 | LLTextureCtrl* snapshot = LLViewerUICtrlFactory::getTexturePickerByName(this, "info_image"); | ||
242 | if (snapshot) | ||
243 | { | ||
244 | snapshot->setImageAssetID(mParcelSnapshot); | ||
245 | } | ||
246 | |||
247 | childSetText("info_parcel", mParcel->getName()); | ||
248 | childSetTextArg("info_size", "[AREA]", llformat("%d", mParcelActualArea)); | ||
249 | |||
250 | LLString price_str = childGetValue("price").asString(); | ||
251 | bool valid_price = false; | ||
252 | valid_price = (price_str != "") && LLLineEditor::prevalidateNonNegativeS32(utf8str_to_wstring(price_str)); | ||
253 | |||
254 | if (valid_price && mParcelActualArea > 0) | ||
255 | { | ||
256 | F32 per_meter_price = 0; | ||
257 | per_meter_price = F32(mParcelPrice) / F32(mParcelActualArea); | ||
258 | childSetTextArg("price_per_m", "[PER_METER]", llformat("%0.2f", per_meter_price)); | ||
259 | childShow("price_per_m"); | ||
260 | |||
261 | setBadge("step_price", BADGE_OK); | ||
262 | } | ||
263 | else | ||
264 | { | ||
265 | childHide("price_per_m"); | ||
266 | |||
267 | if ("" == price_str) | ||
268 | { | ||
269 | setBadge("step_price", BADGE_NOTE); | ||
270 | } | ||
271 | else | ||
272 | { | ||
273 | setBadge("step_price", BADGE_ERROR); | ||
274 | } | ||
275 | } | ||
276 | |||
277 | if (mSellToBuyer) | ||
278 | { | ||
279 | childSetValue("sell_to", "user"); | ||
280 | childShow("sell_to_agent"); | ||
281 | childShow("sell_to_select_agent"); | ||
282 | } | ||
283 | else | ||
284 | { | ||
285 | if (mChoseSellTo) | ||
286 | { | ||
287 | childSetValue("sell_to", "anyone"); | ||
288 | } | ||
289 | else | ||
290 | { | ||
291 | childSetValue("sell_to", "select"); | ||
292 | } | ||
293 | childHide("sell_to_agent"); | ||
294 | childHide("sell_to_select_agent"); | ||
295 | } | ||
296 | |||
297 | // Must select Sell To: Anybody, or User (with a specified username) | ||
298 | LLString sell_to = childGetValue("sell_to").asString(); | ||
299 | bool valid_sell_to = "select" != sell_to && | ||
300 | ("user" != sell_to || mAuthorizedBuyer.notNull()); | ||
301 | |||
302 | if (!valid_sell_to) | ||
303 | { | ||
304 | setBadge("step_sell_to", BADGE_NOTE); | ||
305 | } | ||
306 | else | ||
307 | { | ||
308 | setBadge("step_sell_to", BADGE_OK); | ||
309 | } | ||
310 | |||
311 | bool valid_sell_objects = ("none" != childGetValue("sell_objects").asString()); | ||
312 | |||
313 | if (!valid_sell_objects) | ||
314 | { | ||
315 | setBadge("step_sell_objects", BADGE_NOTE); | ||
316 | } | ||
317 | else | ||
318 | { | ||
319 | setBadge("step_sell_objects", BADGE_OK); | ||
320 | } | ||
321 | |||
322 | if (valid_sell_to && valid_price && valid_sell_objects) | ||
323 | { | ||
324 | childEnable("sell_btn"); | ||
325 | } | ||
326 | else | ||
327 | { | ||
328 | childDisable("sell_btn"); | ||
329 | } | ||
330 | } | ||
331 | |||
332 | // static | ||
333 | void LLFloaterSellLandUI::onChangeValue(LLUICtrl *ctrl, void *userdata) | ||
334 | { | ||
335 | LLFloaterSellLandUI *self = (LLFloaterSellLandUI *)userdata; | ||
336 | |||
337 | LLString sell_to = self->childGetValue("sell_to").asString(); | ||
338 | |||
339 | if (sell_to == "user") | ||
340 | { | ||
341 | self->mChoseSellTo = true; | ||
342 | self->mSellToBuyer = true; | ||
343 | if (self->mAuthorizedBuyer.isNull()) | ||
344 | { | ||
345 | doSelectAgent(self); | ||
346 | } | ||
347 | } | ||
348 | else if (sell_to == "anyone") | ||
349 | { | ||
350 | self->mChoseSellTo = true; | ||
351 | self->mSellToBuyer = false; | ||
352 | } | ||
353 | |||
354 | self->mParcelPrice = self->childGetValue("price"); | ||
355 | |||
356 | if ("yes" == self->childGetValue("sell_objects").asString()) | ||
357 | { | ||
358 | self->mParcelSoldWithObjects = true; | ||
359 | } | ||
360 | else | ||
361 | { | ||
362 | self->mParcelSoldWithObjects = false; | ||
363 | } | ||
364 | |||
365 | self->refreshUI(); | ||
366 | } | ||
367 | |||
368 | // static | ||
369 | void LLFloaterSellLandUI::doSelectAgent(void *userdata) | ||
370 | { | ||
371 | LLFloaterSellLandUI* floaterp = (LLFloaterSellLandUI*)userdata; | ||
372 | // grandparent is a floater, in order to set up dependency | ||
373 | floaterp->addDependentFloater(LLFloaterAvatarPicker::show(callbackAvatarPick, floaterp, FALSE, TRUE)); | ||
374 | } | ||
375 | |||
376 | // static | ||
377 | void LLFloaterSellLandUI::callbackAvatarPick(const std::vector<std::string>& names, const std::vector<LLUUID>& ids, void* data) | ||
378 | { | ||
379 | LLFloaterSellLandUI* floaterp = (LLFloaterSellLandUI*)data; | ||
380 | LLParcel* parcel = floaterp->mParcel; | ||
381 | |||
382 | if (names.empty() || ids.empty()) return; | ||
383 | |||
384 | LLUUID id = ids[0]; | ||
385 | parcel->setAuthorizedBuyerID(id); | ||
386 | |||
387 | floaterp->mAuthorizedBuyer = ids[0]; | ||
388 | |||
389 | floaterp->childSetText("sell_to_agent", names[0]); | ||
390 | |||
391 | floaterp->refreshUI(); | ||
392 | } | ||
393 | |||
394 | // static | ||
395 | void LLFloaterSellLandUI::doCancel(void *userdata) | ||
396 | { | ||
397 | LLFloaterSellLandUI* self = (LLFloaterSellLandUI*)userdata; | ||
398 | self->close(); | ||
399 | } | ||
400 | |||
401 | // static | ||
402 | void LLFloaterSellLandUI::doShowObjects(void *userdata) | ||
403 | { | ||
404 | LLFloaterSellLandUI* self = (LLFloaterSellLandUI*)userdata; | ||
405 | send_parcel_select_objects(self->mParcel->getLocalID(), RT_SELL); | ||
406 | |||
407 | LLNotifyBox::showXml("TransferObjectsHighlighted", | ||
408 | callbackHighlightTransferable, | ||
409 | userdata); | ||
410 | } | ||
411 | |||
412 | // static | ||
413 | void LLFloaterSellLandUI::callbackHighlightTransferable(S32 option, void* userdata) | ||
414 | { | ||
415 | gSelectMgr->unhighlightAll(); | ||
416 | } | ||
417 | |||
418 | // static | ||
419 | void LLFloaterSellLandUI::doSellLand(void *userdata) | ||
420 | { | ||
421 | LLFloaterSellLandUI* self = (LLFloaterSellLandUI*)userdata; | ||
422 | |||
423 | LLParcel* parcel = self->mParcel; | ||
424 | |||
425 | // Do a confirmation | ||
426 | if (!parcel->getForSale()) | ||
427 | { | ||
428 | S32 sale_price = self->childGetValue("price"); | ||
429 | S32 area = parcel->getArea(); | ||
430 | std::string authorizedBuyerName = "Anyone"; | ||
431 | bool sell_to_anyone = true; | ||
432 | if ("user" == self->childGetValue("sell_to").asString()) | ||
433 | { | ||
434 | authorizedBuyerName = self->childGetText("sell_to_agent"); | ||
435 | sell_to_anyone = false; | ||
436 | } | ||
437 | |||
438 | // must sell to someone if indicating sale to anyone | ||
439 | if ((sale_price == 0) && sell_to_anyone) | ||
440 | { | ||
441 | gViewerWindow->alertXml("SalePriceRestriction"); | ||
442 | return; | ||
443 | } | ||
444 | |||
445 | LLStringBase<char>::format_map_t args; | ||
446 | args["[LAND_SIZE]"] = llformat("%d",area); | ||
447 | args["[SALE_PRICE]"] = llformat("%d",sale_price); | ||
448 | args["[NAME]"] = authorizedBuyerName; | ||
449 | |||
450 | gViewerWindow->alertXml("ConfirmLandSaleChange", args, onConfirmSale, self); | ||
451 | } | ||
452 | else | ||
453 | { | ||
454 | onConfirmSale(-1, self); | ||
455 | } | ||
456 | } | ||
457 | |||
458 | // static | ||
459 | void LLFloaterSellLandUI::onConfirmSale(S32 option, void *userdata) | ||
460 | { | ||
461 | if (option != 0) | ||
462 | { | ||
463 | return; | ||
464 | } | ||
465 | LLFloaterSellLandUI* self = (LLFloaterSellLandUI*)userdata; | ||
466 | S32 sale_price = self->childGetValue("price"); | ||
467 | |||
468 | // Valid extracted data | ||
469 | if (sale_price < 0) | ||
470 | { | ||
471 | // TomY TODO: Throw an error | ||
472 | return; | ||
473 | } | ||
474 | |||
475 | LLParcel* parcel = self->mParcel; | ||
476 | |||
477 | // can_agent_modify_parcel deprecated by GROUPS | ||
478 | // if (!can_agent_modify_parcel(parcel)) | ||
479 | // { | ||
480 | // self->close(); | ||
481 | // return; | ||
482 | // } | ||
483 | |||
484 | parcel->setParcelFlag(PF_FOR_SALE, TRUE); | ||
485 | parcel->setSalePrice(sale_price); | ||
486 | bool sell_with_objects = false; | ||
487 | if ("yes" == self->childGetValue("sell_objects").asString()) | ||
488 | { | ||
489 | sell_with_objects = true; | ||
490 | } | ||
491 | parcel->setSellWithObjects(sell_with_objects); | ||
492 | if ("user" == self->childGetValue("sell_to").asString()) | ||
493 | { | ||
494 | parcel->setAuthorizedBuyerID(self->mAuthorizedBuyer); | ||
495 | } | ||
496 | else | ||
497 | { | ||
498 | parcel->setAuthorizedBuyerID(LLUUID::null); | ||
499 | } | ||
500 | |||
501 | // Send update to server | ||
502 | gParcelMgr->sendParcelPropertiesUpdate( parcel, LLFloaterLand::sRequestReplyOnUpdate ); | ||
503 | |||
504 | self->close(); | ||
505 | } | ||