redBag.js 9.1 KB

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