scene_ex.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. *场景逻辑扩展
  3. *对话框功能扩展
  4. */
  5. 'use strict';
  6. var path = require('path');
  7. var fs = require('fs');
  8. var md5 = require('md5');
  9. let setValue = (comp_uuid,key,value)=>{
  10. Editor.Ipc.sendToPanel('scene', 'scene:set-property',{
  11. id: comp_uuid,
  12. path: key,//要修改的属性
  13. type: "String",
  14. value: value,
  15. isSubProp: false,
  16. });
  17. }
  18. let SetInfoFuncs = {
  19. 'cc.Label'(node,args){
  20. let comp = node.getComponent('cc.Label')
  21. if(comp){
  22. setValue(comp.uuid,'string',args.string)
  23. }
  24. },
  25. 'cc.RichText'(node,args){
  26. let comp = node.getComponent('cc.RichText')
  27. if(comp){
  28. setValue(comp.uuid,'string',args.string)
  29. }
  30. },
  31. 'cc.EditBox'(node,args){
  32. let comp = node.getComponent('cc.EditBox')
  33. if(comp){
  34. setValue(comp.uuid,args.isPlaceholder ? 'placeholder' : 'string',args.string)
  35. }
  36. },
  37. }
  38. let GetInfoFuncs = {
  39. 'cc.Label'(node){
  40. let comp = node.getComponent('cc.Label')
  41. if(comp){
  42. return {string : comp.string};
  43. }
  44. },
  45. 'cc.RichText'(node){
  46. let comp = node.getComponent('cc.RichText')
  47. if(comp){
  48. return {string : comp.string};
  49. }
  50. },
  51. 'cc.EditBox'(node){
  52. let comp = node.getComponent('cc.EditBox')
  53. if(comp){
  54. return {string : comp.string || comp.placeholder , isPlaceholder : comp.string == '' };
  55. }
  56. },
  57. }
  58. module.exports = {
  59. /************* 事件 *************/
  60. messages:
  61. {
  62. // 当前Node的Label组件信息
  63. 'getCurrNodeLabelInfo'(event)
  64. {
  65. let uuids = Editor.Selection.curSelection('node');
  66. let args;
  67. if(uuids && uuids[0])
  68. {
  69. let node = cc.engine.getInstanceById(uuids[0])
  70. for (const key in GetInfoFuncs)
  71. {
  72. const func = GetInfoFuncs[key];
  73. args = func(node);
  74. if(args){
  75. args.type = key;
  76. args.uuid = node.uuid;
  77. break;
  78. }
  79. }
  80. }
  81. event.reply(null,args);
  82. },
  83. // 当前Node的Label组件信息
  84. 'setCurrNodeLabelInfo'(event,args)
  85. {
  86. let node = cc.engine.getInstanceById(args.uuid)
  87. if(node){
  88. let func = SetInfoFuncs[args.type];
  89. if(func) func(node,args)
  90. }
  91. },
  92. }
  93. };