Turnable.ts 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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(sp.Skeleton)
  14. spine_light: sp.Skeleton = null;
  15. @property(cc.Sprite)
  16. btn_close: cc.Sprite = null;
  17. @property(cc.RichText)
  18. lbl_left: cc.RichText = null;
  19. private audioId:number;
  20. onLoad() {
  21. this.initData();
  22. }
  23. /**
  24. * 初始化奖励和抽奖次数
  25. */
  26. private initData() {
  27. if (gData.turnable.config) {
  28. for (let i = 0; i < gData.turnable.config.length; i++) {
  29. let sc = this.node_items[i].getComponent(TurnableItem);
  30. sc.initData(gData.turnable.config[i].type);
  31. }
  32. }
  33. this.updateLeftTimes();
  34. }
  35. /** 点击抽奖 */
  36. clickDraw() {
  37. if (gData.turnable.leftTimes > 0) {
  38. gData.adData.watchVideo(AdFun.turntable);
  39. }
  40. }
  41. private async play() {
  42. this.audioId = await mk.audio.playEffect("turnableplay", true);
  43. this.btn_close.getComponent(BtnClosePanel).block_click = true;
  44. this.node_turn.angle = 1800;
  45. let index = 2;
  46. let tar = index * 60;
  47. cc.tween(this.node_turn)
  48. .to(5, { angle: tar }, { easing: 'expoInOut' })
  49. .call(this.playOver, this).start();
  50. }
  51. private playOver() {
  52. mk.audio.stopEffect(null);
  53. this.btn_close.getComponent(BtnClosePanel).block_click = false;
  54. this.updateLeftTimes();
  55. mk.ui.openPanel("module/reward/reward");
  56. }
  57. updateLeftTimes() {
  58. this.lbl_left.string = `剩余:<color=#FFED99>${gData.turnable.leftTimes}</color>次`;
  59. }
  60. update() {
  61. if (gData.turnable.requestFinish) {
  62. this.updateLeftTimes();
  63. gData.turnable.requestFinish = false;
  64. }
  65. if (gData.turnable.adData) {
  66. this.play();
  67. gData.reward.data = gData.turnable.adData;
  68. gData.turnable.adData = null;
  69. }
  70. }
  71. onDestroy() {
  72. }
  73. }