Turnable.ts 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import BtnClosePanel from "../../component/BtnClosePanel";
  2. import { AdFun } from "../../data/AdData";
  3. import TurnableItem from "./TurnableItem";
  4. const { ccclass, property } = cc._decorator;
  5. /**
  6. * 转盘
  7. * @author 邹勇
  8. */
  9. @ccclass
  10. export default class Turnable extends cc.Component {
  11. @property(cc.Node)
  12. node_turn: cc.Node = null;
  13. @property(cc.Node)
  14. node_items: cc.Node[] = [];
  15. @property(cc.Node)
  16. btn_draw: cc.Node = null;
  17. @property(cc.Sprite)
  18. btn_close: cc.Sprite = null;
  19. @property(cc.RichText)
  20. lbl_left: cc.RichText = null;
  21. private audioId: number;
  22. onLoad() {
  23. this.initData();
  24. }
  25. /**
  26. * 初始化奖励和抽奖次数
  27. */
  28. private initData() {
  29. if (gData.turnable.config) {
  30. for (let i = 0; i < gData.turnable.config.length; i++) {
  31. let sc = this.node_items[i].getComponent(TurnableItem);
  32. sc.initData(gData.turnable.config[i].type);
  33. }
  34. }
  35. gData.turnable.requestData();
  36. this.updateLeftTimes();
  37. }
  38. /** 点击抽奖 */
  39. clickDraw() {
  40. if (gData.turnable.leftTimes > 0) {
  41. mk.ad.watchAd((success: boolean) => {
  42. mk.console.log("watchAD:" + success);
  43. if (success) {
  44. gData.adData.watchVideo(AdFun.turntable);
  45. }
  46. });
  47. }
  48. }
  49. private async play() {
  50. this.audioId = await mk.audio.playEffect("turnableplay", true);
  51. this.btn_close.getComponent(BtnClosePanel).block_click = true;
  52. this.node_turn.angle = 1800;
  53. let index = 2;
  54. let tar = index * 60;
  55. cc.tween(this.node_turn)
  56. .to(5, { angle: tar }, { easing: 'expoInOut' })
  57. .call(this.playOver, this).start();
  58. }
  59. private playOver() {
  60. mk.audio.stopEffect(this.audioId);
  61. this.btn_close.getComponent(BtnClosePanel).block_click = false;
  62. this.updateLeftTimes();
  63. mk.ui.openPanel("module/reward/reward");
  64. }
  65. updateLeftTimes() {
  66. this.lbl_left.string = `剩余:<color=#FFED99>${gData.turnable.leftTimes}</color>次`;
  67. }
  68. update() {
  69. if (gData.turnable.requestFinish) {
  70. this.updateLeftTimes();
  71. gData.turnable.requestFinish = false;
  72. }
  73. if (gData.turnable.adData) {
  74. this.play();
  75. gData.reward.data = gData.turnable.adData;
  76. gData.turnable.adData = null;
  77. }
  78. }
  79. onDestroy() {
  80. }
  81. }