BtnClosePanel.ts 1.2 KB

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