widget_item.ts 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  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_container, 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. const { ccclass, property } = _decorator;
  13. @ccclass('widget_item')
  14. export class widget_item extends Component {
  15. @property(Node) lab_name:Node = null;
  16. @property(Node) spr:Node = null;
  17. @property(Node) slide:Node = null;
  18. @property(Node) drag:Node = null;
  19. @property(Node) lab_drag:Node = null;
  20. @property(Node) img_select:Node = null;
  21. @property(Prefab) ui_prefab:Prefab = null;
  22. @property(Prefab) text_sound_pf:Prefab = null;
  23. @property(Prefab) count_down_pf:Prefab = null;
  24. @property(Prefab) question_select_pf:Prefab = null;
  25. @property(Prefab) self_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. @property(Node) lab_remark:Node = null;
  30. @property(Node) btn_look_voice_text:Node = null;
  31. @property(Node) btn_delete:Node = null;
  32. @property(Node) container:Node = null;
  33. private m_data:widget_item_data = null;
  34. private m_att:attributes_data = null;
  35. private isMove:boolean = false;
  36. private call_back = null;
  37. private m_ui_widget:Node = null;
  38. private m_text_sound:Node = null;
  39. private m_question_select:Node = null;
  40. private m_count_down:Node = null;
  41. private x_len:number = 0;
  42. private y_len:number = 0;
  43. private m_isShowDragOtherList:boolean = false;
  44. private m_isShowContainerChilden:boolean = true;
  45. private m_delete_cb = null;
  46. protected start(): void {
  47. this.btn_delete.on(Node.EventType.TOUCH_END, ()=>{
  48. this.m_delete_cb && this.m_delete_cb(this)
  49. })
  50. }
  51. public hideContainerChilden(){
  52. this.m_isShowContainerChilden = false
  53. }
  54. public initHideDragOtherList() {
  55. // 点击->控件列表,不显示拖拽其他按钮
  56. this.hideContainerChilden()
  57. this.m_isShowDragOtherList = true
  58. }
  59. public initView(data:widget_item_data,call=null,cur_select_id:number=-1){
  60. this.m_data = data;
  61. this.lab_name.getComponent(Label).string = data.name + (this.m_data.att?`id:${this.m_data.att.id}`:"");
  62. this.lab_remark.getComponent(Label).string = ''
  63. if(data.att!=null){
  64. this.lab_remark.getComponent(Label).string = this.m_data.att.remark
  65. if(this.m_data.type==config.Widget_Type_List.TEXT_SOUND) {
  66. this.btn_look_voice_text.active = true
  67. this.btn_look_voice_text.off(Node.EventType.TOUCH_END)
  68. this.btn_look_voice_text.on(Node.EventType.TOUCH_END, ()=> {
  69. tools.show_dialog(this.m_data.att.text_sound_data.text, null)
  70. },this)
  71. } else {
  72. this.btn_look_voice_text.active = false
  73. }
  74. this.call_back = call
  75. if(cur_select_id===null){
  76. this.toggle_active.active = true;
  77. this.toggle_check.getComponent(Toggle).isChecked = this.m_data.att.edit_active
  78. this.toggle_check.on(Node.EventType.TOUCH_END,()=>{
  79. if(this.call_back!=null){
  80. this.m_data.att.edit_active = !this.m_data.att.edit_active;
  81. this.call_back(this.m_data)
  82. }
  83. })
  84. }else{
  85. this.node.on(Node.EventType.TOUCH_END,()=>{
  86. if(this.call_back!=null){
  87. this.call_back(this.m_data)
  88. }
  89. })
  90. if(cur_select_id===this.m_data.att.id){
  91. this.img_select.active = true;
  92. }
  93. }
  94. this.initWidgetHaveAtt(data.att)
  95. this.node.active = true
  96. }else{
  97. this.node.on(Node.EventType.MOUSE_DOWN,this.onDragWidget.bind(this),this)
  98. }
  99. }
  100. public showButtonDelete(is_show:boolean, delete_cb:Function) {
  101. this.btn_delete.active = is_show
  102. if(is_show) {
  103. this.m_delete_cb = delete_cb
  104. }
  105. }
  106. public getShowWidgetData(){
  107. return this.m_data;
  108. }
  109. public setSelectStatus(){
  110. if(this.call_back!=null){
  111. this.m_data.att.edit_active = true;
  112. this.toggle_check.getComponent(Toggle).isChecked = true
  113. this.call_back(this.m_data)
  114. }
  115. }
  116. public setUnSelectStatus(){
  117. if(this.call_back!=null){
  118. this.m_data.att.edit_active = false;
  119. this.toggle_check.getComponent(Toggle).isChecked = false
  120. this.call_back(this.m_data)
  121. }
  122. }
  123. onDragWidget(){
  124. ClientEvent.dispatchEvent(config.Event.DragWidget,this.node)
  125. }
  126. initDrag(){
  127. this.drag.on(Node.EventType.TOUCH_MOVE,(et:EventTouch)=>{
  128. let p = new Vec3(et.getUILocation().x,et.getUILocation().y)
  129. let n_p = this.node.getComponent(UITransform).convertToNodeSpaceAR(p)
  130. this.drag.position = n_p;
  131. this.m_att.drag_data.drag_pos_x = this.drag.position.x;
  132. this.m_att.drag_data.drag_pos_y = this.drag.position.y;
  133. })
  134. if(this.m_att.drag_data.other_drag_list==undefined){
  135. this.m_att.drag_data.other_drag_list = []
  136. }
  137. // 刷新 其他拖拽
  138. this.other_drag_content.removeAllChildren()
  139. for (let index = 0; index < this.m_att.drag_data.other_drag_list.length; index++) {
  140. const element:att_drag_data = this.m_att.drag_data.other_drag_list[index];
  141. let item = instantiate(this.drag)
  142. item.off(Node.EventType.TOUCH_MOVE)
  143. item.parent = this.other_drag_content;
  144. item.position = new Vec3(element.drag_pos_x,element.drag_pos_y)
  145. item.getComponent(UITransform).setContentSize(new Size(element.drag_size_width,element.drag_size_height))
  146. item.on(Node.EventType.TOUCH_MOVE,(et:EventTouch)=>{
  147. let p = new Vec3(et.getUILocation().x,et.getUILocation().y)
  148. let n_p = this.node.getComponent(UITransform).convertToNodeSpaceAR(p)
  149. item.position = n_p;
  150. this.m_att.drag_data.other_drag_list[index].drag_pos_x = item.position.x;
  151. this.m_att.drag_data.other_drag_list[index].drag_pos_y = item.position.y;
  152. })
  153. item.getComponent(Sprite).color = this.getOtherDragListColor(index) //Color.YELLOW
  154. item.getChildByName('lab_drag_remark').getComponent(Label).string = element.remark
  155. if(element.is_show_inTheEditor==undefined) {
  156. element.is_show_inTheEditor = true
  157. }
  158. item.active = element.is_show_inTheEditor
  159. }
  160. this.lab_drag.getComponent(Label).string = `${this.m_data.name}id:${this.m_att.id}`
  161. }
  162. initSlide(){
  163. this.slide.getComponent(slide).updateDistance(this.m_att.slide_data.slide_dir,this.m_att.slide_data.slide_distance)
  164. }
  165. initUiWidget(){
  166. if(this.call_back==null){
  167. let ui = instantiate(this.ui_prefab)
  168. ui.parent = this.node;
  169. ui.getComponent(ui_top).initView(this.m_att.top_data)
  170. this.m_ui_widget = ui;
  171. this.node.getComponent(UITransform).contentSize = new Size(1080,1020)
  172. }
  173. }
  174. initTextSound(){
  175. if(this.call_back==null){
  176. let text_sound = instantiate(this.text_sound_pf)
  177. text_sound.parent = this.node;
  178. text_sound.getComponent(Text_Sound).initView(this.m_att.text_sound_data)
  179. this.m_text_sound = text_sound;
  180. this.node.getComponent(UITransform).contentSize = new Size(1080,1020)
  181. }
  182. }
  183. initQuestionSelect(){
  184. if(this.call_back==null){
  185. let node_question_select = instantiate(this.question_select_pf)
  186. node_question_select.parent = this.node;
  187. node_question_select.getComponent(question_select).initView(this.m_att.question_select)
  188. this.m_question_select = node_question_select;
  189. this.node.getComponent(UITransform).contentSize = new Size(1080,1020)
  190. }
  191. }
  192. initConatiner(){
  193. let container_layer = this.m_att.container_layer
  194. this.container.removeAllChildren()
  195. if(container_layer!=null){
  196. for (let index = 0; index < container_layer.widget_list.length; index++) {
  197. const widget_data = container_layer.widget_list[index];
  198. console.log("widget_data",widget_data)
  199. let node = instantiate(this.self_pf)
  200. node.getComponent(widget_item).initWidgetByScene(widget_data,widget_data.att)
  201. node.parent = this.container
  202. }
  203. }
  204. }
  205. initCountDown(){
  206. if(this.call_back==null){
  207. let _time_count = instantiate(this.count_down_pf)
  208. _time_count.parent = this.node;
  209. _time_count.getComponent(count_down).initView(this.m_att.count_down)
  210. this.m_count_down = _time_count;
  211. this.node.getComponent(UITransform).contentSize = new Size(1080,1020)
  212. }
  213. }
  214. initWidgetHaveAtt(att:attributes_data){
  215. if(att!=null){
  216. this.lab_name.active = true;
  217. this.m_att = att;
  218. this.initWidgetAtt()
  219. }else{
  220. this.m_att = new attributes_data
  221. this.m_att.id = config.getNewId();
  222. }
  223. if(this.m_data.type===config.Widget_Type_List.DRAG_TYPE){
  224. if(this.m_att.drag_data===null){
  225. this.m_att.drag_data = new att_drag_data;
  226. }
  227. this.drag.active = true;
  228. if(this.m_isShowDragOtherList == false) {
  229. this.initDrag()
  230. }
  231. }else if(this.m_data.type===config.Widget_Type_List.SLIDE_TYPE){
  232. this.slide.active = true;
  233. if(this.m_att.slide_data===null){
  234. this.m_att.slide_data = new att_slide_data;
  235. }
  236. this.initSlide()
  237. }else if(this.m_data.type===config.Widget_Type_List.CLICK_TYPE){
  238. if(this.m_att.click_data===null){
  239. this.m_att.click_data = new att_click_data;
  240. }
  241. this.lab_name.getComponent(Label).string = config.clcik_type_map.get(this.m_att.click_data.click_type) +`id${this.m_att.id}`
  242. }else if(this.m_data.type===config.Widget_Type_List.UI_TOP){
  243. if(this.m_att.top_data===null){
  244. this.m_att.top_data = new att_top_data;
  245. }
  246. this.initUiWidget()
  247. 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}`
  248. }else if(this.m_data.type===config.Widget_Type_List.TEXT_SOUND){
  249. if(this.m_att.text_sound_data===null){
  250. this.m_att.text_sound_data = new att_text_sound_data;
  251. }
  252. this.lab_name.getComponent(Label).string =`文本和语音-id:${this.m_att.id}`
  253. this.initTextSound()
  254. }else if(this.m_data.type===config.Widget_Type_List.QUESTION_SELECT){
  255. if(this.m_att.question_select===null){
  256. this.m_att.question_select = new att_question_select;
  257. }
  258. this.initQuestionSelect()
  259. this.lab_name.getComponent(Label).string =`问题选择-id:${this.m_att.id}`
  260. }else if(this.m_data.type===config.Widget_Type_List.COUNT_DOWN){
  261. if(this.m_att.count_down===null){
  262. this.m_att.count_down = new att_count_down;
  263. }
  264. this.initCountDown()
  265. this.lab_name.getComponent(Label).string =`倒计时-id:${this.m_att.id}`
  266. }else if(this.m_data.type===config.Widget_Type_List.CONTAINER_LAYER){
  267. if(this.m_att.container_layer===null){
  268. this.m_att.container_layer = new att_container;
  269. }
  270. if(this.m_isShowContainerChilden){
  271. this.initConatiner()
  272. }
  273. this.lab_name.getComponent(Label).string =`容器层-id:${this.m_att.id}`
  274. }
  275. this.node.active = this.m_att.edit_active
  276. }
  277. public initWidgetByScene(data:widget_item_data,att:attributes_data=null){
  278. this.m_data = data;
  279. this.initWidgetHaveAtt(att)
  280. if(this.m_data.type===config.Widget_Type_List.UI_TOP){ //弹窗不可以拖动
  281. // MAC电脑浏览器
  282. if(config.is_MAC_edit) {
  283. this.node.on(Node.EventType.TOUCH_END,(et:EventTouch)=>{
  284. ClientEvent.dispatchEvent(config.Event.UpdateAttributes,this.getWidgetAtt())
  285. })
  286. return
  287. }
  288. this.node.on(Node.EventType.MOUSE_DOWN,(et:EventTouch)=>{
  289. ClientEvent.dispatchEvent(config.Event.UpdateAttributes,this.getWidgetAtt())
  290. })
  291. }else if(this.m_data.type===config.Widget_Type_List.TEXT_SOUND){
  292. // MAC电脑浏览器
  293. if(config.is_MAC_edit) {
  294. this.node.on(Node.EventType.TOUCH_END,(et:EventTouch)=>{
  295. ClientEvent.dispatchEvent(config.Event.UpdateAttributes,this.getWidgetAtt())
  296. })
  297. return
  298. }
  299. this.node.on(Node.EventType.MOUSE_DOWN,(et:EventTouch)=>{
  300. ClientEvent.dispatchEvent(config.Event.UpdateAttributes,this.getWidgetAtt())
  301. })
  302. }
  303. else if(this.m_data.type==config.Widget_Type_List.CONTAINER_LAYER){
  304. this.node.on(Node.EventType.MOUSE_DOWN,(et:EventTouch)=>{
  305. ClientEvent.dispatchEvent(config.Event.UpdateAttributes,this.getWidgetAtt())
  306. },this,true)
  307. }
  308. else{
  309. this.node.on(Node.EventType.TOUCH_MOVE,(et:EventTouch)=>{
  310. if(this.isMove){
  311. let p = new Vec3(et.getUILocation().x,et.getUILocation().y)
  312. let n_p = this.node.parent.getComponent(UITransform).convertToNodeSpaceAR(p)
  313. let offset_x = this.x_len;
  314. let offset_y = this.y_len;
  315. this.node.position = new Vec3(n_p.x-offset_x,n_p.y-offset_y);
  316. if(this.node.parent.name=="content"){
  317. this.node.parent.parent.parent.getComponent(scroll_scene).stopTouch()
  318. }
  319. ClientEvent.dispatchEvent(config.Event.UpdateAttributes,this.getWidgetAtt())
  320. }
  321. })
  322. this.node.on(Node.EventType.MOUSE_DOWN,(et:EventTouch)=>{
  323. et.propagationStopped = true;
  324. let pos = this.node.parent.getComponent(UITransform).convertToWorldSpaceAR(this.node.position)
  325. if(this.x_len==0){
  326. this.x_len = (et.getUILocation().x - pos.x)*2;
  327. this.y_len = (et.getUILocation().y - pos.y)*2;
  328. let p = new Vec3(et.getUILocation().x,et.getUILocation().y)
  329. let n_p = this.node.parent.getComponent(UITransform).convertToNodeSpaceAR(p)
  330. this.node.position = new Vec3(n_p.x-this.x_len,n_p.y-this.y_len);
  331. // console.log("a_x",this.x_len, this.y_len ,et.getUILocation().x,this.m_att.width)
  332. }
  333. // console.log("this.x_len",this.x_len,this.y_len)
  334. this.isMove = true;
  335. ClientEvent.dispatchEvent(config.Event.UpdateAttributes,this.getWidgetAtt())
  336. })
  337. this.node.on(Node.EventType.MOUSE_LEAVE,()=>{
  338. if(this.node.parent.name=="content"){
  339. this.node.parent.parent.parent.getComponent(scroll_scene).startTouch()
  340. }
  341. this.isMove = false;
  342. this.x_len = 0;
  343. this.y_len = 0;
  344. })
  345. this.node.on(Node.EventType.TOUCH_END,(et:EventTouch)=>{
  346. if(this.node.parent.name=="content"){
  347. this.node.parent.parent.parent.getComponent(scroll_scene).startTouch()
  348. }
  349. this.isMove = false;
  350. this.x_len = 0;
  351. this.y_len = 0;
  352. // MAC电脑浏览器
  353. if(config.is_MAC_edit) {
  354. let pos = this.node.parent.getComponent(UITransform).convertToWorldSpaceAR(this.node.position)
  355. if(this.x_len==0){
  356. this.x_len = (et.getUILocation().x - pos.x)*2;
  357. this.y_len = (et.getUILocation().y - pos.y)*2;
  358. let p = new Vec3(et.getUILocation().x,et.getUILocation().y)
  359. let n_p = this.node.parent.getComponent(UITransform).convertToNodeSpaceAR(p)
  360. this.node.position = new Vec3(n_p.x-this.x_len,n_p.y-this.y_len);
  361. // console.log("a_x",this.x_len, this.y_len ,et.getUILocation().x,this.m_att.width)
  362. }
  363. // console.log("this.x_len",this.x_len,this.y_len)
  364. this.isMove = true;
  365. ClientEvent.dispatchEvent(config.Event.UpdateAttributes,this.getWidgetAtt())
  366. }
  367. })
  368. }
  369. ClientEvent.dispatchEvent(config.Event.UpdateAttributes,this.getWidgetAtt())
  370. ClientEvent.on(config.Event.UpdateAttributesToView,this.UpdateAttributesToView,this)
  371. }
  372. protected onDestroy(): void {
  373. ClientEvent.off(config.Event.UpdateAttributesToView,this.UpdateAttributesToView,this)
  374. }
  375. UpdateAttributesToView(data:attributes_data,update_type:string){
  376. if(this.m_att===null){
  377. return;
  378. }
  379. if(data.id===this.m_att.id){
  380. console.log("this.m_att",this.m_att)
  381. switch(update_type){
  382. case config.attributes_list_type.pos:
  383. this.m_att.x = data.x;
  384. this.m_att.y = data.y;
  385. this.m_att.z = data.z;
  386. this.node.setSiblingIndex(this.m_att.z)
  387. this.node.position = new Vec3(data.x,data.y)
  388. break;
  389. case config.attributes_list_type.animation:
  390. this.m_att.animation_list = data.animation_list;
  391. break;
  392. case config.attributes_list_type.size:
  393. this.m_att.width = data.width;
  394. this.m_att.height = data.height;
  395. this.spr.getComponent(UITransform).contentSize = new Size(data.width,data.height)
  396. this.node.getComponent(UITransform).contentSize = this.spr.getComponent(UITransform).contentSize
  397. break;
  398. case config.attributes_list_type.anchor:
  399. this.m_att.anchor_x = data.anchor_x;
  400. this.m_att.anchor_y = data.anchor_y;
  401. this.spr.getComponent(UITransform).setAnchorPoint(data.anchor_x, data.anchor_y)
  402. break;
  403. case config.attributes_list_type.rotation:
  404. this.m_att.rotation = data.rotation;
  405. this.spr.angle = data.rotation;
  406. break;
  407. case config.attributes_list_type.url:
  408. this.m_att.src = data.src
  409. this.m_att.src_name = data.src_name
  410. if(this.m_att.src.length<=0){
  411. this.spr.getComponent(Sprite).spriteFrame = null
  412. }else{
  413. assetManager.loadRemote<ImageAsset>(this.m_att.src, (err, imageAsset2)=>{
  414. if (!err && imageAsset2) {
  415. this.lab_name.active = false;
  416. const texture = new Texture2D();
  417. texture.image = imageAsset2;
  418. let spFrame2 = new SpriteFrame();
  419. spFrame2.texture = texture;
  420. this.spr.getComponent(Sprite).spriteFrame = spFrame2
  421. this.spr.getComponent(UITransform).contentSize = new Size(data.width,data.height)
  422. director.once(Director.EVENT_AFTER_DRAW,()=>{
  423. this.node.getComponent(UITransform).contentSize = this.spr.getComponent(UITransform).contentSize
  424. })
  425. }
  426. });
  427. }
  428. break;
  429. case config.attributes_list_type.origin:
  430. if(this.m_att.src.length>0){
  431. this.spr.getComponent(UITransform).setContentSize(new Size(this.m_att.width,this.m_att.height))
  432. this.node.getComponent(UITransform).contentSize = this.spr.getComponent(UITransform).contentSize
  433. ClientEvent.dispatchEvent(config.Event.UpdateAttributes,this.getWidgetAtt())
  434. // this.spr.getComponent(Sprite).sizeMode = Sprite.SizeMode.RAW;
  435. // director.once(Director.EVENT_AFTER_DRAW,()=>{
  436. // console.log("Director.EVENT_AFTER_DRAW")
  437. // this.m_att.width = this.spr.getComponent(UITransform).contentSize.width;
  438. // this.m_att.height = this.spr.getComponent(UITransform).contentSize.height;
  439. // director.once(Director.EVENT_AFTER_DRAW,()=>{
  440. // this.node.getComponent(UITransform).contentSize = this.spr.getComponent(UITransform).contentSize
  441. // })
  442. // ClientEvent.dispatchEvent(config.Event.UpdateAttributes,this.getWidgetAtt())
  443. // })
  444. }
  445. break;
  446. case config.attributes_list_type.delete:
  447. this.node.destroy()
  448. this.node.removeFromParent()
  449. ClientEvent.dispatchEvent(config.Event.UpdateAttributes,null)
  450. ClientEvent.dispatchEvent(config.Event.RemoveWidget,this.node)
  451. break;
  452. case config.attributes_list_type.drag:
  453. this.m_att.drag_data = data.drag_data
  454. if(this.m_data.type===config.Widget_Type_List.DRAG_TYPE){
  455. this.drag.getComponent(UITransform).contentSize = new Size(data.drag_data.drag_size_width,data.drag_data.drag_size_height);
  456. this.drag.position = new Vec3( this.m_att.drag_data.drag_pos_x , this.m_att.drag_data.drag_pos_y)
  457. if(this.m_att.drag_data.other_drag_list==undefined){
  458. this.m_att.drag_data.other_drag_list = []
  459. }
  460. // 更新 其他拖拽
  461. this.other_drag_content.removeAllChildren()
  462. for (let index = 0; index < this.m_att.drag_data.other_drag_list.length; index++) {
  463. const element = this.m_att.drag_data.other_drag_list[index];
  464. let item = instantiate(this.drag)
  465. item.off(Node.EventType.TOUCH_MOVE)
  466. item.parent = this.other_drag_content;
  467. item.position = new Vec3(element.drag_pos_x,element.drag_pos_y)
  468. item.getComponent(UITransform).setContentSize(new Size(element.drag_size_width,element.drag_size_height))
  469. item.on(Node.EventType.TOUCH_MOVE,(et:EventTouch)=>{
  470. let p = new Vec3(et.getUILocation().x,et.getUILocation().y)
  471. let n_p = this.node.getComponent(UITransform).convertToNodeSpaceAR(p)
  472. item.position = n_p;
  473. this.m_att.drag_data.other_drag_list[index].drag_pos_x = item.position.x;
  474. this.m_att.drag_data.other_drag_list[index].drag_pos_y = item.position.y;
  475. })
  476. item.getComponent(Sprite).color = this.getOtherDragListColor(index) //Color.YELLOW
  477. item.getChildByName('lab_drag_remark').getComponent(Label).string = element.remark
  478. item.active = element.is_show_inTheEditor
  479. }
  480. }
  481. break;
  482. case config.attributes_list_type.drag_err_back_status:
  483. if(this.m_data.type===config.Widget_Type_List.DRAG_TYPE){
  484. this.m_att.drag_data.is_err_drag_back = data.drag_data.is_err_drag_back;
  485. }
  486. break;
  487. case config.attributes_list_type.slide:
  488. if(this.m_data.type===config.Widget_Type_List.SLIDE_TYPE){
  489. this.m_att.slide_data.slide_dir = data.slide_data.slide_dir;
  490. this.m_att.slide_data.slide_distance = data.slide_data.slide_distance;
  491. this.m_att.slide_data.slide_num = data.slide_data.slide_num;
  492. this.slide.getComponent(slide).updateDistance(this.m_att.slide_data.slide_dir,this.m_att.slide_data.slide_distance)
  493. }
  494. break;
  495. case config.attributes_list_type.click:
  496. if(this.m_data.type===config.Widget_Type_List.CLICK_TYPE){
  497. this.m_att.click_data = data.click_data;
  498. this.lab_name.getComponent(Label).string = config.clcik_type_map.get(this.m_att.click_data.click_type)
  499. }
  500. case config.attributes_list_type.is_interaction:
  501. this.m_att.is_interaction = data.is_interaction;
  502. break;
  503. case config.attributes_list_type.find_widget_pos:
  504. this.Shiny()
  505. break;
  506. case config.attributes_list_type.active:
  507. this.m_att.edit_active = data.edit_active;
  508. this.node.active = this.m_att.edit_active
  509. this.toggle_check.getComponent(Toggle).isChecked = this.m_att.edit_active
  510. break;
  511. case config.attributes_list_type.top:
  512. this.m_att.top_data = data.top_data;
  513. if(this.m_ui_widget!=null){
  514. this.m_ui_widget.getComponent(ui_top).changeData(this.m_att.top_data)
  515. }
  516. break;
  517. case config.attributes_list_type.text_sound:
  518. this.m_att.text_sound_data = data.text_sound_data;
  519. if(this.m_text_sound!=null){
  520. this.m_text_sound.getComponent(Text_Sound).updateView(this.m_att.text_sound_data)
  521. }
  522. break;
  523. case config.attributes_list_type.question_select:
  524. this.m_att.question_select = data.question_select;
  525. if(this.m_question_select!=null){
  526. this.m_question_select.getComponent(question_select).updateView(this.m_att.question_select)
  527. }
  528. break;
  529. case config.attributes_list_type.count_down:
  530. this.m_att.count_down = data.count_down;
  531. if(this.m_count_down!=null){
  532. this.m_count_down.getComponent(count_down).updateView(this.m_att.count_down)
  533. }
  534. break;
  535. case config.attributes_list_type.zIndex:
  536. this.m_att.zIndex = data.zIndex;
  537. break;
  538. case config.attributes_list_type.dir:
  539. this.m_att.img_dir = data.img_dir;
  540. this.updateDir()
  541. break;
  542. case config.attributes_list_type.show:
  543. this.m_att.is_show = data.is_show;
  544. break;
  545. case config.attributes_list_type.container:
  546. this.m_att.container_layer = data.container_layer
  547. // this.initConatiner()
  548. break;
  549. }
  550. }
  551. director.once(Director.EVENT_AFTER_DRAW,()=>{
  552. ClientEvent.dispatchEvent(config.Event.updateWidgetData)
  553. })
  554. }
  555. updateDir(){
  556. if(this.call_back==null){
  557. switch (this.m_att.img_dir) {
  558. case config.widget_scale_dir.left:
  559. this.spr.scale = new Vec3(-1,1)
  560. break;
  561. case config.widget_scale_dir.up:
  562. this.spr.scale = new Vec3(1,-1)
  563. break;
  564. case config.widget_scale_dir.normal:
  565. this.spr.scale = new Vec3(1,1)
  566. break;
  567. }
  568. }
  569. }
  570. getOtherDragListColor(index:number):Color {
  571. var color_index = index
  572. if(index >= config.COLOR_LIST.length) {
  573. let count = Math.floor(index / config.COLOR_LIST.length)
  574. color_index = index - (config.COLOR_LIST.length * count)
  575. }
  576. return config.COLOR_LIST[color_index]
  577. // return Color.YELLOW
  578. }
  579. Shiny(){
  580. this.img_select.active = true;
  581. this.img_select.getComponent(UITransform).setContentSize(this.node.getComponent(UITransform).contentSize)
  582. Tween.stopAllByTarget(this.img_select)
  583. tween(this.img_select).delay(0.3).hide().delay(0.3).show().delay(0.3).hide().delay(0.3).show().delay(0.3).call(()=>{
  584. this.img_select.active = false;
  585. }).start()
  586. }
  587. public getWidgetAtt(){
  588. this.m_att.name = this.m_data.name!=""?this.m_data.name:"普通控件";
  589. this.m_att.remark = this.m_att.remark;
  590. this.m_att.height = this.spr.getComponent(UITransform).contentSize.height;
  591. this.m_att.width = this.spr.getComponent(UITransform).contentSize.width;
  592. this.m_att.anchor_x = this.m_att.anchor_x==undefined?0.5:this.m_att.anchor_x
  593. this.m_att.anchor_y = this.m_att.anchor_y==undefined?0.5:this.m_att.anchor_y
  594. this.m_att.rotation = this.m_att.rotation;
  595. this.m_att.x = this.node.position.x;
  596. this.m_att.widget_type = this.m_data.type;
  597. this.m_att.y = this.node.position.y;
  598. this.m_att.z = this.node.getSiblingIndex();
  599. this.m_att.type = config.attributes_type.widget;
  600. this.m_att.src_name = this.m_att.src.length>0? this.m_att.src_name:"空";
  601. if(this.m_att.drag_data!=null){
  602. this.m_att.drag_data.drag_pos_x = this.drag.position.x;
  603. this.m_att.drag_data.drag_pos_y = this.drag.position.y;
  604. this.m_att.drag_data.drag_size_width = this.drag.getComponent(UITransform).contentSize.width;
  605. this.m_att.drag_data.drag_size_height = this.drag.getComponent(UITransform).contentSize.height;
  606. }
  607. return this.m_att;
  608. }
  609. initWidgetAtt(){
  610. if(this.call_back==null){
  611. this.node.position = new Vec3(this.m_att.x,this.m_att.y)
  612. this.node.getComponent(UITransform).setContentSize(new Size( this.m_att.width,this.m_att.height))
  613. this.spr.angle = this.m_att.rotation
  614. this.spr.getComponent(UITransform).setAnchorPoint(new Vec2(this.m_att.anchor_x, this.m_att.anchor_y))
  615. if(this.m_att.drag_data!=null){
  616. this.drag.position = new Vec3(this.m_att.drag_data.drag_pos_x,this.m_att.drag_data.drag_pos_y)
  617. this.drag.getComponent(UITransform).setContentSize(new Size(this.m_att.drag_data.drag_size_width ,this.m_att.drag_data.drag_size_height ))
  618. }
  619. this.spr.getComponent(UITransform).setContentSize(this.node.getComponent(UITransform).contentSize)
  620. this.lab_name.getComponent(Label).string = this.m_att.name+"id:"+this.m_att.id;;
  621. }else{
  622. this.lab_name.getComponent(Label).string = this.m_data.name+"id:"+this.m_att.id;
  623. }
  624. if(this.m_att.src!=""&&this.m_att.src.length>0){
  625. assetManager.loadRemote<ImageAsset>(this.m_att.src, (err, imageAsset2)=>{
  626. if (!err && imageAsset2) {
  627. const texture = new Texture2D();
  628. texture.image = imageAsset2;
  629. let spFrame2 = new SpriteFrame();
  630. spFrame2.texture = texture;
  631. this.spr.getComponent(Sprite).spriteFrame = spFrame2
  632. }
  633. });
  634. }
  635. //进行数据差矫正
  636. let t_data = new attributes_data
  637. for (const key in t_data) {
  638. if (Object.prototype.hasOwnProperty.call(t_data ,key)) {
  639. const element = t_data[key];
  640. if(this.m_att[key]===undefined){
  641. this.m_att[key] = element;
  642. }
  643. }
  644. }
  645. this.updateDir()
  646. }
  647. public getData(){
  648. if(this.m_att!=null){
  649. this.getWidgetAtt()
  650. }
  651. this.m_data.att = this.m_att;
  652. return this.m_data;
  653. }
  654. public setData(data){
  655. this.m_data = data;
  656. }
  657. public getContainer(){
  658. return this.container
  659. }
  660. }