BtnOpenPanel.ts 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 (this.bool_Auth) {
  35. if (!gData.loginData.isAuth) {
  36. JsbSystem.WxAuth();
  37. return;
  38. }
  39. }
  40. if (!this.panel_name) return;
  41. await mk.ui.openPanel(this.panel_name, this.open_type);
  42. const c_count = this.onComplete.length;
  43. for (let i = 0; i < c_count; i++) {
  44. if (this.onComplete[i].handler) this.onComplete[i].emit([])
  45. }
  46. mk.console.log('open->' + this.panel_name)
  47. }
  48. // update (dt) {}
  49. }