BtnOpenPanel.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  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 BtnOpenPanel extends cc.Component {
  9. @property({ displayName: '界面名字', tooltip: '对应路径:resources/prefab/uiPanel/' })
  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: 'game游戏界面,module模块界面', type: cc.Enum(PanelType) })
  14. private panel_type = PanelType.module;
  15. @property({ displayName: '完成回调', tooltip: "面板打开完成后触发", type: cc.Component.EventHandler })
  16. public onComplete: cc.Component.EventHandler[] = [];
  17. onLoad() {
  18. if (!this.node.getComponent(cc.Button)) this.node.addComponent(cc.Button);
  19. }
  20. start() {
  21. this.node.on('click', this.openPanel, this);
  22. }
  23. private async openPanel() {
  24. await mk.ui.openPanel(this.panel_name, this.panel_type, this.open_type);
  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. }