ToGetGoldWin.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. import { _decorator, instantiate, Component, Node, TERRAIN_SOUTH_INDEX, Label, UITransform, Widget, Prefab, math } from 'cc';
  2. import { OpenWindow } from '../core/ui/window/OpenWindow';
  3. import { ResourcesUtils } from '../core/resourceManager/ResourcesUtils';
  4. import { RotatingLightAnim } from '../SpecialEffects/RotatingLightAnim';
  5. import { StarAnim } from '../SpecialEffects/StarAnim';
  6. import { FsUtils } from "../FsUtils/FsUtils";
  7. import { Http } from '../core/net/Http';
  8. import { g } from '../Data/g';
  9. import { WindowManager } from '../core/ui/window/WindowManager';
  10. import { LoginWaitWin } from './LoginWaitWin';
  11. import { WindowOpenMode } from '../core/ui/window/WindowOpenMode';
  12. import { MultipleType } from '../Data/ADData';
  13. import { ADHelper } from '../ADHelper';
  14. const { ccclass, property } = _decorator;
  15. @ccclass('ToGetGoldWin')
  16. export class ToGetGoldWin extends Component {
  17. @property({ tooltip: "窗口标题", type: Node }) public title: Node;
  18. @property({ tooltip: "当天剩余的领取次数", type: Node }) public getGoldTimes: Node;
  19. @property({ tooltip: "不看视频,领取少量金币", type: Node }) public getLittleGold: Node;
  20. @property({ tooltip: "视频观看按键,显示文字内容", type: Node }) public videoBtnTxt: Node;
  21. @property({ tooltip: "视频观看按键", type: Node }) public videoBtn: Node;
  22. @property({ tooltip: "界面关闭按钮", type: Node }) public closeBtn: Node;
  23. @property({ tooltip: "界面展示窗口", type: Node }) public windowBox: Node;
  24. @property({ tooltip: "离线文字box", type: Node }) public offlineTile: Node;
  25. @property({ tooltip: "离线时间文本", type: Node }) public offlineTime: Node;
  26. @property({ tooltip: "奖励金币box", type: Node }) public offlineMoneyBox: Node;
  27. @property({ tooltip: "奖励金币txt", type: Node }) public offlineMoney: Node;
  28. @property({ tooltip: "金币不足专用按钮", type: Node }) public videoBtn0: Node;
  29. @property({ tooltip: "光效预制体根目录" }) public lightEfficiency = '';
  30. @property({ tooltip: "旋转光效父节点", type: Node }) public turnLight: Node;
  31. @property({ tooltip: "星星特效预制体根目录" }) public starEfficiency = '';
  32. @property({ tooltip: "星星特效节点", type: Node }) public starEffects: Node;
  33. @property({ tooltip: "http服务", type: Http }) public http: Http;
  34. @property({ tooltip: "广告控制器", type: Node }) public AD: Node;
  35. public uiData: any[];
  36. public multiple = 1;//视频金币倍数
  37. public windowType = [//0:飞行宝箱,1:离线收益,2:金币不足
  38. {
  39. isShowClosebtn: false,
  40. title: "获取金币奖励",
  41. bgWidth: 660,
  42. bgHeight: 660,
  43. isShowGetTimes: true,
  44. isShowGetLittleGold: true,
  45. videoBtnBottom: -18,
  46. isShowOfflineTime: false,
  47. http: MultipleType.FlyBox,
  48. isShowVideoBtn: false
  49. },
  50. {
  51. isShowClosebtn: true,
  52. title: "离线收益",
  53. bgWidth: 600,
  54. bgHeight: 750,
  55. isShowGetTimes: false,
  56. isShowGetLittleGold: false,
  57. videoBtnBottom: -80,
  58. isShowOfflineTime: true,
  59. http: MultipleType.OffLine,
  60. isShowVideoBtn: false
  61. },
  62. {
  63. isShowClosebtn: true,
  64. title: "金币不足",
  65. bgWidth: 600,
  66. bgHeight: 660,
  67. isShowGetTimes: false,
  68. isShowGetLittleGold: false,
  69. videoBtnBottom: -18,
  70. isShowOfflineTime: false,
  71. http: MultipleType.LessMoney,
  72. isShowVideoBtn: true
  73. },
  74. ];
  75. start() {
  76. // this.initUI(1, "");
  77. g.gameData.isPlayVideo = false;
  78. }
  79. /**
  80. * 加载光效
  81. */
  82. public async addLigthEffects() {
  83. let prefabsData = await ResourcesUtils.load<Prefab>(this.lightEfficiency, null, this.node);
  84. var lightNode = instantiate(prefabsData);
  85. lightNode.parent = this.turnLight;
  86. let rotatingLight = lightNode.getComponent(RotatingLightAnim);
  87. rotatingLight.set_Data(800, 800, 0.3, false, "light");
  88. }
  89. /**
  90. * 加载星星特效
  91. */
  92. public async addStar() {
  93. for (let i = 0; i < 25; i++) {
  94. let prefabsData = await ResourcesUtils.load<Prefab>(this.starEfficiency, null, this.node);
  95. var starNode = instantiate(prefabsData);
  96. starNode.parent = this.starEffects;
  97. let starAnim = starNode.getComponent(StarAnim);
  98. let wrapMode = Math.random() < 0.5 ? 38 : 2;
  99. let startTime = Math.random() * 3;
  100. let _size = this.starEffects.getComponent(UITransform).contentSize;
  101. let tempWidth = Math.random() * _size.width;
  102. let temp_x = tempWidth > _size.width / 2 ?
  103. -(tempWidth - (_size.width / 2)) : tempWidth;
  104. let tempHeight = Math.random() * _size.height;
  105. let temp_y = tempHeight > _size.height / 2 ?
  106. -(tempHeight - (_size.height / 2)) : tempHeight;
  107. starAnim.setData(wrapMode, startTime, temp_x, temp_y, Math.random() * 1.3, "star1");
  108. }
  109. }
  110. /**
  111. * @zh 获取金币视频弹窗初始化
  112. * @param data 0:(0:飞行宝箱,1:离线奖励,2:金币不足看视频领金币);
  113. * 1:可领取金币金额;
  114. * 2:翻倍领取倍数;
  115. * 3:离线时间(非离线奖励可不填)
  116. */
  117. public initUI(data: any[]) {
  118. this.uiData = data;
  119. let uiData = this.windowType[data[0]];
  120. this.closeBtn.active = uiData.isShowClosebtn;
  121. this.title.getComponent(Label).string = uiData.title;
  122. this.windowBox.getComponent(UITransform).setContentSize(uiData.bgWidth, uiData.bgHeight);
  123. this.getGoldTimes.active = uiData.isShowGetTimes;
  124. this.getLittleGold.active = uiData.isShowGetLittleGold;
  125. this.videoBtn.getComponent(Widget).bottom = uiData.videoBtnBottom;
  126. this.videoBtn0.active = uiData.isShowVideoBtn;
  127. this.videoBtn.active = !uiData.isShowVideoBtn;
  128. if (uiData.isShowVideoBtn) {
  129. this.AD.destroy();
  130. }
  131. //获取界面相关文本
  132. if (uiData.isShowGetTimes) {
  133. this.getGoldTimes.getComponent(Label).string = "今日剩余领取次数:" + g.gameData.flyBoxTimes;
  134. }
  135. if (data[2]) {
  136. this.videoBtnTxt.getComponent(Label).string = data[2] + "倍领取";
  137. this.multiple = data[2];
  138. }
  139. this.offlineMoney.getComponent(Label).string = FsUtils.moneyFormat(data[1]);
  140. if (uiData.isShowOfflineTime) {
  141. this.offlineMoneyBox.getComponent(Widget).bottom = 40;
  142. this.offlineTile.getComponent(Widget).bottom = 130;
  143. var tempMin = Math.floor(data[3] / 60) % 60;
  144. var tempHour = Math.floor((Math.floor(data[3] / 60) - tempMin) / 60);
  145. tempHour = tempHour > 2 ? 2 : tempHour;
  146. var tempText = tempHour > 0 ? "您已离线" + tempHour + "小时" : "您已离线";
  147. if (tempHour != 2) {
  148. tempText = tempMin > 0 ? tempText + tempMin + "分钟" : tempText;
  149. }
  150. this.offlineTime.getComponent(Label).string = tempText;
  151. } else {
  152. this.offlineMoneyBox.getComponent(Widget).bottom = 112;
  153. this.offlineTile.active = false;
  154. }
  155. this.addLigthEffects();
  156. this.addStar();
  157. }
  158. public isSend = false;
  159. // 播放视频
  160. public async playVideo() {
  161. if (g.gameData.isPlayVideo) {
  162. return;
  163. }
  164. g.gameData.isPlayVideo = true;
  165. //#region 打开加载等待界面
  166. let _window = await WindowManager.open("Prefabs/Windows/加载等待窗口", WindowOpenMode.NotCloseAndCover);
  167. let data = await this.http.send("/api/ad/WatchVideoAD");//观看视频起始
  168. _window.getComponent(LoginWaitWin).close();//关闭加载等待界面
  169. switch (data.code) {
  170. case 0:
  171. //播放视频
  172. let adData = await g.showRewardVideo();
  173. if (adData) {
  174. this.videoBack();
  175. } else {
  176. //视频观看失败
  177. WindowManager.showTips("视频观看时间不足");
  178. }
  179. break;
  180. case 108:
  181. WindowManager.showTips("今日视频次数已用完,请明日再继续");
  182. g.gameData.isPlayVideo = false;
  183. break;
  184. default:
  185. WindowManager.showTips("视频准备中,请稍后再试");
  186. // WindowManager.showTips(g.CodeMsg[data.code]);
  187. // this.close();
  188. g.gameData.isPlayVideo = false;
  189. break;
  190. }
  191. }
  192. //视频结束回调
  193. public async videoBack() {
  194. //#region 打开加载等待界面
  195. let _window = await WindowManager.open("Prefabs/Windows/加载等待窗口", WindowOpenMode.NotCloseAndCover);
  196. //#endregion
  197. let data = await this.http.send("/api/wealth/AddDiamondForVideo", { multipleType: this.windowType[this.uiData[0]].http, adData: g.adData })
  198. _window.getComponent(LoginWaitWin).close();//关闭加载等待界面
  199. if (data.code == 0) {//视频观看成功
  200. if (data.data.addDiamond > 0) {
  201. this.getComponent(OpenWindow).prefabPath = "Prefabs/Windows/神石领取界面";
  202. let _window = this.getComponent(OpenWindow);
  203. _window.open([data.data.addDiamond, 0, [this.uiData[1] * this.multiple, this.uiData[0]]]);
  204. WindowManager.close(this.node);
  205. } else {
  206. WindowManager.open("Prefabs/Windows/金币领取窗口", WindowOpenMode.CloseAndAdd, [this.uiData[1] * this.multiple, this.uiData[0]])
  207. WindowManager.close(this.node);
  208. }
  209. } else {
  210. g.gameData.isPlayVideo = false;
  211. WindowManager.showTips(g.CodeMsg[data.code]);
  212. }
  213. }
  214. //未看视频领取
  215. public setGoldData() {
  216. let _window = this.getComponent(OpenWindow);
  217. _window.open([this.uiData[1], this.uiData[0]]);
  218. }
  219. //直接关闭窗口,离线奖励点击关闭按钮也会领取金币
  220. public close() {
  221. if (this.uiData[0] == 1) {
  222. let _window = this.getComponent(OpenWindow);
  223. _window.open([this.uiData[1], this.uiData[0]]);
  224. WindowManager.close(this.node);
  225. } else {
  226. WindowManager.close(this.node);
  227. }
  228. }
  229. onDestroy() {
  230. g.gameData.isPlayVideo = false;
  231. }
  232. }