panel_ex.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. 面板扩展
  3. 功能: 双击编辑Label
  4. */
  5. 'use strict';
  6. const path = require('path');
  7. const md5 = require('md5');
  8. const fs = require('fs');
  9. const fe = Editor.require('packages://simple-code/tools/tools.js');
  10. const cfg = Editor.require('packages://simple-code/config.js');
  11. module.exports = {
  12. /** @type import('../../panel/vs-panel/vs-panel-base') */
  13. parent : null,
  14. // 面板初始化
  15. onLoad(parent){
  16. // index.js 对象
  17. this.parent = parent;
  18. // 绑定页面全局快捷键事件
  19. this.parent.addKeybodyEvent([["F2"]],(e)=>
  20. {
  21. if(this.openEditBox()){
  22. e.preventDefault();// 吞噬捕获事件
  23. return false;
  24. }
  25. },0)
  26. },
  27. openEditBox(){
  28. let div = Editor.Panel.getFocusedPanel()
  29. if(div && div.id == 'scene'){
  30. Editor.Scene.callSceneScript('simple-code', 'getCurrNodeLabelInfo', (err, labelInfo) =>
  31. {
  32. if(!labelInfo){
  33. return
  34. }
  35. this.editString((string)=>{
  36. labelInfo.string = string;
  37. Editor.Scene.callSceneScript('simple-code', 'setCurrNodeLabelInfo',labelInfo)
  38. },labelInfo.string)
  39. })
  40. return true
  41. }
  42. },
  43. // 双击事件
  44. onMouseDoubleClick(mousePos)
  45. {
  46. this.openEditBox()
  47. },
  48. editString(callback,defineName='',result=[])
  49. {
  50. let reSize = (pos)=>
  51. {
  52. let line = 0
  53. for (let index = 0; index < defineName.length; index++) if(defineName[index] == '\n') line++
  54. let width = 100
  55. let isAutoHeight = 1;
  56. let isEditMode = 0;
  57. if(defineName.length >100 || line>4){
  58. width = 800
  59. isEditMode = 1
  60. }else if(defineName.length >20){
  61. width = 300
  62. isAutoHeight = 1
  63. }else if(defineName.length >12){
  64. width = 150
  65. }
  66. this.parent.ace.setMiniSearchBox(pos,width,1,isEditMode,true);
  67. }
  68. let onSearchAccept = (data,cmdLine)=>
  69. {
  70. let name = cmdLine.getValue();
  71. callback(name);
  72. }
  73. // 修改搜索框时,通过该函数读取显示的实时显示下拉列表内容, cmdLine为输入文本框对象
  74. let onCompletionsFunc = (cmdLine)=>{
  75. let name = cmdLine.getValue();
  76. defineName = name;
  77. callback(name);
  78. reSize();
  79. return result;
  80. }
  81. this.parent.ace.openSearchBox(defineName,[],(data,cmdLine)=>onSearchAccept(data,cmdLine),(cmdLine)=>onCompletionsFunc(cmdLine))
  82. reSize(this.parent.mouse_pos);
  83. // 记录撤销
  84. Editor.Ipc.sendToAll('scene:undo-commit')
  85. },
  86. /************* 事件 *************/
  87. messages:{
  88. },
  89. };