llfloaterbuycurrency.cpp
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:7k
源码类别:

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file llfloaterbuycurrency.cpp
  3.  * @brief LLFloaterBuyCurrency class implementation
  4.  *
  5.  * $LicenseInfo:firstyear=2005&license=viewergpl$
  6.  * 
  7.  * Copyright (c) 2005-2010, Linden Research, Inc.
  8.  * 
  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. #include "llviewerprecompiledheaders.h"
  33. #include "llfloaterbuycurrency.h"
  34. // viewer includes
  35. #include "llcurrencyuimanager.h"
  36. #include "llfloater.h"
  37. #include "llfloaterreg.h"
  38. #include "llnotificationsutil.h"
  39. #include "llstatusbar.h"
  40. #include "lltextbox.h"
  41. #include "llviewchildren.h"
  42. #include "llviewerwindow.h"
  43. #include "lluictrlfactory.h"
  44. #include "llweb.h"
  45. #include "llwindow.h"
  46. #include "llappviewer.h"
  47. static const S32 STANDARD_BUY_AMOUNT = 2000;
  48. static const S32 MINIMUM_BALANCE_AMOUNT = 0;
  49. class LLFloaterBuyCurrencyUI
  50. : public LLFloater
  51. {
  52. public:
  53. LLFloaterBuyCurrencyUI(const LLSD& key);
  54. virtual ~LLFloaterBuyCurrencyUI();
  55. public:
  56. LLViewChildren mChildren;
  57. LLCurrencyUIManager mManager;
  58. bool mHasTarget;
  59. std::string mTargetName;
  60. S32 mTargetPrice;
  61. public:
  62. void noTarget();
  63. void target(const std::string& name, S32 price);
  64. virtual BOOL postBuild();
  65. void updateUI();
  66. virtual void draw();
  67. virtual BOOL canClose();
  68. void onClickBuy();
  69. void onClickCancel();
  70. void onClickErrorWeb();
  71. };
  72. LLFloater* LLFloaterBuyCurrency::buildFloater(const LLSD& key)
  73. {
  74. LLFloaterBuyCurrencyUI* floater = new LLFloaterBuyCurrencyUI(key);
  75. return floater;
  76. }
  77. #if LL_WINDOWS
  78. // passing 'this' during construction generates a warning. The callee
  79. // only uses the pointer to hold a reference to 'this' which is
  80. // already valid, so this call does the correct thing. Disable the
  81. // warning so that we can compile without generating a warning.
  82. #pragma warning(disable : 4355)
  83. #endif 
  84. LLFloaterBuyCurrencyUI::LLFloaterBuyCurrencyUI(const LLSD& key)
  85. : LLFloater(key),
  86. mChildren(*this),
  87. mManager(*this)
  88. {
  89. }
  90. LLFloaterBuyCurrencyUI::~LLFloaterBuyCurrencyUI()
  91. {
  92. }
  93. void LLFloaterBuyCurrencyUI::noTarget()
  94. {
  95. mHasTarget = false;
  96. mManager.setAmount(STANDARD_BUY_AMOUNT);
  97. }
  98. void LLFloaterBuyCurrencyUI::target(const std::string& name, S32 price)
  99. {
  100. mHasTarget = true;
  101. mTargetName = name;
  102. mTargetPrice = price;
  103. S32 balance = gStatusBar->getBalance();
  104. S32 need = price - balance;
  105. if (need < 0)
  106. {
  107. need = 0;
  108. }
  109. mManager.setAmount(need + MINIMUM_BALANCE_AMOUNT);
  110. }
  111. // virtual
  112. BOOL LLFloaterBuyCurrencyUI::postBuild()
  113. {
  114. mManager.prepare();
  115. getChild<LLUICtrl>("buy_btn")->setCommitCallback( boost::bind(&LLFloaterBuyCurrencyUI::onClickBuy, this));
  116. getChild<LLUICtrl>("cancel_btn")->setCommitCallback( boost::bind(&LLFloaterBuyCurrencyUI::onClickCancel, this));
  117. getChild<LLUICtrl>("error_web")->setCommitCallback( boost::bind(&LLFloaterBuyCurrencyUI::onClickErrorWeb, this));
  118. center();
  119. updateUI();
  120. return TRUE;
  121. }
  122. void LLFloaterBuyCurrencyUI::draw()
  123. {
  124. if (mManager.process())
  125. {
  126. if (mManager.bought())
  127. {
  128. LLNotificationsUtil::add("BuyLindenDollarSuccess");
  129. closeFloater();
  130. return;
  131. }
  132. updateUI();
  133. }
  134. // disable the Buy button when we are not able to buy
  135. childSetEnabled("buy_btn", mManager.canBuy());
  136. LLFloater::draw();
  137. }
  138. BOOL LLFloaterBuyCurrencyUI::canClose()
  139. {
  140. return mManager.canCancel();
  141. }
  142. void LLFloaterBuyCurrencyUI::updateUI()
  143. {
  144. bool hasError = mManager.hasError();
  145. mManager.updateUI(!hasError && !mManager.buying());
  146. // hide most widgets - we'll turn them on as needed next
  147. childHide("info_buying");
  148. childHide("info_cannot_buy");
  149. childHide("info_need_more");
  150. childHide("purchase_warning_repurchase");
  151. childHide("purchase_warning_notenough");
  152. childHide("contacting");
  153. childHide("buy_action");
  154. if (hasError)
  155. {
  156. // display an error from the server
  157. childHide("normal_background");
  158. childShow("error_background");
  159. childShow("info_cannot_buy");
  160. childShow("cannot_buy_message");
  161. childHide("balance_label");
  162. childHide("balance_amount");
  163. childHide("buying_label");
  164. childHide("buying_amount");
  165. childHide("total_label");
  166. childHide("total_amount");
  167.         LLTextBox* message = getChild<LLTextBox>("cannot_buy_message");
  168.         if (message)
  169. {
  170. message->setText(mManager.errorMessage());
  171. }
  172. childSetVisible("error_web", !mManager.errorURI().empty());
  173. }
  174. else
  175. {
  176. // display the main Buy L$ interface
  177. childShow("normal_background");
  178. childHide("error_background");
  179. childHide("cannot_buy_message");
  180. childHide("error_web");
  181. if (mHasTarget)
  182. {
  183. childShow("info_need_more");
  184. }
  185. else
  186. {
  187. childShow("info_buying");
  188. }
  189. if (mManager.buying())
  190. {
  191. childSetVisible("contacting", true);
  192. }
  193. else
  194. {
  195. if (mHasTarget)
  196. {
  197. childSetVisible("buy_action", true);
  198. childSetTextArg("buy_action", "[NAME]", mTargetName);
  199. childSetTextArg("buy_action", "[PRICE]", llformat("%d",mTargetPrice));
  200. }
  201. }
  202. S32 balance = gStatusBar->getBalance();
  203. childShow("balance_label");
  204. childShow("balance_amount");
  205. childSetTextArg("balance_amount", "[AMT]", llformat("%d", balance));
  206. S32 buying = mManager.getAmount();
  207. childShow("buying_label");
  208. childShow("buying_amount");
  209. childSetTextArg("buying_amount", "[AMT]", llformat("%d", buying));
  210. S32 total = balance + buying;
  211. childShow("total_label");
  212. childShow("total_amount");
  213. childSetTextArg("total_amount", "[AMT]", llformat("%d", total));
  214. if (mHasTarget)
  215. {
  216. if (total >= mTargetPrice)
  217. {
  218. childSetVisible("purchase_warning_repurchase", true);
  219. }
  220. else
  221. {
  222. childSetVisible("purchase_warning_notenough", true);
  223. }
  224. }
  225. }
  226. childSetVisible("getting_data", !mManager.canBuy() && !hasError);
  227. }
  228. void LLFloaterBuyCurrencyUI::onClickBuy()
  229. {
  230. mManager.buy(getString("buy_currency"));
  231. updateUI();
  232. }
  233. void LLFloaterBuyCurrencyUI::onClickCancel()
  234. {
  235. closeFloater();
  236. }
  237. void LLFloaterBuyCurrencyUI::onClickErrorWeb()
  238. {
  239. LLWeb::loadURLExternal(mManager.errorURI());
  240. closeFloater();
  241. }
  242. // static
  243. void LLFloaterBuyCurrency::buyCurrency()
  244. {
  245. LLFloaterBuyCurrencyUI* ui = LLFloaterReg::showTypedInstance<LLFloaterBuyCurrencyUI>("buy_currency");
  246. ui->noTarget();
  247. ui->updateUI();
  248. }
  249. // static
  250. void LLFloaterBuyCurrency::buyCurrency(const std::string& name, S32 price)
  251. {
  252. LLFloaterBuyCurrencyUI* ui = LLFloaterReg::showTypedInstance<LLFloaterBuyCurrencyUI>("buy_currency");
  253. ui->target(name, price);
  254. ui->updateUI();
  255. }