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/llfloaterbuycurrency.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/llfloaterbuycurrency.cpp')
-rw-r--r-- | linden/indra/newview/llfloaterbuycurrency.cpp | 375 |
1 files changed, 375 insertions, 0 deletions
diff --git a/linden/indra/newview/llfloaterbuycurrency.cpp b/linden/indra/newview/llfloaterbuycurrency.cpp new file mode 100644 index 0000000..3ecffd5 --- /dev/null +++ b/linden/indra/newview/llfloaterbuycurrency.cpp | |||
@@ -0,0 +1,375 @@ | |||
1 | /** | ||
2 | * @file llfloaterbuycurrency.cpp | ||
3 | * @brief LLFloaterBuyCurrency class implementation | ||
4 | * | ||
5 | * Copyright (c) 2005-2007, Linden Research, Inc. | ||
6 | * | ||
7 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
8 | * to you under the terms of the GNU General Public License, version 2.0 | ||
9 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
10 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
11 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
12 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
13 | * | ||
14 | * There are special exceptions to the terms and conditions of the GPL as | ||
15 | * it is applied to this Source Code. View the full text of the exception | ||
16 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
17 | * online at http://secondlife.com/developers/opensource/flossexception | ||
18 | * | ||
19 | * By copying, modifying or distributing this software, you acknowledge | ||
20 | * that you have read and understood your obligations described above, | ||
21 | * and agree to abide by those obligations. | ||
22 | * | ||
23 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
24 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
25 | * COMPLETENESS OR PERFORMANCE. | ||
26 | */ | ||
27 | |||
28 | #include "llviewerprecompiledheaders.h" | ||
29 | |||
30 | #include "llfloaterbuycurrency.h" | ||
31 | |||
32 | // viewer includes | ||
33 | #include "llcurrencyuimanager.h" | ||
34 | #include "llfloater.h" | ||
35 | #include "llstatusbar.h" | ||
36 | #include "lltextbox.h" | ||
37 | #include "llviewchildren.h" | ||
38 | #include "llviewerwindow.h" | ||
39 | #include "llvieweruictrlfactory.h" | ||
40 | #include "llweb.h" | ||
41 | #include "llwindow.h" | ||
42 | #include "viewer.h" | ||
43 | |||
44 | static const S32 STANDARD_BUY_AMOUNT = 1000; | ||
45 | static const S32 MINIMUM_BALANCE_AMOUNT = 0; | ||
46 | |||
47 | class LLFloaterBuyCurrencyUI | ||
48 | : public LLFloater | ||
49 | { | ||
50 | public: | ||
51 | static LLFloaterBuyCurrencyUI* soleInstance(bool createIfNeeded); | ||
52 | |||
53 | private: | ||
54 | static LLFloaterBuyCurrencyUI* sInstance; | ||
55 | |||
56 | LLFloaterBuyCurrencyUI(); | ||
57 | virtual ~LLFloaterBuyCurrencyUI(); | ||
58 | |||
59 | |||
60 | public: | ||
61 | LLViewChildren mChildren; | ||
62 | LLCurrencyUIManager mManager; | ||
63 | |||
64 | bool mHasTarget; | ||
65 | std::string mTargetName; | ||
66 | S32 mTargetPrice; | ||
67 | |||
68 | public: | ||
69 | void noTarget(); | ||
70 | void target(const std::string& name, S32 price); | ||
71 | |||
72 | virtual BOOL postBuild(); | ||
73 | |||
74 | void updateUI(); | ||
75 | |||
76 | virtual void draw(); | ||
77 | virtual BOOL canClose(); | ||
78 | virtual void onClose(bool app_quitting); | ||
79 | |||
80 | static void onClickBuy(void* data); | ||
81 | static void onClickCancel(void* data); | ||
82 | static void onClickErrorWeb(void* data); | ||
83 | }; | ||
84 | |||
85 | |||
86 | // static | ||
87 | LLFloaterBuyCurrencyUI* LLFloaterBuyCurrencyUI::sInstance = NULL; | ||
88 | |||
89 | // static | ||
90 | LLFloaterBuyCurrencyUI* LLFloaterBuyCurrencyUI::soleInstance(bool createIfNeeded) | ||
91 | { | ||
92 | if (!sInstance && createIfNeeded) | ||
93 | { | ||
94 | sInstance = new LLFloaterBuyCurrencyUI(); | ||
95 | |||
96 | gUICtrlFactory->buildFloater(sInstance, "floater_buy_currency.xml"); | ||
97 | sInstance->center(); | ||
98 | } | ||
99 | |||
100 | return sInstance; | ||
101 | } | ||
102 | |||
103 | |||
104 | #if LL_WINDOWS | ||
105 | // passing 'this' during construction generates a warning. The callee | ||
106 | // only uses the pointer to hold a reference to 'this' which is | ||
107 | // already valid, so this call does the correct thing. Disable the | ||
108 | // warning so that we can compile without generating a warning. | ||
109 | #pragma warning(disable : 4355) | ||
110 | #endif | ||
111 | LLFloaterBuyCurrencyUI::LLFloaterBuyCurrencyUI() | ||
112 | : LLFloater("Buy Currency"), | ||
113 | mChildren(*this), | ||
114 | mManager(*this) | ||
115 | { | ||
116 | } | ||
117 | |||
118 | LLFloaterBuyCurrencyUI::~LLFloaterBuyCurrencyUI() | ||
119 | { | ||
120 | if (sInstance == this) | ||
121 | { | ||
122 | sInstance = NULL; | ||
123 | } | ||
124 | } | ||
125 | |||
126 | |||
127 | void LLFloaterBuyCurrencyUI::noTarget() | ||
128 | { | ||
129 | mHasTarget = false; | ||
130 | mManager.setAmount(STANDARD_BUY_AMOUNT); | ||
131 | } | ||
132 | |||
133 | void LLFloaterBuyCurrencyUI::target(const std::string& name, S32 price) | ||
134 | { | ||
135 | mHasTarget = true; | ||
136 | mTargetName = name; | ||
137 | mTargetPrice = price; | ||
138 | |||
139 | S32 balance = gStatusBar->getBalance(); | ||
140 | S32 need = price - balance; | ||
141 | if (need < 0) | ||
142 | { | ||
143 | need = 0; | ||
144 | } | ||
145 | |||
146 | mManager.setAmount(need + MINIMUM_BALANCE_AMOUNT); | ||
147 | } | ||
148 | |||
149 | |||
150 | // virtual | ||
151 | BOOL LLFloaterBuyCurrencyUI::postBuild() | ||
152 | { | ||
153 | mManager.prepare(); | ||
154 | |||
155 | childSetAction("buy_btn", onClickBuy, this); | ||
156 | childSetAction("cancel_btn", onClickCancel, this); | ||
157 | childSetAction("error_web", onClickErrorWeb, this); | ||
158 | |||
159 | updateUI(); | ||
160 | |||
161 | return TRUE; | ||
162 | } | ||
163 | |||
164 | void LLFloaterBuyCurrencyUI::draw() | ||
165 | { | ||
166 | if (mManager.process()) | ||
167 | { | ||
168 | if (mManager.bought()) | ||
169 | { | ||
170 | close(); | ||
171 | return; | ||
172 | } | ||
173 | |||
174 | updateUI(); | ||
175 | } | ||
176 | |||
177 | LLFloater::draw(); | ||
178 | } | ||
179 | |||
180 | BOOL LLFloaterBuyCurrencyUI::canClose() | ||
181 | { | ||
182 | return mManager.canCancel(); | ||
183 | } | ||
184 | |||
185 | void LLFloaterBuyCurrencyUI::onClose(bool app_quitting) | ||
186 | { | ||
187 | LLFloater::onClose(app_quitting); | ||
188 | delete this; | ||
189 | } | ||
190 | |||
191 | void LLFloaterBuyCurrencyUI::updateUI() | ||
192 | { | ||
193 | bool hasError = mManager.hasError(); | ||
194 | mManager.updateUI(!hasError && !mManager.buying()); | ||
195 | |||
196 | // section zero: title area | ||
197 | { | ||
198 | childSetVisible("info_buying", false); | ||
199 | childSetVisible("info_cannot_buy", false); | ||
200 | childSetVisible("info_need_more", false); | ||
201 | if (hasError) | ||
202 | { | ||
203 | childSetVisible("info_cannot_buy", true); | ||
204 | } | ||
205 | else if (mHasTarget) | ||
206 | { | ||
207 | childSetVisible("info_need_more", true); | ||
208 | } | ||
209 | else | ||
210 | { | ||
211 | childSetVisible("info_buying", true); | ||
212 | } | ||
213 | } | ||
214 | |||
215 | // error section | ||
216 | if (hasError) | ||
217 | { | ||
218 | mChildren.setBadge("step_error", LLViewChildren::BADGE_ERROR); | ||
219 | |||
220 | LLTextBox* message = LLUICtrlFactory::getTextBoxByName(this, "error_message"); | ||
221 | if (message) | ||
222 | { | ||
223 | message->setVisible(true); | ||
224 | message->setWrappedText(mManager.errorMessage()); | ||
225 | } | ||
226 | |||
227 | childSetVisible("error_web", !mManager.errorURI().empty()); | ||
228 | } | ||
229 | else | ||
230 | { | ||
231 | childHide("step_error"); | ||
232 | childHide("error_message"); | ||
233 | childHide("error_web"); | ||
234 | } | ||
235 | |||
236 | |||
237 | // currency | ||
238 | childSetVisible("contacting", false); | ||
239 | childSetVisible("buy_action", false); | ||
240 | childSetVisible("buy_action_unknown", false); | ||
241 | |||
242 | if (!hasError) | ||
243 | { | ||
244 | mChildren.setBadge("step_1", LLViewChildren::BADGE_NOTE); | ||
245 | |||
246 | if (mManager.buying()) | ||
247 | { | ||
248 | childSetVisible("contacting", true); | ||
249 | } | ||
250 | else | ||
251 | { | ||
252 | if (mHasTarget) | ||
253 | { | ||
254 | childSetVisible("buy_action", true); | ||
255 | childSetTextArg("buy_action", "[NAME]", mTargetName); | ||
256 | childSetTextArg("buy_action", "[PRICE]", llformat("%d",mTargetPrice)); | ||
257 | } | ||
258 | else | ||
259 | { | ||
260 | childSetVisible("buy_action_unknown", true); | ||
261 | } | ||
262 | } | ||
263 | |||
264 | S32 balance = gStatusBar->getBalance(); | ||
265 | childShow("balance_label"); | ||
266 | childShow("balance_amount"); | ||
267 | childSetTextArg("balance_amount", "[AMT]", llformat("%d", balance)); | ||
268 | |||
269 | S32 buying = mManager.getAmount(); | ||
270 | childShow("buying_label"); | ||
271 | childShow("buying_amount"); | ||
272 | childSetTextArg("buying_amount", "[AMT]", llformat("%d", buying)); | ||
273 | |||
274 | S32 total = balance + buying; | ||
275 | childShow("total_label"); | ||
276 | childShow("total_amount"); | ||
277 | childSetTextArg("total_amount", "[AMT]", llformat("%d", total)); | ||
278 | |||
279 | childSetVisible("purchase_warning_repurchase", false); | ||
280 | childSetVisible("purchase_warning_notenough", false); | ||
281 | if (mHasTarget) | ||
282 | { | ||
283 | if (total >= mTargetPrice) | ||
284 | { | ||
285 | childSetVisible("purchase_warning_repurchase", true); | ||
286 | } | ||
287 | else | ||
288 | { | ||
289 | childSetVisible("purchase_warning_notenough", true); | ||
290 | } | ||
291 | } | ||
292 | } | ||
293 | else | ||
294 | { | ||
295 | childHide("step_1"); | ||
296 | childHide("balance_label"); | ||
297 | childHide("balance_amount"); | ||
298 | childHide("buying_label"); | ||
299 | childHide("buying_amount"); | ||
300 | childHide("total_label"); | ||
301 | childHide("total_amount"); | ||
302 | childHide("purchase_warning_repurchase"); | ||
303 | childHide("purchase_warning_notenough"); | ||
304 | } | ||
305 | |||
306 | childSetEnabled("buy_btn", mManager.canBuy()); | ||
307 | } | ||
308 | |||
309 | // static | ||
310 | void LLFloaterBuyCurrencyUI::onClickBuy(void* data) | ||
311 | { | ||
312 | LLFloaterBuyCurrencyUI* self = LLFloaterBuyCurrencyUI::soleInstance(false); | ||
313 | if (self) | ||
314 | { | ||
315 | self->mManager.buy(); | ||
316 | self->updateUI(); | ||
317 | // JC: updateUI() doesn't get called again until progress is made | ||
318 | // with transaction processing, so the "Purchase" button would be | ||
319 | // left enabled for some time. Pre-emptively disable. | ||
320 | self->childSetEnabled("buy_btn", false); | ||
321 | } | ||
322 | } | ||
323 | |||
324 | // static | ||
325 | void LLFloaterBuyCurrencyUI::onClickCancel(void* data) | ||
326 | { | ||
327 | LLFloaterBuyCurrencyUI* self = LLFloaterBuyCurrencyUI::soleInstance(false); | ||
328 | if (self) | ||
329 | { | ||
330 | self->close(); | ||
331 | } | ||
332 | } | ||
333 | |||
334 | // static | ||
335 | void LLFloaterBuyCurrencyUI::onClickErrorWeb(void* data) | ||
336 | { | ||
337 | LLFloaterBuyCurrencyUI* self = LLFloaterBuyCurrencyUI::soleInstance(false); | ||
338 | if (self) | ||
339 | { | ||
340 | LLWeb::loadURLExternal(self->mManager.errorURI()); | ||
341 | self->close(); | ||
342 | } | ||
343 | } | ||
344 | |||
345 | // static | ||
346 | void LLFloaterBuyCurrency::buyCurrency() | ||
347 | { | ||
348 | if (gHideLinks) | ||
349 | { | ||
350 | return; | ||
351 | } | ||
352 | |||
353 | LLFloaterBuyCurrencyUI* ui = LLFloaterBuyCurrencyUI::soleInstance(true); | ||
354 | ui->noTarget(); | ||
355 | ui->updateUI(); | ||
356 | ui->open(); | ||
357 | } | ||
358 | |||
359 | void LLFloaterBuyCurrency::buyCurrency(const std::string& name, S32 price) | ||
360 | { | ||
361 | if (gHideLinks) | ||
362 | { | ||
363 | LLStringBase<char>::format_map_t args; | ||
364 | args["[NAME]"] = name.c_str(); | ||
365 | args["[PRICE]"] = price; | ||
366 | gViewerWindow->alertXml("NotEnoughCurrency", args); | ||
367 | return; | ||
368 | } | ||
369 | |||
370 | LLFloaterBuyCurrencyUI* ui = LLFloaterBuyCurrencyUI::soleInstance(true); | ||
371 | ui->target(name, price); | ||
372 | ui->updateUI(); | ||
373 | ui->open(); | ||
374 | } | ||
375 | |||