redBag.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. const ADSdk = require("ADSdk");
  2. cc.Class({
  3. extends: cc.Component,
  4. properties: {
  5. closeBtn_kaiUI: cc.Node,
  6. openBtn_kaiUI: cc.Node,
  7. closeBtn: cc.Node,
  8. tixianBtn: cc.Node,
  9. sureBtn: cc.Node,
  10. uiNode: [cc.Node], // 0开红包界面 1红包已到账界面 2get UI 3left UI 4提现界面
  11. curMoneyLabel: cc.Label,
  12. getMoneyLabel: cc.Label,
  13. moneyTip: cc.Node,
  14. // 提现界面
  15. returnBtn: cc.Node,
  16. tiXianBtn_1: cc.Node,
  17. itemParent: cc.Node,
  18. moneyLabelTiXian: cc.Label,
  19. iconSpriteFrame: [cc.SpriteFrame],
  20. videoTip:cc.Node,
  21. },
  22. // LIFE-CYCLE CALLBACKS:
  23. onLoad() {
  24. this.closeBtn_kaiUI.on("click", this._closeKaiUI, this);
  25. this.openBtn_kaiUI.on("click", this._open, this);
  26. this.closeBtn.on("click", this._close, this);
  27. this.tixianBtn.on("click", this.showMoneyTip, this);
  28. this.sureBtn.on("click", this.closeMoneyTip, this);
  29. this.returnBtn.on("click", this._return, this);
  30. this.tiXianBtn_1.on("click", this._tixian, this);
  31. this.selectedId = 0;
  32. this.tipLabel = this.moneyTip.getChildByName("tipLabel").getComponent(cc.Label);
  33. this.moneyNumArr = ["0.03", "20.00", "30.00", "50.00", "100.00", "200.00"];
  34. },
  35. init(id, c) {
  36. if (c) this.controller = c;
  37. this.node.active = true;
  38. this.closeMoneyTip();
  39. this.showUI(id);
  40. },
  41. _close() {
  42. // 恢复初始
  43. // this.uiNode[0].active = true;
  44. // this.uiNode[1].active = true;
  45. // this.uiNode[2].active = true;
  46. // this.uiNode[3].y = 0;
  47. this.node.active = false;
  48. // TODO 广告 关闭原生广告/插屏广告
  49. },
  50. _open() {
  51. if (AppConst.SHOWADUI) {
  52. let videoAD = AppConst.probabilityConfig.videoAD;
  53. if (AppConst.CHANNEL == AppConst.channel.ANDROID) {
  54. if (this.playVidepNum < videoAD.redBagUI.probability) {
  55. // this.videoTip.active = true;
  56. this.openBtn_kaiUI.getComponent(cc.Button).interactable = false;
  57. ADSdk.pay(10, this);
  58. } else {
  59. // this.videoTip.active = false;
  60. this.openRedBag();
  61. }
  62. } else {
  63. if (this.playVidepNum < videoAD.redBagUI.probability) {
  64. // this.videoTip.active = true;
  65. this.openBtn_kaiUI.getComponent(cc.Button).interactable = false;
  66. ADSdk.showVideo(null, (result) => {
  67. if (result == 1) {
  68. this.openRedBag();
  69. }
  70. });
  71. } else {
  72. // this.videoTip.active = false;
  73. this.openRedBag();
  74. }
  75. }
  76. } else {
  77. this.openRedBag();
  78. }
  79. },
  80. openRedBag() {
  81. let moneyNum = Utils.getRedPacketNum();
  82. // 0.00 -- 20.00 0 -- 2000
  83. this.addNum = 0;
  84. let min = 1, max = 50;
  85. if (moneyNum >= 19) {
  86. this.addNum = 0.01;
  87. } else {
  88. this.addNum = Utils.randomNum(min, max) / 100;
  89. }
  90. if (moneyNum + this.addNum < 20) {
  91. Utils.addRedPacketNum(this.addNum);
  92. Utils.clearRedPacket();
  93. this.init(1);
  94. }
  95. // 更新游戏界面主界面UI
  96. this.controller.startPage.showRedBtn();
  97. this.controller.game.showRedBtn();
  98. },
  99. _closeKaiUI() {
  100. // 动画保存红包 更新 UI
  101. this.controller.startPage.showRedBtn();
  102. this.controller.game.showRedBtn();
  103. this._close();
  104. this.controller.game.closeRedUIAni();
  105. },
  106. // 原生UI
  107. showNativeAdUI(id) {
  108. },
  109. // 0开红包界面 1红包已到账界面 2余额界面 3提现界面
  110. showUI(id) {
  111. let ui = this.node.children[1];
  112. this.uiNode[4].active = false;
  113. ui.scaleX = 0.1;
  114. ui.scaleY = 0.1;
  115. let moneyNum = Utils.getRedPacketNum();
  116. if (moneyNum == 0) moneyNum = "0.00";
  117. switch (id) {
  118. case 0:
  119. this.openBtn_kaiUI.getComponent(cc.Button).interactable = true;
  120. this.uiNode[0].active = true;
  121. this.uiNode[1].active = false;
  122. // TODO 广告 原生广告/插屏广告
  123. let num = Utils.randomNum(0, 100);
  124. let redBagUI = AppConst.probabilityConfig.nativeAD.redBagUI;
  125. let videoAD = AppConst.probabilityConfig.videoAD;
  126. this.playVidepNum = Utils.randomNum(0, 100);
  127. if (this.playVidepNum < videoAD.redBagUI.probability) {
  128. this.videoTip.active = true;
  129. } else {
  130. this.videoTip.active = false;
  131. }
  132. if (num < redBagUI.probability) {
  133. // console.log("==============显示提示");
  134. if (AppConst.SHOWADUI) {
  135. if (AppConst.CHANNEL == AppConst.channel.ANDROID) {
  136. let time = redBagUI.delayTime;
  137. this.scheduleOnce(() => {
  138. ADSdk.pay(8, this);
  139. }, time);
  140. } else {
  141. ADSdk.showInsertAd();
  142. }
  143. }
  144. }
  145. break;
  146. case 1:
  147. this.uiNode[0].active = false;
  148. this.uiNode[1].active = true;
  149. this.uiNode[2].active = true;
  150. this.uiNode[3].y = 0;
  151. this.curMoneyLabel.string = moneyNum + "元";
  152. this.getMoneyLabel.string = this.addNum + "元";
  153. break;
  154. case 2:
  155. this.uiNode[0].active = false;
  156. this.uiNode[1].active = true;
  157. this.uiNode[2].active = false;
  158. this.uiNode[3].y = -80;
  159. this.curMoneyLabel.string = moneyNum + "元";
  160. break;
  161. case 3:
  162. this.uiNode[4].active = true;
  163. this.moneyLabelTiXian.string = moneyNum;
  164. this.showItem();
  165. break;
  166. }
  167. ui.runAction(
  168. cc.sequence(
  169. cc.scaleTo(0.3, 1.1),
  170. cc.scaleTo(0.2, 1)
  171. ));
  172. },
  173. showMoneyTip() {
  174. this.init(3);
  175. },
  176. closeMoneyTip() {
  177. this.moneyTip.active = false;
  178. },
  179. showItem() {
  180. for (let i = 0; i < this.itemParent.childrenCount; i++) {
  181. this.itemParent.children[i].getComponent("itemMoney").init(this, i);
  182. }
  183. },
  184. showTip(str,newStr) {
  185. let des = "红包金额达到" + str + "元方可提现"
  186. if(newStr) des = str;
  187. this.tipLabel.string = des;
  188. this.moneyTip.active = true;
  189. },
  190. _return() {
  191. this._close();
  192. },
  193. _tixian() {
  194. if (this.selectedId != 0) {
  195. this.showTip(this.moneyNumArr[this.selectedId]);
  196. return;
  197. }
  198. if (window.newPlayer) {
  199. let moneyNum = Utils.getRedPacketNum();
  200. if (moneyNum >= 0.03) {
  201. // 提现
  202. // QQApi.createRed((result) => {
  203. // if (result == 1) {
  204. // window.newPlayer = false;
  205. // Utils.reduceRedPacketNum(0.03);
  206. // this.itemParent.children[0].active = false;
  207. // let src = this.itemParent.children[1].getComponent("itemMoney");
  208. // src.iconSprite.spriteFrame = this.iconSpriteFrame[1];
  209. // moneyNum = Utils.getRedPacketNum();
  210. // this.moneyLabelTiXian.string = moneyNum;
  211. // this.showTip("恭喜您,提现成功",true);
  212. // }else{
  213. // this.showTip("系统繁忙,请稍后再试!",true);
  214. // }
  215. // });
  216. }else{
  217. this.showTip(0.03);
  218. }
  219. } else {
  220. // this.moneyTip.active = true;
  221. this.showTip(this.moneyNumArr[this.selectedId]);
  222. }
  223. }
  224. // update (dt) {},
  225. });