panel_ex.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. 面板扩展
  3. 功能: 新建脚本并绑定组件
  4. */
  5. 'use strict';
  6. const path = require('path');
  7. const fs = require('fs');
  8. const config = require('../../config');
  9. const tools = require('../../tools/tools');
  10. module.exports = {
  11. /** @type import('../../panel/vs-panel/vs-panel-base') */
  12. parent : null,
  13. // 面板初始化
  14. ready(parent) {
  15. // index.js 对象
  16. this.parent = parent;
  17. },
  18. // monaco 编辑器初始化
  19. onLoad() {
  20. },
  21. /** 需要刷新creator右键菜单
  22. * @param type = node | asset
  23. * */
  24. onRefreshCreatorMenu(type,uuid){
  25. if (uuid == null || type != 'node') {
  26. // 清除菜单
  27. Editor.Ipc.sendToMain('simple-code:setMenuConfig', {id: 'cc-goto-widget-event',menuCfg: undefined,});
  28. return;
  29. }
  30. Editor.Scene.callSceneScript('simple-code', 'getWidgetBindEvents',{uuid}, (err, eventList) => {
  31. this.eventList = eventList;
  32. if (!eventList || !eventList.length) {
  33. // 清除菜单
  34. Editor.Ipc.sendToMain('simple-code:setMenuConfig', {id: 'cc-goto-widget-event',menuCfg: undefined,});
  35. return;
  36. }
  37. let menuCfg = {
  38. layerMenu: [
  39. { type: 'separator' },
  40. {
  41. label: tools.translate('cc-goto-widget-event'),
  42. enabled: true,
  43. cmd : 'cc-goto-widget-event'
  44. }, // 生成拖拽组件
  45. ],
  46. };
  47. Editor.Ipc.sendToMain('simple-code:setMenuConfig', {
  48. id: 'cc-goto-widget-event',
  49. menuCfg: menuCfg,
  50. });
  51. });
  52. },
  53. // 面板销毁
  54. onDestroy() {},
  55. messages: {
  56. 'cc-goto-widget-event'() {
  57. if(!this.eventList || !this.eventList[0]){
  58. return;
  59. }
  60. let eventInfo = this.eventList[0];
  61. let fsPath = Editor.remote.assetdb.uuidToFspath(eventInfo.scriptUuid);
  62. let model = this.parent.fileMgr.getModelByFsPath(fsPath);
  63. let findObj = model.getValue().match(new RegExp(eventInfo.funcName + "[\s]*?\(.*\)[\s]*?{"));
  64. let selection;
  65. if(findObj){
  66. let position = model.getPositionAt(findObj.index);
  67. selection = new this.parent.monaco.Selection(position.lineNumber,position.column,position.lineNumber,position.column);
  68. }
  69. this.parent.monaco.sendEvent('vs-open-file-tab',{
  70. uri:model.uri,
  71. selection:selection,
  72. })
  73. },
  74. },
  75. };