RedeemNode.ts 8.9 KB

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