AdRbPanel.ts 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. import { TuCaoData } from "../datas/TuCaoData";
  2. import GameM, { AUDIO_TYPE, VIDEO_TYPE } from "../manager/GameM";
  3. import GuideMng from "../manager/GuideMng";
  4. import AdRbItem from "../other/item/AdRbItem";
  5. import BasePanel from "../uiFrames/BasePanel";
  6. import UIMng, { PanelType } from "../uiFrames/UIMng";
  7. import EffectNode from "./EffectNode";
  8. const { ccclass, property } = cc._decorator;
  9. @ccclass
  10. export default class AdRbPanel extends BasePanel {
  11. @property(cc.Label)
  12. txtBigNum: cc.Label = null;
  13. @property(cc.Label)
  14. txtAddEft: cc.Label = null;
  15. @property(cc.RichText)
  16. txtTipAd: cc.RichText = null;
  17. @property(cc.RichText)
  18. txtBigDelta: cc.RichText = null;
  19. @property(cc.RichText)
  20. txtBigTask: cc.RichText = null;
  21. @property(cc.RichText)
  22. txtRemaindAdNum: cc.RichText = null;
  23. @property(AdRbItem)
  24. adRbItem: AdRbItem = null;
  25. @property(cc.Node)
  26. itemContent: cc.Node = null;
  27. @property(cc.Node)
  28. btnCash: cc.Node = null;
  29. @property(cc.Node)
  30. btnAd: cc.Node = null;
  31. @property(cc.Animation)
  32. aniBigAdBtn: cc.Animation = null;
  33. @property(cc.Node)
  34. adIcon: cc.Node = null;
  35. @property(cc.Animation)
  36. aniBtnAd: cc.Animation = null;
  37. @property(cc.Node)
  38. rbOpenBtn: cc.Node = null;
  39. @property(cc.Node)
  40. nodeRb: cc.Node = null;
  41. @property(cc.Label)
  42. txtRbNum: cc.Label = null;
  43. @property(cc.Node)
  44. nodeHelp: cc.Node = null;
  45. @property(cc.Node)
  46. testNode: cc.Node = null;
  47. @property(cc.EditBox)
  48. inputBox: cc.EditBox = null;
  49. @property(cc.Node)
  50. cashSurePanel: cc.Node = null;
  51. @property(cc.Label)
  52. cashSureTxtNum: cc.Label = null;
  53. //@property(cc.Node)
  54. //panelNode: cc.Node = null;
  55. private isInit: boolean = false
  56. /**红包页面类型 1 大额 2 任务*/
  57. private rbPanelType: number = 0;
  58. private adrbArray: AdRbItem[] = [];
  59. onLoad() {
  60. this.testNode.active = GameM.commonData.globalCfg.VideoRedBagEmpty == 1;
  61. }
  62. OnEnter() {
  63. //this.panelNode.scale = 0;
  64. this.node.active = true;
  65. //cc.tween(this.panelNode).to(0.2, { scale: 1 }, { easing: "backOut" })
  66. // .call(() => {
  67. //
  68. // })
  69. // .start();
  70. if (!this.isInit) {
  71. TuCaoData.Ins.adRbPanel = this;
  72. }
  73. this.isPlayAni = false;
  74. this.UpdateInfo(false, true);
  75. if (GuideMng.Ins.CurGuideId == 28)
  76. GuideMng.Ins.ResumeGuide();
  77. }
  78. OnExit() {
  79. this.node.active = false;
  80. if (this.adrbArray.length >= 4) {
  81. for (let i = 0; i < this.adrbArray.length; i++) {
  82. this.adrbArray[i].OnExit();
  83. }
  84. }
  85. }
  86. update(dt) {
  87. this.PlayMoneyAniUpdate(dt);
  88. }
  89. UpdateInfo(isPlayAni: boolean = false, isPlayInitAni: boolean = false) {
  90. let data = TuCaoData.Ins.videoRbData;
  91. this.targetProgress = data.cumulativeAmount;
  92. this.txtBigDelta.node.active = data.showTask != 1;
  93. this.txtBigTask.node.active = data.showTask == 1;
  94. this.txtTipAd.string = data.showTask == 1 ? "提现中..." : "<b>满<color=#FFE00C>" + data.requestAmount + "元</color>可提现</b>";
  95. //this.txtBigNum.string = data.cumulativeAmount + "元";
  96. this.txtBigDelta.string = "<outline color=#8C1010 width=4><b>每次视频额外奖励<color=#FFE00C>" + data.videoAmountPerTime + "元</color></b></outline>";
  97. this.txtBigTask.string = "<outline color=#8C1010 width=4>金额已达标,完成<color=#4EB7FF>观看视频</color>任务可到账"
  98. + "\n观看视频次数:<color=#FFE00C>" + data.taskVideoWatchTime + "/" + data.taskVideoTime + "</color>,连续观看天数:<color=#FFE00C>" + data.taskVideoWatchDay + "/" + data.taskVideoDay + "</color></outline>"
  99. this.txtRemaindAdNum.string = "<b>今日剩余次数:<color=#B02D29>" + data.videoTime + "</color></b>";
  100. this.adIcon.active = data.needToWatchTheVideo == 1;
  101. if (isPlayAni) {
  102. if (this.lastNum < data.cumulativeAmount) {
  103. EffectNode.instance.PlayCoinAnim(1, 10, this.btnAd.getPosition(), true, this.btnCash.getPosition(), () => {
  104. this.aniBigAdBtn.setCurrentTime(0);
  105. this.aniBigAdBtn.play();
  106. });
  107. this.txtAddEft.node.setPosition(cc.v2(0, 380));
  108. this.txtAddEft.string = "+" + data.videoAmountPerTime + "元";
  109. this.txtAddEft.node.stopAllActions();
  110. this.txtAddEft.node.scale = 0;
  111. this.txtAddEft.node.opacity = 255;
  112. this.txtAddEft.node.active = true;
  113. let a0 = cc.delayTime(0.8);
  114. let a1t = cc.sequence(cc.scaleTo(0.15, 1.2), cc.scaleTo(0.15, 1));
  115. let a1a = cc.spawn(cc.moveBy(0.3, cc.v2(0, 30)), a1t);
  116. let a2 = cc.delayTime(0.5);
  117. let a3 = cc.fadeOut(0.15);
  118. let a4 = cc.callFunc(() => {
  119. //this.txtBigNum.string = data.cumulativeAmount + "元";
  120. this.PlayMoneyAni(0.2);
  121. this.txtAddEft.node.active = false;
  122. });
  123. this.txtAddEft.node.runAction(cc.sequence(a0, a1a, a2, a3, a4));
  124. } else {
  125. this.txtBigNum.string = data.cumulativeAmount.toFixed(2) + "元";
  126. this.lastNum = data.cumulativeAmount;
  127. }
  128. } else {
  129. this.txtBigNum.string = data.cumulativeAmount.toFixed(2) + "元";
  130. this.lastNum = data.cumulativeAmount;
  131. }
  132. let isFourProFinish = true;
  133. if (this.adrbArray.length < 4) {
  134. this.adrbArray = [];
  135. this.itemContent.removeAllChildren();
  136. for (let i = 0; i < data.redMonies.length; i++) {
  137. let copyitem = cc.instantiate(this.adRbItem.node);
  138. copyitem.active = true;
  139. this.itemContent.addChild(copyitem);
  140. let copySrc = copyitem.getComponent(AdRbItem);
  141. copySrc.Init(data.redMonies[i], isPlayAni, isPlayInitAni);
  142. this.adrbArray.push(copySrc);
  143. if (data.redMonies[i].progressRate < 100)
  144. isFourProFinish = false;
  145. }
  146. } else {
  147. for (let i = 0; i < data.redMonies.length; i++) {
  148. this.adrbArray[i].Init(data.redMonies[i], isPlayAni, isPlayInitAni);
  149. if (data.redMonies[i].progressRate < 100)
  150. isFourProFinish = false;
  151. }
  152. }
  153. //29 引导大额任务
  154. if (isFourProFinish) {
  155. GuideMng.Ins.CheckAdRbGuide29();
  156. }
  157. }
  158. private isPlayAni = false;
  159. targetProgress: number = 0;
  160. delta: number = 0;
  161. curValue: number = 0;
  162. curTime: number = 0;
  163. totalTime: number = 0;
  164. lastNum: number = 0;
  165. PlayMoneyAni(time) {
  166. this.totalTime = time;
  167. this.delta = (this.targetProgress - this.lastNum) / time;
  168. this.curValue = this.lastNum;
  169. this.curTime = 0;
  170. console.log("--->Update Time: " + time + " delta: " + this.delta + " curValue: " + this.curValue + " lastNum: " + this.lastNum);
  171. this.isPlayAni = true;
  172. }
  173. PlayMoneyAniUpdate(dt) {
  174. if (this.isPlayAni) {
  175. if (this.curTime < this.totalTime) {
  176. this.curTime += dt;
  177. this.curValue += this.delta * dt;
  178. if (this.curValue >= this.targetProgress) {
  179. this.isPlayAni = false;
  180. this.curValue = this.targetProgress;
  181. this.lastNum = this.targetProgress;
  182. }
  183. console.log("-->CurValue:" + this.curValue);
  184. } else {
  185. this.isPlayAni = false;
  186. this.curTime = this.totalTime;
  187. //this.unschedule(this.UpdateAni);
  188. this.curValue = this.targetProgress;
  189. this.lastNum = this.targetProgress;
  190. }
  191. this.txtBigNum.string = this.curValue.toFixed(2) + "元";
  192. }
  193. }
  194. Click_AdProgressBtn() {
  195. if (TuCaoData.Ins.videoRbData.needToWatchTheVideo != 1) {
  196. //免费加进度
  197. TuCaoData.Ins.HttpNoAdProgress((data) => {
  198. this.UpdateInfo(true);
  199. });
  200. } else {
  201. if (TuCaoData.Ins.videoRbData.videoTime > 0) {
  202. GameM.adM.watchVideo(VIDEO_TYPE.adRbProgressAd);
  203. } else {
  204. EffectNode.instance.PlayTip("今日观看次数已用完");
  205. }
  206. }
  207. GameM.audioM.playEffect(AUDIO_TYPE.button);
  208. console.log("--->You Click AdProgressBtn");
  209. }
  210. /**看视频拿红包 增加提现进度回调*/
  211. AdProgressEnd() {
  212. //EffectNode.instance.PlayTip("进度增加成功");
  213. }
  214. /**
  215. * 打开红包页面
  216. * @param type 打开红包类型 1 大额红包 2 任务红包
  217. * @param num 红包金额
  218. */
  219. OpenRbPanel(type: number, num: number) {
  220. this.rbPanelType = type;
  221. this.txtRbNum.string = num + "元";
  222. this.nodeRb.active = true;
  223. this.rbOpenBtn.active = true;
  224. }
  225. CheckCashRedCode() {
  226. let data = TuCaoData.Ins.videoRbData;
  227. if (data.redMoneyCode.length > 0) {
  228. for (let i = 0; i < data.redMoneyCode.length; i++) {
  229. if (data.preLargeAmountCashId == data.redMoneyCode[i].RedMoneyId) {
  230. if (data.redMoneyCode[i].RedMoneyCode != "") {
  231. UIMng.Ins.AsyncGetPanel(PanelType.RedCodePanel, (panel) => {
  232. let num = TuCaoData.Ins.videoRbData.redMoneyCode.length;
  233. panel.OnEnter({ money: data.redMoneyCode[i].VideoCashBig, code: data.redMoneyCode[i].RedMoneyCode });
  234. });
  235. } else {
  236. EffectNode.instance.PlayTip("提现成功");
  237. }
  238. return;
  239. }
  240. }
  241. }
  242. EffectNode.instance.PlayTip("请先完成提现任务");
  243. }
  244. Click_CashBtn() {
  245. console.log("--->You Click CashBtn");
  246. if (TuCaoData.Ins.videoRbData.cumulativeAmount >= TuCaoData.Ins.videoRbData.requestAmount) {
  247. TuCaoData.Ins.HttpCashBig((data) => {
  248. console.log("-->BigRbData:" + JSON.stringify(data));
  249. this.UpdateInfo();
  250. //this.nodeRb.active = false;
  251. if (data.code == 1) {
  252. //弹红包码界面
  253. this.CheckCashRedCode();
  254. } else {
  255. EffectNode.instance.PlayTip("请先完成提现任务");
  256. }
  257. })
  258. } else {
  259. EffectNode.instance.PlayTip("累计到" + TuCaoData.Ins.videoRbData.requestAmount + "元才可提现");
  260. }
  261. //if (TuCaoData.Ins.videoRbData.canCash == 1) {
  262. // TuCaoData.Ins.bigRbNum = TuCaoData.Ins.videoRbData.requestAmount;
  263. // //如果提现条件满足弹出红包界面
  264. // this.OpenRbPanel(1, TuCaoData.Ins.videoRbData.requestAmount);
  265. //} else {
  266. // EffectNode.instance.PlayTip("累计到"+TuCaoData.Ins.videoRbData.requestAmount+"元才可提现");
  267. //}
  268. }
  269. canOpen: boolean = true;
  270. /**红包界面开按钮*/
  271. Click_CashOpenBtn() {
  272. if (!this.canOpen) return;
  273. this.canOpen = false;
  274. if (this.rbPanelType == 1) {
  275. //走不到这 改用Click_CashBtn
  276. TuCaoData.Ins.HttpCashBig((data) => {
  277. console.log("-->BigRbData:" + JSON.stringify(data));
  278. this.UpdateInfo();
  279. this.nodeRb.active = false;
  280. UIMng.Ins.AsyncGetPanel(PanelType.CashProPanel, (panel) => {
  281. panel.OnEnter(TuCaoData.Ins.bigRbNum);
  282. });
  283. })
  284. } else {
  285. //弹确认提现界面
  286. this.rbOpenBtn.active = false;
  287. this.aniBtnAd.node.active = true;
  288. this.aniBtnAd.setCurrentTime(0);
  289. this.aniBtnAd.play();
  290. setTimeout(() => {
  291. //this.aniBtnAd.node.active = false;
  292. this.aniBtnAd.stop();
  293. this.aniBtnAd.node.active = false;
  294. this.rbOpenBtn.active = true;
  295. //this.aniBtnAd.enabled = false;
  296. this.nodeRb.active = false;
  297. this.cashSureTxtNum.string = "¥" + TuCaoData.Ins.taskRbNum;
  298. this.cashSurePanel.active = true;
  299. this.canOpen = true;
  300. }, 1000);
  301. }
  302. }
  303. //提现确认界面 任务红包提现
  304. Click_CashSureBtn() {
  305. //this.cashSurePanel.active = false;
  306. //return;
  307. TuCaoData.Ins.HttpCashTask((data) => {
  308. console.log("-->TaskRbData:" + JSON.stringify(data));
  309. this.UpdateInfo();
  310. this.nodeRb.active = false;
  311. this.cashSurePanel.active = false;
  312. if (data.code == 1) {
  313. UIMng.Ins.AsyncGetPanel(PanelType.CashProPanel, (panel) => {
  314. panel.OnEnter(TuCaoData.Ins.taskRbNum);
  315. });
  316. }
  317. })
  318. }
  319. Click_RedCodeBtn() {
  320. UIMng.Ins.AsyncGetPanel(PanelType.RedCodeListPanel, (panel) => {
  321. panel.OnEnter(60);
  322. });
  323. }
  324. Click_HelpBtn() {
  325. this.nodeHelp.active = true;
  326. GameM.audioM.playEffect(AUDIO_TYPE.button);
  327. }
  328. Click_CloseHelpBtn() {
  329. this.nodeHelp.active = false;
  330. GameM.audioM.playEffect(AUDIO_TYPE.button);
  331. }
  332. Click_InitData() {
  333. TuCaoData.Ins.HttpInitAdRbData();
  334. }
  335. Click_CloseBtn() {
  336. this.OnExit();
  337. GameM.audioM.playEffect(AUDIO_TYPE.button);
  338. }
  339. EditBox_End() {
  340. console.log("-->Input:", this.inputBox.string);
  341. TuCaoData.Ins.adsource_id_value = this.inputBox.string;
  342. }
  343. }