RedeemNode.ts 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /**
  2. * @description 兑换码界面
  3. * @author kaka
  4. */
  5. const { ccclass, property } = cc._decorator;
  6. @ccclass
  7. export default class RichHelpPanel extends cc.Component {
  8. @property(cc.Label)
  9. txtTitle: cc.Label = null;
  10. @property(cc.Label)
  11. txtGiftName: cc.Label = null;
  12. @property(cc.Node)
  13. rds: cc.Node[] = [];
  14. @property(cc.Sprite)
  15. rd_imgs: cc.Sprite[] = [];
  16. @property(cc.Label)
  17. rd_txts: cc.Label[] = [];
  18. @property(cc.EditBox)
  19. inputBox: cc.EditBox = null;
  20. @property(cc.Node)
  21. suc_node: cc.Node = null;
  22. @property(cc.Node)
  23. suc_node_panel: cc.Node = null;
  24. @property(cc.Node)
  25. suc_rds: cc.Node[] = [];
  26. @property(cc.Sprite)
  27. suc_rd_imgs: cc.Sprite[] = [];
  28. @property(cc.Label)
  29. suc_rd_txts: cc.Label[] = [];
  30. videoNode = null;
  31. rewardData: any = null;
  32. update() {
  33. if (gData.redeem.init_redeemData) {
  34. this.InitData();
  35. }
  36. }
  37. lateUpdate() {
  38. gData.redeem.init_redeemData = false;
  39. }
  40. InitData() {
  41. let data = gData.redeem.redeemData.redemption;
  42. this.txtTitle.string = data.title;
  43. this.txtGiftName.string = data.title;
  44. this.rewardData = data.content;
  45. for (let n of this.rds) {
  46. n.active = false;
  47. }
  48. for (let m of this.suc_rds) {
  49. m.active = false;
  50. }
  51. for (let i = 0; i < this.rewardData.length; i++) {
  52. this.rds[i].active = true;
  53. this.suc_rds[i].active = true;
  54. cc.loader.loadRes("xiyou/icon/reward" + this.rewardData[i].type, cc.SpriteFrame, (err, res) => {
  55. if (err) { console.log("img load err:" + JSON.stringify(err)); }
  56. this.rd_imgs[i].spriteFrame = res;
  57. this.suc_rd_imgs[i].spriteFrame = res;
  58. });
  59. if (this.rewardData[i].type == "10001") {
  60. this.rd_txts[i].string = mk.math.format(this.rewardData[i].count) + "分钟";
  61. this.suc_rd_txts[i].string = mk.math.format(this.rewardData[i].count) + "分钟";
  62. } else {
  63. this.rd_txts[i].string = mk.math.format(this.rewardData[i].count);
  64. this.suc_rd_txts[i].string = mk.math.format(this.rewardData[i].count);
  65. }
  66. }
  67. }
  68. async Click_RedeemBtn() {
  69. console.log("---RedeemCode: " + this.inputBox.string);
  70. if (this.inputBox.string != "") {
  71. let response = await gData.redeem.redeemExchange(this.inputBox.string);
  72. if (response && response.data.code == 1) {
  73. console.log("兑换成功");
  74. this.suc_node_panel.scale = 0;
  75. this.suc_node.active = true;
  76. cc.tween(this.suc_node_panel).to(0.2, { scale: 1 }, { easing: "backOut" }).start();
  77. }
  78. else {
  79. mk.tip.pop(response.data.msg);
  80. }
  81. } else {
  82. mk.tip.pop('请输入兑换码');
  83. }
  84. }
  85. coolTime = false
  86. /** 点击教程 */
  87. async Click_TeachBtn() {
  88. GameM.audioM.playEffect(AUDIO_TYPE.button)
  89. if (this.coolTime) {
  90. return
  91. }
  92. this.coolTime = true
  93. console.log('clickTeach')
  94. GameM.commonData.teachVideoType = 2;
  95. let temp = await Utils.loadResPromise('prefabs/VideoNode')
  96. this.videoNode = cc.instantiate(temp)
  97. this.videoNode.getChildByName('video').on("completed", this.onCompleted, this)
  98. this.node.addChild(this.videoNode)
  99. }
  100. onCompleted() {
  101. this.videoNode.getChildByName('video').off("completed", this.onCompleted, this)
  102. this.videoNode.destroy()
  103. //西游
  104. GameM.audioM.setTempEffect(true)
  105. GameController.Ins.SwitchAudio(1)
  106. //GameM.audioM.setResumeMusic()
  107. this.coolTime = false
  108. }
  109. /** 点击复制公众号 */
  110. clickCopyOfficial() {
  111. GameM.audioM.playEffect(AUDIO_TYPE.button)
  112. AdM.setClipboard("白羊游戏社")
  113. }
  114. /** 点击复制礼包名 */
  115. clickCopyInfo() {
  116. GameM.audioM.playEffect(AUDIO_TYPE.button)
  117. AdM.setClipboard(this.txtTitle.string)
  118. }
  119. Click_CloseBtn() {
  120. UiM.Instance.offPanel(PANEL_NAME.RedeemNode);
  121. //let classnew: any = cc.js.getClassByName("CashOut");
  122. //console.log("-->: " + classnew);
  123. }
  124. async Click_GetBtn() {
  125. this.suc_node.active = false;
  126. let richDice: any = null;
  127. for (let i = 0; i < this.rewardData.length; i++) {
  128. if (this.rewardData[i].type == "10001") {
  129. let coinNum = Sciencen_M.instance.accMul(GameM.commonData.goldSecond.toString(), (Number(this.rewardData[i].count) * 60).toString());
  130. GameM.commonData.updateGold(coinNum);
  131. GameM.audioM.playEffect(AUDIO_TYPE.getGold, false);
  132. EffectNode.instance.PlayCoinAnim(0, 5, cc.v2(0, -300));
  133. } else if (this.rewardData[i].type == "10002") {
  134. GameM.commonData.updateRedMoney(Number(this.rewardData[i].count))
  135. EffectNode.instance.PlayCoinAnim(1, 5, cc.v2(0, -300));
  136. } else if (this.rewardData[i].type == "20002") {
  137. GameM.commonData.roleData.turntableCard += Number(this.rewardData[i].count);
  138. EffectNode.instance.PlayCoinAnim(11, 5, cc.v2(0, -300));
  139. } else if (this.rewardData[i].type == "20001") {
  140. GameM.commonData.roleData.speedCard += Number(this.rewardData[i].count);
  141. EffectNode.instance.PlayCoinAnim(10, 5, cc.v2(0, -300));
  142. } else if (this.rewardData[i].type == "20003") {
  143. GameM.commonData.roleData.ticket += Number(this.rewardData[i].count);
  144. EffectNode.instance.PlayCoinAnim(12, 5, cc.v2(0, -300));
  145. } else if (this.rewardData[i].type == "20006") {
  146. MateData.Ins.talentCoin += Number(this.rewardData[i].count)
  147. GameM.httpM.SendData(HTTP_TYPE.updateBattleStoneCount, { "count": MateData.Ins.talentCoin })
  148. EffectNode.instance.PlayCoinAnim(13, 5, cc.v2(0, -300));
  149. } else if (this.rewardData[i].type == "30001") {
  150. if (richDice == null) richDice = {};
  151. richDice.diceAdNum = Number(this.rewardData[i].count);
  152. EffectNode.instance.PlayCoinAnim(6, 5, cc.v2(0, -300));
  153. } else if (this.rewardData[i].type == "30002") {
  154. if (richDice == null) richDice = {};
  155. richDice.remoteCtrlNum = Number(this.rewardData[i].count);
  156. EffectNode.instance.PlayCoinAnim(7, 5, cc.v2(0, -300));
  157. } else if (this.rewardData[i].type == "30004") {
  158. if (richDice == null) richDice = {};
  159. richDice.scriptureNum = Number(this.rewardData[i].count);
  160. EffectNode.instance.PlayCoinAnim(9, 5, cc.v2(0, -300));
  161. } else if (this.rewardData[i].type == "30005") {
  162. if (richDice == null) richDice = {};
  163. richDice.doubleNum = Number(this.rewardData[i].count);
  164. EffectNode.instance.PlayCoinAnim(8, 5, cc.v2(0, -300));
  165. }
  166. }
  167. if (richDice != null) {
  168. //进入取经战斗 前提就是满足奖励条件下
  169. RichData.Ins.UpdateItemCard2(richDice, null, false);
  170. }
  171. let response = await gData.redeem.redeemGetRedemption();
  172. if (response && response.data.code == 1) {
  173. this.InitData();
  174. }
  175. else {
  176. }
  177. // HttpM.Instance.SendData(HTTP_TYPE.redeemGetRedemption, {}, (res) => {
  178. // console.log("--->RedeemGift RedeemPanel:", res);
  179. // if (res.data != null && res.errcode == 0) {
  180. // GameM.commonData.redeemData = res.data;
  181. // UiM.Instance.hallNode.getComponent(Main).redeemBtn.active = res.data.code == 1;
  182. // if (res.data.code == 1) {
  183. // this.InitData();
  184. // } else {
  185. // UiM.Instance.offPanel(PANEL_NAME.RedeemNode);
  186. // }
  187. // } else {
  188. // UiM.Instance.offPanel(PANEL_NAME.RedeemNode);
  189. // }
  190. // });
  191. // AdM.onSendEvent('duihuan_success', '兑换码-兑换成功', 'duihuan')
  192. }
  193. }