GetDiamondRedBox.ts 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. import { _decorator, Component, Node, LabelAtlas, Label, EventHandler, find, Sprite } from 'cc';
  2. import { Http } from '../core/net/Http';
  3. import { OpenWindow } from '../core/ui/window/OpenWindow';
  4. import { Window } from '../core/ui/window/Window';
  5. import { WindowManager } from '../core/ui/window/WindowManager';
  6. import { WindowOpenMode } from '../core/ui/window/WindowOpenMode';
  7. import { g } from '../Data/g';
  8. import { UIEffect } from '../Main/UIEffect';
  9. import { LoginWaitWin } from './LoginWaitWin';
  10. import { NoviceWindow } from './NoviceWindow';
  11. const { ccclass, property } = _decorator;
  12. @ccclass('GetDiamondRedBox')
  13. export class GetDiamondRedBox extends Component {
  14. @property({ tooltip: "神石文本", type: Node }) public diamondTxt: Node;
  15. @property({ tooltip: "现金文本", type: Node }) public moneyTxt: Node;
  16. @property({ tooltip: "双倍领取图标", type: Node }) public doubleIcon: Node;
  17. @property({ tooltip: "领取图标", type: Node }) public getIcon: Node;
  18. @property({ tooltip: "http服务", type: Http }) public http: Http;
  19. @property({ tooltip: "关闭按钮", type: Node }) public closeBtn: Node;
  20. @property({ tooltip: "单倍直接领取", type: Node }) public getBtn: Node;
  21. @property({ tooltip: "玩家昵称", type: Label }) public nameTxt: Label;
  22. public closeBackFun: EventHandler;
  23. public addDiamond: number = 0;//领取神石数目
  24. public get2LvRedPath = "/wealth/ReceiveLvRedPacketForTwo";//二级红包URL
  25. public lvRedType = -1;//红包类型,-1:非等级红包;0:2级红包;1:2级以上红包需要视频领取
  26. start() {
  27. this.nameTxt.string = g.userData.nickName;
  28. g.gameData.isPlayVideo = false;
  29. }
  30. /**
  31. * 设置界面信息
  32. * @param data 0:获得神石数值
  33. * 1:界面关闭回调方法
  34. * 2:有数据为等級红包(-1:非等级红包,0:2级红包,1:2级以上红包需要视频领取)
  35. */
  36. public setData(data: any[]) {
  37. this.addDiamond = data[0];
  38. this.diamondTxt.getComponent(Label).string = this.addDiamond + "神石";
  39. // this.diamondTxt.getComponent(Label).string = "(=" + this.addDiamond + "神石)";
  40. this.moneyTxt.getComponent(Label).string = this.addDiamond / 10000 + "元";
  41. if (data[1]) {
  42. this.closeBackFun = data[1];
  43. }
  44. switch (data[2]) {
  45. case 0:
  46. this.doubleIcon.active = true;
  47. this.getIcon.active = false;
  48. this.closeBtn.active = false;
  49. this.lvRedType = data[2];
  50. this.getBtn.active = true;
  51. break;
  52. case 1:
  53. this.doubleIcon.active = true;
  54. this.getIcon.active = false;
  55. this.closeBtn.active = true;
  56. this.lvRedType = data[2];
  57. this.getBtn.active = true;
  58. break;
  59. }
  60. }
  61. public isSend = false;
  62. //领取按键
  63. public async getDiamond() {
  64. if (g.gameData.isPlayVideo) {
  65. return;
  66. }
  67. g.gameData.isPlayVideo = true;
  68. switch (this.lvRedType) {//红包类型,-1:非等级红包,0:2级红包,1:2级以上红包需要视频领取
  69. case 0:
  70. let data = await this.http.send("/api/ad/WatchVideoAD");
  71. switch (data.code) {
  72. case 0:
  73. //播放视频
  74. let adData = await g.showRewardVideo();
  75. if (adData) {
  76. this.videoBack();
  77. } else {
  78. //视频观看失败
  79. WindowManager.showTips("视频观看时间不足");
  80. }
  81. break;
  82. case 108:
  83. WindowManager.showTips("今日视频次数已用完,请明日再继续");
  84. g.gameData.isPlayVideo = false;
  85. break;
  86. default:
  87. // WindowManager.showTips(g.CodeMsg[data.code]);
  88. WindowManager.showTips("视频准备中,请稍后再试");
  89. g.gameData.isPlayVideo = false;
  90. break;
  91. }
  92. break;
  93. case 1:
  94. let data0 = await this.http.send("/api/ad/WatchVideoAD");
  95. switch (data0.code) {
  96. case 0:
  97. //播放视频
  98. let adData = await g.showRewardVideo();
  99. if (adData) {
  100. this.videoBack();
  101. } else {
  102. //视频观看失败
  103. WindowManager.showTips("视频观看时间不足");
  104. }
  105. break;
  106. case 108:
  107. WindowManager.showTips("今日视频次数已用完,请明日再继续");
  108. g.gameData.isPlayVideo = false;
  109. break;
  110. default:
  111. // WindowManager.showTips(g.CodeMsg[data.code]);
  112. WindowManager.showTips("视频准备中,请稍后再试");
  113. g.gameData.isPlayVideo = false;
  114. break;
  115. }
  116. break;
  117. default:
  118. this.close();
  119. break;
  120. }
  121. }
  122. //视频结束回调,等级红包
  123. public async videoBack() {
  124. //#region 打开加载等待界面
  125. let _window = await WindowManager.open("Prefabs/Windows/加载等待窗口", WindowOpenMode.NotCloseAndCover);
  126. //#endregion
  127. let data = await this.http.send("/api/lvRedPacket/ReceiveLvRedPacket", { type: 2, adData: g.adData });
  128. _window.getComponent(LoginWaitWin).close();//关闭加载等待界面
  129. if (data.code == 0) {
  130. this.addDiamond = data.data.addDiamond;
  131. g.gameData.lvRedPacket = data.data.receiveLv;
  132. this.close();
  133. } else {
  134. WindowManager.showTips(g.CodeMsg[data.code]);
  135. this.closeBtn.active = true;
  136. g.gameData.isPlayVideo = false;
  137. }
  138. }
  139. //少量领取
  140. public async toGetDiamond() {
  141. if (g.gameData.isPlayVideo) {
  142. return;
  143. }
  144. g.gameData.isPlayVideo = true;
  145. //#region 打开加载等待界面
  146. let _window = await WindowManager.open("Prefabs/Windows/加载等待窗口", WindowOpenMode.NotCloseAndCover);
  147. //#endregion
  148. let data = await this.http.send("/api/lvRedPacket/ReceiveLvRedPacket", { type: 1, adData: g.adData });
  149. _window.getComponent(LoginWaitWin).close();//关闭加载等待界面
  150. switch (data.code) {
  151. case 0:
  152. this.addDiamond = data.data.addDiamond;
  153. g.gameData.lvRedPacket = data.data.receiveLv;
  154. this.close();
  155. break;
  156. default:
  157. WindowManager.showTips(g.CodeMsg[data.code]);
  158. this.closeBtn.active = true;
  159. g.gameData.isPlayVideo = false;
  160. break;
  161. }
  162. }
  163. public async close() {
  164. if (this.addDiamond > 0) {
  165. // this.addDiamond = 0;//测试
  166. let times = this.addDiamond > 10 ? 10 : this.addDiamond;
  167. let _window = await WindowManager.open("Prefabs/Windows/货币飞行控制器", WindowOpenMode.NotCloseAndAdd);
  168. _window.getComponent(UIEffect).changeDiamond(this.addDiamond, times);
  169. _window.getComponent(UIEffect).showEffect(0, times);
  170. }
  171. this.closeBackFun && this.closeBackFun.emit([]);
  172. this.toClose();
  173. }
  174. //直接关闭窗口
  175. public toClose() {
  176. this.getComponent(Window).close();
  177. }
  178. onDestroy() {
  179. g.gameData.isPlayVideo = false;
  180. }
  181. }