Turnable.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import BtnClosePanel from "../../../component/BtnClosePanel";
  2. import { AdFun } from "../../../data/AdData";
  3. import TurnableItem from "./TurnableItem";
  4. const { ccclass, property } = cc._decorator;
  5. @ccclass
  6. export default class Turnable extends cc.Component {
  7. @property(cc.Node)
  8. node_turn: cc.Node = null;
  9. @property(cc.Node)
  10. node_items: cc.Node[] = [];
  11. @property(cc.Node)
  12. btn_draw: cc.Node = null;
  13. @property(cc.Sprite)
  14. btn_close: cc.Sprite = null;
  15. @property(cc.RichText)
  16. lbl_left: cc.RichText = null;
  17. onLoad() {
  18. this.initData();
  19. }
  20. /**
  21. * 初始化奖励和抽奖次数
  22. */
  23. private initData() {
  24. for (let i = 0; i < this.node_items.length; i++) {
  25. let sc = this.node_items[i].getComponent(TurnableItem);
  26. sc.initData((i % 3 + 1) + "");
  27. }
  28. this.updateLeftTimes();
  29. }
  30. /** 点击抽奖 */
  31. clickDraw() {
  32. if (gData.turnable.leftTimes > 0) {
  33. gData.adData.watchVideo(AdFun.turntable);
  34. }
  35. }
  36. private play() {
  37. this.btn_close.getComponent(BtnClosePanel).block_click = true;
  38. this.node_turn.angle = 1800;
  39. let index = 2;
  40. let tar = index * 60;
  41. cc.tween(this.node_turn)
  42. .to(5, { angle: tar }, { easing: 'expoInOut' })
  43. .call(this.playOver, this).start();
  44. }
  45. private playOver() {
  46. this.btn_close.getComponent(BtnClosePanel).block_click = false;
  47. this.updateLeftTimes();
  48. mk.ui.openPanel("module/reward/reward");
  49. }
  50. updateLeftTimes() {
  51. this.lbl_left.string = `剩余:<color=#FFED99>${gData.turnable.leftTimes}</color>次`;
  52. }
  53. update() {
  54. if (gData.turnable.adData) {
  55. this.play();
  56. gData.reward.data = gData.turnable.adData;
  57. gData.turnable.adData = null;
  58. }
  59. }
  60. onDestroy() {
  61. }
  62. }