BtnClosePanel.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. const { ccclass, property } = cc._decorator;
  2. /**
  3. * 关闭指定面板
  4. * @author 薛鸿潇
  5. */
  6. @ccclass
  7. export default class BtnClosePanel extends cc.Component {
  8. @property({ displayName: '关闭界面', tooltip: '', type: cc.Node })
  9. private node_panel: cc.Node = null!;;
  10. @property({ displayName: '完成回调', tooltip: "面板打开完成后触发", type: cc.Component.EventHandler })
  11. public onComplete: cc.Component.EventHandler[] = [];
  12. /** 阻断点击 */
  13. public block_click: boolean = false;
  14. onLoad() {
  15. if (!this.node.getComponent(cc.Button)) this.node.addComponent(cc.Button);
  16. }
  17. start() {
  18. this.node.on('click', this.closePanel, this);
  19. }
  20. private async closePanel() {
  21. if (this.block_click) return;
  22. if (this.node_panel) {
  23. mk.ui.closePanel(this.node_panel.name);
  24. }
  25. const c_count = this.onComplete.length;
  26. for (let i = 0; i < c_count; i++) {
  27. if (this.onComplete[i].handler) this.onComplete[i].emit([])
  28. }
  29. }
  30. // update (dt) {}
  31. }