adbe707c-701d-41ed-8da2-a87e27338043.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. "use strict";
  2. cc._RF.push(module, 'adbe7B8cB1B7Y2iqH4nM4BD', 'OpenRedBagPanel');
  3. // common-plugin/Scripts/OpenRedBagPanel.ts
  4. "use strict";
  5. var __extends = (this && this.__extends) || (function () {
  6. var extendStatics = function (d, b) {
  7. extendStatics = Object.setPrototypeOf ||
  8. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  9. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  10. return extendStatics(d, b);
  11. };
  12. return function (d, b) {
  13. extendStatics(d, b);
  14. function __() { this.constructor = d; }
  15. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  16. };
  17. })();
  18. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  19. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  20. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  21. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  22. return c > 3 && r && Object.defineProperty(target, key, r), r;
  23. };
  24. Object.defineProperty(exports, "__esModule", { value: true });
  25. var Utils_1 = require("./Utils");
  26. var YZ_Constant_1 = require("./YZ_Constant");
  27. var PlatUtils_1 = require("./PlatUtils");
  28. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  29. var OpenRedBagPanel = /** @class */ (function (_super) {
  30. __extends(OpenRedBagPanel, _super);
  31. function OpenRedBagPanel() {
  32. var _this = _super !== null && _super.apply(this, arguments) || this;
  33. _this._panel = null;
  34. _this._moneyLbl = null;
  35. _this._totalMoneyLbl = null;
  36. _this._openPanel = null;
  37. _this._rewardPanel = null;
  38. _this._btnOpen = null;
  39. _this._redBagInfo = null;
  40. _this._btnClose = null;
  41. _this._btnVideoOpen = null;
  42. _this._title = null;
  43. _this._btnDouble = null;
  44. _this._proInfo = null;
  45. _this._money = 0;
  46. // update() {
  47. // if (this._dataDirty) {
  48. // this._dataDirty = false;
  49. // this._updatePanel();
  50. // }
  51. // }
  52. _this._canShowVideoOpen = false;
  53. _this._show_type = 1; // 1、每日红包 2、闯关红包 3、现金红包
  54. return _this;
  55. }
  56. // _location: SubLocation = SubLocation.isMoreGame;
  57. OpenRedBagPanel.prototype.onLoad = function () {
  58. var _this = this;
  59. if (Utils_1.utils.otherConfig && Utils_1.utils.otherConfig.group) {
  60. this.node.group = Utils_1.utils.otherConfig.group;
  61. }
  62. if (!PlatUtils_1.default.IsNativeAndroid) {
  63. Utils_1.utils.adManager.HideBanner(YZ_Constant_1.BannerLocation.Home);
  64. }
  65. this._panel = this.node.getChildByName("Panel");
  66. this._openPanel = this._panel.getChildByName("onOpenPanel");
  67. this._openPanel.setScale(0.5);
  68. this._openPanel.runAction(cc.scaleTo(0.3, 1));
  69. this._rewardPanel = this._panel.getChildByName("rewardPanel");
  70. this._btnOpen = this._openPanel.getChildByName("btnOpen");
  71. this._btnClose = this._panel.getChildByName("btnClose");
  72. this._btnVideoOpen = this._btnOpen.getChildByName("btn_openVideo");
  73. this._title = this._openPanel.getChildByName("title");
  74. this._totalMoneyLbl = this._rewardPanel.getChildByName("totalMoneyLabel").getComponent(cc.Label);
  75. this._moneyLbl = this._rewardPanel.getChildByName("moneyLbl").getComponent(cc.Label);
  76. this._btnDouble = this._rewardPanel.getChildByName("btnDouble");
  77. setTimeout(function () {
  78. _this._btnOpen.runAction(cc.repeatForever(cc.sequence(cc.scaleTo(0.5, 1.2), cc.scaleTo(0.5, 1))));
  79. }, 500);
  80. this._redBagInfo = Utils_1.utils.yzRedBagInfo;
  81. this._proInfo = Utils_1.utils.yzRedBagInfo.curProgressInfo;
  82. var ratio = 1;
  83. if (cc.winSize.height < cc.winSize.width) {
  84. // 横屏游戏
  85. ratio = cc.winSize.width / 1920 * 0.5;
  86. }
  87. else {
  88. ratio = cc.winSize.width / 1080;
  89. }
  90. this._panel.scale = ratio;
  91. this.init();
  92. };
  93. OpenRedBagPanel.prototype.openRedBag = function () {
  94. var _this = this;
  95. if (this._redBagInfo.progress < this._redBagInfo.totalProgress && !this._redBagInfo.isFreeRedBag && this._redBagInfo.freeRedBagCount <= 0)
  96. return;
  97. this._btnClose.opacity = 0;
  98. this._btnClose.active = true;
  99. var timeout = Utils_1.utils.ServerConfig.red_bag_close_btn_show_delay ? Utils_1.utils.ServerConfig.red_bag_close_btn_show_delay : 0;
  100. setTimeout(function () {
  101. Utils_1.utils.showLog("拆红包关闭按钮延迟显示 " + timeout + "秒显示!");
  102. _this._btnClose.runAction(cc.fadeIn(0.3));
  103. }, timeout * 1000);
  104. setTimeout(function () {
  105. _this._btnDouble.runAction(cc.repeatForever(cc.sequence(cc.scaleTo(0.5, 1.2), cc.scaleTo(0.5, 1))));
  106. }, 500);
  107. if (this._canShowVideoOpen) {
  108. Utils_1.utils.adManager.ShowVideo(function (res, msg) {
  109. if (res) {
  110. Utils_1.utils.SendEvent('拆红包弹窗-视频拆红包成功!');
  111. _this.scheduleOnce(function () {
  112. _this.showRedBag();
  113. });
  114. }
  115. else {
  116. _this._btnClose.runAction(cc.fadeIn(0.3));
  117. Utils_1.utils.SendEvent('拆红包弹窗-视频拆红包失败!');
  118. Utils_1.utils.showMsg(msg ? msg : "视频加载失败!");
  119. }
  120. });
  121. }
  122. else {
  123. this.showRedBag();
  124. }
  125. };
  126. OpenRedBagPanel.prototype.showRedBag = function () {
  127. var _this = this;
  128. var money = 0;
  129. var proInfo = this._proInfo;
  130. cc.log("proInfo ", JSON.stringify(proInfo));
  131. money = parseFloat((Math.random() * (proInfo.max_money - proInfo.min_money) + proInfo.min_money).toFixed(3));
  132. cc.log("红包金额:" + money);
  133. // let max = this._redBagInfo.withdrawaMoneys[0];
  134. // if (this._redBagInfo.balance <= 0) {
  135. // money = parseFloat((Math.random() * (max / 4)).toFixed(3));
  136. // } else if (this._redBagInfo.balance <= (max / 2.8)) {
  137. // money = parseFloat((Math.random() * (max / 5)).toFixed(3));
  138. // } else if (this._redBagInfo.balance >= (max - 1)) {
  139. // money = Math.random();
  140. // money = parseFloat((money * 0.01 + 0.001).toFixed(3))
  141. // } else if (this._redBagInfo.balance >= max - 2) {
  142. // money = Math.random();
  143. // money = parseFloat((money * 0.01 + 0.001).toFixed(3))
  144. // } else {
  145. // money = Math.random();
  146. // if (money > 0.1) {
  147. // money = parseFloat((money * 0.1).toFixed(3))
  148. // } else {
  149. // money = parseFloat(money.toFixed(3));
  150. // }
  151. // }
  152. // utils.SendEvent("拆红包弹窗-获得红包:" + money + "元");
  153. this._money = money;
  154. this._redBagInfo.balance = parseFloat((this._redBagInfo.balance + money).toFixed(3));
  155. if (this._redBagInfo.isFreeRedBag && this._show_type == 1) {
  156. this._redBagInfo.lastOpenFreeRedBagTime = new Date().toDateString();
  157. }
  158. if (this._show_type == 2) {
  159. this._redBagInfo.progress -= this._redBagInfo.totalProgress;
  160. }
  161. this._redBagInfo.totalMoney = parseFloat((this._redBagInfo.totalMoney + money).toFixed(3));
  162. this._moneyLbl.string = "\u00A5" + money + "\u5143";
  163. this._totalMoneyLbl.string = "\u7D2F\u8BA1\u83B7\u5F97\u73B0\u91D1" + this._redBagInfo.totalMoney + "\u5143";
  164. this._rewardPanel.scaleX = 0;
  165. this._rewardPanel.active = true;
  166. this._openPanel.runAction(cc.sequence(cc.scaleTo(0.3, 0, 1), cc.callFunc(function () {
  167. _this._openPanel.active = false;
  168. _this._rewardPanel.runAction(cc.sequence(cc.scaleTo(0.3, 1), cc.callFunc(function () {
  169. })));
  170. })));
  171. if (Utils_1.utils.currentLevel > parseInt(this._redBagInfo.lastOpenLevel) && this._show_type == 2) {
  172. this._redBagInfo.lastOpenLevel = Utils_1.utils.currentLevel.toString();
  173. }
  174. };
  175. OpenRedBagPanel.prototype.onBtnDoubleMoney = function (event, data) {
  176. var _this = this;
  177. Utils_1.utils.SendEvent("拆红包弹窗-点击视频双倍领取");
  178. Utils_1.utils.adManager.ShowVideo(function (ret, msg) {
  179. if (ret) {
  180. _this._redBagInfo.balance = parseFloat((_this._redBagInfo.balance + _this._money).toFixed(3));
  181. _this._redBagInfo.totalMoney = parseFloat((_this._redBagInfo.totalMoney + _this._money).toFixed(3));
  182. _this._totalMoneyLbl.string = "\u7D2F\u8BA1\u83B7\u5F97\u73B0\u91D1" + _this._redBagInfo.totalMoney + "\u5143";
  183. Utils_1.utils.showMsg("领取双倍红包成功!");
  184. Utils_1.utils.SendEvent("拆红包弹窗-视频双倍领取成功");
  185. event.target.active = false;
  186. }
  187. else {
  188. Utils_1.utils.showMsg(msg);
  189. Utils_1.utils.SendEvent("拆红包弹窗-视频双倍领取失败");
  190. }
  191. });
  192. };
  193. OpenRedBagPanel.prototype.showWithDrawalPanel = function () {
  194. Utils_1.utils.SendEvent("拆红包弹窗-点击提现上报");
  195. Utils_1.utils.showWithdrawalPanel();
  196. };
  197. OpenRedBagPanel.prototype.init = function () {
  198. var _this = this;
  199. Utils_1.utils.SendEvent("拆红包弹窗-展示成功!" + this._show_type + " :" + this._redBagInfo.isFreeRedBag);
  200. this._title.children[0].active = this._show_type == 1 && this._redBagInfo.isFreeRedBag;
  201. this._title.children[1].active = this._show_type == 2;
  202. this._title.children[2].active = this._show_type == 3;
  203. if (this._proInfo.type == 2 && this._show_type == 2) {
  204. this._canShowVideoOpen = true;
  205. this._btnVideoOpen.active = true;
  206. }
  207. else {
  208. this._canShowVideoOpen = false;
  209. this._btnVideoOpen.active = false;
  210. }
  211. // utils.ServerConfig.red_bag_open_view_close_btn_show_delay = 1;
  212. if (Utils_1.utils.ServerConfig.red_bag_open_view_close_btn_show_delay && Utils_1.utils.ServerConfig.red_bag_open_view_close_btn_show_delay > 0) {
  213. this._btnClose.opacity = 0;
  214. var timeout_1 = Utils_1.utils.ServerConfig.red_bag_open_view_close_btn_show_delay ? Utils_1.utils.ServerConfig.red_bag_open_view_close_btn_show_delay : 0;
  215. setTimeout(function () {
  216. Utils_1.utils.showLog("拆红包关闭按钮延迟显示 " + timeout_1 + "秒显示!");
  217. _this._btnClose.runAction(cc.fadeIn(0.3));
  218. }, timeout_1 * 1000);
  219. }
  220. else {
  221. if (this._redBagInfo.progress < this._redBagInfo.totalProgress && !this._redBagInfo.isFreeRedBag && this._redBagInfo.freeRedBagCount <= 0) {
  222. this._btnOpen.children[0].active = true;
  223. this._btnOpen.children[1].getComponent(cc.Button).enableAutoGrayEffect = true;
  224. this._btnClose.opacity = 0;
  225. var timeout_2 = Utils_1.utils.ServerConfig.red_bag_close_btn_show_delay ? Utils_1.utils.ServerConfig.red_bag_close_btn_show_delay : 0;
  226. setTimeout(function () {
  227. Utils_1.utils.showLog("拆红包关闭按钮延迟显示 " + timeout_2 + "秒显示!");
  228. _this._btnClose.runAction(cc.fadeIn(0.3));
  229. }, timeout_2 * 1000);
  230. }
  231. else {
  232. this._btnClose.active = false;
  233. }
  234. }
  235. this._totalMoneyLbl.string = "\u7D2F\u8BA1\u83B7\u5F97\u73B0\u91D1" + this._redBagInfo.totalMoney + "\u5143";
  236. };
  237. OpenRedBagPanel.prototype.initData = function (showType) {
  238. this._show_type = showType;
  239. };
  240. OpenRedBagPanel.prototype.show = function () {
  241. this.node.active = true;
  242. };
  243. OpenRedBagPanel.prototype.hide = function () {
  244. // console.log(utils.rewardCloseFunc, "<<callFUnc");
  245. // this._panel.runAction(cc.sequence(cc.moveTo(0.3, CompatibleTool.position(-this._panel.getContentSize().width, 0)).easing(cc.easeQuadraticActionOut()), cc.callFunc(() => {
  246. this.node.active = false;
  247. Utils_1.utils.rewardCloseFunc && Utils_1.utils.rewardCloseFunc();
  248. if (Utils_1.utils.rewardCloseFunc) {
  249. Utils_1.utils.rewardCloseFunc = null;
  250. }
  251. // })));
  252. // if (!PlatUtils.IsNativeAndroid) {
  253. // utils.adManager.ShowBanner(BannerLocation.Home);
  254. // }
  255. };
  256. OpenRedBagPanel.prototype.onCloseBtnHandler = function (event, data) {
  257. this.hide();
  258. };
  259. OpenRedBagPanel = __decorate([
  260. ccclass
  261. ], OpenRedBagPanel);
  262. return OpenRedBagPanel;
  263. }(cc.Component));
  264. exports.default = OpenRedBagPanel;
  265. cc._RF.pop();