widget_item.ts 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  1. import { _decorator, assetManager, Color, Component, Director, director, EventTouch, ImageAsset, instantiate, Label, math, Node, NodePool, Prefab, Size, Sprite, SpriteFrame, Texture2D, Toggle, Tween, tween, UITransform, Vec2, Vec3 } from 'cc';
  2. import { att_click_data, att_count_down, att_drag_data, att_question_select, att_slide_data, att_text_sound_data, att_top_data, attributes_data, widget_item_data } from '../../data/data';
  3. import { ClientEvent } from '../clientEvent';
  4. import { config } from '../config';
  5. import { scroll_scene } from './scroll_scene';
  6. import { slide } from './slide';
  7. import { ui_top } from './uiWidget/ui_top';
  8. import { tools } from '../tools';
  9. import { Text_Sound } from './uiWidget/Text_Sound';
  10. import { question_select } from './uiWidget/question_select';
  11. import { count_down } from './uiWidget/count_down';
  12. import { Attributes } from './Attributes';
  13. const { ccclass, property } = _decorator;
  14. @ccclass('widget_item')
  15. export class widget_item extends Component {
  16. @property(Node) lab_name:Node = null;
  17. @property(Node) spr:Node = null;
  18. @property(Node) slide:Node = null;
  19. @property(Node) drag:Node = null;
  20. @property(Node) lab_drag:Node = null;
  21. @property(Node) img_select:Node = null;
  22. @property(Prefab) ui_prefab:Prefab = null;
  23. @property(Prefab) text_sound_pf:Prefab = null;
  24. @property(Prefab) count_down_pf:Prefab = null;
  25. @property(Prefab) question_select_pf:Prefab = null;
  26. @property(Node) toggle_active:Node = null;
  27. @property(Node) toggle_check:Node = null;
  28. @property(Node) other_drag_content:Node = null;
  29. private m_data:widget_item_data = null;
  30. private m_att:attributes_data = null;
  31. private isMove:boolean = false;
  32. private call_back = null;
  33. private m_ui_widget:Node = null;
  34. private m_text_sound:Node = null;
  35. private m_question_select:Node = null;
  36. private m_count_down:Node = null;
  37. private x_len:number = 0;
  38. private y_len:number = 0;
  39. public initView(data:widget_item_data,call=null,cur_select_id:number=-1){
  40. this.m_data = data;
  41. this.lab_name.getComponent(Label).string = data.name + (this.m_data.att?`id:${this.m_data.att.id}`:"");
  42. if(data.att!=null){
  43. this.call_back = call
  44. if(cur_select_id===null){
  45. this.toggle_active.active = true;
  46. this.toggle_check.getComponent(Toggle).isChecked = this.m_data.att.edit_active
  47. this.toggle_check.on(Node.EventType.TOUCH_END,()=>{
  48. if(this.call_back!=null){
  49. this.m_data.att.edit_active = !this.m_data.att.edit_active;
  50. this.call_back(this.m_data)
  51. }
  52. })
  53. }else{
  54. this.node.on(Node.EventType.TOUCH_END,()=>{
  55. if(this.call_back!=null){
  56. this.call_back(this.m_data)
  57. }
  58. })
  59. if(cur_select_id===this.m_data.att.id){
  60. this.img_select.active = true;
  61. }
  62. }
  63. this.initWidgetHaveAtt(data.att)
  64. this.node.active = true
  65. }else{
  66. this.node.on(Node.EventType.MOUSE_DOWN,this.onDragWidget.bind(this),this)
  67. }
  68. }
  69. public getShowWidgetData(){
  70. return this.m_data;
  71. }
  72. public setSelectStatus(){
  73. if(this.call_back!=null){
  74. this.m_data.att.edit_active = true;
  75. this.toggle_check.getComponent(Toggle).isChecked = true
  76. this.call_back(this.m_data)
  77. }
  78. }
  79. public setUnSelectStatus(){
  80. if(this.call_back!=null){
  81. this.m_data.att.edit_active = false;
  82. this.toggle_check.getComponent(Toggle).isChecked = false
  83. this.call_back(this.m_data)
  84. }
  85. }
  86. onDragWidget(){
  87. ClientEvent.dispatchEvent(config.Event.DragWidget,this.node)
  88. }
  89. initDrag(){
  90. this.drag.on(Node.EventType.TOUCH_MOVE,(et:EventTouch)=>{
  91. let p = new Vec3(et.getUILocation().x,et.getUILocation().y)
  92. let n_p = this.node.getComponent(UITransform).convertToNodeSpaceAR(p)
  93. this.drag.position = n_p;
  94. this.m_att.drag_data.drag_pos_x = this.drag.position.x;
  95. this.m_att.drag_data.drag_pos_y = this.drag.position.y;
  96. })
  97. if(this.m_att.drag_data.other_drag_list==undefined){
  98. this.m_att.drag_data.other_drag_list = []
  99. }
  100. this.other_drag_content.removeAllChildren()
  101. for (let index = 0; index < this.m_att.drag_data.other_drag_list.length; index++) {
  102. const element = this.m_att.drag_data.other_drag_list[index];
  103. let item = instantiate(this.drag)
  104. item.off(Node.EventType.TOUCH_MOVE)
  105. item.parent = this.other_drag_content;
  106. item.position = new Vec3(element.drag_pos_x,element.drag_pos_y)
  107. item.getComponent(UITransform).setContentSize(new Size(element.drag_size_width,element.drag_size_height))
  108. item.on(Node.EventType.TOUCH_MOVE,(et:EventTouch)=>{
  109. let p = new Vec3(et.getUILocation().x,et.getUILocation().y)
  110. let n_p = this.node.getComponent(UITransform).convertToNodeSpaceAR(p)
  111. item.position = n_p;
  112. this.m_att.drag_data.other_drag_list[index].drag_pos_x = item.position.x;
  113. this.m_att.drag_data.other_drag_list[index].drag_pos_y = item.position.y;
  114. })
  115. item.getComponent(Sprite).color = Color.YELLOW
  116. }
  117. this.lab_drag.getComponent(Label).string = `${this.m_data.name}id:${this.m_att.id}`
  118. }
  119. initSlide(){
  120. this.slide.getComponent(slide).updateDistance(this.m_att.slide_data.slide_dir,this.m_att.slide_data.slide_distance)
  121. }
  122. initUiWidget(){
  123. if(this.call_back==null){
  124. let ui = instantiate(this.ui_prefab)
  125. ui.parent = this.node;
  126. ui.getComponent(ui_top).initView(this.m_att.top_data)
  127. this.m_ui_widget = ui;
  128. this.node.getComponent(UITransform).contentSize = new Size(1080,1020)
  129. }
  130. }
  131. initTextSound(){
  132. if(this.call_back==null){
  133. let text_sound = instantiate(this.text_sound_pf)
  134. text_sound.parent = this.node;
  135. text_sound.getComponent(Text_Sound).initView(this.m_att.text_sound_data)
  136. this.m_text_sound = text_sound;
  137. this.node.getComponent(UITransform).contentSize = new Size(1080,1020)
  138. }
  139. }
  140. initQuestionSelect(){
  141. if(this.call_back==null){
  142. let node_question_select = instantiate(this.question_select_pf)
  143. node_question_select.parent = this.node;
  144. node_question_select.getComponent(question_select).initView(this.m_att.question_select)
  145. this.m_question_select = node_question_select;
  146. this.node.getComponent(UITransform).contentSize = new Size(1080,1020)
  147. }
  148. }
  149. initCountDown(){
  150. if(this.call_back==null){
  151. let _time_count = instantiate(this.count_down_pf)
  152. _time_count.parent = this.node;
  153. _time_count.getComponent(count_down).initView(this.m_att.count_down)
  154. this.m_count_down = _time_count;
  155. this.node.getComponent(UITransform).contentSize = new Size(1080,1020)
  156. }
  157. }
  158. initWidgetHaveAtt(att:attributes_data){
  159. if(att!=null){
  160. this.lab_name.active = true;
  161. this.m_att = att;
  162. this.initWidgetAtt()
  163. }else{
  164. this.m_att = new attributes_data
  165. this.m_att.id = config.getNewId();
  166. }
  167. if(this.m_data.type===config.Widget_Type_List.DRAG_TYPE){
  168. if(this.m_att.drag_data===null){
  169. this.m_att.drag_data = new att_drag_data;
  170. }
  171. this.drag.active = true;
  172. this.initDrag()
  173. }else if(this.m_data.type===config.Widget_Type_List.SLIDE_TYPE){
  174. this.slide.active = true;
  175. if(this.m_att.slide_data===null){
  176. this.m_att.slide_data = new att_slide_data;
  177. }
  178. this.initSlide()
  179. }else if(this.m_data.type===config.Widget_Type_List.CLICK_TYPE){
  180. if(this.m_att.click_data===null){
  181. this.m_att.click_data = new att_click_data;
  182. }
  183. this.lab_name.getComponent(Label).string = config.clcik_type_map.get(this.m_att.click_data.click_type) +`id${this.m_att.id}`
  184. }else if(this.m_data.type===config.Widget_Type_List.UI_TOP){
  185. if(this.m_att.top_data===null){
  186. this.m_att.top_data = new att_top_data;
  187. }
  188. this.initUiWidget()
  189. this.lab_name.getComponent(Label).string = `弹窗:${config.top_view_type_map.get(this.m_att.top_data.top_ui_type)}:id${this.m_att.id}`
  190. }else if(this.m_data.type===config.Widget_Type_List.TEXT_SOUND){
  191. if(this.m_att.text_sound_data===null){
  192. this.m_att.text_sound_data = new att_text_sound_data;
  193. }
  194. this.lab_name.getComponent(Label).string =`文本和语音-id:${this.m_att.id}`
  195. this.initTextSound()
  196. }else if(this.m_data.type===config.Widget_Type_List.QUESTION_SELECT){
  197. if(this.m_att.question_select===null){
  198. this.m_att.question_select = new att_question_select;
  199. }
  200. this.initQuestionSelect()
  201. this.lab_name.getComponent(Label).string =`问题选择-id:${this.m_att.id}`
  202. }else if(this.m_data.type===config.Widget_Type_List.COUNT_DOWN){
  203. if(this.m_att.count_down===null){
  204. this.m_att.count_down = new att_count_down;
  205. }
  206. this.initCountDown()
  207. this.lab_name.getComponent(Label).string =`倒计时-id:${this.m_att.id}`
  208. }
  209. this.node.active = this.m_att.edit_active
  210. }
  211. public initWidgetByScene(data:widget_item_data,att:attributes_data=null){
  212. this.m_data = data;
  213. this.initWidgetHaveAtt(att)
  214. if(this.m_data.type===config.Widget_Type_List.UI_TOP){ //弹窗不可以拖动
  215. this.node.on(Node.EventType.MOUSE_DOWN,(et:EventTouch)=>{
  216. ClientEvent.dispatchEvent(config.Event.UpdateAttributes,this.getWidgetAtt())
  217. })
  218. }else if(this.m_data.type===config.Widget_Type_List.TEXT_SOUND){
  219. this.node.on(Node.EventType.MOUSE_DOWN,(et:EventTouch)=>{
  220. ClientEvent.dispatchEvent(config.Event.UpdateAttributes,this.getWidgetAtt())
  221. })
  222. }else{
  223. this.node.on(Node.EventType.TOUCH_MOVE,(et:EventTouch)=>{
  224. if(this.isMove){
  225. let p = new Vec3(et.getUILocation().x,et.getUILocation().y)
  226. let n_p = this.node.parent.getComponent(UITransform).convertToNodeSpaceAR(p)
  227. let offset_x = this.x_len;
  228. let offset_y = this.y_len;
  229. this.node.position = new Vec3(n_p.x-offset_x,n_p.y-offset_y);
  230. if(this.node.parent.name=="content"){
  231. this.node.parent.parent.parent.getComponent(scroll_scene).stopTouch()
  232. }
  233. ClientEvent.dispatchEvent(config.Event.UpdateAttributes,this.getWidgetAtt())
  234. }
  235. })
  236. this.node.on(Node.EventType.MOUSE_DOWN,(et:EventTouch)=>{
  237. let pos = this.node.parent.getComponent(UITransform).convertToWorldSpaceAR(this.node.position)
  238. if(this.x_len==0){
  239. this.x_len = (et.getUILocation().x - pos.x)*2;
  240. this.y_len = (et.getUILocation().y - pos.y)*2;
  241. let p = new Vec3(et.getUILocation().x,et.getUILocation().y)
  242. let n_p = this.node.parent.getComponent(UITransform).convertToNodeSpaceAR(p)
  243. this.node.position = new Vec3(n_p.x-this.x_len,n_p.y-this.y_len);
  244. // console.log("a_x",this.x_len, this.y_len ,et.getUILocation().x,this.m_att.width)
  245. }
  246. // console.log("this.x_len",this.x_len,this.y_len)
  247. this.isMove = true;
  248. ClientEvent.dispatchEvent(config.Event.UpdateAttributes,this.getWidgetAtt())
  249. })
  250. this.node.on(Node.EventType.MOUSE_LEAVE,()=>{
  251. if(this.node.parent.name=="content"){
  252. this.node.parent.parent.parent.getComponent(scroll_scene).startTouch()
  253. }
  254. this.isMove = false;
  255. this.x_len = 0;
  256. this.y_len = 0;
  257. })
  258. this.node.on(Node.EventType.TOUCH_END,()=>{
  259. if(this.node.parent.name=="content"){
  260. this.node.parent.parent.parent.getComponent(scroll_scene).startTouch()
  261. }
  262. this.isMove = false;
  263. this.x_len = 0;
  264. this.y_len = 0;
  265. })
  266. }
  267. ClientEvent.dispatchEvent(config.Event.UpdateAttributes,this.getWidgetAtt())
  268. ClientEvent.on(config.Event.UpdateAttributesToView,this.UpdateAttributesToView,this)
  269. }
  270. protected onDestroy(): void {
  271. ClientEvent.off(config.Event.UpdateAttributesToView,this.UpdateAttributesToView,this)
  272. }
  273. UpdateAttributesToView(data:attributes_data,update_type:string){
  274. if(this.m_att===null){
  275. return;
  276. }
  277. if(data.id===this.m_att.id){
  278. switch(update_type){
  279. case config.attributes_list_type.pos:
  280. this.m_att.x = data.x;
  281. this.m_att.y = data.y;
  282. this.m_att.z = data.z;
  283. this.node.setSiblingIndex(this.m_att.z)
  284. this.node.position = new Vec3(data.x,data.y)
  285. break;
  286. case config.attributes_list_type.animation:
  287. this.m_att.animation_list = data.animation_list;
  288. break;
  289. case config.attributes_list_type.size:
  290. this.m_att.width = data.width;
  291. this.m_att.height = data.height;
  292. this.spr.getComponent(UITransform).contentSize = new Size(data.width,data.height)
  293. this.node.getComponent(UITransform).contentSize = this.spr.getComponent(UITransform).contentSize
  294. break;
  295. case config.attributes_list_type.url:
  296. this.m_att.src = data.src
  297. this.m_att.src_name = data.src_name
  298. if(this.m_att.src.length<=0){
  299. this.spr.getComponent(Sprite).spriteFrame = null
  300. }else{
  301. assetManager.loadRemote<ImageAsset>(this.m_att.src, (err, imageAsset2)=>{
  302. if (!err && imageAsset2) {
  303. this.lab_name.active = false;
  304. const texture = new Texture2D();
  305. texture.image = imageAsset2;
  306. let spFrame2 = new SpriteFrame();
  307. spFrame2.texture = texture;
  308. this.spr.getComponent(Sprite).spriteFrame = spFrame2
  309. this.spr.getComponent(UITransform).contentSize = new Size(data.width,data.height)
  310. director.once(Director.EVENT_AFTER_DRAW,()=>{
  311. this.node.getComponent(UITransform).contentSize = this.spr.getComponent(UITransform).contentSize
  312. })
  313. }
  314. });
  315. }
  316. break;
  317. case config.attributes_list_type.origin:
  318. if(this.m_att.src.length>0){
  319. this.spr.getComponent(Sprite).sizeMode = Sprite.SizeMode.RAW;
  320. director.once(Director.EVENT_AFTER_DRAW,()=>{
  321. console.log("Director.EVENT_AFTER_DRAW")
  322. this.m_att.width = this.spr.getComponent(UITransform).contentSize.width;
  323. this.m_att.height = this.spr.getComponent(UITransform).contentSize.height;
  324. director.once(Director.EVENT_AFTER_DRAW,()=>{
  325. this.node.getComponent(UITransform).contentSize = this.spr.getComponent(UITransform).contentSize
  326. })
  327. ClientEvent.dispatchEvent(config.Event.UpdateAttributes,this.getWidgetAtt())
  328. })
  329. }
  330. break;
  331. case config.attributes_list_type.delete:
  332. this.node.destroy()
  333. this.node.removeFromParent()
  334. ClientEvent.dispatchEvent(config.Event.UpdateAttributes,null)
  335. ClientEvent.dispatchEvent(config.Event.RemoveWidget,this.node)
  336. break;
  337. case config.attributes_list_type.drag:
  338. this.m_att.drag_data = data.drag_data
  339. if(this.m_data.type===config.Widget_Type_List.DRAG_TYPE){
  340. this.drag.getComponent(UITransform).contentSize = new Size(data.drag_data.drag_size_width,data.drag_data.drag_size_height);
  341. this.drag.position = new Vec3( this.m_att.drag_data.drag_pos_x , this.m_att.drag_data.drag_pos_y)
  342. if(this.m_att.drag_data.other_drag_list==undefined){
  343. this.m_att.drag_data.other_drag_list = []
  344. }
  345. this.other_drag_content.removeAllChildren()
  346. for (let index = 0; index < this.m_att.drag_data.other_drag_list.length; index++) {
  347. const element = this.m_att.drag_data.other_drag_list[index];
  348. let item = instantiate(this.drag)
  349. item.off(Node.EventType.TOUCH_MOVE)
  350. item.parent = this.other_drag_content;
  351. item.position = new Vec3(element.drag_pos_x,element.drag_pos_y)
  352. item.getComponent(UITransform).setContentSize(new Size(element.drag_size_width,element.drag_size_height))
  353. item.on(Node.EventType.TOUCH_MOVE,(et:EventTouch)=>{
  354. let p = new Vec3(et.getUILocation().x,et.getUILocation().y)
  355. let n_p = this.node.getComponent(UITransform).convertToNodeSpaceAR(p)
  356. item.position = n_p;
  357. this.m_att.drag_data.other_drag_list[index].drag_pos_x = item.position.x;
  358. this.m_att.drag_data.other_drag_list[index].drag_pos_y = item.position.y;
  359. })
  360. item.getComponent(Sprite).color = Color.YELLOW
  361. }
  362. }
  363. break;
  364. case config.attributes_list_type.drag_err_back_status:
  365. if(this.m_data.type===config.Widget_Type_List.DRAG_TYPE){
  366. this.m_att.drag_data.is_err_drag_back = data.drag_data.is_err_drag_back;
  367. }
  368. break;
  369. case config.attributes_list_type.slide:
  370. if(this.m_data.type===config.Widget_Type_List.SLIDE_TYPE){
  371. this.m_att.slide_data.slide_dir = data.slide_data.slide_dir;
  372. this.m_att.slide_data.slide_distance = data.slide_data.slide_distance;
  373. this.m_att.slide_data.slide_num = data.slide_data.slide_num;
  374. this.slide.getComponent(slide).updateDistance(this.m_att.slide_data.slide_dir,this.m_att.slide_data.slide_distance)
  375. }
  376. break;
  377. case config.attributes_list_type.click:
  378. if(this.m_data.type===config.Widget_Type_List.CLICK_TYPE){
  379. this.m_att.click_data = data.click_data;
  380. this.lab_name.getComponent(Label).string = config.clcik_type_map.get(this.m_att.click_data.click_type)
  381. }
  382. case config.attributes_list_type.is_interaction:
  383. this.m_att.is_interaction = data.is_interaction;
  384. break;
  385. case config.attributes_list_type.find_widget_pos:
  386. this.Shiny()
  387. break;
  388. case config.attributes_list_type.active:
  389. this.m_att.edit_active = data.edit_active;
  390. this.node.active = this.m_att.edit_active
  391. this.toggle_check.getComponent(Toggle).isChecked = this.m_att.edit_active
  392. break;
  393. case config.attributes_list_type.top:
  394. this.m_att.top_data = data.top_data;
  395. if(this.m_ui_widget!=null){
  396. this.m_ui_widget.getComponent(ui_top).changeData(this.m_att.top_data)
  397. }
  398. break;
  399. case config.attributes_list_type.text_sound:
  400. this.m_att.text_sound_data = data.text_sound_data;
  401. if(this.m_text_sound!=null){
  402. this.m_text_sound.getComponent(Text_Sound).updateView(this.m_att.text_sound_data)
  403. }
  404. break;
  405. case config.attributes_list_type.question_select:
  406. this.m_att.question_select = data.question_select;
  407. if(this.m_question_select!=null){
  408. this.m_question_select.getComponent(question_select).updateView(this.m_att.question_select)
  409. }
  410. break;
  411. case config.attributes_list_type.count_down:
  412. this.m_att.count_down = data.count_down;
  413. if(this.m_count_down!=null){
  414. this.m_count_down.getComponent(count_down).updateView(this.m_att.count_down)
  415. }
  416. break;
  417. case config.attributes_list_type.zIndex:
  418. this.m_att.zIndex = data.zIndex;
  419. break;
  420. case config.attributes_list_type.dir:
  421. this.m_att.img_dir = data.img_dir;
  422. this.updateDir()
  423. break;
  424. case config.attributes_list_type.show:
  425. this.m_att.is_show = data.is_show;
  426. break;
  427. }
  428. }
  429. director.once(Director.EVENT_AFTER_DRAW,()=>{
  430. ClientEvent.dispatchEvent(config.Event.updateWidgetData)
  431. })
  432. }
  433. updateDir(){
  434. if(this.call_back==null){
  435. switch (this.m_att.img_dir) {
  436. case config.widget_scale_dir.left:
  437. this.spr.scale = new Vec3(-1,1)
  438. break;
  439. case config.widget_scale_dir.up:
  440. this.spr.scale = new Vec3(1,-1)
  441. break;
  442. case config.widget_scale_dir.normal:
  443. this.spr.scale = new Vec3(1,1)
  444. break;
  445. }
  446. }
  447. }
  448. Shiny(){
  449. this.img_select.active = true;
  450. this.img_select.getComponent(UITransform).setContentSize(this.node.getComponent(UITransform).contentSize)
  451. Tween.stopAllByTarget(this.img_select)
  452. tween(this.img_select).delay(0.3).hide().delay(0.3).show().delay(0.3).hide().delay(0.3).show().delay(0.3).call(()=>{
  453. this.img_select.active = false;
  454. }).start()
  455. }
  456. public getWidgetAtt(){
  457. this.m_att.name = this.m_data.name!=""?this.m_data.name:"普通控件";
  458. this.m_att.height = this.spr.getComponent(UITransform).contentSize.height;
  459. this.m_att.width = this.spr.getComponent(UITransform).contentSize.width;
  460. this.m_att.x = this.node.position.x;
  461. this.m_att.widget_type = this.m_data.type;
  462. this.m_att.y = this.node.position.y;
  463. this.m_att.z = this.node.getSiblingIndex();
  464. this.m_att.type = config.attributes_type.widget;
  465. this.m_att.src_name = this.m_att.src.length>0? this.m_att.src_name:"空";
  466. if(this.m_att.drag_data!=null){
  467. this.m_att.drag_data.drag_pos_x = this.drag.position.x;
  468. this.m_att.drag_data.drag_pos_y = this.drag.position.y;
  469. this.m_att.drag_data.drag_size_width = this.drag.getComponent(UITransform).contentSize.width;
  470. this.m_att.drag_data.drag_size_height = this.drag.getComponent(UITransform).contentSize.height;
  471. }
  472. return this.m_att;
  473. }
  474. initWidgetAtt(){
  475. if(this.call_back==null){
  476. this.node.position = new Vec3(this.m_att.x,this.m_att.y)
  477. this.node.getComponent(UITransform).setContentSize(new Size( this.m_att.width,this.m_att.height))
  478. if(this.m_att.drag_data!=null){
  479. this.drag.position = new Vec3(this.m_att.drag_data.drag_pos_x,this.m_att.drag_data.drag_pos_y)
  480. this.drag.getComponent(UITransform).setContentSize(new Size(this.m_att.drag_data.drag_size_width ,this.m_att.drag_data.drag_size_height ))
  481. }
  482. this.spr.getComponent(UITransform).setContentSize(this.node.getComponent(UITransform).contentSize)
  483. this.lab_name.getComponent(Label).string = this.m_att.name+"id:"+this.m_att.id;;
  484. }else{
  485. this.lab_name.getComponent(Label).string = this.m_data.name+"id:"+this.m_att.id;
  486. }
  487. if(this.m_att.src!=""&&this.m_att.src.length>0){
  488. assetManager.loadRemote<ImageAsset>(this.m_att.src, (err, imageAsset2)=>{
  489. if (!err && imageAsset2) {
  490. const texture = new Texture2D();
  491. texture.image = imageAsset2;
  492. let spFrame2 = new SpriteFrame();
  493. spFrame2.texture = texture;
  494. this.spr.getComponent(Sprite).spriteFrame = spFrame2
  495. }
  496. });
  497. }
  498. //进行数据差矫正
  499. let t_data = new attributes_data
  500. for (const key in t_data) {
  501. if (Object.prototype.hasOwnProperty.call(t_data ,key)) {
  502. const element = t_data[key];
  503. if(this.m_att[key]===undefined){
  504. this.m_att[key] = element;
  505. }
  506. }
  507. }
  508. this.updateDir()
  509. }
  510. public getData(){
  511. if(this.m_att!=null){
  512. this.getWidgetAtt()
  513. }
  514. this.m_data.att = this.m_att;
  515. return this.m_data;
  516. }
  517. public setData(data){
  518. this.m_data = data;
  519. }
  520. }