BtnClosePanel.ts 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  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. onLoad() {
  14. if (!this.node.getComponent(cc.Button)) this.node.addComponent(cc.Button);
  15. }
  16. start() {
  17. this.node.on('click', this.closePanel, this);
  18. }
  19. private async closePanel() {
  20. if (this.node_panel) {
  21. mk.ui.closePanel(this.node_panel.name);
  22. }
  23. const c_count = this.onComplete.length;
  24. for (let i = 0; i < c_count; i++) {
  25. if (this.onComplete[i].handler) this.onComplete[i].emit([])
  26. }
  27. }
  28. // update (dt) {}
  29. }