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

