BtnOpenPanel.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. const { ccclass, property } = cc._decorator;
  2. import { OpenActionType } from '../../mk/system/UISystem';
  3. /**
  4. * 打开指定名字的面板
  5. * @author 薛鸿潇
  6. */
  7. @ccclass
  8. export default class BtnOpenPanel extends cc.Component {
  9. @property({ displayName: '预制体路径', tooltip: '对应路径:resources/' })
  10. private panel_name = '';
  11. @property({ displayName: '打开类型', tooltip: 'normal不操作,closeOther关闭其他,closeLast关闭上一个', type: cc.Enum(OpenActionType) })
  12. private open_type = OpenActionType.normal;
  13. @property({ displayName: '点击效果', tooltip: "仅支持 NONE 和 SCALE", type: cc.Enum(cc.Button.Transition) })
  14. public transition_type: cc.Button.Transition = cc.Button.Transition.NONE;
  15. @property({ displayName: '完成回调', tooltip: "面板打开完成后触发", type: cc.Component.EventHandler })
  16. public onComplete: cc.Component.EventHandler[] = [];
  17. onLoad() {
  18. if (!this.node.getComponent(cc.Button)) {
  19. let btn_comp = this.node.addComponent(cc.Button);
  20. btn_comp.transition = this.transition_type;
  21. }
  22. }
  23. start() {
  24. this.node.on('click', this.openPanel, this);
  25. }
  26. private async openPanel() {
  27. mk.audio.playEffect("button");
  28. if (!this.panel_name) return;
  29. await mk.ui.openPanel(this.panel_name, this.open_type);
  30. const c_count = this.onComplete.length;
  31. for (let i = 0; i < c_count; i++) {
  32. if (this.onComplete[i].handler) this.onComplete[i].emit([])
  33. }
  34. }
  35. // update (dt) {}
  36. }