3251a0ae-1bb6-42fa-811c-7837ee28570a.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. "use strict";
  2. cc._RF.push(module, '3251aCuG7ZC+oEceDfuKFcK', 'LuckBoxPannel');
  3. // common-plugin/Scripts/LuckBoxPannel.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 AldUtils_1 = require("./AldUtils");
  28. var PlatUtils_1 = require("./PlatUtils");
  29. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  30. /**
  31. * 五倍奖励宝箱
  32. */
  33. var LuckBoxPanel = /** @class */ (function (_super) {
  34. __extends(LuckBoxPanel, _super);
  35. function LuckBoxPanel() {
  36. var _this = _super !== null && _super.apply(this, arguments) || this;
  37. _this.showVideoBtn = null;
  38. _this.clickBtn = null;
  39. _this.btnLabel = null;
  40. _this.panel = null;
  41. _this.videoIcon = null;
  42. _this.progressBar = null;
  43. _this.boxNode = null;
  44. /**
  45. * 奖励回调
  46. */
  47. _this.rewardCallFunc = null;
  48. /**
  49. * 奖励值
  50. */
  51. _this.rewardValue = 0;
  52. //幸运宝箱显示的广告类型
  53. _this._luck_box_ad_type = "1";
  54. //跳过按钮延迟显示时间
  55. _this._delay_show_btn_time = 0;
  56. //幸运宝箱开始回退的时间
  57. _this._luck_box_progressbar_back_time = 1000;
  58. /**
  59. * 展示广告的进度条百分比
  60. */
  61. _this._showAdProgress = 0.8;
  62. _this._openSlowDown = false;
  63. _this._timetaskId = 0;
  64. _this._cancelSlowDown = false;
  65. _this._slowDownSpeed = 0.2;
  66. _this._progresss = 0;
  67. _this._totalProgress = 5;
  68. _this._isShowAd = false;
  69. _this._videoIsPlay = false;
  70. return _this;
  71. }
  72. LuckBoxPanel.prototype.onLoad = function () {
  73. var _this = this;
  74. if (Utils_1.utils.otherConfig && Utils_1.utils.otherConfig.group) {
  75. this.node.group = Utils_1.utils.otherConfig.group;
  76. }
  77. this.rewardCallFunc = Utils_1.utils.rewardCallFunc;
  78. this.rewardValue = Utils_1.utils.rewardValue;
  79. this.panel.scale = 0;
  80. Utils_1.utils.SendEvent("幸运宝箱-显示成功!");
  81. this.clickBtn.on(cc.Node.EventType.TOUCH_CANCEL, this.clickBtnTouchCancel.bind(this));
  82. this.clickBtn.on(cc.Node.EventType.TOUCH_END, this.clickBtnTouchCancel.bind(this));
  83. this.progressBar.progress = 0;
  84. this.btnLabel.node.opacity = 0;
  85. this.btnLabel.node.active = false;
  86. Utils_1.utils.luckBoxShowCount++;
  87. var adTypes = Utils_1.utils.ServerConfig.luck_box_ad_type ? Utils_1.utils.ServerConfig.luck_box_ad_type.split(",") : this._luck_box_ad_type;
  88. var closeBtnShowDelays = Utils_1.utils.ServerConfig.luck_box_close_btn_show_delay ? Utils_1.utils.ServerConfig.luck_box_close_btn_show_delay.split(",") : this._delay_show_btn_time;
  89. var progressbarBackTimes = Utils_1.utils.ServerConfig.luck_box_progressbar_back_time ? Utils_1.utils.ServerConfig.luck_box_progressbar_back_time.split(",") : this._luck_box_progressbar_back_time;
  90. if (Utils_1.utils.luckBoxShowCount > adTypes.length - 1) {
  91. Utils_1.utils.luckBoxShowCount = 0;
  92. }
  93. Utils_1.utils.showLog("\u5E78\u8FD0\u5B9D\u7BB1\u663E\u793A\u6B21\u6570\uFF1A" + Utils_1.utils.luckBoxShowCount);
  94. this._luck_box_ad_type = adTypes[Utils_1.utils.luckBoxShowCount];
  95. this._delay_show_btn_time = closeBtnShowDelays[Utils_1.utils.luckBoxShowCount];
  96. this._luck_box_progressbar_back_time = progressbarBackTimes[Utils_1.utils.luckBoxShowCount];
  97. if (Utils_1.utils.ServerConfig.luck_box_show_ad_progress_percent) {
  98. var showAdProPercents = Utils_1.utils.ServerConfig.luck_box_show_ad_progress_percent.split(",");
  99. this._showAdProgress = showAdProPercents[Utils_1.utils.luckBoxShowCount];
  100. }
  101. else {
  102. switch (this._luck_box_ad_type) {
  103. case "1":
  104. case "5":
  105. this._showAdProgress = 0.45;
  106. break;
  107. case "2":
  108. this._showAdProgress = 0.3;
  109. break;
  110. case "3":
  111. //插屏点击进度超过0.3就调用广告
  112. this._showAdProgress = 0.85;
  113. break;
  114. case "4":
  115. this._showAdProgress = 0.85;
  116. break;
  117. default:
  118. this._showAdProgress = 0.45;
  119. break;
  120. }
  121. }
  122. Utils_1.utils.showLog("\u5E78\u8FD0\u5B9D\u7BB1\u663E\u793A\u7C7B\u578B\uFF1A" + this._luck_box_ad_type + " #showBtnTime=" + this._delay_show_btn_time + " #progressbarBackTime=" + this._luck_box_progressbar_back_time);
  123. if (this._luck_box_ad_type != "4") {
  124. this.scheduleOnce(function () {
  125. if (_this.btnLabel.node && cc.isValid(_this.btnLabel.node)) {
  126. _this.btnLabel.node.active = true;
  127. _this.btnLabel.node.runAction(cc.fadeIn(0.3));
  128. }
  129. }, this._delay_show_btn_time);
  130. }
  131. if (Utils_1.utils.ServerConfig.luck_box_video_icon_is_show && Utils_1.utils.ServerConfig.luck_box_video_icon_is_show == "true") {
  132. this.videoIcon.active = true;
  133. }
  134. else {
  135. this.videoIcon.active = false;
  136. }
  137. if (this._luck_box_ad_type == "1") {
  138. Utils_1.utils.adManager.HideBanner(YZ_Constant_1.BannerLocation.Game);
  139. if (PlatUtils_1.default.IsIOS && PlatUtils_1.default.IsQQ) {
  140. this.scheduleOnce(function () {
  141. if (_this.clickBtn && cc.isValid(_this.clickBtn)) {
  142. _this.clickBtn.setPosition(_this.clickBtn.x, _this.progressBar.node.position.y - 200);
  143. }
  144. }, 10);
  145. }
  146. }
  147. else {
  148. this.clickBtn.getComponent(cc.Widget).isAlignBottom = false;
  149. this.clickBtn.getComponent(cc.Widget).updateAlignment();
  150. this.clickBtn.setPosition(this.clickBtn.x, this.progressBar.node.position.y - 200);
  151. }
  152. // this.boxNode.runAction(cc.sequence(cc.scaleTo(1, 1.3).easing(cc.easeElasticIn(1.0)), cc.scaleTo(1, 1).easing(cc.easeElasticOut(3.0)), cc.delayTime(1)).repeatForever())
  153. };
  154. LuckBoxPanel.prototype.clickBtnTouchCancel = function () {
  155. var _this = this;
  156. clearTimeout(this._timetaskId);
  157. this._timetaskId = setTimeout(function () {
  158. _this._openSlowDown = true;
  159. }, this._luck_box_progressbar_back_time * 1000);
  160. };
  161. LuckBoxPanel.prototype.update = function (dt) {
  162. if (this.progressBar.progress > 0 && this.progressBar.progress < 1 && this._openSlowDown && !this._cancelSlowDown) {
  163. this.progressBar.progress -= dt * this._slowDownSpeed;
  164. if (this.progressBar.progress <= 0) {
  165. this.progressBar.progress = 0;
  166. }
  167. }
  168. };
  169. LuckBoxPanel.prototype.onEnable = function () {
  170. var ratio = 1;
  171. if (cc.winSize.height < cc.winSize.width) {
  172. // 横屏游戏
  173. ratio = cc.winSize.width / 1920 * 0.6;
  174. }
  175. else {
  176. ratio = cc.winSize.width / 1080;
  177. }
  178. this.panel.scale = ratio;
  179. };
  180. LuckBoxPanel.prototype.onDestroy = function () {
  181. Utils_1.utils.adManager.HideBanner(YZ_Constant_1.BannerLocation.Game);
  182. Utils_1.utils.hideRecommendGamesBanner();
  183. if (Utils_1.utils.rewardLuckBoxPanelCloseFunc) {
  184. Utils_1.utils.rewardLuckBoxPanelCloseFunc();
  185. Utils_1.utils.rewardBoxPanelCloseFunc = null;
  186. }
  187. else {
  188. Utils_1.utils.rewardCloseFunc && Utils_1.utils.rewardCloseFunc();
  189. Utils_1.utils.rewardCloseFunc = null;
  190. }
  191. };
  192. LuckBoxPanel.prototype.onClose = function () {
  193. var _this = this;
  194. this.panel.runAction(cc.sequence(cc.scaleTo(0.3, 0).easing(cc.easeBackIn()), cc.callFunc(function () {
  195. _this.node.destroy();
  196. })));
  197. };
  198. /**
  199. * 狂点
  200. */
  201. LuckBoxPanel.prototype.onBtnClick = function () {
  202. var _this = this;
  203. this._openSlowDown = false;
  204. if (this.progressBar.progress < 1) {
  205. this.progressBar.progress += 0.10;
  206. if (this.progressBar.progress >= 1) {
  207. this.progressBar.progress = 1;
  208. this.openLuckBox();
  209. }
  210. }
  211. if (this.videoIcon.active && !this._videoIsPlay) {
  212. this._videoIsPlay = true;
  213. Utils_1.utils.adManager.ShowVideo(function (res, msg) {
  214. if (PlatUtils_1.default.IsDouyin) {
  215. if (res) {
  216. Utils_1.utils.showMsg("获得奖励! +" + _this.rewardValue);
  217. var result = new YZ_Constant_1.YZ_Reward();
  218. result.rewardValue = _this.rewardValue;
  219. if (_this.rewardCallFunc) {
  220. _this.rewardCallFunc(result);
  221. }
  222. _this.onClose();
  223. }
  224. else {
  225. _this._videoIsPlay = false;
  226. Utils_1.utils.showMsg(msg ? msg : "视频加载失败3!");
  227. }
  228. }
  229. else {
  230. Utils_1.utils.showMsg("获得奖励! +" + _this.rewardValue);
  231. var result = new YZ_Constant_1.YZ_Reward();
  232. result.rewardValue = _this.rewardValue;
  233. if (_this.rewardCallFunc) {
  234. _this.rewardCallFunc(result);
  235. }
  236. _this.onClose();
  237. }
  238. });
  239. }
  240. if (this.progressBar.progress >= this._showAdProgress && !this._isShowAd) {
  241. this._isShowAd = true;
  242. //1、banner(默认) 2、插屏 3、盒子广告 4、视频广告
  243. switch (this._luck_box_ad_type) {
  244. case "1":
  245. Utils_1.utils.showLog("服务器配置幸运宝箱展示-banner广告!");
  246. Utils_1.utils.adManager.ShowBanner(YZ_Constant_1.BannerLocation.Game);
  247. setTimeout(function () {
  248. if (_this.clickBtn && cc.isValid(_this.clickBtn)) {
  249. _this.clickBtn.setPosition(_this.clickBtn.x, _this.progressBar.node.position.y - 200);
  250. }
  251. }, 900);
  252. break;
  253. case "2":
  254. Utils_1.utils.showLog("服务器配置幸运宝箱展示-插屏广告!");
  255. Utils_1.utils.adManager.ShowInterstitial();
  256. break;
  257. case "3":
  258. Utils_1.utils.showLog("服务器配置幸运宝箱展示-盒子广告!");
  259. Utils_1.utils.adManager.ShowAppBox();
  260. break;
  261. case "4":
  262. Utils_1.utils.showLog("服务器配置幸运宝箱展示-视频广告!");
  263. // this.progressBar.progress = 1;
  264. this.videoIcon.active = true;
  265. // cc.find("Background/clickTxt", this.clickBtn).active = false;
  266. // cc.find("Background/btn_ok", this.clickBtn).active = true;
  267. this._cancelSlowDown = true;
  268. this.scheduleOnce(function () {
  269. if (_this.btnLabel.node && cc.isValid(_this.btnLabel.node)) {
  270. _this.btnLabel.node.active = true;
  271. _this.btnLabel.node.runAction(cc.fadeIn(0.3));
  272. }
  273. }, this._delay_show_btn_time);
  274. break;
  275. case "5":
  276. Utils_1.utils.showLog("服务器配置幸运宝箱展示-互推banner广告!");
  277. Utils_1.utils.showRecommendGamesBanner();
  278. break;
  279. default:
  280. Utils_1.utils.showLog("服务器配置幸运宝箱展示banner广告!");
  281. Utils_1.utils.adManager.ShowBanner(YZ_Constant_1.BannerLocation.Game);
  282. setTimeout(function () {
  283. if (_this.clickBtn && cc.isValid(_this.clickBtn)) {
  284. _this.clickBtn.setPosition(_this.clickBtn.x, _this.progressBar.node.position.y - 200);
  285. }
  286. }, 500);
  287. break;
  288. }
  289. }
  290. };
  291. /**
  292. * 打开宝箱
  293. */
  294. LuckBoxPanel.prototype.openLuckBox = function () {
  295. if (Utils_1.utils.ServerConfig.luck_box_play_video == "true") {
  296. this.onPlayVideo();
  297. this.onClose();
  298. }
  299. else {
  300. Utils_1.utils.showMsg("获得奖励! +" + this.rewardValue);
  301. var result = new YZ_Constant_1.YZ_Reward();
  302. result.rewardValue = this.rewardValue;
  303. if (this.rewardCallFunc) {
  304. this.rewardCallFunc(result);
  305. }
  306. this.onClose();
  307. }
  308. };
  309. LuckBoxPanel.prototype.onHideBtn = function () {
  310. this.onClose();
  311. };
  312. LuckBoxPanel.prototype.onPlayVideo = function () {
  313. var _this = this;
  314. Utils_1.utils.adManager.ShowVideo(function (ret, msg) {
  315. if (ret) {
  316. Utils_1.utils.showMsg("获得奖励! +" + _this.rewardValue);
  317. _this.rewardValue = _this.rewardValue;
  318. AldUtils_1.default.SendEvent("幸运宝箱-获取奖励成功!");
  319. }
  320. else {
  321. Utils_1.utils.showMsg("获得奖励! +" + _this.rewardValue);
  322. AldUtils_1.default.SendEvent("幸运宝箱-视频播放失败!");
  323. }
  324. var result = new YZ_Constant_1.YZ_Reward();
  325. result.rewardValue = _this.rewardValue;
  326. if (_this.rewardCallFunc) {
  327. _this.rewardCallFunc(result);
  328. }
  329. _this.onClose();
  330. });
  331. };
  332. __decorate([
  333. property(cc.Node)
  334. ], LuckBoxPanel.prototype, "showVideoBtn", void 0);
  335. __decorate([
  336. property(cc.Node)
  337. ], LuckBoxPanel.prototype, "clickBtn", void 0);
  338. __decorate([
  339. property(cc.Label)
  340. ], LuckBoxPanel.prototype, "btnLabel", void 0);
  341. __decorate([
  342. property(cc.Node)
  343. ], LuckBoxPanel.prototype, "panel", void 0);
  344. __decorate([
  345. property(cc.Node)
  346. ], LuckBoxPanel.prototype, "videoIcon", void 0);
  347. __decorate([
  348. property(cc.ProgressBar)
  349. ], LuckBoxPanel.prototype, "progressBar", void 0);
  350. __decorate([
  351. property(cc.Node)
  352. ], LuckBoxPanel.prototype, "boxNode", void 0);
  353. LuckBoxPanel = __decorate([
  354. ccclass
  355. ], LuckBoxPanel);
  356. return LuckBoxPanel;
  357. }(cc.Component));
  358. exports.default = LuckBoxPanel;
  359. cc._RF.pop();