BtnOpenPanel.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. const { ccclass, property } = cc._decorator;
  2. import JsbSystem from '../../mk/system/JsbSystem';
  3. import { OpenActionType } from '../../mk/system/UISystem';
  4. /**
  5. * 打开指定名字的面板
  6. * @author 薛鸿潇
  7. */
  8. @ccclass
  9. export default class BtnOpenPanel extends cc.Component {
  10. @property({ displayName: '预制体路径', tooltip: '对应路径:resources/' })
  11. private panel_name = '';
  12. @property({ displayName: '是否需要微信授权', tooltip: '授权勾选' })
  13. private bool_Auth: boolean = false;
  14. @property({ displayName: '打开类型', tooltip: 'normal不操作,closeOther关闭其他,closeLast关闭上一个', type: cc.Enum(OpenActionType) })
  15. private open_type = OpenActionType.normal;
  16. @property({ displayName: '点击效果', tooltip: "仅支持 NONE 和 SCALE", type: cc.Enum(cc.Button.Transition) })
  17. public transition_type: cc.Button.Transition = cc.Button.Transition.NONE;
  18. @property({ displayName: '完成回调', tooltip: "面板打开完成后触发", type: cc.Component.EventHandler })
  19. public onComplete: cc.Component.EventHandler[] = [];
  20. onLoad() {
  21. if (!this.node.getComponent(cc.Button)) {
  22. let btn_comp = this.node.addComponent(cc.Button);
  23. btn_comp.transition = this.transition_type;
  24. }
  25. }
  26. start() {
  27. this.node.on('click', this.openPanel, this);
  28. }
  29. private async openPanel() {
  30. if(!mk.game.checkContinuousClick(this.node)){
  31. return;
  32. }
  33. mk.audio.playEffect("button");
  34. if (cc.sys.isNative && this.bool_Auth) {
  35. if (!gData.loginData.isAuth) {
  36. // JsbSystem.WxAuth();
  37. mk.ui.openPanel('module/authUI/authUI');
  38. return;
  39. }
  40. }
  41. if (!this.panel_name) return;
  42. await mk.ui.openPanel(this.panel_name, this.open_type);
  43. const c_count = this.onComplete.length;
  44. for (let i = 0; i < c_count; i++) {
  45. if (this.onComplete[i].handler) this.onComplete[i].emit([])
  46. }
  47. mk.console.log('open->' + this.panel_name)
  48. }
  49. // update (dt) {}
  50. }