widget_item.ts 33 KB

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