RewardedPanel.ts 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /**
  2. * 代码描述
  3. */
  4. import { Audio } from "../../common/src/Audio";
  5. import { GameDataCenter } from "../../common/src/GameDataCenter";
  6. import { UIManager } from "../../common/src/UIManager";
  7. import { Utils } from "../../common/src/Utils";
  8. const { ccclass, property } = cc._decorator;
  9. @ccclass
  10. export class RewardedPanel extends cc.Component {
  11. @property({ type: cc.Prefab, tooltip: '奖励预制体' })
  12. itemPrefab: cc.Prefab = null;
  13. @property({ type: cc.Node, tooltip: '物品节点' })
  14. item: cc.Node = null;
  15. @property({ type: [cc.SpriteFrame], tooltip: '奖励集合\n0.炸弹\n1.激光\n2.七色\n3.闪电\n4.金币' })
  16. itemSpriteFrame: cc.SpriteFrame[] = [];
  17. private type: number[] = [];
  18. private num: number[] = [];
  19. private ui: string[] = ['special1', 'special2', 'special3', 'special4', 'coin'];
  20. onEnable() {
  21. //初始化面板
  22. this.node.getChildByName('panel').getChildByName('closeButton').on('click', this.onClose, this);
  23. this.node.getChildByName('panel').getChildByName('doubleGet').on('click', this.onDoubleGet, this);
  24. for (let i = 0; i < GameDataCenter.rewarded.length; i++) {
  25. let array = GameDataCenter.rewarded[i].split(':');
  26. let type: number = +array[0];
  27. let num: number = +array[1];
  28. this.type.push(type);
  29. this.num.push(num);
  30. let node = cc.instantiate(this.itemPrefab);
  31. node.parent = this.item;
  32. node.getComponent(cc.Sprite).spriteFrame = this.itemSpriteFrame[type];
  33. node.children[0].getComponent(cc.Label).string = `:${num}`;
  34. node.scale = 0;
  35. cc.tween(node)
  36. .to(0.3, { scale: 1 })
  37. .start();
  38. cc.systemEvent.emit('updateUI', this.ui[type], num);
  39. }
  40. //背景动画
  41. cc.tween(this.node.getChildByName('panel').getChildByName('bg'))
  42. .by(0.05, { angle: 1 })
  43. .repeatForever()
  44. .start();
  45. //面板缩放
  46. Utils.openPanel(this.node.getChildByName('panel'));
  47. //按钮跳动
  48. Utils.btnTween(this.node.getChildByName('panel').getChildByName('doubleGet'));
  49. }
  50. /**关闭 */
  51. private onClose(): void {
  52. Audio.playSoundByPath('rewarded:res/snd/click');
  53. UIManager.close('rewarded:RewardedPanel', true);
  54. }
  55. /**双倍领取 */
  56. private onDoubleGet(): void {
  57. Audio.playSoundByPath('rewarded:res/snd/click');
  58. for (let i = 0; i < this.type.length; i++) {
  59. cc.systemEvent.emit('updateUI', this.ui[this.type[i]], this.num[i]);
  60. }
  61. this.onClose();
  62. }
  63. }